si.c 217 KB

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