si.c 221 KB

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