si.c 171 KB

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