si.c 200 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154
  1. /*
  2. * Copyright 2011 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 <linux/module.h>
  27. #include <drm/drmP.h>
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include <drm/radeon_drm.h>
  31. #include "sid.h"
  32. #include "atom.h"
  33. #include "si_blit_shaders.h"
  34. #include "clearstate_si.h"
  35. #include "radeon_ucode.h"
  36. MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
  37. MODULE_FIRMWARE("radeon/TAHITI_me.bin");
  38. MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
  39. MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
  40. MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
  41. MODULE_FIRMWARE("radeon/TAHITI_smc.bin");
  42. MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
  43. MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
  44. MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
  45. MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
  46. MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
  47. MODULE_FIRMWARE("radeon/PITCAIRN_smc.bin");
  48. MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
  49. MODULE_FIRMWARE("radeon/VERDE_me.bin");
  50. MODULE_FIRMWARE("radeon/VERDE_ce.bin");
  51. MODULE_FIRMWARE("radeon/VERDE_mc.bin");
  52. MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
  53. MODULE_FIRMWARE("radeon/VERDE_smc.bin");
  54. MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
  55. MODULE_FIRMWARE("radeon/OLAND_me.bin");
  56. MODULE_FIRMWARE("radeon/OLAND_ce.bin");
  57. MODULE_FIRMWARE("radeon/OLAND_mc.bin");
  58. MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
  59. MODULE_FIRMWARE("radeon/OLAND_smc.bin");
  60. MODULE_FIRMWARE("radeon/HAINAN_pfp.bin");
  61. MODULE_FIRMWARE("radeon/HAINAN_me.bin");
  62. MODULE_FIRMWARE("radeon/HAINAN_ce.bin");
  63. MODULE_FIRMWARE("radeon/HAINAN_mc.bin");
  64. MODULE_FIRMWARE("radeon/HAINAN_rlc.bin");
  65. MODULE_FIRMWARE("radeon/HAINAN_smc.bin");
  66. static void si_pcie_gen3_enable(struct radeon_device *rdev);
  67. static void si_program_aspm(struct radeon_device *rdev);
  68. extern void sumo_rlc_fini(struct radeon_device *rdev);
  69. extern int sumo_rlc_init(struct radeon_device *rdev);
  70. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  71. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  72. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  73. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  74. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  75. extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
  76. extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
  77. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  78. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  79. bool enable);
  80. static void si_fini_pg(struct radeon_device *rdev);
  81. static void si_fini_cg(struct radeon_device *rdev);
  82. static void si_rlc_stop(struct radeon_device *rdev);
  83. static const u32 verde_rlc_save_restore_register_list[] =
  84. {
  85. (0x8000 << 16) | (0x98f4 >> 2),
  86. 0x00000000,
  87. (0x8040 << 16) | (0x98f4 >> 2),
  88. 0x00000000,
  89. (0x8000 << 16) | (0xe80 >> 2),
  90. 0x00000000,
  91. (0x8040 << 16) | (0xe80 >> 2),
  92. 0x00000000,
  93. (0x8000 << 16) | (0x89bc >> 2),
  94. 0x00000000,
  95. (0x8040 << 16) | (0x89bc >> 2),
  96. 0x00000000,
  97. (0x8000 << 16) | (0x8c1c >> 2),
  98. 0x00000000,
  99. (0x8040 << 16) | (0x8c1c >> 2),
  100. 0x00000000,
  101. (0x9c00 << 16) | (0x98f0 >> 2),
  102. 0x00000000,
  103. (0x9c00 << 16) | (0xe7c >> 2),
  104. 0x00000000,
  105. (0x8000 << 16) | (0x9148 >> 2),
  106. 0x00000000,
  107. (0x8040 << 16) | (0x9148 >> 2),
  108. 0x00000000,
  109. (0x9c00 << 16) | (0x9150 >> 2),
  110. 0x00000000,
  111. (0x9c00 << 16) | (0x897c >> 2),
  112. 0x00000000,
  113. (0x9c00 << 16) | (0x8d8c >> 2),
  114. 0x00000000,
  115. (0x9c00 << 16) | (0xac54 >> 2),
  116. 0X00000000,
  117. 0x3,
  118. (0x9c00 << 16) | (0x98f8 >> 2),
  119. 0x00000000,
  120. (0x9c00 << 16) | (0x9910 >> 2),
  121. 0x00000000,
  122. (0x9c00 << 16) | (0x9914 >> 2),
  123. 0x00000000,
  124. (0x9c00 << 16) | (0x9918 >> 2),
  125. 0x00000000,
  126. (0x9c00 << 16) | (0x991c >> 2),
  127. 0x00000000,
  128. (0x9c00 << 16) | (0x9920 >> 2),
  129. 0x00000000,
  130. (0x9c00 << 16) | (0x9924 >> 2),
  131. 0x00000000,
  132. (0x9c00 << 16) | (0x9928 >> 2),
  133. 0x00000000,
  134. (0x9c00 << 16) | (0x992c >> 2),
  135. 0x00000000,
  136. (0x9c00 << 16) | (0x9930 >> 2),
  137. 0x00000000,
  138. (0x9c00 << 16) | (0x9934 >> 2),
  139. 0x00000000,
  140. (0x9c00 << 16) | (0x9938 >> 2),
  141. 0x00000000,
  142. (0x9c00 << 16) | (0x993c >> 2),
  143. 0x00000000,
  144. (0x9c00 << 16) | (0x9940 >> 2),
  145. 0x00000000,
  146. (0x9c00 << 16) | (0x9944 >> 2),
  147. 0x00000000,
  148. (0x9c00 << 16) | (0x9948 >> 2),
  149. 0x00000000,
  150. (0x9c00 << 16) | (0x994c >> 2),
  151. 0x00000000,
  152. (0x9c00 << 16) | (0x9950 >> 2),
  153. 0x00000000,
  154. (0x9c00 << 16) | (0x9954 >> 2),
  155. 0x00000000,
  156. (0x9c00 << 16) | (0x9958 >> 2),
  157. 0x00000000,
  158. (0x9c00 << 16) | (0x995c >> 2),
  159. 0x00000000,
  160. (0x9c00 << 16) | (0x9960 >> 2),
  161. 0x00000000,
  162. (0x9c00 << 16) | (0x9964 >> 2),
  163. 0x00000000,
  164. (0x9c00 << 16) | (0x9968 >> 2),
  165. 0x00000000,
  166. (0x9c00 << 16) | (0x996c >> 2),
  167. 0x00000000,
  168. (0x9c00 << 16) | (0x9970 >> 2),
  169. 0x00000000,
  170. (0x9c00 << 16) | (0x9974 >> 2),
  171. 0x00000000,
  172. (0x9c00 << 16) | (0x9978 >> 2),
  173. 0x00000000,
  174. (0x9c00 << 16) | (0x997c >> 2),
  175. 0x00000000,
  176. (0x9c00 << 16) | (0x9980 >> 2),
  177. 0x00000000,
  178. (0x9c00 << 16) | (0x9984 >> 2),
  179. 0x00000000,
  180. (0x9c00 << 16) | (0x9988 >> 2),
  181. 0x00000000,
  182. (0x9c00 << 16) | (0x998c >> 2),
  183. 0x00000000,
  184. (0x9c00 << 16) | (0x8c00 >> 2),
  185. 0x00000000,
  186. (0x9c00 << 16) | (0x8c14 >> 2),
  187. 0x00000000,
  188. (0x9c00 << 16) | (0x8c04 >> 2),
  189. 0x00000000,
  190. (0x9c00 << 16) | (0x8c08 >> 2),
  191. 0x00000000,
  192. (0x8000 << 16) | (0x9b7c >> 2),
  193. 0x00000000,
  194. (0x8040 << 16) | (0x9b7c >> 2),
  195. 0x00000000,
  196. (0x8000 << 16) | (0xe84 >> 2),
  197. 0x00000000,
  198. (0x8040 << 16) | (0xe84 >> 2),
  199. 0x00000000,
  200. (0x8000 << 16) | (0x89c0 >> 2),
  201. 0x00000000,
  202. (0x8040 << 16) | (0x89c0 >> 2),
  203. 0x00000000,
  204. (0x8000 << 16) | (0x914c >> 2),
  205. 0x00000000,
  206. (0x8040 << 16) | (0x914c >> 2),
  207. 0x00000000,
  208. (0x8000 << 16) | (0x8c20 >> 2),
  209. 0x00000000,
  210. (0x8040 << 16) | (0x8c20 >> 2),
  211. 0x00000000,
  212. (0x8000 << 16) | (0x9354 >> 2),
  213. 0x00000000,
  214. (0x8040 << 16) | (0x9354 >> 2),
  215. 0x00000000,
  216. (0x9c00 << 16) | (0x9060 >> 2),
  217. 0x00000000,
  218. (0x9c00 << 16) | (0x9364 >> 2),
  219. 0x00000000,
  220. (0x9c00 << 16) | (0x9100 >> 2),
  221. 0x00000000,
  222. (0x9c00 << 16) | (0x913c >> 2),
  223. 0x00000000,
  224. (0x8000 << 16) | (0x90e0 >> 2),
  225. 0x00000000,
  226. (0x8000 << 16) | (0x90e4 >> 2),
  227. 0x00000000,
  228. (0x8000 << 16) | (0x90e8 >> 2),
  229. 0x00000000,
  230. (0x8040 << 16) | (0x90e0 >> 2),
  231. 0x00000000,
  232. (0x8040 << 16) | (0x90e4 >> 2),
  233. 0x00000000,
  234. (0x8040 << 16) | (0x90e8 >> 2),
  235. 0x00000000,
  236. (0x9c00 << 16) | (0x8bcc >> 2),
  237. 0x00000000,
  238. (0x9c00 << 16) | (0x8b24 >> 2),
  239. 0x00000000,
  240. (0x9c00 << 16) | (0x88c4 >> 2),
  241. 0x00000000,
  242. (0x9c00 << 16) | (0x8e50 >> 2),
  243. 0x00000000,
  244. (0x9c00 << 16) | (0x8c0c >> 2),
  245. 0x00000000,
  246. (0x9c00 << 16) | (0x8e58 >> 2),
  247. 0x00000000,
  248. (0x9c00 << 16) | (0x8e5c >> 2),
  249. 0x00000000,
  250. (0x9c00 << 16) | (0x9508 >> 2),
  251. 0x00000000,
  252. (0x9c00 << 16) | (0x950c >> 2),
  253. 0x00000000,
  254. (0x9c00 << 16) | (0x9494 >> 2),
  255. 0x00000000,
  256. (0x9c00 << 16) | (0xac0c >> 2),
  257. 0x00000000,
  258. (0x9c00 << 16) | (0xac10 >> 2),
  259. 0x00000000,
  260. (0x9c00 << 16) | (0xac14 >> 2),
  261. 0x00000000,
  262. (0x9c00 << 16) | (0xae00 >> 2),
  263. 0x00000000,
  264. (0x9c00 << 16) | (0xac08 >> 2),
  265. 0x00000000,
  266. (0x9c00 << 16) | (0x88d4 >> 2),
  267. 0x00000000,
  268. (0x9c00 << 16) | (0x88c8 >> 2),
  269. 0x00000000,
  270. (0x9c00 << 16) | (0x88cc >> 2),
  271. 0x00000000,
  272. (0x9c00 << 16) | (0x89b0 >> 2),
  273. 0x00000000,
  274. (0x9c00 << 16) | (0x8b10 >> 2),
  275. 0x00000000,
  276. (0x9c00 << 16) | (0x8a14 >> 2),
  277. 0x00000000,
  278. (0x9c00 << 16) | (0x9830 >> 2),
  279. 0x00000000,
  280. (0x9c00 << 16) | (0x9834 >> 2),
  281. 0x00000000,
  282. (0x9c00 << 16) | (0x9838 >> 2),
  283. 0x00000000,
  284. (0x9c00 << 16) | (0x9a10 >> 2),
  285. 0x00000000,
  286. (0x8000 << 16) | (0x9870 >> 2),
  287. 0x00000000,
  288. (0x8000 << 16) | (0x9874 >> 2),
  289. 0x00000000,
  290. (0x8001 << 16) | (0x9870 >> 2),
  291. 0x00000000,
  292. (0x8001 << 16) | (0x9874 >> 2),
  293. 0x00000000,
  294. (0x8040 << 16) | (0x9870 >> 2),
  295. 0x00000000,
  296. (0x8040 << 16) | (0x9874 >> 2),
  297. 0x00000000,
  298. (0x8041 << 16) | (0x9870 >> 2),
  299. 0x00000000,
  300. (0x8041 << 16) | (0x9874 >> 2),
  301. 0x00000000,
  302. 0x00000000
  303. };
  304. static const u32 tahiti_golden_rlc_registers[] =
  305. {
  306. 0xc424, 0xffffffff, 0x00601005,
  307. 0xc47c, 0xffffffff, 0x10104040,
  308. 0xc488, 0xffffffff, 0x0100000a,
  309. 0xc314, 0xffffffff, 0x00000800,
  310. 0xc30c, 0xffffffff, 0x800000f4,
  311. 0xf4a8, 0xffffffff, 0x00000000
  312. };
  313. static const u32 tahiti_golden_registers[] =
  314. {
  315. 0x9a10, 0x00010000, 0x00018208,
  316. 0x9830, 0xffffffff, 0x00000000,
  317. 0x9834, 0xf00fffff, 0x00000400,
  318. 0x9838, 0x0002021c, 0x00020200,
  319. 0xc78, 0x00000080, 0x00000000,
  320. 0xd030, 0x000300c0, 0x00800040,
  321. 0xd830, 0x000300c0, 0x00800040,
  322. 0x5bb0, 0x000000f0, 0x00000070,
  323. 0x5bc0, 0x00200000, 0x50100000,
  324. 0x7030, 0x31000311, 0x00000011,
  325. 0x277c, 0x00000003, 0x000007ff,
  326. 0x240c, 0x000007ff, 0x00000000,
  327. 0x8a14, 0xf000001f, 0x00000007,
  328. 0x8b24, 0xffffffff, 0x00ffffff,
  329. 0x8b10, 0x0000ff0f, 0x00000000,
  330. 0x28a4c, 0x07ffffff, 0x4e000000,
  331. 0x28350, 0x3f3f3fff, 0x2a00126a,
  332. 0x30, 0x000000ff, 0x0040,
  333. 0x34, 0x00000040, 0x00004040,
  334. 0x9100, 0x07ffffff, 0x03000000,
  335. 0x8e88, 0x01ff1f3f, 0x00000000,
  336. 0x8e84, 0x01ff1f3f, 0x00000000,
  337. 0x9060, 0x0000007f, 0x00000020,
  338. 0x9508, 0x00010000, 0x00010000,
  339. 0xac14, 0x00000200, 0x000002fb,
  340. 0xac10, 0xffffffff, 0x0000543b,
  341. 0xac0c, 0xffffffff, 0xa9210876,
  342. 0x88d0, 0xffffffff, 0x000fff40,
  343. 0x88d4, 0x0000001f, 0x00000010,
  344. 0x1410, 0x20000000, 0x20fffed8,
  345. 0x15c0, 0x000c0fc0, 0x000c0400
  346. };
  347. static const u32 tahiti_golden_registers2[] =
  348. {
  349. 0xc64, 0x00000001, 0x00000001
  350. };
  351. static const u32 pitcairn_golden_rlc_registers[] =
  352. {
  353. 0xc424, 0xffffffff, 0x00601004,
  354. 0xc47c, 0xffffffff, 0x10102020,
  355. 0xc488, 0xffffffff, 0x01000020,
  356. 0xc314, 0xffffffff, 0x00000800,
  357. 0xc30c, 0xffffffff, 0x800000a4
  358. };
  359. static const u32 pitcairn_golden_registers[] =
  360. {
  361. 0x9a10, 0x00010000, 0x00018208,
  362. 0x9830, 0xffffffff, 0x00000000,
  363. 0x9834, 0xf00fffff, 0x00000400,
  364. 0x9838, 0x0002021c, 0x00020200,
  365. 0xc78, 0x00000080, 0x00000000,
  366. 0xd030, 0x000300c0, 0x00800040,
  367. 0xd830, 0x000300c0, 0x00800040,
  368. 0x5bb0, 0x000000f0, 0x00000070,
  369. 0x5bc0, 0x00200000, 0x50100000,
  370. 0x7030, 0x31000311, 0x00000011,
  371. 0x2ae4, 0x00073ffe, 0x000022a2,
  372. 0x240c, 0x000007ff, 0x00000000,
  373. 0x8a14, 0xf000001f, 0x00000007,
  374. 0x8b24, 0xffffffff, 0x00ffffff,
  375. 0x8b10, 0x0000ff0f, 0x00000000,
  376. 0x28a4c, 0x07ffffff, 0x4e000000,
  377. 0x28350, 0x3f3f3fff, 0x2a00126a,
  378. 0x30, 0x000000ff, 0x0040,
  379. 0x34, 0x00000040, 0x00004040,
  380. 0x9100, 0x07ffffff, 0x03000000,
  381. 0x9060, 0x0000007f, 0x00000020,
  382. 0x9508, 0x00010000, 0x00010000,
  383. 0xac14, 0x000003ff, 0x000000f7,
  384. 0xac10, 0xffffffff, 0x00000000,
  385. 0xac0c, 0xffffffff, 0x32761054,
  386. 0x88d4, 0x0000001f, 0x00000010,
  387. 0x15c0, 0x000c0fc0, 0x000c0400
  388. };
  389. static const u32 verde_golden_rlc_registers[] =
  390. {
  391. 0xc424, 0xffffffff, 0x033f1005,
  392. 0xc47c, 0xffffffff, 0x10808020,
  393. 0xc488, 0xffffffff, 0x00800008,
  394. 0xc314, 0xffffffff, 0x00001000,
  395. 0xc30c, 0xffffffff, 0x80010014
  396. };
  397. static const u32 verde_golden_registers[] =
  398. {
  399. 0x9a10, 0x00010000, 0x00018208,
  400. 0x9830, 0xffffffff, 0x00000000,
  401. 0x9834, 0xf00fffff, 0x00000400,
  402. 0x9838, 0x0002021c, 0x00020200,
  403. 0xc78, 0x00000080, 0x00000000,
  404. 0xd030, 0x000300c0, 0x00800040,
  405. 0xd030, 0x000300c0, 0x00800040,
  406. 0xd830, 0x000300c0, 0x00800040,
  407. 0xd830, 0x000300c0, 0x00800040,
  408. 0x5bb0, 0x000000f0, 0x00000070,
  409. 0x5bc0, 0x00200000, 0x50100000,
  410. 0x7030, 0x31000311, 0x00000011,
  411. 0x2ae4, 0x00073ffe, 0x000022a2,
  412. 0x2ae4, 0x00073ffe, 0x000022a2,
  413. 0x2ae4, 0x00073ffe, 0x000022a2,
  414. 0x240c, 0x000007ff, 0x00000000,
  415. 0x240c, 0x000007ff, 0x00000000,
  416. 0x240c, 0x000007ff, 0x00000000,
  417. 0x8a14, 0xf000001f, 0x00000007,
  418. 0x8a14, 0xf000001f, 0x00000007,
  419. 0x8a14, 0xf000001f, 0x00000007,
  420. 0x8b24, 0xffffffff, 0x00ffffff,
  421. 0x8b10, 0x0000ff0f, 0x00000000,
  422. 0x28a4c, 0x07ffffff, 0x4e000000,
  423. 0x28350, 0x3f3f3fff, 0x0000124a,
  424. 0x28350, 0x3f3f3fff, 0x0000124a,
  425. 0x28350, 0x3f3f3fff, 0x0000124a,
  426. 0x30, 0x000000ff, 0x0040,
  427. 0x34, 0x00000040, 0x00004040,
  428. 0x9100, 0x07ffffff, 0x03000000,
  429. 0x9100, 0x07ffffff, 0x03000000,
  430. 0x8e88, 0x01ff1f3f, 0x00000000,
  431. 0x8e88, 0x01ff1f3f, 0x00000000,
  432. 0x8e88, 0x01ff1f3f, 0x00000000,
  433. 0x8e84, 0x01ff1f3f, 0x00000000,
  434. 0x8e84, 0x01ff1f3f, 0x00000000,
  435. 0x8e84, 0x01ff1f3f, 0x00000000,
  436. 0x9060, 0x0000007f, 0x00000020,
  437. 0x9508, 0x00010000, 0x00010000,
  438. 0xac14, 0x000003ff, 0x00000003,
  439. 0xac14, 0x000003ff, 0x00000003,
  440. 0xac14, 0x000003ff, 0x00000003,
  441. 0xac10, 0xffffffff, 0x00000000,
  442. 0xac10, 0xffffffff, 0x00000000,
  443. 0xac10, 0xffffffff, 0x00000000,
  444. 0xac0c, 0xffffffff, 0x00001032,
  445. 0xac0c, 0xffffffff, 0x00001032,
  446. 0xac0c, 0xffffffff, 0x00001032,
  447. 0x88d4, 0x0000001f, 0x00000010,
  448. 0x88d4, 0x0000001f, 0x00000010,
  449. 0x88d4, 0x0000001f, 0x00000010,
  450. 0x15c0, 0x000c0fc0, 0x000c0400
  451. };
  452. static const u32 oland_golden_rlc_registers[] =
  453. {
  454. 0xc424, 0xffffffff, 0x00601005,
  455. 0xc47c, 0xffffffff, 0x10104040,
  456. 0xc488, 0xffffffff, 0x0100000a,
  457. 0xc314, 0xffffffff, 0x00000800,
  458. 0xc30c, 0xffffffff, 0x800000f4
  459. };
  460. static const u32 oland_golden_registers[] =
  461. {
  462. 0x9a10, 0x00010000, 0x00018208,
  463. 0x9830, 0xffffffff, 0x00000000,
  464. 0x9834, 0xf00fffff, 0x00000400,
  465. 0x9838, 0x0002021c, 0x00020200,
  466. 0xc78, 0x00000080, 0x00000000,
  467. 0xd030, 0x000300c0, 0x00800040,
  468. 0xd830, 0x000300c0, 0x00800040,
  469. 0x5bb0, 0x000000f0, 0x00000070,
  470. 0x5bc0, 0x00200000, 0x50100000,
  471. 0x7030, 0x31000311, 0x00000011,
  472. 0x2ae4, 0x00073ffe, 0x000022a2,
  473. 0x240c, 0x000007ff, 0x00000000,
  474. 0x8a14, 0xf000001f, 0x00000007,
  475. 0x8b24, 0xffffffff, 0x00ffffff,
  476. 0x8b10, 0x0000ff0f, 0x00000000,
  477. 0x28a4c, 0x07ffffff, 0x4e000000,
  478. 0x28350, 0x3f3f3fff, 0x00000082,
  479. 0x30, 0x000000ff, 0x0040,
  480. 0x34, 0x00000040, 0x00004040,
  481. 0x9100, 0x07ffffff, 0x03000000,
  482. 0x9060, 0x0000007f, 0x00000020,
  483. 0x9508, 0x00010000, 0x00010000,
  484. 0xac14, 0x000003ff, 0x000000f3,
  485. 0xac10, 0xffffffff, 0x00000000,
  486. 0xac0c, 0xffffffff, 0x00003210,
  487. 0x88d4, 0x0000001f, 0x00000010,
  488. 0x15c0, 0x000c0fc0, 0x000c0400
  489. };
  490. static const u32 hainan_golden_registers[] =
  491. {
  492. 0x9a10, 0x00010000, 0x00018208,
  493. 0x9830, 0xffffffff, 0x00000000,
  494. 0x9834, 0xf00fffff, 0x00000400,
  495. 0x9838, 0x0002021c, 0x00020200,
  496. 0xd0c0, 0xff000fff, 0x00000100,
  497. 0xd030, 0x000300c0, 0x00800040,
  498. 0xd8c0, 0xff000fff, 0x00000100,
  499. 0xd830, 0x000300c0, 0x00800040,
  500. 0x2ae4, 0x00073ffe, 0x000022a2,
  501. 0x240c, 0x000007ff, 0x00000000,
  502. 0x8a14, 0xf000001f, 0x00000007,
  503. 0x8b24, 0xffffffff, 0x00ffffff,
  504. 0x8b10, 0x0000ff0f, 0x00000000,
  505. 0x28a4c, 0x07ffffff, 0x4e000000,
  506. 0x28350, 0x3f3f3fff, 0x00000000,
  507. 0x30, 0x000000ff, 0x0040,
  508. 0x34, 0x00000040, 0x00004040,
  509. 0x9100, 0x03e00000, 0x03600000,
  510. 0x9060, 0x0000007f, 0x00000020,
  511. 0x9508, 0x00010000, 0x00010000,
  512. 0xac14, 0x000003ff, 0x000000f1,
  513. 0xac10, 0xffffffff, 0x00000000,
  514. 0xac0c, 0xffffffff, 0x00003210,
  515. 0x88d4, 0x0000001f, 0x00000010,
  516. 0x15c0, 0x000c0fc0, 0x000c0400
  517. };
  518. static const u32 hainan_golden_registers2[] =
  519. {
  520. 0x98f8, 0xffffffff, 0x02010001
  521. };
  522. static const u32 tahiti_mgcg_cgcg_init[] =
  523. {
  524. 0xc400, 0xffffffff, 0xfffffffc,
  525. 0x802c, 0xffffffff, 0xe0000000,
  526. 0x9a60, 0xffffffff, 0x00000100,
  527. 0x92a4, 0xffffffff, 0x00000100,
  528. 0xc164, 0xffffffff, 0x00000100,
  529. 0x9774, 0xffffffff, 0x00000100,
  530. 0x8984, 0xffffffff, 0x06000100,
  531. 0x8a18, 0xffffffff, 0x00000100,
  532. 0x92a0, 0xffffffff, 0x00000100,
  533. 0xc380, 0xffffffff, 0x00000100,
  534. 0x8b28, 0xffffffff, 0x00000100,
  535. 0x9144, 0xffffffff, 0x00000100,
  536. 0x8d88, 0xffffffff, 0x00000100,
  537. 0x8d8c, 0xffffffff, 0x00000100,
  538. 0x9030, 0xffffffff, 0x00000100,
  539. 0x9034, 0xffffffff, 0x00000100,
  540. 0x9038, 0xffffffff, 0x00000100,
  541. 0x903c, 0xffffffff, 0x00000100,
  542. 0xad80, 0xffffffff, 0x00000100,
  543. 0xac54, 0xffffffff, 0x00000100,
  544. 0x897c, 0xffffffff, 0x06000100,
  545. 0x9868, 0xffffffff, 0x00000100,
  546. 0x9510, 0xffffffff, 0x00000100,
  547. 0xaf04, 0xffffffff, 0x00000100,
  548. 0xae04, 0xffffffff, 0x00000100,
  549. 0x949c, 0xffffffff, 0x00000100,
  550. 0x802c, 0xffffffff, 0xe0000000,
  551. 0x9160, 0xffffffff, 0x00010000,
  552. 0x9164, 0xffffffff, 0x00030002,
  553. 0x9168, 0xffffffff, 0x00040007,
  554. 0x916c, 0xffffffff, 0x00060005,
  555. 0x9170, 0xffffffff, 0x00090008,
  556. 0x9174, 0xffffffff, 0x00020001,
  557. 0x9178, 0xffffffff, 0x00040003,
  558. 0x917c, 0xffffffff, 0x00000007,
  559. 0x9180, 0xffffffff, 0x00060005,
  560. 0x9184, 0xffffffff, 0x00090008,
  561. 0x9188, 0xffffffff, 0x00030002,
  562. 0x918c, 0xffffffff, 0x00050004,
  563. 0x9190, 0xffffffff, 0x00000008,
  564. 0x9194, 0xffffffff, 0x00070006,
  565. 0x9198, 0xffffffff, 0x000a0009,
  566. 0x919c, 0xffffffff, 0x00040003,
  567. 0x91a0, 0xffffffff, 0x00060005,
  568. 0x91a4, 0xffffffff, 0x00000009,
  569. 0x91a8, 0xffffffff, 0x00080007,
  570. 0x91ac, 0xffffffff, 0x000b000a,
  571. 0x91b0, 0xffffffff, 0x00050004,
  572. 0x91b4, 0xffffffff, 0x00070006,
  573. 0x91b8, 0xffffffff, 0x0008000b,
  574. 0x91bc, 0xffffffff, 0x000a0009,
  575. 0x91c0, 0xffffffff, 0x000d000c,
  576. 0x91c4, 0xffffffff, 0x00060005,
  577. 0x91c8, 0xffffffff, 0x00080007,
  578. 0x91cc, 0xffffffff, 0x0000000b,
  579. 0x91d0, 0xffffffff, 0x000a0009,
  580. 0x91d4, 0xffffffff, 0x000d000c,
  581. 0x91d8, 0xffffffff, 0x00070006,
  582. 0x91dc, 0xffffffff, 0x00090008,
  583. 0x91e0, 0xffffffff, 0x0000000c,
  584. 0x91e4, 0xffffffff, 0x000b000a,
  585. 0x91e8, 0xffffffff, 0x000e000d,
  586. 0x91ec, 0xffffffff, 0x00080007,
  587. 0x91f0, 0xffffffff, 0x000a0009,
  588. 0x91f4, 0xffffffff, 0x0000000d,
  589. 0x91f8, 0xffffffff, 0x000c000b,
  590. 0x91fc, 0xffffffff, 0x000f000e,
  591. 0x9200, 0xffffffff, 0x00090008,
  592. 0x9204, 0xffffffff, 0x000b000a,
  593. 0x9208, 0xffffffff, 0x000c000f,
  594. 0x920c, 0xffffffff, 0x000e000d,
  595. 0x9210, 0xffffffff, 0x00110010,
  596. 0x9214, 0xffffffff, 0x000a0009,
  597. 0x9218, 0xffffffff, 0x000c000b,
  598. 0x921c, 0xffffffff, 0x0000000f,
  599. 0x9220, 0xffffffff, 0x000e000d,
  600. 0x9224, 0xffffffff, 0x00110010,
  601. 0x9228, 0xffffffff, 0x000b000a,
  602. 0x922c, 0xffffffff, 0x000d000c,
  603. 0x9230, 0xffffffff, 0x00000010,
  604. 0x9234, 0xffffffff, 0x000f000e,
  605. 0x9238, 0xffffffff, 0x00120011,
  606. 0x923c, 0xffffffff, 0x000c000b,
  607. 0x9240, 0xffffffff, 0x000e000d,
  608. 0x9244, 0xffffffff, 0x00000011,
  609. 0x9248, 0xffffffff, 0x0010000f,
  610. 0x924c, 0xffffffff, 0x00130012,
  611. 0x9250, 0xffffffff, 0x000d000c,
  612. 0x9254, 0xffffffff, 0x000f000e,
  613. 0x9258, 0xffffffff, 0x00100013,
  614. 0x925c, 0xffffffff, 0x00120011,
  615. 0x9260, 0xffffffff, 0x00150014,
  616. 0x9264, 0xffffffff, 0x000e000d,
  617. 0x9268, 0xffffffff, 0x0010000f,
  618. 0x926c, 0xffffffff, 0x00000013,
  619. 0x9270, 0xffffffff, 0x00120011,
  620. 0x9274, 0xffffffff, 0x00150014,
  621. 0x9278, 0xffffffff, 0x000f000e,
  622. 0x927c, 0xffffffff, 0x00110010,
  623. 0x9280, 0xffffffff, 0x00000014,
  624. 0x9284, 0xffffffff, 0x00130012,
  625. 0x9288, 0xffffffff, 0x00160015,
  626. 0x928c, 0xffffffff, 0x0010000f,
  627. 0x9290, 0xffffffff, 0x00120011,
  628. 0x9294, 0xffffffff, 0x00000015,
  629. 0x9298, 0xffffffff, 0x00140013,
  630. 0x929c, 0xffffffff, 0x00170016,
  631. 0x9150, 0xffffffff, 0x96940200,
  632. 0x8708, 0xffffffff, 0x00900100,
  633. 0xc478, 0xffffffff, 0x00000080,
  634. 0xc404, 0xffffffff, 0x0020003f,
  635. 0x30, 0xffffffff, 0x0000001c,
  636. 0x34, 0x000f0000, 0x000f0000,
  637. 0x160c, 0xffffffff, 0x00000100,
  638. 0x1024, 0xffffffff, 0x00000100,
  639. 0x102c, 0x00000101, 0x00000000,
  640. 0x20a8, 0xffffffff, 0x00000104,
  641. 0x264c, 0x000c0000, 0x000c0000,
  642. 0x2648, 0x000c0000, 0x000c0000,
  643. 0x55e4, 0xff000fff, 0x00000100,
  644. 0x55e8, 0x00000001, 0x00000001,
  645. 0x2f50, 0x00000001, 0x00000001,
  646. 0x30cc, 0xc0000fff, 0x00000104,
  647. 0xc1e4, 0x00000001, 0x00000001,
  648. 0xd0c0, 0xfffffff0, 0x00000100,
  649. 0xd8c0, 0xfffffff0, 0x00000100
  650. };
  651. static const u32 pitcairn_mgcg_cgcg_init[] =
  652. {
  653. 0xc400, 0xffffffff, 0xfffffffc,
  654. 0x802c, 0xffffffff, 0xe0000000,
  655. 0x9a60, 0xffffffff, 0x00000100,
  656. 0x92a4, 0xffffffff, 0x00000100,
  657. 0xc164, 0xffffffff, 0x00000100,
  658. 0x9774, 0xffffffff, 0x00000100,
  659. 0x8984, 0xffffffff, 0x06000100,
  660. 0x8a18, 0xffffffff, 0x00000100,
  661. 0x92a0, 0xffffffff, 0x00000100,
  662. 0xc380, 0xffffffff, 0x00000100,
  663. 0x8b28, 0xffffffff, 0x00000100,
  664. 0x9144, 0xffffffff, 0x00000100,
  665. 0x8d88, 0xffffffff, 0x00000100,
  666. 0x8d8c, 0xffffffff, 0x00000100,
  667. 0x9030, 0xffffffff, 0x00000100,
  668. 0x9034, 0xffffffff, 0x00000100,
  669. 0x9038, 0xffffffff, 0x00000100,
  670. 0x903c, 0xffffffff, 0x00000100,
  671. 0xad80, 0xffffffff, 0x00000100,
  672. 0xac54, 0xffffffff, 0x00000100,
  673. 0x897c, 0xffffffff, 0x06000100,
  674. 0x9868, 0xffffffff, 0x00000100,
  675. 0x9510, 0xffffffff, 0x00000100,
  676. 0xaf04, 0xffffffff, 0x00000100,
  677. 0xae04, 0xffffffff, 0x00000100,
  678. 0x949c, 0xffffffff, 0x00000100,
  679. 0x802c, 0xffffffff, 0xe0000000,
  680. 0x9160, 0xffffffff, 0x00010000,
  681. 0x9164, 0xffffffff, 0x00030002,
  682. 0x9168, 0xffffffff, 0x00040007,
  683. 0x916c, 0xffffffff, 0x00060005,
  684. 0x9170, 0xffffffff, 0x00090008,
  685. 0x9174, 0xffffffff, 0x00020001,
  686. 0x9178, 0xffffffff, 0x00040003,
  687. 0x917c, 0xffffffff, 0x00000007,
  688. 0x9180, 0xffffffff, 0x00060005,
  689. 0x9184, 0xffffffff, 0x00090008,
  690. 0x9188, 0xffffffff, 0x00030002,
  691. 0x918c, 0xffffffff, 0x00050004,
  692. 0x9190, 0xffffffff, 0x00000008,
  693. 0x9194, 0xffffffff, 0x00070006,
  694. 0x9198, 0xffffffff, 0x000a0009,
  695. 0x919c, 0xffffffff, 0x00040003,
  696. 0x91a0, 0xffffffff, 0x00060005,
  697. 0x91a4, 0xffffffff, 0x00000009,
  698. 0x91a8, 0xffffffff, 0x00080007,
  699. 0x91ac, 0xffffffff, 0x000b000a,
  700. 0x91b0, 0xffffffff, 0x00050004,
  701. 0x91b4, 0xffffffff, 0x00070006,
  702. 0x91b8, 0xffffffff, 0x0008000b,
  703. 0x91bc, 0xffffffff, 0x000a0009,
  704. 0x91c0, 0xffffffff, 0x000d000c,
  705. 0x9200, 0xffffffff, 0x00090008,
  706. 0x9204, 0xffffffff, 0x000b000a,
  707. 0x9208, 0xffffffff, 0x000c000f,
  708. 0x920c, 0xffffffff, 0x000e000d,
  709. 0x9210, 0xffffffff, 0x00110010,
  710. 0x9214, 0xffffffff, 0x000a0009,
  711. 0x9218, 0xffffffff, 0x000c000b,
  712. 0x921c, 0xffffffff, 0x0000000f,
  713. 0x9220, 0xffffffff, 0x000e000d,
  714. 0x9224, 0xffffffff, 0x00110010,
  715. 0x9228, 0xffffffff, 0x000b000a,
  716. 0x922c, 0xffffffff, 0x000d000c,
  717. 0x9230, 0xffffffff, 0x00000010,
  718. 0x9234, 0xffffffff, 0x000f000e,
  719. 0x9238, 0xffffffff, 0x00120011,
  720. 0x923c, 0xffffffff, 0x000c000b,
  721. 0x9240, 0xffffffff, 0x000e000d,
  722. 0x9244, 0xffffffff, 0x00000011,
  723. 0x9248, 0xffffffff, 0x0010000f,
  724. 0x924c, 0xffffffff, 0x00130012,
  725. 0x9250, 0xffffffff, 0x000d000c,
  726. 0x9254, 0xffffffff, 0x000f000e,
  727. 0x9258, 0xffffffff, 0x00100013,
  728. 0x925c, 0xffffffff, 0x00120011,
  729. 0x9260, 0xffffffff, 0x00150014,
  730. 0x9150, 0xffffffff, 0x96940200,
  731. 0x8708, 0xffffffff, 0x00900100,
  732. 0xc478, 0xffffffff, 0x00000080,
  733. 0xc404, 0xffffffff, 0x0020003f,
  734. 0x30, 0xffffffff, 0x0000001c,
  735. 0x34, 0x000f0000, 0x000f0000,
  736. 0x160c, 0xffffffff, 0x00000100,
  737. 0x1024, 0xffffffff, 0x00000100,
  738. 0x102c, 0x00000101, 0x00000000,
  739. 0x20a8, 0xffffffff, 0x00000104,
  740. 0x55e4, 0xff000fff, 0x00000100,
  741. 0x55e8, 0x00000001, 0x00000001,
  742. 0x2f50, 0x00000001, 0x00000001,
  743. 0x30cc, 0xc0000fff, 0x00000104,
  744. 0xc1e4, 0x00000001, 0x00000001,
  745. 0xd0c0, 0xfffffff0, 0x00000100,
  746. 0xd8c0, 0xfffffff0, 0x00000100
  747. };
  748. static const u32 verde_mgcg_cgcg_init[] =
  749. {
  750. 0xc400, 0xffffffff, 0xfffffffc,
  751. 0x802c, 0xffffffff, 0xe0000000,
  752. 0x9a60, 0xffffffff, 0x00000100,
  753. 0x92a4, 0xffffffff, 0x00000100,
  754. 0xc164, 0xffffffff, 0x00000100,
  755. 0x9774, 0xffffffff, 0x00000100,
  756. 0x8984, 0xffffffff, 0x06000100,
  757. 0x8a18, 0xffffffff, 0x00000100,
  758. 0x92a0, 0xffffffff, 0x00000100,
  759. 0xc380, 0xffffffff, 0x00000100,
  760. 0x8b28, 0xffffffff, 0x00000100,
  761. 0x9144, 0xffffffff, 0x00000100,
  762. 0x8d88, 0xffffffff, 0x00000100,
  763. 0x8d8c, 0xffffffff, 0x00000100,
  764. 0x9030, 0xffffffff, 0x00000100,
  765. 0x9034, 0xffffffff, 0x00000100,
  766. 0x9038, 0xffffffff, 0x00000100,
  767. 0x903c, 0xffffffff, 0x00000100,
  768. 0xad80, 0xffffffff, 0x00000100,
  769. 0xac54, 0xffffffff, 0x00000100,
  770. 0x897c, 0xffffffff, 0x06000100,
  771. 0x9868, 0xffffffff, 0x00000100,
  772. 0x9510, 0xffffffff, 0x00000100,
  773. 0xaf04, 0xffffffff, 0x00000100,
  774. 0xae04, 0xffffffff, 0x00000100,
  775. 0x949c, 0xffffffff, 0x00000100,
  776. 0x802c, 0xffffffff, 0xe0000000,
  777. 0x9160, 0xffffffff, 0x00010000,
  778. 0x9164, 0xffffffff, 0x00030002,
  779. 0x9168, 0xffffffff, 0x00040007,
  780. 0x916c, 0xffffffff, 0x00060005,
  781. 0x9170, 0xffffffff, 0x00090008,
  782. 0x9174, 0xffffffff, 0x00020001,
  783. 0x9178, 0xffffffff, 0x00040003,
  784. 0x917c, 0xffffffff, 0x00000007,
  785. 0x9180, 0xffffffff, 0x00060005,
  786. 0x9184, 0xffffffff, 0x00090008,
  787. 0x9188, 0xffffffff, 0x00030002,
  788. 0x918c, 0xffffffff, 0x00050004,
  789. 0x9190, 0xffffffff, 0x00000008,
  790. 0x9194, 0xffffffff, 0x00070006,
  791. 0x9198, 0xffffffff, 0x000a0009,
  792. 0x919c, 0xffffffff, 0x00040003,
  793. 0x91a0, 0xffffffff, 0x00060005,
  794. 0x91a4, 0xffffffff, 0x00000009,
  795. 0x91a8, 0xffffffff, 0x00080007,
  796. 0x91ac, 0xffffffff, 0x000b000a,
  797. 0x91b0, 0xffffffff, 0x00050004,
  798. 0x91b4, 0xffffffff, 0x00070006,
  799. 0x91b8, 0xffffffff, 0x0008000b,
  800. 0x91bc, 0xffffffff, 0x000a0009,
  801. 0x91c0, 0xffffffff, 0x000d000c,
  802. 0x9200, 0xffffffff, 0x00090008,
  803. 0x9204, 0xffffffff, 0x000b000a,
  804. 0x9208, 0xffffffff, 0x000c000f,
  805. 0x920c, 0xffffffff, 0x000e000d,
  806. 0x9210, 0xffffffff, 0x00110010,
  807. 0x9214, 0xffffffff, 0x000a0009,
  808. 0x9218, 0xffffffff, 0x000c000b,
  809. 0x921c, 0xffffffff, 0x0000000f,
  810. 0x9220, 0xffffffff, 0x000e000d,
  811. 0x9224, 0xffffffff, 0x00110010,
  812. 0x9228, 0xffffffff, 0x000b000a,
  813. 0x922c, 0xffffffff, 0x000d000c,
  814. 0x9230, 0xffffffff, 0x00000010,
  815. 0x9234, 0xffffffff, 0x000f000e,
  816. 0x9238, 0xffffffff, 0x00120011,
  817. 0x923c, 0xffffffff, 0x000c000b,
  818. 0x9240, 0xffffffff, 0x000e000d,
  819. 0x9244, 0xffffffff, 0x00000011,
  820. 0x9248, 0xffffffff, 0x0010000f,
  821. 0x924c, 0xffffffff, 0x00130012,
  822. 0x9250, 0xffffffff, 0x000d000c,
  823. 0x9254, 0xffffffff, 0x000f000e,
  824. 0x9258, 0xffffffff, 0x00100013,
  825. 0x925c, 0xffffffff, 0x00120011,
  826. 0x9260, 0xffffffff, 0x00150014,
  827. 0x9150, 0xffffffff, 0x96940200,
  828. 0x8708, 0xffffffff, 0x00900100,
  829. 0xc478, 0xffffffff, 0x00000080,
  830. 0xc404, 0xffffffff, 0x0020003f,
  831. 0x30, 0xffffffff, 0x0000001c,
  832. 0x34, 0x000f0000, 0x000f0000,
  833. 0x160c, 0xffffffff, 0x00000100,
  834. 0x1024, 0xffffffff, 0x00000100,
  835. 0x102c, 0x00000101, 0x00000000,
  836. 0x20a8, 0xffffffff, 0x00000104,
  837. 0x264c, 0x000c0000, 0x000c0000,
  838. 0x2648, 0x000c0000, 0x000c0000,
  839. 0x55e4, 0xff000fff, 0x00000100,
  840. 0x55e8, 0x00000001, 0x00000001,
  841. 0x2f50, 0x00000001, 0x00000001,
  842. 0x30cc, 0xc0000fff, 0x00000104,
  843. 0xc1e4, 0x00000001, 0x00000001,
  844. 0xd0c0, 0xfffffff0, 0x00000100,
  845. 0xd8c0, 0xfffffff0, 0x00000100
  846. };
  847. static const u32 oland_mgcg_cgcg_init[] =
  848. {
  849. 0xc400, 0xffffffff, 0xfffffffc,
  850. 0x802c, 0xffffffff, 0xe0000000,
  851. 0x9a60, 0xffffffff, 0x00000100,
  852. 0x92a4, 0xffffffff, 0x00000100,
  853. 0xc164, 0xffffffff, 0x00000100,
  854. 0x9774, 0xffffffff, 0x00000100,
  855. 0x8984, 0xffffffff, 0x06000100,
  856. 0x8a18, 0xffffffff, 0x00000100,
  857. 0x92a0, 0xffffffff, 0x00000100,
  858. 0xc380, 0xffffffff, 0x00000100,
  859. 0x8b28, 0xffffffff, 0x00000100,
  860. 0x9144, 0xffffffff, 0x00000100,
  861. 0x8d88, 0xffffffff, 0x00000100,
  862. 0x8d8c, 0xffffffff, 0x00000100,
  863. 0x9030, 0xffffffff, 0x00000100,
  864. 0x9034, 0xffffffff, 0x00000100,
  865. 0x9038, 0xffffffff, 0x00000100,
  866. 0x903c, 0xffffffff, 0x00000100,
  867. 0xad80, 0xffffffff, 0x00000100,
  868. 0xac54, 0xffffffff, 0x00000100,
  869. 0x897c, 0xffffffff, 0x06000100,
  870. 0x9868, 0xffffffff, 0x00000100,
  871. 0x9510, 0xffffffff, 0x00000100,
  872. 0xaf04, 0xffffffff, 0x00000100,
  873. 0xae04, 0xffffffff, 0x00000100,
  874. 0x949c, 0xffffffff, 0x00000100,
  875. 0x802c, 0xffffffff, 0xe0000000,
  876. 0x9160, 0xffffffff, 0x00010000,
  877. 0x9164, 0xffffffff, 0x00030002,
  878. 0x9168, 0xffffffff, 0x00040007,
  879. 0x916c, 0xffffffff, 0x00060005,
  880. 0x9170, 0xffffffff, 0x00090008,
  881. 0x9174, 0xffffffff, 0x00020001,
  882. 0x9178, 0xffffffff, 0x00040003,
  883. 0x917c, 0xffffffff, 0x00000007,
  884. 0x9180, 0xffffffff, 0x00060005,
  885. 0x9184, 0xffffffff, 0x00090008,
  886. 0x9188, 0xffffffff, 0x00030002,
  887. 0x918c, 0xffffffff, 0x00050004,
  888. 0x9190, 0xffffffff, 0x00000008,
  889. 0x9194, 0xffffffff, 0x00070006,
  890. 0x9198, 0xffffffff, 0x000a0009,
  891. 0x919c, 0xffffffff, 0x00040003,
  892. 0x91a0, 0xffffffff, 0x00060005,
  893. 0x91a4, 0xffffffff, 0x00000009,
  894. 0x91a8, 0xffffffff, 0x00080007,
  895. 0x91ac, 0xffffffff, 0x000b000a,
  896. 0x91b0, 0xffffffff, 0x00050004,
  897. 0x91b4, 0xffffffff, 0x00070006,
  898. 0x91b8, 0xffffffff, 0x0008000b,
  899. 0x91bc, 0xffffffff, 0x000a0009,
  900. 0x91c0, 0xffffffff, 0x000d000c,
  901. 0x91c4, 0xffffffff, 0x00060005,
  902. 0x91c8, 0xffffffff, 0x00080007,
  903. 0x91cc, 0xffffffff, 0x0000000b,
  904. 0x91d0, 0xffffffff, 0x000a0009,
  905. 0x91d4, 0xffffffff, 0x000d000c,
  906. 0x9150, 0xffffffff, 0x96940200,
  907. 0x8708, 0xffffffff, 0x00900100,
  908. 0xc478, 0xffffffff, 0x00000080,
  909. 0xc404, 0xffffffff, 0x0020003f,
  910. 0x30, 0xffffffff, 0x0000001c,
  911. 0x34, 0x000f0000, 0x000f0000,
  912. 0x160c, 0xffffffff, 0x00000100,
  913. 0x1024, 0xffffffff, 0x00000100,
  914. 0x102c, 0x00000101, 0x00000000,
  915. 0x20a8, 0xffffffff, 0x00000104,
  916. 0x264c, 0x000c0000, 0x000c0000,
  917. 0x2648, 0x000c0000, 0x000c0000,
  918. 0x55e4, 0xff000fff, 0x00000100,
  919. 0x55e8, 0x00000001, 0x00000001,
  920. 0x2f50, 0x00000001, 0x00000001,
  921. 0x30cc, 0xc0000fff, 0x00000104,
  922. 0xc1e4, 0x00000001, 0x00000001,
  923. 0xd0c0, 0xfffffff0, 0x00000100,
  924. 0xd8c0, 0xfffffff0, 0x00000100
  925. };
  926. static const u32 hainan_mgcg_cgcg_init[] =
  927. {
  928. 0xc400, 0xffffffff, 0xfffffffc,
  929. 0x802c, 0xffffffff, 0xe0000000,
  930. 0x9a60, 0xffffffff, 0x00000100,
  931. 0x92a4, 0xffffffff, 0x00000100,
  932. 0xc164, 0xffffffff, 0x00000100,
  933. 0x9774, 0xffffffff, 0x00000100,
  934. 0x8984, 0xffffffff, 0x06000100,
  935. 0x8a18, 0xffffffff, 0x00000100,
  936. 0x92a0, 0xffffffff, 0x00000100,
  937. 0xc380, 0xffffffff, 0x00000100,
  938. 0x8b28, 0xffffffff, 0x00000100,
  939. 0x9144, 0xffffffff, 0x00000100,
  940. 0x8d88, 0xffffffff, 0x00000100,
  941. 0x8d8c, 0xffffffff, 0x00000100,
  942. 0x9030, 0xffffffff, 0x00000100,
  943. 0x9034, 0xffffffff, 0x00000100,
  944. 0x9038, 0xffffffff, 0x00000100,
  945. 0x903c, 0xffffffff, 0x00000100,
  946. 0xad80, 0xffffffff, 0x00000100,
  947. 0xac54, 0xffffffff, 0x00000100,
  948. 0x897c, 0xffffffff, 0x06000100,
  949. 0x9868, 0xffffffff, 0x00000100,
  950. 0x9510, 0xffffffff, 0x00000100,
  951. 0xaf04, 0xffffffff, 0x00000100,
  952. 0xae04, 0xffffffff, 0x00000100,
  953. 0x949c, 0xffffffff, 0x00000100,
  954. 0x802c, 0xffffffff, 0xe0000000,
  955. 0x9160, 0xffffffff, 0x00010000,
  956. 0x9164, 0xffffffff, 0x00030002,
  957. 0x9168, 0xffffffff, 0x00040007,
  958. 0x916c, 0xffffffff, 0x00060005,
  959. 0x9170, 0xffffffff, 0x00090008,
  960. 0x9174, 0xffffffff, 0x00020001,
  961. 0x9178, 0xffffffff, 0x00040003,
  962. 0x917c, 0xffffffff, 0x00000007,
  963. 0x9180, 0xffffffff, 0x00060005,
  964. 0x9184, 0xffffffff, 0x00090008,
  965. 0x9188, 0xffffffff, 0x00030002,
  966. 0x918c, 0xffffffff, 0x00050004,
  967. 0x9190, 0xffffffff, 0x00000008,
  968. 0x9194, 0xffffffff, 0x00070006,
  969. 0x9198, 0xffffffff, 0x000a0009,
  970. 0x919c, 0xffffffff, 0x00040003,
  971. 0x91a0, 0xffffffff, 0x00060005,
  972. 0x91a4, 0xffffffff, 0x00000009,
  973. 0x91a8, 0xffffffff, 0x00080007,
  974. 0x91ac, 0xffffffff, 0x000b000a,
  975. 0x91b0, 0xffffffff, 0x00050004,
  976. 0x91b4, 0xffffffff, 0x00070006,
  977. 0x91b8, 0xffffffff, 0x0008000b,
  978. 0x91bc, 0xffffffff, 0x000a0009,
  979. 0x91c0, 0xffffffff, 0x000d000c,
  980. 0x91c4, 0xffffffff, 0x00060005,
  981. 0x91c8, 0xffffffff, 0x00080007,
  982. 0x91cc, 0xffffffff, 0x0000000b,
  983. 0x91d0, 0xffffffff, 0x000a0009,
  984. 0x91d4, 0xffffffff, 0x000d000c,
  985. 0x9150, 0xffffffff, 0x96940200,
  986. 0x8708, 0xffffffff, 0x00900100,
  987. 0xc478, 0xffffffff, 0x00000080,
  988. 0xc404, 0xffffffff, 0x0020003f,
  989. 0x30, 0xffffffff, 0x0000001c,
  990. 0x34, 0x000f0000, 0x000f0000,
  991. 0x160c, 0xffffffff, 0x00000100,
  992. 0x1024, 0xffffffff, 0x00000100,
  993. 0x20a8, 0xffffffff, 0x00000104,
  994. 0x264c, 0x000c0000, 0x000c0000,
  995. 0x2648, 0x000c0000, 0x000c0000,
  996. 0x2f50, 0x00000001, 0x00000001,
  997. 0x30cc, 0xc0000fff, 0x00000104,
  998. 0xc1e4, 0x00000001, 0x00000001,
  999. 0xd0c0, 0xfffffff0, 0x00000100,
  1000. 0xd8c0, 0xfffffff0, 0x00000100
  1001. };
  1002. static u32 verde_pg_init[] =
  1003. {
  1004. 0x353c, 0xffffffff, 0x40000,
  1005. 0x3538, 0xffffffff, 0x200010ff,
  1006. 0x353c, 0xffffffff, 0x0,
  1007. 0x353c, 0xffffffff, 0x0,
  1008. 0x353c, 0xffffffff, 0x0,
  1009. 0x353c, 0xffffffff, 0x0,
  1010. 0x353c, 0xffffffff, 0x0,
  1011. 0x353c, 0xffffffff, 0x7007,
  1012. 0x3538, 0xffffffff, 0x300010ff,
  1013. 0x353c, 0xffffffff, 0x0,
  1014. 0x353c, 0xffffffff, 0x0,
  1015. 0x353c, 0xffffffff, 0x0,
  1016. 0x353c, 0xffffffff, 0x0,
  1017. 0x353c, 0xffffffff, 0x0,
  1018. 0x353c, 0xffffffff, 0x400000,
  1019. 0x3538, 0xffffffff, 0x100010ff,
  1020. 0x353c, 0xffffffff, 0x0,
  1021. 0x353c, 0xffffffff, 0x0,
  1022. 0x353c, 0xffffffff, 0x0,
  1023. 0x353c, 0xffffffff, 0x0,
  1024. 0x353c, 0xffffffff, 0x0,
  1025. 0x353c, 0xffffffff, 0x120200,
  1026. 0x3538, 0xffffffff, 0x500010ff,
  1027. 0x353c, 0xffffffff, 0x0,
  1028. 0x353c, 0xffffffff, 0x0,
  1029. 0x353c, 0xffffffff, 0x0,
  1030. 0x353c, 0xffffffff, 0x0,
  1031. 0x353c, 0xffffffff, 0x0,
  1032. 0x353c, 0xffffffff, 0x1e1e16,
  1033. 0x3538, 0xffffffff, 0x600010ff,
  1034. 0x353c, 0xffffffff, 0x0,
  1035. 0x353c, 0xffffffff, 0x0,
  1036. 0x353c, 0xffffffff, 0x0,
  1037. 0x353c, 0xffffffff, 0x0,
  1038. 0x353c, 0xffffffff, 0x0,
  1039. 0x353c, 0xffffffff, 0x171f1e,
  1040. 0x3538, 0xffffffff, 0x700010ff,
  1041. 0x353c, 0xffffffff, 0x0,
  1042. 0x353c, 0xffffffff, 0x0,
  1043. 0x353c, 0xffffffff, 0x0,
  1044. 0x353c, 0xffffffff, 0x0,
  1045. 0x353c, 0xffffffff, 0x0,
  1046. 0x353c, 0xffffffff, 0x0,
  1047. 0x3538, 0xffffffff, 0x9ff,
  1048. 0x3500, 0xffffffff, 0x0,
  1049. 0x3504, 0xffffffff, 0x10000800,
  1050. 0x3504, 0xffffffff, 0xf,
  1051. 0x3504, 0xffffffff, 0xf,
  1052. 0x3500, 0xffffffff, 0x4,
  1053. 0x3504, 0xffffffff, 0x1000051e,
  1054. 0x3504, 0xffffffff, 0xffff,
  1055. 0x3504, 0xffffffff, 0xffff,
  1056. 0x3500, 0xffffffff, 0x8,
  1057. 0x3504, 0xffffffff, 0x80500,
  1058. 0x3500, 0xffffffff, 0x12,
  1059. 0x3504, 0xffffffff, 0x9050c,
  1060. 0x3500, 0xffffffff, 0x1d,
  1061. 0x3504, 0xffffffff, 0xb052c,
  1062. 0x3500, 0xffffffff, 0x2a,
  1063. 0x3504, 0xffffffff, 0x1053e,
  1064. 0x3500, 0xffffffff, 0x2d,
  1065. 0x3504, 0xffffffff, 0x10546,
  1066. 0x3500, 0xffffffff, 0x30,
  1067. 0x3504, 0xffffffff, 0xa054e,
  1068. 0x3500, 0xffffffff, 0x3c,
  1069. 0x3504, 0xffffffff, 0x1055f,
  1070. 0x3500, 0xffffffff, 0x3f,
  1071. 0x3504, 0xffffffff, 0x10567,
  1072. 0x3500, 0xffffffff, 0x42,
  1073. 0x3504, 0xffffffff, 0x1056f,
  1074. 0x3500, 0xffffffff, 0x45,
  1075. 0x3504, 0xffffffff, 0x10572,
  1076. 0x3500, 0xffffffff, 0x48,
  1077. 0x3504, 0xffffffff, 0x20575,
  1078. 0x3500, 0xffffffff, 0x4c,
  1079. 0x3504, 0xffffffff, 0x190801,
  1080. 0x3500, 0xffffffff, 0x67,
  1081. 0x3504, 0xffffffff, 0x1082a,
  1082. 0x3500, 0xffffffff, 0x6a,
  1083. 0x3504, 0xffffffff, 0x1b082d,
  1084. 0x3500, 0xffffffff, 0x87,
  1085. 0x3504, 0xffffffff, 0x310851,
  1086. 0x3500, 0xffffffff, 0xba,
  1087. 0x3504, 0xffffffff, 0x891,
  1088. 0x3500, 0xffffffff, 0xbc,
  1089. 0x3504, 0xffffffff, 0x893,
  1090. 0x3500, 0xffffffff, 0xbe,
  1091. 0x3504, 0xffffffff, 0x20895,
  1092. 0x3500, 0xffffffff, 0xc2,
  1093. 0x3504, 0xffffffff, 0x20899,
  1094. 0x3500, 0xffffffff, 0xc6,
  1095. 0x3504, 0xffffffff, 0x2089d,
  1096. 0x3500, 0xffffffff, 0xca,
  1097. 0x3504, 0xffffffff, 0x8a1,
  1098. 0x3500, 0xffffffff, 0xcc,
  1099. 0x3504, 0xffffffff, 0x8a3,
  1100. 0x3500, 0xffffffff, 0xce,
  1101. 0x3504, 0xffffffff, 0x308a5,
  1102. 0x3500, 0xffffffff, 0xd3,
  1103. 0x3504, 0xffffffff, 0x6d08cd,
  1104. 0x3500, 0xffffffff, 0x142,
  1105. 0x3504, 0xffffffff, 0x2000095a,
  1106. 0x3504, 0xffffffff, 0x1,
  1107. 0x3500, 0xffffffff, 0x144,
  1108. 0x3504, 0xffffffff, 0x301f095b,
  1109. 0x3500, 0xffffffff, 0x165,
  1110. 0x3504, 0xffffffff, 0xc094d,
  1111. 0x3500, 0xffffffff, 0x173,
  1112. 0x3504, 0xffffffff, 0xf096d,
  1113. 0x3500, 0xffffffff, 0x184,
  1114. 0x3504, 0xffffffff, 0x15097f,
  1115. 0x3500, 0xffffffff, 0x19b,
  1116. 0x3504, 0xffffffff, 0xc0998,
  1117. 0x3500, 0xffffffff, 0x1a9,
  1118. 0x3504, 0xffffffff, 0x409a7,
  1119. 0x3500, 0xffffffff, 0x1af,
  1120. 0x3504, 0xffffffff, 0xcdc,
  1121. 0x3500, 0xffffffff, 0x1b1,
  1122. 0x3504, 0xffffffff, 0x800,
  1123. 0x3508, 0xffffffff, 0x6c9b2000,
  1124. 0x3510, 0xfc00, 0x2000,
  1125. 0x3544, 0xffffffff, 0xfc0,
  1126. 0x28d4, 0x00000100, 0x100
  1127. };
  1128. static void si_init_golden_registers(struct radeon_device *rdev)
  1129. {
  1130. switch (rdev->family) {
  1131. case CHIP_TAHITI:
  1132. radeon_program_register_sequence(rdev,
  1133. tahiti_golden_registers,
  1134. (const u32)ARRAY_SIZE(tahiti_golden_registers));
  1135. radeon_program_register_sequence(rdev,
  1136. tahiti_golden_rlc_registers,
  1137. (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
  1138. radeon_program_register_sequence(rdev,
  1139. tahiti_mgcg_cgcg_init,
  1140. (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
  1141. radeon_program_register_sequence(rdev,
  1142. tahiti_golden_registers2,
  1143. (const u32)ARRAY_SIZE(tahiti_golden_registers2));
  1144. break;
  1145. case CHIP_PITCAIRN:
  1146. radeon_program_register_sequence(rdev,
  1147. pitcairn_golden_registers,
  1148. (const u32)ARRAY_SIZE(pitcairn_golden_registers));
  1149. radeon_program_register_sequence(rdev,
  1150. pitcairn_golden_rlc_registers,
  1151. (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
  1152. radeon_program_register_sequence(rdev,
  1153. pitcairn_mgcg_cgcg_init,
  1154. (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
  1155. break;
  1156. case CHIP_VERDE:
  1157. radeon_program_register_sequence(rdev,
  1158. verde_golden_registers,
  1159. (const u32)ARRAY_SIZE(verde_golden_registers));
  1160. radeon_program_register_sequence(rdev,
  1161. verde_golden_rlc_registers,
  1162. (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
  1163. radeon_program_register_sequence(rdev,
  1164. verde_mgcg_cgcg_init,
  1165. (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
  1166. radeon_program_register_sequence(rdev,
  1167. verde_pg_init,
  1168. (const u32)ARRAY_SIZE(verde_pg_init));
  1169. break;
  1170. case CHIP_OLAND:
  1171. radeon_program_register_sequence(rdev,
  1172. oland_golden_registers,
  1173. (const u32)ARRAY_SIZE(oland_golden_registers));
  1174. radeon_program_register_sequence(rdev,
  1175. oland_golden_rlc_registers,
  1176. (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
  1177. radeon_program_register_sequence(rdev,
  1178. oland_mgcg_cgcg_init,
  1179. (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
  1180. break;
  1181. case CHIP_HAINAN:
  1182. radeon_program_register_sequence(rdev,
  1183. hainan_golden_registers,
  1184. (const u32)ARRAY_SIZE(hainan_golden_registers));
  1185. radeon_program_register_sequence(rdev,
  1186. hainan_golden_registers2,
  1187. (const u32)ARRAY_SIZE(hainan_golden_registers2));
  1188. radeon_program_register_sequence(rdev,
  1189. hainan_mgcg_cgcg_init,
  1190. (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
  1191. break;
  1192. default:
  1193. break;
  1194. }
  1195. }
  1196. #define PCIE_BUS_CLK 10000
  1197. #define TCLK (PCIE_BUS_CLK / 10)
  1198. /**
  1199. * si_get_xclk - get the xclk
  1200. *
  1201. * @rdev: radeon_device pointer
  1202. *
  1203. * Returns the reference clock used by the gfx engine
  1204. * (SI).
  1205. */
  1206. u32 si_get_xclk(struct radeon_device *rdev)
  1207. {
  1208. u32 reference_clock = rdev->clock.spll.reference_freq;
  1209. u32 tmp;
  1210. tmp = RREG32(CG_CLKPIN_CNTL_2);
  1211. if (tmp & MUX_TCLK_TO_XCLK)
  1212. return TCLK;
  1213. tmp = RREG32(CG_CLKPIN_CNTL);
  1214. if (tmp & XTALIN_DIVIDE)
  1215. return reference_clock / 4;
  1216. return reference_clock;
  1217. }
  1218. /* get temperature in millidegrees */
  1219. int si_get_temp(struct radeon_device *rdev)
  1220. {
  1221. u32 temp;
  1222. int actual_temp = 0;
  1223. temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  1224. CTF_TEMP_SHIFT;
  1225. if (temp & 0x200)
  1226. actual_temp = 255;
  1227. else
  1228. actual_temp = temp & 0x1ff;
  1229. actual_temp = (actual_temp * 1000);
  1230. return actual_temp;
  1231. }
  1232. #define TAHITI_IO_MC_REGS_SIZE 36
  1233. static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1234. {0x0000006f, 0x03044000},
  1235. {0x00000070, 0x0480c018},
  1236. {0x00000071, 0x00000040},
  1237. {0x00000072, 0x01000000},
  1238. {0x00000074, 0x000000ff},
  1239. {0x00000075, 0x00143400},
  1240. {0x00000076, 0x08ec0800},
  1241. {0x00000077, 0x040000cc},
  1242. {0x00000079, 0x00000000},
  1243. {0x0000007a, 0x21000409},
  1244. {0x0000007c, 0x00000000},
  1245. {0x0000007d, 0xe8000000},
  1246. {0x0000007e, 0x044408a8},
  1247. {0x0000007f, 0x00000003},
  1248. {0x00000080, 0x00000000},
  1249. {0x00000081, 0x01000000},
  1250. {0x00000082, 0x02000000},
  1251. {0x00000083, 0x00000000},
  1252. {0x00000084, 0xe3f3e4f4},
  1253. {0x00000085, 0x00052024},
  1254. {0x00000087, 0x00000000},
  1255. {0x00000088, 0x66036603},
  1256. {0x00000089, 0x01000000},
  1257. {0x0000008b, 0x1c0a0000},
  1258. {0x0000008c, 0xff010000},
  1259. {0x0000008e, 0xffffefff},
  1260. {0x0000008f, 0xfff3efff},
  1261. {0x00000090, 0xfff3efbf},
  1262. {0x00000094, 0x00101101},
  1263. {0x00000095, 0x00000fff},
  1264. {0x00000096, 0x00116fff},
  1265. {0x00000097, 0x60010000},
  1266. {0x00000098, 0x10010000},
  1267. {0x00000099, 0x00006000},
  1268. {0x0000009a, 0x00001000},
  1269. {0x0000009f, 0x00a77400}
  1270. };
  1271. static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1272. {0x0000006f, 0x03044000},
  1273. {0x00000070, 0x0480c018},
  1274. {0x00000071, 0x00000040},
  1275. {0x00000072, 0x01000000},
  1276. {0x00000074, 0x000000ff},
  1277. {0x00000075, 0x00143400},
  1278. {0x00000076, 0x08ec0800},
  1279. {0x00000077, 0x040000cc},
  1280. {0x00000079, 0x00000000},
  1281. {0x0000007a, 0x21000409},
  1282. {0x0000007c, 0x00000000},
  1283. {0x0000007d, 0xe8000000},
  1284. {0x0000007e, 0x044408a8},
  1285. {0x0000007f, 0x00000003},
  1286. {0x00000080, 0x00000000},
  1287. {0x00000081, 0x01000000},
  1288. {0x00000082, 0x02000000},
  1289. {0x00000083, 0x00000000},
  1290. {0x00000084, 0xe3f3e4f4},
  1291. {0x00000085, 0x00052024},
  1292. {0x00000087, 0x00000000},
  1293. {0x00000088, 0x66036603},
  1294. {0x00000089, 0x01000000},
  1295. {0x0000008b, 0x1c0a0000},
  1296. {0x0000008c, 0xff010000},
  1297. {0x0000008e, 0xffffefff},
  1298. {0x0000008f, 0xfff3efff},
  1299. {0x00000090, 0xfff3efbf},
  1300. {0x00000094, 0x00101101},
  1301. {0x00000095, 0x00000fff},
  1302. {0x00000096, 0x00116fff},
  1303. {0x00000097, 0x60010000},
  1304. {0x00000098, 0x10010000},
  1305. {0x00000099, 0x00006000},
  1306. {0x0000009a, 0x00001000},
  1307. {0x0000009f, 0x00a47400}
  1308. };
  1309. static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1310. {0x0000006f, 0x03044000},
  1311. {0x00000070, 0x0480c018},
  1312. {0x00000071, 0x00000040},
  1313. {0x00000072, 0x01000000},
  1314. {0x00000074, 0x000000ff},
  1315. {0x00000075, 0x00143400},
  1316. {0x00000076, 0x08ec0800},
  1317. {0x00000077, 0x040000cc},
  1318. {0x00000079, 0x00000000},
  1319. {0x0000007a, 0x21000409},
  1320. {0x0000007c, 0x00000000},
  1321. {0x0000007d, 0xe8000000},
  1322. {0x0000007e, 0x044408a8},
  1323. {0x0000007f, 0x00000003},
  1324. {0x00000080, 0x00000000},
  1325. {0x00000081, 0x01000000},
  1326. {0x00000082, 0x02000000},
  1327. {0x00000083, 0x00000000},
  1328. {0x00000084, 0xe3f3e4f4},
  1329. {0x00000085, 0x00052024},
  1330. {0x00000087, 0x00000000},
  1331. {0x00000088, 0x66036603},
  1332. {0x00000089, 0x01000000},
  1333. {0x0000008b, 0x1c0a0000},
  1334. {0x0000008c, 0xff010000},
  1335. {0x0000008e, 0xffffefff},
  1336. {0x0000008f, 0xfff3efff},
  1337. {0x00000090, 0xfff3efbf},
  1338. {0x00000094, 0x00101101},
  1339. {0x00000095, 0x00000fff},
  1340. {0x00000096, 0x00116fff},
  1341. {0x00000097, 0x60010000},
  1342. {0x00000098, 0x10010000},
  1343. {0x00000099, 0x00006000},
  1344. {0x0000009a, 0x00001000},
  1345. {0x0000009f, 0x00a37400}
  1346. };
  1347. static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1348. {0x0000006f, 0x03044000},
  1349. {0x00000070, 0x0480c018},
  1350. {0x00000071, 0x00000040},
  1351. {0x00000072, 0x01000000},
  1352. {0x00000074, 0x000000ff},
  1353. {0x00000075, 0x00143400},
  1354. {0x00000076, 0x08ec0800},
  1355. {0x00000077, 0x040000cc},
  1356. {0x00000079, 0x00000000},
  1357. {0x0000007a, 0x21000409},
  1358. {0x0000007c, 0x00000000},
  1359. {0x0000007d, 0xe8000000},
  1360. {0x0000007e, 0x044408a8},
  1361. {0x0000007f, 0x00000003},
  1362. {0x00000080, 0x00000000},
  1363. {0x00000081, 0x01000000},
  1364. {0x00000082, 0x02000000},
  1365. {0x00000083, 0x00000000},
  1366. {0x00000084, 0xe3f3e4f4},
  1367. {0x00000085, 0x00052024},
  1368. {0x00000087, 0x00000000},
  1369. {0x00000088, 0x66036603},
  1370. {0x00000089, 0x01000000},
  1371. {0x0000008b, 0x1c0a0000},
  1372. {0x0000008c, 0xff010000},
  1373. {0x0000008e, 0xffffefff},
  1374. {0x0000008f, 0xfff3efff},
  1375. {0x00000090, 0xfff3efbf},
  1376. {0x00000094, 0x00101101},
  1377. {0x00000095, 0x00000fff},
  1378. {0x00000096, 0x00116fff},
  1379. {0x00000097, 0x60010000},
  1380. {0x00000098, 0x10010000},
  1381. {0x00000099, 0x00006000},
  1382. {0x0000009a, 0x00001000},
  1383. {0x0000009f, 0x00a17730}
  1384. };
  1385. static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1386. {0x0000006f, 0x03044000},
  1387. {0x00000070, 0x0480c018},
  1388. {0x00000071, 0x00000040},
  1389. {0x00000072, 0x01000000},
  1390. {0x00000074, 0x000000ff},
  1391. {0x00000075, 0x00143400},
  1392. {0x00000076, 0x08ec0800},
  1393. {0x00000077, 0x040000cc},
  1394. {0x00000079, 0x00000000},
  1395. {0x0000007a, 0x21000409},
  1396. {0x0000007c, 0x00000000},
  1397. {0x0000007d, 0xe8000000},
  1398. {0x0000007e, 0x044408a8},
  1399. {0x0000007f, 0x00000003},
  1400. {0x00000080, 0x00000000},
  1401. {0x00000081, 0x01000000},
  1402. {0x00000082, 0x02000000},
  1403. {0x00000083, 0x00000000},
  1404. {0x00000084, 0xe3f3e4f4},
  1405. {0x00000085, 0x00052024},
  1406. {0x00000087, 0x00000000},
  1407. {0x00000088, 0x66036603},
  1408. {0x00000089, 0x01000000},
  1409. {0x0000008b, 0x1c0a0000},
  1410. {0x0000008c, 0xff010000},
  1411. {0x0000008e, 0xffffefff},
  1412. {0x0000008f, 0xfff3efff},
  1413. {0x00000090, 0xfff3efbf},
  1414. {0x00000094, 0x00101101},
  1415. {0x00000095, 0x00000fff},
  1416. {0x00000096, 0x00116fff},
  1417. {0x00000097, 0x60010000},
  1418. {0x00000098, 0x10010000},
  1419. {0x00000099, 0x00006000},
  1420. {0x0000009a, 0x00001000},
  1421. {0x0000009f, 0x00a07730}
  1422. };
  1423. /* ucode loading */
  1424. static int si_mc_load_microcode(struct radeon_device *rdev)
  1425. {
  1426. const __be32 *fw_data;
  1427. u32 running, blackout = 0;
  1428. u32 *io_mc_regs;
  1429. int i, ucode_size, regs_size;
  1430. if (!rdev->mc_fw)
  1431. return -EINVAL;
  1432. switch (rdev->family) {
  1433. case CHIP_TAHITI:
  1434. io_mc_regs = (u32 *)&tahiti_io_mc_regs;
  1435. ucode_size = SI_MC_UCODE_SIZE;
  1436. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1437. break;
  1438. case CHIP_PITCAIRN:
  1439. io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
  1440. ucode_size = SI_MC_UCODE_SIZE;
  1441. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1442. break;
  1443. case CHIP_VERDE:
  1444. default:
  1445. io_mc_regs = (u32 *)&verde_io_mc_regs;
  1446. ucode_size = SI_MC_UCODE_SIZE;
  1447. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1448. break;
  1449. case CHIP_OLAND:
  1450. io_mc_regs = (u32 *)&oland_io_mc_regs;
  1451. ucode_size = OLAND_MC_UCODE_SIZE;
  1452. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1453. break;
  1454. case CHIP_HAINAN:
  1455. io_mc_regs = (u32 *)&hainan_io_mc_regs;
  1456. ucode_size = OLAND_MC_UCODE_SIZE;
  1457. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1458. break;
  1459. }
  1460. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1461. if (running == 0) {
  1462. if (running) {
  1463. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1464. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1465. }
  1466. /* reset the engine and set to writable */
  1467. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1468. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1469. /* load mc io regs */
  1470. for (i = 0; i < regs_size; i++) {
  1471. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1472. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1473. }
  1474. /* load the MC ucode */
  1475. fw_data = (const __be32 *)rdev->mc_fw->data;
  1476. for (i = 0; i < ucode_size; i++)
  1477. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1478. /* put the engine back into the active state */
  1479. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1480. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1481. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1482. /* wait for training to complete */
  1483. for (i = 0; i < rdev->usec_timeout; i++) {
  1484. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1485. break;
  1486. udelay(1);
  1487. }
  1488. for (i = 0; i < rdev->usec_timeout; i++) {
  1489. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1490. break;
  1491. udelay(1);
  1492. }
  1493. if (running)
  1494. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1495. }
  1496. return 0;
  1497. }
  1498. static int si_init_microcode(struct radeon_device *rdev)
  1499. {
  1500. const char *chip_name;
  1501. const char *rlc_chip_name;
  1502. size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
  1503. size_t smc_req_size;
  1504. char fw_name[30];
  1505. int err;
  1506. DRM_DEBUG("\n");
  1507. switch (rdev->family) {
  1508. case CHIP_TAHITI:
  1509. chip_name = "TAHITI";
  1510. rlc_chip_name = "TAHITI";
  1511. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1512. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1513. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1514. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1515. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1516. smc_req_size = ALIGN(TAHITI_SMC_UCODE_SIZE, 4);
  1517. break;
  1518. case CHIP_PITCAIRN:
  1519. chip_name = "PITCAIRN";
  1520. rlc_chip_name = "PITCAIRN";
  1521. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1522. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1523. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1524. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1525. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1526. smc_req_size = ALIGN(PITCAIRN_SMC_UCODE_SIZE, 4);
  1527. break;
  1528. case CHIP_VERDE:
  1529. chip_name = "VERDE";
  1530. rlc_chip_name = "VERDE";
  1531. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1532. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1533. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1534. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1535. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1536. smc_req_size = ALIGN(VERDE_SMC_UCODE_SIZE, 4);
  1537. break;
  1538. case CHIP_OLAND:
  1539. chip_name = "OLAND";
  1540. rlc_chip_name = "OLAND";
  1541. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1542. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1543. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1544. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1545. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1546. smc_req_size = ALIGN(OLAND_SMC_UCODE_SIZE, 4);
  1547. break;
  1548. case CHIP_HAINAN:
  1549. chip_name = "HAINAN";
  1550. rlc_chip_name = "HAINAN";
  1551. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1552. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1553. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1554. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1555. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1556. smc_req_size = ALIGN(HAINAN_SMC_UCODE_SIZE, 4);
  1557. break;
  1558. default: BUG();
  1559. }
  1560. DRM_INFO("Loading %s Microcode\n", chip_name);
  1561. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1562. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  1563. if (err)
  1564. goto out;
  1565. if (rdev->pfp_fw->size != pfp_req_size) {
  1566. printk(KERN_ERR
  1567. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1568. rdev->pfp_fw->size, fw_name);
  1569. err = -EINVAL;
  1570. goto out;
  1571. }
  1572. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1573. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  1574. if (err)
  1575. goto out;
  1576. if (rdev->me_fw->size != me_req_size) {
  1577. printk(KERN_ERR
  1578. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1579. rdev->me_fw->size, fw_name);
  1580. err = -EINVAL;
  1581. }
  1582. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1583. err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
  1584. if (err)
  1585. goto out;
  1586. if (rdev->ce_fw->size != ce_req_size) {
  1587. printk(KERN_ERR
  1588. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1589. rdev->ce_fw->size, fw_name);
  1590. err = -EINVAL;
  1591. }
  1592. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1593. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  1594. if (err)
  1595. goto out;
  1596. if (rdev->rlc_fw->size != rlc_req_size) {
  1597. printk(KERN_ERR
  1598. "si_rlc: Bogus length %zu in firmware \"%s\"\n",
  1599. rdev->rlc_fw->size, fw_name);
  1600. err = -EINVAL;
  1601. }
  1602. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1603. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  1604. if (err)
  1605. goto out;
  1606. if (rdev->mc_fw->size != mc_req_size) {
  1607. printk(KERN_ERR
  1608. "si_mc: Bogus length %zu in firmware \"%s\"\n",
  1609. rdev->mc_fw->size, fw_name);
  1610. err = -EINVAL;
  1611. }
  1612. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
  1613. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  1614. if (err) {
  1615. printk(KERN_ERR
  1616. "smc: error loading firmware \"%s\"\n",
  1617. fw_name);
  1618. release_firmware(rdev->smc_fw);
  1619. rdev->smc_fw = NULL;
  1620. err = 0;
  1621. } else if (rdev->smc_fw->size != smc_req_size) {
  1622. printk(KERN_ERR
  1623. "si_smc: Bogus length %zu in firmware \"%s\"\n",
  1624. rdev->smc_fw->size, fw_name);
  1625. err = -EINVAL;
  1626. }
  1627. out:
  1628. if (err) {
  1629. if (err != -EINVAL)
  1630. printk(KERN_ERR
  1631. "si_cp: Failed to load firmware \"%s\"\n",
  1632. fw_name);
  1633. release_firmware(rdev->pfp_fw);
  1634. rdev->pfp_fw = NULL;
  1635. release_firmware(rdev->me_fw);
  1636. rdev->me_fw = NULL;
  1637. release_firmware(rdev->ce_fw);
  1638. rdev->ce_fw = NULL;
  1639. release_firmware(rdev->rlc_fw);
  1640. rdev->rlc_fw = NULL;
  1641. release_firmware(rdev->mc_fw);
  1642. rdev->mc_fw = NULL;
  1643. release_firmware(rdev->smc_fw);
  1644. rdev->smc_fw = NULL;
  1645. }
  1646. return err;
  1647. }
  1648. /* watermark setup */
  1649. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1650. struct radeon_crtc *radeon_crtc,
  1651. struct drm_display_mode *mode,
  1652. struct drm_display_mode *other_mode)
  1653. {
  1654. u32 tmp, buffer_alloc, i;
  1655. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1656. /*
  1657. * Line Buffer Setup
  1658. * There are 3 line buffers, each one shared by 2 display controllers.
  1659. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1660. * the display controllers. The paritioning is done via one of four
  1661. * preset allocations specified in bits 21:20:
  1662. * 0 - half lb
  1663. * 2 - whole lb, other crtc must be disabled
  1664. */
  1665. /* this can get tricky if we have two large displays on a paired group
  1666. * of crtcs. Ideally for multiple large displays we'd assign them to
  1667. * non-linked crtcs for maximum line buffer allocation.
  1668. */
  1669. if (radeon_crtc->base.enabled && mode) {
  1670. if (other_mode) {
  1671. tmp = 0; /* 1/2 */
  1672. buffer_alloc = 1;
  1673. } else {
  1674. tmp = 2; /* whole */
  1675. buffer_alloc = 2;
  1676. }
  1677. } else {
  1678. tmp = 0;
  1679. buffer_alloc = 0;
  1680. }
  1681. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1682. DC_LB_MEMORY_CONFIG(tmp));
  1683. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1684. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1685. for (i = 0; i < rdev->usec_timeout; i++) {
  1686. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1687. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1688. break;
  1689. udelay(1);
  1690. }
  1691. if (radeon_crtc->base.enabled && mode) {
  1692. switch (tmp) {
  1693. case 0:
  1694. default:
  1695. return 4096 * 2;
  1696. case 2:
  1697. return 8192 * 2;
  1698. }
  1699. }
  1700. /* controller not enabled, so no lb used */
  1701. return 0;
  1702. }
  1703. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1704. {
  1705. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1706. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1707. case 0:
  1708. default:
  1709. return 1;
  1710. case 1:
  1711. return 2;
  1712. case 2:
  1713. return 4;
  1714. case 3:
  1715. return 8;
  1716. case 4:
  1717. return 3;
  1718. case 5:
  1719. return 6;
  1720. case 6:
  1721. return 10;
  1722. case 7:
  1723. return 12;
  1724. case 8:
  1725. return 16;
  1726. }
  1727. }
  1728. struct dce6_wm_params {
  1729. u32 dram_channels; /* number of dram channels */
  1730. u32 yclk; /* bandwidth per dram data pin in kHz */
  1731. u32 sclk; /* engine clock in kHz */
  1732. u32 disp_clk; /* display clock in kHz */
  1733. u32 src_width; /* viewport width */
  1734. u32 active_time; /* active display time in ns */
  1735. u32 blank_time; /* blank time in ns */
  1736. bool interlaced; /* mode is interlaced */
  1737. fixed20_12 vsc; /* vertical scale ratio */
  1738. u32 num_heads; /* number of active crtcs */
  1739. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1740. u32 lb_size; /* line buffer allocated to pipe */
  1741. u32 vtaps; /* vertical scaler taps */
  1742. };
  1743. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1744. {
  1745. /* Calculate raw DRAM Bandwidth */
  1746. fixed20_12 dram_efficiency; /* 0.7 */
  1747. fixed20_12 yclk, dram_channels, bandwidth;
  1748. fixed20_12 a;
  1749. a.full = dfixed_const(1000);
  1750. yclk.full = dfixed_const(wm->yclk);
  1751. yclk.full = dfixed_div(yclk, a);
  1752. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1753. a.full = dfixed_const(10);
  1754. dram_efficiency.full = dfixed_const(7);
  1755. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1756. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1757. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1758. return dfixed_trunc(bandwidth);
  1759. }
  1760. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1761. {
  1762. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1763. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1764. fixed20_12 yclk, dram_channels, bandwidth;
  1765. fixed20_12 a;
  1766. a.full = dfixed_const(1000);
  1767. yclk.full = dfixed_const(wm->yclk);
  1768. yclk.full = dfixed_div(yclk, a);
  1769. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1770. a.full = dfixed_const(10);
  1771. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1772. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1773. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1774. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1775. return dfixed_trunc(bandwidth);
  1776. }
  1777. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1778. {
  1779. /* Calculate the display Data return Bandwidth */
  1780. fixed20_12 return_efficiency; /* 0.8 */
  1781. fixed20_12 sclk, bandwidth;
  1782. fixed20_12 a;
  1783. a.full = dfixed_const(1000);
  1784. sclk.full = dfixed_const(wm->sclk);
  1785. sclk.full = dfixed_div(sclk, a);
  1786. a.full = dfixed_const(10);
  1787. return_efficiency.full = dfixed_const(8);
  1788. return_efficiency.full = dfixed_div(return_efficiency, a);
  1789. a.full = dfixed_const(32);
  1790. bandwidth.full = dfixed_mul(a, sclk);
  1791. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1792. return dfixed_trunc(bandwidth);
  1793. }
  1794. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1795. {
  1796. return 32;
  1797. }
  1798. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1799. {
  1800. /* Calculate the DMIF Request Bandwidth */
  1801. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1802. fixed20_12 disp_clk, sclk, bandwidth;
  1803. fixed20_12 a, b1, b2;
  1804. u32 min_bandwidth;
  1805. a.full = dfixed_const(1000);
  1806. disp_clk.full = dfixed_const(wm->disp_clk);
  1807. disp_clk.full = dfixed_div(disp_clk, a);
  1808. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1809. b1.full = dfixed_mul(a, disp_clk);
  1810. a.full = dfixed_const(1000);
  1811. sclk.full = dfixed_const(wm->sclk);
  1812. sclk.full = dfixed_div(sclk, a);
  1813. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1814. b2.full = dfixed_mul(a, sclk);
  1815. a.full = dfixed_const(10);
  1816. disp_clk_request_efficiency.full = dfixed_const(8);
  1817. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1818. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1819. a.full = dfixed_const(min_bandwidth);
  1820. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1821. return dfixed_trunc(bandwidth);
  1822. }
  1823. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1824. {
  1825. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1826. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1827. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1828. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1829. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1830. }
  1831. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1832. {
  1833. /* Calculate the display mode Average Bandwidth
  1834. * DisplayMode should contain the source and destination dimensions,
  1835. * timing, etc.
  1836. */
  1837. fixed20_12 bpp;
  1838. fixed20_12 line_time;
  1839. fixed20_12 src_width;
  1840. fixed20_12 bandwidth;
  1841. fixed20_12 a;
  1842. a.full = dfixed_const(1000);
  1843. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1844. line_time.full = dfixed_div(line_time, a);
  1845. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1846. src_width.full = dfixed_const(wm->src_width);
  1847. bandwidth.full = dfixed_mul(src_width, bpp);
  1848. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1849. bandwidth.full = dfixed_div(bandwidth, line_time);
  1850. return dfixed_trunc(bandwidth);
  1851. }
  1852. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1853. {
  1854. /* First calcualte the latency in ns */
  1855. u32 mc_latency = 2000; /* 2000 ns. */
  1856. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1857. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1858. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1859. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1860. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1861. (wm->num_heads * cursor_line_pair_return_time);
  1862. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1863. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1864. u32 tmp, dmif_size = 12288;
  1865. fixed20_12 a, b, c;
  1866. if (wm->num_heads == 0)
  1867. return 0;
  1868. a.full = dfixed_const(2);
  1869. b.full = dfixed_const(1);
  1870. if ((wm->vsc.full > a.full) ||
  1871. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1872. (wm->vtaps >= 5) ||
  1873. ((wm->vsc.full >= a.full) && wm->interlaced))
  1874. max_src_lines_per_dst_line = 4;
  1875. else
  1876. max_src_lines_per_dst_line = 2;
  1877. a.full = dfixed_const(available_bandwidth);
  1878. b.full = dfixed_const(wm->num_heads);
  1879. a.full = dfixed_div(a, b);
  1880. b.full = dfixed_const(mc_latency + 512);
  1881. c.full = dfixed_const(wm->disp_clk);
  1882. b.full = dfixed_div(b, c);
  1883. c.full = dfixed_const(dmif_size);
  1884. b.full = dfixed_div(c, b);
  1885. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1886. b.full = dfixed_const(1000);
  1887. c.full = dfixed_const(wm->disp_clk);
  1888. b.full = dfixed_div(c, b);
  1889. c.full = dfixed_const(wm->bytes_per_pixel);
  1890. b.full = dfixed_mul(b, c);
  1891. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1892. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1893. b.full = dfixed_const(1000);
  1894. c.full = dfixed_const(lb_fill_bw);
  1895. b.full = dfixed_div(c, b);
  1896. a.full = dfixed_div(a, b);
  1897. line_fill_time = dfixed_trunc(a);
  1898. if (line_fill_time < wm->active_time)
  1899. return latency;
  1900. else
  1901. return latency + (line_fill_time - wm->active_time);
  1902. }
  1903. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1904. {
  1905. if (dce6_average_bandwidth(wm) <=
  1906. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1907. return true;
  1908. else
  1909. return false;
  1910. };
  1911. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1912. {
  1913. if (dce6_average_bandwidth(wm) <=
  1914. (dce6_available_bandwidth(wm) / wm->num_heads))
  1915. return true;
  1916. else
  1917. return false;
  1918. };
  1919. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1920. {
  1921. u32 lb_partitions = wm->lb_size / wm->src_width;
  1922. u32 line_time = wm->active_time + wm->blank_time;
  1923. u32 latency_tolerant_lines;
  1924. u32 latency_hiding;
  1925. fixed20_12 a;
  1926. a.full = dfixed_const(1);
  1927. if (wm->vsc.full > a.full)
  1928. latency_tolerant_lines = 1;
  1929. else {
  1930. if (lb_partitions <= (wm->vtaps + 1))
  1931. latency_tolerant_lines = 1;
  1932. else
  1933. latency_tolerant_lines = 2;
  1934. }
  1935. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1936. if (dce6_latency_watermark(wm) <= latency_hiding)
  1937. return true;
  1938. else
  1939. return false;
  1940. }
  1941. static void dce6_program_watermarks(struct radeon_device *rdev,
  1942. struct radeon_crtc *radeon_crtc,
  1943. u32 lb_size, u32 num_heads)
  1944. {
  1945. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1946. struct dce6_wm_params wm_low, wm_high;
  1947. u32 dram_channels;
  1948. u32 pixel_period;
  1949. u32 line_time = 0;
  1950. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1951. u32 priority_a_mark = 0, priority_b_mark = 0;
  1952. u32 priority_a_cnt = PRIORITY_OFF;
  1953. u32 priority_b_cnt = PRIORITY_OFF;
  1954. u32 tmp, arb_control3;
  1955. fixed20_12 a, b, c;
  1956. if (radeon_crtc->base.enabled && num_heads && mode) {
  1957. pixel_period = 1000000 / (u32)mode->clock;
  1958. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1959. priority_a_cnt = 0;
  1960. priority_b_cnt = 0;
  1961. if (rdev->family == CHIP_ARUBA)
  1962. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1963. else
  1964. dram_channels = si_get_number_of_dram_channels(rdev);
  1965. /* watermark for high clocks */
  1966. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1967. wm_high.yclk =
  1968. radeon_dpm_get_mclk(rdev, false) * 10;
  1969. wm_high.sclk =
  1970. radeon_dpm_get_sclk(rdev, false) * 10;
  1971. } else {
  1972. wm_high.yclk = rdev->pm.current_mclk * 10;
  1973. wm_high.sclk = rdev->pm.current_sclk * 10;
  1974. }
  1975. wm_high.disp_clk = mode->clock;
  1976. wm_high.src_width = mode->crtc_hdisplay;
  1977. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  1978. wm_high.blank_time = line_time - wm_high.active_time;
  1979. wm_high.interlaced = false;
  1980. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1981. wm_high.interlaced = true;
  1982. wm_high.vsc = radeon_crtc->vsc;
  1983. wm_high.vtaps = 1;
  1984. if (radeon_crtc->rmx_type != RMX_OFF)
  1985. wm_high.vtaps = 2;
  1986. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1987. wm_high.lb_size = lb_size;
  1988. wm_high.dram_channels = dram_channels;
  1989. wm_high.num_heads = num_heads;
  1990. /* watermark for low clocks */
  1991. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1992. wm_low.yclk =
  1993. radeon_dpm_get_mclk(rdev, true) * 10;
  1994. wm_low.sclk =
  1995. radeon_dpm_get_sclk(rdev, true) * 10;
  1996. } else {
  1997. wm_low.yclk = rdev->pm.current_mclk * 10;
  1998. wm_low.sclk = rdev->pm.current_sclk * 10;
  1999. }
  2000. wm_low.disp_clk = mode->clock;
  2001. wm_low.src_width = mode->crtc_hdisplay;
  2002. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2003. wm_low.blank_time = line_time - wm_low.active_time;
  2004. wm_low.interlaced = false;
  2005. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2006. wm_low.interlaced = true;
  2007. wm_low.vsc = radeon_crtc->vsc;
  2008. wm_low.vtaps = 1;
  2009. if (radeon_crtc->rmx_type != RMX_OFF)
  2010. wm_low.vtaps = 2;
  2011. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2012. wm_low.lb_size = lb_size;
  2013. wm_low.dram_channels = dram_channels;
  2014. wm_low.num_heads = num_heads;
  2015. /* set for high clocks */
  2016. latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
  2017. /* set for low clocks */
  2018. latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
  2019. /* possibly force display priority to high */
  2020. /* should really do this at mode validation time... */
  2021. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2022. !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2023. !dce6_check_latency_hiding(&wm_high) ||
  2024. (rdev->disp_priority == 2)) {
  2025. DRM_DEBUG_KMS("force priority to high\n");
  2026. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2027. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2028. }
  2029. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2030. !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2031. !dce6_check_latency_hiding(&wm_low) ||
  2032. (rdev->disp_priority == 2)) {
  2033. DRM_DEBUG_KMS("force priority to high\n");
  2034. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2035. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2036. }
  2037. a.full = dfixed_const(1000);
  2038. b.full = dfixed_const(mode->clock);
  2039. b.full = dfixed_div(b, a);
  2040. c.full = dfixed_const(latency_watermark_a);
  2041. c.full = dfixed_mul(c, b);
  2042. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2043. c.full = dfixed_div(c, a);
  2044. a.full = dfixed_const(16);
  2045. c.full = dfixed_div(c, a);
  2046. priority_a_mark = dfixed_trunc(c);
  2047. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2048. a.full = dfixed_const(1000);
  2049. b.full = dfixed_const(mode->clock);
  2050. b.full = dfixed_div(b, a);
  2051. c.full = dfixed_const(latency_watermark_b);
  2052. c.full = dfixed_mul(c, b);
  2053. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2054. c.full = dfixed_div(c, a);
  2055. a.full = dfixed_const(16);
  2056. c.full = dfixed_div(c, a);
  2057. priority_b_mark = dfixed_trunc(c);
  2058. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2059. }
  2060. /* select wm A */
  2061. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2062. tmp = arb_control3;
  2063. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2064. tmp |= LATENCY_WATERMARK_MASK(1);
  2065. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2066. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2067. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2068. LATENCY_HIGH_WATERMARK(line_time)));
  2069. /* select wm B */
  2070. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2071. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2072. tmp |= LATENCY_WATERMARK_MASK(2);
  2073. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2074. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2075. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2076. LATENCY_HIGH_WATERMARK(line_time)));
  2077. /* restore original selection */
  2078. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  2079. /* write the priority marks */
  2080. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2081. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2082. /* save values for DPM */
  2083. radeon_crtc->line_time = line_time;
  2084. radeon_crtc->wm_high = latency_watermark_a;
  2085. radeon_crtc->wm_low = latency_watermark_b;
  2086. }
  2087. void dce6_bandwidth_update(struct radeon_device *rdev)
  2088. {
  2089. struct drm_display_mode *mode0 = NULL;
  2090. struct drm_display_mode *mode1 = NULL;
  2091. u32 num_heads = 0, lb_size;
  2092. int i;
  2093. radeon_update_display_priority(rdev);
  2094. for (i = 0; i < rdev->num_crtc; i++) {
  2095. if (rdev->mode_info.crtcs[i]->base.enabled)
  2096. num_heads++;
  2097. }
  2098. for (i = 0; i < rdev->num_crtc; i += 2) {
  2099. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2100. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2101. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2102. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2103. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2104. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2105. }
  2106. }
  2107. /*
  2108. * Core functions
  2109. */
  2110. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  2111. {
  2112. const u32 num_tile_mode_states = 32;
  2113. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  2114. switch (rdev->config.si.mem_row_size_in_kb) {
  2115. case 1:
  2116. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  2117. break;
  2118. case 2:
  2119. default:
  2120. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  2121. break;
  2122. case 4:
  2123. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  2124. break;
  2125. }
  2126. if ((rdev->family == CHIP_TAHITI) ||
  2127. (rdev->family == CHIP_PITCAIRN)) {
  2128. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2129. switch (reg_offset) {
  2130. case 0: /* non-AA compressed depth or any compressed stencil */
  2131. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2132. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2133. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2134. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2135. NUM_BANKS(ADDR_SURF_16_BANK) |
  2136. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2137. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2138. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2139. break;
  2140. case 1: /* 2xAA/4xAA compressed depth only */
  2141. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2142. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2143. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2144. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2145. NUM_BANKS(ADDR_SURF_16_BANK) |
  2146. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2147. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2148. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2149. break;
  2150. case 2: /* 8xAA compressed depth only */
  2151. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2152. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2153. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2154. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2155. NUM_BANKS(ADDR_SURF_16_BANK) |
  2156. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2157. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2158. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2159. break;
  2160. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2161. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2162. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2163. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2164. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2165. NUM_BANKS(ADDR_SURF_16_BANK) |
  2166. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2167. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2168. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2169. break;
  2170. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2171. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2172. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2173. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2174. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2175. NUM_BANKS(ADDR_SURF_16_BANK) |
  2176. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2177. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2178. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2179. break;
  2180. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2181. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2182. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2183. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2184. TILE_SPLIT(split_equal_to_row_size) |
  2185. NUM_BANKS(ADDR_SURF_16_BANK) |
  2186. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2187. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2188. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2189. break;
  2190. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2191. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2192. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2193. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2194. TILE_SPLIT(split_equal_to_row_size) |
  2195. NUM_BANKS(ADDR_SURF_16_BANK) |
  2196. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2197. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2198. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2199. break;
  2200. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2201. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2202. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2203. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2204. TILE_SPLIT(split_equal_to_row_size) |
  2205. NUM_BANKS(ADDR_SURF_16_BANK) |
  2206. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2207. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2208. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2209. break;
  2210. case 8: /* 1D and 1D Array Surfaces */
  2211. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2212. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2213. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2214. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2215. NUM_BANKS(ADDR_SURF_16_BANK) |
  2216. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2217. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2218. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2219. break;
  2220. case 9: /* Displayable maps. */
  2221. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2222. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2223. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2224. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2225. NUM_BANKS(ADDR_SURF_16_BANK) |
  2226. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2227. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2228. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2229. break;
  2230. case 10: /* Display 8bpp. */
  2231. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2232. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2233. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2234. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2235. NUM_BANKS(ADDR_SURF_16_BANK) |
  2236. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2237. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2238. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2239. break;
  2240. case 11: /* Display 16bpp. */
  2241. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2242. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2243. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2244. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2245. NUM_BANKS(ADDR_SURF_16_BANK) |
  2246. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2247. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2248. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2249. break;
  2250. case 12: /* Display 32bpp. */
  2251. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2252. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2253. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2254. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2255. NUM_BANKS(ADDR_SURF_16_BANK) |
  2256. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2257. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2258. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2259. break;
  2260. case 13: /* Thin. */
  2261. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2262. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2263. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2264. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2265. NUM_BANKS(ADDR_SURF_16_BANK) |
  2266. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2267. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2268. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2269. break;
  2270. case 14: /* Thin 8 bpp. */
  2271. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2272. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2273. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2274. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2275. NUM_BANKS(ADDR_SURF_16_BANK) |
  2276. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2277. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2278. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2279. break;
  2280. case 15: /* Thin 16 bpp. */
  2281. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2282. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2283. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2284. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2285. NUM_BANKS(ADDR_SURF_16_BANK) |
  2286. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2287. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2288. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2289. break;
  2290. case 16: /* Thin 32 bpp. */
  2291. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2292. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2293. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2294. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2295. NUM_BANKS(ADDR_SURF_16_BANK) |
  2296. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2297. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2298. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2299. break;
  2300. case 17: /* Thin 64 bpp. */
  2301. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2302. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2303. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2304. TILE_SPLIT(split_equal_to_row_size) |
  2305. NUM_BANKS(ADDR_SURF_16_BANK) |
  2306. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2307. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2308. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2309. break;
  2310. case 21: /* 8 bpp PRT. */
  2311. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2312. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2313. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2314. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2315. NUM_BANKS(ADDR_SURF_16_BANK) |
  2316. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2317. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2318. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2319. break;
  2320. case 22: /* 16 bpp PRT */
  2321. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2322. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2323. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2324. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2325. NUM_BANKS(ADDR_SURF_16_BANK) |
  2326. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2327. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2328. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2329. break;
  2330. case 23: /* 32 bpp PRT */
  2331. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2332. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2333. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2334. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2335. NUM_BANKS(ADDR_SURF_16_BANK) |
  2336. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2337. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2338. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2339. break;
  2340. case 24: /* 64 bpp PRT */
  2341. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2342. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2343. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2344. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2345. NUM_BANKS(ADDR_SURF_16_BANK) |
  2346. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2347. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2348. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2349. break;
  2350. case 25: /* 128 bpp PRT */
  2351. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2352. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2353. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2354. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2355. NUM_BANKS(ADDR_SURF_8_BANK) |
  2356. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2357. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2358. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2359. break;
  2360. default:
  2361. gb_tile_moden = 0;
  2362. break;
  2363. }
  2364. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2365. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2366. }
  2367. } else if ((rdev->family == CHIP_VERDE) ||
  2368. (rdev->family == CHIP_OLAND) ||
  2369. (rdev->family == CHIP_HAINAN)) {
  2370. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2371. switch (reg_offset) {
  2372. case 0: /* non-AA compressed depth or any compressed stencil */
  2373. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2374. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2375. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2376. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2377. NUM_BANKS(ADDR_SURF_16_BANK) |
  2378. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2379. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2380. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2381. break;
  2382. case 1: /* 2xAA/4xAA compressed depth only */
  2383. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2384. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2385. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2386. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2387. NUM_BANKS(ADDR_SURF_16_BANK) |
  2388. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2389. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2390. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2391. break;
  2392. case 2: /* 8xAA compressed depth only */
  2393. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2394. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2395. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2396. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2397. NUM_BANKS(ADDR_SURF_16_BANK) |
  2398. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2399. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2400. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2401. break;
  2402. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2403. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2404. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2405. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2406. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2407. NUM_BANKS(ADDR_SURF_16_BANK) |
  2408. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2409. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2410. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2411. break;
  2412. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2413. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2414. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2415. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2416. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2417. NUM_BANKS(ADDR_SURF_16_BANK) |
  2418. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2419. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2420. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2421. break;
  2422. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2423. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2424. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2425. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2426. TILE_SPLIT(split_equal_to_row_size) |
  2427. NUM_BANKS(ADDR_SURF_16_BANK) |
  2428. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2429. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2430. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2431. break;
  2432. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2433. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2434. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2435. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2436. TILE_SPLIT(split_equal_to_row_size) |
  2437. NUM_BANKS(ADDR_SURF_16_BANK) |
  2438. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2439. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2440. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2441. break;
  2442. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2443. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2444. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2445. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2446. TILE_SPLIT(split_equal_to_row_size) |
  2447. NUM_BANKS(ADDR_SURF_16_BANK) |
  2448. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2449. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2450. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2451. break;
  2452. case 8: /* 1D and 1D Array Surfaces */
  2453. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2454. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2455. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2456. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2457. NUM_BANKS(ADDR_SURF_16_BANK) |
  2458. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2459. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2460. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2461. break;
  2462. case 9: /* Displayable maps. */
  2463. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2464. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2465. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2466. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2467. NUM_BANKS(ADDR_SURF_16_BANK) |
  2468. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2469. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2470. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2471. break;
  2472. case 10: /* Display 8bpp. */
  2473. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2474. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2475. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2476. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2477. NUM_BANKS(ADDR_SURF_16_BANK) |
  2478. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2479. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2480. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2481. break;
  2482. case 11: /* Display 16bpp. */
  2483. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2484. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2485. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2486. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2487. NUM_BANKS(ADDR_SURF_16_BANK) |
  2488. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2489. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2490. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2491. break;
  2492. case 12: /* Display 32bpp. */
  2493. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2494. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2495. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2496. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2497. NUM_BANKS(ADDR_SURF_16_BANK) |
  2498. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2499. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2500. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2501. break;
  2502. case 13: /* Thin. */
  2503. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2504. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2505. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2506. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2507. NUM_BANKS(ADDR_SURF_16_BANK) |
  2508. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2509. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2510. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2511. break;
  2512. case 14: /* Thin 8 bpp. */
  2513. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2514. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2515. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2516. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2517. NUM_BANKS(ADDR_SURF_16_BANK) |
  2518. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2519. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2520. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2521. break;
  2522. case 15: /* Thin 16 bpp. */
  2523. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2524. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2525. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2526. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2527. NUM_BANKS(ADDR_SURF_16_BANK) |
  2528. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2529. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2530. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2531. break;
  2532. case 16: /* Thin 32 bpp. */
  2533. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2534. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2535. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2536. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2537. NUM_BANKS(ADDR_SURF_16_BANK) |
  2538. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2539. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2540. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2541. break;
  2542. case 17: /* Thin 64 bpp. */
  2543. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2544. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2545. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2546. TILE_SPLIT(split_equal_to_row_size) |
  2547. NUM_BANKS(ADDR_SURF_16_BANK) |
  2548. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2549. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2550. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2551. break;
  2552. case 21: /* 8 bpp PRT. */
  2553. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2554. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2555. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2556. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2557. NUM_BANKS(ADDR_SURF_16_BANK) |
  2558. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2559. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2560. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2561. break;
  2562. case 22: /* 16 bpp PRT */
  2563. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2564. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2565. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2566. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2567. NUM_BANKS(ADDR_SURF_16_BANK) |
  2568. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2569. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2570. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2571. break;
  2572. case 23: /* 32 bpp PRT */
  2573. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2574. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2575. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2576. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2577. NUM_BANKS(ADDR_SURF_16_BANK) |
  2578. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2579. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2580. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2581. break;
  2582. case 24: /* 64 bpp PRT */
  2583. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2584. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2585. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2586. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2587. NUM_BANKS(ADDR_SURF_16_BANK) |
  2588. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2589. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2590. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2591. break;
  2592. case 25: /* 128 bpp PRT */
  2593. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2594. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2595. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2596. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2597. NUM_BANKS(ADDR_SURF_8_BANK) |
  2598. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2599. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2600. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2601. break;
  2602. default:
  2603. gb_tile_moden = 0;
  2604. break;
  2605. }
  2606. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2607. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2608. }
  2609. } else
  2610. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2611. }
  2612. static void si_select_se_sh(struct radeon_device *rdev,
  2613. u32 se_num, u32 sh_num)
  2614. {
  2615. u32 data = INSTANCE_BROADCAST_WRITES;
  2616. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2617. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2618. else if (se_num == 0xffffffff)
  2619. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2620. else if (sh_num == 0xffffffff)
  2621. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2622. else
  2623. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2624. WREG32(GRBM_GFX_INDEX, data);
  2625. }
  2626. static u32 si_create_bitmask(u32 bit_width)
  2627. {
  2628. u32 i, mask = 0;
  2629. for (i = 0; i < bit_width; i++) {
  2630. mask <<= 1;
  2631. mask |= 1;
  2632. }
  2633. return mask;
  2634. }
  2635. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2636. {
  2637. u32 data, mask;
  2638. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2639. if (data & 1)
  2640. data &= INACTIVE_CUS_MASK;
  2641. else
  2642. data = 0;
  2643. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2644. data >>= INACTIVE_CUS_SHIFT;
  2645. mask = si_create_bitmask(cu_per_sh);
  2646. return ~data & mask;
  2647. }
  2648. static void si_setup_spi(struct radeon_device *rdev,
  2649. u32 se_num, u32 sh_per_se,
  2650. u32 cu_per_sh)
  2651. {
  2652. int i, j, k;
  2653. u32 data, mask, active_cu;
  2654. for (i = 0; i < se_num; i++) {
  2655. for (j = 0; j < sh_per_se; j++) {
  2656. si_select_se_sh(rdev, i, j);
  2657. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2658. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2659. mask = 1;
  2660. for (k = 0; k < 16; k++) {
  2661. mask <<= k;
  2662. if (active_cu & mask) {
  2663. data &= ~mask;
  2664. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2665. break;
  2666. }
  2667. }
  2668. }
  2669. }
  2670. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2671. }
  2672. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2673. u32 max_rb_num, u32 se_num,
  2674. u32 sh_per_se)
  2675. {
  2676. u32 data, mask;
  2677. data = RREG32(CC_RB_BACKEND_DISABLE);
  2678. if (data & 1)
  2679. data &= BACKEND_DISABLE_MASK;
  2680. else
  2681. data = 0;
  2682. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2683. data >>= BACKEND_DISABLE_SHIFT;
  2684. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2685. return data & mask;
  2686. }
  2687. static void si_setup_rb(struct radeon_device *rdev,
  2688. u32 se_num, u32 sh_per_se,
  2689. u32 max_rb_num)
  2690. {
  2691. int i, j;
  2692. u32 data, mask;
  2693. u32 disabled_rbs = 0;
  2694. u32 enabled_rbs = 0;
  2695. for (i = 0; i < se_num; i++) {
  2696. for (j = 0; j < sh_per_se; j++) {
  2697. si_select_se_sh(rdev, i, j);
  2698. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2699. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2700. }
  2701. }
  2702. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2703. mask = 1;
  2704. for (i = 0; i < max_rb_num; i++) {
  2705. if (!(disabled_rbs & mask))
  2706. enabled_rbs |= mask;
  2707. mask <<= 1;
  2708. }
  2709. for (i = 0; i < se_num; i++) {
  2710. si_select_se_sh(rdev, i, 0xffffffff);
  2711. data = 0;
  2712. for (j = 0; j < sh_per_se; j++) {
  2713. switch (enabled_rbs & 3) {
  2714. case 1:
  2715. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2716. break;
  2717. case 2:
  2718. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2719. break;
  2720. case 3:
  2721. default:
  2722. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2723. break;
  2724. }
  2725. enabled_rbs >>= 2;
  2726. }
  2727. WREG32(PA_SC_RASTER_CONFIG, data);
  2728. }
  2729. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2730. }
  2731. static void si_gpu_init(struct radeon_device *rdev)
  2732. {
  2733. u32 gb_addr_config = 0;
  2734. u32 mc_shared_chmap, mc_arb_ramcfg;
  2735. u32 sx_debug_1;
  2736. u32 hdp_host_path_cntl;
  2737. u32 tmp;
  2738. int i, j;
  2739. switch (rdev->family) {
  2740. case CHIP_TAHITI:
  2741. rdev->config.si.max_shader_engines = 2;
  2742. rdev->config.si.max_tile_pipes = 12;
  2743. rdev->config.si.max_cu_per_sh = 8;
  2744. rdev->config.si.max_sh_per_se = 2;
  2745. rdev->config.si.max_backends_per_se = 4;
  2746. rdev->config.si.max_texture_channel_caches = 12;
  2747. rdev->config.si.max_gprs = 256;
  2748. rdev->config.si.max_gs_threads = 32;
  2749. rdev->config.si.max_hw_contexts = 8;
  2750. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2751. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2752. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2753. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2754. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2755. break;
  2756. case CHIP_PITCAIRN:
  2757. rdev->config.si.max_shader_engines = 2;
  2758. rdev->config.si.max_tile_pipes = 8;
  2759. rdev->config.si.max_cu_per_sh = 5;
  2760. rdev->config.si.max_sh_per_se = 2;
  2761. rdev->config.si.max_backends_per_se = 4;
  2762. rdev->config.si.max_texture_channel_caches = 8;
  2763. rdev->config.si.max_gprs = 256;
  2764. rdev->config.si.max_gs_threads = 32;
  2765. rdev->config.si.max_hw_contexts = 8;
  2766. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2767. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2768. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2769. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2770. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2771. break;
  2772. case CHIP_VERDE:
  2773. default:
  2774. rdev->config.si.max_shader_engines = 1;
  2775. rdev->config.si.max_tile_pipes = 4;
  2776. rdev->config.si.max_cu_per_sh = 5;
  2777. rdev->config.si.max_sh_per_se = 2;
  2778. rdev->config.si.max_backends_per_se = 4;
  2779. rdev->config.si.max_texture_channel_caches = 4;
  2780. rdev->config.si.max_gprs = 256;
  2781. rdev->config.si.max_gs_threads = 32;
  2782. rdev->config.si.max_hw_contexts = 8;
  2783. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2784. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2785. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2786. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2787. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2788. break;
  2789. case CHIP_OLAND:
  2790. rdev->config.si.max_shader_engines = 1;
  2791. rdev->config.si.max_tile_pipes = 4;
  2792. rdev->config.si.max_cu_per_sh = 6;
  2793. rdev->config.si.max_sh_per_se = 1;
  2794. rdev->config.si.max_backends_per_se = 2;
  2795. rdev->config.si.max_texture_channel_caches = 4;
  2796. rdev->config.si.max_gprs = 256;
  2797. rdev->config.si.max_gs_threads = 16;
  2798. rdev->config.si.max_hw_contexts = 8;
  2799. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2800. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2801. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2802. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2803. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2804. break;
  2805. case CHIP_HAINAN:
  2806. rdev->config.si.max_shader_engines = 1;
  2807. rdev->config.si.max_tile_pipes = 4;
  2808. rdev->config.si.max_cu_per_sh = 5;
  2809. rdev->config.si.max_sh_per_se = 1;
  2810. rdev->config.si.max_backends_per_se = 1;
  2811. rdev->config.si.max_texture_channel_caches = 2;
  2812. rdev->config.si.max_gprs = 256;
  2813. rdev->config.si.max_gs_threads = 16;
  2814. rdev->config.si.max_hw_contexts = 8;
  2815. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2816. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2817. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2818. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2819. gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
  2820. break;
  2821. }
  2822. /* Initialize HDP */
  2823. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2824. WREG32((0x2c14 + j), 0x00000000);
  2825. WREG32((0x2c18 + j), 0x00000000);
  2826. WREG32((0x2c1c + j), 0x00000000);
  2827. WREG32((0x2c20 + j), 0x00000000);
  2828. WREG32((0x2c24 + j), 0x00000000);
  2829. }
  2830. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2831. evergreen_fix_pci_max_read_req_size(rdev);
  2832. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2833. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2834. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2835. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2836. rdev->config.si.mem_max_burst_length_bytes = 256;
  2837. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2838. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2839. if (rdev->config.si.mem_row_size_in_kb > 4)
  2840. rdev->config.si.mem_row_size_in_kb = 4;
  2841. /* XXX use MC settings? */
  2842. rdev->config.si.shader_engine_tile_size = 32;
  2843. rdev->config.si.num_gpus = 1;
  2844. rdev->config.si.multi_gpu_tile_size = 64;
  2845. /* fix up row size */
  2846. gb_addr_config &= ~ROW_SIZE_MASK;
  2847. switch (rdev->config.si.mem_row_size_in_kb) {
  2848. case 1:
  2849. default:
  2850. gb_addr_config |= ROW_SIZE(0);
  2851. break;
  2852. case 2:
  2853. gb_addr_config |= ROW_SIZE(1);
  2854. break;
  2855. case 4:
  2856. gb_addr_config |= ROW_SIZE(2);
  2857. break;
  2858. }
  2859. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2860. * not have bank info, so create a custom tiling dword.
  2861. * bits 3:0 num_pipes
  2862. * bits 7:4 num_banks
  2863. * bits 11:8 group_size
  2864. * bits 15:12 row_size
  2865. */
  2866. rdev->config.si.tile_config = 0;
  2867. switch (rdev->config.si.num_tile_pipes) {
  2868. case 1:
  2869. rdev->config.si.tile_config |= (0 << 0);
  2870. break;
  2871. case 2:
  2872. rdev->config.si.tile_config |= (1 << 0);
  2873. break;
  2874. case 4:
  2875. rdev->config.si.tile_config |= (2 << 0);
  2876. break;
  2877. case 8:
  2878. default:
  2879. /* XXX what about 12? */
  2880. rdev->config.si.tile_config |= (3 << 0);
  2881. break;
  2882. }
  2883. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2884. case 0: /* four banks */
  2885. rdev->config.si.tile_config |= 0 << 4;
  2886. break;
  2887. case 1: /* eight banks */
  2888. rdev->config.si.tile_config |= 1 << 4;
  2889. break;
  2890. case 2: /* sixteen banks */
  2891. default:
  2892. rdev->config.si.tile_config |= 2 << 4;
  2893. break;
  2894. }
  2895. rdev->config.si.tile_config |=
  2896. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2897. rdev->config.si.tile_config |=
  2898. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2899. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2900. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2901. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2902. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2903. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2904. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2905. if (rdev->has_uvd) {
  2906. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2907. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2908. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2909. }
  2910. si_tiling_mode_table_init(rdev);
  2911. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2912. rdev->config.si.max_sh_per_se,
  2913. rdev->config.si.max_backends_per_se);
  2914. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2915. rdev->config.si.max_sh_per_se,
  2916. rdev->config.si.max_cu_per_sh);
  2917. /* set HW defaults for 3D engine */
  2918. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2919. ROQ_IB2_START(0x2b)));
  2920. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2921. sx_debug_1 = RREG32(SX_DEBUG_1);
  2922. WREG32(SX_DEBUG_1, sx_debug_1);
  2923. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2924. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2925. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2926. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2927. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2928. WREG32(VGT_NUM_INSTANCES, 1);
  2929. WREG32(CP_PERFMON_CNTL, 0);
  2930. WREG32(SQ_CONFIG, 0);
  2931. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2932. FORCE_EOV_MAX_REZ_CNT(255)));
  2933. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2934. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2935. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2936. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2937. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2938. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2939. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2940. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2941. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2942. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2943. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2944. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2945. tmp = RREG32(HDP_MISC_CNTL);
  2946. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2947. WREG32(HDP_MISC_CNTL, tmp);
  2948. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2949. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2950. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2951. udelay(50);
  2952. }
  2953. /*
  2954. * GPU scratch registers helpers function.
  2955. */
  2956. static void si_scratch_init(struct radeon_device *rdev)
  2957. {
  2958. int i;
  2959. rdev->scratch.num_reg = 7;
  2960. rdev->scratch.reg_base = SCRATCH_REG0;
  2961. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2962. rdev->scratch.free[i] = true;
  2963. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2964. }
  2965. }
  2966. void si_fence_ring_emit(struct radeon_device *rdev,
  2967. struct radeon_fence *fence)
  2968. {
  2969. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2970. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2971. /* flush read cache over gart */
  2972. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2973. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2974. radeon_ring_write(ring, 0);
  2975. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2976. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2977. PACKET3_TC_ACTION_ENA |
  2978. PACKET3_SH_KCACHE_ACTION_ENA |
  2979. PACKET3_SH_ICACHE_ACTION_ENA);
  2980. radeon_ring_write(ring, 0xFFFFFFFF);
  2981. radeon_ring_write(ring, 0);
  2982. radeon_ring_write(ring, 10); /* poll interval */
  2983. /* EVENT_WRITE_EOP - flush caches, send int */
  2984. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2985. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2986. radeon_ring_write(ring, addr & 0xffffffff);
  2987. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2988. radeon_ring_write(ring, fence->seq);
  2989. radeon_ring_write(ring, 0);
  2990. }
  2991. /*
  2992. * IB stuff
  2993. */
  2994. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2995. {
  2996. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2997. u32 header;
  2998. if (ib->is_const_ib) {
  2999. /* set switch buffer packet before const IB */
  3000. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3001. radeon_ring_write(ring, 0);
  3002. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  3003. } else {
  3004. u32 next_rptr;
  3005. if (ring->rptr_save_reg) {
  3006. next_rptr = ring->wptr + 3 + 4 + 8;
  3007. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3008. radeon_ring_write(ring, ((ring->rptr_save_reg -
  3009. PACKET3_SET_CONFIG_REG_START) >> 2));
  3010. radeon_ring_write(ring, next_rptr);
  3011. } else if (rdev->wb.enabled) {
  3012. next_rptr = ring->wptr + 5 + 4 + 8;
  3013. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3014. radeon_ring_write(ring, (1 << 8));
  3015. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3016. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  3017. radeon_ring_write(ring, next_rptr);
  3018. }
  3019. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  3020. }
  3021. radeon_ring_write(ring, header);
  3022. radeon_ring_write(ring,
  3023. #ifdef __BIG_ENDIAN
  3024. (2 << 0) |
  3025. #endif
  3026. (ib->gpu_addr & 0xFFFFFFFC));
  3027. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  3028. radeon_ring_write(ring, ib->length_dw |
  3029. (ib->vm ? (ib->vm->id << 24) : 0));
  3030. if (!ib->is_const_ib) {
  3031. /* flush read cache over gart for this vmid */
  3032. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3033. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  3034. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  3035. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  3036. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  3037. PACKET3_TC_ACTION_ENA |
  3038. PACKET3_SH_KCACHE_ACTION_ENA |
  3039. PACKET3_SH_ICACHE_ACTION_ENA);
  3040. radeon_ring_write(ring, 0xFFFFFFFF);
  3041. radeon_ring_write(ring, 0);
  3042. radeon_ring_write(ring, 10); /* poll interval */
  3043. }
  3044. }
  3045. /*
  3046. * CP.
  3047. */
  3048. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  3049. {
  3050. if (enable)
  3051. WREG32(CP_ME_CNTL, 0);
  3052. else {
  3053. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  3054. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  3055. WREG32(SCRATCH_UMSK, 0);
  3056. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3057. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3058. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3059. }
  3060. udelay(50);
  3061. }
  3062. static int si_cp_load_microcode(struct radeon_device *rdev)
  3063. {
  3064. const __be32 *fw_data;
  3065. int i;
  3066. if (!rdev->me_fw || !rdev->pfp_fw)
  3067. return -EINVAL;
  3068. si_cp_enable(rdev, false);
  3069. /* PFP */
  3070. fw_data = (const __be32 *)rdev->pfp_fw->data;
  3071. WREG32(CP_PFP_UCODE_ADDR, 0);
  3072. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  3073. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  3074. WREG32(CP_PFP_UCODE_ADDR, 0);
  3075. /* CE */
  3076. fw_data = (const __be32 *)rdev->ce_fw->data;
  3077. WREG32(CP_CE_UCODE_ADDR, 0);
  3078. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  3079. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  3080. WREG32(CP_CE_UCODE_ADDR, 0);
  3081. /* ME */
  3082. fw_data = (const __be32 *)rdev->me_fw->data;
  3083. WREG32(CP_ME_RAM_WADDR, 0);
  3084. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  3085. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  3086. WREG32(CP_ME_RAM_WADDR, 0);
  3087. WREG32(CP_PFP_UCODE_ADDR, 0);
  3088. WREG32(CP_CE_UCODE_ADDR, 0);
  3089. WREG32(CP_ME_RAM_WADDR, 0);
  3090. WREG32(CP_ME_RAM_RADDR, 0);
  3091. return 0;
  3092. }
  3093. static int si_cp_start(struct radeon_device *rdev)
  3094. {
  3095. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3096. int r, i;
  3097. r = radeon_ring_lock(rdev, ring, 7 + 4);
  3098. if (r) {
  3099. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3100. return r;
  3101. }
  3102. /* init the CP */
  3103. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  3104. radeon_ring_write(ring, 0x1);
  3105. radeon_ring_write(ring, 0x0);
  3106. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  3107. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  3108. radeon_ring_write(ring, 0);
  3109. radeon_ring_write(ring, 0);
  3110. /* init the CE partitions */
  3111. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  3112. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  3113. radeon_ring_write(ring, 0xc000);
  3114. radeon_ring_write(ring, 0xe000);
  3115. radeon_ring_unlock_commit(rdev, ring);
  3116. si_cp_enable(rdev, true);
  3117. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  3118. if (r) {
  3119. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3120. return r;
  3121. }
  3122. /* setup clear context state */
  3123. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3124. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3125. for (i = 0; i < si_default_size; i++)
  3126. radeon_ring_write(ring, si_default_state[i]);
  3127. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3128. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  3129. /* set clear context state */
  3130. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  3131. radeon_ring_write(ring, 0);
  3132. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3133. radeon_ring_write(ring, 0x00000316);
  3134. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  3135. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  3136. radeon_ring_unlock_commit(rdev, ring);
  3137. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  3138. ring = &rdev->ring[i];
  3139. r = radeon_ring_lock(rdev, ring, 2);
  3140. /* clear the compute context state */
  3141. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  3142. radeon_ring_write(ring, 0);
  3143. radeon_ring_unlock_commit(rdev, ring);
  3144. }
  3145. return 0;
  3146. }
  3147. static void si_cp_fini(struct radeon_device *rdev)
  3148. {
  3149. struct radeon_ring *ring;
  3150. si_cp_enable(rdev, false);
  3151. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3152. radeon_ring_fini(rdev, ring);
  3153. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3154. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3155. radeon_ring_fini(rdev, ring);
  3156. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3157. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3158. radeon_ring_fini(rdev, ring);
  3159. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3160. }
  3161. static int si_cp_resume(struct radeon_device *rdev)
  3162. {
  3163. struct radeon_ring *ring;
  3164. u32 tmp;
  3165. u32 rb_bufsz;
  3166. int r;
  3167. si_enable_gui_idle_interrupt(rdev, false);
  3168. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  3169. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  3170. /* Set the write pointer delay */
  3171. WREG32(CP_RB_WPTR_DELAY, 0);
  3172. WREG32(CP_DEBUG, 0);
  3173. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  3174. /* ring 0 - compute and gfx */
  3175. /* Set ring buffer size */
  3176. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3177. rb_bufsz = order_base_2(ring->ring_size / 8);
  3178. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3179. #ifdef __BIG_ENDIAN
  3180. tmp |= BUF_SWAP_32BIT;
  3181. #endif
  3182. WREG32(CP_RB0_CNTL, tmp);
  3183. /* Initialize the ring buffer's read and write pointers */
  3184. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  3185. ring->wptr = 0;
  3186. WREG32(CP_RB0_WPTR, ring->wptr);
  3187. /* set the wb address whether it's enabled or not */
  3188. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  3189. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  3190. if (rdev->wb.enabled)
  3191. WREG32(SCRATCH_UMSK, 0xff);
  3192. else {
  3193. tmp |= RB_NO_UPDATE;
  3194. WREG32(SCRATCH_UMSK, 0);
  3195. }
  3196. mdelay(1);
  3197. WREG32(CP_RB0_CNTL, tmp);
  3198. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  3199. ring->rptr = RREG32(CP_RB0_RPTR);
  3200. /* ring1 - compute only */
  3201. /* Set ring buffer size */
  3202. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3203. rb_bufsz = order_base_2(ring->ring_size / 8);
  3204. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3205. #ifdef __BIG_ENDIAN
  3206. tmp |= BUF_SWAP_32BIT;
  3207. #endif
  3208. WREG32(CP_RB1_CNTL, tmp);
  3209. /* Initialize the ring buffer's read and write pointers */
  3210. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  3211. ring->wptr = 0;
  3212. WREG32(CP_RB1_WPTR, ring->wptr);
  3213. /* set the wb address whether it's enabled or not */
  3214. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  3215. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  3216. mdelay(1);
  3217. WREG32(CP_RB1_CNTL, tmp);
  3218. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  3219. ring->rptr = RREG32(CP_RB1_RPTR);
  3220. /* ring2 - compute only */
  3221. /* Set ring buffer size */
  3222. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3223. rb_bufsz = order_base_2(ring->ring_size / 8);
  3224. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3225. #ifdef __BIG_ENDIAN
  3226. tmp |= BUF_SWAP_32BIT;
  3227. #endif
  3228. WREG32(CP_RB2_CNTL, tmp);
  3229. /* Initialize the ring buffer's read and write pointers */
  3230. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  3231. ring->wptr = 0;
  3232. WREG32(CP_RB2_WPTR, ring->wptr);
  3233. /* set the wb address whether it's enabled or not */
  3234. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  3235. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  3236. mdelay(1);
  3237. WREG32(CP_RB2_CNTL, tmp);
  3238. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  3239. ring->rptr = RREG32(CP_RB2_RPTR);
  3240. /* start the rings */
  3241. si_cp_start(rdev);
  3242. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  3243. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  3244. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  3245. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  3246. if (r) {
  3247. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3248. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3249. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3250. return r;
  3251. }
  3252. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  3253. if (r) {
  3254. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3255. }
  3256. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  3257. if (r) {
  3258. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3259. }
  3260. si_enable_gui_idle_interrupt(rdev, true);
  3261. return 0;
  3262. }
  3263. u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  3264. {
  3265. u32 reset_mask = 0;
  3266. u32 tmp;
  3267. /* GRBM_STATUS */
  3268. tmp = RREG32(GRBM_STATUS);
  3269. if (tmp & (PA_BUSY | SC_BUSY |
  3270. BCI_BUSY | SX_BUSY |
  3271. TA_BUSY | VGT_BUSY |
  3272. DB_BUSY | CB_BUSY |
  3273. GDS_BUSY | SPI_BUSY |
  3274. IA_BUSY | IA_BUSY_NO_DMA))
  3275. reset_mask |= RADEON_RESET_GFX;
  3276. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3277. CP_BUSY | CP_COHERENCY_BUSY))
  3278. reset_mask |= RADEON_RESET_CP;
  3279. if (tmp & GRBM_EE_BUSY)
  3280. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3281. /* GRBM_STATUS2 */
  3282. tmp = RREG32(GRBM_STATUS2);
  3283. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3284. reset_mask |= RADEON_RESET_RLC;
  3285. /* DMA_STATUS_REG 0 */
  3286. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  3287. if (!(tmp & DMA_IDLE))
  3288. reset_mask |= RADEON_RESET_DMA;
  3289. /* DMA_STATUS_REG 1 */
  3290. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  3291. if (!(tmp & DMA_IDLE))
  3292. reset_mask |= RADEON_RESET_DMA1;
  3293. /* SRBM_STATUS2 */
  3294. tmp = RREG32(SRBM_STATUS2);
  3295. if (tmp & DMA_BUSY)
  3296. reset_mask |= RADEON_RESET_DMA;
  3297. if (tmp & DMA1_BUSY)
  3298. reset_mask |= RADEON_RESET_DMA1;
  3299. /* SRBM_STATUS */
  3300. tmp = RREG32(SRBM_STATUS);
  3301. if (tmp & IH_BUSY)
  3302. reset_mask |= RADEON_RESET_IH;
  3303. if (tmp & SEM_BUSY)
  3304. reset_mask |= RADEON_RESET_SEM;
  3305. if (tmp & GRBM_RQ_PENDING)
  3306. reset_mask |= RADEON_RESET_GRBM;
  3307. if (tmp & VMC_BUSY)
  3308. reset_mask |= RADEON_RESET_VMC;
  3309. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3310. MCC_BUSY | MCD_BUSY))
  3311. reset_mask |= RADEON_RESET_MC;
  3312. if (evergreen_is_display_hung(rdev))
  3313. reset_mask |= RADEON_RESET_DISPLAY;
  3314. /* VM_L2_STATUS */
  3315. tmp = RREG32(VM_L2_STATUS);
  3316. if (tmp & L2_BUSY)
  3317. reset_mask |= RADEON_RESET_VMC;
  3318. /* Skip MC reset as it's mostly likely not hung, just busy */
  3319. if (reset_mask & RADEON_RESET_MC) {
  3320. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3321. reset_mask &= ~RADEON_RESET_MC;
  3322. }
  3323. return reset_mask;
  3324. }
  3325. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3326. {
  3327. struct evergreen_mc_save save;
  3328. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3329. u32 tmp;
  3330. if (reset_mask == 0)
  3331. return;
  3332. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3333. evergreen_print_gpu_status_regs(rdev);
  3334. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  3335. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  3336. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  3337. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  3338. /* disable PG/CG */
  3339. si_fini_pg(rdev);
  3340. si_fini_cg(rdev);
  3341. /* stop the rlc */
  3342. si_rlc_stop(rdev);
  3343. /* Disable CP parsing/prefetching */
  3344. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  3345. if (reset_mask & RADEON_RESET_DMA) {
  3346. /* dma0 */
  3347. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  3348. tmp &= ~DMA_RB_ENABLE;
  3349. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3350. }
  3351. if (reset_mask & RADEON_RESET_DMA1) {
  3352. /* dma1 */
  3353. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  3354. tmp &= ~DMA_RB_ENABLE;
  3355. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3356. }
  3357. udelay(50);
  3358. evergreen_mc_stop(rdev, &save);
  3359. if (evergreen_mc_wait_for_idle(rdev)) {
  3360. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3361. }
  3362. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  3363. grbm_soft_reset = SOFT_RESET_CB |
  3364. SOFT_RESET_DB |
  3365. SOFT_RESET_GDS |
  3366. SOFT_RESET_PA |
  3367. SOFT_RESET_SC |
  3368. SOFT_RESET_BCI |
  3369. SOFT_RESET_SPI |
  3370. SOFT_RESET_SX |
  3371. SOFT_RESET_TC |
  3372. SOFT_RESET_TA |
  3373. SOFT_RESET_VGT |
  3374. SOFT_RESET_IA;
  3375. }
  3376. if (reset_mask & RADEON_RESET_CP) {
  3377. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  3378. srbm_soft_reset |= SOFT_RESET_GRBM;
  3379. }
  3380. if (reset_mask & RADEON_RESET_DMA)
  3381. srbm_soft_reset |= SOFT_RESET_DMA;
  3382. if (reset_mask & RADEON_RESET_DMA1)
  3383. srbm_soft_reset |= SOFT_RESET_DMA1;
  3384. if (reset_mask & RADEON_RESET_DISPLAY)
  3385. srbm_soft_reset |= SOFT_RESET_DC;
  3386. if (reset_mask & RADEON_RESET_RLC)
  3387. grbm_soft_reset |= SOFT_RESET_RLC;
  3388. if (reset_mask & RADEON_RESET_SEM)
  3389. srbm_soft_reset |= SOFT_RESET_SEM;
  3390. if (reset_mask & RADEON_RESET_IH)
  3391. srbm_soft_reset |= SOFT_RESET_IH;
  3392. if (reset_mask & RADEON_RESET_GRBM)
  3393. srbm_soft_reset |= SOFT_RESET_GRBM;
  3394. if (reset_mask & RADEON_RESET_VMC)
  3395. srbm_soft_reset |= SOFT_RESET_VMC;
  3396. if (reset_mask & RADEON_RESET_MC)
  3397. srbm_soft_reset |= SOFT_RESET_MC;
  3398. if (grbm_soft_reset) {
  3399. tmp = RREG32(GRBM_SOFT_RESET);
  3400. tmp |= grbm_soft_reset;
  3401. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3402. WREG32(GRBM_SOFT_RESET, tmp);
  3403. tmp = RREG32(GRBM_SOFT_RESET);
  3404. udelay(50);
  3405. tmp &= ~grbm_soft_reset;
  3406. WREG32(GRBM_SOFT_RESET, tmp);
  3407. tmp = RREG32(GRBM_SOFT_RESET);
  3408. }
  3409. if (srbm_soft_reset) {
  3410. tmp = RREG32(SRBM_SOFT_RESET);
  3411. tmp |= srbm_soft_reset;
  3412. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3413. WREG32(SRBM_SOFT_RESET, tmp);
  3414. tmp = RREG32(SRBM_SOFT_RESET);
  3415. udelay(50);
  3416. tmp &= ~srbm_soft_reset;
  3417. WREG32(SRBM_SOFT_RESET, tmp);
  3418. tmp = RREG32(SRBM_SOFT_RESET);
  3419. }
  3420. /* Wait a little for things to settle down */
  3421. udelay(50);
  3422. evergreen_mc_resume(rdev, &save);
  3423. udelay(50);
  3424. evergreen_print_gpu_status_regs(rdev);
  3425. }
  3426. int si_asic_reset(struct radeon_device *rdev)
  3427. {
  3428. u32 reset_mask;
  3429. reset_mask = si_gpu_check_soft_reset(rdev);
  3430. if (reset_mask)
  3431. r600_set_bios_scratch_engine_hung(rdev, true);
  3432. si_gpu_soft_reset(rdev, reset_mask);
  3433. reset_mask = si_gpu_check_soft_reset(rdev);
  3434. if (!reset_mask)
  3435. r600_set_bios_scratch_engine_hung(rdev, false);
  3436. return 0;
  3437. }
  3438. /**
  3439. * si_gfx_is_lockup - Check if the GFX engine is locked up
  3440. *
  3441. * @rdev: radeon_device pointer
  3442. * @ring: radeon_ring structure holding ring information
  3443. *
  3444. * Check if the GFX engine is locked up.
  3445. * Returns true if the engine appears to be locked up, false if not.
  3446. */
  3447. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3448. {
  3449. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3450. if (!(reset_mask & (RADEON_RESET_GFX |
  3451. RADEON_RESET_COMPUTE |
  3452. RADEON_RESET_CP))) {
  3453. radeon_ring_lockup_update(ring);
  3454. return false;
  3455. }
  3456. /* force CP activities */
  3457. radeon_ring_force_activity(rdev, ring);
  3458. return radeon_ring_test_lockup(rdev, ring);
  3459. }
  3460. /* MC */
  3461. static void si_mc_program(struct radeon_device *rdev)
  3462. {
  3463. struct evergreen_mc_save save;
  3464. u32 tmp;
  3465. int i, j;
  3466. /* Initialize HDP */
  3467. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3468. WREG32((0x2c14 + j), 0x00000000);
  3469. WREG32((0x2c18 + j), 0x00000000);
  3470. WREG32((0x2c1c + j), 0x00000000);
  3471. WREG32((0x2c20 + j), 0x00000000);
  3472. WREG32((0x2c24 + j), 0x00000000);
  3473. }
  3474. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3475. evergreen_mc_stop(rdev, &save);
  3476. if (radeon_mc_wait_for_idle(rdev)) {
  3477. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3478. }
  3479. if (!ASIC_IS_NODCE(rdev))
  3480. /* Lockout access through VGA aperture*/
  3481. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3482. /* Update configuration */
  3483. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3484. rdev->mc.vram_start >> 12);
  3485. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3486. rdev->mc.vram_end >> 12);
  3487. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3488. rdev->vram_scratch.gpu_addr >> 12);
  3489. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3490. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3491. WREG32(MC_VM_FB_LOCATION, tmp);
  3492. /* XXX double check these! */
  3493. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3494. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3495. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3496. WREG32(MC_VM_AGP_BASE, 0);
  3497. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3498. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3499. if (radeon_mc_wait_for_idle(rdev)) {
  3500. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3501. }
  3502. evergreen_mc_resume(rdev, &save);
  3503. if (!ASIC_IS_NODCE(rdev)) {
  3504. /* we need to own VRAM, so turn off the VGA renderer here
  3505. * to stop it overwriting our objects */
  3506. rv515_vga_render_disable(rdev);
  3507. }
  3508. }
  3509. void si_vram_gtt_location(struct radeon_device *rdev,
  3510. struct radeon_mc *mc)
  3511. {
  3512. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3513. /* leave room for at least 1024M GTT */
  3514. dev_warn(rdev->dev, "limiting VRAM\n");
  3515. mc->real_vram_size = 0xFFC0000000ULL;
  3516. mc->mc_vram_size = 0xFFC0000000ULL;
  3517. }
  3518. radeon_vram_location(rdev, &rdev->mc, 0);
  3519. rdev->mc.gtt_base_align = 0;
  3520. radeon_gtt_location(rdev, mc);
  3521. }
  3522. static int si_mc_init(struct radeon_device *rdev)
  3523. {
  3524. u32 tmp;
  3525. int chansize, numchan;
  3526. /* Get VRAM informations */
  3527. rdev->mc.vram_is_ddr = true;
  3528. tmp = RREG32(MC_ARB_RAMCFG);
  3529. if (tmp & CHANSIZE_OVERRIDE) {
  3530. chansize = 16;
  3531. } else if (tmp & CHANSIZE_MASK) {
  3532. chansize = 64;
  3533. } else {
  3534. chansize = 32;
  3535. }
  3536. tmp = RREG32(MC_SHARED_CHMAP);
  3537. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3538. case 0:
  3539. default:
  3540. numchan = 1;
  3541. break;
  3542. case 1:
  3543. numchan = 2;
  3544. break;
  3545. case 2:
  3546. numchan = 4;
  3547. break;
  3548. case 3:
  3549. numchan = 8;
  3550. break;
  3551. case 4:
  3552. numchan = 3;
  3553. break;
  3554. case 5:
  3555. numchan = 6;
  3556. break;
  3557. case 6:
  3558. numchan = 10;
  3559. break;
  3560. case 7:
  3561. numchan = 12;
  3562. break;
  3563. case 8:
  3564. numchan = 16;
  3565. break;
  3566. }
  3567. rdev->mc.vram_width = numchan * chansize;
  3568. /* Could aper size report 0 ? */
  3569. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3570. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3571. /* size in MB on si */
  3572. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3573. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3574. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3575. si_vram_gtt_location(rdev, &rdev->mc);
  3576. radeon_update_bandwidth_info(rdev);
  3577. return 0;
  3578. }
  3579. /*
  3580. * GART
  3581. */
  3582. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3583. {
  3584. /* flush hdp cache */
  3585. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3586. /* bits 0-15 are the VM contexts0-15 */
  3587. WREG32(VM_INVALIDATE_REQUEST, 1);
  3588. }
  3589. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3590. {
  3591. int r, i;
  3592. if (rdev->gart.robj == NULL) {
  3593. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3594. return -EINVAL;
  3595. }
  3596. r = radeon_gart_table_vram_pin(rdev);
  3597. if (r)
  3598. return r;
  3599. radeon_gart_restore(rdev);
  3600. /* Setup TLB control */
  3601. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3602. (0xA << 7) |
  3603. ENABLE_L1_TLB |
  3604. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3605. ENABLE_ADVANCED_DRIVER_MODEL |
  3606. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3607. /* Setup L2 cache */
  3608. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3609. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3610. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3611. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3612. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3613. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3614. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3615. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3616. /* setup context0 */
  3617. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3618. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3619. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3620. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3621. (u32)(rdev->dummy_page.addr >> 12));
  3622. WREG32(VM_CONTEXT0_CNTL2, 0);
  3623. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3624. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3625. WREG32(0x15D4, 0);
  3626. WREG32(0x15D8, 0);
  3627. WREG32(0x15DC, 0);
  3628. /* empty context1-15 */
  3629. /* set vm size, must be a multiple of 4 */
  3630. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3631. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3632. /* Assign the pt base to something valid for now; the pts used for
  3633. * the VMs are determined by the application and setup and assigned
  3634. * on the fly in the vm part of radeon_gart.c
  3635. */
  3636. for (i = 1; i < 16; i++) {
  3637. if (i < 8)
  3638. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3639. rdev->gart.table_addr >> 12);
  3640. else
  3641. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3642. rdev->gart.table_addr >> 12);
  3643. }
  3644. /* enable context1-15 */
  3645. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3646. (u32)(rdev->dummy_page.addr >> 12));
  3647. WREG32(VM_CONTEXT1_CNTL2, 4);
  3648. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3649. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3650. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3651. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3652. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3653. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3654. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3655. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3656. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3657. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3658. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3659. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3660. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3661. si_pcie_gart_tlb_flush(rdev);
  3662. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3663. (unsigned)(rdev->mc.gtt_size >> 20),
  3664. (unsigned long long)rdev->gart.table_addr);
  3665. rdev->gart.ready = true;
  3666. return 0;
  3667. }
  3668. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3669. {
  3670. /* Disable all tables */
  3671. WREG32(VM_CONTEXT0_CNTL, 0);
  3672. WREG32(VM_CONTEXT1_CNTL, 0);
  3673. /* Setup TLB control */
  3674. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3675. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3676. /* Setup L2 cache */
  3677. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3678. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3679. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3680. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3681. WREG32(VM_L2_CNTL2, 0);
  3682. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3683. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3684. radeon_gart_table_vram_unpin(rdev);
  3685. }
  3686. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3687. {
  3688. si_pcie_gart_disable(rdev);
  3689. radeon_gart_table_vram_free(rdev);
  3690. radeon_gart_fini(rdev);
  3691. }
  3692. /* vm parser */
  3693. static bool si_vm_reg_valid(u32 reg)
  3694. {
  3695. /* context regs are fine */
  3696. if (reg >= 0x28000)
  3697. return true;
  3698. /* check config regs */
  3699. switch (reg) {
  3700. case GRBM_GFX_INDEX:
  3701. case CP_STRMOUT_CNTL:
  3702. case VGT_VTX_VECT_EJECT_REG:
  3703. case VGT_CACHE_INVALIDATION:
  3704. case VGT_ESGS_RING_SIZE:
  3705. case VGT_GSVS_RING_SIZE:
  3706. case VGT_GS_VERTEX_REUSE:
  3707. case VGT_PRIMITIVE_TYPE:
  3708. case VGT_INDEX_TYPE:
  3709. case VGT_NUM_INDICES:
  3710. case VGT_NUM_INSTANCES:
  3711. case VGT_TF_RING_SIZE:
  3712. case VGT_HS_OFFCHIP_PARAM:
  3713. case VGT_TF_MEMORY_BASE:
  3714. case PA_CL_ENHANCE:
  3715. case PA_SU_LINE_STIPPLE_VALUE:
  3716. case PA_SC_LINE_STIPPLE_STATE:
  3717. case PA_SC_ENHANCE:
  3718. case SQC_CACHES:
  3719. case SPI_STATIC_THREAD_MGMT_1:
  3720. case SPI_STATIC_THREAD_MGMT_2:
  3721. case SPI_STATIC_THREAD_MGMT_3:
  3722. case SPI_PS_MAX_WAVE_ID:
  3723. case SPI_CONFIG_CNTL:
  3724. case SPI_CONFIG_CNTL_1:
  3725. case TA_CNTL_AUX:
  3726. return true;
  3727. default:
  3728. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3729. return false;
  3730. }
  3731. }
  3732. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3733. u32 *ib, struct radeon_cs_packet *pkt)
  3734. {
  3735. switch (pkt->opcode) {
  3736. case PACKET3_NOP:
  3737. case PACKET3_SET_BASE:
  3738. case PACKET3_SET_CE_DE_COUNTERS:
  3739. case PACKET3_LOAD_CONST_RAM:
  3740. case PACKET3_WRITE_CONST_RAM:
  3741. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3742. case PACKET3_DUMP_CONST_RAM:
  3743. case PACKET3_INCREMENT_CE_COUNTER:
  3744. case PACKET3_WAIT_ON_DE_COUNTER:
  3745. case PACKET3_CE_WRITE:
  3746. break;
  3747. default:
  3748. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3749. return -EINVAL;
  3750. }
  3751. return 0;
  3752. }
  3753. static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
  3754. {
  3755. u32 start_reg, reg, i;
  3756. u32 command = ib[idx + 4];
  3757. u32 info = ib[idx + 1];
  3758. u32 idx_value = ib[idx];
  3759. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3760. /* src address space is register */
  3761. if (((info & 0x60000000) >> 29) == 0) {
  3762. start_reg = idx_value << 2;
  3763. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3764. reg = start_reg;
  3765. if (!si_vm_reg_valid(reg)) {
  3766. DRM_ERROR("CP DMA Bad SRC register\n");
  3767. return -EINVAL;
  3768. }
  3769. } else {
  3770. for (i = 0; i < (command & 0x1fffff); i++) {
  3771. reg = start_reg + (4 * i);
  3772. if (!si_vm_reg_valid(reg)) {
  3773. DRM_ERROR("CP DMA Bad SRC register\n");
  3774. return -EINVAL;
  3775. }
  3776. }
  3777. }
  3778. }
  3779. }
  3780. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3781. /* dst address space is register */
  3782. if (((info & 0x00300000) >> 20) == 0) {
  3783. start_reg = ib[idx + 2];
  3784. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3785. reg = start_reg;
  3786. if (!si_vm_reg_valid(reg)) {
  3787. DRM_ERROR("CP DMA Bad DST register\n");
  3788. return -EINVAL;
  3789. }
  3790. } else {
  3791. for (i = 0; i < (command & 0x1fffff); i++) {
  3792. reg = start_reg + (4 * i);
  3793. if (!si_vm_reg_valid(reg)) {
  3794. DRM_ERROR("CP DMA Bad DST register\n");
  3795. return -EINVAL;
  3796. }
  3797. }
  3798. }
  3799. }
  3800. }
  3801. return 0;
  3802. }
  3803. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3804. u32 *ib, struct radeon_cs_packet *pkt)
  3805. {
  3806. int r;
  3807. u32 idx = pkt->idx + 1;
  3808. u32 idx_value = ib[idx];
  3809. u32 start_reg, end_reg, reg, i;
  3810. switch (pkt->opcode) {
  3811. case PACKET3_NOP:
  3812. case PACKET3_SET_BASE:
  3813. case PACKET3_CLEAR_STATE:
  3814. case PACKET3_INDEX_BUFFER_SIZE:
  3815. case PACKET3_DISPATCH_DIRECT:
  3816. case PACKET3_DISPATCH_INDIRECT:
  3817. case PACKET3_ALLOC_GDS:
  3818. case PACKET3_WRITE_GDS_RAM:
  3819. case PACKET3_ATOMIC_GDS:
  3820. case PACKET3_ATOMIC:
  3821. case PACKET3_OCCLUSION_QUERY:
  3822. case PACKET3_SET_PREDICATION:
  3823. case PACKET3_COND_EXEC:
  3824. case PACKET3_PRED_EXEC:
  3825. case PACKET3_DRAW_INDIRECT:
  3826. case PACKET3_DRAW_INDEX_INDIRECT:
  3827. case PACKET3_INDEX_BASE:
  3828. case PACKET3_DRAW_INDEX_2:
  3829. case PACKET3_CONTEXT_CONTROL:
  3830. case PACKET3_INDEX_TYPE:
  3831. case PACKET3_DRAW_INDIRECT_MULTI:
  3832. case PACKET3_DRAW_INDEX_AUTO:
  3833. case PACKET3_DRAW_INDEX_IMMD:
  3834. case PACKET3_NUM_INSTANCES:
  3835. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3836. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3837. case PACKET3_DRAW_INDEX_OFFSET_2:
  3838. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3839. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3840. case PACKET3_MPEG_INDEX:
  3841. case PACKET3_WAIT_REG_MEM:
  3842. case PACKET3_MEM_WRITE:
  3843. case PACKET3_PFP_SYNC_ME:
  3844. case PACKET3_SURFACE_SYNC:
  3845. case PACKET3_EVENT_WRITE:
  3846. case PACKET3_EVENT_WRITE_EOP:
  3847. case PACKET3_EVENT_WRITE_EOS:
  3848. case PACKET3_SET_CONTEXT_REG:
  3849. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3850. case PACKET3_SET_SH_REG:
  3851. case PACKET3_SET_SH_REG_OFFSET:
  3852. case PACKET3_INCREMENT_DE_COUNTER:
  3853. case PACKET3_WAIT_ON_CE_COUNTER:
  3854. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3855. case PACKET3_ME_WRITE:
  3856. break;
  3857. case PACKET3_COPY_DATA:
  3858. if ((idx_value & 0xf00) == 0) {
  3859. reg = ib[idx + 3] * 4;
  3860. if (!si_vm_reg_valid(reg))
  3861. return -EINVAL;
  3862. }
  3863. break;
  3864. case PACKET3_WRITE_DATA:
  3865. if ((idx_value & 0xf00) == 0) {
  3866. start_reg = ib[idx + 1] * 4;
  3867. if (idx_value & 0x10000) {
  3868. if (!si_vm_reg_valid(start_reg))
  3869. return -EINVAL;
  3870. } else {
  3871. for (i = 0; i < (pkt->count - 2); i++) {
  3872. reg = start_reg + (4 * i);
  3873. if (!si_vm_reg_valid(reg))
  3874. return -EINVAL;
  3875. }
  3876. }
  3877. }
  3878. break;
  3879. case PACKET3_COND_WRITE:
  3880. if (idx_value & 0x100) {
  3881. reg = ib[idx + 5] * 4;
  3882. if (!si_vm_reg_valid(reg))
  3883. return -EINVAL;
  3884. }
  3885. break;
  3886. case PACKET3_COPY_DW:
  3887. if (idx_value & 0x2) {
  3888. reg = ib[idx + 3] * 4;
  3889. if (!si_vm_reg_valid(reg))
  3890. return -EINVAL;
  3891. }
  3892. break;
  3893. case PACKET3_SET_CONFIG_REG:
  3894. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3895. end_reg = 4 * pkt->count + start_reg - 4;
  3896. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3897. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3898. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3899. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3900. return -EINVAL;
  3901. }
  3902. for (i = 0; i < pkt->count; i++) {
  3903. reg = start_reg + (4 * i);
  3904. if (!si_vm_reg_valid(reg))
  3905. return -EINVAL;
  3906. }
  3907. break;
  3908. case PACKET3_CP_DMA:
  3909. r = si_vm_packet3_cp_dma_check(ib, idx);
  3910. if (r)
  3911. return r;
  3912. break;
  3913. default:
  3914. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3915. return -EINVAL;
  3916. }
  3917. return 0;
  3918. }
  3919. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3920. u32 *ib, struct radeon_cs_packet *pkt)
  3921. {
  3922. int r;
  3923. u32 idx = pkt->idx + 1;
  3924. u32 idx_value = ib[idx];
  3925. u32 start_reg, reg, i;
  3926. switch (pkt->opcode) {
  3927. case PACKET3_NOP:
  3928. case PACKET3_SET_BASE:
  3929. case PACKET3_CLEAR_STATE:
  3930. case PACKET3_DISPATCH_DIRECT:
  3931. case PACKET3_DISPATCH_INDIRECT:
  3932. case PACKET3_ALLOC_GDS:
  3933. case PACKET3_WRITE_GDS_RAM:
  3934. case PACKET3_ATOMIC_GDS:
  3935. case PACKET3_ATOMIC:
  3936. case PACKET3_OCCLUSION_QUERY:
  3937. case PACKET3_SET_PREDICATION:
  3938. case PACKET3_COND_EXEC:
  3939. case PACKET3_PRED_EXEC:
  3940. case PACKET3_CONTEXT_CONTROL:
  3941. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3942. case PACKET3_WAIT_REG_MEM:
  3943. case PACKET3_MEM_WRITE:
  3944. case PACKET3_PFP_SYNC_ME:
  3945. case PACKET3_SURFACE_SYNC:
  3946. case PACKET3_EVENT_WRITE:
  3947. case PACKET3_EVENT_WRITE_EOP:
  3948. case PACKET3_EVENT_WRITE_EOS:
  3949. case PACKET3_SET_CONTEXT_REG:
  3950. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3951. case PACKET3_SET_SH_REG:
  3952. case PACKET3_SET_SH_REG_OFFSET:
  3953. case PACKET3_INCREMENT_DE_COUNTER:
  3954. case PACKET3_WAIT_ON_CE_COUNTER:
  3955. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3956. case PACKET3_ME_WRITE:
  3957. break;
  3958. case PACKET3_COPY_DATA:
  3959. if ((idx_value & 0xf00) == 0) {
  3960. reg = ib[idx + 3] * 4;
  3961. if (!si_vm_reg_valid(reg))
  3962. return -EINVAL;
  3963. }
  3964. break;
  3965. case PACKET3_WRITE_DATA:
  3966. if ((idx_value & 0xf00) == 0) {
  3967. start_reg = ib[idx + 1] * 4;
  3968. if (idx_value & 0x10000) {
  3969. if (!si_vm_reg_valid(start_reg))
  3970. return -EINVAL;
  3971. } else {
  3972. for (i = 0; i < (pkt->count - 2); i++) {
  3973. reg = start_reg + (4 * i);
  3974. if (!si_vm_reg_valid(reg))
  3975. return -EINVAL;
  3976. }
  3977. }
  3978. }
  3979. break;
  3980. case PACKET3_COND_WRITE:
  3981. if (idx_value & 0x100) {
  3982. reg = ib[idx + 5] * 4;
  3983. if (!si_vm_reg_valid(reg))
  3984. return -EINVAL;
  3985. }
  3986. break;
  3987. case PACKET3_COPY_DW:
  3988. if (idx_value & 0x2) {
  3989. reg = ib[idx + 3] * 4;
  3990. if (!si_vm_reg_valid(reg))
  3991. return -EINVAL;
  3992. }
  3993. break;
  3994. case PACKET3_CP_DMA:
  3995. r = si_vm_packet3_cp_dma_check(ib, idx);
  3996. if (r)
  3997. return r;
  3998. break;
  3999. default:
  4000. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  4001. return -EINVAL;
  4002. }
  4003. return 0;
  4004. }
  4005. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  4006. {
  4007. int ret = 0;
  4008. u32 idx = 0;
  4009. struct radeon_cs_packet pkt;
  4010. do {
  4011. pkt.idx = idx;
  4012. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  4013. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  4014. pkt.one_reg_wr = 0;
  4015. switch (pkt.type) {
  4016. case RADEON_PACKET_TYPE0:
  4017. dev_err(rdev->dev, "Packet0 not allowed!\n");
  4018. ret = -EINVAL;
  4019. break;
  4020. case RADEON_PACKET_TYPE2:
  4021. idx += 1;
  4022. break;
  4023. case RADEON_PACKET_TYPE3:
  4024. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  4025. if (ib->is_const_ib)
  4026. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  4027. else {
  4028. switch (ib->ring) {
  4029. case RADEON_RING_TYPE_GFX_INDEX:
  4030. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  4031. break;
  4032. case CAYMAN_RING_TYPE_CP1_INDEX:
  4033. case CAYMAN_RING_TYPE_CP2_INDEX:
  4034. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  4035. break;
  4036. default:
  4037. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  4038. ret = -EINVAL;
  4039. break;
  4040. }
  4041. }
  4042. idx += pkt.count + 2;
  4043. break;
  4044. default:
  4045. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  4046. ret = -EINVAL;
  4047. break;
  4048. }
  4049. if (ret)
  4050. break;
  4051. } while (idx < ib->length_dw);
  4052. return ret;
  4053. }
  4054. /*
  4055. * vm
  4056. */
  4057. int si_vm_init(struct radeon_device *rdev)
  4058. {
  4059. /* number of VMs */
  4060. rdev->vm_manager.nvm = 16;
  4061. /* base offset of vram pages */
  4062. rdev->vm_manager.vram_base_offset = 0;
  4063. return 0;
  4064. }
  4065. void si_vm_fini(struct radeon_device *rdev)
  4066. {
  4067. }
  4068. /**
  4069. * si_vm_decode_fault - print human readable fault info
  4070. *
  4071. * @rdev: radeon_device pointer
  4072. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  4073. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  4074. *
  4075. * Print human readable fault information (SI).
  4076. */
  4077. static void si_vm_decode_fault(struct radeon_device *rdev,
  4078. u32 status, u32 addr)
  4079. {
  4080. u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  4081. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  4082. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  4083. char *block;
  4084. if (rdev->family == CHIP_TAHITI) {
  4085. switch (mc_id) {
  4086. case 160:
  4087. case 144:
  4088. case 96:
  4089. case 80:
  4090. case 224:
  4091. case 208:
  4092. case 32:
  4093. case 16:
  4094. block = "CB";
  4095. break;
  4096. case 161:
  4097. case 145:
  4098. case 97:
  4099. case 81:
  4100. case 225:
  4101. case 209:
  4102. case 33:
  4103. case 17:
  4104. block = "CB_FMASK";
  4105. break;
  4106. case 162:
  4107. case 146:
  4108. case 98:
  4109. case 82:
  4110. case 226:
  4111. case 210:
  4112. case 34:
  4113. case 18:
  4114. block = "CB_CMASK";
  4115. break;
  4116. case 163:
  4117. case 147:
  4118. case 99:
  4119. case 83:
  4120. case 227:
  4121. case 211:
  4122. case 35:
  4123. case 19:
  4124. block = "CB_IMMED";
  4125. break;
  4126. case 164:
  4127. case 148:
  4128. case 100:
  4129. case 84:
  4130. case 228:
  4131. case 212:
  4132. case 36:
  4133. case 20:
  4134. block = "DB";
  4135. break;
  4136. case 165:
  4137. case 149:
  4138. case 101:
  4139. case 85:
  4140. case 229:
  4141. case 213:
  4142. case 37:
  4143. case 21:
  4144. block = "DB_HTILE";
  4145. break;
  4146. case 167:
  4147. case 151:
  4148. case 103:
  4149. case 87:
  4150. case 231:
  4151. case 215:
  4152. case 39:
  4153. case 23:
  4154. block = "DB_STEN";
  4155. break;
  4156. case 72:
  4157. case 68:
  4158. case 64:
  4159. case 8:
  4160. case 4:
  4161. case 0:
  4162. case 136:
  4163. case 132:
  4164. case 128:
  4165. case 200:
  4166. case 196:
  4167. case 192:
  4168. block = "TC";
  4169. break;
  4170. case 112:
  4171. case 48:
  4172. block = "CP";
  4173. break;
  4174. case 49:
  4175. case 177:
  4176. case 50:
  4177. case 178:
  4178. block = "SH";
  4179. break;
  4180. case 53:
  4181. case 190:
  4182. block = "VGT";
  4183. break;
  4184. case 117:
  4185. block = "IH";
  4186. break;
  4187. case 51:
  4188. case 115:
  4189. block = "RLC";
  4190. break;
  4191. case 119:
  4192. case 183:
  4193. block = "DMA0";
  4194. break;
  4195. case 61:
  4196. block = "DMA1";
  4197. break;
  4198. case 248:
  4199. case 120:
  4200. block = "HDP";
  4201. break;
  4202. default:
  4203. block = "unknown";
  4204. break;
  4205. }
  4206. } else {
  4207. switch (mc_id) {
  4208. case 32:
  4209. case 16:
  4210. case 96:
  4211. case 80:
  4212. case 160:
  4213. case 144:
  4214. case 224:
  4215. case 208:
  4216. block = "CB";
  4217. break;
  4218. case 33:
  4219. case 17:
  4220. case 97:
  4221. case 81:
  4222. case 161:
  4223. case 145:
  4224. case 225:
  4225. case 209:
  4226. block = "CB_FMASK";
  4227. break;
  4228. case 34:
  4229. case 18:
  4230. case 98:
  4231. case 82:
  4232. case 162:
  4233. case 146:
  4234. case 226:
  4235. case 210:
  4236. block = "CB_CMASK";
  4237. break;
  4238. case 35:
  4239. case 19:
  4240. case 99:
  4241. case 83:
  4242. case 163:
  4243. case 147:
  4244. case 227:
  4245. case 211:
  4246. block = "CB_IMMED";
  4247. break;
  4248. case 36:
  4249. case 20:
  4250. case 100:
  4251. case 84:
  4252. case 164:
  4253. case 148:
  4254. case 228:
  4255. case 212:
  4256. block = "DB";
  4257. break;
  4258. case 37:
  4259. case 21:
  4260. case 101:
  4261. case 85:
  4262. case 165:
  4263. case 149:
  4264. case 229:
  4265. case 213:
  4266. block = "DB_HTILE";
  4267. break;
  4268. case 39:
  4269. case 23:
  4270. case 103:
  4271. case 87:
  4272. case 167:
  4273. case 151:
  4274. case 231:
  4275. case 215:
  4276. block = "DB_STEN";
  4277. break;
  4278. case 72:
  4279. case 68:
  4280. case 8:
  4281. case 4:
  4282. case 136:
  4283. case 132:
  4284. case 200:
  4285. case 196:
  4286. block = "TC";
  4287. break;
  4288. case 112:
  4289. case 48:
  4290. block = "CP";
  4291. break;
  4292. case 49:
  4293. case 177:
  4294. case 50:
  4295. case 178:
  4296. block = "SH";
  4297. break;
  4298. case 53:
  4299. block = "VGT";
  4300. break;
  4301. case 117:
  4302. block = "IH";
  4303. break;
  4304. case 51:
  4305. case 115:
  4306. block = "RLC";
  4307. break;
  4308. case 119:
  4309. case 183:
  4310. block = "DMA0";
  4311. break;
  4312. case 61:
  4313. block = "DMA1";
  4314. break;
  4315. case 248:
  4316. case 120:
  4317. block = "HDP";
  4318. break;
  4319. default:
  4320. block = "unknown";
  4321. break;
  4322. }
  4323. }
  4324. printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
  4325. protections, vmid, addr,
  4326. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  4327. block, mc_id);
  4328. }
  4329. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  4330. {
  4331. struct radeon_ring *ring = &rdev->ring[ridx];
  4332. if (vm == NULL)
  4333. return;
  4334. /* write new base address */
  4335. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4336. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4337. WRITE_DATA_DST_SEL(0)));
  4338. if (vm->id < 8) {
  4339. radeon_ring_write(ring,
  4340. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  4341. } else {
  4342. radeon_ring_write(ring,
  4343. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  4344. }
  4345. radeon_ring_write(ring, 0);
  4346. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  4347. /* flush hdp cache */
  4348. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4349. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4350. WRITE_DATA_DST_SEL(0)));
  4351. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  4352. radeon_ring_write(ring, 0);
  4353. radeon_ring_write(ring, 0x1);
  4354. /* bits 0-15 are the VM contexts0-15 */
  4355. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4356. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4357. WRITE_DATA_DST_SEL(0)));
  4358. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  4359. radeon_ring_write(ring, 0);
  4360. radeon_ring_write(ring, 1 << vm->id);
  4361. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  4362. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  4363. radeon_ring_write(ring, 0x0);
  4364. }
  4365. /*
  4366. * Power and clock gating
  4367. */
  4368. static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
  4369. {
  4370. int i;
  4371. for (i = 0; i < rdev->usec_timeout; i++) {
  4372. if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
  4373. break;
  4374. udelay(1);
  4375. }
  4376. for (i = 0; i < rdev->usec_timeout; i++) {
  4377. if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
  4378. break;
  4379. udelay(1);
  4380. }
  4381. }
  4382. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  4383. bool enable)
  4384. {
  4385. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  4386. u32 mask;
  4387. int i;
  4388. if (enable)
  4389. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4390. else
  4391. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4392. WREG32(CP_INT_CNTL_RING0, tmp);
  4393. if (!enable) {
  4394. /* read a gfx register */
  4395. tmp = RREG32(DB_DEPTH_INFO);
  4396. mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
  4397. for (i = 0; i < rdev->usec_timeout; i++) {
  4398. if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
  4399. break;
  4400. udelay(1);
  4401. }
  4402. }
  4403. }
  4404. static void si_set_uvd_dcm(struct radeon_device *rdev,
  4405. bool sw_mode)
  4406. {
  4407. u32 tmp, tmp2;
  4408. tmp = RREG32(UVD_CGC_CTRL);
  4409. tmp &= ~(CLK_OD_MASK | CG_DT_MASK);
  4410. tmp |= DCM | CG_DT(1) | CLK_OD(4);
  4411. if (sw_mode) {
  4412. tmp &= ~0x7ffff800;
  4413. tmp2 = DYN_OR_EN | DYN_RR_EN | G_DIV_ID(7);
  4414. } else {
  4415. tmp |= 0x7ffff800;
  4416. tmp2 = 0;
  4417. }
  4418. WREG32(UVD_CGC_CTRL, tmp);
  4419. WREG32_UVD_CTX(UVD_CGC_CTRL2, tmp2);
  4420. }
  4421. void si_init_uvd_internal_cg(struct radeon_device *rdev)
  4422. {
  4423. bool hw_mode = true;
  4424. if (hw_mode) {
  4425. si_set_uvd_dcm(rdev, false);
  4426. } else {
  4427. u32 tmp = RREG32(UVD_CGC_CTRL);
  4428. tmp &= ~DCM;
  4429. WREG32(UVD_CGC_CTRL, tmp);
  4430. }
  4431. }
  4432. static u32 si_halt_rlc(struct radeon_device *rdev)
  4433. {
  4434. u32 data, orig;
  4435. orig = data = RREG32(RLC_CNTL);
  4436. if (data & RLC_ENABLE) {
  4437. data &= ~RLC_ENABLE;
  4438. WREG32(RLC_CNTL, data);
  4439. si_wait_for_rlc_serdes(rdev);
  4440. }
  4441. return orig;
  4442. }
  4443. static void si_update_rlc(struct radeon_device *rdev, u32 rlc)
  4444. {
  4445. u32 tmp;
  4446. tmp = RREG32(RLC_CNTL);
  4447. if (tmp != rlc)
  4448. WREG32(RLC_CNTL, rlc);
  4449. }
  4450. static void si_enable_dma_pg(struct radeon_device *rdev, bool enable)
  4451. {
  4452. u32 data, orig;
  4453. orig = data = RREG32(DMA_PG);
  4454. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA))
  4455. data |= PG_CNTL_ENABLE;
  4456. else
  4457. data &= ~PG_CNTL_ENABLE;
  4458. if (orig != data)
  4459. WREG32(DMA_PG, data);
  4460. }
  4461. static void si_init_dma_pg(struct radeon_device *rdev)
  4462. {
  4463. u32 tmp;
  4464. WREG32(DMA_PGFSM_WRITE, 0x00002000);
  4465. WREG32(DMA_PGFSM_CONFIG, 0x100010ff);
  4466. for (tmp = 0; tmp < 5; tmp++)
  4467. WREG32(DMA_PGFSM_WRITE, 0);
  4468. }
  4469. static void si_enable_gfx_cgpg(struct radeon_device *rdev,
  4470. bool enable)
  4471. {
  4472. u32 tmp;
  4473. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
  4474. tmp = RLC_PUD(0x10) | RLC_PDD(0x10) | RLC_TTPD(0x10) | RLC_MSD(0x10);
  4475. WREG32(RLC_TTOP_D, tmp);
  4476. tmp = RREG32(RLC_PG_CNTL);
  4477. tmp |= GFX_PG_ENABLE;
  4478. WREG32(RLC_PG_CNTL, tmp);
  4479. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4480. tmp |= AUTO_PG_EN;
  4481. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4482. } else {
  4483. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4484. tmp &= ~AUTO_PG_EN;
  4485. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4486. tmp = RREG32(DB_RENDER_CONTROL);
  4487. }
  4488. }
  4489. static void si_init_gfx_cgpg(struct radeon_device *rdev)
  4490. {
  4491. u32 tmp;
  4492. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4493. tmp = RREG32(RLC_PG_CNTL);
  4494. tmp |= GFX_PG_SRC;
  4495. WREG32(RLC_PG_CNTL, tmp);
  4496. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4497. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4498. tmp &= ~GRBM_REG_SGIT_MASK;
  4499. tmp |= GRBM_REG_SGIT(0x700);
  4500. tmp &= ~PG_AFTER_GRBM_REG_ST_MASK;
  4501. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4502. }
  4503. static u32 si_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
  4504. {
  4505. u32 mask = 0, tmp, tmp1;
  4506. int i;
  4507. si_select_se_sh(rdev, se, sh);
  4508. tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  4509. tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  4510. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4511. tmp &= 0xffff0000;
  4512. tmp |= tmp1;
  4513. tmp >>= 16;
  4514. for (i = 0; i < rdev->config.si.max_cu_per_sh; i ++) {
  4515. mask <<= 1;
  4516. mask |= 1;
  4517. }
  4518. return (~tmp) & mask;
  4519. }
  4520. static void si_init_ao_cu_mask(struct radeon_device *rdev)
  4521. {
  4522. u32 i, j, k, active_cu_number = 0;
  4523. u32 mask, counter, cu_bitmap;
  4524. u32 tmp = 0;
  4525. for (i = 0; i < rdev->config.si.max_shader_engines; i++) {
  4526. for (j = 0; j < rdev->config.si.max_sh_per_se; j++) {
  4527. mask = 1;
  4528. cu_bitmap = 0;
  4529. counter = 0;
  4530. for (k = 0; k < rdev->config.si.max_cu_per_sh; k++) {
  4531. if (si_get_cu_active_bitmap(rdev, i, j) & mask) {
  4532. if (counter < 2)
  4533. cu_bitmap |= mask;
  4534. counter++;
  4535. }
  4536. mask <<= 1;
  4537. }
  4538. active_cu_number += counter;
  4539. tmp |= (cu_bitmap << (i * 16 + j * 8));
  4540. }
  4541. }
  4542. WREG32(RLC_PG_AO_CU_MASK, tmp);
  4543. tmp = RREG32(RLC_MAX_PG_CU);
  4544. tmp &= ~MAX_PU_CU_MASK;
  4545. tmp |= MAX_PU_CU(active_cu_number);
  4546. WREG32(RLC_MAX_PG_CU, tmp);
  4547. }
  4548. static void si_enable_cgcg(struct radeon_device *rdev,
  4549. bool enable)
  4550. {
  4551. u32 data, orig, tmp;
  4552. orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
  4553. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
  4554. si_enable_gui_idle_interrupt(rdev, true);
  4555. WREG32(RLC_GCPM_GENERAL_3, 0x00000080);
  4556. tmp = si_halt_rlc(rdev);
  4557. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4558. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4559. WREG32(RLC_SERDES_WR_CTRL, 0x00b000ff);
  4560. si_wait_for_rlc_serdes(rdev);
  4561. si_update_rlc(rdev, tmp);
  4562. WREG32(RLC_SERDES_WR_CTRL, 0x007000ff);
  4563. data |= CGCG_EN | CGLS_EN;
  4564. } else {
  4565. si_enable_gui_idle_interrupt(rdev, false);
  4566. RREG32(CB_CGTT_SCLK_CTRL);
  4567. RREG32(CB_CGTT_SCLK_CTRL);
  4568. RREG32(CB_CGTT_SCLK_CTRL);
  4569. RREG32(CB_CGTT_SCLK_CTRL);
  4570. data &= ~(CGCG_EN | CGLS_EN);
  4571. }
  4572. if (orig != data)
  4573. WREG32(RLC_CGCG_CGLS_CTRL, data);
  4574. }
  4575. static void si_enable_mgcg(struct radeon_device *rdev,
  4576. bool enable)
  4577. {
  4578. u32 data, orig, tmp = 0;
  4579. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
  4580. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4581. data = 0x96940200;
  4582. if (orig != data)
  4583. WREG32(CGTS_SM_CTRL_REG, data);
  4584. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
  4585. orig = data = RREG32(CP_MEM_SLP_CNTL);
  4586. data |= CP_MEM_LS_EN;
  4587. if (orig != data)
  4588. WREG32(CP_MEM_SLP_CNTL, data);
  4589. }
  4590. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4591. data &= 0xffffffc0;
  4592. if (orig != data)
  4593. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4594. tmp = si_halt_rlc(rdev);
  4595. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4596. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4597. WREG32(RLC_SERDES_WR_CTRL, 0x00d000ff);
  4598. si_update_rlc(rdev, tmp);
  4599. } else {
  4600. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4601. data |= 0x00000003;
  4602. if (orig != data)
  4603. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4604. data = RREG32(CP_MEM_SLP_CNTL);
  4605. if (data & CP_MEM_LS_EN) {
  4606. data &= ~CP_MEM_LS_EN;
  4607. WREG32(CP_MEM_SLP_CNTL, data);
  4608. }
  4609. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4610. data |= LS_OVERRIDE | OVERRIDE;
  4611. if (orig != data)
  4612. WREG32(CGTS_SM_CTRL_REG, data);
  4613. tmp = si_halt_rlc(rdev);
  4614. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4615. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4616. WREG32(RLC_SERDES_WR_CTRL, 0x00e000ff);
  4617. si_update_rlc(rdev, tmp);
  4618. }
  4619. }
  4620. static void si_enable_uvd_mgcg(struct radeon_device *rdev,
  4621. bool enable)
  4622. {
  4623. u32 orig, data, tmp;
  4624. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
  4625. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4626. tmp |= 0x3fff;
  4627. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4628. orig = data = RREG32(UVD_CGC_CTRL);
  4629. data |= DCM;
  4630. if (orig != data)
  4631. WREG32(UVD_CGC_CTRL, data);
  4632. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0);
  4633. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0);
  4634. } else {
  4635. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4636. tmp &= ~0x3fff;
  4637. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4638. orig = data = RREG32(UVD_CGC_CTRL);
  4639. data &= ~DCM;
  4640. if (orig != data)
  4641. WREG32(UVD_CGC_CTRL, data);
  4642. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0xffffffff);
  4643. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0xffffffff);
  4644. }
  4645. }
  4646. static const u32 mc_cg_registers[] =
  4647. {
  4648. MC_HUB_MISC_HUB_CG,
  4649. MC_HUB_MISC_SIP_CG,
  4650. MC_HUB_MISC_VM_CG,
  4651. MC_XPB_CLK_GAT,
  4652. ATC_MISC_CG,
  4653. MC_CITF_MISC_WR_CG,
  4654. MC_CITF_MISC_RD_CG,
  4655. MC_CITF_MISC_VM_CG,
  4656. VM_L2_CG,
  4657. };
  4658. static void si_enable_mc_ls(struct radeon_device *rdev,
  4659. bool enable)
  4660. {
  4661. int i;
  4662. u32 orig, data;
  4663. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4664. orig = data = RREG32(mc_cg_registers[i]);
  4665. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
  4666. data |= MC_LS_ENABLE;
  4667. else
  4668. data &= ~MC_LS_ENABLE;
  4669. if (data != orig)
  4670. WREG32(mc_cg_registers[i], data);
  4671. }
  4672. }
  4673. static void si_enable_mc_mgcg(struct radeon_device *rdev,
  4674. bool enable)
  4675. {
  4676. int i;
  4677. u32 orig, data;
  4678. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4679. orig = data = RREG32(mc_cg_registers[i]);
  4680. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
  4681. data |= MC_CG_ENABLE;
  4682. else
  4683. data &= ~MC_CG_ENABLE;
  4684. if (data != orig)
  4685. WREG32(mc_cg_registers[i], data);
  4686. }
  4687. }
  4688. static void si_enable_dma_mgcg(struct radeon_device *rdev,
  4689. bool enable)
  4690. {
  4691. u32 orig, data, offset;
  4692. int i;
  4693. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
  4694. for (i = 0; i < 2; i++) {
  4695. if (i == 0)
  4696. offset = DMA0_REGISTER_OFFSET;
  4697. else
  4698. offset = DMA1_REGISTER_OFFSET;
  4699. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4700. data &= ~MEM_POWER_OVERRIDE;
  4701. if (data != orig)
  4702. WREG32(DMA_POWER_CNTL + offset, data);
  4703. WREG32(DMA_CLK_CTRL + offset, 0x00000100);
  4704. }
  4705. } else {
  4706. for (i = 0; i < 2; i++) {
  4707. if (i == 0)
  4708. offset = DMA0_REGISTER_OFFSET;
  4709. else
  4710. offset = DMA1_REGISTER_OFFSET;
  4711. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4712. data |= MEM_POWER_OVERRIDE;
  4713. if (data != orig)
  4714. WREG32(DMA_POWER_CNTL + offset, data);
  4715. orig = data = RREG32(DMA_CLK_CTRL + offset);
  4716. data = 0xff000000;
  4717. if (data != orig)
  4718. WREG32(DMA_CLK_CTRL + offset, data);
  4719. }
  4720. }
  4721. }
  4722. static void si_enable_bif_mgls(struct radeon_device *rdev,
  4723. bool enable)
  4724. {
  4725. u32 orig, data;
  4726. orig = data = RREG32_PCIE(PCIE_CNTL2);
  4727. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
  4728. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4729. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
  4730. else
  4731. data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4732. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
  4733. if (orig != data)
  4734. WREG32_PCIE(PCIE_CNTL2, data);
  4735. }
  4736. static void si_enable_hdp_mgcg(struct radeon_device *rdev,
  4737. bool enable)
  4738. {
  4739. u32 orig, data;
  4740. orig = data = RREG32(HDP_HOST_PATH_CNTL);
  4741. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
  4742. data &= ~CLOCK_GATING_DIS;
  4743. else
  4744. data |= CLOCK_GATING_DIS;
  4745. if (orig != data)
  4746. WREG32(HDP_HOST_PATH_CNTL, data);
  4747. }
  4748. static void si_enable_hdp_ls(struct radeon_device *rdev,
  4749. bool enable)
  4750. {
  4751. u32 orig, data;
  4752. orig = data = RREG32(HDP_MEM_POWER_LS);
  4753. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
  4754. data |= HDP_LS_ENABLE;
  4755. else
  4756. data &= ~HDP_LS_ENABLE;
  4757. if (orig != data)
  4758. WREG32(HDP_MEM_POWER_LS, data);
  4759. }
  4760. void si_update_cg(struct radeon_device *rdev,
  4761. u32 block, bool enable)
  4762. {
  4763. if (block & RADEON_CG_BLOCK_GFX) {
  4764. si_enable_gui_idle_interrupt(rdev, false);
  4765. /* order matters! */
  4766. if (enable) {
  4767. si_enable_mgcg(rdev, true);
  4768. si_enable_cgcg(rdev, true);
  4769. } else {
  4770. si_enable_cgcg(rdev, false);
  4771. si_enable_mgcg(rdev, false);
  4772. }
  4773. si_enable_gui_idle_interrupt(rdev, true);
  4774. }
  4775. if (block & RADEON_CG_BLOCK_MC) {
  4776. si_enable_mc_mgcg(rdev, enable);
  4777. si_enable_mc_ls(rdev, enable);
  4778. }
  4779. if (block & RADEON_CG_BLOCK_SDMA) {
  4780. si_enable_dma_mgcg(rdev, enable);
  4781. }
  4782. if (block & RADEON_CG_BLOCK_BIF) {
  4783. si_enable_bif_mgls(rdev, enable);
  4784. }
  4785. if (block & RADEON_CG_BLOCK_UVD) {
  4786. if (rdev->has_uvd) {
  4787. si_enable_uvd_mgcg(rdev, enable);
  4788. }
  4789. }
  4790. if (block & RADEON_CG_BLOCK_HDP) {
  4791. si_enable_hdp_mgcg(rdev, enable);
  4792. si_enable_hdp_ls(rdev, enable);
  4793. }
  4794. }
  4795. static void si_init_cg(struct radeon_device *rdev)
  4796. {
  4797. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4798. RADEON_CG_BLOCK_MC |
  4799. RADEON_CG_BLOCK_SDMA |
  4800. RADEON_CG_BLOCK_BIF |
  4801. RADEON_CG_BLOCK_HDP), true);
  4802. if (rdev->has_uvd) {
  4803. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
  4804. si_init_uvd_internal_cg(rdev);
  4805. }
  4806. }
  4807. static void si_fini_cg(struct radeon_device *rdev)
  4808. {
  4809. if (rdev->has_uvd) {
  4810. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
  4811. }
  4812. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4813. RADEON_CG_BLOCK_MC |
  4814. RADEON_CG_BLOCK_SDMA |
  4815. RADEON_CG_BLOCK_BIF |
  4816. RADEON_CG_BLOCK_HDP), false);
  4817. }
  4818. u32 si_get_csb_size(struct radeon_device *rdev)
  4819. {
  4820. u32 count = 0;
  4821. const struct cs_section_def *sect = NULL;
  4822. const struct cs_extent_def *ext = NULL;
  4823. if (rdev->rlc.cs_data == NULL)
  4824. return 0;
  4825. /* begin clear state */
  4826. count += 2;
  4827. /* context control state */
  4828. count += 3;
  4829. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4830. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4831. if (sect->id == SECT_CONTEXT)
  4832. count += 2 + ext->reg_count;
  4833. else
  4834. return 0;
  4835. }
  4836. }
  4837. /* pa_sc_raster_config */
  4838. count += 3;
  4839. /* end clear state */
  4840. count += 2;
  4841. /* clear state */
  4842. count += 2;
  4843. return count;
  4844. }
  4845. void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
  4846. {
  4847. u32 count = 0, i;
  4848. const struct cs_section_def *sect = NULL;
  4849. const struct cs_extent_def *ext = NULL;
  4850. if (rdev->rlc.cs_data == NULL)
  4851. return;
  4852. if (buffer == NULL)
  4853. return;
  4854. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4855. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  4856. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  4857. buffer[count++] = cpu_to_le32(0x80000000);
  4858. buffer[count++] = cpu_to_le32(0x80000000);
  4859. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4860. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4861. if (sect->id == SECT_CONTEXT) {
  4862. buffer[count++] =
  4863. cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  4864. buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
  4865. for (i = 0; i < ext->reg_count; i++)
  4866. buffer[count++] = cpu_to_le32(ext->extent[i]);
  4867. } else {
  4868. return;
  4869. }
  4870. }
  4871. }
  4872. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  4873. buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  4874. switch (rdev->family) {
  4875. case CHIP_TAHITI:
  4876. case CHIP_PITCAIRN:
  4877. buffer[count++] = cpu_to_le32(0x2a00126a);
  4878. break;
  4879. case CHIP_VERDE:
  4880. buffer[count++] = cpu_to_le32(0x0000124a);
  4881. break;
  4882. case CHIP_OLAND:
  4883. buffer[count++] = cpu_to_le32(0x00000082);
  4884. break;
  4885. case CHIP_HAINAN:
  4886. buffer[count++] = cpu_to_le32(0x00000000);
  4887. break;
  4888. default:
  4889. buffer[count++] = cpu_to_le32(0x00000000);
  4890. break;
  4891. }
  4892. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4893. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
  4894. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
  4895. buffer[count++] = cpu_to_le32(0);
  4896. }
  4897. static void si_init_pg(struct radeon_device *rdev)
  4898. {
  4899. if (rdev->pg_flags) {
  4900. if (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA) {
  4901. si_init_dma_pg(rdev);
  4902. }
  4903. si_init_ao_cu_mask(rdev);
  4904. if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
  4905. si_init_gfx_cgpg(rdev);
  4906. }
  4907. si_enable_dma_pg(rdev, true);
  4908. si_enable_gfx_cgpg(rdev, true);
  4909. } else {
  4910. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4911. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4912. }
  4913. }
  4914. static void si_fini_pg(struct radeon_device *rdev)
  4915. {
  4916. if (rdev->pg_flags) {
  4917. si_enable_dma_pg(rdev, false);
  4918. si_enable_gfx_cgpg(rdev, false);
  4919. }
  4920. }
  4921. /*
  4922. * RLC
  4923. */
  4924. void si_rlc_reset(struct radeon_device *rdev)
  4925. {
  4926. u32 tmp = RREG32(GRBM_SOFT_RESET);
  4927. tmp |= SOFT_RESET_RLC;
  4928. WREG32(GRBM_SOFT_RESET, tmp);
  4929. udelay(50);
  4930. tmp &= ~SOFT_RESET_RLC;
  4931. WREG32(GRBM_SOFT_RESET, tmp);
  4932. udelay(50);
  4933. }
  4934. static void si_rlc_stop(struct radeon_device *rdev)
  4935. {
  4936. WREG32(RLC_CNTL, 0);
  4937. si_enable_gui_idle_interrupt(rdev, false);
  4938. si_wait_for_rlc_serdes(rdev);
  4939. }
  4940. static void si_rlc_start(struct radeon_device *rdev)
  4941. {
  4942. WREG32(RLC_CNTL, RLC_ENABLE);
  4943. si_enable_gui_idle_interrupt(rdev, true);
  4944. udelay(50);
  4945. }
  4946. static bool si_lbpw_supported(struct radeon_device *rdev)
  4947. {
  4948. u32 tmp;
  4949. /* Enable LBPW only for DDR3 */
  4950. tmp = RREG32(MC_SEQ_MISC0);
  4951. if ((tmp & 0xF0000000) == 0xB0000000)
  4952. return true;
  4953. return false;
  4954. }
  4955. static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
  4956. {
  4957. u32 tmp;
  4958. tmp = RREG32(RLC_LB_CNTL);
  4959. if (enable)
  4960. tmp |= LOAD_BALANCE_ENABLE;
  4961. else
  4962. tmp &= ~LOAD_BALANCE_ENABLE;
  4963. WREG32(RLC_LB_CNTL, tmp);
  4964. if (!enable) {
  4965. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4966. WREG32(SPI_LB_CU_MASK, 0x00ff);
  4967. }
  4968. }
  4969. static int si_rlc_resume(struct radeon_device *rdev)
  4970. {
  4971. u32 i;
  4972. const __be32 *fw_data;
  4973. if (!rdev->rlc_fw)
  4974. return -EINVAL;
  4975. si_rlc_stop(rdev);
  4976. si_rlc_reset(rdev);
  4977. si_init_pg(rdev);
  4978. si_init_cg(rdev);
  4979. WREG32(RLC_RL_BASE, 0);
  4980. WREG32(RLC_RL_SIZE, 0);
  4981. WREG32(RLC_LB_CNTL, 0);
  4982. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  4983. WREG32(RLC_LB_CNTR_INIT, 0);
  4984. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  4985. WREG32(RLC_MC_CNTL, 0);
  4986. WREG32(RLC_UCODE_CNTL, 0);
  4987. fw_data = (const __be32 *)rdev->rlc_fw->data;
  4988. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  4989. WREG32(RLC_UCODE_ADDR, i);
  4990. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4991. }
  4992. WREG32(RLC_UCODE_ADDR, 0);
  4993. si_enable_lbpw(rdev, si_lbpw_supported(rdev));
  4994. si_rlc_start(rdev);
  4995. return 0;
  4996. }
  4997. static void si_enable_interrupts(struct radeon_device *rdev)
  4998. {
  4999. u32 ih_cntl = RREG32(IH_CNTL);
  5000. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5001. ih_cntl |= ENABLE_INTR;
  5002. ih_rb_cntl |= IH_RB_ENABLE;
  5003. WREG32(IH_CNTL, ih_cntl);
  5004. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5005. rdev->ih.enabled = true;
  5006. }
  5007. static void si_disable_interrupts(struct radeon_device *rdev)
  5008. {
  5009. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5010. u32 ih_cntl = RREG32(IH_CNTL);
  5011. ih_rb_cntl &= ~IH_RB_ENABLE;
  5012. ih_cntl &= ~ENABLE_INTR;
  5013. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5014. WREG32(IH_CNTL, ih_cntl);
  5015. /* set rptr, wptr to 0 */
  5016. WREG32(IH_RB_RPTR, 0);
  5017. WREG32(IH_RB_WPTR, 0);
  5018. rdev->ih.enabled = false;
  5019. rdev->ih.rptr = 0;
  5020. }
  5021. static void si_disable_interrupt_state(struct radeon_device *rdev)
  5022. {
  5023. u32 tmp;
  5024. tmp = RREG32(CP_INT_CNTL_RING0) &
  5025. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5026. WREG32(CP_INT_CNTL_RING0, tmp);
  5027. WREG32(CP_INT_CNTL_RING1, 0);
  5028. WREG32(CP_INT_CNTL_RING2, 0);
  5029. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5030. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  5031. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5032. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  5033. WREG32(GRBM_INT_CNTL, 0);
  5034. if (rdev->num_crtc >= 2) {
  5035. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5036. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5037. }
  5038. if (rdev->num_crtc >= 4) {
  5039. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5040. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5041. }
  5042. if (rdev->num_crtc >= 6) {
  5043. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5044. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5045. }
  5046. if (rdev->num_crtc >= 2) {
  5047. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5048. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5049. }
  5050. if (rdev->num_crtc >= 4) {
  5051. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5052. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5053. }
  5054. if (rdev->num_crtc >= 6) {
  5055. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5056. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5057. }
  5058. if (!ASIC_IS_NODCE(rdev)) {
  5059. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  5060. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5061. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5062. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5063. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5064. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5065. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5066. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5067. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5068. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5069. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5070. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5071. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5072. }
  5073. }
  5074. static int si_irq_init(struct radeon_device *rdev)
  5075. {
  5076. int ret = 0;
  5077. int rb_bufsz;
  5078. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  5079. /* allocate ring */
  5080. ret = r600_ih_ring_alloc(rdev);
  5081. if (ret)
  5082. return ret;
  5083. /* disable irqs */
  5084. si_disable_interrupts(rdev);
  5085. /* init rlc */
  5086. ret = si_rlc_resume(rdev);
  5087. if (ret) {
  5088. r600_ih_ring_fini(rdev);
  5089. return ret;
  5090. }
  5091. /* setup interrupt control */
  5092. /* set dummy read address to ring address */
  5093. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  5094. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  5095. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  5096. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  5097. */
  5098. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  5099. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  5100. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  5101. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  5102. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  5103. rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
  5104. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  5105. IH_WPTR_OVERFLOW_CLEAR |
  5106. (rb_bufsz << 1));
  5107. if (rdev->wb.enabled)
  5108. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  5109. /* set the writeback address whether it's enabled or not */
  5110. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  5111. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  5112. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5113. /* set rptr, wptr to 0 */
  5114. WREG32(IH_RB_RPTR, 0);
  5115. WREG32(IH_RB_WPTR, 0);
  5116. /* Default settings for IH_CNTL (disabled at first) */
  5117. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  5118. /* RPTR_REARM only works if msi's are enabled */
  5119. if (rdev->msi_enabled)
  5120. ih_cntl |= RPTR_REARM;
  5121. WREG32(IH_CNTL, ih_cntl);
  5122. /* force the active interrupt state to all disabled */
  5123. si_disable_interrupt_state(rdev);
  5124. pci_set_master(rdev->pdev);
  5125. /* enable irqs */
  5126. si_enable_interrupts(rdev);
  5127. return ret;
  5128. }
  5129. int si_irq_set(struct radeon_device *rdev)
  5130. {
  5131. u32 cp_int_cntl;
  5132. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  5133. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  5134. u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  5135. u32 grbm_int_cntl = 0;
  5136. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  5137. u32 dma_cntl, dma_cntl1;
  5138. u32 thermal_int = 0;
  5139. if (!rdev->irq.installed) {
  5140. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  5141. return -EINVAL;
  5142. }
  5143. /* don't enable anything if the ih is disabled */
  5144. if (!rdev->ih.enabled) {
  5145. si_disable_interrupts(rdev);
  5146. /* force the active interrupt state to all disabled */
  5147. si_disable_interrupt_state(rdev);
  5148. return 0;
  5149. }
  5150. cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
  5151. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5152. if (!ASIC_IS_NODCE(rdev)) {
  5153. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5154. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5155. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5156. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5157. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5158. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5159. }
  5160. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5161. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5162. thermal_int = RREG32(CG_THERMAL_INT) &
  5163. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  5164. /* enable CP interrupts on all rings */
  5165. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  5166. DRM_DEBUG("si_irq_set: sw int gfx\n");
  5167. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  5168. }
  5169. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  5170. DRM_DEBUG("si_irq_set: sw int cp1\n");
  5171. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  5172. }
  5173. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  5174. DRM_DEBUG("si_irq_set: sw int cp2\n");
  5175. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  5176. }
  5177. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  5178. DRM_DEBUG("si_irq_set: sw int dma\n");
  5179. dma_cntl |= TRAP_ENABLE;
  5180. }
  5181. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  5182. DRM_DEBUG("si_irq_set: sw int dma1\n");
  5183. dma_cntl1 |= TRAP_ENABLE;
  5184. }
  5185. if (rdev->irq.crtc_vblank_int[0] ||
  5186. atomic_read(&rdev->irq.pflip[0])) {
  5187. DRM_DEBUG("si_irq_set: vblank 0\n");
  5188. crtc1 |= VBLANK_INT_MASK;
  5189. }
  5190. if (rdev->irq.crtc_vblank_int[1] ||
  5191. atomic_read(&rdev->irq.pflip[1])) {
  5192. DRM_DEBUG("si_irq_set: vblank 1\n");
  5193. crtc2 |= VBLANK_INT_MASK;
  5194. }
  5195. if (rdev->irq.crtc_vblank_int[2] ||
  5196. atomic_read(&rdev->irq.pflip[2])) {
  5197. DRM_DEBUG("si_irq_set: vblank 2\n");
  5198. crtc3 |= VBLANK_INT_MASK;
  5199. }
  5200. if (rdev->irq.crtc_vblank_int[3] ||
  5201. atomic_read(&rdev->irq.pflip[3])) {
  5202. DRM_DEBUG("si_irq_set: vblank 3\n");
  5203. crtc4 |= VBLANK_INT_MASK;
  5204. }
  5205. if (rdev->irq.crtc_vblank_int[4] ||
  5206. atomic_read(&rdev->irq.pflip[4])) {
  5207. DRM_DEBUG("si_irq_set: vblank 4\n");
  5208. crtc5 |= VBLANK_INT_MASK;
  5209. }
  5210. if (rdev->irq.crtc_vblank_int[5] ||
  5211. atomic_read(&rdev->irq.pflip[5])) {
  5212. DRM_DEBUG("si_irq_set: vblank 5\n");
  5213. crtc6 |= VBLANK_INT_MASK;
  5214. }
  5215. if (rdev->irq.hpd[0]) {
  5216. DRM_DEBUG("si_irq_set: hpd 1\n");
  5217. hpd1 |= DC_HPDx_INT_EN;
  5218. }
  5219. if (rdev->irq.hpd[1]) {
  5220. DRM_DEBUG("si_irq_set: hpd 2\n");
  5221. hpd2 |= DC_HPDx_INT_EN;
  5222. }
  5223. if (rdev->irq.hpd[2]) {
  5224. DRM_DEBUG("si_irq_set: hpd 3\n");
  5225. hpd3 |= DC_HPDx_INT_EN;
  5226. }
  5227. if (rdev->irq.hpd[3]) {
  5228. DRM_DEBUG("si_irq_set: hpd 4\n");
  5229. hpd4 |= DC_HPDx_INT_EN;
  5230. }
  5231. if (rdev->irq.hpd[4]) {
  5232. DRM_DEBUG("si_irq_set: hpd 5\n");
  5233. hpd5 |= DC_HPDx_INT_EN;
  5234. }
  5235. if (rdev->irq.hpd[5]) {
  5236. DRM_DEBUG("si_irq_set: hpd 6\n");
  5237. hpd6 |= DC_HPDx_INT_EN;
  5238. }
  5239. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  5240. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  5241. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  5242. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  5243. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  5244. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  5245. if (rdev->irq.dpm_thermal) {
  5246. DRM_DEBUG("dpm thermal\n");
  5247. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  5248. }
  5249. if (rdev->num_crtc >= 2) {
  5250. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  5251. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  5252. }
  5253. if (rdev->num_crtc >= 4) {
  5254. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  5255. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  5256. }
  5257. if (rdev->num_crtc >= 6) {
  5258. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  5259. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  5260. }
  5261. if (rdev->num_crtc >= 2) {
  5262. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  5263. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  5264. }
  5265. if (rdev->num_crtc >= 4) {
  5266. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  5267. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  5268. }
  5269. if (rdev->num_crtc >= 6) {
  5270. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  5271. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  5272. }
  5273. if (!ASIC_IS_NODCE(rdev)) {
  5274. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  5275. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  5276. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  5277. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  5278. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  5279. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  5280. }
  5281. WREG32(CG_THERMAL_INT, thermal_int);
  5282. return 0;
  5283. }
  5284. static inline void si_irq_ack(struct radeon_device *rdev)
  5285. {
  5286. u32 tmp;
  5287. if (ASIC_IS_NODCE(rdev))
  5288. return;
  5289. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  5290. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  5291. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  5292. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  5293. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  5294. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  5295. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  5296. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  5297. if (rdev->num_crtc >= 4) {
  5298. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  5299. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  5300. }
  5301. if (rdev->num_crtc >= 6) {
  5302. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  5303. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  5304. }
  5305. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  5306. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5307. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  5308. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5309. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  5310. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  5311. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  5312. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  5313. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  5314. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  5315. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  5316. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  5317. if (rdev->num_crtc >= 4) {
  5318. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  5319. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5320. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  5321. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5322. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  5323. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  5324. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  5325. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  5326. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  5327. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  5328. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  5329. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  5330. }
  5331. if (rdev->num_crtc >= 6) {
  5332. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  5333. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5334. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  5335. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5336. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  5337. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  5338. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  5339. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  5340. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  5341. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  5342. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  5343. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  5344. }
  5345. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5346. tmp = RREG32(DC_HPD1_INT_CONTROL);
  5347. tmp |= DC_HPDx_INT_ACK;
  5348. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5349. }
  5350. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5351. tmp = RREG32(DC_HPD2_INT_CONTROL);
  5352. tmp |= DC_HPDx_INT_ACK;
  5353. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5354. }
  5355. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5356. tmp = RREG32(DC_HPD3_INT_CONTROL);
  5357. tmp |= DC_HPDx_INT_ACK;
  5358. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5359. }
  5360. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5361. tmp = RREG32(DC_HPD4_INT_CONTROL);
  5362. tmp |= DC_HPDx_INT_ACK;
  5363. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5364. }
  5365. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5366. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5367. tmp |= DC_HPDx_INT_ACK;
  5368. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5369. }
  5370. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5371. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5372. tmp |= DC_HPDx_INT_ACK;
  5373. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5374. }
  5375. }
  5376. static void si_irq_disable(struct radeon_device *rdev)
  5377. {
  5378. si_disable_interrupts(rdev);
  5379. /* Wait and acknowledge irq */
  5380. mdelay(1);
  5381. si_irq_ack(rdev);
  5382. si_disable_interrupt_state(rdev);
  5383. }
  5384. static void si_irq_suspend(struct radeon_device *rdev)
  5385. {
  5386. si_irq_disable(rdev);
  5387. si_rlc_stop(rdev);
  5388. }
  5389. static void si_irq_fini(struct radeon_device *rdev)
  5390. {
  5391. si_irq_suspend(rdev);
  5392. r600_ih_ring_fini(rdev);
  5393. }
  5394. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  5395. {
  5396. u32 wptr, tmp;
  5397. if (rdev->wb.enabled)
  5398. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  5399. else
  5400. wptr = RREG32(IH_RB_WPTR);
  5401. if (wptr & RB_OVERFLOW) {
  5402. /* When a ring buffer overflow happen start parsing interrupt
  5403. * from the last not overwritten vector (wptr + 16). Hopefully
  5404. * this should allow us to catchup.
  5405. */
  5406. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  5407. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  5408. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  5409. tmp = RREG32(IH_RB_CNTL);
  5410. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  5411. WREG32(IH_RB_CNTL, tmp);
  5412. }
  5413. return (wptr & rdev->ih.ptr_mask);
  5414. }
  5415. /* SI IV Ring
  5416. * Each IV ring entry is 128 bits:
  5417. * [7:0] - interrupt source id
  5418. * [31:8] - reserved
  5419. * [59:32] - interrupt source data
  5420. * [63:60] - reserved
  5421. * [71:64] - RINGID
  5422. * [79:72] - VMID
  5423. * [127:80] - reserved
  5424. */
  5425. int si_irq_process(struct radeon_device *rdev)
  5426. {
  5427. u32 wptr;
  5428. u32 rptr;
  5429. u32 src_id, src_data, ring_id;
  5430. u32 ring_index;
  5431. bool queue_hotplug = false;
  5432. bool queue_thermal = false;
  5433. u32 status, addr;
  5434. if (!rdev->ih.enabled || rdev->shutdown)
  5435. return IRQ_NONE;
  5436. wptr = si_get_ih_wptr(rdev);
  5437. restart_ih:
  5438. /* is somebody else already processing irqs? */
  5439. if (atomic_xchg(&rdev->ih.lock, 1))
  5440. return IRQ_NONE;
  5441. rptr = rdev->ih.rptr;
  5442. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  5443. /* Order reading of wptr vs. reading of IH ring data */
  5444. rmb();
  5445. /* display interrupts */
  5446. si_irq_ack(rdev);
  5447. while (rptr != wptr) {
  5448. /* wptr/rptr are in bytes! */
  5449. ring_index = rptr / 4;
  5450. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  5451. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  5452. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  5453. switch (src_id) {
  5454. case 1: /* D1 vblank/vline */
  5455. switch (src_data) {
  5456. case 0: /* D1 vblank */
  5457. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  5458. if (rdev->irq.crtc_vblank_int[0]) {
  5459. drm_handle_vblank(rdev->ddev, 0);
  5460. rdev->pm.vblank_sync = true;
  5461. wake_up(&rdev->irq.vblank_queue);
  5462. }
  5463. if (atomic_read(&rdev->irq.pflip[0]))
  5464. radeon_crtc_handle_flip(rdev, 0);
  5465. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  5466. DRM_DEBUG("IH: D1 vblank\n");
  5467. }
  5468. break;
  5469. case 1: /* D1 vline */
  5470. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  5471. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  5472. DRM_DEBUG("IH: D1 vline\n");
  5473. }
  5474. break;
  5475. default:
  5476. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5477. break;
  5478. }
  5479. break;
  5480. case 2: /* D2 vblank/vline */
  5481. switch (src_data) {
  5482. case 0: /* D2 vblank */
  5483. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  5484. if (rdev->irq.crtc_vblank_int[1]) {
  5485. drm_handle_vblank(rdev->ddev, 1);
  5486. rdev->pm.vblank_sync = true;
  5487. wake_up(&rdev->irq.vblank_queue);
  5488. }
  5489. if (atomic_read(&rdev->irq.pflip[1]))
  5490. radeon_crtc_handle_flip(rdev, 1);
  5491. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  5492. DRM_DEBUG("IH: D2 vblank\n");
  5493. }
  5494. break;
  5495. case 1: /* D2 vline */
  5496. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  5497. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  5498. DRM_DEBUG("IH: D2 vline\n");
  5499. }
  5500. break;
  5501. default:
  5502. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5503. break;
  5504. }
  5505. break;
  5506. case 3: /* D3 vblank/vline */
  5507. switch (src_data) {
  5508. case 0: /* D3 vblank */
  5509. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  5510. if (rdev->irq.crtc_vblank_int[2]) {
  5511. drm_handle_vblank(rdev->ddev, 2);
  5512. rdev->pm.vblank_sync = true;
  5513. wake_up(&rdev->irq.vblank_queue);
  5514. }
  5515. if (atomic_read(&rdev->irq.pflip[2]))
  5516. radeon_crtc_handle_flip(rdev, 2);
  5517. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  5518. DRM_DEBUG("IH: D3 vblank\n");
  5519. }
  5520. break;
  5521. case 1: /* D3 vline */
  5522. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  5523. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  5524. DRM_DEBUG("IH: D3 vline\n");
  5525. }
  5526. break;
  5527. default:
  5528. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5529. break;
  5530. }
  5531. break;
  5532. case 4: /* D4 vblank/vline */
  5533. switch (src_data) {
  5534. case 0: /* D4 vblank */
  5535. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  5536. if (rdev->irq.crtc_vblank_int[3]) {
  5537. drm_handle_vblank(rdev->ddev, 3);
  5538. rdev->pm.vblank_sync = true;
  5539. wake_up(&rdev->irq.vblank_queue);
  5540. }
  5541. if (atomic_read(&rdev->irq.pflip[3]))
  5542. radeon_crtc_handle_flip(rdev, 3);
  5543. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  5544. DRM_DEBUG("IH: D4 vblank\n");
  5545. }
  5546. break;
  5547. case 1: /* D4 vline */
  5548. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  5549. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  5550. DRM_DEBUG("IH: D4 vline\n");
  5551. }
  5552. break;
  5553. default:
  5554. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5555. break;
  5556. }
  5557. break;
  5558. case 5: /* D5 vblank/vline */
  5559. switch (src_data) {
  5560. case 0: /* D5 vblank */
  5561. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  5562. if (rdev->irq.crtc_vblank_int[4]) {
  5563. drm_handle_vblank(rdev->ddev, 4);
  5564. rdev->pm.vblank_sync = true;
  5565. wake_up(&rdev->irq.vblank_queue);
  5566. }
  5567. if (atomic_read(&rdev->irq.pflip[4]))
  5568. radeon_crtc_handle_flip(rdev, 4);
  5569. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  5570. DRM_DEBUG("IH: D5 vblank\n");
  5571. }
  5572. break;
  5573. case 1: /* D5 vline */
  5574. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  5575. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  5576. DRM_DEBUG("IH: D5 vline\n");
  5577. }
  5578. break;
  5579. default:
  5580. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5581. break;
  5582. }
  5583. break;
  5584. case 6: /* D6 vblank/vline */
  5585. switch (src_data) {
  5586. case 0: /* D6 vblank */
  5587. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  5588. if (rdev->irq.crtc_vblank_int[5]) {
  5589. drm_handle_vblank(rdev->ddev, 5);
  5590. rdev->pm.vblank_sync = true;
  5591. wake_up(&rdev->irq.vblank_queue);
  5592. }
  5593. if (atomic_read(&rdev->irq.pflip[5]))
  5594. radeon_crtc_handle_flip(rdev, 5);
  5595. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  5596. DRM_DEBUG("IH: D6 vblank\n");
  5597. }
  5598. break;
  5599. case 1: /* D6 vline */
  5600. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  5601. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  5602. DRM_DEBUG("IH: D6 vline\n");
  5603. }
  5604. break;
  5605. default:
  5606. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5607. break;
  5608. }
  5609. break;
  5610. case 42: /* HPD hotplug */
  5611. switch (src_data) {
  5612. case 0:
  5613. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5614. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  5615. queue_hotplug = true;
  5616. DRM_DEBUG("IH: HPD1\n");
  5617. }
  5618. break;
  5619. case 1:
  5620. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5621. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  5622. queue_hotplug = true;
  5623. DRM_DEBUG("IH: HPD2\n");
  5624. }
  5625. break;
  5626. case 2:
  5627. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5628. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  5629. queue_hotplug = true;
  5630. DRM_DEBUG("IH: HPD3\n");
  5631. }
  5632. break;
  5633. case 3:
  5634. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5635. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  5636. queue_hotplug = true;
  5637. DRM_DEBUG("IH: HPD4\n");
  5638. }
  5639. break;
  5640. case 4:
  5641. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5642. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  5643. queue_hotplug = true;
  5644. DRM_DEBUG("IH: HPD5\n");
  5645. }
  5646. break;
  5647. case 5:
  5648. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5649. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  5650. queue_hotplug = true;
  5651. DRM_DEBUG("IH: HPD6\n");
  5652. }
  5653. break;
  5654. default:
  5655. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5656. break;
  5657. }
  5658. break;
  5659. case 146:
  5660. case 147:
  5661. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  5662. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  5663. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  5664. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  5665. addr);
  5666. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  5667. status);
  5668. si_vm_decode_fault(rdev, status, addr);
  5669. /* reset addr and status */
  5670. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  5671. break;
  5672. case 176: /* RINGID0 CP_INT */
  5673. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5674. break;
  5675. case 177: /* RINGID1 CP_INT */
  5676. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5677. break;
  5678. case 178: /* RINGID2 CP_INT */
  5679. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5680. break;
  5681. case 181: /* CP EOP event */
  5682. DRM_DEBUG("IH: CP EOP\n");
  5683. switch (ring_id) {
  5684. case 0:
  5685. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5686. break;
  5687. case 1:
  5688. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5689. break;
  5690. case 2:
  5691. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5692. break;
  5693. }
  5694. break;
  5695. case 224: /* DMA trap event */
  5696. DRM_DEBUG("IH: DMA trap\n");
  5697. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  5698. break;
  5699. case 230: /* thermal low to high */
  5700. DRM_DEBUG("IH: thermal low to high\n");
  5701. rdev->pm.dpm.thermal.high_to_low = false;
  5702. queue_thermal = true;
  5703. break;
  5704. case 231: /* thermal high to low */
  5705. DRM_DEBUG("IH: thermal high to low\n");
  5706. rdev->pm.dpm.thermal.high_to_low = true;
  5707. queue_thermal = true;
  5708. break;
  5709. case 233: /* GUI IDLE */
  5710. DRM_DEBUG("IH: GUI idle\n");
  5711. break;
  5712. case 244: /* DMA trap event */
  5713. DRM_DEBUG("IH: DMA1 trap\n");
  5714. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5715. break;
  5716. default:
  5717. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5718. break;
  5719. }
  5720. /* wptr/rptr are in bytes! */
  5721. rptr += 16;
  5722. rptr &= rdev->ih.ptr_mask;
  5723. }
  5724. if (queue_hotplug)
  5725. schedule_work(&rdev->hotplug_work);
  5726. if (queue_thermal && rdev->pm.dpm_enabled)
  5727. schedule_work(&rdev->pm.dpm.thermal.work);
  5728. rdev->ih.rptr = rptr;
  5729. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  5730. atomic_set(&rdev->ih.lock, 0);
  5731. /* make sure wptr hasn't changed while processing */
  5732. wptr = si_get_ih_wptr(rdev);
  5733. if (wptr != rptr)
  5734. goto restart_ih;
  5735. return IRQ_HANDLED;
  5736. }
  5737. /*
  5738. * startup/shutdown callbacks
  5739. */
  5740. static int si_startup(struct radeon_device *rdev)
  5741. {
  5742. struct radeon_ring *ring;
  5743. int r;
  5744. /* enable pcie gen2/3 link */
  5745. si_pcie_gen3_enable(rdev);
  5746. /* enable aspm */
  5747. si_program_aspm(rdev);
  5748. /* scratch needs to be initialized before MC */
  5749. r = r600_vram_scratch_init(rdev);
  5750. if (r)
  5751. return r;
  5752. si_mc_program(rdev);
  5753. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  5754. !rdev->rlc_fw || !rdev->mc_fw) {
  5755. r = si_init_microcode(rdev);
  5756. if (r) {
  5757. DRM_ERROR("Failed to load firmware!\n");
  5758. return r;
  5759. }
  5760. }
  5761. r = si_mc_load_microcode(rdev);
  5762. if (r) {
  5763. DRM_ERROR("Failed to load MC firmware!\n");
  5764. return r;
  5765. }
  5766. r = si_pcie_gart_enable(rdev);
  5767. if (r)
  5768. return r;
  5769. si_gpu_init(rdev);
  5770. /* allocate rlc buffers */
  5771. if (rdev->family == CHIP_VERDE) {
  5772. rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
  5773. rdev->rlc.reg_list_size =
  5774. (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
  5775. }
  5776. rdev->rlc.cs_data = si_cs_data;
  5777. r = sumo_rlc_init(rdev);
  5778. if (r) {
  5779. DRM_ERROR("Failed to init rlc BOs!\n");
  5780. return r;
  5781. }
  5782. /* allocate wb buffer */
  5783. r = radeon_wb_init(rdev);
  5784. if (r)
  5785. return r;
  5786. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5787. if (r) {
  5788. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5789. return r;
  5790. }
  5791. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5792. if (r) {
  5793. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5794. return r;
  5795. }
  5796. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5797. if (r) {
  5798. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5799. return r;
  5800. }
  5801. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  5802. if (r) {
  5803. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5804. return r;
  5805. }
  5806. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5807. if (r) {
  5808. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5809. return r;
  5810. }
  5811. if (rdev->has_uvd) {
  5812. r = uvd_v2_2_resume(rdev);
  5813. if (!r) {
  5814. r = radeon_fence_driver_start_ring(rdev,
  5815. R600_RING_TYPE_UVD_INDEX);
  5816. if (r)
  5817. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  5818. }
  5819. if (r)
  5820. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5821. }
  5822. /* Enable IRQ */
  5823. if (!rdev->irq.installed) {
  5824. r = radeon_irq_kms_init(rdev);
  5825. if (r)
  5826. return r;
  5827. }
  5828. r = si_irq_init(rdev);
  5829. if (r) {
  5830. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5831. radeon_irq_kms_fini(rdev);
  5832. return r;
  5833. }
  5834. si_irq_set(rdev);
  5835. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5836. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5837. CP_RB0_RPTR, CP_RB0_WPTR,
  5838. RADEON_CP_PACKET2);
  5839. if (r)
  5840. return r;
  5841. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5842. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  5843. CP_RB1_RPTR, CP_RB1_WPTR,
  5844. RADEON_CP_PACKET2);
  5845. if (r)
  5846. return r;
  5847. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5848. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  5849. CP_RB2_RPTR, CP_RB2_WPTR,
  5850. RADEON_CP_PACKET2);
  5851. if (r)
  5852. return r;
  5853. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5854. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5855. DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
  5856. DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
  5857. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5858. if (r)
  5859. return r;
  5860. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  5861. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  5862. DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
  5863. DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
  5864. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5865. if (r)
  5866. return r;
  5867. r = si_cp_load_microcode(rdev);
  5868. if (r)
  5869. return r;
  5870. r = si_cp_resume(rdev);
  5871. if (r)
  5872. return r;
  5873. r = cayman_dma_resume(rdev);
  5874. if (r)
  5875. return r;
  5876. if (rdev->has_uvd) {
  5877. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5878. if (ring->ring_size) {
  5879. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  5880. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  5881. RADEON_CP_PACKET2);
  5882. if (!r)
  5883. r = uvd_v1_0_init(rdev);
  5884. if (r)
  5885. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  5886. }
  5887. }
  5888. r = radeon_ib_pool_init(rdev);
  5889. if (r) {
  5890. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5891. return r;
  5892. }
  5893. r = radeon_vm_manager_init(rdev);
  5894. if (r) {
  5895. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  5896. return r;
  5897. }
  5898. r = dce6_audio_init(rdev);
  5899. if (r)
  5900. return r;
  5901. return 0;
  5902. }
  5903. int si_resume(struct radeon_device *rdev)
  5904. {
  5905. int r;
  5906. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5907. * posting will perform necessary task to bring back GPU into good
  5908. * shape.
  5909. */
  5910. /* post card */
  5911. atom_asic_init(rdev->mode_info.atom_context);
  5912. /* init golden registers */
  5913. si_init_golden_registers(rdev);
  5914. rdev->accel_working = true;
  5915. r = si_startup(rdev);
  5916. if (r) {
  5917. DRM_ERROR("si startup failed on resume\n");
  5918. rdev->accel_working = false;
  5919. return r;
  5920. }
  5921. return r;
  5922. }
  5923. int si_suspend(struct radeon_device *rdev)
  5924. {
  5925. dce6_audio_fini(rdev);
  5926. radeon_vm_manager_fini(rdev);
  5927. si_cp_enable(rdev, false);
  5928. cayman_dma_stop(rdev);
  5929. if (rdev->has_uvd) {
  5930. uvd_v1_0_fini(rdev);
  5931. radeon_uvd_suspend(rdev);
  5932. }
  5933. si_fini_pg(rdev);
  5934. si_fini_cg(rdev);
  5935. si_irq_suspend(rdev);
  5936. radeon_wb_disable(rdev);
  5937. si_pcie_gart_disable(rdev);
  5938. return 0;
  5939. }
  5940. /* Plan is to move initialization in that function and use
  5941. * helper function so that radeon_device_init pretty much
  5942. * do nothing more than calling asic specific function. This
  5943. * should also allow to remove a bunch of callback function
  5944. * like vram_info.
  5945. */
  5946. int si_init(struct radeon_device *rdev)
  5947. {
  5948. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5949. int r;
  5950. /* Read BIOS */
  5951. if (!radeon_get_bios(rdev)) {
  5952. if (ASIC_IS_AVIVO(rdev))
  5953. return -EINVAL;
  5954. }
  5955. /* Must be an ATOMBIOS */
  5956. if (!rdev->is_atom_bios) {
  5957. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  5958. return -EINVAL;
  5959. }
  5960. r = radeon_atombios_init(rdev);
  5961. if (r)
  5962. return r;
  5963. /* Post card if necessary */
  5964. if (!radeon_card_posted(rdev)) {
  5965. if (!rdev->bios) {
  5966. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5967. return -EINVAL;
  5968. }
  5969. DRM_INFO("GPU not posted. posting now...\n");
  5970. atom_asic_init(rdev->mode_info.atom_context);
  5971. }
  5972. /* init golden registers */
  5973. si_init_golden_registers(rdev);
  5974. /* Initialize scratch registers */
  5975. si_scratch_init(rdev);
  5976. /* Initialize surface registers */
  5977. radeon_surface_init(rdev);
  5978. /* Initialize clocks */
  5979. radeon_get_clock_info(rdev->ddev);
  5980. /* Fence driver */
  5981. r = radeon_fence_driver_init(rdev);
  5982. if (r)
  5983. return r;
  5984. /* initialize memory controller */
  5985. r = si_mc_init(rdev);
  5986. if (r)
  5987. return r;
  5988. /* Memory manager */
  5989. r = radeon_bo_init(rdev);
  5990. if (r)
  5991. return r;
  5992. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5993. ring->ring_obj = NULL;
  5994. r600_ring_init(rdev, ring, 1024 * 1024);
  5995. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5996. ring->ring_obj = NULL;
  5997. r600_ring_init(rdev, ring, 1024 * 1024);
  5998. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5999. ring->ring_obj = NULL;
  6000. r600_ring_init(rdev, ring, 1024 * 1024);
  6001. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  6002. ring->ring_obj = NULL;
  6003. r600_ring_init(rdev, ring, 64 * 1024);
  6004. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  6005. ring->ring_obj = NULL;
  6006. r600_ring_init(rdev, ring, 64 * 1024);
  6007. if (rdev->has_uvd) {
  6008. r = radeon_uvd_init(rdev);
  6009. if (!r) {
  6010. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  6011. ring->ring_obj = NULL;
  6012. r600_ring_init(rdev, ring, 4096);
  6013. }
  6014. }
  6015. rdev->ih.ring_obj = NULL;
  6016. r600_ih_ring_init(rdev, 64 * 1024);
  6017. r = r600_pcie_gart_init(rdev);
  6018. if (r)
  6019. return r;
  6020. rdev->accel_working = true;
  6021. r = si_startup(rdev);
  6022. if (r) {
  6023. dev_err(rdev->dev, "disabling GPU acceleration\n");
  6024. si_cp_fini(rdev);
  6025. cayman_dma_fini(rdev);
  6026. si_irq_fini(rdev);
  6027. sumo_rlc_fini(rdev);
  6028. radeon_wb_fini(rdev);
  6029. radeon_ib_pool_fini(rdev);
  6030. radeon_vm_manager_fini(rdev);
  6031. radeon_irq_kms_fini(rdev);
  6032. si_pcie_gart_fini(rdev);
  6033. rdev->accel_working = false;
  6034. }
  6035. /* Don't start up if the MC ucode is missing.
  6036. * The default clocks and voltages before the MC ucode
  6037. * is loaded are not suffient for advanced operations.
  6038. */
  6039. if (!rdev->mc_fw) {
  6040. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  6041. return -EINVAL;
  6042. }
  6043. return 0;
  6044. }
  6045. void si_fini(struct radeon_device *rdev)
  6046. {
  6047. si_cp_fini(rdev);
  6048. cayman_dma_fini(rdev);
  6049. si_fini_pg(rdev);
  6050. si_fini_cg(rdev);
  6051. si_irq_fini(rdev);
  6052. sumo_rlc_fini(rdev);
  6053. radeon_wb_fini(rdev);
  6054. radeon_vm_manager_fini(rdev);
  6055. radeon_ib_pool_fini(rdev);
  6056. radeon_irq_kms_fini(rdev);
  6057. if (rdev->has_uvd) {
  6058. uvd_v1_0_fini(rdev);
  6059. radeon_uvd_fini(rdev);
  6060. }
  6061. si_pcie_gart_fini(rdev);
  6062. r600_vram_scratch_fini(rdev);
  6063. radeon_gem_fini(rdev);
  6064. radeon_fence_driver_fini(rdev);
  6065. radeon_bo_fini(rdev);
  6066. radeon_atombios_fini(rdev);
  6067. kfree(rdev->bios);
  6068. rdev->bios = NULL;
  6069. }
  6070. /**
  6071. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  6072. *
  6073. * @rdev: radeon_device pointer
  6074. *
  6075. * Fetches a GPU clock counter snapshot (SI).
  6076. * Returns the 64 bit clock counter snapshot.
  6077. */
  6078. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  6079. {
  6080. uint64_t clock;
  6081. mutex_lock(&rdev->gpu_clock_mutex);
  6082. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  6083. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  6084. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  6085. mutex_unlock(&rdev->gpu_clock_mutex);
  6086. return clock;
  6087. }
  6088. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  6089. {
  6090. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  6091. int r;
  6092. /* bypass vclk and dclk with bclk */
  6093. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6094. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  6095. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6096. /* put PLL in bypass mode */
  6097. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  6098. if (!vclk || !dclk) {
  6099. /* keep the Bypass mode, put PLL to sleep */
  6100. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6101. return 0;
  6102. }
  6103. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  6104. 16384, 0x03FFFFFF, 0, 128, 5,
  6105. &fb_div, &vclk_div, &dclk_div);
  6106. if (r)
  6107. return r;
  6108. /* set RESET_ANTI_MUX to 0 */
  6109. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  6110. /* set VCO_MODE to 1 */
  6111. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  6112. /* toggle UPLL_SLEEP to 1 then back to 0 */
  6113. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6114. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  6115. /* deassert UPLL_RESET */
  6116. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6117. mdelay(1);
  6118. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6119. if (r)
  6120. return r;
  6121. /* assert UPLL_RESET again */
  6122. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  6123. /* disable spread spectrum. */
  6124. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  6125. /* set feedback divider */
  6126. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  6127. /* set ref divider to 0 */
  6128. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  6129. if (fb_div < 307200)
  6130. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  6131. else
  6132. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  6133. /* set PDIV_A and PDIV_B */
  6134. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6135. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  6136. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  6137. /* give the PLL some time to settle */
  6138. mdelay(15);
  6139. /* deassert PLL_RESET */
  6140. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6141. mdelay(15);
  6142. /* switch from bypass mode to normal mode */
  6143. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  6144. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6145. if (r)
  6146. return r;
  6147. /* switch VCLK and DCLK selection */
  6148. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6149. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  6150. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6151. mdelay(100);
  6152. return 0;
  6153. }
  6154. static void si_pcie_gen3_enable(struct radeon_device *rdev)
  6155. {
  6156. struct pci_dev *root = rdev->pdev->bus->self;
  6157. int bridge_pos, gpu_pos;
  6158. u32 speed_cntl, mask, current_data_rate;
  6159. int ret, i;
  6160. u16 tmp16;
  6161. if (radeon_pcie_gen2 == 0)
  6162. return;
  6163. if (rdev->flags & RADEON_IS_IGP)
  6164. return;
  6165. if (!(rdev->flags & RADEON_IS_PCIE))
  6166. return;
  6167. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  6168. if (ret != 0)
  6169. return;
  6170. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  6171. return;
  6172. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6173. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  6174. LC_CURRENT_DATA_RATE_SHIFT;
  6175. if (mask & DRM_PCIE_SPEED_80) {
  6176. if (current_data_rate == 2) {
  6177. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  6178. return;
  6179. }
  6180. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  6181. } else if (mask & DRM_PCIE_SPEED_50) {
  6182. if (current_data_rate == 1) {
  6183. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  6184. return;
  6185. }
  6186. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  6187. }
  6188. bridge_pos = pci_pcie_cap(root);
  6189. if (!bridge_pos)
  6190. return;
  6191. gpu_pos = pci_pcie_cap(rdev->pdev);
  6192. if (!gpu_pos)
  6193. return;
  6194. if (mask & DRM_PCIE_SPEED_80) {
  6195. /* re-try equalization if gen3 is not already enabled */
  6196. if (current_data_rate != 2) {
  6197. u16 bridge_cfg, gpu_cfg;
  6198. u16 bridge_cfg2, gpu_cfg2;
  6199. u32 max_lw, current_lw, tmp;
  6200. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6201. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6202. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  6203. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6204. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  6205. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6206. tmp = RREG32_PCIE(PCIE_LC_STATUS1);
  6207. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  6208. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  6209. if (current_lw < max_lw) {
  6210. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6211. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  6212. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  6213. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  6214. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  6215. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  6216. }
  6217. }
  6218. for (i = 0; i < 10; i++) {
  6219. /* check status */
  6220. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  6221. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  6222. break;
  6223. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6224. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6225. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  6226. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  6227. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6228. tmp |= LC_SET_QUIESCE;
  6229. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6230. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6231. tmp |= LC_REDO_EQ;
  6232. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6233. mdelay(100);
  6234. /* linkctl */
  6235. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  6236. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6237. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  6238. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6239. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  6240. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6241. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  6242. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6243. /* linkctl2 */
  6244. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  6245. tmp16 &= ~((1 << 4) | (7 << 9));
  6246. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  6247. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  6248. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6249. tmp16 &= ~((1 << 4) | (7 << 9));
  6250. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  6251. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6252. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6253. tmp &= ~LC_SET_QUIESCE;
  6254. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6255. }
  6256. }
  6257. }
  6258. /* set the link speed */
  6259. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  6260. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  6261. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6262. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6263. tmp16 &= ~0xf;
  6264. if (mask & DRM_PCIE_SPEED_80)
  6265. tmp16 |= 3; /* gen3 */
  6266. else if (mask & DRM_PCIE_SPEED_50)
  6267. tmp16 |= 2; /* gen2 */
  6268. else
  6269. tmp16 |= 1; /* gen1 */
  6270. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6271. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6272. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  6273. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6274. for (i = 0; i < rdev->usec_timeout; i++) {
  6275. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6276. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  6277. break;
  6278. udelay(1);
  6279. }
  6280. }
  6281. static void si_program_aspm(struct radeon_device *rdev)
  6282. {
  6283. u32 data, orig;
  6284. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  6285. bool disable_clkreq = false;
  6286. if (radeon_aspm == 0)
  6287. return;
  6288. if (!(rdev->flags & RADEON_IS_PCIE))
  6289. return;
  6290. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6291. data &= ~LC_XMIT_N_FTS_MASK;
  6292. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  6293. if (orig != data)
  6294. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  6295. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  6296. data |= LC_GO_TO_RECOVERY;
  6297. if (orig != data)
  6298. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  6299. orig = data = RREG32_PCIE(PCIE_P_CNTL);
  6300. data |= P_IGNORE_EDB_ERR;
  6301. if (orig != data)
  6302. WREG32_PCIE(PCIE_P_CNTL, data);
  6303. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6304. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  6305. data |= LC_PMI_TO_L1_DIS;
  6306. if (!disable_l0s)
  6307. data |= LC_L0S_INACTIVITY(7);
  6308. if (!disable_l1) {
  6309. data |= LC_L1_INACTIVITY(7);
  6310. data &= ~LC_PMI_TO_L1_DIS;
  6311. if (orig != data)
  6312. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6313. if (!disable_plloff_in_l1) {
  6314. bool clk_req_support;
  6315. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6316. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6317. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6318. if (orig != data)
  6319. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6320. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6321. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6322. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6323. if (orig != data)
  6324. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6325. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6326. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6327. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6328. if (orig != data)
  6329. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6330. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6331. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6332. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6333. if (orig != data)
  6334. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6335. if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
  6336. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6337. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6338. if (orig != data)
  6339. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6340. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6341. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6342. if (orig != data)
  6343. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6344. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
  6345. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6346. if (orig != data)
  6347. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
  6348. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
  6349. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6350. if (orig != data)
  6351. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
  6352. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6353. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6354. if (orig != data)
  6355. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6356. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6357. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6358. if (orig != data)
  6359. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6360. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
  6361. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6362. if (orig != data)
  6363. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
  6364. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
  6365. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6366. if (orig != data)
  6367. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
  6368. }
  6369. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6370. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  6371. data |= LC_DYN_LANES_PWR_STATE(3);
  6372. if (orig != data)
  6373. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  6374. orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  6375. data &= ~LS2_EXIT_TIME_MASK;
  6376. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6377. data |= LS2_EXIT_TIME(5);
  6378. if (orig != data)
  6379. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  6380. orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  6381. data &= ~LS2_EXIT_TIME_MASK;
  6382. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6383. data |= LS2_EXIT_TIME(5);
  6384. if (orig != data)
  6385. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  6386. if (!disable_clkreq) {
  6387. struct pci_dev *root = rdev->pdev->bus->self;
  6388. u32 lnkcap;
  6389. clk_req_support = false;
  6390. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  6391. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  6392. clk_req_support = true;
  6393. } else {
  6394. clk_req_support = false;
  6395. }
  6396. if (clk_req_support) {
  6397. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  6398. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  6399. if (orig != data)
  6400. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  6401. orig = data = RREG32(THM_CLK_CNTL);
  6402. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  6403. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  6404. if (orig != data)
  6405. WREG32(THM_CLK_CNTL, data);
  6406. orig = data = RREG32(MISC_CLK_CNTL);
  6407. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  6408. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  6409. if (orig != data)
  6410. WREG32(MISC_CLK_CNTL, data);
  6411. orig = data = RREG32(CG_CLKPIN_CNTL);
  6412. data &= ~BCLK_AS_XCLK;
  6413. if (orig != data)
  6414. WREG32(CG_CLKPIN_CNTL, data);
  6415. orig = data = RREG32(CG_CLKPIN_CNTL_2);
  6416. data &= ~FORCE_BIF_REFCLK_EN;
  6417. if (orig != data)
  6418. WREG32(CG_CLKPIN_CNTL_2, data);
  6419. orig = data = RREG32(MPLL_BYPASSCLK_SEL);
  6420. data &= ~MPLL_CLKOUT_SEL_MASK;
  6421. data |= MPLL_CLKOUT_SEL(4);
  6422. if (orig != data)
  6423. WREG32(MPLL_BYPASSCLK_SEL, data);
  6424. orig = data = RREG32(SPLL_CNTL_MODE);
  6425. data &= ~SPLL_REFCLK_SEL_MASK;
  6426. if (orig != data)
  6427. WREG32(SPLL_CNTL_MODE, data);
  6428. }
  6429. }
  6430. } else {
  6431. if (orig != data)
  6432. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6433. }
  6434. orig = data = RREG32_PCIE(PCIE_CNTL2);
  6435. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  6436. if (orig != data)
  6437. WREG32_PCIE(PCIE_CNTL2, data);
  6438. if (!disable_l0s) {
  6439. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6440. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  6441. data = RREG32_PCIE(PCIE_LC_STATUS1);
  6442. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  6443. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6444. data &= ~LC_L0S_INACTIVITY_MASK;
  6445. if (orig != data)
  6446. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6447. }
  6448. }
  6449. }
  6450. }