cik.c 245 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888
  1. /*
  2. * Copyright 2012 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 "drmP.h"
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include "cikd.h"
  31. #include "atom.h"
  32. #include "cik_blit_shaders.h"
  33. #include "radeon_ucode.h"
  34. #include "clearstate_ci.h"
  35. MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
  36. MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
  37. MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
  38. MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
  39. MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
  40. MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
  41. MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
  42. MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
  43. MODULE_FIRMWARE("radeon/KAVERI_me.bin");
  44. MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
  45. MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
  46. MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
  47. MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
  48. MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
  49. MODULE_FIRMWARE("radeon/KABINI_me.bin");
  50. MODULE_FIRMWARE("radeon/KABINI_ce.bin");
  51. MODULE_FIRMWARE("radeon/KABINI_mec.bin");
  52. MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
  53. MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
  54. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  55. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  56. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  57. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  58. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  59. extern void sumo_rlc_fini(struct radeon_device *rdev);
  60. extern int sumo_rlc_init(struct radeon_device *rdev);
  61. extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  62. extern void si_rlc_reset(struct radeon_device *rdev);
  63. extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
  64. static void cik_rlc_stop(struct radeon_device *rdev);
  65. static void cik_pcie_gen3_enable(struct radeon_device *rdev);
  66. static void cik_program_aspm(struct radeon_device *rdev);
  67. static void cik_init_pg(struct radeon_device *rdev);
  68. static void cik_init_cg(struct radeon_device *rdev);
  69. /* get temperature in millidegrees */
  70. int ci_get_temp(struct radeon_device *rdev)
  71. {
  72. u32 temp;
  73. int actual_temp = 0;
  74. temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  75. CTF_TEMP_SHIFT;
  76. if (temp & 0x200)
  77. actual_temp = 255;
  78. else
  79. actual_temp = temp & 0x1ff;
  80. actual_temp = actual_temp * 1000;
  81. return actual_temp;
  82. }
  83. /* get temperature in millidegrees */
  84. int kv_get_temp(struct radeon_device *rdev)
  85. {
  86. u32 temp;
  87. int actual_temp = 0;
  88. temp = RREG32_SMC(0xC0300E0C);
  89. if (temp)
  90. actual_temp = (temp / 8) - 49;
  91. else
  92. actual_temp = 0;
  93. actual_temp = actual_temp * 1000;
  94. return actual_temp;
  95. }
  96. /*
  97. * Indirect registers accessor
  98. */
  99. u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
  100. {
  101. u32 r;
  102. WREG32(PCIE_INDEX, reg);
  103. (void)RREG32(PCIE_INDEX);
  104. r = RREG32(PCIE_DATA);
  105. return r;
  106. }
  107. void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  108. {
  109. WREG32(PCIE_INDEX, reg);
  110. (void)RREG32(PCIE_INDEX);
  111. WREG32(PCIE_DATA, v);
  112. (void)RREG32(PCIE_DATA);
  113. }
  114. static const u32 spectre_rlc_save_restore_register_list[] =
  115. {
  116. (0x0e00 << 16) | (0xc12c >> 2),
  117. 0x00000000,
  118. (0x0e00 << 16) | (0xc140 >> 2),
  119. 0x00000000,
  120. (0x0e00 << 16) | (0xc150 >> 2),
  121. 0x00000000,
  122. (0x0e00 << 16) | (0xc15c >> 2),
  123. 0x00000000,
  124. (0x0e00 << 16) | (0xc168 >> 2),
  125. 0x00000000,
  126. (0x0e00 << 16) | (0xc170 >> 2),
  127. 0x00000000,
  128. (0x0e00 << 16) | (0xc178 >> 2),
  129. 0x00000000,
  130. (0x0e00 << 16) | (0xc204 >> 2),
  131. 0x00000000,
  132. (0x0e00 << 16) | (0xc2b4 >> 2),
  133. 0x00000000,
  134. (0x0e00 << 16) | (0xc2b8 >> 2),
  135. 0x00000000,
  136. (0x0e00 << 16) | (0xc2bc >> 2),
  137. 0x00000000,
  138. (0x0e00 << 16) | (0xc2c0 >> 2),
  139. 0x00000000,
  140. (0x0e00 << 16) | (0x8228 >> 2),
  141. 0x00000000,
  142. (0x0e00 << 16) | (0x829c >> 2),
  143. 0x00000000,
  144. (0x0e00 << 16) | (0x869c >> 2),
  145. 0x00000000,
  146. (0x0600 << 16) | (0x98f4 >> 2),
  147. 0x00000000,
  148. (0x0e00 << 16) | (0x98f8 >> 2),
  149. 0x00000000,
  150. (0x0e00 << 16) | (0x9900 >> 2),
  151. 0x00000000,
  152. (0x0e00 << 16) | (0xc260 >> 2),
  153. 0x00000000,
  154. (0x0e00 << 16) | (0x90e8 >> 2),
  155. 0x00000000,
  156. (0x0e00 << 16) | (0x3c000 >> 2),
  157. 0x00000000,
  158. (0x0e00 << 16) | (0x3c00c >> 2),
  159. 0x00000000,
  160. (0x0e00 << 16) | (0x8c1c >> 2),
  161. 0x00000000,
  162. (0x0e00 << 16) | (0x9700 >> 2),
  163. 0x00000000,
  164. (0x0e00 << 16) | (0xcd20 >> 2),
  165. 0x00000000,
  166. (0x4e00 << 16) | (0xcd20 >> 2),
  167. 0x00000000,
  168. (0x5e00 << 16) | (0xcd20 >> 2),
  169. 0x00000000,
  170. (0x6e00 << 16) | (0xcd20 >> 2),
  171. 0x00000000,
  172. (0x7e00 << 16) | (0xcd20 >> 2),
  173. 0x00000000,
  174. (0x8e00 << 16) | (0xcd20 >> 2),
  175. 0x00000000,
  176. (0x9e00 << 16) | (0xcd20 >> 2),
  177. 0x00000000,
  178. (0xae00 << 16) | (0xcd20 >> 2),
  179. 0x00000000,
  180. (0xbe00 << 16) | (0xcd20 >> 2),
  181. 0x00000000,
  182. (0x0e00 << 16) | (0x89bc >> 2),
  183. 0x00000000,
  184. (0x0e00 << 16) | (0x8900 >> 2),
  185. 0x00000000,
  186. 0x3,
  187. (0x0e00 << 16) | (0xc130 >> 2),
  188. 0x00000000,
  189. (0x0e00 << 16) | (0xc134 >> 2),
  190. 0x00000000,
  191. (0x0e00 << 16) | (0xc1fc >> 2),
  192. 0x00000000,
  193. (0x0e00 << 16) | (0xc208 >> 2),
  194. 0x00000000,
  195. (0x0e00 << 16) | (0xc264 >> 2),
  196. 0x00000000,
  197. (0x0e00 << 16) | (0xc268 >> 2),
  198. 0x00000000,
  199. (0x0e00 << 16) | (0xc26c >> 2),
  200. 0x00000000,
  201. (0x0e00 << 16) | (0xc270 >> 2),
  202. 0x00000000,
  203. (0x0e00 << 16) | (0xc274 >> 2),
  204. 0x00000000,
  205. (0x0e00 << 16) | (0xc278 >> 2),
  206. 0x00000000,
  207. (0x0e00 << 16) | (0xc27c >> 2),
  208. 0x00000000,
  209. (0x0e00 << 16) | (0xc280 >> 2),
  210. 0x00000000,
  211. (0x0e00 << 16) | (0xc284 >> 2),
  212. 0x00000000,
  213. (0x0e00 << 16) | (0xc288 >> 2),
  214. 0x00000000,
  215. (0x0e00 << 16) | (0xc28c >> 2),
  216. 0x00000000,
  217. (0x0e00 << 16) | (0xc290 >> 2),
  218. 0x00000000,
  219. (0x0e00 << 16) | (0xc294 >> 2),
  220. 0x00000000,
  221. (0x0e00 << 16) | (0xc298 >> 2),
  222. 0x00000000,
  223. (0x0e00 << 16) | (0xc29c >> 2),
  224. 0x00000000,
  225. (0x0e00 << 16) | (0xc2a0 >> 2),
  226. 0x00000000,
  227. (0x0e00 << 16) | (0xc2a4 >> 2),
  228. 0x00000000,
  229. (0x0e00 << 16) | (0xc2a8 >> 2),
  230. 0x00000000,
  231. (0x0e00 << 16) | (0xc2ac >> 2),
  232. 0x00000000,
  233. (0x0e00 << 16) | (0xc2b0 >> 2),
  234. 0x00000000,
  235. (0x0e00 << 16) | (0x301d0 >> 2),
  236. 0x00000000,
  237. (0x0e00 << 16) | (0x30238 >> 2),
  238. 0x00000000,
  239. (0x0e00 << 16) | (0x30250 >> 2),
  240. 0x00000000,
  241. (0x0e00 << 16) | (0x30254 >> 2),
  242. 0x00000000,
  243. (0x0e00 << 16) | (0x30258 >> 2),
  244. 0x00000000,
  245. (0x0e00 << 16) | (0x3025c >> 2),
  246. 0x00000000,
  247. (0x4e00 << 16) | (0xc900 >> 2),
  248. 0x00000000,
  249. (0x5e00 << 16) | (0xc900 >> 2),
  250. 0x00000000,
  251. (0x6e00 << 16) | (0xc900 >> 2),
  252. 0x00000000,
  253. (0x7e00 << 16) | (0xc900 >> 2),
  254. 0x00000000,
  255. (0x8e00 << 16) | (0xc900 >> 2),
  256. 0x00000000,
  257. (0x9e00 << 16) | (0xc900 >> 2),
  258. 0x00000000,
  259. (0xae00 << 16) | (0xc900 >> 2),
  260. 0x00000000,
  261. (0xbe00 << 16) | (0xc900 >> 2),
  262. 0x00000000,
  263. (0x4e00 << 16) | (0xc904 >> 2),
  264. 0x00000000,
  265. (0x5e00 << 16) | (0xc904 >> 2),
  266. 0x00000000,
  267. (0x6e00 << 16) | (0xc904 >> 2),
  268. 0x00000000,
  269. (0x7e00 << 16) | (0xc904 >> 2),
  270. 0x00000000,
  271. (0x8e00 << 16) | (0xc904 >> 2),
  272. 0x00000000,
  273. (0x9e00 << 16) | (0xc904 >> 2),
  274. 0x00000000,
  275. (0xae00 << 16) | (0xc904 >> 2),
  276. 0x00000000,
  277. (0xbe00 << 16) | (0xc904 >> 2),
  278. 0x00000000,
  279. (0x4e00 << 16) | (0xc908 >> 2),
  280. 0x00000000,
  281. (0x5e00 << 16) | (0xc908 >> 2),
  282. 0x00000000,
  283. (0x6e00 << 16) | (0xc908 >> 2),
  284. 0x00000000,
  285. (0x7e00 << 16) | (0xc908 >> 2),
  286. 0x00000000,
  287. (0x8e00 << 16) | (0xc908 >> 2),
  288. 0x00000000,
  289. (0x9e00 << 16) | (0xc908 >> 2),
  290. 0x00000000,
  291. (0xae00 << 16) | (0xc908 >> 2),
  292. 0x00000000,
  293. (0xbe00 << 16) | (0xc908 >> 2),
  294. 0x00000000,
  295. (0x4e00 << 16) | (0xc90c >> 2),
  296. 0x00000000,
  297. (0x5e00 << 16) | (0xc90c >> 2),
  298. 0x00000000,
  299. (0x6e00 << 16) | (0xc90c >> 2),
  300. 0x00000000,
  301. (0x7e00 << 16) | (0xc90c >> 2),
  302. 0x00000000,
  303. (0x8e00 << 16) | (0xc90c >> 2),
  304. 0x00000000,
  305. (0x9e00 << 16) | (0xc90c >> 2),
  306. 0x00000000,
  307. (0xae00 << 16) | (0xc90c >> 2),
  308. 0x00000000,
  309. (0xbe00 << 16) | (0xc90c >> 2),
  310. 0x00000000,
  311. (0x4e00 << 16) | (0xc910 >> 2),
  312. 0x00000000,
  313. (0x5e00 << 16) | (0xc910 >> 2),
  314. 0x00000000,
  315. (0x6e00 << 16) | (0xc910 >> 2),
  316. 0x00000000,
  317. (0x7e00 << 16) | (0xc910 >> 2),
  318. 0x00000000,
  319. (0x8e00 << 16) | (0xc910 >> 2),
  320. 0x00000000,
  321. (0x9e00 << 16) | (0xc910 >> 2),
  322. 0x00000000,
  323. (0xae00 << 16) | (0xc910 >> 2),
  324. 0x00000000,
  325. (0xbe00 << 16) | (0xc910 >> 2),
  326. 0x00000000,
  327. (0x0e00 << 16) | (0xc99c >> 2),
  328. 0x00000000,
  329. (0x0e00 << 16) | (0x9834 >> 2),
  330. 0x00000000,
  331. (0x0000 << 16) | (0x30f00 >> 2),
  332. 0x00000000,
  333. (0x0001 << 16) | (0x30f00 >> 2),
  334. 0x00000000,
  335. (0x0000 << 16) | (0x30f04 >> 2),
  336. 0x00000000,
  337. (0x0001 << 16) | (0x30f04 >> 2),
  338. 0x00000000,
  339. (0x0000 << 16) | (0x30f08 >> 2),
  340. 0x00000000,
  341. (0x0001 << 16) | (0x30f08 >> 2),
  342. 0x00000000,
  343. (0x0000 << 16) | (0x30f0c >> 2),
  344. 0x00000000,
  345. (0x0001 << 16) | (0x30f0c >> 2),
  346. 0x00000000,
  347. (0x0600 << 16) | (0x9b7c >> 2),
  348. 0x00000000,
  349. (0x0e00 << 16) | (0x8a14 >> 2),
  350. 0x00000000,
  351. (0x0e00 << 16) | (0x8a18 >> 2),
  352. 0x00000000,
  353. (0x0600 << 16) | (0x30a00 >> 2),
  354. 0x00000000,
  355. (0x0e00 << 16) | (0x8bf0 >> 2),
  356. 0x00000000,
  357. (0x0e00 << 16) | (0x8bcc >> 2),
  358. 0x00000000,
  359. (0x0e00 << 16) | (0x8b24 >> 2),
  360. 0x00000000,
  361. (0x0e00 << 16) | (0x30a04 >> 2),
  362. 0x00000000,
  363. (0x0600 << 16) | (0x30a10 >> 2),
  364. 0x00000000,
  365. (0x0600 << 16) | (0x30a14 >> 2),
  366. 0x00000000,
  367. (0x0600 << 16) | (0x30a18 >> 2),
  368. 0x00000000,
  369. (0x0600 << 16) | (0x30a2c >> 2),
  370. 0x00000000,
  371. (0x0e00 << 16) | (0xc700 >> 2),
  372. 0x00000000,
  373. (0x0e00 << 16) | (0xc704 >> 2),
  374. 0x00000000,
  375. (0x0e00 << 16) | (0xc708 >> 2),
  376. 0x00000000,
  377. (0x0e00 << 16) | (0xc768 >> 2),
  378. 0x00000000,
  379. (0x0400 << 16) | (0xc770 >> 2),
  380. 0x00000000,
  381. (0x0400 << 16) | (0xc774 >> 2),
  382. 0x00000000,
  383. (0x0400 << 16) | (0xc778 >> 2),
  384. 0x00000000,
  385. (0x0400 << 16) | (0xc77c >> 2),
  386. 0x00000000,
  387. (0x0400 << 16) | (0xc780 >> 2),
  388. 0x00000000,
  389. (0x0400 << 16) | (0xc784 >> 2),
  390. 0x00000000,
  391. (0x0400 << 16) | (0xc788 >> 2),
  392. 0x00000000,
  393. (0x0400 << 16) | (0xc78c >> 2),
  394. 0x00000000,
  395. (0x0400 << 16) | (0xc798 >> 2),
  396. 0x00000000,
  397. (0x0400 << 16) | (0xc79c >> 2),
  398. 0x00000000,
  399. (0x0400 << 16) | (0xc7a0 >> 2),
  400. 0x00000000,
  401. (0x0400 << 16) | (0xc7a4 >> 2),
  402. 0x00000000,
  403. (0x0400 << 16) | (0xc7a8 >> 2),
  404. 0x00000000,
  405. (0x0400 << 16) | (0xc7ac >> 2),
  406. 0x00000000,
  407. (0x0400 << 16) | (0xc7b0 >> 2),
  408. 0x00000000,
  409. (0x0400 << 16) | (0xc7b4 >> 2),
  410. 0x00000000,
  411. (0x0e00 << 16) | (0x9100 >> 2),
  412. 0x00000000,
  413. (0x0e00 << 16) | (0x3c010 >> 2),
  414. 0x00000000,
  415. (0x0e00 << 16) | (0x92a8 >> 2),
  416. 0x00000000,
  417. (0x0e00 << 16) | (0x92ac >> 2),
  418. 0x00000000,
  419. (0x0e00 << 16) | (0x92b4 >> 2),
  420. 0x00000000,
  421. (0x0e00 << 16) | (0x92b8 >> 2),
  422. 0x00000000,
  423. (0x0e00 << 16) | (0x92bc >> 2),
  424. 0x00000000,
  425. (0x0e00 << 16) | (0x92c0 >> 2),
  426. 0x00000000,
  427. (0x0e00 << 16) | (0x92c4 >> 2),
  428. 0x00000000,
  429. (0x0e00 << 16) | (0x92c8 >> 2),
  430. 0x00000000,
  431. (0x0e00 << 16) | (0x92cc >> 2),
  432. 0x00000000,
  433. (0x0e00 << 16) | (0x92d0 >> 2),
  434. 0x00000000,
  435. (0x0e00 << 16) | (0x8c00 >> 2),
  436. 0x00000000,
  437. (0x0e00 << 16) | (0x8c04 >> 2),
  438. 0x00000000,
  439. (0x0e00 << 16) | (0x8c20 >> 2),
  440. 0x00000000,
  441. (0x0e00 << 16) | (0x8c38 >> 2),
  442. 0x00000000,
  443. (0x0e00 << 16) | (0x8c3c >> 2),
  444. 0x00000000,
  445. (0x0e00 << 16) | (0xae00 >> 2),
  446. 0x00000000,
  447. (0x0e00 << 16) | (0x9604 >> 2),
  448. 0x00000000,
  449. (0x0e00 << 16) | (0xac08 >> 2),
  450. 0x00000000,
  451. (0x0e00 << 16) | (0xac0c >> 2),
  452. 0x00000000,
  453. (0x0e00 << 16) | (0xac10 >> 2),
  454. 0x00000000,
  455. (0x0e00 << 16) | (0xac14 >> 2),
  456. 0x00000000,
  457. (0x0e00 << 16) | (0xac58 >> 2),
  458. 0x00000000,
  459. (0x0e00 << 16) | (0xac68 >> 2),
  460. 0x00000000,
  461. (0x0e00 << 16) | (0xac6c >> 2),
  462. 0x00000000,
  463. (0x0e00 << 16) | (0xac70 >> 2),
  464. 0x00000000,
  465. (0x0e00 << 16) | (0xac74 >> 2),
  466. 0x00000000,
  467. (0x0e00 << 16) | (0xac78 >> 2),
  468. 0x00000000,
  469. (0x0e00 << 16) | (0xac7c >> 2),
  470. 0x00000000,
  471. (0x0e00 << 16) | (0xac80 >> 2),
  472. 0x00000000,
  473. (0x0e00 << 16) | (0xac84 >> 2),
  474. 0x00000000,
  475. (0x0e00 << 16) | (0xac88 >> 2),
  476. 0x00000000,
  477. (0x0e00 << 16) | (0xac8c >> 2),
  478. 0x00000000,
  479. (0x0e00 << 16) | (0x970c >> 2),
  480. 0x00000000,
  481. (0x0e00 << 16) | (0x9714 >> 2),
  482. 0x00000000,
  483. (0x0e00 << 16) | (0x9718 >> 2),
  484. 0x00000000,
  485. (0x0e00 << 16) | (0x971c >> 2),
  486. 0x00000000,
  487. (0x0e00 << 16) | (0x31068 >> 2),
  488. 0x00000000,
  489. (0x4e00 << 16) | (0x31068 >> 2),
  490. 0x00000000,
  491. (0x5e00 << 16) | (0x31068 >> 2),
  492. 0x00000000,
  493. (0x6e00 << 16) | (0x31068 >> 2),
  494. 0x00000000,
  495. (0x7e00 << 16) | (0x31068 >> 2),
  496. 0x00000000,
  497. (0x8e00 << 16) | (0x31068 >> 2),
  498. 0x00000000,
  499. (0x9e00 << 16) | (0x31068 >> 2),
  500. 0x00000000,
  501. (0xae00 << 16) | (0x31068 >> 2),
  502. 0x00000000,
  503. (0xbe00 << 16) | (0x31068 >> 2),
  504. 0x00000000,
  505. (0x0e00 << 16) | (0xcd10 >> 2),
  506. 0x00000000,
  507. (0x0e00 << 16) | (0xcd14 >> 2),
  508. 0x00000000,
  509. (0x0e00 << 16) | (0x88b0 >> 2),
  510. 0x00000000,
  511. (0x0e00 << 16) | (0x88b4 >> 2),
  512. 0x00000000,
  513. (0x0e00 << 16) | (0x88b8 >> 2),
  514. 0x00000000,
  515. (0x0e00 << 16) | (0x88bc >> 2),
  516. 0x00000000,
  517. (0x0400 << 16) | (0x89c0 >> 2),
  518. 0x00000000,
  519. (0x0e00 << 16) | (0x88c4 >> 2),
  520. 0x00000000,
  521. (0x0e00 << 16) | (0x88c8 >> 2),
  522. 0x00000000,
  523. (0x0e00 << 16) | (0x88d0 >> 2),
  524. 0x00000000,
  525. (0x0e00 << 16) | (0x88d4 >> 2),
  526. 0x00000000,
  527. (0x0e00 << 16) | (0x88d8 >> 2),
  528. 0x00000000,
  529. (0x0e00 << 16) | (0x8980 >> 2),
  530. 0x00000000,
  531. (0x0e00 << 16) | (0x30938 >> 2),
  532. 0x00000000,
  533. (0x0e00 << 16) | (0x3093c >> 2),
  534. 0x00000000,
  535. (0x0e00 << 16) | (0x30940 >> 2),
  536. 0x00000000,
  537. (0x0e00 << 16) | (0x89a0 >> 2),
  538. 0x00000000,
  539. (0x0e00 << 16) | (0x30900 >> 2),
  540. 0x00000000,
  541. (0x0e00 << 16) | (0x30904 >> 2),
  542. 0x00000000,
  543. (0x0e00 << 16) | (0x89b4 >> 2),
  544. 0x00000000,
  545. (0x0e00 << 16) | (0x3c210 >> 2),
  546. 0x00000000,
  547. (0x0e00 << 16) | (0x3c214 >> 2),
  548. 0x00000000,
  549. (0x0e00 << 16) | (0x3c218 >> 2),
  550. 0x00000000,
  551. (0x0e00 << 16) | (0x8904 >> 2),
  552. 0x00000000,
  553. 0x5,
  554. (0x0e00 << 16) | (0x8c28 >> 2),
  555. (0x0e00 << 16) | (0x8c2c >> 2),
  556. (0x0e00 << 16) | (0x8c30 >> 2),
  557. (0x0e00 << 16) | (0x8c34 >> 2),
  558. (0x0e00 << 16) | (0x9600 >> 2),
  559. };
  560. static const u32 kalindi_rlc_save_restore_register_list[] =
  561. {
  562. (0x0e00 << 16) | (0xc12c >> 2),
  563. 0x00000000,
  564. (0x0e00 << 16) | (0xc140 >> 2),
  565. 0x00000000,
  566. (0x0e00 << 16) | (0xc150 >> 2),
  567. 0x00000000,
  568. (0x0e00 << 16) | (0xc15c >> 2),
  569. 0x00000000,
  570. (0x0e00 << 16) | (0xc168 >> 2),
  571. 0x00000000,
  572. (0x0e00 << 16) | (0xc170 >> 2),
  573. 0x00000000,
  574. (0x0e00 << 16) | (0xc204 >> 2),
  575. 0x00000000,
  576. (0x0e00 << 16) | (0xc2b4 >> 2),
  577. 0x00000000,
  578. (0x0e00 << 16) | (0xc2b8 >> 2),
  579. 0x00000000,
  580. (0x0e00 << 16) | (0xc2bc >> 2),
  581. 0x00000000,
  582. (0x0e00 << 16) | (0xc2c0 >> 2),
  583. 0x00000000,
  584. (0x0e00 << 16) | (0x8228 >> 2),
  585. 0x00000000,
  586. (0x0e00 << 16) | (0x829c >> 2),
  587. 0x00000000,
  588. (0x0e00 << 16) | (0x869c >> 2),
  589. 0x00000000,
  590. (0x0600 << 16) | (0x98f4 >> 2),
  591. 0x00000000,
  592. (0x0e00 << 16) | (0x98f8 >> 2),
  593. 0x00000000,
  594. (0x0e00 << 16) | (0x9900 >> 2),
  595. 0x00000000,
  596. (0x0e00 << 16) | (0xc260 >> 2),
  597. 0x00000000,
  598. (0x0e00 << 16) | (0x90e8 >> 2),
  599. 0x00000000,
  600. (0x0e00 << 16) | (0x3c000 >> 2),
  601. 0x00000000,
  602. (0x0e00 << 16) | (0x3c00c >> 2),
  603. 0x00000000,
  604. (0x0e00 << 16) | (0x8c1c >> 2),
  605. 0x00000000,
  606. (0x0e00 << 16) | (0x9700 >> 2),
  607. 0x00000000,
  608. (0x0e00 << 16) | (0xcd20 >> 2),
  609. 0x00000000,
  610. (0x4e00 << 16) | (0xcd20 >> 2),
  611. 0x00000000,
  612. (0x5e00 << 16) | (0xcd20 >> 2),
  613. 0x00000000,
  614. (0x6e00 << 16) | (0xcd20 >> 2),
  615. 0x00000000,
  616. (0x7e00 << 16) | (0xcd20 >> 2),
  617. 0x00000000,
  618. (0x0e00 << 16) | (0x89bc >> 2),
  619. 0x00000000,
  620. (0x0e00 << 16) | (0x8900 >> 2),
  621. 0x00000000,
  622. 0x3,
  623. (0x0e00 << 16) | (0xc130 >> 2),
  624. 0x00000000,
  625. (0x0e00 << 16) | (0xc134 >> 2),
  626. 0x00000000,
  627. (0x0e00 << 16) | (0xc1fc >> 2),
  628. 0x00000000,
  629. (0x0e00 << 16) | (0xc208 >> 2),
  630. 0x00000000,
  631. (0x0e00 << 16) | (0xc264 >> 2),
  632. 0x00000000,
  633. (0x0e00 << 16) | (0xc268 >> 2),
  634. 0x00000000,
  635. (0x0e00 << 16) | (0xc26c >> 2),
  636. 0x00000000,
  637. (0x0e00 << 16) | (0xc270 >> 2),
  638. 0x00000000,
  639. (0x0e00 << 16) | (0xc274 >> 2),
  640. 0x00000000,
  641. (0x0e00 << 16) | (0xc28c >> 2),
  642. 0x00000000,
  643. (0x0e00 << 16) | (0xc290 >> 2),
  644. 0x00000000,
  645. (0x0e00 << 16) | (0xc294 >> 2),
  646. 0x00000000,
  647. (0x0e00 << 16) | (0xc298 >> 2),
  648. 0x00000000,
  649. (0x0e00 << 16) | (0xc2a0 >> 2),
  650. 0x00000000,
  651. (0x0e00 << 16) | (0xc2a4 >> 2),
  652. 0x00000000,
  653. (0x0e00 << 16) | (0xc2a8 >> 2),
  654. 0x00000000,
  655. (0x0e00 << 16) | (0xc2ac >> 2),
  656. 0x00000000,
  657. (0x0e00 << 16) | (0x301d0 >> 2),
  658. 0x00000000,
  659. (0x0e00 << 16) | (0x30238 >> 2),
  660. 0x00000000,
  661. (0x0e00 << 16) | (0x30250 >> 2),
  662. 0x00000000,
  663. (0x0e00 << 16) | (0x30254 >> 2),
  664. 0x00000000,
  665. (0x0e00 << 16) | (0x30258 >> 2),
  666. 0x00000000,
  667. (0x0e00 << 16) | (0x3025c >> 2),
  668. 0x00000000,
  669. (0x4e00 << 16) | (0xc900 >> 2),
  670. 0x00000000,
  671. (0x5e00 << 16) | (0xc900 >> 2),
  672. 0x00000000,
  673. (0x6e00 << 16) | (0xc900 >> 2),
  674. 0x00000000,
  675. (0x7e00 << 16) | (0xc900 >> 2),
  676. 0x00000000,
  677. (0x4e00 << 16) | (0xc904 >> 2),
  678. 0x00000000,
  679. (0x5e00 << 16) | (0xc904 >> 2),
  680. 0x00000000,
  681. (0x6e00 << 16) | (0xc904 >> 2),
  682. 0x00000000,
  683. (0x7e00 << 16) | (0xc904 >> 2),
  684. 0x00000000,
  685. (0x4e00 << 16) | (0xc908 >> 2),
  686. 0x00000000,
  687. (0x5e00 << 16) | (0xc908 >> 2),
  688. 0x00000000,
  689. (0x6e00 << 16) | (0xc908 >> 2),
  690. 0x00000000,
  691. (0x7e00 << 16) | (0xc908 >> 2),
  692. 0x00000000,
  693. (0x4e00 << 16) | (0xc90c >> 2),
  694. 0x00000000,
  695. (0x5e00 << 16) | (0xc90c >> 2),
  696. 0x00000000,
  697. (0x6e00 << 16) | (0xc90c >> 2),
  698. 0x00000000,
  699. (0x7e00 << 16) | (0xc90c >> 2),
  700. 0x00000000,
  701. (0x4e00 << 16) | (0xc910 >> 2),
  702. 0x00000000,
  703. (0x5e00 << 16) | (0xc910 >> 2),
  704. 0x00000000,
  705. (0x6e00 << 16) | (0xc910 >> 2),
  706. 0x00000000,
  707. (0x7e00 << 16) | (0xc910 >> 2),
  708. 0x00000000,
  709. (0x0e00 << 16) | (0xc99c >> 2),
  710. 0x00000000,
  711. (0x0e00 << 16) | (0x9834 >> 2),
  712. 0x00000000,
  713. (0x0000 << 16) | (0x30f00 >> 2),
  714. 0x00000000,
  715. (0x0000 << 16) | (0x30f04 >> 2),
  716. 0x00000000,
  717. (0x0000 << 16) | (0x30f08 >> 2),
  718. 0x00000000,
  719. (0x0000 << 16) | (0x30f0c >> 2),
  720. 0x00000000,
  721. (0x0600 << 16) | (0x9b7c >> 2),
  722. 0x00000000,
  723. (0x0e00 << 16) | (0x8a14 >> 2),
  724. 0x00000000,
  725. (0x0e00 << 16) | (0x8a18 >> 2),
  726. 0x00000000,
  727. (0x0600 << 16) | (0x30a00 >> 2),
  728. 0x00000000,
  729. (0x0e00 << 16) | (0x8bf0 >> 2),
  730. 0x00000000,
  731. (0x0e00 << 16) | (0x8bcc >> 2),
  732. 0x00000000,
  733. (0x0e00 << 16) | (0x8b24 >> 2),
  734. 0x00000000,
  735. (0x0e00 << 16) | (0x30a04 >> 2),
  736. 0x00000000,
  737. (0x0600 << 16) | (0x30a10 >> 2),
  738. 0x00000000,
  739. (0x0600 << 16) | (0x30a14 >> 2),
  740. 0x00000000,
  741. (0x0600 << 16) | (0x30a18 >> 2),
  742. 0x00000000,
  743. (0x0600 << 16) | (0x30a2c >> 2),
  744. 0x00000000,
  745. (0x0e00 << 16) | (0xc700 >> 2),
  746. 0x00000000,
  747. (0x0e00 << 16) | (0xc704 >> 2),
  748. 0x00000000,
  749. (0x0e00 << 16) | (0xc708 >> 2),
  750. 0x00000000,
  751. (0x0e00 << 16) | (0xc768 >> 2),
  752. 0x00000000,
  753. (0x0400 << 16) | (0xc770 >> 2),
  754. 0x00000000,
  755. (0x0400 << 16) | (0xc774 >> 2),
  756. 0x00000000,
  757. (0x0400 << 16) | (0xc798 >> 2),
  758. 0x00000000,
  759. (0x0400 << 16) | (0xc79c >> 2),
  760. 0x00000000,
  761. (0x0e00 << 16) | (0x9100 >> 2),
  762. 0x00000000,
  763. (0x0e00 << 16) | (0x3c010 >> 2),
  764. 0x00000000,
  765. (0x0e00 << 16) | (0x8c00 >> 2),
  766. 0x00000000,
  767. (0x0e00 << 16) | (0x8c04 >> 2),
  768. 0x00000000,
  769. (0x0e00 << 16) | (0x8c20 >> 2),
  770. 0x00000000,
  771. (0x0e00 << 16) | (0x8c38 >> 2),
  772. 0x00000000,
  773. (0x0e00 << 16) | (0x8c3c >> 2),
  774. 0x00000000,
  775. (0x0e00 << 16) | (0xae00 >> 2),
  776. 0x00000000,
  777. (0x0e00 << 16) | (0x9604 >> 2),
  778. 0x00000000,
  779. (0x0e00 << 16) | (0xac08 >> 2),
  780. 0x00000000,
  781. (0x0e00 << 16) | (0xac0c >> 2),
  782. 0x00000000,
  783. (0x0e00 << 16) | (0xac10 >> 2),
  784. 0x00000000,
  785. (0x0e00 << 16) | (0xac14 >> 2),
  786. 0x00000000,
  787. (0x0e00 << 16) | (0xac58 >> 2),
  788. 0x00000000,
  789. (0x0e00 << 16) | (0xac68 >> 2),
  790. 0x00000000,
  791. (0x0e00 << 16) | (0xac6c >> 2),
  792. 0x00000000,
  793. (0x0e00 << 16) | (0xac70 >> 2),
  794. 0x00000000,
  795. (0x0e00 << 16) | (0xac74 >> 2),
  796. 0x00000000,
  797. (0x0e00 << 16) | (0xac78 >> 2),
  798. 0x00000000,
  799. (0x0e00 << 16) | (0xac7c >> 2),
  800. 0x00000000,
  801. (0x0e00 << 16) | (0xac80 >> 2),
  802. 0x00000000,
  803. (0x0e00 << 16) | (0xac84 >> 2),
  804. 0x00000000,
  805. (0x0e00 << 16) | (0xac88 >> 2),
  806. 0x00000000,
  807. (0x0e00 << 16) | (0xac8c >> 2),
  808. 0x00000000,
  809. (0x0e00 << 16) | (0x970c >> 2),
  810. 0x00000000,
  811. (0x0e00 << 16) | (0x9714 >> 2),
  812. 0x00000000,
  813. (0x0e00 << 16) | (0x9718 >> 2),
  814. 0x00000000,
  815. (0x0e00 << 16) | (0x971c >> 2),
  816. 0x00000000,
  817. (0x0e00 << 16) | (0x31068 >> 2),
  818. 0x00000000,
  819. (0x4e00 << 16) | (0x31068 >> 2),
  820. 0x00000000,
  821. (0x5e00 << 16) | (0x31068 >> 2),
  822. 0x00000000,
  823. (0x6e00 << 16) | (0x31068 >> 2),
  824. 0x00000000,
  825. (0x7e00 << 16) | (0x31068 >> 2),
  826. 0x00000000,
  827. (0x0e00 << 16) | (0xcd10 >> 2),
  828. 0x00000000,
  829. (0x0e00 << 16) | (0xcd14 >> 2),
  830. 0x00000000,
  831. (0x0e00 << 16) | (0x88b0 >> 2),
  832. 0x00000000,
  833. (0x0e00 << 16) | (0x88b4 >> 2),
  834. 0x00000000,
  835. (0x0e00 << 16) | (0x88b8 >> 2),
  836. 0x00000000,
  837. (0x0e00 << 16) | (0x88bc >> 2),
  838. 0x00000000,
  839. (0x0400 << 16) | (0x89c0 >> 2),
  840. 0x00000000,
  841. (0x0e00 << 16) | (0x88c4 >> 2),
  842. 0x00000000,
  843. (0x0e00 << 16) | (0x88c8 >> 2),
  844. 0x00000000,
  845. (0x0e00 << 16) | (0x88d0 >> 2),
  846. 0x00000000,
  847. (0x0e00 << 16) | (0x88d4 >> 2),
  848. 0x00000000,
  849. (0x0e00 << 16) | (0x88d8 >> 2),
  850. 0x00000000,
  851. (0x0e00 << 16) | (0x8980 >> 2),
  852. 0x00000000,
  853. (0x0e00 << 16) | (0x30938 >> 2),
  854. 0x00000000,
  855. (0x0e00 << 16) | (0x3093c >> 2),
  856. 0x00000000,
  857. (0x0e00 << 16) | (0x30940 >> 2),
  858. 0x00000000,
  859. (0x0e00 << 16) | (0x89a0 >> 2),
  860. 0x00000000,
  861. (0x0e00 << 16) | (0x30900 >> 2),
  862. 0x00000000,
  863. (0x0e00 << 16) | (0x30904 >> 2),
  864. 0x00000000,
  865. (0x0e00 << 16) | (0x89b4 >> 2),
  866. 0x00000000,
  867. (0x0e00 << 16) | (0x3e1fc >> 2),
  868. 0x00000000,
  869. (0x0e00 << 16) | (0x3c210 >> 2),
  870. 0x00000000,
  871. (0x0e00 << 16) | (0x3c214 >> 2),
  872. 0x00000000,
  873. (0x0e00 << 16) | (0x3c218 >> 2),
  874. 0x00000000,
  875. (0x0e00 << 16) | (0x8904 >> 2),
  876. 0x00000000,
  877. 0x5,
  878. (0x0e00 << 16) | (0x8c28 >> 2),
  879. (0x0e00 << 16) | (0x8c2c >> 2),
  880. (0x0e00 << 16) | (0x8c30 >> 2),
  881. (0x0e00 << 16) | (0x8c34 >> 2),
  882. (0x0e00 << 16) | (0x9600 >> 2),
  883. };
  884. static const u32 bonaire_golden_spm_registers[] =
  885. {
  886. 0x30800, 0xe0ffffff, 0xe0000000
  887. };
  888. static const u32 bonaire_golden_common_registers[] =
  889. {
  890. 0xc770, 0xffffffff, 0x00000800,
  891. 0xc774, 0xffffffff, 0x00000800,
  892. 0xc798, 0xffffffff, 0x00007fbf,
  893. 0xc79c, 0xffffffff, 0x00007faf
  894. };
  895. static const u32 bonaire_golden_registers[] =
  896. {
  897. 0x3354, 0x00000333, 0x00000333,
  898. 0x3350, 0x000c0fc0, 0x00040200,
  899. 0x9a10, 0x00010000, 0x00058208,
  900. 0x3c000, 0xffff1fff, 0x00140000,
  901. 0x3c200, 0xfdfc0fff, 0x00000100,
  902. 0x3c234, 0x40000000, 0x40000200,
  903. 0x9830, 0xffffffff, 0x00000000,
  904. 0x9834, 0xf00fffff, 0x00000400,
  905. 0x9838, 0x0002021c, 0x00020200,
  906. 0xc78, 0x00000080, 0x00000000,
  907. 0x5bb0, 0x000000f0, 0x00000070,
  908. 0x5bc0, 0xf0311fff, 0x80300000,
  909. 0x98f8, 0x73773777, 0x12010001,
  910. 0x350c, 0x00810000, 0x408af000,
  911. 0x7030, 0x31000111, 0x00000011,
  912. 0x2f48, 0x73773777, 0x12010001,
  913. 0x220c, 0x00007fb6, 0x0021a1b1,
  914. 0x2210, 0x00007fb6, 0x002021b1,
  915. 0x2180, 0x00007fb6, 0x00002191,
  916. 0x2218, 0x00007fb6, 0x002121b1,
  917. 0x221c, 0x00007fb6, 0x002021b1,
  918. 0x21dc, 0x00007fb6, 0x00002191,
  919. 0x21e0, 0x00007fb6, 0x00002191,
  920. 0x3628, 0x0000003f, 0x0000000a,
  921. 0x362c, 0x0000003f, 0x0000000a,
  922. 0x2ae4, 0x00073ffe, 0x000022a2,
  923. 0x240c, 0x000007ff, 0x00000000,
  924. 0x8a14, 0xf000003f, 0x00000007,
  925. 0x8bf0, 0x00002001, 0x00000001,
  926. 0x8b24, 0xffffffff, 0x00ffffff,
  927. 0x30a04, 0x0000ff0f, 0x00000000,
  928. 0x28a4c, 0x07ffffff, 0x06000000,
  929. 0x4d8, 0x00000fff, 0x00000100,
  930. 0x3e78, 0x00000001, 0x00000002,
  931. 0x9100, 0x03000000, 0x0362c688,
  932. 0x8c00, 0x000000ff, 0x00000001,
  933. 0xe40, 0x00001fff, 0x00001fff,
  934. 0x9060, 0x0000007f, 0x00000020,
  935. 0x9508, 0x00010000, 0x00010000,
  936. 0xac14, 0x000003ff, 0x000000f3,
  937. 0xac0c, 0xffffffff, 0x00001032
  938. };
  939. static const u32 bonaire_mgcg_cgcg_init[] =
  940. {
  941. 0xc420, 0xffffffff, 0xfffffffc,
  942. 0x30800, 0xffffffff, 0xe0000000,
  943. 0x3c2a0, 0xffffffff, 0x00000100,
  944. 0x3c208, 0xffffffff, 0x00000100,
  945. 0x3c2c0, 0xffffffff, 0xc0000100,
  946. 0x3c2c8, 0xffffffff, 0xc0000100,
  947. 0x3c2c4, 0xffffffff, 0xc0000100,
  948. 0x55e4, 0xffffffff, 0x00600100,
  949. 0x3c280, 0xffffffff, 0x00000100,
  950. 0x3c214, 0xffffffff, 0x06000100,
  951. 0x3c220, 0xffffffff, 0x00000100,
  952. 0x3c218, 0xffffffff, 0x06000100,
  953. 0x3c204, 0xffffffff, 0x00000100,
  954. 0x3c2e0, 0xffffffff, 0x00000100,
  955. 0x3c224, 0xffffffff, 0x00000100,
  956. 0x3c200, 0xffffffff, 0x00000100,
  957. 0x3c230, 0xffffffff, 0x00000100,
  958. 0x3c234, 0xffffffff, 0x00000100,
  959. 0x3c250, 0xffffffff, 0x00000100,
  960. 0x3c254, 0xffffffff, 0x00000100,
  961. 0x3c258, 0xffffffff, 0x00000100,
  962. 0x3c25c, 0xffffffff, 0x00000100,
  963. 0x3c260, 0xffffffff, 0x00000100,
  964. 0x3c27c, 0xffffffff, 0x00000100,
  965. 0x3c278, 0xffffffff, 0x00000100,
  966. 0x3c210, 0xffffffff, 0x06000100,
  967. 0x3c290, 0xffffffff, 0x00000100,
  968. 0x3c274, 0xffffffff, 0x00000100,
  969. 0x3c2b4, 0xffffffff, 0x00000100,
  970. 0x3c2b0, 0xffffffff, 0x00000100,
  971. 0x3c270, 0xffffffff, 0x00000100,
  972. 0x30800, 0xffffffff, 0xe0000000,
  973. 0x3c020, 0xffffffff, 0x00010000,
  974. 0x3c024, 0xffffffff, 0x00030002,
  975. 0x3c028, 0xffffffff, 0x00040007,
  976. 0x3c02c, 0xffffffff, 0x00060005,
  977. 0x3c030, 0xffffffff, 0x00090008,
  978. 0x3c034, 0xffffffff, 0x00010000,
  979. 0x3c038, 0xffffffff, 0x00030002,
  980. 0x3c03c, 0xffffffff, 0x00040007,
  981. 0x3c040, 0xffffffff, 0x00060005,
  982. 0x3c044, 0xffffffff, 0x00090008,
  983. 0x3c048, 0xffffffff, 0x00010000,
  984. 0x3c04c, 0xffffffff, 0x00030002,
  985. 0x3c050, 0xffffffff, 0x00040007,
  986. 0x3c054, 0xffffffff, 0x00060005,
  987. 0x3c058, 0xffffffff, 0x00090008,
  988. 0x3c05c, 0xffffffff, 0x00010000,
  989. 0x3c060, 0xffffffff, 0x00030002,
  990. 0x3c064, 0xffffffff, 0x00040007,
  991. 0x3c068, 0xffffffff, 0x00060005,
  992. 0x3c06c, 0xffffffff, 0x00090008,
  993. 0x3c070, 0xffffffff, 0x00010000,
  994. 0x3c074, 0xffffffff, 0x00030002,
  995. 0x3c078, 0xffffffff, 0x00040007,
  996. 0x3c07c, 0xffffffff, 0x00060005,
  997. 0x3c080, 0xffffffff, 0x00090008,
  998. 0x3c084, 0xffffffff, 0x00010000,
  999. 0x3c088, 0xffffffff, 0x00030002,
  1000. 0x3c08c, 0xffffffff, 0x00040007,
  1001. 0x3c090, 0xffffffff, 0x00060005,
  1002. 0x3c094, 0xffffffff, 0x00090008,
  1003. 0x3c098, 0xffffffff, 0x00010000,
  1004. 0x3c09c, 0xffffffff, 0x00030002,
  1005. 0x3c0a0, 0xffffffff, 0x00040007,
  1006. 0x3c0a4, 0xffffffff, 0x00060005,
  1007. 0x3c0a8, 0xffffffff, 0x00090008,
  1008. 0x3c000, 0xffffffff, 0x96e00200,
  1009. 0x8708, 0xffffffff, 0x00900100,
  1010. 0xc424, 0xffffffff, 0x0020003f,
  1011. 0x38, 0xffffffff, 0x0140001c,
  1012. 0x3c, 0x000f0000, 0x000f0000,
  1013. 0x220, 0xffffffff, 0xC060000C,
  1014. 0x224, 0xc0000fff, 0x00000100,
  1015. 0xf90, 0xffffffff, 0x00000100,
  1016. 0xf98, 0x00000101, 0x00000000,
  1017. 0x20a8, 0xffffffff, 0x00000104,
  1018. 0x55e4, 0xff000fff, 0x00000100,
  1019. 0x30cc, 0xc0000fff, 0x00000104,
  1020. 0xc1e4, 0x00000001, 0x00000001,
  1021. 0xd00c, 0xff000ff0, 0x00000100,
  1022. 0xd80c, 0xff000ff0, 0x00000100
  1023. };
  1024. static const u32 spectre_golden_spm_registers[] =
  1025. {
  1026. 0x30800, 0xe0ffffff, 0xe0000000
  1027. };
  1028. static const u32 spectre_golden_common_registers[] =
  1029. {
  1030. 0xc770, 0xffffffff, 0x00000800,
  1031. 0xc774, 0xffffffff, 0x00000800,
  1032. 0xc798, 0xffffffff, 0x00007fbf,
  1033. 0xc79c, 0xffffffff, 0x00007faf
  1034. };
  1035. static const u32 spectre_golden_registers[] =
  1036. {
  1037. 0x3c000, 0xffff1fff, 0x96940200,
  1038. 0x3c00c, 0xffff0001, 0xff000000,
  1039. 0x3c200, 0xfffc0fff, 0x00000100,
  1040. 0x6ed8, 0x00010101, 0x00010000,
  1041. 0x9834, 0xf00fffff, 0x00000400,
  1042. 0x9838, 0xfffffffc, 0x00020200,
  1043. 0x5bb0, 0x000000f0, 0x00000070,
  1044. 0x5bc0, 0xf0311fff, 0x80300000,
  1045. 0x98f8, 0x73773777, 0x12010001,
  1046. 0x9b7c, 0x00ff0000, 0x00fc0000,
  1047. 0x2f48, 0x73773777, 0x12010001,
  1048. 0x8a14, 0xf000003f, 0x00000007,
  1049. 0x8b24, 0xffffffff, 0x00ffffff,
  1050. 0x28350, 0x3f3f3fff, 0x00000082,
  1051. 0x28355, 0x0000003f, 0x00000000,
  1052. 0x3e78, 0x00000001, 0x00000002,
  1053. 0x913c, 0xffff03df, 0x00000004,
  1054. 0xc768, 0x00000008, 0x00000008,
  1055. 0x8c00, 0x000008ff, 0x00000800,
  1056. 0x9508, 0x00010000, 0x00010000,
  1057. 0xac0c, 0xffffffff, 0x54763210,
  1058. 0x214f8, 0x01ff01ff, 0x00000002,
  1059. 0x21498, 0x007ff800, 0x00200000,
  1060. 0x2015c, 0xffffffff, 0x00000f40,
  1061. 0x30934, 0xffffffff, 0x00000001
  1062. };
  1063. static const u32 spectre_mgcg_cgcg_init[] =
  1064. {
  1065. 0xc420, 0xffffffff, 0xfffffffc,
  1066. 0x30800, 0xffffffff, 0xe0000000,
  1067. 0x3c2a0, 0xffffffff, 0x00000100,
  1068. 0x3c208, 0xffffffff, 0x00000100,
  1069. 0x3c2c0, 0xffffffff, 0x00000100,
  1070. 0x3c2c8, 0xffffffff, 0x00000100,
  1071. 0x3c2c4, 0xffffffff, 0x00000100,
  1072. 0x55e4, 0xffffffff, 0x00600100,
  1073. 0x3c280, 0xffffffff, 0x00000100,
  1074. 0x3c214, 0xffffffff, 0x06000100,
  1075. 0x3c220, 0xffffffff, 0x00000100,
  1076. 0x3c218, 0xffffffff, 0x06000100,
  1077. 0x3c204, 0xffffffff, 0x00000100,
  1078. 0x3c2e0, 0xffffffff, 0x00000100,
  1079. 0x3c224, 0xffffffff, 0x00000100,
  1080. 0x3c200, 0xffffffff, 0x00000100,
  1081. 0x3c230, 0xffffffff, 0x00000100,
  1082. 0x3c234, 0xffffffff, 0x00000100,
  1083. 0x3c250, 0xffffffff, 0x00000100,
  1084. 0x3c254, 0xffffffff, 0x00000100,
  1085. 0x3c258, 0xffffffff, 0x00000100,
  1086. 0x3c25c, 0xffffffff, 0x00000100,
  1087. 0x3c260, 0xffffffff, 0x00000100,
  1088. 0x3c27c, 0xffffffff, 0x00000100,
  1089. 0x3c278, 0xffffffff, 0x00000100,
  1090. 0x3c210, 0xffffffff, 0x06000100,
  1091. 0x3c290, 0xffffffff, 0x00000100,
  1092. 0x3c274, 0xffffffff, 0x00000100,
  1093. 0x3c2b4, 0xffffffff, 0x00000100,
  1094. 0x3c2b0, 0xffffffff, 0x00000100,
  1095. 0x3c270, 0xffffffff, 0x00000100,
  1096. 0x30800, 0xffffffff, 0xe0000000,
  1097. 0x3c020, 0xffffffff, 0x00010000,
  1098. 0x3c024, 0xffffffff, 0x00030002,
  1099. 0x3c028, 0xffffffff, 0x00040007,
  1100. 0x3c02c, 0xffffffff, 0x00060005,
  1101. 0x3c030, 0xffffffff, 0x00090008,
  1102. 0x3c034, 0xffffffff, 0x00010000,
  1103. 0x3c038, 0xffffffff, 0x00030002,
  1104. 0x3c03c, 0xffffffff, 0x00040007,
  1105. 0x3c040, 0xffffffff, 0x00060005,
  1106. 0x3c044, 0xffffffff, 0x00090008,
  1107. 0x3c048, 0xffffffff, 0x00010000,
  1108. 0x3c04c, 0xffffffff, 0x00030002,
  1109. 0x3c050, 0xffffffff, 0x00040007,
  1110. 0x3c054, 0xffffffff, 0x00060005,
  1111. 0x3c058, 0xffffffff, 0x00090008,
  1112. 0x3c05c, 0xffffffff, 0x00010000,
  1113. 0x3c060, 0xffffffff, 0x00030002,
  1114. 0x3c064, 0xffffffff, 0x00040007,
  1115. 0x3c068, 0xffffffff, 0x00060005,
  1116. 0x3c06c, 0xffffffff, 0x00090008,
  1117. 0x3c070, 0xffffffff, 0x00010000,
  1118. 0x3c074, 0xffffffff, 0x00030002,
  1119. 0x3c078, 0xffffffff, 0x00040007,
  1120. 0x3c07c, 0xffffffff, 0x00060005,
  1121. 0x3c080, 0xffffffff, 0x00090008,
  1122. 0x3c084, 0xffffffff, 0x00010000,
  1123. 0x3c088, 0xffffffff, 0x00030002,
  1124. 0x3c08c, 0xffffffff, 0x00040007,
  1125. 0x3c090, 0xffffffff, 0x00060005,
  1126. 0x3c094, 0xffffffff, 0x00090008,
  1127. 0x3c098, 0xffffffff, 0x00010000,
  1128. 0x3c09c, 0xffffffff, 0x00030002,
  1129. 0x3c0a0, 0xffffffff, 0x00040007,
  1130. 0x3c0a4, 0xffffffff, 0x00060005,
  1131. 0x3c0a8, 0xffffffff, 0x00090008,
  1132. 0x3c0ac, 0xffffffff, 0x00010000,
  1133. 0x3c0b0, 0xffffffff, 0x00030002,
  1134. 0x3c0b4, 0xffffffff, 0x00040007,
  1135. 0x3c0b8, 0xffffffff, 0x00060005,
  1136. 0x3c0bc, 0xffffffff, 0x00090008,
  1137. 0x3c000, 0xffffffff, 0x96e00200,
  1138. 0x8708, 0xffffffff, 0x00900100,
  1139. 0xc424, 0xffffffff, 0x0020003f,
  1140. 0x38, 0xffffffff, 0x0140001c,
  1141. 0x3c, 0x000f0000, 0x000f0000,
  1142. 0x220, 0xffffffff, 0xC060000C,
  1143. 0x224, 0xc0000fff, 0x00000100,
  1144. 0xf90, 0xffffffff, 0x00000100,
  1145. 0xf98, 0x00000101, 0x00000000,
  1146. 0x20a8, 0xffffffff, 0x00000104,
  1147. 0x55e4, 0xff000fff, 0x00000100,
  1148. 0x30cc, 0xc0000fff, 0x00000104,
  1149. 0xc1e4, 0x00000001, 0x00000001,
  1150. 0xd00c, 0xff000ff0, 0x00000100,
  1151. 0xd80c, 0xff000ff0, 0x00000100
  1152. };
  1153. static const u32 kalindi_golden_spm_registers[] =
  1154. {
  1155. 0x30800, 0xe0ffffff, 0xe0000000
  1156. };
  1157. static const u32 kalindi_golden_common_registers[] =
  1158. {
  1159. 0xc770, 0xffffffff, 0x00000800,
  1160. 0xc774, 0xffffffff, 0x00000800,
  1161. 0xc798, 0xffffffff, 0x00007fbf,
  1162. 0xc79c, 0xffffffff, 0x00007faf
  1163. };
  1164. static const u32 kalindi_golden_registers[] =
  1165. {
  1166. 0x3c000, 0xffffdfff, 0x6e944040,
  1167. 0x55e4, 0xff607fff, 0xfc000100,
  1168. 0x3c220, 0xff000fff, 0x00000100,
  1169. 0x3c224, 0xff000fff, 0x00000100,
  1170. 0x3c200, 0xfffc0fff, 0x00000100,
  1171. 0x6ed8, 0x00010101, 0x00010000,
  1172. 0x9830, 0xffffffff, 0x00000000,
  1173. 0x9834, 0xf00fffff, 0x00000400,
  1174. 0x5bb0, 0x000000f0, 0x00000070,
  1175. 0x5bc0, 0xf0311fff, 0x80300000,
  1176. 0x98f8, 0x73773777, 0x12010001,
  1177. 0x98fc, 0xffffffff, 0x00000010,
  1178. 0x9b7c, 0x00ff0000, 0x00fc0000,
  1179. 0x8030, 0x00001f0f, 0x0000100a,
  1180. 0x2f48, 0x73773777, 0x12010001,
  1181. 0x2408, 0x000fffff, 0x000c007f,
  1182. 0x8a14, 0xf000003f, 0x00000007,
  1183. 0x8b24, 0x3fff3fff, 0x00ffcfff,
  1184. 0x30a04, 0x0000ff0f, 0x00000000,
  1185. 0x28a4c, 0x07ffffff, 0x06000000,
  1186. 0x4d8, 0x00000fff, 0x00000100,
  1187. 0x3e78, 0x00000001, 0x00000002,
  1188. 0xc768, 0x00000008, 0x00000008,
  1189. 0x8c00, 0x000000ff, 0x00000003,
  1190. 0x214f8, 0x01ff01ff, 0x00000002,
  1191. 0x21498, 0x007ff800, 0x00200000,
  1192. 0x2015c, 0xffffffff, 0x00000f40,
  1193. 0x88c4, 0x001f3ae3, 0x00000082,
  1194. 0x88d4, 0x0000001f, 0x00000010,
  1195. 0x30934, 0xffffffff, 0x00000000
  1196. };
  1197. static const u32 kalindi_mgcg_cgcg_init[] =
  1198. {
  1199. 0xc420, 0xffffffff, 0xfffffffc,
  1200. 0x30800, 0xffffffff, 0xe0000000,
  1201. 0x3c2a0, 0xffffffff, 0x00000100,
  1202. 0x3c208, 0xffffffff, 0x00000100,
  1203. 0x3c2c0, 0xffffffff, 0x00000100,
  1204. 0x3c2c8, 0xffffffff, 0x00000100,
  1205. 0x3c2c4, 0xffffffff, 0x00000100,
  1206. 0x55e4, 0xffffffff, 0x00600100,
  1207. 0x3c280, 0xffffffff, 0x00000100,
  1208. 0x3c214, 0xffffffff, 0x06000100,
  1209. 0x3c220, 0xffffffff, 0x00000100,
  1210. 0x3c218, 0xffffffff, 0x06000100,
  1211. 0x3c204, 0xffffffff, 0x00000100,
  1212. 0x3c2e0, 0xffffffff, 0x00000100,
  1213. 0x3c224, 0xffffffff, 0x00000100,
  1214. 0x3c200, 0xffffffff, 0x00000100,
  1215. 0x3c230, 0xffffffff, 0x00000100,
  1216. 0x3c234, 0xffffffff, 0x00000100,
  1217. 0x3c250, 0xffffffff, 0x00000100,
  1218. 0x3c254, 0xffffffff, 0x00000100,
  1219. 0x3c258, 0xffffffff, 0x00000100,
  1220. 0x3c25c, 0xffffffff, 0x00000100,
  1221. 0x3c260, 0xffffffff, 0x00000100,
  1222. 0x3c27c, 0xffffffff, 0x00000100,
  1223. 0x3c278, 0xffffffff, 0x00000100,
  1224. 0x3c210, 0xffffffff, 0x06000100,
  1225. 0x3c290, 0xffffffff, 0x00000100,
  1226. 0x3c274, 0xffffffff, 0x00000100,
  1227. 0x3c2b4, 0xffffffff, 0x00000100,
  1228. 0x3c2b0, 0xffffffff, 0x00000100,
  1229. 0x3c270, 0xffffffff, 0x00000100,
  1230. 0x30800, 0xffffffff, 0xe0000000,
  1231. 0x3c020, 0xffffffff, 0x00010000,
  1232. 0x3c024, 0xffffffff, 0x00030002,
  1233. 0x3c028, 0xffffffff, 0x00040007,
  1234. 0x3c02c, 0xffffffff, 0x00060005,
  1235. 0x3c030, 0xffffffff, 0x00090008,
  1236. 0x3c034, 0xffffffff, 0x00010000,
  1237. 0x3c038, 0xffffffff, 0x00030002,
  1238. 0x3c03c, 0xffffffff, 0x00040007,
  1239. 0x3c040, 0xffffffff, 0x00060005,
  1240. 0x3c044, 0xffffffff, 0x00090008,
  1241. 0x3c000, 0xffffffff, 0x96e00200,
  1242. 0x8708, 0xffffffff, 0x00900100,
  1243. 0xc424, 0xffffffff, 0x0020003f,
  1244. 0x38, 0xffffffff, 0x0140001c,
  1245. 0x3c, 0x000f0000, 0x000f0000,
  1246. 0x220, 0xffffffff, 0xC060000C,
  1247. 0x224, 0xc0000fff, 0x00000100,
  1248. 0x20a8, 0xffffffff, 0x00000104,
  1249. 0x55e4, 0xff000fff, 0x00000100,
  1250. 0x30cc, 0xc0000fff, 0x00000104,
  1251. 0xc1e4, 0x00000001, 0x00000001,
  1252. 0xd00c, 0xff000ff0, 0x00000100,
  1253. 0xd80c, 0xff000ff0, 0x00000100
  1254. };
  1255. static void cik_init_golden_registers(struct radeon_device *rdev)
  1256. {
  1257. switch (rdev->family) {
  1258. case CHIP_BONAIRE:
  1259. radeon_program_register_sequence(rdev,
  1260. bonaire_mgcg_cgcg_init,
  1261. (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
  1262. radeon_program_register_sequence(rdev,
  1263. bonaire_golden_registers,
  1264. (const u32)ARRAY_SIZE(bonaire_golden_registers));
  1265. radeon_program_register_sequence(rdev,
  1266. bonaire_golden_common_registers,
  1267. (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
  1268. radeon_program_register_sequence(rdev,
  1269. bonaire_golden_spm_registers,
  1270. (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
  1271. break;
  1272. case CHIP_KABINI:
  1273. radeon_program_register_sequence(rdev,
  1274. kalindi_mgcg_cgcg_init,
  1275. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  1276. radeon_program_register_sequence(rdev,
  1277. kalindi_golden_registers,
  1278. (const u32)ARRAY_SIZE(kalindi_golden_registers));
  1279. radeon_program_register_sequence(rdev,
  1280. kalindi_golden_common_registers,
  1281. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  1282. radeon_program_register_sequence(rdev,
  1283. kalindi_golden_spm_registers,
  1284. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  1285. break;
  1286. case CHIP_KAVERI:
  1287. radeon_program_register_sequence(rdev,
  1288. spectre_mgcg_cgcg_init,
  1289. (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
  1290. radeon_program_register_sequence(rdev,
  1291. spectre_golden_registers,
  1292. (const u32)ARRAY_SIZE(spectre_golden_registers));
  1293. radeon_program_register_sequence(rdev,
  1294. spectre_golden_common_registers,
  1295. (const u32)ARRAY_SIZE(spectre_golden_common_registers));
  1296. radeon_program_register_sequence(rdev,
  1297. spectre_golden_spm_registers,
  1298. (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
  1299. break;
  1300. default:
  1301. break;
  1302. }
  1303. }
  1304. /**
  1305. * cik_get_xclk - get the xclk
  1306. *
  1307. * @rdev: radeon_device pointer
  1308. *
  1309. * Returns the reference clock used by the gfx engine
  1310. * (CIK).
  1311. */
  1312. u32 cik_get_xclk(struct radeon_device *rdev)
  1313. {
  1314. u32 reference_clock = rdev->clock.spll.reference_freq;
  1315. if (rdev->flags & RADEON_IS_IGP) {
  1316. if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
  1317. return reference_clock / 2;
  1318. } else {
  1319. if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
  1320. return reference_clock / 4;
  1321. }
  1322. return reference_clock;
  1323. }
  1324. /**
  1325. * cik_mm_rdoorbell - read a doorbell dword
  1326. *
  1327. * @rdev: radeon_device pointer
  1328. * @offset: byte offset into the aperture
  1329. *
  1330. * Returns the value in the doorbell aperture at the
  1331. * requested offset (CIK).
  1332. */
  1333. u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset)
  1334. {
  1335. if (offset < rdev->doorbell.size) {
  1336. return readl(((void __iomem *)rdev->doorbell.ptr) + offset);
  1337. } else {
  1338. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", offset);
  1339. return 0;
  1340. }
  1341. }
  1342. /**
  1343. * cik_mm_wdoorbell - write a doorbell dword
  1344. *
  1345. * @rdev: radeon_device pointer
  1346. * @offset: byte offset into the aperture
  1347. * @v: value to write
  1348. *
  1349. * Writes @v to the doorbell aperture at the
  1350. * requested offset (CIK).
  1351. */
  1352. void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v)
  1353. {
  1354. if (offset < rdev->doorbell.size) {
  1355. writel(v, ((void __iomem *)rdev->doorbell.ptr) + offset);
  1356. } else {
  1357. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", offset);
  1358. }
  1359. }
  1360. #define BONAIRE_IO_MC_REGS_SIZE 36
  1361. static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
  1362. {
  1363. {0x00000070, 0x04400000},
  1364. {0x00000071, 0x80c01803},
  1365. {0x00000072, 0x00004004},
  1366. {0x00000073, 0x00000100},
  1367. {0x00000074, 0x00ff0000},
  1368. {0x00000075, 0x34000000},
  1369. {0x00000076, 0x08000014},
  1370. {0x00000077, 0x00cc08ec},
  1371. {0x00000078, 0x00000400},
  1372. {0x00000079, 0x00000000},
  1373. {0x0000007a, 0x04090000},
  1374. {0x0000007c, 0x00000000},
  1375. {0x0000007e, 0x4408a8e8},
  1376. {0x0000007f, 0x00000304},
  1377. {0x00000080, 0x00000000},
  1378. {0x00000082, 0x00000001},
  1379. {0x00000083, 0x00000002},
  1380. {0x00000084, 0xf3e4f400},
  1381. {0x00000085, 0x052024e3},
  1382. {0x00000087, 0x00000000},
  1383. {0x00000088, 0x01000000},
  1384. {0x0000008a, 0x1c0a0000},
  1385. {0x0000008b, 0xff010000},
  1386. {0x0000008d, 0xffffefff},
  1387. {0x0000008e, 0xfff3efff},
  1388. {0x0000008f, 0xfff3efbf},
  1389. {0x00000092, 0xf7ffffff},
  1390. {0x00000093, 0xffffff7f},
  1391. {0x00000095, 0x00101101},
  1392. {0x00000096, 0x00000fff},
  1393. {0x00000097, 0x00116fff},
  1394. {0x00000098, 0x60010000},
  1395. {0x00000099, 0x10010000},
  1396. {0x0000009a, 0x00006000},
  1397. {0x0000009b, 0x00001000},
  1398. {0x0000009f, 0x00b48000}
  1399. };
  1400. /**
  1401. * cik_srbm_select - select specific register instances
  1402. *
  1403. * @rdev: radeon_device pointer
  1404. * @me: selected ME (micro engine)
  1405. * @pipe: pipe
  1406. * @queue: queue
  1407. * @vmid: VMID
  1408. *
  1409. * Switches the currently active registers instances. Some
  1410. * registers are instanced per VMID, others are instanced per
  1411. * me/pipe/queue combination.
  1412. */
  1413. static void cik_srbm_select(struct radeon_device *rdev,
  1414. u32 me, u32 pipe, u32 queue, u32 vmid)
  1415. {
  1416. u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
  1417. MEID(me & 0x3) |
  1418. VMID(vmid & 0xf) |
  1419. QUEUEID(queue & 0x7));
  1420. WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
  1421. }
  1422. /* ucode loading */
  1423. /**
  1424. * ci_mc_load_microcode - load MC ucode into the hw
  1425. *
  1426. * @rdev: radeon_device pointer
  1427. *
  1428. * Load the GDDR MC ucode into the hw (CIK).
  1429. * Returns 0 on success, error on failure.
  1430. */
  1431. static int ci_mc_load_microcode(struct radeon_device *rdev)
  1432. {
  1433. const __be32 *fw_data;
  1434. u32 running, blackout = 0;
  1435. u32 *io_mc_regs;
  1436. int i, ucode_size, regs_size;
  1437. if (!rdev->mc_fw)
  1438. return -EINVAL;
  1439. switch (rdev->family) {
  1440. case CHIP_BONAIRE:
  1441. default:
  1442. io_mc_regs = (u32 *)&bonaire_io_mc_regs;
  1443. ucode_size = CIK_MC_UCODE_SIZE;
  1444. regs_size = BONAIRE_IO_MC_REGS_SIZE;
  1445. break;
  1446. }
  1447. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1448. if (running == 0) {
  1449. if (running) {
  1450. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1451. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1452. }
  1453. /* reset the engine and set to writable */
  1454. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1455. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1456. /* load mc io regs */
  1457. for (i = 0; i < regs_size; i++) {
  1458. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1459. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1460. }
  1461. /* load the MC ucode */
  1462. fw_data = (const __be32 *)rdev->mc_fw->data;
  1463. for (i = 0; i < ucode_size; i++)
  1464. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1465. /* put the engine back into the active state */
  1466. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1467. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1468. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1469. /* wait for training to complete */
  1470. for (i = 0; i < rdev->usec_timeout; i++) {
  1471. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1472. break;
  1473. udelay(1);
  1474. }
  1475. for (i = 0; i < rdev->usec_timeout; i++) {
  1476. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1477. break;
  1478. udelay(1);
  1479. }
  1480. if (running)
  1481. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1482. }
  1483. return 0;
  1484. }
  1485. /**
  1486. * cik_init_microcode - load ucode images from disk
  1487. *
  1488. * @rdev: radeon_device pointer
  1489. *
  1490. * Use the firmware interface to load the ucode images into
  1491. * the driver (not loaded into hw).
  1492. * Returns 0 on success, error on failure.
  1493. */
  1494. static int cik_init_microcode(struct radeon_device *rdev)
  1495. {
  1496. const char *chip_name;
  1497. size_t pfp_req_size, me_req_size, ce_req_size,
  1498. mec_req_size, rlc_req_size, mc_req_size,
  1499. sdma_req_size;
  1500. char fw_name[30];
  1501. int err;
  1502. DRM_DEBUG("\n");
  1503. switch (rdev->family) {
  1504. case CHIP_BONAIRE:
  1505. chip_name = "BONAIRE";
  1506. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1507. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1508. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1509. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1510. rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
  1511. mc_req_size = CIK_MC_UCODE_SIZE * 4;
  1512. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1513. break;
  1514. case CHIP_KAVERI:
  1515. chip_name = "KAVERI";
  1516. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1517. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1518. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1519. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1520. rlc_req_size = KV_RLC_UCODE_SIZE * 4;
  1521. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1522. break;
  1523. case CHIP_KABINI:
  1524. chip_name = "KABINI";
  1525. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1526. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1527. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1528. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1529. rlc_req_size = KB_RLC_UCODE_SIZE * 4;
  1530. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1531. break;
  1532. default: BUG();
  1533. }
  1534. DRM_INFO("Loading %s Microcode\n", chip_name);
  1535. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1536. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  1537. if (err)
  1538. goto out;
  1539. if (rdev->pfp_fw->size != pfp_req_size) {
  1540. printk(KERN_ERR
  1541. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  1542. rdev->pfp_fw->size, fw_name);
  1543. err = -EINVAL;
  1544. goto out;
  1545. }
  1546. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1547. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  1548. if (err)
  1549. goto out;
  1550. if (rdev->me_fw->size != me_req_size) {
  1551. printk(KERN_ERR
  1552. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  1553. rdev->me_fw->size, fw_name);
  1554. err = -EINVAL;
  1555. }
  1556. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1557. err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
  1558. if (err)
  1559. goto out;
  1560. if (rdev->ce_fw->size != ce_req_size) {
  1561. printk(KERN_ERR
  1562. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  1563. rdev->ce_fw->size, fw_name);
  1564. err = -EINVAL;
  1565. }
  1566. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
  1567. err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
  1568. if (err)
  1569. goto out;
  1570. if (rdev->mec_fw->size != mec_req_size) {
  1571. printk(KERN_ERR
  1572. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  1573. rdev->mec_fw->size, fw_name);
  1574. err = -EINVAL;
  1575. }
  1576. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
  1577. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  1578. if (err)
  1579. goto out;
  1580. if (rdev->rlc_fw->size != rlc_req_size) {
  1581. printk(KERN_ERR
  1582. "cik_rlc: Bogus length %zu in firmware \"%s\"\n",
  1583. rdev->rlc_fw->size, fw_name);
  1584. err = -EINVAL;
  1585. }
  1586. snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", chip_name);
  1587. err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
  1588. if (err)
  1589. goto out;
  1590. if (rdev->sdma_fw->size != sdma_req_size) {
  1591. printk(KERN_ERR
  1592. "cik_sdma: Bogus length %zu in firmware \"%s\"\n",
  1593. rdev->sdma_fw->size, fw_name);
  1594. err = -EINVAL;
  1595. }
  1596. /* No MC ucode on APUs */
  1597. if (!(rdev->flags & RADEON_IS_IGP)) {
  1598. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1599. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  1600. if (err)
  1601. goto out;
  1602. if (rdev->mc_fw->size != mc_req_size) {
  1603. printk(KERN_ERR
  1604. "cik_mc: Bogus length %zu in firmware \"%s\"\n",
  1605. rdev->mc_fw->size, fw_name);
  1606. err = -EINVAL;
  1607. }
  1608. }
  1609. out:
  1610. if (err) {
  1611. if (err != -EINVAL)
  1612. printk(KERN_ERR
  1613. "cik_cp: Failed to load firmware \"%s\"\n",
  1614. fw_name);
  1615. release_firmware(rdev->pfp_fw);
  1616. rdev->pfp_fw = NULL;
  1617. release_firmware(rdev->me_fw);
  1618. rdev->me_fw = NULL;
  1619. release_firmware(rdev->ce_fw);
  1620. rdev->ce_fw = NULL;
  1621. release_firmware(rdev->rlc_fw);
  1622. rdev->rlc_fw = NULL;
  1623. release_firmware(rdev->mc_fw);
  1624. rdev->mc_fw = NULL;
  1625. }
  1626. return err;
  1627. }
  1628. /*
  1629. * Core functions
  1630. */
  1631. /**
  1632. * cik_tiling_mode_table_init - init the hw tiling table
  1633. *
  1634. * @rdev: radeon_device pointer
  1635. *
  1636. * Starting with SI, the tiling setup is done globally in a
  1637. * set of 32 tiling modes. Rather than selecting each set of
  1638. * parameters per surface as on older asics, we just select
  1639. * which index in the tiling table we want to use, and the
  1640. * surface uses those parameters (CIK).
  1641. */
  1642. static void cik_tiling_mode_table_init(struct radeon_device *rdev)
  1643. {
  1644. const u32 num_tile_mode_states = 32;
  1645. const u32 num_secondary_tile_mode_states = 16;
  1646. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  1647. u32 num_pipe_configs;
  1648. u32 num_rbs = rdev->config.cik.max_backends_per_se *
  1649. rdev->config.cik.max_shader_engines;
  1650. switch (rdev->config.cik.mem_row_size_in_kb) {
  1651. case 1:
  1652. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  1653. break;
  1654. case 2:
  1655. default:
  1656. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  1657. break;
  1658. case 4:
  1659. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  1660. break;
  1661. }
  1662. num_pipe_configs = rdev->config.cik.max_tile_pipes;
  1663. if (num_pipe_configs > 8)
  1664. num_pipe_configs = 8; /* ??? */
  1665. if (num_pipe_configs == 8) {
  1666. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1667. switch (reg_offset) {
  1668. case 0:
  1669. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1670. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1671. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1672. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  1673. break;
  1674. case 1:
  1675. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1676. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1677. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1678. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  1679. break;
  1680. case 2:
  1681. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1682. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1683. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1684. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  1685. break;
  1686. case 3:
  1687. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1688. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1689. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1690. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  1691. break;
  1692. case 4:
  1693. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1694. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1695. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1696. TILE_SPLIT(split_equal_to_row_size));
  1697. break;
  1698. case 5:
  1699. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1700. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1701. break;
  1702. case 6:
  1703. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1704. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1705. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1706. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  1707. break;
  1708. case 7:
  1709. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1710. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1711. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1712. TILE_SPLIT(split_equal_to_row_size));
  1713. break;
  1714. case 8:
  1715. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1716. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
  1717. break;
  1718. case 9:
  1719. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1720. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  1721. break;
  1722. case 10:
  1723. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1724. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1725. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1726. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1727. break;
  1728. case 11:
  1729. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1730. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1731. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1732. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1733. break;
  1734. case 12:
  1735. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1736. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1737. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1738. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1739. break;
  1740. case 13:
  1741. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1742. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1743. break;
  1744. case 14:
  1745. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1746. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1747. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1748. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1749. break;
  1750. case 16:
  1751. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1752. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1753. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1754. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1755. break;
  1756. case 17:
  1757. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1758. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1759. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1760. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1761. break;
  1762. case 27:
  1763. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1764. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  1765. break;
  1766. case 28:
  1767. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1768. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1769. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1770. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1771. break;
  1772. case 29:
  1773. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1774. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1775. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1776. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1777. break;
  1778. case 30:
  1779. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1780. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1781. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  1782. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1783. break;
  1784. default:
  1785. gb_tile_moden = 0;
  1786. break;
  1787. }
  1788. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  1789. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  1790. }
  1791. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  1792. switch (reg_offset) {
  1793. case 0:
  1794. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1795. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1796. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1797. NUM_BANKS(ADDR_SURF_16_BANK));
  1798. break;
  1799. case 1:
  1800. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1801. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1802. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1803. NUM_BANKS(ADDR_SURF_16_BANK));
  1804. break;
  1805. case 2:
  1806. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1807. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1808. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1809. NUM_BANKS(ADDR_SURF_16_BANK));
  1810. break;
  1811. case 3:
  1812. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1813. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1814. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1815. NUM_BANKS(ADDR_SURF_16_BANK));
  1816. break;
  1817. case 4:
  1818. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1819. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1820. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1821. NUM_BANKS(ADDR_SURF_8_BANK));
  1822. break;
  1823. case 5:
  1824. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1825. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1826. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1827. NUM_BANKS(ADDR_SURF_4_BANK));
  1828. break;
  1829. case 6:
  1830. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1831. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1832. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1833. NUM_BANKS(ADDR_SURF_2_BANK));
  1834. break;
  1835. case 8:
  1836. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1837. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  1838. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1839. NUM_BANKS(ADDR_SURF_16_BANK));
  1840. break;
  1841. case 9:
  1842. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1843. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1844. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1845. NUM_BANKS(ADDR_SURF_16_BANK));
  1846. break;
  1847. case 10:
  1848. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1849. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1850. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1851. NUM_BANKS(ADDR_SURF_16_BANK));
  1852. break;
  1853. case 11:
  1854. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1855. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1856. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1857. NUM_BANKS(ADDR_SURF_16_BANK));
  1858. break;
  1859. case 12:
  1860. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1861. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1862. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1863. NUM_BANKS(ADDR_SURF_8_BANK));
  1864. break;
  1865. case 13:
  1866. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1867. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1868. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1869. NUM_BANKS(ADDR_SURF_4_BANK));
  1870. break;
  1871. case 14:
  1872. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1873. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1874. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1875. NUM_BANKS(ADDR_SURF_2_BANK));
  1876. break;
  1877. default:
  1878. gb_tile_moden = 0;
  1879. break;
  1880. }
  1881. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  1882. }
  1883. } else if (num_pipe_configs == 4) {
  1884. if (num_rbs == 4) {
  1885. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1886. switch (reg_offset) {
  1887. case 0:
  1888. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1889. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1890. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1891. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  1892. break;
  1893. case 1:
  1894. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1895. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1896. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1897. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  1898. break;
  1899. case 2:
  1900. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1901. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1902. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1903. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  1904. break;
  1905. case 3:
  1906. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1907. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1908. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1909. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  1910. break;
  1911. case 4:
  1912. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1913. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1914. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1915. TILE_SPLIT(split_equal_to_row_size));
  1916. break;
  1917. case 5:
  1918. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1919. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1920. break;
  1921. case 6:
  1922. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1923. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1924. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1925. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  1926. break;
  1927. case 7:
  1928. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1929. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1930. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1931. TILE_SPLIT(split_equal_to_row_size));
  1932. break;
  1933. case 8:
  1934. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1935. PIPE_CONFIG(ADDR_SURF_P4_16x16));
  1936. break;
  1937. case 9:
  1938. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1939. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  1940. break;
  1941. case 10:
  1942. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1943. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1944. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1945. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1946. break;
  1947. case 11:
  1948. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1949. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1950. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1951. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1952. break;
  1953. case 12:
  1954. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1955. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1956. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1957. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1958. break;
  1959. case 13:
  1960. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1961. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1962. break;
  1963. case 14:
  1964. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1965. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1966. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1967. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1968. break;
  1969. case 16:
  1970. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1971. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1972. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1973. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1974. break;
  1975. case 17:
  1976. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1977. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1978. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1979. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1980. break;
  1981. case 27:
  1982. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1983. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  1984. break;
  1985. case 28:
  1986. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1987. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1988. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1989. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1990. break;
  1991. case 29:
  1992. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1993. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1994. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1995. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1996. break;
  1997. case 30:
  1998. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1999. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2000. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2001. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2002. break;
  2003. default:
  2004. gb_tile_moden = 0;
  2005. break;
  2006. }
  2007. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2008. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2009. }
  2010. } else if (num_rbs < 4) {
  2011. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2012. switch (reg_offset) {
  2013. case 0:
  2014. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2015. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2016. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2017. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2018. break;
  2019. case 1:
  2020. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2021. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2022. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2023. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2024. break;
  2025. case 2:
  2026. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2027. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2028. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2029. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2030. break;
  2031. case 3:
  2032. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2033. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2034. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2035. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2036. break;
  2037. case 4:
  2038. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2039. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2040. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2041. TILE_SPLIT(split_equal_to_row_size));
  2042. break;
  2043. case 5:
  2044. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2045. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2046. break;
  2047. case 6:
  2048. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2049. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2050. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2051. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2052. break;
  2053. case 7:
  2054. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2055. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2056. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2057. TILE_SPLIT(split_equal_to_row_size));
  2058. break;
  2059. case 8:
  2060. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2061. PIPE_CONFIG(ADDR_SURF_P4_8x16));
  2062. break;
  2063. case 9:
  2064. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2065. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2066. break;
  2067. case 10:
  2068. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2069. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2070. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2071. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2072. break;
  2073. case 11:
  2074. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2075. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2076. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2077. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2078. break;
  2079. case 12:
  2080. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2081. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2082. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2083. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2084. break;
  2085. case 13:
  2086. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2087. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2088. break;
  2089. case 14:
  2090. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2091. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2092. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2093. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2094. break;
  2095. case 16:
  2096. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2097. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2098. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2099. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2100. break;
  2101. case 17:
  2102. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2103. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2104. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2105. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2106. break;
  2107. case 27:
  2108. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2109. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2110. break;
  2111. case 28:
  2112. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2113. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2114. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2115. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2116. break;
  2117. case 29:
  2118. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2119. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2120. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2121. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2122. break;
  2123. case 30:
  2124. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2125. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2126. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2127. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2128. break;
  2129. default:
  2130. gb_tile_moden = 0;
  2131. break;
  2132. }
  2133. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2134. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2135. }
  2136. }
  2137. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  2138. switch (reg_offset) {
  2139. case 0:
  2140. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2141. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2142. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2143. NUM_BANKS(ADDR_SURF_16_BANK));
  2144. break;
  2145. case 1:
  2146. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2147. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2148. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2149. NUM_BANKS(ADDR_SURF_16_BANK));
  2150. break;
  2151. case 2:
  2152. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2153. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2154. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2155. NUM_BANKS(ADDR_SURF_16_BANK));
  2156. break;
  2157. case 3:
  2158. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2159. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2160. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2161. NUM_BANKS(ADDR_SURF_16_BANK));
  2162. break;
  2163. case 4:
  2164. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2165. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2166. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2167. NUM_BANKS(ADDR_SURF_16_BANK));
  2168. break;
  2169. case 5:
  2170. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2171. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2172. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2173. NUM_BANKS(ADDR_SURF_8_BANK));
  2174. break;
  2175. case 6:
  2176. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2177. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2178. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2179. NUM_BANKS(ADDR_SURF_4_BANK));
  2180. break;
  2181. case 8:
  2182. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2183. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2184. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2185. NUM_BANKS(ADDR_SURF_16_BANK));
  2186. break;
  2187. case 9:
  2188. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2189. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2190. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2191. NUM_BANKS(ADDR_SURF_16_BANK));
  2192. break;
  2193. case 10:
  2194. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2195. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2196. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2197. NUM_BANKS(ADDR_SURF_16_BANK));
  2198. break;
  2199. case 11:
  2200. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2201. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2202. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2203. NUM_BANKS(ADDR_SURF_16_BANK));
  2204. break;
  2205. case 12:
  2206. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2207. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2208. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2209. NUM_BANKS(ADDR_SURF_16_BANK));
  2210. break;
  2211. case 13:
  2212. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2213. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2214. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2215. NUM_BANKS(ADDR_SURF_8_BANK));
  2216. break;
  2217. case 14:
  2218. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2219. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2220. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2221. NUM_BANKS(ADDR_SURF_4_BANK));
  2222. break;
  2223. default:
  2224. gb_tile_moden = 0;
  2225. break;
  2226. }
  2227. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2228. }
  2229. } else if (num_pipe_configs == 2) {
  2230. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2231. switch (reg_offset) {
  2232. case 0:
  2233. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2234. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2235. PIPE_CONFIG(ADDR_SURF_P2) |
  2236. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2237. break;
  2238. case 1:
  2239. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2240. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2241. PIPE_CONFIG(ADDR_SURF_P2) |
  2242. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2243. break;
  2244. case 2:
  2245. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2246. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2247. PIPE_CONFIG(ADDR_SURF_P2) |
  2248. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2249. break;
  2250. case 3:
  2251. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2252. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2253. PIPE_CONFIG(ADDR_SURF_P2) |
  2254. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2255. break;
  2256. case 4:
  2257. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2258. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2259. PIPE_CONFIG(ADDR_SURF_P2) |
  2260. TILE_SPLIT(split_equal_to_row_size));
  2261. break;
  2262. case 5:
  2263. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2264. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2265. break;
  2266. case 6:
  2267. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2268. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2269. PIPE_CONFIG(ADDR_SURF_P2) |
  2270. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2271. break;
  2272. case 7:
  2273. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2274. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2275. PIPE_CONFIG(ADDR_SURF_P2) |
  2276. TILE_SPLIT(split_equal_to_row_size));
  2277. break;
  2278. case 8:
  2279. gb_tile_moden = ARRAY_MODE(ARRAY_LINEAR_ALIGNED);
  2280. break;
  2281. case 9:
  2282. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2283. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2284. break;
  2285. case 10:
  2286. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2287. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2288. PIPE_CONFIG(ADDR_SURF_P2) |
  2289. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2290. break;
  2291. case 11:
  2292. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2293. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2294. PIPE_CONFIG(ADDR_SURF_P2) |
  2295. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2296. break;
  2297. case 12:
  2298. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2299. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2300. PIPE_CONFIG(ADDR_SURF_P2) |
  2301. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2302. break;
  2303. case 13:
  2304. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2305. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2306. break;
  2307. case 14:
  2308. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2309. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2310. PIPE_CONFIG(ADDR_SURF_P2) |
  2311. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2312. break;
  2313. case 16:
  2314. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2315. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2316. PIPE_CONFIG(ADDR_SURF_P2) |
  2317. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2318. break;
  2319. case 17:
  2320. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2321. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2322. PIPE_CONFIG(ADDR_SURF_P2) |
  2323. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2324. break;
  2325. case 27:
  2326. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2327. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2328. break;
  2329. case 28:
  2330. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2331. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2332. PIPE_CONFIG(ADDR_SURF_P2) |
  2333. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2334. break;
  2335. case 29:
  2336. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2337. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2338. PIPE_CONFIG(ADDR_SURF_P2) |
  2339. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2340. break;
  2341. case 30:
  2342. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2343. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2344. PIPE_CONFIG(ADDR_SURF_P2) |
  2345. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2346. break;
  2347. default:
  2348. gb_tile_moden = 0;
  2349. break;
  2350. }
  2351. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2352. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2353. }
  2354. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  2355. switch (reg_offset) {
  2356. case 0:
  2357. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2358. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2359. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2360. NUM_BANKS(ADDR_SURF_16_BANK));
  2361. break;
  2362. case 1:
  2363. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2364. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2365. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2366. NUM_BANKS(ADDR_SURF_16_BANK));
  2367. break;
  2368. case 2:
  2369. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2370. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2371. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2372. NUM_BANKS(ADDR_SURF_16_BANK));
  2373. break;
  2374. case 3:
  2375. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2376. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2377. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2378. NUM_BANKS(ADDR_SURF_16_BANK));
  2379. break;
  2380. case 4:
  2381. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2382. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2383. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2384. NUM_BANKS(ADDR_SURF_16_BANK));
  2385. break;
  2386. case 5:
  2387. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2388. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2389. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2390. NUM_BANKS(ADDR_SURF_16_BANK));
  2391. break;
  2392. case 6:
  2393. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2394. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2395. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2396. NUM_BANKS(ADDR_SURF_8_BANK));
  2397. break;
  2398. case 8:
  2399. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2400. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2401. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2402. NUM_BANKS(ADDR_SURF_16_BANK));
  2403. break;
  2404. case 9:
  2405. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2406. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2407. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2408. NUM_BANKS(ADDR_SURF_16_BANK));
  2409. break;
  2410. case 10:
  2411. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2412. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2413. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2414. NUM_BANKS(ADDR_SURF_16_BANK));
  2415. break;
  2416. case 11:
  2417. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2418. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2419. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2420. NUM_BANKS(ADDR_SURF_16_BANK));
  2421. break;
  2422. case 12:
  2423. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2424. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2425. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2426. NUM_BANKS(ADDR_SURF_16_BANK));
  2427. break;
  2428. case 13:
  2429. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2430. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2431. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2432. NUM_BANKS(ADDR_SURF_16_BANK));
  2433. break;
  2434. case 14:
  2435. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2436. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2437. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2438. NUM_BANKS(ADDR_SURF_8_BANK));
  2439. break;
  2440. default:
  2441. gb_tile_moden = 0;
  2442. break;
  2443. }
  2444. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2445. }
  2446. } else
  2447. DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
  2448. }
  2449. /**
  2450. * cik_select_se_sh - select which SE, SH to address
  2451. *
  2452. * @rdev: radeon_device pointer
  2453. * @se_num: shader engine to address
  2454. * @sh_num: sh block to address
  2455. *
  2456. * Select which SE, SH combinations to address. Certain
  2457. * registers are instanced per SE or SH. 0xffffffff means
  2458. * broadcast to all SEs or SHs (CIK).
  2459. */
  2460. static void cik_select_se_sh(struct radeon_device *rdev,
  2461. u32 se_num, u32 sh_num)
  2462. {
  2463. u32 data = INSTANCE_BROADCAST_WRITES;
  2464. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2465. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2466. else if (se_num == 0xffffffff)
  2467. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2468. else if (sh_num == 0xffffffff)
  2469. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2470. else
  2471. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2472. WREG32(GRBM_GFX_INDEX, data);
  2473. }
  2474. /**
  2475. * cik_create_bitmask - create a bitmask
  2476. *
  2477. * @bit_width: length of the mask
  2478. *
  2479. * create a variable length bit mask (CIK).
  2480. * Returns the bitmask.
  2481. */
  2482. static u32 cik_create_bitmask(u32 bit_width)
  2483. {
  2484. u32 i, mask = 0;
  2485. for (i = 0; i < bit_width; i++) {
  2486. mask <<= 1;
  2487. mask |= 1;
  2488. }
  2489. return mask;
  2490. }
  2491. /**
  2492. * cik_select_se_sh - select which SE, SH to address
  2493. *
  2494. * @rdev: radeon_device pointer
  2495. * @max_rb_num: max RBs (render backends) for the asic
  2496. * @se_num: number of SEs (shader engines) for the asic
  2497. * @sh_per_se: number of SH blocks per SE for the asic
  2498. *
  2499. * Calculates the bitmask of disabled RBs (CIK).
  2500. * Returns the disabled RB bitmask.
  2501. */
  2502. static u32 cik_get_rb_disabled(struct radeon_device *rdev,
  2503. u32 max_rb_num, u32 se_num,
  2504. u32 sh_per_se)
  2505. {
  2506. u32 data, mask;
  2507. data = RREG32(CC_RB_BACKEND_DISABLE);
  2508. if (data & 1)
  2509. data &= BACKEND_DISABLE_MASK;
  2510. else
  2511. data = 0;
  2512. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2513. data >>= BACKEND_DISABLE_SHIFT;
  2514. mask = cik_create_bitmask(max_rb_num / se_num / sh_per_se);
  2515. return data & mask;
  2516. }
  2517. /**
  2518. * cik_setup_rb - setup the RBs on the asic
  2519. *
  2520. * @rdev: radeon_device pointer
  2521. * @se_num: number of SEs (shader engines) for the asic
  2522. * @sh_per_se: number of SH blocks per SE for the asic
  2523. * @max_rb_num: max RBs (render backends) for the asic
  2524. *
  2525. * Configures per-SE/SH RB registers (CIK).
  2526. */
  2527. static void cik_setup_rb(struct radeon_device *rdev,
  2528. u32 se_num, u32 sh_per_se,
  2529. u32 max_rb_num)
  2530. {
  2531. int i, j;
  2532. u32 data, mask;
  2533. u32 disabled_rbs = 0;
  2534. u32 enabled_rbs = 0;
  2535. for (i = 0; i < se_num; i++) {
  2536. for (j = 0; j < sh_per_se; j++) {
  2537. cik_select_se_sh(rdev, i, j);
  2538. data = cik_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2539. disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
  2540. }
  2541. }
  2542. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2543. mask = 1;
  2544. for (i = 0; i < max_rb_num; i++) {
  2545. if (!(disabled_rbs & mask))
  2546. enabled_rbs |= mask;
  2547. mask <<= 1;
  2548. }
  2549. for (i = 0; i < se_num; i++) {
  2550. cik_select_se_sh(rdev, i, 0xffffffff);
  2551. data = 0;
  2552. for (j = 0; j < sh_per_se; j++) {
  2553. switch (enabled_rbs & 3) {
  2554. case 1:
  2555. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2556. break;
  2557. case 2:
  2558. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2559. break;
  2560. case 3:
  2561. default:
  2562. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2563. break;
  2564. }
  2565. enabled_rbs >>= 2;
  2566. }
  2567. WREG32(PA_SC_RASTER_CONFIG, data);
  2568. }
  2569. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2570. }
  2571. /**
  2572. * cik_gpu_init - setup the 3D engine
  2573. *
  2574. * @rdev: radeon_device pointer
  2575. *
  2576. * Configures the 3D engine and tiling configuration
  2577. * registers so that the 3D engine is usable.
  2578. */
  2579. static void cik_gpu_init(struct radeon_device *rdev)
  2580. {
  2581. u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
  2582. u32 mc_shared_chmap, mc_arb_ramcfg;
  2583. u32 hdp_host_path_cntl;
  2584. u32 tmp;
  2585. int i, j;
  2586. switch (rdev->family) {
  2587. case CHIP_BONAIRE:
  2588. rdev->config.cik.max_shader_engines = 2;
  2589. rdev->config.cik.max_tile_pipes = 4;
  2590. rdev->config.cik.max_cu_per_sh = 7;
  2591. rdev->config.cik.max_sh_per_se = 1;
  2592. rdev->config.cik.max_backends_per_se = 2;
  2593. rdev->config.cik.max_texture_channel_caches = 4;
  2594. rdev->config.cik.max_gprs = 256;
  2595. rdev->config.cik.max_gs_threads = 32;
  2596. rdev->config.cik.max_hw_contexts = 8;
  2597. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  2598. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  2599. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  2600. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  2601. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  2602. break;
  2603. case CHIP_KAVERI:
  2604. /* TODO */
  2605. break;
  2606. case CHIP_KABINI:
  2607. default:
  2608. rdev->config.cik.max_shader_engines = 1;
  2609. rdev->config.cik.max_tile_pipes = 2;
  2610. rdev->config.cik.max_cu_per_sh = 2;
  2611. rdev->config.cik.max_sh_per_se = 1;
  2612. rdev->config.cik.max_backends_per_se = 1;
  2613. rdev->config.cik.max_texture_channel_caches = 2;
  2614. rdev->config.cik.max_gprs = 256;
  2615. rdev->config.cik.max_gs_threads = 16;
  2616. rdev->config.cik.max_hw_contexts = 8;
  2617. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  2618. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  2619. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  2620. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  2621. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  2622. break;
  2623. }
  2624. /* Initialize HDP */
  2625. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2626. WREG32((0x2c14 + j), 0x00000000);
  2627. WREG32((0x2c18 + j), 0x00000000);
  2628. WREG32((0x2c1c + j), 0x00000000);
  2629. WREG32((0x2c20 + j), 0x00000000);
  2630. WREG32((0x2c24 + j), 0x00000000);
  2631. }
  2632. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2633. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2634. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2635. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2636. rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
  2637. rdev->config.cik.mem_max_burst_length_bytes = 256;
  2638. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2639. rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2640. if (rdev->config.cik.mem_row_size_in_kb > 4)
  2641. rdev->config.cik.mem_row_size_in_kb = 4;
  2642. /* XXX use MC settings? */
  2643. rdev->config.cik.shader_engine_tile_size = 32;
  2644. rdev->config.cik.num_gpus = 1;
  2645. rdev->config.cik.multi_gpu_tile_size = 64;
  2646. /* fix up row size */
  2647. gb_addr_config &= ~ROW_SIZE_MASK;
  2648. switch (rdev->config.cik.mem_row_size_in_kb) {
  2649. case 1:
  2650. default:
  2651. gb_addr_config |= ROW_SIZE(0);
  2652. break;
  2653. case 2:
  2654. gb_addr_config |= ROW_SIZE(1);
  2655. break;
  2656. case 4:
  2657. gb_addr_config |= ROW_SIZE(2);
  2658. break;
  2659. }
  2660. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2661. * not have bank info, so create a custom tiling dword.
  2662. * bits 3:0 num_pipes
  2663. * bits 7:4 num_banks
  2664. * bits 11:8 group_size
  2665. * bits 15:12 row_size
  2666. */
  2667. rdev->config.cik.tile_config = 0;
  2668. switch (rdev->config.cik.num_tile_pipes) {
  2669. case 1:
  2670. rdev->config.cik.tile_config |= (0 << 0);
  2671. break;
  2672. case 2:
  2673. rdev->config.cik.tile_config |= (1 << 0);
  2674. break;
  2675. case 4:
  2676. rdev->config.cik.tile_config |= (2 << 0);
  2677. break;
  2678. case 8:
  2679. default:
  2680. /* XXX what about 12? */
  2681. rdev->config.cik.tile_config |= (3 << 0);
  2682. break;
  2683. }
  2684. if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
  2685. rdev->config.cik.tile_config |= 1 << 4;
  2686. else
  2687. rdev->config.cik.tile_config |= 0 << 4;
  2688. rdev->config.cik.tile_config |=
  2689. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2690. rdev->config.cik.tile_config |=
  2691. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2692. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2693. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2694. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2695. WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
  2696. WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
  2697. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2698. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2699. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2700. cik_tiling_mode_table_init(rdev);
  2701. cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
  2702. rdev->config.cik.max_sh_per_se,
  2703. rdev->config.cik.max_backends_per_se);
  2704. /* set HW defaults for 3D engine */
  2705. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2706. WREG32(SX_DEBUG_1, 0x20);
  2707. WREG32(TA_CNTL_AUX, 0x00010000);
  2708. tmp = RREG32(SPI_CONFIG_CNTL);
  2709. tmp |= 0x03000000;
  2710. WREG32(SPI_CONFIG_CNTL, tmp);
  2711. WREG32(SQ_CONFIG, 1);
  2712. WREG32(DB_DEBUG, 0);
  2713. tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
  2714. tmp |= 0x00000400;
  2715. WREG32(DB_DEBUG2, tmp);
  2716. tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
  2717. tmp |= 0x00020200;
  2718. WREG32(DB_DEBUG3, tmp);
  2719. tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
  2720. tmp |= 0x00018208;
  2721. WREG32(CB_HW_CONTROL, tmp);
  2722. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2723. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
  2724. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
  2725. SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
  2726. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
  2727. WREG32(VGT_NUM_INSTANCES, 1);
  2728. WREG32(CP_PERFMON_CNTL, 0);
  2729. WREG32(SQ_CONFIG, 0);
  2730. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2731. FORCE_EOV_MAX_REZ_CNT(255)));
  2732. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2733. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2734. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2735. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2736. tmp = RREG32(HDP_MISC_CNTL);
  2737. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2738. WREG32(HDP_MISC_CNTL, tmp);
  2739. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2740. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2741. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2742. WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
  2743. udelay(50);
  2744. }
  2745. /*
  2746. * GPU scratch registers helpers function.
  2747. */
  2748. /**
  2749. * cik_scratch_init - setup driver info for CP scratch regs
  2750. *
  2751. * @rdev: radeon_device pointer
  2752. *
  2753. * Set up the number and offset of the CP scratch registers.
  2754. * NOTE: use of CP scratch registers is a legacy inferface and
  2755. * is not used by default on newer asics (r6xx+). On newer asics,
  2756. * memory buffers are used for fences rather than scratch regs.
  2757. */
  2758. static void cik_scratch_init(struct radeon_device *rdev)
  2759. {
  2760. int i;
  2761. rdev->scratch.num_reg = 7;
  2762. rdev->scratch.reg_base = SCRATCH_REG0;
  2763. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2764. rdev->scratch.free[i] = true;
  2765. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2766. }
  2767. }
  2768. /**
  2769. * cik_ring_test - basic gfx ring test
  2770. *
  2771. * @rdev: radeon_device pointer
  2772. * @ring: radeon_ring structure holding ring information
  2773. *
  2774. * Allocate a scratch register and write to it using the gfx ring (CIK).
  2775. * Provides a basic gfx ring test to verify that the ring is working.
  2776. * Used by cik_cp_gfx_resume();
  2777. * Returns 0 on success, error on failure.
  2778. */
  2779. int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
  2780. {
  2781. uint32_t scratch;
  2782. uint32_t tmp = 0;
  2783. unsigned i;
  2784. int r;
  2785. r = radeon_scratch_get(rdev, &scratch);
  2786. if (r) {
  2787. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  2788. return r;
  2789. }
  2790. WREG32(scratch, 0xCAFEDEAD);
  2791. r = radeon_ring_lock(rdev, ring, 3);
  2792. if (r) {
  2793. DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
  2794. radeon_scratch_free(rdev, scratch);
  2795. return r;
  2796. }
  2797. radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  2798. radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
  2799. radeon_ring_write(ring, 0xDEADBEEF);
  2800. radeon_ring_unlock_commit(rdev, ring);
  2801. for (i = 0; i < rdev->usec_timeout; i++) {
  2802. tmp = RREG32(scratch);
  2803. if (tmp == 0xDEADBEEF)
  2804. break;
  2805. DRM_UDELAY(1);
  2806. }
  2807. if (i < rdev->usec_timeout) {
  2808. DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
  2809. } else {
  2810. DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  2811. ring->idx, scratch, tmp);
  2812. r = -EINVAL;
  2813. }
  2814. radeon_scratch_free(rdev, scratch);
  2815. return r;
  2816. }
  2817. /**
  2818. * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
  2819. *
  2820. * @rdev: radeon_device pointer
  2821. * @fence: radeon fence object
  2822. *
  2823. * Emits a fence sequnce number on the gfx ring and flushes
  2824. * GPU caches.
  2825. */
  2826. void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
  2827. struct radeon_fence *fence)
  2828. {
  2829. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2830. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2831. /* EVENT_WRITE_EOP - flush caches, send int */
  2832. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2833. radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
  2834. EOP_TC_ACTION_EN |
  2835. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  2836. EVENT_INDEX(5)));
  2837. radeon_ring_write(ring, addr & 0xfffffffc);
  2838. radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
  2839. radeon_ring_write(ring, fence->seq);
  2840. radeon_ring_write(ring, 0);
  2841. /* HDP flush */
  2842. /* We should be using the new WAIT_REG_MEM special op packet here
  2843. * but it causes the CP to hang
  2844. */
  2845. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2846. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  2847. WRITE_DATA_DST_SEL(0)));
  2848. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  2849. radeon_ring_write(ring, 0);
  2850. radeon_ring_write(ring, 0);
  2851. }
  2852. /**
  2853. * cik_fence_compute_ring_emit - emit a fence on the compute ring
  2854. *
  2855. * @rdev: radeon_device pointer
  2856. * @fence: radeon fence object
  2857. *
  2858. * Emits a fence sequnce number on the compute ring and flushes
  2859. * GPU caches.
  2860. */
  2861. void cik_fence_compute_ring_emit(struct radeon_device *rdev,
  2862. struct radeon_fence *fence)
  2863. {
  2864. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2865. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2866. /* RELEASE_MEM - flush caches, send int */
  2867. radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
  2868. radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
  2869. EOP_TC_ACTION_EN |
  2870. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  2871. EVENT_INDEX(5)));
  2872. radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
  2873. radeon_ring_write(ring, addr & 0xfffffffc);
  2874. radeon_ring_write(ring, upper_32_bits(addr));
  2875. radeon_ring_write(ring, fence->seq);
  2876. radeon_ring_write(ring, 0);
  2877. /* HDP flush */
  2878. /* We should be using the new WAIT_REG_MEM special op packet here
  2879. * but it causes the CP to hang
  2880. */
  2881. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2882. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  2883. WRITE_DATA_DST_SEL(0)));
  2884. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  2885. radeon_ring_write(ring, 0);
  2886. radeon_ring_write(ring, 0);
  2887. }
  2888. void cik_semaphore_ring_emit(struct radeon_device *rdev,
  2889. struct radeon_ring *ring,
  2890. struct radeon_semaphore *semaphore,
  2891. bool emit_wait)
  2892. {
  2893. uint64_t addr = semaphore->gpu_addr;
  2894. unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
  2895. radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
  2896. radeon_ring_write(ring, addr & 0xffffffff);
  2897. radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
  2898. }
  2899. /*
  2900. * IB stuff
  2901. */
  2902. /**
  2903. * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
  2904. *
  2905. * @rdev: radeon_device pointer
  2906. * @ib: radeon indirect buffer object
  2907. *
  2908. * Emits an DE (drawing engine) or CE (constant engine) IB
  2909. * on the gfx ring. IBs are usually generated by userspace
  2910. * acceleration drivers and submitted to the kernel for
  2911. * sheduling on the ring. This function schedules the IB
  2912. * on the gfx ring for execution by the GPU.
  2913. */
  2914. void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2915. {
  2916. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2917. u32 header, control = INDIRECT_BUFFER_VALID;
  2918. if (ib->is_const_ib) {
  2919. /* set switch buffer packet before const IB */
  2920. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2921. radeon_ring_write(ring, 0);
  2922. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  2923. } else {
  2924. u32 next_rptr;
  2925. if (ring->rptr_save_reg) {
  2926. next_rptr = ring->wptr + 3 + 4;
  2927. radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  2928. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2929. PACKET3_SET_UCONFIG_REG_START) >> 2));
  2930. radeon_ring_write(ring, next_rptr);
  2931. } else if (rdev->wb.enabled) {
  2932. next_rptr = ring->wptr + 5 + 4;
  2933. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2934. radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
  2935. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2936. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  2937. radeon_ring_write(ring, next_rptr);
  2938. }
  2939. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  2940. }
  2941. control |= ib->length_dw |
  2942. (ib->vm ? (ib->vm->id << 24) : 0);
  2943. radeon_ring_write(ring, header);
  2944. radeon_ring_write(ring,
  2945. #ifdef __BIG_ENDIAN
  2946. (2 << 0) |
  2947. #endif
  2948. (ib->gpu_addr & 0xFFFFFFFC));
  2949. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2950. radeon_ring_write(ring, control);
  2951. }
  2952. /**
  2953. * cik_ib_test - basic gfx ring IB test
  2954. *
  2955. * @rdev: radeon_device pointer
  2956. * @ring: radeon_ring structure holding ring information
  2957. *
  2958. * Allocate an IB and execute it on the gfx ring (CIK).
  2959. * Provides a basic gfx ring test to verify that IBs are working.
  2960. * Returns 0 on success, error on failure.
  2961. */
  2962. int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
  2963. {
  2964. struct radeon_ib ib;
  2965. uint32_t scratch;
  2966. uint32_t tmp = 0;
  2967. unsigned i;
  2968. int r;
  2969. r = radeon_scratch_get(rdev, &scratch);
  2970. if (r) {
  2971. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  2972. return r;
  2973. }
  2974. WREG32(scratch, 0xCAFEDEAD);
  2975. r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
  2976. if (r) {
  2977. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  2978. return r;
  2979. }
  2980. ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
  2981. ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
  2982. ib.ptr[2] = 0xDEADBEEF;
  2983. ib.length_dw = 3;
  2984. r = radeon_ib_schedule(rdev, &ib, NULL);
  2985. if (r) {
  2986. radeon_scratch_free(rdev, scratch);
  2987. radeon_ib_free(rdev, &ib);
  2988. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  2989. return r;
  2990. }
  2991. r = radeon_fence_wait(ib.fence, false);
  2992. if (r) {
  2993. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  2994. return r;
  2995. }
  2996. for (i = 0; i < rdev->usec_timeout; i++) {
  2997. tmp = RREG32(scratch);
  2998. if (tmp == 0xDEADBEEF)
  2999. break;
  3000. DRM_UDELAY(1);
  3001. }
  3002. if (i < rdev->usec_timeout) {
  3003. DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
  3004. } else {
  3005. DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
  3006. scratch, tmp);
  3007. r = -EINVAL;
  3008. }
  3009. radeon_scratch_free(rdev, scratch);
  3010. radeon_ib_free(rdev, &ib);
  3011. return r;
  3012. }
  3013. /*
  3014. * CP.
  3015. * On CIK, gfx and compute now have independant command processors.
  3016. *
  3017. * GFX
  3018. * Gfx consists of a single ring and can process both gfx jobs and
  3019. * compute jobs. The gfx CP consists of three microengines (ME):
  3020. * PFP - Pre-Fetch Parser
  3021. * ME - Micro Engine
  3022. * CE - Constant Engine
  3023. * The PFP and ME make up what is considered the Drawing Engine (DE).
  3024. * The CE is an asynchronous engine used for updating buffer desciptors
  3025. * used by the DE so that they can be loaded into cache in parallel
  3026. * while the DE is processing state update packets.
  3027. *
  3028. * Compute
  3029. * The compute CP consists of two microengines (ME):
  3030. * MEC1 - Compute MicroEngine 1
  3031. * MEC2 - Compute MicroEngine 2
  3032. * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
  3033. * The queues are exposed to userspace and are programmed directly
  3034. * by the compute runtime.
  3035. */
  3036. /**
  3037. * cik_cp_gfx_enable - enable/disable the gfx CP MEs
  3038. *
  3039. * @rdev: radeon_device pointer
  3040. * @enable: enable or disable the MEs
  3041. *
  3042. * Halts or unhalts the gfx MEs.
  3043. */
  3044. static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
  3045. {
  3046. if (enable)
  3047. WREG32(CP_ME_CNTL, 0);
  3048. else {
  3049. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  3050. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3051. }
  3052. udelay(50);
  3053. }
  3054. /**
  3055. * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
  3056. *
  3057. * @rdev: radeon_device pointer
  3058. *
  3059. * Loads the gfx PFP, ME, and CE ucode.
  3060. * Returns 0 for success, -EINVAL if the ucode is not available.
  3061. */
  3062. static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
  3063. {
  3064. const __be32 *fw_data;
  3065. int i;
  3066. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
  3067. return -EINVAL;
  3068. cik_cp_gfx_enable(rdev, false);
  3069. /* PFP */
  3070. fw_data = (const __be32 *)rdev->pfp_fw->data;
  3071. WREG32(CP_PFP_UCODE_ADDR, 0);
  3072. for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
  3073. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  3074. WREG32(CP_PFP_UCODE_ADDR, 0);
  3075. /* CE */
  3076. fw_data = (const __be32 *)rdev->ce_fw->data;
  3077. WREG32(CP_CE_UCODE_ADDR, 0);
  3078. for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
  3079. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  3080. WREG32(CP_CE_UCODE_ADDR, 0);
  3081. /* ME */
  3082. fw_data = (const __be32 *)rdev->me_fw->data;
  3083. WREG32(CP_ME_RAM_WADDR, 0);
  3084. for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
  3085. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  3086. WREG32(CP_ME_RAM_WADDR, 0);
  3087. WREG32(CP_PFP_UCODE_ADDR, 0);
  3088. WREG32(CP_CE_UCODE_ADDR, 0);
  3089. WREG32(CP_ME_RAM_WADDR, 0);
  3090. WREG32(CP_ME_RAM_RADDR, 0);
  3091. return 0;
  3092. }
  3093. /**
  3094. * cik_cp_gfx_start - start the gfx ring
  3095. *
  3096. * @rdev: radeon_device pointer
  3097. *
  3098. * Enables the ring and loads the clear state context and other
  3099. * packets required to init the ring.
  3100. * Returns 0 for success, error for failure.
  3101. */
  3102. static int cik_cp_gfx_start(struct radeon_device *rdev)
  3103. {
  3104. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3105. int r, i;
  3106. /* init the CP */
  3107. WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
  3108. WREG32(CP_ENDIAN_SWAP, 0);
  3109. WREG32(CP_DEVICE_ID, 1);
  3110. cik_cp_gfx_enable(rdev, true);
  3111. r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
  3112. if (r) {
  3113. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3114. return r;
  3115. }
  3116. /* init the CE partitions. CE only used for gfx on CIK */
  3117. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  3118. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  3119. radeon_ring_write(ring, 0xc000);
  3120. radeon_ring_write(ring, 0xc000);
  3121. /* setup clear context state */
  3122. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3123. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3124. radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  3125. radeon_ring_write(ring, 0x80000000);
  3126. radeon_ring_write(ring, 0x80000000);
  3127. for (i = 0; i < cik_default_size; i++)
  3128. radeon_ring_write(ring, cik_default_state[i]);
  3129. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3130. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  3131. /* set clear context state */
  3132. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  3133. radeon_ring_write(ring, 0);
  3134. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3135. radeon_ring_write(ring, 0x00000316);
  3136. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  3137. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  3138. radeon_ring_unlock_commit(rdev, ring);
  3139. return 0;
  3140. }
  3141. /**
  3142. * cik_cp_gfx_fini - stop the gfx ring
  3143. *
  3144. * @rdev: radeon_device pointer
  3145. *
  3146. * Stop the gfx ring and tear down the driver ring
  3147. * info.
  3148. */
  3149. static void cik_cp_gfx_fini(struct radeon_device *rdev)
  3150. {
  3151. cik_cp_gfx_enable(rdev, false);
  3152. radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  3153. }
  3154. /**
  3155. * cik_cp_gfx_resume - setup the gfx ring buffer registers
  3156. *
  3157. * @rdev: radeon_device pointer
  3158. *
  3159. * Program the location and size of the gfx ring buffer
  3160. * and test it to make sure it's working.
  3161. * Returns 0 for success, error for failure.
  3162. */
  3163. static int cik_cp_gfx_resume(struct radeon_device *rdev)
  3164. {
  3165. struct radeon_ring *ring;
  3166. u32 tmp;
  3167. u32 rb_bufsz;
  3168. u64 rb_addr;
  3169. int r;
  3170. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  3171. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  3172. /* Set the write pointer delay */
  3173. WREG32(CP_RB_WPTR_DELAY, 0);
  3174. /* set the RB to use vmid 0 */
  3175. WREG32(CP_RB_VMID, 0);
  3176. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  3177. /* ring 0 - compute and gfx */
  3178. /* Set ring buffer size */
  3179. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3180. rb_bufsz = drm_order(ring->ring_size / 8);
  3181. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3182. #ifdef __BIG_ENDIAN
  3183. tmp |= BUF_SWAP_32BIT;
  3184. #endif
  3185. WREG32(CP_RB0_CNTL, tmp);
  3186. /* Initialize the ring buffer's read and write pointers */
  3187. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  3188. ring->wptr = 0;
  3189. WREG32(CP_RB0_WPTR, ring->wptr);
  3190. /* set the wb address wether it's enabled or not */
  3191. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  3192. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  3193. /* scratch register shadowing is no longer supported */
  3194. WREG32(SCRATCH_UMSK, 0);
  3195. if (!rdev->wb.enabled)
  3196. tmp |= RB_NO_UPDATE;
  3197. mdelay(1);
  3198. WREG32(CP_RB0_CNTL, tmp);
  3199. rb_addr = ring->gpu_addr >> 8;
  3200. WREG32(CP_RB0_BASE, rb_addr);
  3201. WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
  3202. ring->rptr = RREG32(CP_RB0_RPTR);
  3203. /* start the ring */
  3204. cik_cp_gfx_start(rdev);
  3205. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  3206. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  3207. if (r) {
  3208. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3209. return r;
  3210. }
  3211. return 0;
  3212. }
  3213. u32 cik_compute_ring_get_rptr(struct radeon_device *rdev,
  3214. struct radeon_ring *ring)
  3215. {
  3216. u32 rptr;
  3217. if (rdev->wb.enabled) {
  3218. rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]);
  3219. } else {
  3220. mutex_lock(&rdev->srbm_mutex);
  3221. cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
  3222. rptr = RREG32(CP_HQD_PQ_RPTR);
  3223. cik_srbm_select(rdev, 0, 0, 0, 0);
  3224. mutex_unlock(&rdev->srbm_mutex);
  3225. }
  3226. rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
  3227. return rptr;
  3228. }
  3229. u32 cik_compute_ring_get_wptr(struct radeon_device *rdev,
  3230. struct radeon_ring *ring)
  3231. {
  3232. u32 wptr;
  3233. if (rdev->wb.enabled) {
  3234. wptr = le32_to_cpu(rdev->wb.wb[ring->wptr_offs/4]);
  3235. } else {
  3236. mutex_lock(&rdev->srbm_mutex);
  3237. cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
  3238. wptr = RREG32(CP_HQD_PQ_WPTR);
  3239. cik_srbm_select(rdev, 0, 0, 0, 0);
  3240. mutex_unlock(&rdev->srbm_mutex);
  3241. }
  3242. wptr = (wptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
  3243. return wptr;
  3244. }
  3245. void cik_compute_ring_set_wptr(struct radeon_device *rdev,
  3246. struct radeon_ring *ring)
  3247. {
  3248. u32 wptr = (ring->wptr << ring->ptr_reg_shift) & ring->ptr_reg_mask;
  3249. rdev->wb.wb[ring->wptr_offs/4] = cpu_to_le32(wptr);
  3250. WDOORBELL32(ring->doorbell_offset, wptr);
  3251. }
  3252. /**
  3253. * cik_cp_compute_enable - enable/disable the compute CP MEs
  3254. *
  3255. * @rdev: radeon_device pointer
  3256. * @enable: enable or disable the MEs
  3257. *
  3258. * Halts or unhalts the compute MEs.
  3259. */
  3260. static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
  3261. {
  3262. if (enable)
  3263. WREG32(CP_MEC_CNTL, 0);
  3264. else
  3265. WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
  3266. udelay(50);
  3267. }
  3268. /**
  3269. * cik_cp_compute_load_microcode - load the compute CP ME ucode
  3270. *
  3271. * @rdev: radeon_device pointer
  3272. *
  3273. * Loads the compute MEC1&2 ucode.
  3274. * Returns 0 for success, -EINVAL if the ucode is not available.
  3275. */
  3276. static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
  3277. {
  3278. const __be32 *fw_data;
  3279. int i;
  3280. if (!rdev->mec_fw)
  3281. return -EINVAL;
  3282. cik_cp_compute_enable(rdev, false);
  3283. /* MEC1 */
  3284. fw_data = (const __be32 *)rdev->mec_fw->data;
  3285. WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
  3286. for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
  3287. WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
  3288. WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
  3289. if (rdev->family == CHIP_KAVERI) {
  3290. /* MEC2 */
  3291. fw_data = (const __be32 *)rdev->mec_fw->data;
  3292. WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
  3293. for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
  3294. WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
  3295. WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
  3296. }
  3297. return 0;
  3298. }
  3299. /**
  3300. * cik_cp_compute_start - start the compute queues
  3301. *
  3302. * @rdev: radeon_device pointer
  3303. *
  3304. * Enable the compute queues.
  3305. * Returns 0 for success, error for failure.
  3306. */
  3307. static int cik_cp_compute_start(struct radeon_device *rdev)
  3308. {
  3309. cik_cp_compute_enable(rdev, true);
  3310. return 0;
  3311. }
  3312. /**
  3313. * cik_cp_compute_fini - stop the compute queues
  3314. *
  3315. * @rdev: radeon_device pointer
  3316. *
  3317. * Stop the compute queues and tear down the driver queue
  3318. * info.
  3319. */
  3320. static void cik_cp_compute_fini(struct radeon_device *rdev)
  3321. {
  3322. int i, idx, r;
  3323. cik_cp_compute_enable(rdev, false);
  3324. for (i = 0; i < 2; i++) {
  3325. if (i == 0)
  3326. idx = CAYMAN_RING_TYPE_CP1_INDEX;
  3327. else
  3328. idx = CAYMAN_RING_TYPE_CP2_INDEX;
  3329. if (rdev->ring[idx].mqd_obj) {
  3330. r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
  3331. if (unlikely(r != 0))
  3332. dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
  3333. radeon_bo_unpin(rdev->ring[idx].mqd_obj);
  3334. radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
  3335. radeon_bo_unref(&rdev->ring[idx].mqd_obj);
  3336. rdev->ring[idx].mqd_obj = NULL;
  3337. }
  3338. }
  3339. }
  3340. static void cik_mec_fini(struct radeon_device *rdev)
  3341. {
  3342. int r;
  3343. if (rdev->mec.hpd_eop_obj) {
  3344. r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
  3345. if (unlikely(r != 0))
  3346. dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
  3347. radeon_bo_unpin(rdev->mec.hpd_eop_obj);
  3348. radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
  3349. radeon_bo_unref(&rdev->mec.hpd_eop_obj);
  3350. rdev->mec.hpd_eop_obj = NULL;
  3351. }
  3352. }
  3353. #define MEC_HPD_SIZE 2048
  3354. static int cik_mec_init(struct radeon_device *rdev)
  3355. {
  3356. int r;
  3357. u32 *hpd;
  3358. /*
  3359. * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
  3360. * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
  3361. */
  3362. if (rdev->family == CHIP_KAVERI)
  3363. rdev->mec.num_mec = 2;
  3364. else
  3365. rdev->mec.num_mec = 1;
  3366. rdev->mec.num_pipe = 4;
  3367. rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
  3368. if (rdev->mec.hpd_eop_obj == NULL) {
  3369. r = radeon_bo_create(rdev,
  3370. rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
  3371. PAGE_SIZE, true,
  3372. RADEON_GEM_DOMAIN_GTT, NULL,
  3373. &rdev->mec.hpd_eop_obj);
  3374. if (r) {
  3375. dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
  3376. return r;
  3377. }
  3378. }
  3379. r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
  3380. if (unlikely(r != 0)) {
  3381. cik_mec_fini(rdev);
  3382. return r;
  3383. }
  3384. r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
  3385. &rdev->mec.hpd_eop_gpu_addr);
  3386. if (r) {
  3387. dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
  3388. cik_mec_fini(rdev);
  3389. return r;
  3390. }
  3391. r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
  3392. if (r) {
  3393. dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
  3394. cik_mec_fini(rdev);
  3395. return r;
  3396. }
  3397. /* clear memory. Not sure if this is required or not */
  3398. memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
  3399. radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
  3400. radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
  3401. return 0;
  3402. }
  3403. struct hqd_registers
  3404. {
  3405. u32 cp_mqd_base_addr;
  3406. u32 cp_mqd_base_addr_hi;
  3407. u32 cp_hqd_active;
  3408. u32 cp_hqd_vmid;
  3409. u32 cp_hqd_persistent_state;
  3410. u32 cp_hqd_pipe_priority;
  3411. u32 cp_hqd_queue_priority;
  3412. u32 cp_hqd_quantum;
  3413. u32 cp_hqd_pq_base;
  3414. u32 cp_hqd_pq_base_hi;
  3415. u32 cp_hqd_pq_rptr;
  3416. u32 cp_hqd_pq_rptr_report_addr;
  3417. u32 cp_hqd_pq_rptr_report_addr_hi;
  3418. u32 cp_hqd_pq_wptr_poll_addr;
  3419. u32 cp_hqd_pq_wptr_poll_addr_hi;
  3420. u32 cp_hqd_pq_doorbell_control;
  3421. u32 cp_hqd_pq_wptr;
  3422. u32 cp_hqd_pq_control;
  3423. u32 cp_hqd_ib_base_addr;
  3424. u32 cp_hqd_ib_base_addr_hi;
  3425. u32 cp_hqd_ib_rptr;
  3426. u32 cp_hqd_ib_control;
  3427. u32 cp_hqd_iq_timer;
  3428. u32 cp_hqd_iq_rptr;
  3429. u32 cp_hqd_dequeue_request;
  3430. u32 cp_hqd_dma_offload;
  3431. u32 cp_hqd_sema_cmd;
  3432. u32 cp_hqd_msg_type;
  3433. u32 cp_hqd_atomic0_preop_lo;
  3434. u32 cp_hqd_atomic0_preop_hi;
  3435. u32 cp_hqd_atomic1_preop_lo;
  3436. u32 cp_hqd_atomic1_preop_hi;
  3437. u32 cp_hqd_hq_scheduler0;
  3438. u32 cp_hqd_hq_scheduler1;
  3439. u32 cp_mqd_control;
  3440. };
  3441. struct bonaire_mqd
  3442. {
  3443. u32 header;
  3444. u32 dispatch_initiator;
  3445. u32 dimensions[3];
  3446. u32 start_idx[3];
  3447. u32 num_threads[3];
  3448. u32 pipeline_stat_enable;
  3449. u32 perf_counter_enable;
  3450. u32 pgm[2];
  3451. u32 tba[2];
  3452. u32 tma[2];
  3453. u32 pgm_rsrc[2];
  3454. u32 vmid;
  3455. u32 resource_limits;
  3456. u32 static_thread_mgmt01[2];
  3457. u32 tmp_ring_size;
  3458. u32 static_thread_mgmt23[2];
  3459. u32 restart[3];
  3460. u32 thread_trace_enable;
  3461. u32 reserved1;
  3462. u32 user_data[16];
  3463. u32 vgtcs_invoke_count[2];
  3464. struct hqd_registers queue_state;
  3465. u32 dequeue_cntr;
  3466. u32 interrupt_queue[64];
  3467. };
  3468. /**
  3469. * cik_cp_compute_resume - setup the compute queue registers
  3470. *
  3471. * @rdev: radeon_device pointer
  3472. *
  3473. * Program the compute queues and test them to make sure they
  3474. * are working.
  3475. * Returns 0 for success, error for failure.
  3476. */
  3477. static int cik_cp_compute_resume(struct radeon_device *rdev)
  3478. {
  3479. int r, i, idx;
  3480. u32 tmp;
  3481. bool use_doorbell = true;
  3482. u64 hqd_gpu_addr;
  3483. u64 mqd_gpu_addr;
  3484. u64 eop_gpu_addr;
  3485. u64 wb_gpu_addr;
  3486. u32 *buf;
  3487. struct bonaire_mqd *mqd;
  3488. r = cik_cp_compute_start(rdev);
  3489. if (r)
  3490. return r;
  3491. /* fix up chicken bits */
  3492. tmp = RREG32(CP_CPF_DEBUG);
  3493. tmp |= (1 << 23);
  3494. WREG32(CP_CPF_DEBUG, tmp);
  3495. /* init the pipes */
  3496. mutex_lock(&rdev->srbm_mutex);
  3497. for (i = 0; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) {
  3498. int me = (i < 4) ? 1 : 2;
  3499. int pipe = (i < 4) ? i : (i - 4);
  3500. eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i * MEC_HPD_SIZE * 2);
  3501. cik_srbm_select(rdev, me, pipe, 0, 0);
  3502. /* write the EOP addr */
  3503. WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
  3504. WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
  3505. /* set the VMID assigned */
  3506. WREG32(CP_HPD_EOP_VMID, 0);
  3507. /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
  3508. tmp = RREG32(CP_HPD_EOP_CONTROL);
  3509. tmp &= ~EOP_SIZE_MASK;
  3510. tmp |= drm_order(MEC_HPD_SIZE / 8);
  3511. WREG32(CP_HPD_EOP_CONTROL, tmp);
  3512. }
  3513. cik_srbm_select(rdev, 0, 0, 0, 0);
  3514. mutex_unlock(&rdev->srbm_mutex);
  3515. /* init the queues. Just two for now. */
  3516. for (i = 0; i < 2; i++) {
  3517. if (i == 0)
  3518. idx = CAYMAN_RING_TYPE_CP1_INDEX;
  3519. else
  3520. idx = CAYMAN_RING_TYPE_CP2_INDEX;
  3521. if (rdev->ring[idx].mqd_obj == NULL) {
  3522. r = radeon_bo_create(rdev,
  3523. sizeof(struct bonaire_mqd),
  3524. PAGE_SIZE, true,
  3525. RADEON_GEM_DOMAIN_GTT, NULL,
  3526. &rdev->ring[idx].mqd_obj);
  3527. if (r) {
  3528. dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
  3529. return r;
  3530. }
  3531. }
  3532. r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
  3533. if (unlikely(r != 0)) {
  3534. cik_cp_compute_fini(rdev);
  3535. return r;
  3536. }
  3537. r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
  3538. &mqd_gpu_addr);
  3539. if (r) {
  3540. dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
  3541. cik_cp_compute_fini(rdev);
  3542. return r;
  3543. }
  3544. r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
  3545. if (r) {
  3546. dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
  3547. cik_cp_compute_fini(rdev);
  3548. return r;
  3549. }
  3550. /* doorbell offset */
  3551. rdev->ring[idx].doorbell_offset =
  3552. (rdev->ring[idx].doorbell_page_num * PAGE_SIZE) + 0;
  3553. /* init the mqd struct */
  3554. memset(buf, 0, sizeof(struct bonaire_mqd));
  3555. mqd = (struct bonaire_mqd *)buf;
  3556. mqd->header = 0xC0310800;
  3557. mqd->static_thread_mgmt01[0] = 0xffffffff;
  3558. mqd->static_thread_mgmt01[1] = 0xffffffff;
  3559. mqd->static_thread_mgmt23[0] = 0xffffffff;
  3560. mqd->static_thread_mgmt23[1] = 0xffffffff;
  3561. mutex_lock(&rdev->srbm_mutex);
  3562. cik_srbm_select(rdev, rdev->ring[idx].me,
  3563. rdev->ring[idx].pipe,
  3564. rdev->ring[idx].queue, 0);
  3565. /* disable wptr polling */
  3566. tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
  3567. tmp &= ~WPTR_POLL_EN;
  3568. WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
  3569. /* enable doorbell? */
  3570. mqd->queue_state.cp_hqd_pq_doorbell_control =
  3571. RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
  3572. if (use_doorbell)
  3573. mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
  3574. else
  3575. mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
  3576. WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
  3577. mqd->queue_state.cp_hqd_pq_doorbell_control);
  3578. /* disable the queue if it's active */
  3579. mqd->queue_state.cp_hqd_dequeue_request = 0;
  3580. mqd->queue_state.cp_hqd_pq_rptr = 0;
  3581. mqd->queue_state.cp_hqd_pq_wptr= 0;
  3582. if (RREG32(CP_HQD_ACTIVE) & 1) {
  3583. WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
  3584. for (i = 0; i < rdev->usec_timeout; i++) {
  3585. if (!(RREG32(CP_HQD_ACTIVE) & 1))
  3586. break;
  3587. udelay(1);
  3588. }
  3589. WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
  3590. WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
  3591. WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
  3592. }
  3593. /* set the pointer to the MQD */
  3594. mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
  3595. mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
  3596. WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
  3597. WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
  3598. /* set MQD vmid to 0 */
  3599. mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
  3600. mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
  3601. WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
  3602. /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
  3603. hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
  3604. mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
  3605. mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
  3606. WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
  3607. WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
  3608. /* set up the HQD, this is similar to CP_RB0_CNTL */
  3609. mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
  3610. mqd->queue_state.cp_hqd_pq_control &=
  3611. ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
  3612. mqd->queue_state.cp_hqd_pq_control |=
  3613. drm_order(rdev->ring[idx].ring_size / 8);
  3614. mqd->queue_state.cp_hqd_pq_control |=
  3615. (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8);
  3616. #ifdef __BIG_ENDIAN
  3617. mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
  3618. #endif
  3619. mqd->queue_state.cp_hqd_pq_control &=
  3620. ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
  3621. mqd->queue_state.cp_hqd_pq_control |=
  3622. PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
  3623. WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
  3624. /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
  3625. if (i == 0)
  3626. wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
  3627. else
  3628. wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
  3629. mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
  3630. mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
  3631. WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
  3632. WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
  3633. mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
  3634. /* set the wb address wether it's enabled or not */
  3635. if (i == 0)
  3636. wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
  3637. else
  3638. wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
  3639. mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
  3640. mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
  3641. upper_32_bits(wb_gpu_addr) & 0xffff;
  3642. WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
  3643. mqd->queue_state.cp_hqd_pq_rptr_report_addr);
  3644. WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
  3645. mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
  3646. /* enable the doorbell if requested */
  3647. if (use_doorbell) {
  3648. mqd->queue_state.cp_hqd_pq_doorbell_control =
  3649. RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
  3650. mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
  3651. mqd->queue_state.cp_hqd_pq_doorbell_control |=
  3652. DOORBELL_OFFSET(rdev->ring[idx].doorbell_offset / 4);
  3653. mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
  3654. mqd->queue_state.cp_hqd_pq_doorbell_control &=
  3655. ~(DOORBELL_SOURCE | DOORBELL_HIT);
  3656. } else {
  3657. mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
  3658. }
  3659. WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
  3660. mqd->queue_state.cp_hqd_pq_doorbell_control);
  3661. /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
  3662. rdev->ring[idx].wptr = 0;
  3663. mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
  3664. WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
  3665. rdev->ring[idx].rptr = RREG32(CP_HQD_PQ_RPTR);
  3666. mqd->queue_state.cp_hqd_pq_rptr = rdev->ring[idx].rptr;
  3667. /* set the vmid for the queue */
  3668. mqd->queue_state.cp_hqd_vmid = 0;
  3669. WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
  3670. /* activate the queue */
  3671. mqd->queue_state.cp_hqd_active = 1;
  3672. WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
  3673. cik_srbm_select(rdev, 0, 0, 0, 0);
  3674. mutex_unlock(&rdev->srbm_mutex);
  3675. radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
  3676. radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
  3677. rdev->ring[idx].ready = true;
  3678. r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
  3679. if (r)
  3680. rdev->ring[idx].ready = false;
  3681. }
  3682. return 0;
  3683. }
  3684. static void cik_cp_enable(struct radeon_device *rdev, bool enable)
  3685. {
  3686. cik_cp_gfx_enable(rdev, enable);
  3687. cik_cp_compute_enable(rdev, enable);
  3688. }
  3689. static int cik_cp_load_microcode(struct radeon_device *rdev)
  3690. {
  3691. int r;
  3692. r = cik_cp_gfx_load_microcode(rdev);
  3693. if (r)
  3694. return r;
  3695. r = cik_cp_compute_load_microcode(rdev);
  3696. if (r)
  3697. return r;
  3698. return 0;
  3699. }
  3700. static void cik_cp_fini(struct radeon_device *rdev)
  3701. {
  3702. cik_cp_gfx_fini(rdev);
  3703. cik_cp_compute_fini(rdev);
  3704. }
  3705. static int cik_cp_resume(struct radeon_device *rdev)
  3706. {
  3707. int r;
  3708. /* Reset all cp blocks */
  3709. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  3710. RREG32(GRBM_SOFT_RESET);
  3711. mdelay(15);
  3712. WREG32(GRBM_SOFT_RESET, 0);
  3713. RREG32(GRBM_SOFT_RESET);
  3714. r = cik_cp_load_microcode(rdev);
  3715. if (r)
  3716. return r;
  3717. r = cik_cp_gfx_resume(rdev);
  3718. if (r)
  3719. return r;
  3720. r = cik_cp_compute_resume(rdev);
  3721. if (r)
  3722. return r;
  3723. return 0;
  3724. }
  3725. /*
  3726. * sDMA - System DMA
  3727. * Starting with CIK, the GPU has new asynchronous
  3728. * DMA engines. These engines are used for compute
  3729. * and gfx. There are two DMA engines (SDMA0, SDMA1)
  3730. * and each one supports 1 ring buffer used for gfx
  3731. * and 2 queues used for compute.
  3732. *
  3733. * The programming model is very similar to the CP
  3734. * (ring buffer, IBs, etc.), but sDMA has it's own
  3735. * packet format that is different from the PM4 format
  3736. * used by the CP. sDMA supports copying data, writing
  3737. * embedded data, solid fills, and a number of other
  3738. * things. It also has support for tiling/detiling of
  3739. * buffers.
  3740. */
  3741. /**
  3742. * cik_sdma_ring_ib_execute - Schedule an IB on the DMA engine
  3743. *
  3744. * @rdev: radeon_device pointer
  3745. * @ib: IB object to schedule
  3746. *
  3747. * Schedule an IB in the DMA ring (CIK).
  3748. */
  3749. void cik_sdma_ring_ib_execute(struct radeon_device *rdev,
  3750. struct radeon_ib *ib)
  3751. {
  3752. struct radeon_ring *ring = &rdev->ring[ib->ring];
  3753. u32 extra_bits = (ib->vm ? ib->vm->id : 0) & 0xf;
  3754. if (rdev->wb.enabled) {
  3755. u32 next_rptr = ring->wptr + 5;
  3756. while ((next_rptr & 7) != 4)
  3757. next_rptr++;
  3758. next_rptr += 4;
  3759. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0));
  3760. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3761. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  3762. radeon_ring_write(ring, 1); /* number of DWs to follow */
  3763. radeon_ring_write(ring, next_rptr);
  3764. }
  3765. /* IB packet must end on a 8 DW boundary */
  3766. while ((ring->wptr & 7) != 4)
  3767. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
  3768. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_INDIRECT_BUFFER, 0, extra_bits));
  3769. radeon_ring_write(ring, ib->gpu_addr & 0xffffffe0); /* base must be 32 byte aligned */
  3770. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xffffffff);
  3771. radeon_ring_write(ring, ib->length_dw);
  3772. }
  3773. /**
  3774. * cik_sdma_fence_ring_emit - emit a fence on the DMA ring
  3775. *
  3776. * @rdev: radeon_device pointer
  3777. * @fence: radeon fence object
  3778. *
  3779. * Add a DMA fence packet to the ring to write
  3780. * the fence seq number and DMA trap packet to generate
  3781. * an interrupt if needed (CIK).
  3782. */
  3783. void cik_sdma_fence_ring_emit(struct radeon_device *rdev,
  3784. struct radeon_fence *fence)
  3785. {
  3786. struct radeon_ring *ring = &rdev->ring[fence->ring];
  3787. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  3788. u32 extra_bits = (SDMA_POLL_REG_MEM_EXTRA_OP(1) |
  3789. SDMA_POLL_REG_MEM_EXTRA_FUNC(3)); /* == */
  3790. u32 ref_and_mask;
  3791. if (fence->ring == R600_RING_TYPE_DMA_INDEX)
  3792. ref_and_mask = SDMA0;
  3793. else
  3794. ref_and_mask = SDMA1;
  3795. /* write the fence */
  3796. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_FENCE, 0, 0));
  3797. radeon_ring_write(ring, addr & 0xffffffff);
  3798. radeon_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
  3799. radeon_ring_write(ring, fence->seq);
  3800. /* generate an interrupt */
  3801. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_TRAP, 0, 0));
  3802. /* flush HDP */
  3803. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_POLL_REG_MEM, 0, extra_bits));
  3804. radeon_ring_write(ring, GPU_HDP_FLUSH_DONE);
  3805. radeon_ring_write(ring, GPU_HDP_FLUSH_REQ);
  3806. radeon_ring_write(ring, ref_and_mask); /* REFERENCE */
  3807. radeon_ring_write(ring, ref_and_mask); /* MASK */
  3808. radeon_ring_write(ring, (4 << 16) | 10); /* RETRY_COUNT, POLL_INTERVAL */
  3809. }
  3810. /**
  3811. * cik_sdma_semaphore_ring_emit - emit a semaphore on the dma ring
  3812. *
  3813. * @rdev: radeon_device pointer
  3814. * @ring: radeon_ring structure holding ring information
  3815. * @semaphore: radeon semaphore object
  3816. * @emit_wait: wait or signal semaphore
  3817. *
  3818. * Add a DMA semaphore packet to the ring wait on or signal
  3819. * other rings (CIK).
  3820. */
  3821. void cik_sdma_semaphore_ring_emit(struct radeon_device *rdev,
  3822. struct radeon_ring *ring,
  3823. struct radeon_semaphore *semaphore,
  3824. bool emit_wait)
  3825. {
  3826. u64 addr = semaphore->gpu_addr;
  3827. u32 extra_bits = emit_wait ? 0 : SDMA_SEMAPHORE_EXTRA_S;
  3828. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SEMAPHORE, 0, extra_bits));
  3829. radeon_ring_write(ring, addr & 0xfffffff8);
  3830. radeon_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
  3831. }
  3832. /**
  3833. * cik_sdma_gfx_stop - stop the gfx async dma engines
  3834. *
  3835. * @rdev: radeon_device pointer
  3836. *
  3837. * Stop the gfx async dma ring buffers (CIK).
  3838. */
  3839. static void cik_sdma_gfx_stop(struct radeon_device *rdev)
  3840. {
  3841. u32 rb_cntl, reg_offset;
  3842. int i;
  3843. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  3844. for (i = 0; i < 2; i++) {
  3845. if (i == 0)
  3846. reg_offset = SDMA0_REGISTER_OFFSET;
  3847. else
  3848. reg_offset = SDMA1_REGISTER_OFFSET;
  3849. rb_cntl = RREG32(SDMA0_GFX_RB_CNTL + reg_offset);
  3850. rb_cntl &= ~SDMA_RB_ENABLE;
  3851. WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl);
  3852. WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0);
  3853. }
  3854. }
  3855. /**
  3856. * cik_sdma_rlc_stop - stop the compute async dma engines
  3857. *
  3858. * @rdev: radeon_device pointer
  3859. *
  3860. * Stop the compute async dma queues (CIK).
  3861. */
  3862. static void cik_sdma_rlc_stop(struct radeon_device *rdev)
  3863. {
  3864. /* XXX todo */
  3865. }
  3866. /**
  3867. * cik_sdma_enable - stop the async dma engines
  3868. *
  3869. * @rdev: radeon_device pointer
  3870. * @enable: enable/disable the DMA MEs.
  3871. *
  3872. * Halt or unhalt the async dma engines (CIK).
  3873. */
  3874. static void cik_sdma_enable(struct radeon_device *rdev, bool enable)
  3875. {
  3876. u32 me_cntl, reg_offset;
  3877. int i;
  3878. for (i = 0; i < 2; i++) {
  3879. if (i == 0)
  3880. reg_offset = SDMA0_REGISTER_OFFSET;
  3881. else
  3882. reg_offset = SDMA1_REGISTER_OFFSET;
  3883. me_cntl = RREG32(SDMA0_ME_CNTL + reg_offset);
  3884. if (enable)
  3885. me_cntl &= ~SDMA_HALT;
  3886. else
  3887. me_cntl |= SDMA_HALT;
  3888. WREG32(SDMA0_ME_CNTL + reg_offset, me_cntl);
  3889. }
  3890. }
  3891. /**
  3892. * cik_sdma_gfx_resume - setup and start the async dma engines
  3893. *
  3894. * @rdev: radeon_device pointer
  3895. *
  3896. * Set up the gfx DMA ring buffers and enable them (CIK).
  3897. * Returns 0 for success, error for failure.
  3898. */
  3899. static int cik_sdma_gfx_resume(struct radeon_device *rdev)
  3900. {
  3901. struct radeon_ring *ring;
  3902. u32 rb_cntl, ib_cntl;
  3903. u32 rb_bufsz;
  3904. u32 reg_offset, wb_offset;
  3905. int i, r;
  3906. for (i = 0; i < 2; i++) {
  3907. if (i == 0) {
  3908. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  3909. reg_offset = SDMA0_REGISTER_OFFSET;
  3910. wb_offset = R600_WB_DMA_RPTR_OFFSET;
  3911. } else {
  3912. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  3913. reg_offset = SDMA1_REGISTER_OFFSET;
  3914. wb_offset = CAYMAN_WB_DMA1_RPTR_OFFSET;
  3915. }
  3916. WREG32(SDMA0_SEM_INCOMPLETE_TIMER_CNTL + reg_offset, 0);
  3917. WREG32(SDMA0_SEM_WAIT_FAIL_TIMER_CNTL + reg_offset, 0);
  3918. /* Set ring buffer size in dwords */
  3919. rb_bufsz = drm_order(ring->ring_size / 4);
  3920. rb_cntl = rb_bufsz << 1;
  3921. #ifdef __BIG_ENDIAN
  3922. rb_cntl |= SDMA_RB_SWAP_ENABLE | SDMA_RPTR_WRITEBACK_SWAP_ENABLE;
  3923. #endif
  3924. WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl);
  3925. /* Initialize the ring buffer's read and write pointers */
  3926. WREG32(SDMA0_GFX_RB_RPTR + reg_offset, 0);
  3927. WREG32(SDMA0_GFX_RB_WPTR + reg_offset, 0);
  3928. /* set the wb address whether it's enabled or not */
  3929. WREG32(SDMA0_GFX_RB_RPTR_ADDR_HI + reg_offset,
  3930. upper_32_bits(rdev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF);
  3931. WREG32(SDMA0_GFX_RB_RPTR_ADDR_LO + reg_offset,
  3932. ((rdev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC));
  3933. if (rdev->wb.enabled)
  3934. rb_cntl |= SDMA_RPTR_WRITEBACK_ENABLE;
  3935. WREG32(SDMA0_GFX_RB_BASE + reg_offset, ring->gpu_addr >> 8);
  3936. WREG32(SDMA0_GFX_RB_BASE_HI + reg_offset, ring->gpu_addr >> 40);
  3937. ring->wptr = 0;
  3938. WREG32(SDMA0_GFX_RB_WPTR + reg_offset, ring->wptr << 2);
  3939. ring->rptr = RREG32(SDMA0_GFX_RB_RPTR + reg_offset) >> 2;
  3940. /* enable DMA RB */
  3941. WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl | SDMA_RB_ENABLE);
  3942. ib_cntl = SDMA_IB_ENABLE;
  3943. #ifdef __BIG_ENDIAN
  3944. ib_cntl |= SDMA_IB_SWAP_ENABLE;
  3945. #endif
  3946. /* enable DMA IBs */
  3947. WREG32(SDMA0_GFX_IB_CNTL + reg_offset, ib_cntl);
  3948. ring->ready = true;
  3949. r = radeon_ring_test(rdev, ring->idx, ring);
  3950. if (r) {
  3951. ring->ready = false;
  3952. return r;
  3953. }
  3954. }
  3955. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  3956. return 0;
  3957. }
  3958. /**
  3959. * cik_sdma_rlc_resume - setup and start the async dma engines
  3960. *
  3961. * @rdev: radeon_device pointer
  3962. *
  3963. * Set up the compute DMA queues and enable them (CIK).
  3964. * Returns 0 for success, error for failure.
  3965. */
  3966. static int cik_sdma_rlc_resume(struct radeon_device *rdev)
  3967. {
  3968. /* XXX todo */
  3969. return 0;
  3970. }
  3971. /**
  3972. * cik_sdma_load_microcode - load the sDMA ME ucode
  3973. *
  3974. * @rdev: radeon_device pointer
  3975. *
  3976. * Loads the sDMA0/1 ucode.
  3977. * Returns 0 for success, -EINVAL if the ucode is not available.
  3978. */
  3979. static int cik_sdma_load_microcode(struct radeon_device *rdev)
  3980. {
  3981. const __be32 *fw_data;
  3982. int i;
  3983. if (!rdev->sdma_fw)
  3984. return -EINVAL;
  3985. /* stop the gfx rings and rlc compute queues */
  3986. cik_sdma_gfx_stop(rdev);
  3987. cik_sdma_rlc_stop(rdev);
  3988. /* halt the MEs */
  3989. cik_sdma_enable(rdev, false);
  3990. /* sdma0 */
  3991. fw_data = (const __be32 *)rdev->sdma_fw->data;
  3992. WREG32(SDMA0_UCODE_ADDR + SDMA0_REGISTER_OFFSET, 0);
  3993. for (i = 0; i < CIK_SDMA_UCODE_SIZE; i++)
  3994. WREG32(SDMA0_UCODE_DATA + SDMA0_REGISTER_OFFSET, be32_to_cpup(fw_data++));
  3995. WREG32(SDMA0_UCODE_DATA + SDMA0_REGISTER_OFFSET, CIK_SDMA_UCODE_VERSION);
  3996. /* sdma1 */
  3997. fw_data = (const __be32 *)rdev->sdma_fw->data;
  3998. WREG32(SDMA0_UCODE_ADDR + SDMA1_REGISTER_OFFSET, 0);
  3999. for (i = 0; i < CIK_SDMA_UCODE_SIZE; i++)
  4000. WREG32(SDMA0_UCODE_DATA + SDMA1_REGISTER_OFFSET, be32_to_cpup(fw_data++));
  4001. WREG32(SDMA0_UCODE_DATA + SDMA1_REGISTER_OFFSET, CIK_SDMA_UCODE_VERSION);
  4002. WREG32(SDMA0_UCODE_ADDR + SDMA0_REGISTER_OFFSET, 0);
  4003. WREG32(SDMA0_UCODE_ADDR + SDMA1_REGISTER_OFFSET, 0);
  4004. return 0;
  4005. }
  4006. /**
  4007. * cik_sdma_resume - setup and start the async dma engines
  4008. *
  4009. * @rdev: radeon_device pointer
  4010. *
  4011. * Set up the DMA engines and enable them (CIK).
  4012. * Returns 0 for success, error for failure.
  4013. */
  4014. static int cik_sdma_resume(struct radeon_device *rdev)
  4015. {
  4016. int r;
  4017. /* Reset dma */
  4018. WREG32(SRBM_SOFT_RESET, SOFT_RESET_SDMA | SOFT_RESET_SDMA1);
  4019. RREG32(SRBM_SOFT_RESET);
  4020. udelay(50);
  4021. WREG32(SRBM_SOFT_RESET, 0);
  4022. RREG32(SRBM_SOFT_RESET);
  4023. r = cik_sdma_load_microcode(rdev);
  4024. if (r)
  4025. return r;
  4026. /* unhalt the MEs */
  4027. cik_sdma_enable(rdev, true);
  4028. /* start the gfx rings and rlc compute queues */
  4029. r = cik_sdma_gfx_resume(rdev);
  4030. if (r)
  4031. return r;
  4032. r = cik_sdma_rlc_resume(rdev);
  4033. if (r)
  4034. return r;
  4035. return 0;
  4036. }
  4037. /**
  4038. * cik_sdma_fini - tear down the async dma engines
  4039. *
  4040. * @rdev: radeon_device pointer
  4041. *
  4042. * Stop the async dma engines and free the rings (CIK).
  4043. */
  4044. static void cik_sdma_fini(struct radeon_device *rdev)
  4045. {
  4046. /* stop the gfx rings and rlc compute queues */
  4047. cik_sdma_gfx_stop(rdev);
  4048. cik_sdma_rlc_stop(rdev);
  4049. /* halt the MEs */
  4050. cik_sdma_enable(rdev, false);
  4051. radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
  4052. radeon_ring_fini(rdev, &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX]);
  4053. /* XXX - compute dma queue tear down */
  4054. }
  4055. /**
  4056. * cik_copy_dma - copy pages using the DMA engine
  4057. *
  4058. * @rdev: radeon_device pointer
  4059. * @src_offset: src GPU address
  4060. * @dst_offset: dst GPU address
  4061. * @num_gpu_pages: number of GPU pages to xfer
  4062. * @fence: radeon fence object
  4063. *
  4064. * Copy GPU paging using the DMA engine (CIK).
  4065. * Used by the radeon ttm implementation to move pages if
  4066. * registered as the asic copy callback.
  4067. */
  4068. int cik_copy_dma(struct radeon_device *rdev,
  4069. uint64_t src_offset, uint64_t dst_offset,
  4070. unsigned num_gpu_pages,
  4071. struct radeon_fence **fence)
  4072. {
  4073. struct radeon_semaphore *sem = NULL;
  4074. int ring_index = rdev->asic->copy.dma_ring_index;
  4075. struct radeon_ring *ring = &rdev->ring[ring_index];
  4076. u32 size_in_bytes, cur_size_in_bytes;
  4077. int i, num_loops;
  4078. int r = 0;
  4079. r = radeon_semaphore_create(rdev, &sem);
  4080. if (r) {
  4081. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4082. return r;
  4083. }
  4084. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  4085. num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
  4086. r = radeon_ring_lock(rdev, ring, num_loops * 7 + 14);
  4087. if (r) {
  4088. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4089. radeon_semaphore_free(rdev, &sem, NULL);
  4090. return r;
  4091. }
  4092. if (radeon_fence_need_sync(*fence, ring->idx)) {
  4093. radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
  4094. ring->idx);
  4095. radeon_fence_note_sync(*fence, ring->idx);
  4096. } else {
  4097. radeon_semaphore_free(rdev, &sem, NULL);
  4098. }
  4099. for (i = 0; i < num_loops; i++) {
  4100. cur_size_in_bytes = size_in_bytes;
  4101. if (cur_size_in_bytes > 0x1fffff)
  4102. cur_size_in_bytes = 0x1fffff;
  4103. size_in_bytes -= cur_size_in_bytes;
  4104. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_COPY, SDMA_COPY_SUB_OPCODE_LINEAR, 0));
  4105. radeon_ring_write(ring, cur_size_in_bytes);
  4106. radeon_ring_write(ring, 0); /* src/dst endian swap */
  4107. radeon_ring_write(ring, src_offset & 0xffffffff);
  4108. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xffffffff);
  4109. radeon_ring_write(ring, dst_offset & 0xfffffffc);
  4110. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xffffffff);
  4111. src_offset += cur_size_in_bytes;
  4112. dst_offset += cur_size_in_bytes;
  4113. }
  4114. r = radeon_fence_emit(rdev, fence, ring->idx);
  4115. if (r) {
  4116. radeon_ring_unlock_undo(rdev, ring);
  4117. return r;
  4118. }
  4119. radeon_ring_unlock_commit(rdev, ring);
  4120. radeon_semaphore_free(rdev, &sem, *fence);
  4121. return r;
  4122. }
  4123. /**
  4124. * cik_sdma_ring_test - simple async dma engine test
  4125. *
  4126. * @rdev: radeon_device pointer
  4127. * @ring: radeon_ring structure holding ring information
  4128. *
  4129. * Test the DMA engine by writing using it to write an
  4130. * value to memory. (CIK).
  4131. * Returns 0 for success, error for failure.
  4132. */
  4133. int cik_sdma_ring_test(struct radeon_device *rdev,
  4134. struct radeon_ring *ring)
  4135. {
  4136. unsigned i;
  4137. int r;
  4138. void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
  4139. u32 tmp;
  4140. if (!ptr) {
  4141. DRM_ERROR("invalid vram scratch pointer\n");
  4142. return -EINVAL;
  4143. }
  4144. tmp = 0xCAFEDEAD;
  4145. writel(tmp, ptr);
  4146. r = radeon_ring_lock(rdev, ring, 4);
  4147. if (r) {
  4148. DRM_ERROR("radeon: dma failed to lock ring %d (%d).\n", ring->idx, r);
  4149. return r;
  4150. }
  4151. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0));
  4152. radeon_ring_write(ring, rdev->vram_scratch.gpu_addr & 0xfffffffc);
  4153. radeon_ring_write(ring, upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xffffffff);
  4154. radeon_ring_write(ring, 1); /* number of DWs to follow */
  4155. radeon_ring_write(ring, 0xDEADBEEF);
  4156. radeon_ring_unlock_commit(rdev, ring);
  4157. for (i = 0; i < rdev->usec_timeout; i++) {
  4158. tmp = readl(ptr);
  4159. if (tmp == 0xDEADBEEF)
  4160. break;
  4161. DRM_UDELAY(1);
  4162. }
  4163. if (i < rdev->usec_timeout) {
  4164. DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
  4165. } else {
  4166. DRM_ERROR("radeon: ring %d test failed (0x%08X)\n",
  4167. ring->idx, tmp);
  4168. r = -EINVAL;
  4169. }
  4170. return r;
  4171. }
  4172. /**
  4173. * cik_sdma_ib_test - test an IB on the DMA engine
  4174. *
  4175. * @rdev: radeon_device pointer
  4176. * @ring: radeon_ring structure holding ring information
  4177. *
  4178. * Test a simple IB in the DMA ring (CIK).
  4179. * Returns 0 on success, error on failure.
  4180. */
  4181. int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
  4182. {
  4183. struct radeon_ib ib;
  4184. unsigned i;
  4185. int r;
  4186. void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
  4187. u32 tmp = 0;
  4188. if (!ptr) {
  4189. DRM_ERROR("invalid vram scratch pointer\n");
  4190. return -EINVAL;
  4191. }
  4192. tmp = 0xCAFEDEAD;
  4193. writel(tmp, ptr);
  4194. r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
  4195. if (r) {
  4196. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  4197. return r;
  4198. }
  4199. ib.ptr[0] = SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
  4200. ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc;
  4201. ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xffffffff;
  4202. ib.ptr[3] = 1;
  4203. ib.ptr[4] = 0xDEADBEEF;
  4204. ib.length_dw = 5;
  4205. r = radeon_ib_schedule(rdev, &ib, NULL);
  4206. if (r) {
  4207. radeon_ib_free(rdev, &ib);
  4208. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  4209. return r;
  4210. }
  4211. r = radeon_fence_wait(ib.fence, false);
  4212. if (r) {
  4213. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  4214. return r;
  4215. }
  4216. for (i = 0; i < rdev->usec_timeout; i++) {
  4217. tmp = readl(ptr);
  4218. if (tmp == 0xDEADBEEF)
  4219. break;
  4220. DRM_UDELAY(1);
  4221. }
  4222. if (i < rdev->usec_timeout) {
  4223. DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
  4224. } else {
  4225. DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp);
  4226. r = -EINVAL;
  4227. }
  4228. radeon_ib_free(rdev, &ib);
  4229. return r;
  4230. }
  4231. static void cik_print_gpu_status_regs(struct radeon_device *rdev)
  4232. {
  4233. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  4234. RREG32(GRBM_STATUS));
  4235. dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
  4236. RREG32(GRBM_STATUS2));
  4237. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  4238. RREG32(GRBM_STATUS_SE0));
  4239. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  4240. RREG32(GRBM_STATUS_SE1));
  4241. dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
  4242. RREG32(GRBM_STATUS_SE2));
  4243. dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
  4244. RREG32(GRBM_STATUS_SE3));
  4245. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  4246. RREG32(SRBM_STATUS));
  4247. dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
  4248. RREG32(SRBM_STATUS2));
  4249. dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
  4250. RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
  4251. dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
  4252. RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
  4253. dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
  4254. dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
  4255. RREG32(CP_STALLED_STAT1));
  4256. dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
  4257. RREG32(CP_STALLED_STAT2));
  4258. dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
  4259. RREG32(CP_STALLED_STAT3));
  4260. dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
  4261. RREG32(CP_CPF_BUSY_STAT));
  4262. dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
  4263. RREG32(CP_CPF_STALLED_STAT1));
  4264. dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
  4265. dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
  4266. dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
  4267. RREG32(CP_CPC_STALLED_STAT1));
  4268. dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
  4269. }
  4270. /**
  4271. * cik_gpu_check_soft_reset - check which blocks are busy
  4272. *
  4273. * @rdev: radeon_device pointer
  4274. *
  4275. * Check which blocks are busy and return the relevant reset
  4276. * mask to be used by cik_gpu_soft_reset().
  4277. * Returns a mask of the blocks to be reset.
  4278. */
  4279. static u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
  4280. {
  4281. u32 reset_mask = 0;
  4282. u32 tmp;
  4283. /* GRBM_STATUS */
  4284. tmp = RREG32(GRBM_STATUS);
  4285. if (tmp & (PA_BUSY | SC_BUSY |
  4286. BCI_BUSY | SX_BUSY |
  4287. TA_BUSY | VGT_BUSY |
  4288. DB_BUSY | CB_BUSY |
  4289. GDS_BUSY | SPI_BUSY |
  4290. IA_BUSY | IA_BUSY_NO_DMA))
  4291. reset_mask |= RADEON_RESET_GFX;
  4292. if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
  4293. reset_mask |= RADEON_RESET_CP;
  4294. /* GRBM_STATUS2 */
  4295. tmp = RREG32(GRBM_STATUS2);
  4296. if (tmp & RLC_BUSY)
  4297. reset_mask |= RADEON_RESET_RLC;
  4298. /* SDMA0_STATUS_REG */
  4299. tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
  4300. if (!(tmp & SDMA_IDLE))
  4301. reset_mask |= RADEON_RESET_DMA;
  4302. /* SDMA1_STATUS_REG */
  4303. tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
  4304. if (!(tmp & SDMA_IDLE))
  4305. reset_mask |= RADEON_RESET_DMA1;
  4306. /* SRBM_STATUS2 */
  4307. tmp = RREG32(SRBM_STATUS2);
  4308. if (tmp & SDMA_BUSY)
  4309. reset_mask |= RADEON_RESET_DMA;
  4310. if (tmp & SDMA1_BUSY)
  4311. reset_mask |= RADEON_RESET_DMA1;
  4312. /* SRBM_STATUS */
  4313. tmp = RREG32(SRBM_STATUS);
  4314. if (tmp & IH_BUSY)
  4315. reset_mask |= RADEON_RESET_IH;
  4316. if (tmp & SEM_BUSY)
  4317. reset_mask |= RADEON_RESET_SEM;
  4318. if (tmp & GRBM_RQ_PENDING)
  4319. reset_mask |= RADEON_RESET_GRBM;
  4320. if (tmp & VMC_BUSY)
  4321. reset_mask |= RADEON_RESET_VMC;
  4322. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  4323. MCC_BUSY | MCD_BUSY))
  4324. reset_mask |= RADEON_RESET_MC;
  4325. if (evergreen_is_display_hung(rdev))
  4326. reset_mask |= RADEON_RESET_DISPLAY;
  4327. /* Skip MC reset as it's mostly likely not hung, just busy */
  4328. if (reset_mask & RADEON_RESET_MC) {
  4329. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  4330. reset_mask &= ~RADEON_RESET_MC;
  4331. }
  4332. return reset_mask;
  4333. }
  4334. /**
  4335. * cik_gpu_soft_reset - soft reset GPU
  4336. *
  4337. * @rdev: radeon_device pointer
  4338. * @reset_mask: mask of which blocks to reset
  4339. *
  4340. * Soft reset the blocks specified in @reset_mask.
  4341. */
  4342. static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  4343. {
  4344. struct evergreen_mc_save save;
  4345. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4346. u32 tmp;
  4347. if (reset_mask == 0)
  4348. return;
  4349. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  4350. cik_print_gpu_status_regs(rdev);
  4351. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4352. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  4353. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4354. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  4355. /* stop the rlc */
  4356. cik_rlc_stop(rdev);
  4357. /* Disable GFX parsing/prefetching */
  4358. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  4359. /* Disable MEC parsing/prefetching */
  4360. WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
  4361. if (reset_mask & RADEON_RESET_DMA) {
  4362. /* sdma0 */
  4363. tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
  4364. tmp |= SDMA_HALT;
  4365. WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  4366. }
  4367. if (reset_mask & RADEON_RESET_DMA1) {
  4368. /* sdma1 */
  4369. tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
  4370. tmp |= SDMA_HALT;
  4371. WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  4372. }
  4373. evergreen_mc_stop(rdev, &save);
  4374. if (evergreen_mc_wait_for_idle(rdev)) {
  4375. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  4376. }
  4377. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
  4378. grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
  4379. if (reset_mask & RADEON_RESET_CP) {
  4380. grbm_soft_reset |= SOFT_RESET_CP;
  4381. srbm_soft_reset |= SOFT_RESET_GRBM;
  4382. }
  4383. if (reset_mask & RADEON_RESET_DMA)
  4384. srbm_soft_reset |= SOFT_RESET_SDMA;
  4385. if (reset_mask & RADEON_RESET_DMA1)
  4386. srbm_soft_reset |= SOFT_RESET_SDMA1;
  4387. if (reset_mask & RADEON_RESET_DISPLAY)
  4388. srbm_soft_reset |= SOFT_RESET_DC;
  4389. if (reset_mask & RADEON_RESET_RLC)
  4390. grbm_soft_reset |= SOFT_RESET_RLC;
  4391. if (reset_mask & RADEON_RESET_SEM)
  4392. srbm_soft_reset |= SOFT_RESET_SEM;
  4393. if (reset_mask & RADEON_RESET_IH)
  4394. srbm_soft_reset |= SOFT_RESET_IH;
  4395. if (reset_mask & RADEON_RESET_GRBM)
  4396. srbm_soft_reset |= SOFT_RESET_GRBM;
  4397. if (reset_mask & RADEON_RESET_VMC)
  4398. srbm_soft_reset |= SOFT_RESET_VMC;
  4399. if (!(rdev->flags & RADEON_IS_IGP)) {
  4400. if (reset_mask & RADEON_RESET_MC)
  4401. srbm_soft_reset |= SOFT_RESET_MC;
  4402. }
  4403. if (grbm_soft_reset) {
  4404. tmp = RREG32(GRBM_SOFT_RESET);
  4405. tmp |= grbm_soft_reset;
  4406. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  4407. WREG32(GRBM_SOFT_RESET, tmp);
  4408. tmp = RREG32(GRBM_SOFT_RESET);
  4409. udelay(50);
  4410. tmp &= ~grbm_soft_reset;
  4411. WREG32(GRBM_SOFT_RESET, tmp);
  4412. tmp = RREG32(GRBM_SOFT_RESET);
  4413. }
  4414. if (srbm_soft_reset) {
  4415. tmp = RREG32(SRBM_SOFT_RESET);
  4416. tmp |= srbm_soft_reset;
  4417. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  4418. WREG32(SRBM_SOFT_RESET, tmp);
  4419. tmp = RREG32(SRBM_SOFT_RESET);
  4420. udelay(50);
  4421. tmp &= ~srbm_soft_reset;
  4422. WREG32(SRBM_SOFT_RESET, tmp);
  4423. tmp = RREG32(SRBM_SOFT_RESET);
  4424. }
  4425. /* Wait a little for things to settle down */
  4426. udelay(50);
  4427. evergreen_mc_resume(rdev, &save);
  4428. udelay(50);
  4429. cik_print_gpu_status_regs(rdev);
  4430. }
  4431. /**
  4432. * cik_asic_reset - soft reset GPU
  4433. *
  4434. * @rdev: radeon_device pointer
  4435. *
  4436. * Look up which blocks are hung and attempt
  4437. * to reset them.
  4438. * Returns 0 for success.
  4439. */
  4440. int cik_asic_reset(struct radeon_device *rdev)
  4441. {
  4442. u32 reset_mask;
  4443. reset_mask = cik_gpu_check_soft_reset(rdev);
  4444. if (reset_mask)
  4445. r600_set_bios_scratch_engine_hung(rdev, true);
  4446. cik_gpu_soft_reset(rdev, reset_mask);
  4447. reset_mask = cik_gpu_check_soft_reset(rdev);
  4448. if (!reset_mask)
  4449. r600_set_bios_scratch_engine_hung(rdev, false);
  4450. return 0;
  4451. }
  4452. /**
  4453. * cik_gfx_is_lockup - check if the 3D engine is locked up
  4454. *
  4455. * @rdev: radeon_device pointer
  4456. * @ring: radeon_ring structure holding ring information
  4457. *
  4458. * Check if the 3D engine is locked up (CIK).
  4459. * Returns true if the engine is locked, false if not.
  4460. */
  4461. bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  4462. {
  4463. u32 reset_mask = cik_gpu_check_soft_reset(rdev);
  4464. if (!(reset_mask & (RADEON_RESET_GFX |
  4465. RADEON_RESET_COMPUTE |
  4466. RADEON_RESET_CP))) {
  4467. radeon_ring_lockup_update(ring);
  4468. return false;
  4469. }
  4470. /* force CP activities */
  4471. radeon_ring_force_activity(rdev, ring);
  4472. return radeon_ring_test_lockup(rdev, ring);
  4473. }
  4474. /**
  4475. * cik_sdma_is_lockup - Check if the DMA engine is locked up
  4476. *
  4477. * @rdev: radeon_device pointer
  4478. * @ring: radeon_ring structure holding ring information
  4479. *
  4480. * Check if the async DMA engine is locked up (CIK).
  4481. * Returns true if the engine appears to be locked up, false if not.
  4482. */
  4483. bool cik_sdma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  4484. {
  4485. u32 reset_mask = cik_gpu_check_soft_reset(rdev);
  4486. u32 mask;
  4487. if (ring->idx == R600_RING_TYPE_DMA_INDEX)
  4488. mask = RADEON_RESET_DMA;
  4489. else
  4490. mask = RADEON_RESET_DMA1;
  4491. if (!(reset_mask & mask)) {
  4492. radeon_ring_lockup_update(ring);
  4493. return false;
  4494. }
  4495. /* force ring activities */
  4496. radeon_ring_force_activity(rdev, ring);
  4497. return radeon_ring_test_lockup(rdev, ring);
  4498. }
  4499. /* MC */
  4500. /**
  4501. * cik_mc_program - program the GPU memory controller
  4502. *
  4503. * @rdev: radeon_device pointer
  4504. *
  4505. * Set the location of vram, gart, and AGP in the GPU's
  4506. * physical address space (CIK).
  4507. */
  4508. static void cik_mc_program(struct radeon_device *rdev)
  4509. {
  4510. struct evergreen_mc_save save;
  4511. u32 tmp;
  4512. int i, j;
  4513. /* Initialize HDP */
  4514. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  4515. WREG32((0x2c14 + j), 0x00000000);
  4516. WREG32((0x2c18 + j), 0x00000000);
  4517. WREG32((0x2c1c + j), 0x00000000);
  4518. WREG32((0x2c20 + j), 0x00000000);
  4519. WREG32((0x2c24 + j), 0x00000000);
  4520. }
  4521. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  4522. evergreen_mc_stop(rdev, &save);
  4523. if (radeon_mc_wait_for_idle(rdev)) {
  4524. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  4525. }
  4526. /* Lockout access through VGA aperture*/
  4527. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  4528. /* Update configuration */
  4529. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  4530. rdev->mc.vram_start >> 12);
  4531. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  4532. rdev->mc.vram_end >> 12);
  4533. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  4534. rdev->vram_scratch.gpu_addr >> 12);
  4535. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  4536. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  4537. WREG32(MC_VM_FB_LOCATION, tmp);
  4538. /* XXX double check these! */
  4539. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  4540. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  4541. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  4542. WREG32(MC_VM_AGP_BASE, 0);
  4543. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  4544. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  4545. if (radeon_mc_wait_for_idle(rdev)) {
  4546. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  4547. }
  4548. evergreen_mc_resume(rdev, &save);
  4549. /* we need to own VRAM, so turn off the VGA renderer here
  4550. * to stop it overwriting our objects */
  4551. rv515_vga_render_disable(rdev);
  4552. }
  4553. /**
  4554. * cik_mc_init - initialize the memory controller driver params
  4555. *
  4556. * @rdev: radeon_device pointer
  4557. *
  4558. * Look up the amount of vram, vram width, and decide how to place
  4559. * vram and gart within the GPU's physical address space (CIK).
  4560. * Returns 0 for success.
  4561. */
  4562. static int cik_mc_init(struct radeon_device *rdev)
  4563. {
  4564. u32 tmp;
  4565. int chansize, numchan;
  4566. /* Get VRAM informations */
  4567. rdev->mc.vram_is_ddr = true;
  4568. tmp = RREG32(MC_ARB_RAMCFG);
  4569. if (tmp & CHANSIZE_MASK) {
  4570. chansize = 64;
  4571. } else {
  4572. chansize = 32;
  4573. }
  4574. tmp = RREG32(MC_SHARED_CHMAP);
  4575. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  4576. case 0:
  4577. default:
  4578. numchan = 1;
  4579. break;
  4580. case 1:
  4581. numchan = 2;
  4582. break;
  4583. case 2:
  4584. numchan = 4;
  4585. break;
  4586. case 3:
  4587. numchan = 8;
  4588. break;
  4589. case 4:
  4590. numchan = 3;
  4591. break;
  4592. case 5:
  4593. numchan = 6;
  4594. break;
  4595. case 6:
  4596. numchan = 10;
  4597. break;
  4598. case 7:
  4599. numchan = 12;
  4600. break;
  4601. case 8:
  4602. numchan = 16;
  4603. break;
  4604. }
  4605. rdev->mc.vram_width = numchan * chansize;
  4606. /* Could aper size report 0 ? */
  4607. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  4608. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  4609. /* size in MB on si */
  4610. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
  4611. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
  4612. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  4613. si_vram_gtt_location(rdev, &rdev->mc);
  4614. radeon_update_bandwidth_info(rdev);
  4615. return 0;
  4616. }
  4617. /*
  4618. * GART
  4619. * VMID 0 is the physical GPU addresses as used by the kernel.
  4620. * VMIDs 1-15 are used for userspace clients and are handled
  4621. * by the radeon vm/hsa code.
  4622. */
  4623. /**
  4624. * cik_pcie_gart_tlb_flush - gart tlb flush callback
  4625. *
  4626. * @rdev: radeon_device pointer
  4627. *
  4628. * Flush the TLB for the VMID 0 page table (CIK).
  4629. */
  4630. void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
  4631. {
  4632. /* flush hdp cache */
  4633. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
  4634. /* bits 0-15 are the VM contexts0-15 */
  4635. WREG32(VM_INVALIDATE_REQUEST, 0x1);
  4636. }
  4637. /**
  4638. * cik_pcie_gart_enable - gart enable
  4639. *
  4640. * @rdev: radeon_device pointer
  4641. *
  4642. * This sets up the TLBs, programs the page tables for VMID0,
  4643. * sets up the hw for VMIDs 1-15 which are allocated on
  4644. * demand, and sets up the global locations for the LDS, GDS,
  4645. * and GPUVM for FSA64 clients (CIK).
  4646. * Returns 0 for success, errors for failure.
  4647. */
  4648. static int cik_pcie_gart_enable(struct radeon_device *rdev)
  4649. {
  4650. int r, i;
  4651. if (rdev->gart.robj == NULL) {
  4652. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  4653. return -EINVAL;
  4654. }
  4655. r = radeon_gart_table_vram_pin(rdev);
  4656. if (r)
  4657. return r;
  4658. radeon_gart_restore(rdev);
  4659. /* Setup TLB control */
  4660. WREG32(MC_VM_MX_L1_TLB_CNTL,
  4661. (0xA << 7) |
  4662. ENABLE_L1_TLB |
  4663. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  4664. ENABLE_ADVANCED_DRIVER_MODEL |
  4665. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  4666. /* Setup L2 cache */
  4667. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  4668. ENABLE_L2_FRAGMENT_PROCESSING |
  4669. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  4670. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  4671. EFFECTIVE_L2_QUEUE_SIZE(7) |
  4672. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  4673. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  4674. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  4675. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  4676. /* setup context0 */
  4677. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  4678. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  4679. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  4680. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  4681. (u32)(rdev->dummy_page.addr >> 12));
  4682. WREG32(VM_CONTEXT0_CNTL2, 0);
  4683. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  4684. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  4685. WREG32(0x15D4, 0);
  4686. WREG32(0x15D8, 0);
  4687. WREG32(0x15DC, 0);
  4688. /* empty context1-15 */
  4689. /* FIXME start with 4G, once using 2 level pt switch to full
  4690. * vm size space
  4691. */
  4692. /* set vm size, must be a multiple of 4 */
  4693. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  4694. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  4695. for (i = 1; i < 16; i++) {
  4696. if (i < 8)
  4697. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  4698. rdev->gart.table_addr >> 12);
  4699. else
  4700. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  4701. rdev->gart.table_addr >> 12);
  4702. }
  4703. /* enable context1-15 */
  4704. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  4705. (u32)(rdev->dummy_page.addr >> 12));
  4706. WREG32(VM_CONTEXT1_CNTL2, 4);
  4707. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  4708. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4709. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  4710. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4711. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  4712. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4713. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  4714. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4715. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  4716. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4717. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  4718. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  4719. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  4720. /* TC cache setup ??? */
  4721. WREG32(TC_CFG_L1_LOAD_POLICY0, 0);
  4722. WREG32(TC_CFG_L1_LOAD_POLICY1, 0);
  4723. WREG32(TC_CFG_L1_STORE_POLICY, 0);
  4724. WREG32(TC_CFG_L2_LOAD_POLICY0, 0);
  4725. WREG32(TC_CFG_L2_LOAD_POLICY1, 0);
  4726. WREG32(TC_CFG_L2_STORE_POLICY0, 0);
  4727. WREG32(TC_CFG_L2_STORE_POLICY1, 0);
  4728. WREG32(TC_CFG_L2_ATOMIC_POLICY, 0);
  4729. WREG32(TC_CFG_L1_VOLATILE, 0);
  4730. WREG32(TC_CFG_L2_VOLATILE, 0);
  4731. if (rdev->family == CHIP_KAVERI) {
  4732. u32 tmp = RREG32(CHUB_CONTROL);
  4733. tmp &= ~BYPASS_VM;
  4734. WREG32(CHUB_CONTROL, tmp);
  4735. }
  4736. /* XXX SH_MEM regs */
  4737. /* where to put LDS, scratch, GPUVM in FSA64 space */
  4738. mutex_lock(&rdev->srbm_mutex);
  4739. for (i = 0; i < 16; i++) {
  4740. cik_srbm_select(rdev, 0, 0, 0, i);
  4741. /* CP and shaders */
  4742. WREG32(SH_MEM_CONFIG, 0);
  4743. WREG32(SH_MEM_APE1_BASE, 1);
  4744. WREG32(SH_MEM_APE1_LIMIT, 0);
  4745. WREG32(SH_MEM_BASES, 0);
  4746. /* SDMA GFX */
  4747. WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
  4748. WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
  4749. WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
  4750. WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
  4751. /* XXX SDMA RLC - todo */
  4752. }
  4753. cik_srbm_select(rdev, 0, 0, 0, 0);
  4754. mutex_unlock(&rdev->srbm_mutex);
  4755. cik_pcie_gart_tlb_flush(rdev);
  4756. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  4757. (unsigned)(rdev->mc.gtt_size >> 20),
  4758. (unsigned long long)rdev->gart.table_addr);
  4759. rdev->gart.ready = true;
  4760. return 0;
  4761. }
  4762. /**
  4763. * cik_pcie_gart_disable - gart disable
  4764. *
  4765. * @rdev: radeon_device pointer
  4766. *
  4767. * This disables all VM page table (CIK).
  4768. */
  4769. static void cik_pcie_gart_disable(struct radeon_device *rdev)
  4770. {
  4771. /* Disable all tables */
  4772. WREG32(VM_CONTEXT0_CNTL, 0);
  4773. WREG32(VM_CONTEXT1_CNTL, 0);
  4774. /* Setup TLB control */
  4775. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  4776. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  4777. /* Setup L2 cache */
  4778. WREG32(VM_L2_CNTL,
  4779. ENABLE_L2_FRAGMENT_PROCESSING |
  4780. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  4781. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  4782. EFFECTIVE_L2_QUEUE_SIZE(7) |
  4783. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  4784. WREG32(VM_L2_CNTL2, 0);
  4785. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  4786. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  4787. radeon_gart_table_vram_unpin(rdev);
  4788. }
  4789. /**
  4790. * cik_pcie_gart_fini - vm fini callback
  4791. *
  4792. * @rdev: radeon_device pointer
  4793. *
  4794. * Tears down the driver GART/VM setup (CIK).
  4795. */
  4796. static void cik_pcie_gart_fini(struct radeon_device *rdev)
  4797. {
  4798. cik_pcie_gart_disable(rdev);
  4799. radeon_gart_table_vram_free(rdev);
  4800. radeon_gart_fini(rdev);
  4801. }
  4802. /* vm parser */
  4803. /**
  4804. * cik_ib_parse - vm ib_parse callback
  4805. *
  4806. * @rdev: radeon_device pointer
  4807. * @ib: indirect buffer pointer
  4808. *
  4809. * CIK uses hw IB checking so this is a nop (CIK).
  4810. */
  4811. int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  4812. {
  4813. return 0;
  4814. }
  4815. /*
  4816. * vm
  4817. * VMID 0 is the physical GPU addresses as used by the kernel.
  4818. * VMIDs 1-15 are used for userspace clients and are handled
  4819. * by the radeon vm/hsa code.
  4820. */
  4821. /**
  4822. * cik_vm_init - cik vm init callback
  4823. *
  4824. * @rdev: radeon_device pointer
  4825. *
  4826. * Inits cik specific vm parameters (number of VMs, base of vram for
  4827. * VMIDs 1-15) (CIK).
  4828. * Returns 0 for success.
  4829. */
  4830. int cik_vm_init(struct radeon_device *rdev)
  4831. {
  4832. /* number of VMs */
  4833. rdev->vm_manager.nvm = 16;
  4834. /* base offset of vram pages */
  4835. if (rdev->flags & RADEON_IS_IGP) {
  4836. u64 tmp = RREG32(MC_VM_FB_OFFSET);
  4837. tmp <<= 22;
  4838. rdev->vm_manager.vram_base_offset = tmp;
  4839. } else
  4840. rdev->vm_manager.vram_base_offset = 0;
  4841. return 0;
  4842. }
  4843. /**
  4844. * cik_vm_fini - cik vm fini callback
  4845. *
  4846. * @rdev: radeon_device pointer
  4847. *
  4848. * Tear down any asic specific VM setup (CIK).
  4849. */
  4850. void cik_vm_fini(struct radeon_device *rdev)
  4851. {
  4852. }
  4853. /**
  4854. * cik_vm_decode_fault - print human readable fault info
  4855. *
  4856. * @rdev: radeon_device pointer
  4857. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  4858. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  4859. *
  4860. * Print human readable fault information (CIK).
  4861. */
  4862. static void cik_vm_decode_fault(struct radeon_device *rdev,
  4863. u32 status, u32 addr, u32 mc_client)
  4864. {
  4865. u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  4866. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  4867. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  4868. char *block = (char *)&mc_client;
  4869. printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
  4870. protections, vmid, addr,
  4871. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  4872. block, mc_id);
  4873. }
  4874. /**
  4875. * cik_vm_flush - cik vm flush using the CP
  4876. *
  4877. * @rdev: radeon_device pointer
  4878. *
  4879. * Update the page table base and flush the VM TLB
  4880. * using the CP (CIK).
  4881. */
  4882. void cik_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  4883. {
  4884. struct radeon_ring *ring = &rdev->ring[ridx];
  4885. if (vm == NULL)
  4886. return;
  4887. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4888. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4889. WRITE_DATA_DST_SEL(0)));
  4890. if (vm->id < 8) {
  4891. radeon_ring_write(ring,
  4892. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  4893. } else {
  4894. radeon_ring_write(ring,
  4895. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  4896. }
  4897. radeon_ring_write(ring, 0);
  4898. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  4899. /* update SH_MEM_* regs */
  4900. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4901. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4902. WRITE_DATA_DST_SEL(0)));
  4903. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  4904. radeon_ring_write(ring, 0);
  4905. radeon_ring_write(ring, VMID(vm->id));
  4906. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
  4907. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4908. WRITE_DATA_DST_SEL(0)));
  4909. radeon_ring_write(ring, SH_MEM_BASES >> 2);
  4910. radeon_ring_write(ring, 0);
  4911. radeon_ring_write(ring, 0); /* SH_MEM_BASES */
  4912. radeon_ring_write(ring, 0); /* SH_MEM_CONFIG */
  4913. radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
  4914. radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
  4915. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4916. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4917. WRITE_DATA_DST_SEL(0)));
  4918. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  4919. radeon_ring_write(ring, 0);
  4920. radeon_ring_write(ring, VMID(0));
  4921. /* HDP flush */
  4922. /* We should be using the WAIT_REG_MEM packet here like in
  4923. * cik_fence_ring_emit(), but it causes the CP to hang in this
  4924. * context...
  4925. */
  4926. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4927. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4928. WRITE_DATA_DST_SEL(0)));
  4929. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  4930. radeon_ring_write(ring, 0);
  4931. radeon_ring_write(ring, 0);
  4932. /* bits 0-15 are the VM contexts0-15 */
  4933. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4934. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4935. WRITE_DATA_DST_SEL(0)));
  4936. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  4937. radeon_ring_write(ring, 0);
  4938. radeon_ring_write(ring, 1 << vm->id);
  4939. /* compute doesn't have PFP */
  4940. if (ridx == RADEON_RING_TYPE_GFX_INDEX) {
  4941. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  4942. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  4943. radeon_ring_write(ring, 0x0);
  4944. }
  4945. }
  4946. /**
  4947. * cik_vm_set_page - update the page tables using sDMA
  4948. *
  4949. * @rdev: radeon_device pointer
  4950. * @ib: indirect buffer to fill with commands
  4951. * @pe: addr of the page entry
  4952. * @addr: dst addr to write into pe
  4953. * @count: number of page entries to update
  4954. * @incr: increase next addr by incr bytes
  4955. * @flags: access flags
  4956. *
  4957. * Update the page tables using CP or sDMA (CIK).
  4958. */
  4959. void cik_vm_set_page(struct radeon_device *rdev,
  4960. struct radeon_ib *ib,
  4961. uint64_t pe,
  4962. uint64_t addr, unsigned count,
  4963. uint32_t incr, uint32_t flags)
  4964. {
  4965. uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
  4966. uint64_t value;
  4967. unsigned ndw;
  4968. if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
  4969. /* CP */
  4970. while (count) {
  4971. ndw = 2 + count * 2;
  4972. if (ndw > 0x3FFE)
  4973. ndw = 0x3FFE;
  4974. ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
  4975. ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
  4976. WRITE_DATA_DST_SEL(1));
  4977. ib->ptr[ib->length_dw++] = pe;
  4978. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  4979. for (; ndw > 2; ndw -= 2, --count, pe += 8) {
  4980. if (flags & RADEON_VM_PAGE_SYSTEM) {
  4981. value = radeon_vm_map_gart(rdev, addr);
  4982. value &= 0xFFFFFFFFFFFFF000ULL;
  4983. } else if (flags & RADEON_VM_PAGE_VALID) {
  4984. value = addr;
  4985. } else {
  4986. value = 0;
  4987. }
  4988. addr += incr;
  4989. value |= r600_flags;
  4990. ib->ptr[ib->length_dw++] = value;
  4991. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  4992. }
  4993. }
  4994. } else {
  4995. /* DMA */
  4996. if (flags & RADEON_VM_PAGE_SYSTEM) {
  4997. while (count) {
  4998. ndw = count * 2;
  4999. if (ndw > 0xFFFFE)
  5000. ndw = 0xFFFFE;
  5001. /* for non-physically contiguous pages (system) */
  5002. ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
  5003. ib->ptr[ib->length_dw++] = pe;
  5004. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  5005. ib->ptr[ib->length_dw++] = ndw;
  5006. for (; ndw > 0; ndw -= 2, --count, pe += 8) {
  5007. if (flags & RADEON_VM_PAGE_SYSTEM) {
  5008. value = radeon_vm_map_gart(rdev, addr);
  5009. value &= 0xFFFFFFFFFFFFF000ULL;
  5010. } else if (flags & RADEON_VM_PAGE_VALID) {
  5011. value = addr;
  5012. } else {
  5013. value = 0;
  5014. }
  5015. addr += incr;
  5016. value |= r600_flags;
  5017. ib->ptr[ib->length_dw++] = value;
  5018. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  5019. }
  5020. }
  5021. } else {
  5022. while (count) {
  5023. ndw = count;
  5024. if (ndw > 0x7FFFF)
  5025. ndw = 0x7FFFF;
  5026. if (flags & RADEON_VM_PAGE_VALID)
  5027. value = addr;
  5028. else
  5029. value = 0;
  5030. /* for physically contiguous pages (vram) */
  5031. ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_GENERATE_PTE_PDE, 0, 0);
  5032. ib->ptr[ib->length_dw++] = pe; /* dst addr */
  5033. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  5034. ib->ptr[ib->length_dw++] = r600_flags; /* mask */
  5035. ib->ptr[ib->length_dw++] = 0;
  5036. ib->ptr[ib->length_dw++] = value; /* value */
  5037. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  5038. ib->ptr[ib->length_dw++] = incr; /* increment size */
  5039. ib->ptr[ib->length_dw++] = 0;
  5040. ib->ptr[ib->length_dw++] = ndw; /* number of entries */
  5041. pe += ndw * 8;
  5042. addr += ndw * incr;
  5043. count -= ndw;
  5044. }
  5045. }
  5046. while (ib->length_dw & 0x7)
  5047. ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0);
  5048. }
  5049. }
  5050. /**
  5051. * cik_dma_vm_flush - cik vm flush using sDMA
  5052. *
  5053. * @rdev: radeon_device pointer
  5054. *
  5055. * Update the page table base and flush the VM TLB
  5056. * using sDMA (CIK).
  5057. */
  5058. void cik_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  5059. {
  5060. struct radeon_ring *ring = &rdev->ring[ridx];
  5061. u32 extra_bits = (SDMA_POLL_REG_MEM_EXTRA_OP(1) |
  5062. SDMA_POLL_REG_MEM_EXTRA_FUNC(3)); /* == */
  5063. u32 ref_and_mask;
  5064. if (vm == NULL)
  5065. return;
  5066. if (ridx == R600_RING_TYPE_DMA_INDEX)
  5067. ref_and_mask = SDMA0;
  5068. else
  5069. ref_and_mask = SDMA1;
  5070. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5071. if (vm->id < 8) {
  5072. radeon_ring_write(ring, (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  5073. } else {
  5074. radeon_ring_write(ring, (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  5075. }
  5076. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  5077. /* update SH_MEM_* regs */
  5078. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5079. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  5080. radeon_ring_write(ring, VMID(vm->id));
  5081. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5082. radeon_ring_write(ring, SH_MEM_BASES >> 2);
  5083. radeon_ring_write(ring, 0);
  5084. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5085. radeon_ring_write(ring, SH_MEM_CONFIG >> 2);
  5086. radeon_ring_write(ring, 0);
  5087. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5088. radeon_ring_write(ring, SH_MEM_APE1_BASE >> 2);
  5089. radeon_ring_write(ring, 1);
  5090. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5091. radeon_ring_write(ring, SH_MEM_APE1_LIMIT >> 2);
  5092. radeon_ring_write(ring, 0);
  5093. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5094. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  5095. radeon_ring_write(ring, VMID(0));
  5096. /* flush HDP */
  5097. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_POLL_REG_MEM, 0, extra_bits));
  5098. radeon_ring_write(ring, GPU_HDP_FLUSH_DONE);
  5099. radeon_ring_write(ring, GPU_HDP_FLUSH_REQ);
  5100. radeon_ring_write(ring, ref_and_mask); /* REFERENCE */
  5101. radeon_ring_write(ring, ref_and_mask); /* MASK */
  5102. radeon_ring_write(ring, (4 << 16) | 10); /* RETRY_COUNT, POLL_INTERVAL */
  5103. /* flush TLB */
  5104. radeon_ring_write(ring, SDMA_PACKET(SDMA_OPCODE_SRBM_WRITE, 0, 0xf000));
  5105. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  5106. radeon_ring_write(ring, 1 << vm->id);
  5107. }
  5108. /*
  5109. * RLC
  5110. * The RLC is a multi-purpose microengine that handles a
  5111. * variety of functions, the most important of which is
  5112. * the interrupt controller.
  5113. */
  5114. static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
  5115. bool enable)
  5116. {
  5117. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  5118. if (enable)
  5119. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5120. else
  5121. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5122. WREG32(CP_INT_CNTL_RING0, tmp);
  5123. }
  5124. static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
  5125. {
  5126. u32 tmp;
  5127. tmp = RREG32(RLC_LB_CNTL);
  5128. if (enable)
  5129. tmp |= LOAD_BALANCE_ENABLE;
  5130. else
  5131. tmp &= ~LOAD_BALANCE_ENABLE;
  5132. WREG32(RLC_LB_CNTL, tmp);
  5133. }
  5134. static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
  5135. {
  5136. u32 i, j, k;
  5137. u32 mask;
  5138. for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
  5139. for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
  5140. cik_select_se_sh(rdev, i, j);
  5141. for (k = 0; k < rdev->usec_timeout; k++) {
  5142. if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
  5143. break;
  5144. udelay(1);
  5145. }
  5146. }
  5147. }
  5148. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5149. mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
  5150. for (k = 0; k < rdev->usec_timeout; k++) {
  5151. if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
  5152. break;
  5153. udelay(1);
  5154. }
  5155. }
  5156. static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
  5157. {
  5158. u32 tmp;
  5159. tmp = RREG32(RLC_CNTL);
  5160. if (tmp != rlc)
  5161. WREG32(RLC_CNTL, rlc);
  5162. }
  5163. static u32 cik_halt_rlc(struct radeon_device *rdev)
  5164. {
  5165. u32 data, orig;
  5166. orig = data = RREG32(RLC_CNTL);
  5167. if (data & RLC_ENABLE) {
  5168. u32 i;
  5169. data &= ~RLC_ENABLE;
  5170. WREG32(RLC_CNTL, data);
  5171. for (i = 0; i < rdev->usec_timeout; i++) {
  5172. if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
  5173. break;
  5174. udelay(1);
  5175. }
  5176. cik_wait_for_rlc_serdes(rdev);
  5177. }
  5178. return orig;
  5179. }
  5180. void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
  5181. {
  5182. u32 tmp, i, mask;
  5183. tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
  5184. WREG32(RLC_GPR_REG2, tmp);
  5185. mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
  5186. for (i = 0; i < rdev->usec_timeout; i++) {
  5187. if ((RREG32(RLC_GPM_STAT) & mask) == mask)
  5188. break;
  5189. udelay(1);
  5190. }
  5191. for (i = 0; i < rdev->usec_timeout; i++) {
  5192. if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
  5193. break;
  5194. udelay(1);
  5195. }
  5196. }
  5197. void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
  5198. {
  5199. u32 tmp;
  5200. tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
  5201. WREG32(RLC_GPR_REG2, tmp);
  5202. }
  5203. /**
  5204. * cik_rlc_stop - stop the RLC ME
  5205. *
  5206. * @rdev: radeon_device pointer
  5207. *
  5208. * Halt the RLC ME (MicroEngine) (CIK).
  5209. */
  5210. static void cik_rlc_stop(struct radeon_device *rdev)
  5211. {
  5212. WREG32(RLC_CNTL, 0);
  5213. cik_enable_gui_idle_interrupt(rdev, false);
  5214. cik_wait_for_rlc_serdes(rdev);
  5215. }
  5216. /**
  5217. * cik_rlc_start - start the RLC ME
  5218. *
  5219. * @rdev: radeon_device pointer
  5220. *
  5221. * Unhalt the RLC ME (MicroEngine) (CIK).
  5222. */
  5223. static void cik_rlc_start(struct radeon_device *rdev)
  5224. {
  5225. WREG32(RLC_CNTL, RLC_ENABLE);
  5226. cik_enable_gui_idle_interrupt(rdev, true);
  5227. udelay(50);
  5228. }
  5229. /**
  5230. * cik_rlc_resume - setup the RLC hw
  5231. *
  5232. * @rdev: radeon_device pointer
  5233. *
  5234. * Initialize the RLC registers, load the ucode,
  5235. * and start the RLC (CIK).
  5236. * Returns 0 for success, -EINVAL if the ucode is not available.
  5237. */
  5238. static int cik_rlc_resume(struct radeon_device *rdev)
  5239. {
  5240. u32 i, size, tmp;
  5241. const __be32 *fw_data;
  5242. if (!rdev->rlc_fw)
  5243. return -EINVAL;
  5244. switch (rdev->family) {
  5245. case CHIP_BONAIRE:
  5246. default:
  5247. size = BONAIRE_RLC_UCODE_SIZE;
  5248. break;
  5249. case CHIP_KAVERI:
  5250. size = KV_RLC_UCODE_SIZE;
  5251. break;
  5252. case CHIP_KABINI:
  5253. size = KB_RLC_UCODE_SIZE;
  5254. break;
  5255. }
  5256. cik_rlc_stop(rdev);
  5257. /* disable CG */
  5258. tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
  5259. WREG32(RLC_CGCG_CGLS_CTRL, tmp);
  5260. si_rlc_reset(rdev);
  5261. cik_init_pg(rdev);
  5262. cik_init_cg(rdev);
  5263. WREG32(RLC_LB_CNTR_INIT, 0);
  5264. WREG32(RLC_LB_CNTR_MAX, 0x00008000);
  5265. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5266. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  5267. WREG32(RLC_LB_PARAMS, 0x00600408);
  5268. WREG32(RLC_LB_CNTL, 0x80000004);
  5269. WREG32(RLC_MC_CNTL, 0);
  5270. WREG32(RLC_UCODE_CNTL, 0);
  5271. fw_data = (const __be32 *)rdev->rlc_fw->data;
  5272. WREG32(RLC_GPM_UCODE_ADDR, 0);
  5273. for (i = 0; i < size; i++)
  5274. WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
  5275. WREG32(RLC_GPM_UCODE_ADDR, 0);
  5276. /* XXX - find out what chips support lbpw */
  5277. cik_enable_lbpw(rdev, false);
  5278. if (rdev->family == CHIP_BONAIRE)
  5279. WREG32(RLC_DRIVER_DMA_STATUS, 0);
  5280. cik_rlc_start(rdev);
  5281. return 0;
  5282. }
  5283. static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
  5284. {
  5285. u32 data, orig, tmp, tmp2;
  5286. orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
  5287. cik_enable_gui_idle_interrupt(rdev, enable);
  5288. if (enable) {
  5289. tmp = cik_halt_rlc(rdev);
  5290. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5291. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5292. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5293. tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
  5294. WREG32(RLC_SERDES_WR_CTRL, tmp2);
  5295. cik_update_rlc(rdev, tmp);
  5296. data |= CGCG_EN | CGLS_EN;
  5297. } else {
  5298. RREG32(CB_CGTT_SCLK_CTRL);
  5299. RREG32(CB_CGTT_SCLK_CTRL);
  5300. RREG32(CB_CGTT_SCLK_CTRL);
  5301. RREG32(CB_CGTT_SCLK_CTRL);
  5302. data &= ~(CGCG_EN | CGLS_EN);
  5303. }
  5304. if (orig != data)
  5305. WREG32(RLC_CGCG_CGLS_CTRL, data);
  5306. }
  5307. static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
  5308. {
  5309. u32 data, orig, tmp = 0;
  5310. if (enable) {
  5311. orig = data = RREG32(CP_MEM_SLP_CNTL);
  5312. data |= CP_MEM_LS_EN;
  5313. if (orig != data)
  5314. WREG32(CP_MEM_SLP_CNTL, data);
  5315. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  5316. data &= 0xfffffffd;
  5317. if (orig != data)
  5318. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  5319. tmp = cik_halt_rlc(rdev);
  5320. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5321. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5322. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5323. data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
  5324. WREG32(RLC_SERDES_WR_CTRL, data);
  5325. cik_update_rlc(rdev, tmp);
  5326. orig = data = RREG32(CGTS_SM_CTRL_REG);
  5327. data &= ~SM_MODE_MASK;
  5328. data |= SM_MODE(0x2);
  5329. data |= SM_MODE_ENABLE;
  5330. data &= ~CGTS_OVERRIDE;
  5331. data &= ~CGTS_LS_OVERRIDE;
  5332. data &= ~ON_MONITOR_ADD_MASK;
  5333. data |= ON_MONITOR_ADD_EN;
  5334. data |= ON_MONITOR_ADD(0x96);
  5335. if (orig != data)
  5336. WREG32(CGTS_SM_CTRL_REG, data);
  5337. } else {
  5338. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  5339. data |= 0x00000002;
  5340. if (orig != data)
  5341. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  5342. data = RREG32(RLC_MEM_SLP_CNTL);
  5343. if (data & RLC_MEM_LS_EN) {
  5344. data &= ~RLC_MEM_LS_EN;
  5345. WREG32(RLC_MEM_SLP_CNTL, data);
  5346. }
  5347. data = RREG32(CP_MEM_SLP_CNTL);
  5348. if (data & CP_MEM_LS_EN) {
  5349. data &= ~CP_MEM_LS_EN;
  5350. WREG32(CP_MEM_SLP_CNTL, data);
  5351. }
  5352. orig = data = RREG32(CGTS_SM_CTRL_REG);
  5353. data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
  5354. if (orig != data)
  5355. WREG32(CGTS_SM_CTRL_REG, data);
  5356. tmp = cik_halt_rlc(rdev);
  5357. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5358. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5359. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5360. data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
  5361. WREG32(RLC_SERDES_WR_CTRL, data);
  5362. cik_update_rlc(rdev, tmp);
  5363. }
  5364. }
  5365. static const u32 mc_cg_registers[] =
  5366. {
  5367. MC_HUB_MISC_HUB_CG,
  5368. MC_HUB_MISC_SIP_CG,
  5369. MC_HUB_MISC_VM_CG,
  5370. MC_XPB_CLK_GAT,
  5371. ATC_MISC_CG,
  5372. MC_CITF_MISC_WR_CG,
  5373. MC_CITF_MISC_RD_CG,
  5374. MC_CITF_MISC_VM_CG,
  5375. VM_L2_CG,
  5376. };
  5377. static void cik_enable_mc_ls(struct radeon_device *rdev,
  5378. bool enable)
  5379. {
  5380. int i;
  5381. u32 orig, data;
  5382. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  5383. orig = data = RREG32(mc_cg_registers[i]);
  5384. if (enable)
  5385. data |= MC_LS_ENABLE;
  5386. else
  5387. data &= ~MC_LS_ENABLE;
  5388. if (data != orig)
  5389. WREG32(mc_cg_registers[i], data);
  5390. }
  5391. }
  5392. static void cik_enable_mc_mgcg(struct radeon_device *rdev,
  5393. bool enable)
  5394. {
  5395. int i;
  5396. u32 orig, data;
  5397. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  5398. orig = data = RREG32(mc_cg_registers[i]);
  5399. if (enable)
  5400. data |= MC_CG_ENABLE;
  5401. else
  5402. data &= ~MC_CG_ENABLE;
  5403. if (data != orig)
  5404. WREG32(mc_cg_registers[i], data);
  5405. }
  5406. }
  5407. static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
  5408. bool enable)
  5409. {
  5410. u32 orig, data;
  5411. if (enable) {
  5412. WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
  5413. WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
  5414. } else {
  5415. orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
  5416. data |= 0xff000000;
  5417. if (data != orig)
  5418. WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
  5419. orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
  5420. data |= 0xff000000;
  5421. if (data != orig)
  5422. WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
  5423. }
  5424. }
  5425. static void cik_enable_sdma_mgls(struct radeon_device *rdev,
  5426. bool enable)
  5427. {
  5428. u32 orig, data;
  5429. if (enable) {
  5430. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
  5431. data |= 0x100;
  5432. if (orig != data)
  5433. WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
  5434. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
  5435. data |= 0x100;
  5436. if (orig != data)
  5437. WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
  5438. } else {
  5439. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
  5440. data &= ~0x100;
  5441. if (orig != data)
  5442. WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
  5443. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
  5444. data &= ~0x100;
  5445. if (orig != data)
  5446. WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
  5447. }
  5448. }
  5449. static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
  5450. bool enable)
  5451. {
  5452. u32 orig, data;
  5453. if (enable) {
  5454. data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  5455. data = 0xfff;
  5456. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
  5457. orig = data = RREG32(UVD_CGC_CTRL);
  5458. data |= DCM;
  5459. if (orig != data)
  5460. WREG32(UVD_CGC_CTRL, data);
  5461. } else {
  5462. data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  5463. data &= ~0xfff;
  5464. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
  5465. orig = data = RREG32(UVD_CGC_CTRL);
  5466. data &= ~DCM;
  5467. if (orig != data)
  5468. WREG32(UVD_CGC_CTRL, data);
  5469. }
  5470. }
  5471. static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
  5472. bool enable)
  5473. {
  5474. u32 orig, data;
  5475. orig = data = RREG32(HDP_HOST_PATH_CNTL);
  5476. if (enable)
  5477. data &= ~CLOCK_GATING_DIS;
  5478. else
  5479. data |= CLOCK_GATING_DIS;
  5480. if (orig != data)
  5481. WREG32(HDP_HOST_PATH_CNTL, data);
  5482. }
  5483. static void cik_enable_hdp_ls(struct radeon_device *rdev,
  5484. bool enable)
  5485. {
  5486. u32 orig, data;
  5487. orig = data = RREG32(HDP_MEM_POWER_LS);
  5488. if (enable)
  5489. data |= HDP_LS_ENABLE;
  5490. else
  5491. data &= ~HDP_LS_ENABLE;
  5492. if (orig != data)
  5493. WREG32(HDP_MEM_POWER_LS, data);
  5494. }
  5495. void cik_update_cg(struct radeon_device *rdev,
  5496. u32 block, bool enable)
  5497. {
  5498. if (block & RADEON_CG_BLOCK_GFX) {
  5499. /* order matters! */
  5500. if (enable) {
  5501. cik_enable_mgcg(rdev, true);
  5502. cik_enable_cgcg(rdev, true);
  5503. } else {
  5504. cik_enable_cgcg(rdev, false);
  5505. cik_enable_mgcg(rdev, false);
  5506. }
  5507. }
  5508. if (block & RADEON_CG_BLOCK_MC) {
  5509. if (!(rdev->flags & RADEON_IS_IGP)) {
  5510. cik_enable_mc_mgcg(rdev, enable);
  5511. cik_enable_mc_ls(rdev, enable);
  5512. }
  5513. }
  5514. if (block & RADEON_CG_BLOCK_SDMA) {
  5515. cik_enable_sdma_mgcg(rdev, enable);
  5516. cik_enable_sdma_mgls(rdev, enable);
  5517. }
  5518. if (block & RADEON_CG_BLOCK_UVD) {
  5519. if (rdev->has_uvd)
  5520. cik_enable_uvd_mgcg(rdev, enable);
  5521. }
  5522. if (block & RADEON_CG_BLOCK_HDP) {
  5523. cik_enable_hdp_mgcg(rdev, enable);
  5524. cik_enable_hdp_ls(rdev, enable);
  5525. }
  5526. }
  5527. static void cik_init_cg(struct radeon_device *rdev)
  5528. {
  5529. cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false); /* XXX true */
  5530. if (rdev->has_uvd)
  5531. si_init_uvd_internal_cg(rdev);
  5532. cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
  5533. RADEON_CG_BLOCK_SDMA |
  5534. RADEON_CG_BLOCK_UVD |
  5535. RADEON_CG_BLOCK_HDP), true);
  5536. }
  5537. static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
  5538. bool enable)
  5539. {
  5540. u32 data, orig;
  5541. orig = data = RREG32(RLC_PG_CNTL);
  5542. if (enable)
  5543. data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
  5544. else
  5545. data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
  5546. if (orig != data)
  5547. WREG32(RLC_PG_CNTL, data);
  5548. }
  5549. static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
  5550. bool enable)
  5551. {
  5552. u32 data, orig;
  5553. orig = data = RREG32(RLC_PG_CNTL);
  5554. if (enable)
  5555. data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
  5556. else
  5557. data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
  5558. if (orig != data)
  5559. WREG32(RLC_PG_CNTL, data);
  5560. }
  5561. static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
  5562. {
  5563. u32 data, orig;
  5564. orig = data = RREG32(RLC_PG_CNTL);
  5565. if (enable)
  5566. data &= ~DISABLE_CP_PG;
  5567. else
  5568. data |= DISABLE_CP_PG;
  5569. if (orig != data)
  5570. WREG32(RLC_PG_CNTL, data);
  5571. }
  5572. static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
  5573. {
  5574. u32 data, orig;
  5575. orig = data = RREG32(RLC_PG_CNTL);
  5576. if (enable)
  5577. data &= ~DISABLE_GDS_PG;
  5578. else
  5579. data |= DISABLE_GDS_PG;
  5580. if (orig != data)
  5581. WREG32(RLC_PG_CNTL, data);
  5582. }
  5583. #define CP_ME_TABLE_SIZE 96
  5584. #define CP_ME_TABLE_OFFSET 2048
  5585. #define CP_MEC_TABLE_OFFSET 4096
  5586. void cik_init_cp_pg_table(struct radeon_device *rdev)
  5587. {
  5588. const __be32 *fw_data;
  5589. volatile u32 *dst_ptr;
  5590. int me, i, max_me = 4;
  5591. u32 bo_offset = 0;
  5592. u32 table_offset;
  5593. if (rdev->family == CHIP_KAVERI)
  5594. max_me = 5;
  5595. if (rdev->rlc.cp_table_ptr == NULL)
  5596. return;
  5597. /* write the cp table buffer */
  5598. dst_ptr = rdev->rlc.cp_table_ptr;
  5599. for (me = 0; me < max_me; me++) {
  5600. if (me == 0) {
  5601. fw_data = (const __be32 *)rdev->ce_fw->data;
  5602. table_offset = CP_ME_TABLE_OFFSET;
  5603. } else if (me == 1) {
  5604. fw_data = (const __be32 *)rdev->pfp_fw->data;
  5605. table_offset = CP_ME_TABLE_OFFSET;
  5606. } else if (me == 2) {
  5607. fw_data = (const __be32 *)rdev->me_fw->data;
  5608. table_offset = CP_ME_TABLE_OFFSET;
  5609. } else {
  5610. fw_data = (const __be32 *)rdev->mec_fw->data;
  5611. table_offset = CP_MEC_TABLE_OFFSET;
  5612. }
  5613. for (i = 0; i < CP_ME_TABLE_SIZE; i ++) {
  5614. dst_ptr[bo_offset + i] = be32_to_cpu(fw_data[table_offset + i]);
  5615. }
  5616. bo_offset += CP_ME_TABLE_SIZE;
  5617. }
  5618. }
  5619. static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
  5620. bool enable)
  5621. {
  5622. u32 data, orig;
  5623. if (enable) {
  5624. orig = data = RREG32(RLC_PG_CNTL);
  5625. data |= GFX_PG_ENABLE;
  5626. if (orig != data)
  5627. WREG32(RLC_PG_CNTL, data);
  5628. orig = data = RREG32(RLC_AUTO_PG_CTRL);
  5629. data |= AUTO_PG_EN;
  5630. if (orig != data)
  5631. WREG32(RLC_AUTO_PG_CTRL, data);
  5632. } else {
  5633. orig = data = RREG32(RLC_PG_CNTL);
  5634. data &= ~GFX_PG_ENABLE;
  5635. if (orig != data)
  5636. WREG32(RLC_PG_CNTL, data);
  5637. orig = data = RREG32(RLC_AUTO_PG_CTRL);
  5638. data &= ~AUTO_PG_EN;
  5639. if (orig != data)
  5640. WREG32(RLC_AUTO_PG_CTRL, data);
  5641. data = RREG32(DB_RENDER_CONTROL);
  5642. }
  5643. }
  5644. static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
  5645. {
  5646. u32 mask = 0, tmp, tmp1;
  5647. int i;
  5648. cik_select_se_sh(rdev, se, sh);
  5649. tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  5650. tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  5651. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5652. tmp &= 0xffff0000;
  5653. tmp |= tmp1;
  5654. tmp >>= 16;
  5655. for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
  5656. mask <<= 1;
  5657. mask |= 1;
  5658. }
  5659. return (~tmp) & mask;
  5660. }
  5661. static void cik_init_ao_cu_mask(struct radeon_device *rdev)
  5662. {
  5663. u32 i, j, k, active_cu_number = 0;
  5664. u32 mask, counter, cu_bitmap;
  5665. u32 tmp = 0;
  5666. for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
  5667. for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
  5668. mask = 1;
  5669. cu_bitmap = 0;
  5670. counter = 0;
  5671. for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
  5672. if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
  5673. if (counter < 2)
  5674. cu_bitmap |= mask;
  5675. counter ++;
  5676. }
  5677. mask <<= 1;
  5678. }
  5679. active_cu_number += counter;
  5680. tmp |= (cu_bitmap << (i * 16 + j * 8));
  5681. }
  5682. }
  5683. WREG32(RLC_PG_AO_CU_MASK, tmp);
  5684. tmp = RREG32(RLC_MAX_PG_CU);
  5685. tmp &= ~MAX_PU_CU_MASK;
  5686. tmp |= MAX_PU_CU(active_cu_number);
  5687. WREG32(RLC_MAX_PG_CU, tmp);
  5688. }
  5689. static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
  5690. bool enable)
  5691. {
  5692. u32 data, orig;
  5693. orig = data = RREG32(RLC_PG_CNTL);
  5694. if (enable)
  5695. data |= STATIC_PER_CU_PG_ENABLE;
  5696. else
  5697. data &= ~STATIC_PER_CU_PG_ENABLE;
  5698. if (orig != data)
  5699. WREG32(RLC_PG_CNTL, data);
  5700. }
  5701. static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
  5702. bool enable)
  5703. {
  5704. u32 data, orig;
  5705. orig = data = RREG32(RLC_PG_CNTL);
  5706. if (enable)
  5707. data |= DYN_PER_CU_PG_ENABLE;
  5708. else
  5709. data &= ~DYN_PER_CU_PG_ENABLE;
  5710. if (orig != data)
  5711. WREG32(RLC_PG_CNTL, data);
  5712. }
  5713. #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
  5714. #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
  5715. static void cik_init_gfx_cgpg(struct radeon_device *rdev)
  5716. {
  5717. u32 data, orig;
  5718. u32 i;
  5719. if (rdev->rlc.cs_data) {
  5720. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  5721. WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
  5722. WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_gpu_addr);
  5723. WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
  5724. } else {
  5725. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  5726. for (i = 0; i < 3; i++)
  5727. WREG32(RLC_GPM_SCRATCH_DATA, 0);
  5728. }
  5729. if (rdev->rlc.reg_list) {
  5730. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
  5731. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  5732. WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
  5733. }
  5734. orig = data = RREG32(RLC_PG_CNTL);
  5735. data |= GFX_PG_SRC;
  5736. if (orig != data)
  5737. WREG32(RLC_PG_CNTL, data);
  5738. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  5739. WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
  5740. data = RREG32(CP_RB_WPTR_POLL_CNTL);
  5741. data &= ~IDLE_POLL_COUNT_MASK;
  5742. data |= IDLE_POLL_COUNT(0x60);
  5743. WREG32(CP_RB_WPTR_POLL_CNTL, data);
  5744. data = 0x10101010;
  5745. WREG32(RLC_PG_DELAY, data);
  5746. data = RREG32(RLC_PG_DELAY_2);
  5747. data &= ~0xff;
  5748. data |= 0x3;
  5749. WREG32(RLC_PG_DELAY_2, data);
  5750. data = RREG32(RLC_AUTO_PG_CTRL);
  5751. data &= ~GRBM_REG_SGIT_MASK;
  5752. data |= GRBM_REG_SGIT(0x700);
  5753. WREG32(RLC_AUTO_PG_CTRL, data);
  5754. }
  5755. static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
  5756. {
  5757. bool has_pg = false;
  5758. bool has_dyn_mgpg = false;
  5759. bool has_static_mgpg = false;
  5760. /* only APUs have PG */
  5761. if (rdev->flags & RADEON_IS_IGP) {
  5762. has_pg = true;
  5763. has_static_mgpg = true;
  5764. if (rdev->family == CHIP_KAVERI)
  5765. has_dyn_mgpg = true;
  5766. }
  5767. if (has_pg) {
  5768. cik_enable_gfx_cgpg(rdev, enable);
  5769. if (enable) {
  5770. cik_enable_gfx_static_mgpg(rdev, has_static_mgpg);
  5771. cik_enable_gfx_dynamic_mgpg(rdev, has_dyn_mgpg);
  5772. } else {
  5773. cik_enable_gfx_static_mgpg(rdev, false);
  5774. cik_enable_gfx_dynamic_mgpg(rdev, false);
  5775. }
  5776. }
  5777. }
  5778. void cik_init_pg(struct radeon_device *rdev)
  5779. {
  5780. bool has_pg = false;
  5781. /* only APUs have PG */
  5782. if (rdev->flags & RADEON_IS_IGP) {
  5783. /* XXX disable this for now */
  5784. /* has_pg = true; */
  5785. }
  5786. if (has_pg) {
  5787. cik_enable_sck_slowdown_on_pu(rdev, true);
  5788. cik_enable_sck_slowdown_on_pd(rdev, true);
  5789. cik_init_gfx_cgpg(rdev);
  5790. cik_enable_cp_pg(rdev, true);
  5791. cik_enable_gds_pg(rdev, true);
  5792. cik_init_ao_cu_mask(rdev);
  5793. cik_update_gfx_pg(rdev, true);
  5794. }
  5795. }
  5796. /*
  5797. * Interrupts
  5798. * Starting with r6xx, interrupts are handled via a ring buffer.
  5799. * Ring buffers are areas of GPU accessible memory that the GPU
  5800. * writes interrupt vectors into and the host reads vectors out of.
  5801. * There is a rptr (read pointer) that determines where the
  5802. * host is currently reading, and a wptr (write pointer)
  5803. * which determines where the GPU has written. When the
  5804. * pointers are equal, the ring is idle. When the GPU
  5805. * writes vectors to the ring buffer, it increments the
  5806. * wptr. When there is an interrupt, the host then starts
  5807. * fetching commands and processing them until the pointers are
  5808. * equal again at which point it updates the rptr.
  5809. */
  5810. /**
  5811. * cik_enable_interrupts - Enable the interrupt ring buffer
  5812. *
  5813. * @rdev: radeon_device pointer
  5814. *
  5815. * Enable the interrupt ring buffer (CIK).
  5816. */
  5817. static void cik_enable_interrupts(struct radeon_device *rdev)
  5818. {
  5819. u32 ih_cntl = RREG32(IH_CNTL);
  5820. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5821. ih_cntl |= ENABLE_INTR;
  5822. ih_rb_cntl |= IH_RB_ENABLE;
  5823. WREG32(IH_CNTL, ih_cntl);
  5824. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5825. rdev->ih.enabled = true;
  5826. }
  5827. /**
  5828. * cik_disable_interrupts - Disable the interrupt ring buffer
  5829. *
  5830. * @rdev: radeon_device pointer
  5831. *
  5832. * Disable the interrupt ring buffer (CIK).
  5833. */
  5834. static void cik_disable_interrupts(struct radeon_device *rdev)
  5835. {
  5836. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5837. u32 ih_cntl = RREG32(IH_CNTL);
  5838. ih_rb_cntl &= ~IH_RB_ENABLE;
  5839. ih_cntl &= ~ENABLE_INTR;
  5840. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5841. WREG32(IH_CNTL, ih_cntl);
  5842. /* set rptr, wptr to 0 */
  5843. WREG32(IH_RB_RPTR, 0);
  5844. WREG32(IH_RB_WPTR, 0);
  5845. rdev->ih.enabled = false;
  5846. rdev->ih.rptr = 0;
  5847. }
  5848. /**
  5849. * cik_disable_interrupt_state - Disable all interrupt sources
  5850. *
  5851. * @rdev: radeon_device pointer
  5852. *
  5853. * Clear all interrupt enable bits used by the driver (CIK).
  5854. */
  5855. static void cik_disable_interrupt_state(struct radeon_device *rdev)
  5856. {
  5857. u32 tmp;
  5858. /* gfx ring */
  5859. WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5860. /* sdma */
  5861. tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5862. WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  5863. tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5864. WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  5865. /* compute queues */
  5866. WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
  5867. WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
  5868. WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
  5869. WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
  5870. WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
  5871. WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
  5872. WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
  5873. WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
  5874. /* grbm */
  5875. WREG32(GRBM_INT_CNTL, 0);
  5876. /* vline/vblank, etc. */
  5877. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5878. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5879. if (rdev->num_crtc >= 4) {
  5880. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5881. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5882. }
  5883. if (rdev->num_crtc >= 6) {
  5884. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5885. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5886. }
  5887. /* dac hotplug */
  5888. WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
  5889. /* digital hotplug */
  5890. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5891. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5892. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5893. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5894. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5895. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5896. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5897. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5898. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5899. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5900. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5901. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5902. }
  5903. /**
  5904. * cik_irq_init - init and enable the interrupt ring
  5905. *
  5906. * @rdev: radeon_device pointer
  5907. *
  5908. * Allocate a ring buffer for the interrupt controller,
  5909. * enable the RLC, disable interrupts, enable the IH
  5910. * ring buffer and enable it (CIK).
  5911. * Called at device load and reume.
  5912. * Returns 0 for success, errors for failure.
  5913. */
  5914. static int cik_irq_init(struct radeon_device *rdev)
  5915. {
  5916. int ret = 0;
  5917. int rb_bufsz;
  5918. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  5919. /* allocate ring */
  5920. ret = r600_ih_ring_alloc(rdev);
  5921. if (ret)
  5922. return ret;
  5923. /* disable irqs */
  5924. cik_disable_interrupts(rdev);
  5925. /* init rlc */
  5926. ret = cik_rlc_resume(rdev);
  5927. if (ret) {
  5928. r600_ih_ring_fini(rdev);
  5929. return ret;
  5930. }
  5931. /* setup interrupt control */
  5932. /* XXX this should actually be a bus address, not an MC address. same on older asics */
  5933. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  5934. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  5935. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  5936. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  5937. */
  5938. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  5939. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  5940. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  5941. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  5942. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  5943. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  5944. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  5945. IH_WPTR_OVERFLOW_CLEAR |
  5946. (rb_bufsz << 1));
  5947. if (rdev->wb.enabled)
  5948. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  5949. /* set the writeback address whether it's enabled or not */
  5950. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  5951. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  5952. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5953. /* set rptr, wptr to 0 */
  5954. WREG32(IH_RB_RPTR, 0);
  5955. WREG32(IH_RB_WPTR, 0);
  5956. /* Default settings for IH_CNTL (disabled at first) */
  5957. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  5958. /* RPTR_REARM only works if msi's are enabled */
  5959. if (rdev->msi_enabled)
  5960. ih_cntl |= RPTR_REARM;
  5961. WREG32(IH_CNTL, ih_cntl);
  5962. /* force the active interrupt state to all disabled */
  5963. cik_disable_interrupt_state(rdev);
  5964. pci_set_master(rdev->pdev);
  5965. /* enable irqs */
  5966. cik_enable_interrupts(rdev);
  5967. return ret;
  5968. }
  5969. /**
  5970. * cik_irq_set - enable/disable interrupt sources
  5971. *
  5972. * @rdev: radeon_device pointer
  5973. *
  5974. * Enable interrupt sources on the GPU (vblanks, hpd,
  5975. * etc.) (CIK).
  5976. * Returns 0 for success, errors for failure.
  5977. */
  5978. int cik_irq_set(struct radeon_device *rdev)
  5979. {
  5980. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE |
  5981. PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
  5982. u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3;
  5983. u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3;
  5984. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  5985. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  5986. u32 grbm_int_cntl = 0;
  5987. u32 dma_cntl, dma_cntl1;
  5988. if (!rdev->irq.installed) {
  5989. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  5990. return -EINVAL;
  5991. }
  5992. /* don't enable anything if the ih is disabled */
  5993. if (!rdev->ih.enabled) {
  5994. cik_disable_interrupts(rdev);
  5995. /* force the active interrupt state to all disabled */
  5996. cik_disable_interrupt_state(rdev);
  5997. return 0;
  5998. }
  5999. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6000. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6001. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6002. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6003. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6004. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  6005. dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6006. dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6007. cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6008. cp_m1p1 = RREG32(CP_ME1_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6009. cp_m1p2 = RREG32(CP_ME1_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6010. cp_m1p3 = RREG32(CP_ME1_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6011. cp_m2p0 = RREG32(CP_ME2_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6012. cp_m2p1 = RREG32(CP_ME2_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6013. cp_m2p2 = RREG32(CP_ME2_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6014. cp_m2p3 = RREG32(CP_ME2_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6015. /* enable CP interrupts on all rings */
  6016. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  6017. DRM_DEBUG("cik_irq_set: sw int gfx\n");
  6018. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  6019. }
  6020. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  6021. struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6022. DRM_DEBUG("si_irq_set: sw int cp1\n");
  6023. if (ring->me == 1) {
  6024. switch (ring->pipe) {
  6025. case 0:
  6026. cp_m1p0 |= TIME_STAMP_INT_ENABLE;
  6027. break;
  6028. case 1:
  6029. cp_m1p1 |= TIME_STAMP_INT_ENABLE;
  6030. break;
  6031. case 2:
  6032. cp_m1p2 |= TIME_STAMP_INT_ENABLE;
  6033. break;
  6034. case 3:
  6035. cp_m1p2 |= TIME_STAMP_INT_ENABLE;
  6036. break;
  6037. default:
  6038. DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
  6039. break;
  6040. }
  6041. } else if (ring->me == 2) {
  6042. switch (ring->pipe) {
  6043. case 0:
  6044. cp_m2p0 |= TIME_STAMP_INT_ENABLE;
  6045. break;
  6046. case 1:
  6047. cp_m2p1 |= TIME_STAMP_INT_ENABLE;
  6048. break;
  6049. case 2:
  6050. cp_m2p2 |= TIME_STAMP_INT_ENABLE;
  6051. break;
  6052. case 3:
  6053. cp_m2p2 |= TIME_STAMP_INT_ENABLE;
  6054. break;
  6055. default:
  6056. DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
  6057. break;
  6058. }
  6059. } else {
  6060. DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
  6061. }
  6062. }
  6063. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  6064. struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6065. DRM_DEBUG("si_irq_set: sw int cp2\n");
  6066. if (ring->me == 1) {
  6067. switch (ring->pipe) {
  6068. case 0:
  6069. cp_m1p0 |= TIME_STAMP_INT_ENABLE;
  6070. break;
  6071. case 1:
  6072. cp_m1p1 |= TIME_STAMP_INT_ENABLE;
  6073. break;
  6074. case 2:
  6075. cp_m1p2 |= TIME_STAMP_INT_ENABLE;
  6076. break;
  6077. case 3:
  6078. cp_m1p2 |= TIME_STAMP_INT_ENABLE;
  6079. break;
  6080. default:
  6081. DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
  6082. break;
  6083. }
  6084. } else if (ring->me == 2) {
  6085. switch (ring->pipe) {
  6086. case 0:
  6087. cp_m2p0 |= TIME_STAMP_INT_ENABLE;
  6088. break;
  6089. case 1:
  6090. cp_m2p1 |= TIME_STAMP_INT_ENABLE;
  6091. break;
  6092. case 2:
  6093. cp_m2p2 |= TIME_STAMP_INT_ENABLE;
  6094. break;
  6095. case 3:
  6096. cp_m2p2 |= TIME_STAMP_INT_ENABLE;
  6097. break;
  6098. default:
  6099. DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
  6100. break;
  6101. }
  6102. } else {
  6103. DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
  6104. }
  6105. }
  6106. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  6107. DRM_DEBUG("cik_irq_set: sw int dma\n");
  6108. dma_cntl |= TRAP_ENABLE;
  6109. }
  6110. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  6111. DRM_DEBUG("cik_irq_set: sw int dma1\n");
  6112. dma_cntl1 |= TRAP_ENABLE;
  6113. }
  6114. if (rdev->irq.crtc_vblank_int[0] ||
  6115. atomic_read(&rdev->irq.pflip[0])) {
  6116. DRM_DEBUG("cik_irq_set: vblank 0\n");
  6117. crtc1 |= VBLANK_INTERRUPT_MASK;
  6118. }
  6119. if (rdev->irq.crtc_vblank_int[1] ||
  6120. atomic_read(&rdev->irq.pflip[1])) {
  6121. DRM_DEBUG("cik_irq_set: vblank 1\n");
  6122. crtc2 |= VBLANK_INTERRUPT_MASK;
  6123. }
  6124. if (rdev->irq.crtc_vblank_int[2] ||
  6125. atomic_read(&rdev->irq.pflip[2])) {
  6126. DRM_DEBUG("cik_irq_set: vblank 2\n");
  6127. crtc3 |= VBLANK_INTERRUPT_MASK;
  6128. }
  6129. if (rdev->irq.crtc_vblank_int[3] ||
  6130. atomic_read(&rdev->irq.pflip[3])) {
  6131. DRM_DEBUG("cik_irq_set: vblank 3\n");
  6132. crtc4 |= VBLANK_INTERRUPT_MASK;
  6133. }
  6134. if (rdev->irq.crtc_vblank_int[4] ||
  6135. atomic_read(&rdev->irq.pflip[4])) {
  6136. DRM_DEBUG("cik_irq_set: vblank 4\n");
  6137. crtc5 |= VBLANK_INTERRUPT_MASK;
  6138. }
  6139. if (rdev->irq.crtc_vblank_int[5] ||
  6140. atomic_read(&rdev->irq.pflip[5])) {
  6141. DRM_DEBUG("cik_irq_set: vblank 5\n");
  6142. crtc6 |= VBLANK_INTERRUPT_MASK;
  6143. }
  6144. if (rdev->irq.hpd[0]) {
  6145. DRM_DEBUG("cik_irq_set: hpd 1\n");
  6146. hpd1 |= DC_HPDx_INT_EN;
  6147. }
  6148. if (rdev->irq.hpd[1]) {
  6149. DRM_DEBUG("cik_irq_set: hpd 2\n");
  6150. hpd2 |= DC_HPDx_INT_EN;
  6151. }
  6152. if (rdev->irq.hpd[2]) {
  6153. DRM_DEBUG("cik_irq_set: hpd 3\n");
  6154. hpd3 |= DC_HPDx_INT_EN;
  6155. }
  6156. if (rdev->irq.hpd[3]) {
  6157. DRM_DEBUG("cik_irq_set: hpd 4\n");
  6158. hpd4 |= DC_HPDx_INT_EN;
  6159. }
  6160. if (rdev->irq.hpd[4]) {
  6161. DRM_DEBUG("cik_irq_set: hpd 5\n");
  6162. hpd5 |= DC_HPDx_INT_EN;
  6163. }
  6164. if (rdev->irq.hpd[5]) {
  6165. DRM_DEBUG("cik_irq_set: hpd 6\n");
  6166. hpd6 |= DC_HPDx_INT_EN;
  6167. }
  6168. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  6169. WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
  6170. WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
  6171. WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
  6172. WREG32(CP_ME1_PIPE1_INT_CNTL, cp_m1p1);
  6173. WREG32(CP_ME1_PIPE2_INT_CNTL, cp_m1p2);
  6174. WREG32(CP_ME1_PIPE3_INT_CNTL, cp_m1p3);
  6175. WREG32(CP_ME2_PIPE0_INT_CNTL, cp_m2p0);
  6176. WREG32(CP_ME2_PIPE1_INT_CNTL, cp_m2p1);
  6177. WREG32(CP_ME2_PIPE2_INT_CNTL, cp_m2p2);
  6178. WREG32(CP_ME2_PIPE3_INT_CNTL, cp_m2p3);
  6179. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  6180. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  6181. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  6182. if (rdev->num_crtc >= 4) {
  6183. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  6184. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  6185. }
  6186. if (rdev->num_crtc >= 6) {
  6187. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  6188. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  6189. }
  6190. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  6191. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  6192. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  6193. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  6194. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  6195. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  6196. return 0;
  6197. }
  6198. /**
  6199. * cik_irq_ack - ack interrupt sources
  6200. *
  6201. * @rdev: radeon_device pointer
  6202. *
  6203. * Ack interrupt sources on the GPU (vblanks, hpd,
  6204. * etc.) (CIK). Certain interrupts sources are sw
  6205. * generated and do not require an explicit ack.
  6206. */
  6207. static inline void cik_irq_ack(struct radeon_device *rdev)
  6208. {
  6209. u32 tmp;
  6210. rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  6211. rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  6212. rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  6213. rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  6214. rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  6215. rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  6216. rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
  6217. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
  6218. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  6219. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
  6220. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  6221. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  6222. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  6223. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  6224. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  6225. if (rdev->num_crtc >= 4) {
  6226. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  6227. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  6228. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  6229. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  6230. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  6231. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  6232. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  6233. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  6234. }
  6235. if (rdev->num_crtc >= 6) {
  6236. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  6237. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  6238. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  6239. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  6240. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  6241. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  6242. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  6243. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  6244. }
  6245. if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
  6246. tmp = RREG32(DC_HPD1_INT_CONTROL);
  6247. tmp |= DC_HPDx_INT_ACK;
  6248. WREG32(DC_HPD1_INT_CONTROL, tmp);
  6249. }
  6250. if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
  6251. tmp = RREG32(DC_HPD2_INT_CONTROL);
  6252. tmp |= DC_HPDx_INT_ACK;
  6253. WREG32(DC_HPD2_INT_CONTROL, tmp);
  6254. }
  6255. if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  6256. tmp = RREG32(DC_HPD3_INT_CONTROL);
  6257. tmp |= DC_HPDx_INT_ACK;
  6258. WREG32(DC_HPD3_INT_CONTROL, tmp);
  6259. }
  6260. if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  6261. tmp = RREG32(DC_HPD4_INT_CONTROL);
  6262. tmp |= DC_HPDx_INT_ACK;
  6263. WREG32(DC_HPD4_INT_CONTROL, tmp);
  6264. }
  6265. if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  6266. tmp = RREG32(DC_HPD5_INT_CONTROL);
  6267. tmp |= DC_HPDx_INT_ACK;
  6268. WREG32(DC_HPD5_INT_CONTROL, tmp);
  6269. }
  6270. if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  6271. tmp = RREG32(DC_HPD5_INT_CONTROL);
  6272. tmp |= DC_HPDx_INT_ACK;
  6273. WREG32(DC_HPD6_INT_CONTROL, tmp);
  6274. }
  6275. }
  6276. /**
  6277. * cik_irq_disable - disable interrupts
  6278. *
  6279. * @rdev: radeon_device pointer
  6280. *
  6281. * Disable interrupts on the hw (CIK).
  6282. */
  6283. static void cik_irq_disable(struct radeon_device *rdev)
  6284. {
  6285. cik_disable_interrupts(rdev);
  6286. /* Wait and acknowledge irq */
  6287. mdelay(1);
  6288. cik_irq_ack(rdev);
  6289. cik_disable_interrupt_state(rdev);
  6290. }
  6291. /**
  6292. * cik_irq_disable - disable interrupts for suspend
  6293. *
  6294. * @rdev: radeon_device pointer
  6295. *
  6296. * Disable interrupts and stop the RLC (CIK).
  6297. * Used for suspend.
  6298. */
  6299. static void cik_irq_suspend(struct radeon_device *rdev)
  6300. {
  6301. cik_irq_disable(rdev);
  6302. cik_rlc_stop(rdev);
  6303. }
  6304. /**
  6305. * cik_irq_fini - tear down interrupt support
  6306. *
  6307. * @rdev: radeon_device pointer
  6308. *
  6309. * Disable interrupts on the hw and free the IH ring
  6310. * buffer (CIK).
  6311. * Used for driver unload.
  6312. */
  6313. static void cik_irq_fini(struct radeon_device *rdev)
  6314. {
  6315. cik_irq_suspend(rdev);
  6316. r600_ih_ring_fini(rdev);
  6317. }
  6318. /**
  6319. * cik_get_ih_wptr - get the IH ring buffer wptr
  6320. *
  6321. * @rdev: radeon_device pointer
  6322. *
  6323. * Get the IH ring buffer wptr from either the register
  6324. * or the writeback memory buffer (CIK). Also check for
  6325. * ring buffer overflow and deal with it.
  6326. * Used by cik_irq_process().
  6327. * Returns the value of the wptr.
  6328. */
  6329. static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
  6330. {
  6331. u32 wptr, tmp;
  6332. if (rdev->wb.enabled)
  6333. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  6334. else
  6335. wptr = RREG32(IH_RB_WPTR);
  6336. if (wptr & RB_OVERFLOW) {
  6337. /* When a ring buffer overflow happen start parsing interrupt
  6338. * from the last not overwritten vector (wptr + 16). Hopefully
  6339. * this should allow us to catchup.
  6340. */
  6341. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  6342. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  6343. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  6344. tmp = RREG32(IH_RB_CNTL);
  6345. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  6346. WREG32(IH_RB_CNTL, tmp);
  6347. }
  6348. return (wptr & rdev->ih.ptr_mask);
  6349. }
  6350. /* CIK IV Ring
  6351. * Each IV ring entry is 128 bits:
  6352. * [7:0] - interrupt source id
  6353. * [31:8] - reserved
  6354. * [59:32] - interrupt source data
  6355. * [63:60] - reserved
  6356. * [71:64] - RINGID
  6357. * CP:
  6358. * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
  6359. * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
  6360. * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
  6361. * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
  6362. * PIPE_ID - ME0 0=3D
  6363. * - ME1&2 compute dispatcher (4 pipes each)
  6364. * SDMA:
  6365. * INSTANCE_ID [1:0], QUEUE_ID[1:0]
  6366. * INSTANCE_ID - 0 = sdma0, 1 = sdma1
  6367. * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
  6368. * [79:72] - VMID
  6369. * [95:80] - PASID
  6370. * [127:96] - reserved
  6371. */
  6372. /**
  6373. * cik_irq_process - interrupt handler
  6374. *
  6375. * @rdev: radeon_device pointer
  6376. *
  6377. * Interrupt hander (CIK). Walk the IH ring,
  6378. * ack interrupts and schedule work to handle
  6379. * interrupt events.
  6380. * Returns irq process return code.
  6381. */
  6382. int cik_irq_process(struct radeon_device *rdev)
  6383. {
  6384. struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6385. struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6386. u32 wptr;
  6387. u32 rptr;
  6388. u32 src_id, src_data, ring_id;
  6389. u8 me_id, pipe_id, queue_id;
  6390. u32 ring_index;
  6391. bool queue_hotplug = false;
  6392. bool queue_reset = false;
  6393. u32 addr, status, mc_client;
  6394. if (!rdev->ih.enabled || rdev->shutdown)
  6395. return IRQ_NONE;
  6396. wptr = cik_get_ih_wptr(rdev);
  6397. restart_ih:
  6398. /* is somebody else already processing irqs? */
  6399. if (atomic_xchg(&rdev->ih.lock, 1))
  6400. return IRQ_NONE;
  6401. rptr = rdev->ih.rptr;
  6402. DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  6403. /* Order reading of wptr vs. reading of IH ring data */
  6404. rmb();
  6405. /* display interrupts */
  6406. cik_irq_ack(rdev);
  6407. while (rptr != wptr) {
  6408. /* wptr/rptr are in bytes! */
  6409. ring_index = rptr / 4;
  6410. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  6411. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  6412. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  6413. switch (src_id) {
  6414. case 1: /* D1 vblank/vline */
  6415. switch (src_data) {
  6416. case 0: /* D1 vblank */
  6417. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT) {
  6418. if (rdev->irq.crtc_vblank_int[0]) {
  6419. drm_handle_vblank(rdev->ddev, 0);
  6420. rdev->pm.vblank_sync = true;
  6421. wake_up(&rdev->irq.vblank_queue);
  6422. }
  6423. if (atomic_read(&rdev->irq.pflip[0]))
  6424. radeon_crtc_handle_flip(rdev, 0);
  6425. rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  6426. DRM_DEBUG("IH: D1 vblank\n");
  6427. }
  6428. break;
  6429. case 1: /* D1 vline */
  6430. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT) {
  6431. rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  6432. DRM_DEBUG("IH: D1 vline\n");
  6433. }
  6434. break;
  6435. default:
  6436. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6437. break;
  6438. }
  6439. break;
  6440. case 2: /* D2 vblank/vline */
  6441. switch (src_data) {
  6442. case 0: /* D2 vblank */
  6443. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  6444. if (rdev->irq.crtc_vblank_int[1]) {
  6445. drm_handle_vblank(rdev->ddev, 1);
  6446. rdev->pm.vblank_sync = true;
  6447. wake_up(&rdev->irq.vblank_queue);
  6448. }
  6449. if (atomic_read(&rdev->irq.pflip[1]))
  6450. radeon_crtc_handle_flip(rdev, 1);
  6451. rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  6452. DRM_DEBUG("IH: D2 vblank\n");
  6453. }
  6454. break;
  6455. case 1: /* D2 vline */
  6456. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  6457. rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  6458. DRM_DEBUG("IH: D2 vline\n");
  6459. }
  6460. break;
  6461. default:
  6462. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6463. break;
  6464. }
  6465. break;
  6466. case 3: /* D3 vblank/vline */
  6467. switch (src_data) {
  6468. case 0: /* D3 vblank */
  6469. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  6470. if (rdev->irq.crtc_vblank_int[2]) {
  6471. drm_handle_vblank(rdev->ddev, 2);
  6472. rdev->pm.vblank_sync = true;
  6473. wake_up(&rdev->irq.vblank_queue);
  6474. }
  6475. if (atomic_read(&rdev->irq.pflip[2]))
  6476. radeon_crtc_handle_flip(rdev, 2);
  6477. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  6478. DRM_DEBUG("IH: D3 vblank\n");
  6479. }
  6480. break;
  6481. case 1: /* D3 vline */
  6482. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  6483. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  6484. DRM_DEBUG("IH: D3 vline\n");
  6485. }
  6486. break;
  6487. default:
  6488. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6489. break;
  6490. }
  6491. break;
  6492. case 4: /* D4 vblank/vline */
  6493. switch (src_data) {
  6494. case 0: /* D4 vblank */
  6495. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  6496. if (rdev->irq.crtc_vblank_int[3]) {
  6497. drm_handle_vblank(rdev->ddev, 3);
  6498. rdev->pm.vblank_sync = true;
  6499. wake_up(&rdev->irq.vblank_queue);
  6500. }
  6501. if (atomic_read(&rdev->irq.pflip[3]))
  6502. radeon_crtc_handle_flip(rdev, 3);
  6503. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  6504. DRM_DEBUG("IH: D4 vblank\n");
  6505. }
  6506. break;
  6507. case 1: /* D4 vline */
  6508. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  6509. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  6510. DRM_DEBUG("IH: D4 vline\n");
  6511. }
  6512. break;
  6513. default:
  6514. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6515. break;
  6516. }
  6517. break;
  6518. case 5: /* D5 vblank/vline */
  6519. switch (src_data) {
  6520. case 0: /* D5 vblank */
  6521. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  6522. if (rdev->irq.crtc_vblank_int[4]) {
  6523. drm_handle_vblank(rdev->ddev, 4);
  6524. rdev->pm.vblank_sync = true;
  6525. wake_up(&rdev->irq.vblank_queue);
  6526. }
  6527. if (atomic_read(&rdev->irq.pflip[4]))
  6528. radeon_crtc_handle_flip(rdev, 4);
  6529. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  6530. DRM_DEBUG("IH: D5 vblank\n");
  6531. }
  6532. break;
  6533. case 1: /* D5 vline */
  6534. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  6535. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  6536. DRM_DEBUG("IH: D5 vline\n");
  6537. }
  6538. break;
  6539. default:
  6540. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6541. break;
  6542. }
  6543. break;
  6544. case 6: /* D6 vblank/vline */
  6545. switch (src_data) {
  6546. case 0: /* D6 vblank */
  6547. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  6548. if (rdev->irq.crtc_vblank_int[5]) {
  6549. drm_handle_vblank(rdev->ddev, 5);
  6550. rdev->pm.vblank_sync = true;
  6551. wake_up(&rdev->irq.vblank_queue);
  6552. }
  6553. if (atomic_read(&rdev->irq.pflip[5]))
  6554. radeon_crtc_handle_flip(rdev, 5);
  6555. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  6556. DRM_DEBUG("IH: D6 vblank\n");
  6557. }
  6558. break;
  6559. case 1: /* D6 vline */
  6560. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  6561. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  6562. DRM_DEBUG("IH: D6 vline\n");
  6563. }
  6564. break;
  6565. default:
  6566. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6567. break;
  6568. }
  6569. break;
  6570. case 42: /* HPD hotplug */
  6571. switch (src_data) {
  6572. case 0:
  6573. if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
  6574. rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
  6575. queue_hotplug = true;
  6576. DRM_DEBUG("IH: HPD1\n");
  6577. }
  6578. break;
  6579. case 1:
  6580. if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
  6581. rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  6582. queue_hotplug = true;
  6583. DRM_DEBUG("IH: HPD2\n");
  6584. }
  6585. break;
  6586. case 2:
  6587. if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  6588. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  6589. queue_hotplug = true;
  6590. DRM_DEBUG("IH: HPD3\n");
  6591. }
  6592. break;
  6593. case 3:
  6594. if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  6595. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  6596. queue_hotplug = true;
  6597. DRM_DEBUG("IH: HPD4\n");
  6598. }
  6599. break;
  6600. case 4:
  6601. if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  6602. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  6603. queue_hotplug = true;
  6604. DRM_DEBUG("IH: HPD5\n");
  6605. }
  6606. break;
  6607. case 5:
  6608. if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  6609. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  6610. queue_hotplug = true;
  6611. DRM_DEBUG("IH: HPD6\n");
  6612. }
  6613. break;
  6614. default:
  6615. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6616. break;
  6617. }
  6618. break;
  6619. case 146:
  6620. case 147:
  6621. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  6622. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  6623. mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
  6624. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  6625. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  6626. addr);
  6627. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  6628. status);
  6629. cik_vm_decode_fault(rdev, status, addr, mc_client);
  6630. /* reset addr and status */
  6631. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  6632. break;
  6633. case 176: /* GFX RB CP_INT */
  6634. case 177: /* GFX IB CP_INT */
  6635. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  6636. break;
  6637. case 181: /* CP EOP event */
  6638. DRM_DEBUG("IH: CP EOP\n");
  6639. /* XXX check the bitfield order! */
  6640. me_id = (ring_id & 0x60) >> 5;
  6641. pipe_id = (ring_id & 0x18) >> 3;
  6642. queue_id = (ring_id & 0x7) >> 0;
  6643. switch (me_id) {
  6644. case 0:
  6645. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  6646. break;
  6647. case 1:
  6648. case 2:
  6649. if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
  6650. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  6651. if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
  6652. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  6653. break;
  6654. }
  6655. break;
  6656. case 184: /* CP Privileged reg access */
  6657. DRM_ERROR("Illegal register access in command stream\n");
  6658. /* XXX check the bitfield order! */
  6659. me_id = (ring_id & 0x60) >> 5;
  6660. pipe_id = (ring_id & 0x18) >> 3;
  6661. queue_id = (ring_id & 0x7) >> 0;
  6662. switch (me_id) {
  6663. case 0:
  6664. /* This results in a full GPU reset, but all we need to do is soft
  6665. * reset the CP for gfx
  6666. */
  6667. queue_reset = true;
  6668. break;
  6669. case 1:
  6670. /* XXX compute */
  6671. queue_reset = true;
  6672. break;
  6673. case 2:
  6674. /* XXX compute */
  6675. queue_reset = true;
  6676. break;
  6677. }
  6678. break;
  6679. case 185: /* CP Privileged inst */
  6680. DRM_ERROR("Illegal instruction in command stream\n");
  6681. /* XXX check the bitfield order! */
  6682. me_id = (ring_id & 0x60) >> 5;
  6683. pipe_id = (ring_id & 0x18) >> 3;
  6684. queue_id = (ring_id & 0x7) >> 0;
  6685. switch (me_id) {
  6686. case 0:
  6687. /* This results in a full GPU reset, but all we need to do is soft
  6688. * reset the CP for gfx
  6689. */
  6690. queue_reset = true;
  6691. break;
  6692. case 1:
  6693. /* XXX compute */
  6694. queue_reset = true;
  6695. break;
  6696. case 2:
  6697. /* XXX compute */
  6698. queue_reset = true;
  6699. break;
  6700. }
  6701. break;
  6702. case 224: /* SDMA trap event */
  6703. /* XXX check the bitfield order! */
  6704. me_id = (ring_id & 0x3) >> 0;
  6705. queue_id = (ring_id & 0xc) >> 2;
  6706. DRM_DEBUG("IH: SDMA trap\n");
  6707. switch (me_id) {
  6708. case 0:
  6709. switch (queue_id) {
  6710. case 0:
  6711. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  6712. break;
  6713. case 1:
  6714. /* XXX compute */
  6715. break;
  6716. case 2:
  6717. /* XXX compute */
  6718. break;
  6719. }
  6720. break;
  6721. case 1:
  6722. switch (queue_id) {
  6723. case 0:
  6724. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  6725. break;
  6726. case 1:
  6727. /* XXX compute */
  6728. break;
  6729. case 2:
  6730. /* XXX compute */
  6731. break;
  6732. }
  6733. break;
  6734. }
  6735. break;
  6736. case 241: /* SDMA Privileged inst */
  6737. case 247: /* SDMA Privileged inst */
  6738. DRM_ERROR("Illegal instruction in SDMA command stream\n");
  6739. /* XXX check the bitfield order! */
  6740. me_id = (ring_id & 0x3) >> 0;
  6741. queue_id = (ring_id & 0xc) >> 2;
  6742. switch (me_id) {
  6743. case 0:
  6744. switch (queue_id) {
  6745. case 0:
  6746. queue_reset = true;
  6747. break;
  6748. case 1:
  6749. /* XXX compute */
  6750. queue_reset = true;
  6751. break;
  6752. case 2:
  6753. /* XXX compute */
  6754. queue_reset = true;
  6755. break;
  6756. }
  6757. break;
  6758. case 1:
  6759. switch (queue_id) {
  6760. case 0:
  6761. queue_reset = true;
  6762. break;
  6763. case 1:
  6764. /* XXX compute */
  6765. queue_reset = true;
  6766. break;
  6767. case 2:
  6768. /* XXX compute */
  6769. queue_reset = true;
  6770. break;
  6771. }
  6772. break;
  6773. }
  6774. break;
  6775. case 233: /* GUI IDLE */
  6776. DRM_DEBUG("IH: GUI idle\n");
  6777. break;
  6778. default:
  6779. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  6780. break;
  6781. }
  6782. /* wptr/rptr are in bytes! */
  6783. rptr += 16;
  6784. rptr &= rdev->ih.ptr_mask;
  6785. }
  6786. if (queue_hotplug)
  6787. schedule_work(&rdev->hotplug_work);
  6788. if (queue_reset)
  6789. schedule_work(&rdev->reset_work);
  6790. rdev->ih.rptr = rptr;
  6791. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  6792. atomic_set(&rdev->ih.lock, 0);
  6793. /* make sure wptr hasn't changed while processing */
  6794. wptr = cik_get_ih_wptr(rdev);
  6795. if (wptr != rptr)
  6796. goto restart_ih;
  6797. return IRQ_HANDLED;
  6798. }
  6799. /*
  6800. * startup/shutdown callbacks
  6801. */
  6802. /**
  6803. * cik_startup - program the asic to a functional state
  6804. *
  6805. * @rdev: radeon_device pointer
  6806. *
  6807. * Programs the asic to a functional state (CIK).
  6808. * Called by cik_init() and cik_resume().
  6809. * Returns 0 for success, error for failure.
  6810. */
  6811. static int cik_startup(struct radeon_device *rdev)
  6812. {
  6813. struct radeon_ring *ring;
  6814. int r;
  6815. /* enable pcie gen2/3 link */
  6816. cik_pcie_gen3_enable(rdev);
  6817. /* enable aspm */
  6818. cik_program_aspm(rdev);
  6819. cik_mc_program(rdev);
  6820. if (rdev->flags & RADEON_IS_IGP) {
  6821. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  6822. !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
  6823. r = cik_init_microcode(rdev);
  6824. if (r) {
  6825. DRM_ERROR("Failed to load firmware!\n");
  6826. return r;
  6827. }
  6828. }
  6829. } else {
  6830. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  6831. !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
  6832. !rdev->mc_fw) {
  6833. r = cik_init_microcode(rdev);
  6834. if (r) {
  6835. DRM_ERROR("Failed to load firmware!\n");
  6836. return r;
  6837. }
  6838. }
  6839. r = ci_mc_load_microcode(rdev);
  6840. if (r) {
  6841. DRM_ERROR("Failed to load MC firmware!\n");
  6842. return r;
  6843. }
  6844. }
  6845. r = r600_vram_scratch_init(rdev);
  6846. if (r)
  6847. return r;
  6848. r = cik_pcie_gart_enable(rdev);
  6849. if (r)
  6850. return r;
  6851. cik_gpu_init(rdev);
  6852. /* allocate rlc buffers */
  6853. if (rdev->flags & RADEON_IS_IGP) {
  6854. if (rdev->family == CHIP_KAVERI) {
  6855. rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
  6856. rdev->rlc.reg_list_size =
  6857. (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
  6858. } else {
  6859. rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
  6860. rdev->rlc.reg_list_size =
  6861. (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
  6862. }
  6863. }
  6864. rdev->rlc.cs_data = ci_cs_data;
  6865. rdev->rlc.cp_table_size = CP_ME_TABLE_SIZE * 5 * 4;
  6866. r = sumo_rlc_init(rdev);
  6867. if (r) {
  6868. DRM_ERROR("Failed to init rlc BOs!\n");
  6869. return r;
  6870. }
  6871. /* allocate wb buffer */
  6872. r = radeon_wb_init(rdev);
  6873. if (r)
  6874. return r;
  6875. /* allocate mec buffers */
  6876. r = cik_mec_init(rdev);
  6877. if (r) {
  6878. DRM_ERROR("Failed to init MEC BOs!\n");
  6879. return r;
  6880. }
  6881. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  6882. if (r) {
  6883. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  6884. return r;
  6885. }
  6886. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  6887. if (r) {
  6888. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  6889. return r;
  6890. }
  6891. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  6892. if (r) {
  6893. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  6894. return r;
  6895. }
  6896. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  6897. if (r) {
  6898. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  6899. return r;
  6900. }
  6901. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  6902. if (r) {
  6903. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  6904. return r;
  6905. }
  6906. r = cik_uvd_resume(rdev);
  6907. if (!r) {
  6908. r = radeon_fence_driver_start_ring(rdev,
  6909. R600_RING_TYPE_UVD_INDEX);
  6910. if (r)
  6911. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  6912. }
  6913. if (r)
  6914. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  6915. /* Enable IRQ */
  6916. if (!rdev->irq.installed) {
  6917. r = radeon_irq_kms_init(rdev);
  6918. if (r)
  6919. return r;
  6920. }
  6921. r = cik_irq_init(rdev);
  6922. if (r) {
  6923. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  6924. radeon_irq_kms_fini(rdev);
  6925. return r;
  6926. }
  6927. cik_irq_set(rdev);
  6928. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  6929. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  6930. CP_RB0_RPTR, CP_RB0_WPTR,
  6931. 0, 0xfffff, RADEON_CP_PACKET2);
  6932. if (r)
  6933. return r;
  6934. /* set up the compute queues */
  6935. /* type-2 packets are deprecated on MEC, use type-3 instead */
  6936. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6937. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  6938. CP_HQD_PQ_RPTR, CP_HQD_PQ_WPTR,
  6939. 0, 0xfffff, PACKET3(PACKET3_NOP, 0x3FFF));
  6940. if (r)
  6941. return r;
  6942. ring->me = 1; /* first MEC */
  6943. ring->pipe = 0; /* first pipe */
  6944. ring->queue = 0; /* first queue */
  6945. ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
  6946. /* type-2 packets are deprecated on MEC, use type-3 instead */
  6947. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6948. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  6949. CP_HQD_PQ_RPTR, CP_HQD_PQ_WPTR,
  6950. 0, 0xffffffff, PACKET3(PACKET3_NOP, 0x3FFF));
  6951. if (r)
  6952. return r;
  6953. /* dGPU only have 1 MEC */
  6954. ring->me = 1; /* first MEC */
  6955. ring->pipe = 0; /* first pipe */
  6956. ring->queue = 1; /* second queue */
  6957. ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
  6958. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  6959. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  6960. SDMA0_GFX_RB_RPTR + SDMA0_REGISTER_OFFSET,
  6961. SDMA0_GFX_RB_WPTR + SDMA0_REGISTER_OFFSET,
  6962. 2, 0xfffffffc, SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
  6963. if (r)
  6964. return r;
  6965. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  6966. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  6967. SDMA0_GFX_RB_RPTR + SDMA1_REGISTER_OFFSET,
  6968. SDMA0_GFX_RB_WPTR + SDMA1_REGISTER_OFFSET,
  6969. 2, 0xfffffffc, SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
  6970. if (r)
  6971. return r;
  6972. r = cik_cp_resume(rdev);
  6973. if (r)
  6974. return r;
  6975. r = cik_sdma_resume(rdev);
  6976. if (r)
  6977. return r;
  6978. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  6979. if (ring->ring_size) {
  6980. r = radeon_ring_init(rdev, ring, ring->ring_size,
  6981. R600_WB_UVD_RPTR_OFFSET,
  6982. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  6983. 0, 0xfffff, RADEON_CP_PACKET2);
  6984. if (!r)
  6985. r = r600_uvd_init(rdev);
  6986. if (r)
  6987. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  6988. }
  6989. r = radeon_ib_pool_init(rdev);
  6990. if (r) {
  6991. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  6992. return r;
  6993. }
  6994. r = radeon_vm_manager_init(rdev);
  6995. if (r) {
  6996. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  6997. return r;
  6998. }
  6999. return 0;
  7000. }
  7001. /**
  7002. * cik_resume - resume the asic to a functional state
  7003. *
  7004. * @rdev: radeon_device pointer
  7005. *
  7006. * Programs the asic to a functional state (CIK).
  7007. * Called at resume.
  7008. * Returns 0 for success, error for failure.
  7009. */
  7010. int cik_resume(struct radeon_device *rdev)
  7011. {
  7012. int r;
  7013. /* post card */
  7014. atom_asic_init(rdev->mode_info.atom_context);
  7015. /* init golden registers */
  7016. cik_init_golden_registers(rdev);
  7017. rdev->accel_working = true;
  7018. r = cik_startup(rdev);
  7019. if (r) {
  7020. DRM_ERROR("cik startup failed on resume\n");
  7021. rdev->accel_working = false;
  7022. return r;
  7023. }
  7024. return r;
  7025. }
  7026. /**
  7027. * cik_suspend - suspend the asic
  7028. *
  7029. * @rdev: radeon_device pointer
  7030. *
  7031. * Bring the chip into a state suitable for suspend (CIK).
  7032. * Called at suspend.
  7033. * Returns 0 for success.
  7034. */
  7035. int cik_suspend(struct radeon_device *rdev)
  7036. {
  7037. radeon_vm_manager_fini(rdev);
  7038. cik_cp_enable(rdev, false);
  7039. cik_sdma_enable(rdev, false);
  7040. r600_uvd_stop(rdev);
  7041. radeon_uvd_suspend(rdev);
  7042. cik_irq_suspend(rdev);
  7043. radeon_wb_disable(rdev);
  7044. cik_pcie_gart_disable(rdev);
  7045. return 0;
  7046. }
  7047. /* Plan is to move initialization in that function and use
  7048. * helper function so that radeon_device_init pretty much
  7049. * do nothing more than calling asic specific function. This
  7050. * should also allow to remove a bunch of callback function
  7051. * like vram_info.
  7052. */
  7053. /**
  7054. * cik_init - asic specific driver and hw init
  7055. *
  7056. * @rdev: radeon_device pointer
  7057. *
  7058. * Setup asic specific driver variables and program the hw
  7059. * to a functional state (CIK).
  7060. * Called at driver startup.
  7061. * Returns 0 for success, errors for failure.
  7062. */
  7063. int cik_init(struct radeon_device *rdev)
  7064. {
  7065. struct radeon_ring *ring;
  7066. int r;
  7067. /* Read BIOS */
  7068. if (!radeon_get_bios(rdev)) {
  7069. if (ASIC_IS_AVIVO(rdev))
  7070. return -EINVAL;
  7071. }
  7072. /* Must be an ATOMBIOS */
  7073. if (!rdev->is_atom_bios) {
  7074. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  7075. return -EINVAL;
  7076. }
  7077. r = radeon_atombios_init(rdev);
  7078. if (r)
  7079. return r;
  7080. /* Post card if necessary */
  7081. if (!radeon_card_posted(rdev)) {
  7082. if (!rdev->bios) {
  7083. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  7084. return -EINVAL;
  7085. }
  7086. DRM_INFO("GPU not posted. posting now...\n");
  7087. atom_asic_init(rdev->mode_info.atom_context);
  7088. }
  7089. /* init golden registers */
  7090. cik_init_golden_registers(rdev);
  7091. /* Initialize scratch registers */
  7092. cik_scratch_init(rdev);
  7093. /* Initialize surface registers */
  7094. radeon_surface_init(rdev);
  7095. /* Initialize clocks */
  7096. radeon_get_clock_info(rdev->ddev);
  7097. /* Fence driver */
  7098. r = radeon_fence_driver_init(rdev);
  7099. if (r)
  7100. return r;
  7101. /* initialize memory controller */
  7102. r = cik_mc_init(rdev);
  7103. if (r)
  7104. return r;
  7105. /* Memory manager */
  7106. r = radeon_bo_init(rdev);
  7107. if (r)
  7108. return r;
  7109. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  7110. ring->ring_obj = NULL;
  7111. r600_ring_init(rdev, ring, 1024 * 1024);
  7112. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  7113. ring->ring_obj = NULL;
  7114. r600_ring_init(rdev, ring, 1024 * 1024);
  7115. r = radeon_doorbell_get(rdev, &ring->doorbell_page_num);
  7116. if (r)
  7117. return r;
  7118. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  7119. ring->ring_obj = NULL;
  7120. r600_ring_init(rdev, ring, 1024 * 1024);
  7121. r = radeon_doorbell_get(rdev, &ring->doorbell_page_num);
  7122. if (r)
  7123. return r;
  7124. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  7125. ring->ring_obj = NULL;
  7126. r600_ring_init(rdev, ring, 256 * 1024);
  7127. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  7128. ring->ring_obj = NULL;
  7129. r600_ring_init(rdev, ring, 256 * 1024);
  7130. r = radeon_uvd_init(rdev);
  7131. if (!r) {
  7132. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  7133. ring->ring_obj = NULL;
  7134. r600_ring_init(rdev, ring, 4096);
  7135. }
  7136. rdev->ih.ring_obj = NULL;
  7137. r600_ih_ring_init(rdev, 64 * 1024);
  7138. r = r600_pcie_gart_init(rdev);
  7139. if (r)
  7140. return r;
  7141. rdev->accel_working = true;
  7142. r = cik_startup(rdev);
  7143. if (r) {
  7144. dev_err(rdev->dev, "disabling GPU acceleration\n");
  7145. cik_cp_fini(rdev);
  7146. cik_sdma_fini(rdev);
  7147. cik_irq_fini(rdev);
  7148. sumo_rlc_fini(rdev);
  7149. cik_mec_fini(rdev);
  7150. radeon_wb_fini(rdev);
  7151. radeon_ib_pool_fini(rdev);
  7152. radeon_vm_manager_fini(rdev);
  7153. radeon_irq_kms_fini(rdev);
  7154. cik_pcie_gart_fini(rdev);
  7155. rdev->accel_working = false;
  7156. }
  7157. /* Don't start up if the MC ucode is missing.
  7158. * The default clocks and voltages before the MC ucode
  7159. * is loaded are not suffient for advanced operations.
  7160. */
  7161. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  7162. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  7163. return -EINVAL;
  7164. }
  7165. return 0;
  7166. }
  7167. /**
  7168. * cik_fini - asic specific driver and hw fini
  7169. *
  7170. * @rdev: radeon_device pointer
  7171. *
  7172. * Tear down the asic specific driver variables and program the hw
  7173. * to an idle state (CIK).
  7174. * Called at driver unload.
  7175. */
  7176. void cik_fini(struct radeon_device *rdev)
  7177. {
  7178. cik_cp_fini(rdev);
  7179. cik_sdma_fini(rdev);
  7180. cik_irq_fini(rdev);
  7181. sumo_rlc_fini(rdev);
  7182. cik_mec_fini(rdev);
  7183. radeon_wb_fini(rdev);
  7184. radeon_vm_manager_fini(rdev);
  7185. radeon_ib_pool_fini(rdev);
  7186. radeon_irq_kms_fini(rdev);
  7187. r600_uvd_stop(rdev);
  7188. radeon_uvd_fini(rdev);
  7189. cik_pcie_gart_fini(rdev);
  7190. r600_vram_scratch_fini(rdev);
  7191. radeon_gem_fini(rdev);
  7192. radeon_fence_driver_fini(rdev);
  7193. radeon_bo_fini(rdev);
  7194. radeon_atombios_fini(rdev);
  7195. kfree(rdev->bios);
  7196. rdev->bios = NULL;
  7197. }
  7198. /* display watermark setup */
  7199. /**
  7200. * dce8_line_buffer_adjust - Set up the line buffer
  7201. *
  7202. * @rdev: radeon_device pointer
  7203. * @radeon_crtc: the selected display controller
  7204. * @mode: the current display mode on the selected display
  7205. * controller
  7206. *
  7207. * Setup up the line buffer allocation for
  7208. * the selected display controller (CIK).
  7209. * Returns the line buffer size in pixels.
  7210. */
  7211. static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
  7212. struct radeon_crtc *radeon_crtc,
  7213. struct drm_display_mode *mode)
  7214. {
  7215. u32 tmp;
  7216. /*
  7217. * Line Buffer Setup
  7218. * There are 6 line buffers, one for each display controllers.
  7219. * There are 3 partitions per LB. Select the number of partitions
  7220. * to enable based on the display width. For display widths larger
  7221. * than 4096, you need use to use 2 display controllers and combine
  7222. * them using the stereo blender.
  7223. */
  7224. if (radeon_crtc->base.enabled && mode) {
  7225. if (mode->crtc_hdisplay < 1920)
  7226. tmp = 1;
  7227. else if (mode->crtc_hdisplay < 2560)
  7228. tmp = 2;
  7229. else if (mode->crtc_hdisplay < 4096)
  7230. tmp = 0;
  7231. else {
  7232. DRM_DEBUG_KMS("Mode too big for LB!\n");
  7233. tmp = 0;
  7234. }
  7235. } else
  7236. tmp = 1;
  7237. WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
  7238. LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
  7239. if (radeon_crtc->base.enabled && mode) {
  7240. switch (tmp) {
  7241. case 0:
  7242. default:
  7243. return 4096 * 2;
  7244. case 1:
  7245. return 1920 * 2;
  7246. case 2:
  7247. return 2560 * 2;
  7248. }
  7249. }
  7250. /* controller not enabled, so no lb used */
  7251. return 0;
  7252. }
  7253. /**
  7254. * cik_get_number_of_dram_channels - get the number of dram channels
  7255. *
  7256. * @rdev: radeon_device pointer
  7257. *
  7258. * Look up the number of video ram channels (CIK).
  7259. * Used for display watermark bandwidth calculations
  7260. * Returns the number of dram channels
  7261. */
  7262. static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
  7263. {
  7264. u32 tmp = RREG32(MC_SHARED_CHMAP);
  7265. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  7266. case 0:
  7267. default:
  7268. return 1;
  7269. case 1:
  7270. return 2;
  7271. case 2:
  7272. return 4;
  7273. case 3:
  7274. return 8;
  7275. case 4:
  7276. return 3;
  7277. case 5:
  7278. return 6;
  7279. case 6:
  7280. return 10;
  7281. case 7:
  7282. return 12;
  7283. case 8:
  7284. return 16;
  7285. }
  7286. }
  7287. struct dce8_wm_params {
  7288. u32 dram_channels; /* number of dram channels */
  7289. u32 yclk; /* bandwidth per dram data pin in kHz */
  7290. u32 sclk; /* engine clock in kHz */
  7291. u32 disp_clk; /* display clock in kHz */
  7292. u32 src_width; /* viewport width */
  7293. u32 active_time; /* active display time in ns */
  7294. u32 blank_time; /* blank time in ns */
  7295. bool interlaced; /* mode is interlaced */
  7296. fixed20_12 vsc; /* vertical scale ratio */
  7297. u32 num_heads; /* number of active crtcs */
  7298. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  7299. u32 lb_size; /* line buffer allocated to pipe */
  7300. u32 vtaps; /* vertical scaler taps */
  7301. };
  7302. /**
  7303. * dce8_dram_bandwidth - get the dram bandwidth
  7304. *
  7305. * @wm: watermark calculation data
  7306. *
  7307. * Calculate the raw dram bandwidth (CIK).
  7308. * Used for display watermark bandwidth calculations
  7309. * Returns the dram bandwidth in MBytes/s
  7310. */
  7311. static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
  7312. {
  7313. /* Calculate raw DRAM Bandwidth */
  7314. fixed20_12 dram_efficiency; /* 0.7 */
  7315. fixed20_12 yclk, dram_channels, bandwidth;
  7316. fixed20_12 a;
  7317. a.full = dfixed_const(1000);
  7318. yclk.full = dfixed_const(wm->yclk);
  7319. yclk.full = dfixed_div(yclk, a);
  7320. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  7321. a.full = dfixed_const(10);
  7322. dram_efficiency.full = dfixed_const(7);
  7323. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  7324. bandwidth.full = dfixed_mul(dram_channels, yclk);
  7325. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  7326. return dfixed_trunc(bandwidth);
  7327. }
  7328. /**
  7329. * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
  7330. *
  7331. * @wm: watermark calculation data
  7332. *
  7333. * Calculate the dram bandwidth used for display (CIK).
  7334. * Used for display watermark bandwidth calculations
  7335. * Returns the dram bandwidth for display in MBytes/s
  7336. */
  7337. static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  7338. {
  7339. /* Calculate DRAM Bandwidth and the part allocated to display. */
  7340. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  7341. fixed20_12 yclk, dram_channels, bandwidth;
  7342. fixed20_12 a;
  7343. a.full = dfixed_const(1000);
  7344. yclk.full = dfixed_const(wm->yclk);
  7345. yclk.full = dfixed_div(yclk, a);
  7346. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  7347. a.full = dfixed_const(10);
  7348. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  7349. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  7350. bandwidth.full = dfixed_mul(dram_channels, yclk);
  7351. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  7352. return dfixed_trunc(bandwidth);
  7353. }
  7354. /**
  7355. * dce8_data_return_bandwidth - get the data return bandwidth
  7356. *
  7357. * @wm: watermark calculation data
  7358. *
  7359. * Calculate the data return bandwidth used for display (CIK).
  7360. * Used for display watermark bandwidth calculations
  7361. * Returns the data return bandwidth in MBytes/s
  7362. */
  7363. static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
  7364. {
  7365. /* Calculate the display Data return Bandwidth */
  7366. fixed20_12 return_efficiency; /* 0.8 */
  7367. fixed20_12 sclk, bandwidth;
  7368. fixed20_12 a;
  7369. a.full = dfixed_const(1000);
  7370. sclk.full = dfixed_const(wm->sclk);
  7371. sclk.full = dfixed_div(sclk, a);
  7372. a.full = dfixed_const(10);
  7373. return_efficiency.full = dfixed_const(8);
  7374. return_efficiency.full = dfixed_div(return_efficiency, a);
  7375. a.full = dfixed_const(32);
  7376. bandwidth.full = dfixed_mul(a, sclk);
  7377. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  7378. return dfixed_trunc(bandwidth);
  7379. }
  7380. /**
  7381. * dce8_dmif_request_bandwidth - get the dmif bandwidth
  7382. *
  7383. * @wm: watermark calculation data
  7384. *
  7385. * Calculate the dmif bandwidth used for display (CIK).
  7386. * Used for display watermark bandwidth calculations
  7387. * Returns the dmif bandwidth in MBytes/s
  7388. */
  7389. static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
  7390. {
  7391. /* Calculate the DMIF Request Bandwidth */
  7392. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  7393. fixed20_12 disp_clk, bandwidth;
  7394. fixed20_12 a, b;
  7395. a.full = dfixed_const(1000);
  7396. disp_clk.full = dfixed_const(wm->disp_clk);
  7397. disp_clk.full = dfixed_div(disp_clk, a);
  7398. a.full = dfixed_const(32);
  7399. b.full = dfixed_mul(a, disp_clk);
  7400. a.full = dfixed_const(10);
  7401. disp_clk_request_efficiency.full = dfixed_const(8);
  7402. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  7403. bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
  7404. return dfixed_trunc(bandwidth);
  7405. }
  7406. /**
  7407. * dce8_available_bandwidth - get the min available bandwidth
  7408. *
  7409. * @wm: watermark calculation data
  7410. *
  7411. * Calculate the min available bandwidth used for display (CIK).
  7412. * Used for display watermark bandwidth calculations
  7413. * Returns the min available bandwidth in MBytes/s
  7414. */
  7415. static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
  7416. {
  7417. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  7418. u32 dram_bandwidth = dce8_dram_bandwidth(wm);
  7419. u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
  7420. u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
  7421. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  7422. }
  7423. /**
  7424. * dce8_average_bandwidth - get the average available bandwidth
  7425. *
  7426. * @wm: watermark calculation data
  7427. *
  7428. * Calculate the average available bandwidth used for display (CIK).
  7429. * Used for display watermark bandwidth calculations
  7430. * Returns the average available bandwidth in MBytes/s
  7431. */
  7432. static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
  7433. {
  7434. /* Calculate the display mode Average Bandwidth
  7435. * DisplayMode should contain the source and destination dimensions,
  7436. * timing, etc.
  7437. */
  7438. fixed20_12 bpp;
  7439. fixed20_12 line_time;
  7440. fixed20_12 src_width;
  7441. fixed20_12 bandwidth;
  7442. fixed20_12 a;
  7443. a.full = dfixed_const(1000);
  7444. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  7445. line_time.full = dfixed_div(line_time, a);
  7446. bpp.full = dfixed_const(wm->bytes_per_pixel);
  7447. src_width.full = dfixed_const(wm->src_width);
  7448. bandwidth.full = dfixed_mul(src_width, bpp);
  7449. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  7450. bandwidth.full = dfixed_div(bandwidth, line_time);
  7451. return dfixed_trunc(bandwidth);
  7452. }
  7453. /**
  7454. * dce8_latency_watermark - get the latency watermark
  7455. *
  7456. * @wm: watermark calculation data
  7457. *
  7458. * Calculate the latency watermark (CIK).
  7459. * Used for display watermark bandwidth calculations
  7460. * Returns the latency watermark in ns
  7461. */
  7462. static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
  7463. {
  7464. /* First calculate the latency in ns */
  7465. u32 mc_latency = 2000; /* 2000 ns. */
  7466. u32 available_bandwidth = dce8_available_bandwidth(wm);
  7467. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  7468. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  7469. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  7470. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  7471. (wm->num_heads * cursor_line_pair_return_time);
  7472. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  7473. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  7474. u32 tmp, dmif_size = 12288;
  7475. fixed20_12 a, b, c;
  7476. if (wm->num_heads == 0)
  7477. return 0;
  7478. a.full = dfixed_const(2);
  7479. b.full = dfixed_const(1);
  7480. if ((wm->vsc.full > a.full) ||
  7481. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  7482. (wm->vtaps >= 5) ||
  7483. ((wm->vsc.full >= a.full) && wm->interlaced))
  7484. max_src_lines_per_dst_line = 4;
  7485. else
  7486. max_src_lines_per_dst_line = 2;
  7487. a.full = dfixed_const(available_bandwidth);
  7488. b.full = dfixed_const(wm->num_heads);
  7489. a.full = dfixed_div(a, b);
  7490. b.full = dfixed_const(mc_latency + 512);
  7491. c.full = dfixed_const(wm->disp_clk);
  7492. b.full = dfixed_div(b, c);
  7493. c.full = dfixed_const(dmif_size);
  7494. b.full = dfixed_div(c, b);
  7495. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  7496. b.full = dfixed_const(1000);
  7497. c.full = dfixed_const(wm->disp_clk);
  7498. b.full = dfixed_div(c, b);
  7499. c.full = dfixed_const(wm->bytes_per_pixel);
  7500. b.full = dfixed_mul(b, c);
  7501. lb_fill_bw = min(tmp, dfixed_trunc(b));
  7502. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  7503. b.full = dfixed_const(1000);
  7504. c.full = dfixed_const(lb_fill_bw);
  7505. b.full = dfixed_div(c, b);
  7506. a.full = dfixed_div(a, b);
  7507. line_fill_time = dfixed_trunc(a);
  7508. if (line_fill_time < wm->active_time)
  7509. return latency;
  7510. else
  7511. return latency + (line_fill_time - wm->active_time);
  7512. }
  7513. /**
  7514. * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
  7515. * average and available dram bandwidth
  7516. *
  7517. * @wm: watermark calculation data
  7518. *
  7519. * Check if the display average bandwidth fits in the display
  7520. * dram bandwidth (CIK).
  7521. * Used for display watermark bandwidth calculations
  7522. * Returns true if the display fits, false if not.
  7523. */
  7524. static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  7525. {
  7526. if (dce8_average_bandwidth(wm) <=
  7527. (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
  7528. return true;
  7529. else
  7530. return false;
  7531. }
  7532. /**
  7533. * dce8_average_bandwidth_vs_available_bandwidth - check
  7534. * average and available bandwidth
  7535. *
  7536. * @wm: watermark calculation data
  7537. *
  7538. * Check if the display average bandwidth fits in the display
  7539. * available bandwidth (CIK).
  7540. * Used for display watermark bandwidth calculations
  7541. * Returns true if the display fits, false if not.
  7542. */
  7543. static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
  7544. {
  7545. if (dce8_average_bandwidth(wm) <=
  7546. (dce8_available_bandwidth(wm) / wm->num_heads))
  7547. return true;
  7548. else
  7549. return false;
  7550. }
  7551. /**
  7552. * dce8_check_latency_hiding - check latency hiding
  7553. *
  7554. * @wm: watermark calculation data
  7555. *
  7556. * Check latency hiding (CIK).
  7557. * Used for display watermark bandwidth calculations
  7558. * Returns true if the display fits, false if not.
  7559. */
  7560. static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
  7561. {
  7562. u32 lb_partitions = wm->lb_size / wm->src_width;
  7563. u32 line_time = wm->active_time + wm->blank_time;
  7564. u32 latency_tolerant_lines;
  7565. u32 latency_hiding;
  7566. fixed20_12 a;
  7567. a.full = dfixed_const(1);
  7568. if (wm->vsc.full > a.full)
  7569. latency_tolerant_lines = 1;
  7570. else {
  7571. if (lb_partitions <= (wm->vtaps + 1))
  7572. latency_tolerant_lines = 1;
  7573. else
  7574. latency_tolerant_lines = 2;
  7575. }
  7576. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  7577. if (dce8_latency_watermark(wm) <= latency_hiding)
  7578. return true;
  7579. else
  7580. return false;
  7581. }
  7582. /**
  7583. * dce8_program_watermarks - program display watermarks
  7584. *
  7585. * @rdev: radeon_device pointer
  7586. * @radeon_crtc: the selected display controller
  7587. * @lb_size: line buffer size
  7588. * @num_heads: number of display controllers in use
  7589. *
  7590. * Calculate and program the display watermarks for the
  7591. * selected display controller (CIK).
  7592. */
  7593. static void dce8_program_watermarks(struct radeon_device *rdev,
  7594. struct radeon_crtc *radeon_crtc,
  7595. u32 lb_size, u32 num_heads)
  7596. {
  7597. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  7598. struct dce8_wm_params wm_low, wm_high;
  7599. u32 pixel_period;
  7600. u32 line_time = 0;
  7601. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  7602. u32 tmp, wm_mask;
  7603. if (radeon_crtc->base.enabled && num_heads && mode) {
  7604. pixel_period = 1000000 / (u32)mode->clock;
  7605. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  7606. /* watermark for high clocks */
  7607. if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
  7608. rdev->pm.dpm_enabled) {
  7609. wm_high.yclk =
  7610. radeon_dpm_get_mclk(rdev, false) * 10;
  7611. wm_high.sclk =
  7612. radeon_dpm_get_sclk(rdev, false) * 10;
  7613. } else {
  7614. wm_high.yclk = rdev->pm.current_mclk * 10;
  7615. wm_high.sclk = rdev->pm.current_sclk * 10;
  7616. }
  7617. wm_high.disp_clk = mode->clock;
  7618. wm_high.src_width = mode->crtc_hdisplay;
  7619. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  7620. wm_high.blank_time = line_time - wm_high.active_time;
  7621. wm_high.interlaced = false;
  7622. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  7623. wm_high.interlaced = true;
  7624. wm_high.vsc = radeon_crtc->vsc;
  7625. wm_high.vtaps = 1;
  7626. if (radeon_crtc->rmx_type != RMX_OFF)
  7627. wm_high.vtaps = 2;
  7628. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  7629. wm_high.lb_size = lb_size;
  7630. wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
  7631. wm_high.num_heads = num_heads;
  7632. /* set for high clocks */
  7633. latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
  7634. /* possibly force display priority to high */
  7635. /* should really do this at mode validation time... */
  7636. if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  7637. !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  7638. !dce8_check_latency_hiding(&wm_high) ||
  7639. (rdev->disp_priority == 2)) {
  7640. DRM_DEBUG_KMS("force priority to high\n");
  7641. }
  7642. /* watermark for low clocks */
  7643. if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
  7644. rdev->pm.dpm_enabled) {
  7645. wm_low.yclk =
  7646. radeon_dpm_get_mclk(rdev, true) * 10;
  7647. wm_low.sclk =
  7648. radeon_dpm_get_sclk(rdev, true) * 10;
  7649. } else {
  7650. wm_low.yclk = rdev->pm.current_mclk * 10;
  7651. wm_low.sclk = rdev->pm.current_sclk * 10;
  7652. }
  7653. wm_low.disp_clk = mode->clock;
  7654. wm_low.src_width = mode->crtc_hdisplay;
  7655. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  7656. wm_low.blank_time = line_time - wm_low.active_time;
  7657. wm_low.interlaced = false;
  7658. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  7659. wm_low.interlaced = true;
  7660. wm_low.vsc = radeon_crtc->vsc;
  7661. wm_low.vtaps = 1;
  7662. if (radeon_crtc->rmx_type != RMX_OFF)
  7663. wm_low.vtaps = 2;
  7664. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  7665. wm_low.lb_size = lb_size;
  7666. wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
  7667. wm_low.num_heads = num_heads;
  7668. /* set for low clocks */
  7669. latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
  7670. /* possibly force display priority to high */
  7671. /* should really do this at mode validation time... */
  7672. if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  7673. !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  7674. !dce8_check_latency_hiding(&wm_low) ||
  7675. (rdev->disp_priority == 2)) {
  7676. DRM_DEBUG_KMS("force priority to high\n");
  7677. }
  7678. }
  7679. /* select wm A */
  7680. wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
  7681. tmp = wm_mask;
  7682. tmp &= ~LATENCY_WATERMARK_MASK(3);
  7683. tmp |= LATENCY_WATERMARK_MASK(1);
  7684. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
  7685. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  7686. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  7687. LATENCY_HIGH_WATERMARK(line_time)));
  7688. /* select wm B */
  7689. tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
  7690. tmp &= ~LATENCY_WATERMARK_MASK(3);
  7691. tmp |= LATENCY_WATERMARK_MASK(2);
  7692. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
  7693. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  7694. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  7695. LATENCY_HIGH_WATERMARK(line_time)));
  7696. /* restore original selection */
  7697. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
  7698. /* save values for DPM */
  7699. radeon_crtc->line_time = line_time;
  7700. radeon_crtc->wm_high = latency_watermark_a;
  7701. radeon_crtc->wm_low = latency_watermark_b;
  7702. }
  7703. /**
  7704. * dce8_bandwidth_update - program display watermarks
  7705. *
  7706. * @rdev: radeon_device pointer
  7707. *
  7708. * Calculate and program the display watermarks and line
  7709. * buffer allocation (CIK).
  7710. */
  7711. void dce8_bandwidth_update(struct radeon_device *rdev)
  7712. {
  7713. struct drm_display_mode *mode = NULL;
  7714. u32 num_heads = 0, lb_size;
  7715. int i;
  7716. radeon_update_display_priority(rdev);
  7717. for (i = 0; i < rdev->num_crtc; i++) {
  7718. if (rdev->mode_info.crtcs[i]->base.enabled)
  7719. num_heads++;
  7720. }
  7721. for (i = 0; i < rdev->num_crtc; i++) {
  7722. mode = &rdev->mode_info.crtcs[i]->base.mode;
  7723. lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
  7724. dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  7725. }
  7726. }
  7727. /**
  7728. * cik_get_gpu_clock_counter - return GPU clock counter snapshot
  7729. *
  7730. * @rdev: radeon_device pointer
  7731. *
  7732. * Fetches a GPU clock counter snapshot (SI).
  7733. * Returns the 64 bit clock counter snapshot.
  7734. */
  7735. uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
  7736. {
  7737. uint64_t clock;
  7738. mutex_lock(&rdev->gpu_clock_mutex);
  7739. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  7740. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  7741. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  7742. mutex_unlock(&rdev->gpu_clock_mutex);
  7743. return clock;
  7744. }
  7745. static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  7746. u32 cntl_reg, u32 status_reg)
  7747. {
  7748. int r, i;
  7749. struct atom_clock_dividers dividers;
  7750. uint32_t tmp;
  7751. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  7752. clock, false, &dividers);
  7753. if (r)
  7754. return r;
  7755. tmp = RREG32_SMC(cntl_reg);
  7756. tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
  7757. tmp |= dividers.post_divider;
  7758. WREG32_SMC(cntl_reg, tmp);
  7759. for (i = 0; i < 100; i++) {
  7760. if (RREG32_SMC(status_reg) & DCLK_STATUS)
  7761. break;
  7762. mdelay(10);
  7763. }
  7764. if (i == 100)
  7765. return -ETIMEDOUT;
  7766. return 0;
  7767. }
  7768. int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  7769. {
  7770. int r = 0;
  7771. r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  7772. if (r)
  7773. return r;
  7774. r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  7775. return r;
  7776. }
  7777. int cik_uvd_resume(struct radeon_device *rdev)
  7778. {
  7779. uint64_t addr;
  7780. uint32_t size;
  7781. int r;
  7782. r = radeon_uvd_resume(rdev);
  7783. if (r)
  7784. return r;
  7785. /* programm the VCPU memory controller bits 0-27 */
  7786. addr = rdev->uvd.gpu_addr >> 3;
  7787. size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) >> 3;
  7788. WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
  7789. WREG32(UVD_VCPU_CACHE_SIZE0, size);
  7790. addr += size;
  7791. size = RADEON_UVD_STACK_SIZE >> 3;
  7792. WREG32(UVD_VCPU_CACHE_OFFSET1, addr);
  7793. WREG32(UVD_VCPU_CACHE_SIZE1, size);
  7794. addr += size;
  7795. size = RADEON_UVD_HEAP_SIZE >> 3;
  7796. WREG32(UVD_VCPU_CACHE_OFFSET2, addr);
  7797. WREG32(UVD_VCPU_CACHE_SIZE2, size);
  7798. /* bits 28-31 */
  7799. addr = (rdev->uvd.gpu_addr >> 28) & 0xF;
  7800. WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
  7801. /* bits 32-39 */
  7802. addr = (rdev->uvd.gpu_addr >> 32) & 0xFF;
  7803. WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
  7804. return 0;
  7805. }
  7806. static void cik_pcie_gen3_enable(struct radeon_device *rdev)
  7807. {
  7808. struct pci_dev *root = rdev->pdev->bus->self;
  7809. int bridge_pos, gpu_pos;
  7810. u32 speed_cntl, mask, current_data_rate;
  7811. int ret, i;
  7812. u16 tmp16;
  7813. if (radeon_pcie_gen2 == 0)
  7814. return;
  7815. if (rdev->flags & RADEON_IS_IGP)
  7816. return;
  7817. if (!(rdev->flags & RADEON_IS_PCIE))
  7818. return;
  7819. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  7820. if (ret != 0)
  7821. return;
  7822. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  7823. return;
  7824. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  7825. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  7826. LC_CURRENT_DATA_RATE_SHIFT;
  7827. if (mask & DRM_PCIE_SPEED_80) {
  7828. if (current_data_rate == 2) {
  7829. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  7830. return;
  7831. }
  7832. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  7833. } else if (mask & DRM_PCIE_SPEED_50) {
  7834. if (current_data_rate == 1) {
  7835. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  7836. return;
  7837. }
  7838. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  7839. }
  7840. bridge_pos = pci_pcie_cap(root);
  7841. if (!bridge_pos)
  7842. return;
  7843. gpu_pos = pci_pcie_cap(rdev->pdev);
  7844. if (!gpu_pos)
  7845. return;
  7846. if (mask & DRM_PCIE_SPEED_80) {
  7847. /* re-try equalization if gen3 is not already enabled */
  7848. if (current_data_rate != 2) {
  7849. u16 bridge_cfg, gpu_cfg;
  7850. u16 bridge_cfg2, gpu_cfg2;
  7851. u32 max_lw, current_lw, tmp;
  7852. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  7853. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  7854. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  7855. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  7856. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  7857. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  7858. tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
  7859. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  7860. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  7861. if (current_lw < max_lw) {
  7862. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  7863. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  7864. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  7865. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  7866. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  7867. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  7868. }
  7869. }
  7870. for (i = 0; i < 10; i++) {
  7871. /* check status */
  7872. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  7873. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  7874. break;
  7875. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  7876. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  7877. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  7878. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  7879. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  7880. tmp |= LC_SET_QUIESCE;
  7881. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  7882. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  7883. tmp |= LC_REDO_EQ;
  7884. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  7885. mdelay(100);
  7886. /* linkctl */
  7887. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  7888. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  7889. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  7890. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  7891. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  7892. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  7893. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  7894. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  7895. /* linkctl2 */
  7896. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  7897. tmp16 &= ~((1 << 4) | (7 << 9));
  7898. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  7899. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  7900. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  7901. tmp16 &= ~((1 << 4) | (7 << 9));
  7902. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  7903. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  7904. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  7905. tmp &= ~LC_SET_QUIESCE;
  7906. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  7907. }
  7908. }
  7909. }
  7910. /* set the link speed */
  7911. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  7912. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  7913. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  7914. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  7915. tmp16 &= ~0xf;
  7916. if (mask & DRM_PCIE_SPEED_80)
  7917. tmp16 |= 3; /* gen3 */
  7918. else if (mask & DRM_PCIE_SPEED_50)
  7919. tmp16 |= 2; /* gen2 */
  7920. else
  7921. tmp16 |= 1; /* gen1 */
  7922. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  7923. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  7924. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  7925. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  7926. for (i = 0; i < rdev->usec_timeout; i++) {
  7927. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  7928. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  7929. break;
  7930. udelay(1);
  7931. }
  7932. }
  7933. static void cik_program_aspm(struct radeon_device *rdev)
  7934. {
  7935. u32 data, orig;
  7936. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  7937. bool disable_clkreq = false;
  7938. if (radeon_aspm == 0)
  7939. return;
  7940. /* XXX double check IGPs */
  7941. if (rdev->flags & RADEON_IS_IGP)
  7942. return;
  7943. if (!(rdev->flags & RADEON_IS_PCIE))
  7944. return;
  7945. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  7946. data &= ~LC_XMIT_N_FTS_MASK;
  7947. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  7948. if (orig != data)
  7949. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  7950. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  7951. data |= LC_GO_TO_RECOVERY;
  7952. if (orig != data)
  7953. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  7954. orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
  7955. data |= P_IGNORE_EDB_ERR;
  7956. if (orig != data)
  7957. WREG32_PCIE_PORT(PCIE_P_CNTL, data);
  7958. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  7959. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  7960. data |= LC_PMI_TO_L1_DIS;
  7961. if (!disable_l0s)
  7962. data |= LC_L0S_INACTIVITY(7);
  7963. if (!disable_l1) {
  7964. data |= LC_L1_INACTIVITY(7);
  7965. data &= ~LC_PMI_TO_L1_DIS;
  7966. if (orig != data)
  7967. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  7968. if (!disable_plloff_in_l1) {
  7969. bool clk_req_support;
  7970. orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
  7971. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  7972. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  7973. if (orig != data)
  7974. WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
  7975. orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
  7976. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  7977. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  7978. if (orig != data)
  7979. WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
  7980. orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
  7981. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  7982. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  7983. if (orig != data)
  7984. WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
  7985. orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
  7986. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  7987. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  7988. if (orig != data)
  7989. WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
  7990. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  7991. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  7992. data |= LC_DYN_LANES_PWR_STATE(3);
  7993. if (orig != data)
  7994. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  7995. if (!disable_clkreq) {
  7996. struct pci_dev *root = rdev->pdev->bus->self;
  7997. u32 lnkcap;
  7998. clk_req_support = false;
  7999. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  8000. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  8001. clk_req_support = true;
  8002. } else {
  8003. clk_req_support = false;
  8004. }
  8005. if (clk_req_support) {
  8006. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  8007. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  8008. if (orig != data)
  8009. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  8010. orig = data = RREG32_SMC(THM_CLK_CNTL);
  8011. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  8012. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  8013. if (orig != data)
  8014. WREG32_SMC(THM_CLK_CNTL, data);
  8015. orig = data = RREG32_SMC(MISC_CLK_CTRL);
  8016. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  8017. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  8018. if (orig != data)
  8019. WREG32_SMC(MISC_CLK_CTRL, data);
  8020. orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
  8021. data &= ~BCLK_AS_XCLK;
  8022. if (orig != data)
  8023. WREG32_SMC(CG_CLKPIN_CNTL, data);
  8024. orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
  8025. data &= ~FORCE_BIF_REFCLK_EN;
  8026. if (orig != data)
  8027. WREG32_SMC(CG_CLKPIN_CNTL_2, data);
  8028. orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
  8029. data &= ~MPLL_CLKOUT_SEL_MASK;
  8030. data |= MPLL_CLKOUT_SEL(4);
  8031. if (orig != data)
  8032. WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
  8033. }
  8034. }
  8035. } else {
  8036. if (orig != data)
  8037. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  8038. }
  8039. orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
  8040. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  8041. if (orig != data)
  8042. WREG32_PCIE_PORT(PCIE_CNTL2, data);
  8043. if (!disable_l0s) {
  8044. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  8045. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  8046. data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
  8047. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  8048. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  8049. data &= ~LC_L0S_INACTIVITY_MASK;
  8050. if (orig != data)
  8051. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  8052. }
  8053. }
  8054. }
  8055. }