si.c 201 KB

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