evergreen.c 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/slab.h>
  26. #include <drm/drmP.h>
  27. #include "radeon.h"
  28. #include "radeon_asic.h"
  29. #include "radeon_audio.h"
  30. #include <drm/radeon_drm.h>
  31. #include "evergreend.h"
  32. #include "atom.h"
  33. #include "avivod.h"
  34. #include "evergreen_reg.h"
  35. #include "evergreen_blit_shaders.h"
  36. #include "radeon_ucode.h"
  37. /*
  38. * Indirect registers accessor
  39. */
  40. u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
  41. {
  42. unsigned long flags;
  43. u32 r;
  44. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  45. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  46. r = RREG32(EVERGREEN_CG_IND_DATA);
  47. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  48. return r;
  49. }
  50. void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  51. {
  52. unsigned long flags;
  53. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  54. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  55. WREG32(EVERGREEN_CG_IND_DATA, (v));
  56. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  57. }
  58. u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
  59. {
  60. unsigned long flags;
  61. u32 r;
  62. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  63. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  64. r = RREG32(EVERGREEN_PIF_PHY0_DATA);
  65. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  66. return r;
  67. }
  68. void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  69. {
  70. unsigned long flags;
  71. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  72. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  73. WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
  74. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  75. }
  76. u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
  77. {
  78. unsigned long flags;
  79. u32 r;
  80. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  81. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  82. r = RREG32(EVERGREEN_PIF_PHY1_DATA);
  83. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  84. return r;
  85. }
  86. void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  87. {
  88. unsigned long flags;
  89. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  90. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  91. WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
  92. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  93. }
  94. static const u32 crtc_offsets[6] =
  95. {
  96. EVERGREEN_CRTC0_REGISTER_OFFSET,
  97. EVERGREEN_CRTC1_REGISTER_OFFSET,
  98. EVERGREEN_CRTC2_REGISTER_OFFSET,
  99. EVERGREEN_CRTC3_REGISTER_OFFSET,
  100. EVERGREEN_CRTC4_REGISTER_OFFSET,
  101. EVERGREEN_CRTC5_REGISTER_OFFSET
  102. };
  103. #include "clearstate_evergreen.h"
  104. static const u32 sumo_rlc_save_restore_register_list[] =
  105. {
  106. 0x98fc,
  107. 0x9830,
  108. 0x9834,
  109. 0x9838,
  110. 0x9870,
  111. 0x9874,
  112. 0x8a14,
  113. 0x8b24,
  114. 0x8bcc,
  115. 0x8b10,
  116. 0x8d00,
  117. 0x8d04,
  118. 0x8c00,
  119. 0x8c04,
  120. 0x8c08,
  121. 0x8c0c,
  122. 0x8d8c,
  123. 0x8c20,
  124. 0x8c24,
  125. 0x8c28,
  126. 0x8c18,
  127. 0x8c1c,
  128. 0x8cf0,
  129. 0x8e2c,
  130. 0x8e38,
  131. 0x8c30,
  132. 0x9508,
  133. 0x9688,
  134. 0x9608,
  135. 0x960c,
  136. 0x9610,
  137. 0x9614,
  138. 0x88c4,
  139. 0x88d4,
  140. 0xa008,
  141. 0x900c,
  142. 0x9100,
  143. 0x913c,
  144. 0x98f8,
  145. 0x98f4,
  146. 0x9b7c,
  147. 0x3f8c,
  148. 0x8950,
  149. 0x8954,
  150. 0x8a18,
  151. 0x8b28,
  152. 0x9144,
  153. 0x9148,
  154. 0x914c,
  155. 0x3f90,
  156. 0x3f94,
  157. 0x915c,
  158. 0x9160,
  159. 0x9178,
  160. 0x917c,
  161. 0x9180,
  162. 0x918c,
  163. 0x9190,
  164. 0x9194,
  165. 0x9198,
  166. 0x919c,
  167. 0x91a8,
  168. 0x91ac,
  169. 0x91b0,
  170. 0x91b4,
  171. 0x91b8,
  172. 0x91c4,
  173. 0x91c8,
  174. 0x91cc,
  175. 0x91d0,
  176. 0x91d4,
  177. 0x91e0,
  178. 0x91e4,
  179. 0x91ec,
  180. 0x91f0,
  181. 0x91f4,
  182. 0x9200,
  183. 0x9204,
  184. 0x929c,
  185. 0x9150,
  186. 0x802c,
  187. };
  188. static void evergreen_gpu_init(struct radeon_device *rdev);
  189. void evergreen_fini(struct radeon_device *rdev);
  190. void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  191. void evergreen_program_aspm(struct radeon_device *rdev);
  192. extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  193. int ring, u32 cp_int_cntl);
  194. extern void cayman_vm_decode_fault(struct radeon_device *rdev,
  195. u32 status, u32 addr);
  196. void cik_init_cp_pg_table(struct radeon_device *rdev);
  197. extern u32 si_get_csb_size(struct radeon_device *rdev);
  198. extern void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  199. extern u32 cik_get_csb_size(struct radeon_device *rdev);
  200. extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  201. extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
  202. static const u32 evergreen_golden_registers[] =
  203. {
  204. 0x3f90, 0xffff0000, 0xff000000,
  205. 0x9148, 0xffff0000, 0xff000000,
  206. 0x3f94, 0xffff0000, 0xff000000,
  207. 0x914c, 0xffff0000, 0xff000000,
  208. 0x9b7c, 0xffffffff, 0x00000000,
  209. 0x8a14, 0xffffffff, 0x00000007,
  210. 0x8b10, 0xffffffff, 0x00000000,
  211. 0x960c, 0xffffffff, 0x54763210,
  212. 0x88c4, 0xffffffff, 0x000000c2,
  213. 0x88d4, 0xffffffff, 0x00000010,
  214. 0x8974, 0xffffffff, 0x00000000,
  215. 0xc78, 0x00000080, 0x00000080,
  216. 0x5eb4, 0xffffffff, 0x00000002,
  217. 0x5e78, 0xffffffff, 0x001000f0,
  218. 0x6104, 0x01000300, 0x00000000,
  219. 0x5bc0, 0x00300000, 0x00000000,
  220. 0x7030, 0xffffffff, 0x00000011,
  221. 0x7c30, 0xffffffff, 0x00000011,
  222. 0x10830, 0xffffffff, 0x00000011,
  223. 0x11430, 0xffffffff, 0x00000011,
  224. 0x12030, 0xffffffff, 0x00000011,
  225. 0x12c30, 0xffffffff, 0x00000011,
  226. 0xd02c, 0xffffffff, 0x08421000,
  227. 0x240c, 0xffffffff, 0x00000380,
  228. 0x8b24, 0xffffffff, 0x00ff0fff,
  229. 0x28a4c, 0x06000000, 0x06000000,
  230. 0x10c, 0x00000001, 0x00000001,
  231. 0x8d00, 0xffffffff, 0x100e4848,
  232. 0x8d04, 0xffffffff, 0x00164745,
  233. 0x8c00, 0xffffffff, 0xe4000003,
  234. 0x8c04, 0xffffffff, 0x40600060,
  235. 0x8c08, 0xffffffff, 0x001c001c,
  236. 0x8cf0, 0xffffffff, 0x08e00620,
  237. 0x8c20, 0xffffffff, 0x00800080,
  238. 0x8c24, 0xffffffff, 0x00800080,
  239. 0x8c18, 0xffffffff, 0x20202078,
  240. 0x8c1c, 0xffffffff, 0x00001010,
  241. 0x28350, 0xffffffff, 0x00000000,
  242. 0xa008, 0xffffffff, 0x00010000,
  243. 0x5c4, 0xffffffff, 0x00000001,
  244. 0x9508, 0xffffffff, 0x00000002,
  245. 0x913c, 0x0000000f, 0x0000000a
  246. };
  247. static const u32 evergreen_golden_registers2[] =
  248. {
  249. 0x2f4c, 0xffffffff, 0x00000000,
  250. 0x54f4, 0xffffffff, 0x00000000,
  251. 0x54f0, 0xffffffff, 0x00000000,
  252. 0x5498, 0xffffffff, 0x00000000,
  253. 0x549c, 0xffffffff, 0x00000000,
  254. 0x5494, 0xffffffff, 0x00000000,
  255. 0x53cc, 0xffffffff, 0x00000000,
  256. 0x53c8, 0xffffffff, 0x00000000,
  257. 0x53c4, 0xffffffff, 0x00000000,
  258. 0x53c0, 0xffffffff, 0x00000000,
  259. 0x53bc, 0xffffffff, 0x00000000,
  260. 0x53b8, 0xffffffff, 0x00000000,
  261. 0x53b4, 0xffffffff, 0x00000000,
  262. 0x53b0, 0xffffffff, 0x00000000
  263. };
  264. static const u32 cypress_mgcg_init[] =
  265. {
  266. 0x802c, 0xffffffff, 0xc0000000,
  267. 0x5448, 0xffffffff, 0x00000100,
  268. 0x55e4, 0xffffffff, 0x00000100,
  269. 0x160c, 0xffffffff, 0x00000100,
  270. 0x5644, 0xffffffff, 0x00000100,
  271. 0xc164, 0xffffffff, 0x00000100,
  272. 0x8a18, 0xffffffff, 0x00000100,
  273. 0x897c, 0xffffffff, 0x06000100,
  274. 0x8b28, 0xffffffff, 0x00000100,
  275. 0x9144, 0xffffffff, 0x00000100,
  276. 0x9a60, 0xffffffff, 0x00000100,
  277. 0x9868, 0xffffffff, 0x00000100,
  278. 0x8d58, 0xffffffff, 0x00000100,
  279. 0x9510, 0xffffffff, 0x00000100,
  280. 0x949c, 0xffffffff, 0x00000100,
  281. 0x9654, 0xffffffff, 0x00000100,
  282. 0x9030, 0xffffffff, 0x00000100,
  283. 0x9034, 0xffffffff, 0x00000100,
  284. 0x9038, 0xffffffff, 0x00000100,
  285. 0x903c, 0xffffffff, 0x00000100,
  286. 0x9040, 0xffffffff, 0x00000100,
  287. 0xa200, 0xffffffff, 0x00000100,
  288. 0xa204, 0xffffffff, 0x00000100,
  289. 0xa208, 0xffffffff, 0x00000100,
  290. 0xa20c, 0xffffffff, 0x00000100,
  291. 0x971c, 0xffffffff, 0x00000100,
  292. 0x977c, 0xffffffff, 0x00000100,
  293. 0x3f80, 0xffffffff, 0x00000100,
  294. 0xa210, 0xffffffff, 0x00000100,
  295. 0xa214, 0xffffffff, 0x00000100,
  296. 0x4d8, 0xffffffff, 0x00000100,
  297. 0x9784, 0xffffffff, 0x00000100,
  298. 0x9698, 0xffffffff, 0x00000100,
  299. 0x4d4, 0xffffffff, 0x00000200,
  300. 0x30cc, 0xffffffff, 0x00000100,
  301. 0xd0c0, 0xffffffff, 0xff000100,
  302. 0x802c, 0xffffffff, 0x40000000,
  303. 0x915c, 0xffffffff, 0x00010000,
  304. 0x9160, 0xffffffff, 0x00030002,
  305. 0x9178, 0xffffffff, 0x00070000,
  306. 0x917c, 0xffffffff, 0x00030002,
  307. 0x9180, 0xffffffff, 0x00050004,
  308. 0x918c, 0xffffffff, 0x00010006,
  309. 0x9190, 0xffffffff, 0x00090008,
  310. 0x9194, 0xffffffff, 0x00070000,
  311. 0x9198, 0xffffffff, 0x00030002,
  312. 0x919c, 0xffffffff, 0x00050004,
  313. 0x91a8, 0xffffffff, 0x00010006,
  314. 0x91ac, 0xffffffff, 0x00090008,
  315. 0x91b0, 0xffffffff, 0x00070000,
  316. 0x91b4, 0xffffffff, 0x00030002,
  317. 0x91b8, 0xffffffff, 0x00050004,
  318. 0x91c4, 0xffffffff, 0x00010006,
  319. 0x91c8, 0xffffffff, 0x00090008,
  320. 0x91cc, 0xffffffff, 0x00070000,
  321. 0x91d0, 0xffffffff, 0x00030002,
  322. 0x91d4, 0xffffffff, 0x00050004,
  323. 0x91e0, 0xffffffff, 0x00010006,
  324. 0x91e4, 0xffffffff, 0x00090008,
  325. 0x91e8, 0xffffffff, 0x00000000,
  326. 0x91ec, 0xffffffff, 0x00070000,
  327. 0x91f0, 0xffffffff, 0x00030002,
  328. 0x91f4, 0xffffffff, 0x00050004,
  329. 0x9200, 0xffffffff, 0x00010006,
  330. 0x9204, 0xffffffff, 0x00090008,
  331. 0x9208, 0xffffffff, 0x00070000,
  332. 0x920c, 0xffffffff, 0x00030002,
  333. 0x9210, 0xffffffff, 0x00050004,
  334. 0x921c, 0xffffffff, 0x00010006,
  335. 0x9220, 0xffffffff, 0x00090008,
  336. 0x9224, 0xffffffff, 0x00070000,
  337. 0x9228, 0xffffffff, 0x00030002,
  338. 0x922c, 0xffffffff, 0x00050004,
  339. 0x9238, 0xffffffff, 0x00010006,
  340. 0x923c, 0xffffffff, 0x00090008,
  341. 0x9240, 0xffffffff, 0x00070000,
  342. 0x9244, 0xffffffff, 0x00030002,
  343. 0x9248, 0xffffffff, 0x00050004,
  344. 0x9254, 0xffffffff, 0x00010006,
  345. 0x9258, 0xffffffff, 0x00090008,
  346. 0x925c, 0xffffffff, 0x00070000,
  347. 0x9260, 0xffffffff, 0x00030002,
  348. 0x9264, 0xffffffff, 0x00050004,
  349. 0x9270, 0xffffffff, 0x00010006,
  350. 0x9274, 0xffffffff, 0x00090008,
  351. 0x9278, 0xffffffff, 0x00070000,
  352. 0x927c, 0xffffffff, 0x00030002,
  353. 0x9280, 0xffffffff, 0x00050004,
  354. 0x928c, 0xffffffff, 0x00010006,
  355. 0x9290, 0xffffffff, 0x00090008,
  356. 0x9294, 0xffffffff, 0x00000000,
  357. 0x929c, 0xffffffff, 0x00000001,
  358. 0x802c, 0xffffffff, 0x40010000,
  359. 0x915c, 0xffffffff, 0x00010000,
  360. 0x9160, 0xffffffff, 0x00030002,
  361. 0x9178, 0xffffffff, 0x00070000,
  362. 0x917c, 0xffffffff, 0x00030002,
  363. 0x9180, 0xffffffff, 0x00050004,
  364. 0x918c, 0xffffffff, 0x00010006,
  365. 0x9190, 0xffffffff, 0x00090008,
  366. 0x9194, 0xffffffff, 0x00070000,
  367. 0x9198, 0xffffffff, 0x00030002,
  368. 0x919c, 0xffffffff, 0x00050004,
  369. 0x91a8, 0xffffffff, 0x00010006,
  370. 0x91ac, 0xffffffff, 0x00090008,
  371. 0x91b0, 0xffffffff, 0x00070000,
  372. 0x91b4, 0xffffffff, 0x00030002,
  373. 0x91b8, 0xffffffff, 0x00050004,
  374. 0x91c4, 0xffffffff, 0x00010006,
  375. 0x91c8, 0xffffffff, 0x00090008,
  376. 0x91cc, 0xffffffff, 0x00070000,
  377. 0x91d0, 0xffffffff, 0x00030002,
  378. 0x91d4, 0xffffffff, 0x00050004,
  379. 0x91e0, 0xffffffff, 0x00010006,
  380. 0x91e4, 0xffffffff, 0x00090008,
  381. 0x91e8, 0xffffffff, 0x00000000,
  382. 0x91ec, 0xffffffff, 0x00070000,
  383. 0x91f0, 0xffffffff, 0x00030002,
  384. 0x91f4, 0xffffffff, 0x00050004,
  385. 0x9200, 0xffffffff, 0x00010006,
  386. 0x9204, 0xffffffff, 0x00090008,
  387. 0x9208, 0xffffffff, 0x00070000,
  388. 0x920c, 0xffffffff, 0x00030002,
  389. 0x9210, 0xffffffff, 0x00050004,
  390. 0x921c, 0xffffffff, 0x00010006,
  391. 0x9220, 0xffffffff, 0x00090008,
  392. 0x9224, 0xffffffff, 0x00070000,
  393. 0x9228, 0xffffffff, 0x00030002,
  394. 0x922c, 0xffffffff, 0x00050004,
  395. 0x9238, 0xffffffff, 0x00010006,
  396. 0x923c, 0xffffffff, 0x00090008,
  397. 0x9240, 0xffffffff, 0x00070000,
  398. 0x9244, 0xffffffff, 0x00030002,
  399. 0x9248, 0xffffffff, 0x00050004,
  400. 0x9254, 0xffffffff, 0x00010006,
  401. 0x9258, 0xffffffff, 0x00090008,
  402. 0x925c, 0xffffffff, 0x00070000,
  403. 0x9260, 0xffffffff, 0x00030002,
  404. 0x9264, 0xffffffff, 0x00050004,
  405. 0x9270, 0xffffffff, 0x00010006,
  406. 0x9274, 0xffffffff, 0x00090008,
  407. 0x9278, 0xffffffff, 0x00070000,
  408. 0x927c, 0xffffffff, 0x00030002,
  409. 0x9280, 0xffffffff, 0x00050004,
  410. 0x928c, 0xffffffff, 0x00010006,
  411. 0x9290, 0xffffffff, 0x00090008,
  412. 0x9294, 0xffffffff, 0x00000000,
  413. 0x929c, 0xffffffff, 0x00000001,
  414. 0x802c, 0xffffffff, 0xc0000000
  415. };
  416. static const u32 redwood_mgcg_init[] =
  417. {
  418. 0x802c, 0xffffffff, 0xc0000000,
  419. 0x5448, 0xffffffff, 0x00000100,
  420. 0x55e4, 0xffffffff, 0x00000100,
  421. 0x160c, 0xffffffff, 0x00000100,
  422. 0x5644, 0xffffffff, 0x00000100,
  423. 0xc164, 0xffffffff, 0x00000100,
  424. 0x8a18, 0xffffffff, 0x00000100,
  425. 0x897c, 0xffffffff, 0x06000100,
  426. 0x8b28, 0xffffffff, 0x00000100,
  427. 0x9144, 0xffffffff, 0x00000100,
  428. 0x9a60, 0xffffffff, 0x00000100,
  429. 0x9868, 0xffffffff, 0x00000100,
  430. 0x8d58, 0xffffffff, 0x00000100,
  431. 0x9510, 0xffffffff, 0x00000100,
  432. 0x949c, 0xffffffff, 0x00000100,
  433. 0x9654, 0xffffffff, 0x00000100,
  434. 0x9030, 0xffffffff, 0x00000100,
  435. 0x9034, 0xffffffff, 0x00000100,
  436. 0x9038, 0xffffffff, 0x00000100,
  437. 0x903c, 0xffffffff, 0x00000100,
  438. 0x9040, 0xffffffff, 0x00000100,
  439. 0xa200, 0xffffffff, 0x00000100,
  440. 0xa204, 0xffffffff, 0x00000100,
  441. 0xa208, 0xffffffff, 0x00000100,
  442. 0xa20c, 0xffffffff, 0x00000100,
  443. 0x971c, 0xffffffff, 0x00000100,
  444. 0x977c, 0xffffffff, 0x00000100,
  445. 0x3f80, 0xffffffff, 0x00000100,
  446. 0xa210, 0xffffffff, 0x00000100,
  447. 0xa214, 0xffffffff, 0x00000100,
  448. 0x4d8, 0xffffffff, 0x00000100,
  449. 0x9784, 0xffffffff, 0x00000100,
  450. 0x9698, 0xffffffff, 0x00000100,
  451. 0x4d4, 0xffffffff, 0x00000200,
  452. 0x30cc, 0xffffffff, 0x00000100,
  453. 0xd0c0, 0xffffffff, 0xff000100,
  454. 0x802c, 0xffffffff, 0x40000000,
  455. 0x915c, 0xffffffff, 0x00010000,
  456. 0x9160, 0xffffffff, 0x00030002,
  457. 0x9178, 0xffffffff, 0x00070000,
  458. 0x917c, 0xffffffff, 0x00030002,
  459. 0x9180, 0xffffffff, 0x00050004,
  460. 0x918c, 0xffffffff, 0x00010006,
  461. 0x9190, 0xffffffff, 0x00090008,
  462. 0x9194, 0xffffffff, 0x00070000,
  463. 0x9198, 0xffffffff, 0x00030002,
  464. 0x919c, 0xffffffff, 0x00050004,
  465. 0x91a8, 0xffffffff, 0x00010006,
  466. 0x91ac, 0xffffffff, 0x00090008,
  467. 0x91b0, 0xffffffff, 0x00070000,
  468. 0x91b4, 0xffffffff, 0x00030002,
  469. 0x91b8, 0xffffffff, 0x00050004,
  470. 0x91c4, 0xffffffff, 0x00010006,
  471. 0x91c8, 0xffffffff, 0x00090008,
  472. 0x91cc, 0xffffffff, 0x00070000,
  473. 0x91d0, 0xffffffff, 0x00030002,
  474. 0x91d4, 0xffffffff, 0x00050004,
  475. 0x91e0, 0xffffffff, 0x00010006,
  476. 0x91e4, 0xffffffff, 0x00090008,
  477. 0x91e8, 0xffffffff, 0x00000000,
  478. 0x91ec, 0xffffffff, 0x00070000,
  479. 0x91f0, 0xffffffff, 0x00030002,
  480. 0x91f4, 0xffffffff, 0x00050004,
  481. 0x9200, 0xffffffff, 0x00010006,
  482. 0x9204, 0xffffffff, 0x00090008,
  483. 0x9294, 0xffffffff, 0x00000000,
  484. 0x929c, 0xffffffff, 0x00000001,
  485. 0x802c, 0xffffffff, 0xc0000000
  486. };
  487. static const u32 cedar_golden_registers[] =
  488. {
  489. 0x3f90, 0xffff0000, 0xff000000,
  490. 0x9148, 0xffff0000, 0xff000000,
  491. 0x3f94, 0xffff0000, 0xff000000,
  492. 0x914c, 0xffff0000, 0xff000000,
  493. 0x9b7c, 0xffffffff, 0x00000000,
  494. 0x8a14, 0xffffffff, 0x00000007,
  495. 0x8b10, 0xffffffff, 0x00000000,
  496. 0x960c, 0xffffffff, 0x54763210,
  497. 0x88c4, 0xffffffff, 0x000000c2,
  498. 0x88d4, 0xffffffff, 0x00000000,
  499. 0x8974, 0xffffffff, 0x00000000,
  500. 0xc78, 0x00000080, 0x00000080,
  501. 0x5eb4, 0xffffffff, 0x00000002,
  502. 0x5e78, 0xffffffff, 0x001000f0,
  503. 0x6104, 0x01000300, 0x00000000,
  504. 0x5bc0, 0x00300000, 0x00000000,
  505. 0x7030, 0xffffffff, 0x00000011,
  506. 0x7c30, 0xffffffff, 0x00000011,
  507. 0x10830, 0xffffffff, 0x00000011,
  508. 0x11430, 0xffffffff, 0x00000011,
  509. 0xd02c, 0xffffffff, 0x08421000,
  510. 0x240c, 0xffffffff, 0x00000380,
  511. 0x8b24, 0xffffffff, 0x00ff0fff,
  512. 0x28a4c, 0x06000000, 0x06000000,
  513. 0x10c, 0x00000001, 0x00000001,
  514. 0x8d00, 0xffffffff, 0x100e4848,
  515. 0x8d04, 0xffffffff, 0x00164745,
  516. 0x8c00, 0xffffffff, 0xe4000003,
  517. 0x8c04, 0xffffffff, 0x40600060,
  518. 0x8c08, 0xffffffff, 0x001c001c,
  519. 0x8cf0, 0xffffffff, 0x08e00410,
  520. 0x8c20, 0xffffffff, 0x00800080,
  521. 0x8c24, 0xffffffff, 0x00800080,
  522. 0x8c18, 0xffffffff, 0x20202078,
  523. 0x8c1c, 0xffffffff, 0x00001010,
  524. 0x28350, 0xffffffff, 0x00000000,
  525. 0xa008, 0xffffffff, 0x00010000,
  526. 0x5c4, 0xffffffff, 0x00000001,
  527. 0x9508, 0xffffffff, 0x00000002
  528. };
  529. static const u32 cedar_mgcg_init[] =
  530. {
  531. 0x802c, 0xffffffff, 0xc0000000,
  532. 0x5448, 0xffffffff, 0x00000100,
  533. 0x55e4, 0xffffffff, 0x00000100,
  534. 0x160c, 0xffffffff, 0x00000100,
  535. 0x5644, 0xffffffff, 0x00000100,
  536. 0xc164, 0xffffffff, 0x00000100,
  537. 0x8a18, 0xffffffff, 0x00000100,
  538. 0x897c, 0xffffffff, 0x06000100,
  539. 0x8b28, 0xffffffff, 0x00000100,
  540. 0x9144, 0xffffffff, 0x00000100,
  541. 0x9a60, 0xffffffff, 0x00000100,
  542. 0x9868, 0xffffffff, 0x00000100,
  543. 0x8d58, 0xffffffff, 0x00000100,
  544. 0x9510, 0xffffffff, 0x00000100,
  545. 0x949c, 0xffffffff, 0x00000100,
  546. 0x9654, 0xffffffff, 0x00000100,
  547. 0x9030, 0xffffffff, 0x00000100,
  548. 0x9034, 0xffffffff, 0x00000100,
  549. 0x9038, 0xffffffff, 0x00000100,
  550. 0x903c, 0xffffffff, 0x00000100,
  551. 0x9040, 0xffffffff, 0x00000100,
  552. 0xa200, 0xffffffff, 0x00000100,
  553. 0xa204, 0xffffffff, 0x00000100,
  554. 0xa208, 0xffffffff, 0x00000100,
  555. 0xa20c, 0xffffffff, 0x00000100,
  556. 0x971c, 0xffffffff, 0x00000100,
  557. 0x977c, 0xffffffff, 0x00000100,
  558. 0x3f80, 0xffffffff, 0x00000100,
  559. 0xa210, 0xffffffff, 0x00000100,
  560. 0xa214, 0xffffffff, 0x00000100,
  561. 0x4d8, 0xffffffff, 0x00000100,
  562. 0x9784, 0xffffffff, 0x00000100,
  563. 0x9698, 0xffffffff, 0x00000100,
  564. 0x4d4, 0xffffffff, 0x00000200,
  565. 0x30cc, 0xffffffff, 0x00000100,
  566. 0xd0c0, 0xffffffff, 0xff000100,
  567. 0x802c, 0xffffffff, 0x40000000,
  568. 0x915c, 0xffffffff, 0x00010000,
  569. 0x9178, 0xffffffff, 0x00050000,
  570. 0x917c, 0xffffffff, 0x00030002,
  571. 0x918c, 0xffffffff, 0x00010004,
  572. 0x9190, 0xffffffff, 0x00070006,
  573. 0x9194, 0xffffffff, 0x00050000,
  574. 0x9198, 0xffffffff, 0x00030002,
  575. 0x91a8, 0xffffffff, 0x00010004,
  576. 0x91ac, 0xffffffff, 0x00070006,
  577. 0x91e8, 0xffffffff, 0x00000000,
  578. 0x9294, 0xffffffff, 0x00000000,
  579. 0x929c, 0xffffffff, 0x00000001,
  580. 0x802c, 0xffffffff, 0xc0000000
  581. };
  582. static const u32 juniper_mgcg_init[] =
  583. {
  584. 0x802c, 0xffffffff, 0xc0000000,
  585. 0x5448, 0xffffffff, 0x00000100,
  586. 0x55e4, 0xffffffff, 0x00000100,
  587. 0x160c, 0xffffffff, 0x00000100,
  588. 0x5644, 0xffffffff, 0x00000100,
  589. 0xc164, 0xffffffff, 0x00000100,
  590. 0x8a18, 0xffffffff, 0x00000100,
  591. 0x897c, 0xffffffff, 0x06000100,
  592. 0x8b28, 0xffffffff, 0x00000100,
  593. 0x9144, 0xffffffff, 0x00000100,
  594. 0x9a60, 0xffffffff, 0x00000100,
  595. 0x9868, 0xffffffff, 0x00000100,
  596. 0x8d58, 0xffffffff, 0x00000100,
  597. 0x9510, 0xffffffff, 0x00000100,
  598. 0x949c, 0xffffffff, 0x00000100,
  599. 0x9654, 0xffffffff, 0x00000100,
  600. 0x9030, 0xffffffff, 0x00000100,
  601. 0x9034, 0xffffffff, 0x00000100,
  602. 0x9038, 0xffffffff, 0x00000100,
  603. 0x903c, 0xffffffff, 0x00000100,
  604. 0x9040, 0xffffffff, 0x00000100,
  605. 0xa200, 0xffffffff, 0x00000100,
  606. 0xa204, 0xffffffff, 0x00000100,
  607. 0xa208, 0xffffffff, 0x00000100,
  608. 0xa20c, 0xffffffff, 0x00000100,
  609. 0x971c, 0xffffffff, 0x00000100,
  610. 0xd0c0, 0xffffffff, 0xff000100,
  611. 0x802c, 0xffffffff, 0x40000000,
  612. 0x915c, 0xffffffff, 0x00010000,
  613. 0x9160, 0xffffffff, 0x00030002,
  614. 0x9178, 0xffffffff, 0x00070000,
  615. 0x917c, 0xffffffff, 0x00030002,
  616. 0x9180, 0xffffffff, 0x00050004,
  617. 0x918c, 0xffffffff, 0x00010006,
  618. 0x9190, 0xffffffff, 0x00090008,
  619. 0x9194, 0xffffffff, 0x00070000,
  620. 0x9198, 0xffffffff, 0x00030002,
  621. 0x919c, 0xffffffff, 0x00050004,
  622. 0x91a8, 0xffffffff, 0x00010006,
  623. 0x91ac, 0xffffffff, 0x00090008,
  624. 0x91b0, 0xffffffff, 0x00070000,
  625. 0x91b4, 0xffffffff, 0x00030002,
  626. 0x91b8, 0xffffffff, 0x00050004,
  627. 0x91c4, 0xffffffff, 0x00010006,
  628. 0x91c8, 0xffffffff, 0x00090008,
  629. 0x91cc, 0xffffffff, 0x00070000,
  630. 0x91d0, 0xffffffff, 0x00030002,
  631. 0x91d4, 0xffffffff, 0x00050004,
  632. 0x91e0, 0xffffffff, 0x00010006,
  633. 0x91e4, 0xffffffff, 0x00090008,
  634. 0x91e8, 0xffffffff, 0x00000000,
  635. 0x91ec, 0xffffffff, 0x00070000,
  636. 0x91f0, 0xffffffff, 0x00030002,
  637. 0x91f4, 0xffffffff, 0x00050004,
  638. 0x9200, 0xffffffff, 0x00010006,
  639. 0x9204, 0xffffffff, 0x00090008,
  640. 0x9208, 0xffffffff, 0x00070000,
  641. 0x920c, 0xffffffff, 0x00030002,
  642. 0x9210, 0xffffffff, 0x00050004,
  643. 0x921c, 0xffffffff, 0x00010006,
  644. 0x9220, 0xffffffff, 0x00090008,
  645. 0x9224, 0xffffffff, 0x00070000,
  646. 0x9228, 0xffffffff, 0x00030002,
  647. 0x922c, 0xffffffff, 0x00050004,
  648. 0x9238, 0xffffffff, 0x00010006,
  649. 0x923c, 0xffffffff, 0x00090008,
  650. 0x9240, 0xffffffff, 0x00070000,
  651. 0x9244, 0xffffffff, 0x00030002,
  652. 0x9248, 0xffffffff, 0x00050004,
  653. 0x9254, 0xffffffff, 0x00010006,
  654. 0x9258, 0xffffffff, 0x00090008,
  655. 0x925c, 0xffffffff, 0x00070000,
  656. 0x9260, 0xffffffff, 0x00030002,
  657. 0x9264, 0xffffffff, 0x00050004,
  658. 0x9270, 0xffffffff, 0x00010006,
  659. 0x9274, 0xffffffff, 0x00090008,
  660. 0x9278, 0xffffffff, 0x00070000,
  661. 0x927c, 0xffffffff, 0x00030002,
  662. 0x9280, 0xffffffff, 0x00050004,
  663. 0x928c, 0xffffffff, 0x00010006,
  664. 0x9290, 0xffffffff, 0x00090008,
  665. 0x9294, 0xffffffff, 0x00000000,
  666. 0x929c, 0xffffffff, 0x00000001,
  667. 0x802c, 0xffffffff, 0xc0000000,
  668. 0x977c, 0xffffffff, 0x00000100,
  669. 0x3f80, 0xffffffff, 0x00000100,
  670. 0xa210, 0xffffffff, 0x00000100,
  671. 0xa214, 0xffffffff, 0x00000100,
  672. 0x4d8, 0xffffffff, 0x00000100,
  673. 0x9784, 0xffffffff, 0x00000100,
  674. 0x9698, 0xffffffff, 0x00000100,
  675. 0x4d4, 0xffffffff, 0x00000200,
  676. 0x30cc, 0xffffffff, 0x00000100,
  677. 0x802c, 0xffffffff, 0xc0000000
  678. };
  679. static const u32 supersumo_golden_registers[] =
  680. {
  681. 0x5eb4, 0xffffffff, 0x00000002,
  682. 0x5c4, 0xffffffff, 0x00000001,
  683. 0x7030, 0xffffffff, 0x00000011,
  684. 0x7c30, 0xffffffff, 0x00000011,
  685. 0x6104, 0x01000300, 0x00000000,
  686. 0x5bc0, 0x00300000, 0x00000000,
  687. 0x8c04, 0xffffffff, 0x40600060,
  688. 0x8c08, 0xffffffff, 0x001c001c,
  689. 0x8c20, 0xffffffff, 0x00800080,
  690. 0x8c24, 0xffffffff, 0x00800080,
  691. 0x8c18, 0xffffffff, 0x20202078,
  692. 0x8c1c, 0xffffffff, 0x00001010,
  693. 0x918c, 0xffffffff, 0x00010006,
  694. 0x91a8, 0xffffffff, 0x00010006,
  695. 0x91c4, 0xffffffff, 0x00010006,
  696. 0x91e0, 0xffffffff, 0x00010006,
  697. 0x9200, 0xffffffff, 0x00010006,
  698. 0x9150, 0xffffffff, 0x6e944040,
  699. 0x917c, 0xffffffff, 0x00030002,
  700. 0x9180, 0xffffffff, 0x00050004,
  701. 0x9198, 0xffffffff, 0x00030002,
  702. 0x919c, 0xffffffff, 0x00050004,
  703. 0x91b4, 0xffffffff, 0x00030002,
  704. 0x91b8, 0xffffffff, 0x00050004,
  705. 0x91d0, 0xffffffff, 0x00030002,
  706. 0x91d4, 0xffffffff, 0x00050004,
  707. 0x91f0, 0xffffffff, 0x00030002,
  708. 0x91f4, 0xffffffff, 0x00050004,
  709. 0x915c, 0xffffffff, 0x00010000,
  710. 0x9160, 0xffffffff, 0x00030002,
  711. 0x3f90, 0xffff0000, 0xff000000,
  712. 0x9178, 0xffffffff, 0x00070000,
  713. 0x9194, 0xffffffff, 0x00070000,
  714. 0x91b0, 0xffffffff, 0x00070000,
  715. 0x91cc, 0xffffffff, 0x00070000,
  716. 0x91ec, 0xffffffff, 0x00070000,
  717. 0x9148, 0xffff0000, 0xff000000,
  718. 0x9190, 0xffffffff, 0x00090008,
  719. 0x91ac, 0xffffffff, 0x00090008,
  720. 0x91c8, 0xffffffff, 0x00090008,
  721. 0x91e4, 0xffffffff, 0x00090008,
  722. 0x9204, 0xffffffff, 0x00090008,
  723. 0x3f94, 0xffff0000, 0xff000000,
  724. 0x914c, 0xffff0000, 0xff000000,
  725. 0x929c, 0xffffffff, 0x00000001,
  726. 0x8a18, 0xffffffff, 0x00000100,
  727. 0x8b28, 0xffffffff, 0x00000100,
  728. 0x9144, 0xffffffff, 0x00000100,
  729. 0x5644, 0xffffffff, 0x00000100,
  730. 0x9b7c, 0xffffffff, 0x00000000,
  731. 0x8030, 0xffffffff, 0x0000100a,
  732. 0x8a14, 0xffffffff, 0x00000007,
  733. 0x8b24, 0xffffffff, 0x00ff0fff,
  734. 0x8b10, 0xffffffff, 0x00000000,
  735. 0x28a4c, 0x06000000, 0x06000000,
  736. 0x4d8, 0xffffffff, 0x00000100,
  737. 0x913c, 0xffff000f, 0x0100000a,
  738. 0x960c, 0xffffffff, 0x54763210,
  739. 0x88c4, 0xffffffff, 0x000000c2,
  740. 0x88d4, 0xffffffff, 0x00000010,
  741. 0x8974, 0xffffffff, 0x00000000,
  742. 0xc78, 0x00000080, 0x00000080,
  743. 0x5e78, 0xffffffff, 0x001000f0,
  744. 0xd02c, 0xffffffff, 0x08421000,
  745. 0xa008, 0xffffffff, 0x00010000,
  746. 0x8d00, 0xffffffff, 0x100e4848,
  747. 0x8d04, 0xffffffff, 0x00164745,
  748. 0x8c00, 0xffffffff, 0xe4000003,
  749. 0x8cf0, 0x1fffffff, 0x08e00620,
  750. 0x28350, 0xffffffff, 0x00000000,
  751. 0x9508, 0xffffffff, 0x00000002
  752. };
  753. static const u32 sumo_golden_registers[] =
  754. {
  755. 0x900c, 0x00ffffff, 0x0017071f,
  756. 0x8c18, 0xffffffff, 0x10101060,
  757. 0x8c1c, 0xffffffff, 0x00001010,
  758. 0x8c30, 0x0000000f, 0x00000005,
  759. 0x9688, 0x0000000f, 0x00000007
  760. };
  761. static const u32 wrestler_golden_registers[] =
  762. {
  763. 0x5eb4, 0xffffffff, 0x00000002,
  764. 0x5c4, 0xffffffff, 0x00000001,
  765. 0x7030, 0xffffffff, 0x00000011,
  766. 0x7c30, 0xffffffff, 0x00000011,
  767. 0x6104, 0x01000300, 0x00000000,
  768. 0x5bc0, 0x00300000, 0x00000000,
  769. 0x918c, 0xffffffff, 0x00010006,
  770. 0x91a8, 0xffffffff, 0x00010006,
  771. 0x9150, 0xffffffff, 0x6e944040,
  772. 0x917c, 0xffffffff, 0x00030002,
  773. 0x9198, 0xffffffff, 0x00030002,
  774. 0x915c, 0xffffffff, 0x00010000,
  775. 0x3f90, 0xffff0000, 0xff000000,
  776. 0x9178, 0xffffffff, 0x00070000,
  777. 0x9194, 0xffffffff, 0x00070000,
  778. 0x9148, 0xffff0000, 0xff000000,
  779. 0x9190, 0xffffffff, 0x00090008,
  780. 0x91ac, 0xffffffff, 0x00090008,
  781. 0x3f94, 0xffff0000, 0xff000000,
  782. 0x914c, 0xffff0000, 0xff000000,
  783. 0x929c, 0xffffffff, 0x00000001,
  784. 0x8a18, 0xffffffff, 0x00000100,
  785. 0x8b28, 0xffffffff, 0x00000100,
  786. 0x9144, 0xffffffff, 0x00000100,
  787. 0x9b7c, 0xffffffff, 0x00000000,
  788. 0x8030, 0xffffffff, 0x0000100a,
  789. 0x8a14, 0xffffffff, 0x00000001,
  790. 0x8b24, 0xffffffff, 0x00ff0fff,
  791. 0x8b10, 0xffffffff, 0x00000000,
  792. 0x28a4c, 0x06000000, 0x06000000,
  793. 0x4d8, 0xffffffff, 0x00000100,
  794. 0x913c, 0xffff000f, 0x0100000a,
  795. 0x960c, 0xffffffff, 0x54763210,
  796. 0x88c4, 0xffffffff, 0x000000c2,
  797. 0x88d4, 0xffffffff, 0x00000010,
  798. 0x8974, 0xffffffff, 0x00000000,
  799. 0xc78, 0x00000080, 0x00000080,
  800. 0x5e78, 0xffffffff, 0x001000f0,
  801. 0xd02c, 0xffffffff, 0x08421000,
  802. 0xa008, 0xffffffff, 0x00010000,
  803. 0x8d00, 0xffffffff, 0x100e4848,
  804. 0x8d04, 0xffffffff, 0x00164745,
  805. 0x8c00, 0xffffffff, 0xe4000003,
  806. 0x8cf0, 0x1fffffff, 0x08e00410,
  807. 0x28350, 0xffffffff, 0x00000000,
  808. 0x9508, 0xffffffff, 0x00000002,
  809. 0x900c, 0xffffffff, 0x0017071f,
  810. 0x8c18, 0xffffffff, 0x10101060,
  811. 0x8c1c, 0xffffffff, 0x00001010
  812. };
  813. static const u32 barts_golden_registers[] =
  814. {
  815. 0x5eb4, 0xffffffff, 0x00000002,
  816. 0x5e78, 0x8f311ff1, 0x001000f0,
  817. 0x3f90, 0xffff0000, 0xff000000,
  818. 0x9148, 0xffff0000, 0xff000000,
  819. 0x3f94, 0xffff0000, 0xff000000,
  820. 0x914c, 0xffff0000, 0xff000000,
  821. 0xc78, 0x00000080, 0x00000080,
  822. 0xbd4, 0x70073777, 0x00010001,
  823. 0xd02c, 0xbfffff1f, 0x08421000,
  824. 0xd0b8, 0x03773777, 0x02011003,
  825. 0x5bc0, 0x00200000, 0x50100000,
  826. 0x98f8, 0x33773777, 0x02011003,
  827. 0x98fc, 0xffffffff, 0x76543210,
  828. 0x7030, 0x31000311, 0x00000011,
  829. 0x2f48, 0x00000007, 0x02011003,
  830. 0x6b28, 0x00000010, 0x00000012,
  831. 0x7728, 0x00000010, 0x00000012,
  832. 0x10328, 0x00000010, 0x00000012,
  833. 0x10f28, 0x00000010, 0x00000012,
  834. 0x11b28, 0x00000010, 0x00000012,
  835. 0x12728, 0x00000010, 0x00000012,
  836. 0x240c, 0x000007ff, 0x00000380,
  837. 0x8a14, 0xf000001f, 0x00000007,
  838. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  839. 0x8b10, 0x0000ff0f, 0x00000000,
  840. 0x28a4c, 0x07ffffff, 0x06000000,
  841. 0x10c, 0x00000001, 0x00010003,
  842. 0xa02c, 0xffffffff, 0x0000009b,
  843. 0x913c, 0x0000000f, 0x0100000a,
  844. 0x8d00, 0xffff7f7f, 0x100e4848,
  845. 0x8d04, 0x00ffffff, 0x00164745,
  846. 0x8c00, 0xfffc0003, 0xe4000003,
  847. 0x8c04, 0xf8ff00ff, 0x40600060,
  848. 0x8c08, 0x00ff00ff, 0x001c001c,
  849. 0x8cf0, 0x1fff1fff, 0x08e00620,
  850. 0x8c20, 0x0fff0fff, 0x00800080,
  851. 0x8c24, 0x0fff0fff, 0x00800080,
  852. 0x8c18, 0xffffffff, 0x20202078,
  853. 0x8c1c, 0x0000ffff, 0x00001010,
  854. 0x28350, 0x00000f01, 0x00000000,
  855. 0x9508, 0x3700001f, 0x00000002,
  856. 0x960c, 0xffffffff, 0x54763210,
  857. 0x88c4, 0x001f3ae3, 0x000000c2,
  858. 0x88d4, 0x0000001f, 0x00000010,
  859. 0x8974, 0xffffffff, 0x00000000
  860. };
  861. static const u32 turks_golden_registers[] =
  862. {
  863. 0x5eb4, 0xffffffff, 0x00000002,
  864. 0x5e78, 0x8f311ff1, 0x001000f0,
  865. 0x8c8, 0x00003000, 0x00001070,
  866. 0x8cc, 0x000fffff, 0x00040035,
  867. 0x3f90, 0xffff0000, 0xfff00000,
  868. 0x9148, 0xffff0000, 0xfff00000,
  869. 0x3f94, 0xffff0000, 0xfff00000,
  870. 0x914c, 0xffff0000, 0xfff00000,
  871. 0xc78, 0x00000080, 0x00000080,
  872. 0xbd4, 0x00073007, 0x00010002,
  873. 0xd02c, 0xbfffff1f, 0x08421000,
  874. 0xd0b8, 0x03773777, 0x02010002,
  875. 0x5bc0, 0x00200000, 0x50100000,
  876. 0x98f8, 0x33773777, 0x00010002,
  877. 0x98fc, 0xffffffff, 0x33221100,
  878. 0x7030, 0x31000311, 0x00000011,
  879. 0x2f48, 0x33773777, 0x00010002,
  880. 0x6b28, 0x00000010, 0x00000012,
  881. 0x7728, 0x00000010, 0x00000012,
  882. 0x10328, 0x00000010, 0x00000012,
  883. 0x10f28, 0x00000010, 0x00000012,
  884. 0x11b28, 0x00000010, 0x00000012,
  885. 0x12728, 0x00000010, 0x00000012,
  886. 0x240c, 0x000007ff, 0x00000380,
  887. 0x8a14, 0xf000001f, 0x00000007,
  888. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  889. 0x8b10, 0x0000ff0f, 0x00000000,
  890. 0x28a4c, 0x07ffffff, 0x06000000,
  891. 0x10c, 0x00000001, 0x00010003,
  892. 0xa02c, 0xffffffff, 0x0000009b,
  893. 0x913c, 0x0000000f, 0x0100000a,
  894. 0x8d00, 0xffff7f7f, 0x100e4848,
  895. 0x8d04, 0x00ffffff, 0x00164745,
  896. 0x8c00, 0xfffc0003, 0xe4000003,
  897. 0x8c04, 0xf8ff00ff, 0x40600060,
  898. 0x8c08, 0x00ff00ff, 0x001c001c,
  899. 0x8cf0, 0x1fff1fff, 0x08e00410,
  900. 0x8c20, 0x0fff0fff, 0x00800080,
  901. 0x8c24, 0x0fff0fff, 0x00800080,
  902. 0x8c18, 0xffffffff, 0x20202078,
  903. 0x8c1c, 0x0000ffff, 0x00001010,
  904. 0x28350, 0x00000f01, 0x00000000,
  905. 0x9508, 0x3700001f, 0x00000002,
  906. 0x960c, 0xffffffff, 0x54763210,
  907. 0x88c4, 0x001f3ae3, 0x000000c2,
  908. 0x88d4, 0x0000001f, 0x00000010,
  909. 0x8974, 0xffffffff, 0x00000000
  910. };
  911. static const u32 caicos_golden_registers[] =
  912. {
  913. 0x5eb4, 0xffffffff, 0x00000002,
  914. 0x5e78, 0x8f311ff1, 0x001000f0,
  915. 0x8c8, 0x00003420, 0x00001450,
  916. 0x8cc, 0x000fffff, 0x00040035,
  917. 0x3f90, 0xffff0000, 0xfffc0000,
  918. 0x9148, 0xffff0000, 0xfffc0000,
  919. 0x3f94, 0xffff0000, 0xfffc0000,
  920. 0x914c, 0xffff0000, 0xfffc0000,
  921. 0xc78, 0x00000080, 0x00000080,
  922. 0xbd4, 0x00073007, 0x00010001,
  923. 0xd02c, 0xbfffff1f, 0x08421000,
  924. 0xd0b8, 0x03773777, 0x02010001,
  925. 0x5bc0, 0x00200000, 0x50100000,
  926. 0x98f8, 0x33773777, 0x02010001,
  927. 0x98fc, 0xffffffff, 0x33221100,
  928. 0x7030, 0x31000311, 0x00000011,
  929. 0x2f48, 0x33773777, 0x02010001,
  930. 0x6b28, 0x00000010, 0x00000012,
  931. 0x7728, 0x00000010, 0x00000012,
  932. 0x10328, 0x00000010, 0x00000012,
  933. 0x10f28, 0x00000010, 0x00000012,
  934. 0x11b28, 0x00000010, 0x00000012,
  935. 0x12728, 0x00000010, 0x00000012,
  936. 0x240c, 0x000007ff, 0x00000380,
  937. 0x8a14, 0xf000001f, 0x00000001,
  938. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  939. 0x8b10, 0x0000ff0f, 0x00000000,
  940. 0x28a4c, 0x07ffffff, 0x06000000,
  941. 0x10c, 0x00000001, 0x00010003,
  942. 0xa02c, 0xffffffff, 0x0000009b,
  943. 0x913c, 0x0000000f, 0x0100000a,
  944. 0x8d00, 0xffff7f7f, 0x100e4848,
  945. 0x8d04, 0x00ffffff, 0x00164745,
  946. 0x8c00, 0xfffc0003, 0xe4000003,
  947. 0x8c04, 0xf8ff00ff, 0x40600060,
  948. 0x8c08, 0x00ff00ff, 0x001c001c,
  949. 0x8cf0, 0x1fff1fff, 0x08e00410,
  950. 0x8c20, 0x0fff0fff, 0x00800080,
  951. 0x8c24, 0x0fff0fff, 0x00800080,
  952. 0x8c18, 0xffffffff, 0x20202078,
  953. 0x8c1c, 0x0000ffff, 0x00001010,
  954. 0x28350, 0x00000f01, 0x00000000,
  955. 0x9508, 0x3700001f, 0x00000002,
  956. 0x960c, 0xffffffff, 0x54763210,
  957. 0x88c4, 0x001f3ae3, 0x000000c2,
  958. 0x88d4, 0x0000001f, 0x00000010,
  959. 0x8974, 0xffffffff, 0x00000000
  960. };
  961. static void evergreen_init_golden_registers(struct radeon_device *rdev)
  962. {
  963. switch (rdev->family) {
  964. case CHIP_CYPRESS:
  965. case CHIP_HEMLOCK:
  966. radeon_program_register_sequence(rdev,
  967. evergreen_golden_registers,
  968. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  969. radeon_program_register_sequence(rdev,
  970. evergreen_golden_registers2,
  971. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  972. radeon_program_register_sequence(rdev,
  973. cypress_mgcg_init,
  974. (const u32)ARRAY_SIZE(cypress_mgcg_init));
  975. break;
  976. case CHIP_JUNIPER:
  977. radeon_program_register_sequence(rdev,
  978. evergreen_golden_registers,
  979. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  980. radeon_program_register_sequence(rdev,
  981. evergreen_golden_registers2,
  982. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  983. radeon_program_register_sequence(rdev,
  984. juniper_mgcg_init,
  985. (const u32)ARRAY_SIZE(juniper_mgcg_init));
  986. break;
  987. case CHIP_REDWOOD:
  988. radeon_program_register_sequence(rdev,
  989. evergreen_golden_registers,
  990. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  991. radeon_program_register_sequence(rdev,
  992. evergreen_golden_registers2,
  993. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  994. radeon_program_register_sequence(rdev,
  995. redwood_mgcg_init,
  996. (const u32)ARRAY_SIZE(redwood_mgcg_init));
  997. break;
  998. case CHIP_CEDAR:
  999. radeon_program_register_sequence(rdev,
  1000. cedar_golden_registers,
  1001. (const u32)ARRAY_SIZE(cedar_golden_registers));
  1002. radeon_program_register_sequence(rdev,
  1003. evergreen_golden_registers2,
  1004. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  1005. radeon_program_register_sequence(rdev,
  1006. cedar_mgcg_init,
  1007. (const u32)ARRAY_SIZE(cedar_mgcg_init));
  1008. break;
  1009. case CHIP_PALM:
  1010. radeon_program_register_sequence(rdev,
  1011. wrestler_golden_registers,
  1012. (const u32)ARRAY_SIZE(wrestler_golden_registers));
  1013. break;
  1014. case CHIP_SUMO:
  1015. radeon_program_register_sequence(rdev,
  1016. supersumo_golden_registers,
  1017. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1018. break;
  1019. case CHIP_SUMO2:
  1020. radeon_program_register_sequence(rdev,
  1021. supersumo_golden_registers,
  1022. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1023. radeon_program_register_sequence(rdev,
  1024. sumo_golden_registers,
  1025. (const u32)ARRAY_SIZE(sumo_golden_registers));
  1026. break;
  1027. case CHIP_BARTS:
  1028. radeon_program_register_sequence(rdev,
  1029. barts_golden_registers,
  1030. (const u32)ARRAY_SIZE(barts_golden_registers));
  1031. break;
  1032. case CHIP_TURKS:
  1033. radeon_program_register_sequence(rdev,
  1034. turks_golden_registers,
  1035. (const u32)ARRAY_SIZE(turks_golden_registers));
  1036. break;
  1037. case CHIP_CAICOS:
  1038. radeon_program_register_sequence(rdev,
  1039. caicos_golden_registers,
  1040. (const u32)ARRAY_SIZE(caicos_golden_registers));
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. }
  1046. /**
  1047. * evergreen_get_allowed_info_register - fetch the register for the info ioctl
  1048. *
  1049. * @rdev: radeon_device pointer
  1050. * @reg: register offset in bytes
  1051. * @val: register value
  1052. *
  1053. * Returns 0 for success or -EINVAL for an invalid register
  1054. *
  1055. */
  1056. int evergreen_get_allowed_info_register(struct radeon_device *rdev,
  1057. u32 reg, u32 *val)
  1058. {
  1059. switch (reg) {
  1060. case GRBM_STATUS:
  1061. case GRBM_STATUS_SE0:
  1062. case GRBM_STATUS_SE1:
  1063. case SRBM_STATUS:
  1064. case SRBM_STATUS2:
  1065. case DMA_STATUS_REG:
  1066. case UVD_STATUS:
  1067. *val = RREG32(reg);
  1068. return 0;
  1069. default:
  1070. return -EINVAL;
  1071. }
  1072. }
  1073. void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  1074. unsigned *bankh, unsigned *mtaspect,
  1075. unsigned *tile_split)
  1076. {
  1077. *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
  1078. *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
  1079. *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
  1080. *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
  1081. switch (*bankw) {
  1082. default:
  1083. case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
  1084. case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
  1085. case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
  1086. case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
  1087. }
  1088. switch (*bankh) {
  1089. default:
  1090. case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
  1091. case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
  1092. case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
  1093. case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
  1094. }
  1095. switch (*mtaspect) {
  1096. default:
  1097. case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
  1098. case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
  1099. case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
  1100. case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
  1101. }
  1102. }
  1103. static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  1104. u32 cntl_reg, u32 status_reg)
  1105. {
  1106. int r, i;
  1107. struct atom_clock_dividers dividers;
  1108. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1109. clock, false, &dividers);
  1110. if (r)
  1111. return r;
  1112. WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
  1113. for (i = 0; i < 100; i++) {
  1114. if (RREG32(status_reg) & DCLK_STATUS)
  1115. break;
  1116. mdelay(10);
  1117. }
  1118. if (i == 100)
  1119. return -ETIMEDOUT;
  1120. return 0;
  1121. }
  1122. int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1123. {
  1124. int r = 0;
  1125. u32 cg_scratch = RREG32(CG_SCRATCH1);
  1126. r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  1127. if (r)
  1128. goto done;
  1129. cg_scratch &= 0xffff0000;
  1130. cg_scratch |= vclk / 100; /* Mhz */
  1131. r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  1132. if (r)
  1133. goto done;
  1134. cg_scratch &= 0x0000ffff;
  1135. cg_scratch |= (dclk / 100) << 16; /* Mhz */
  1136. done:
  1137. WREG32(CG_SCRATCH1, cg_scratch);
  1138. return r;
  1139. }
  1140. int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1141. {
  1142. /* start off with something large */
  1143. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  1144. int r;
  1145. /* bypass vclk and dclk with bclk */
  1146. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1147. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  1148. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1149. /* put PLL in bypass mode */
  1150. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  1151. if (!vclk || !dclk) {
  1152. /* keep the Bypass mode, put PLL to sleep */
  1153. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1154. return 0;
  1155. }
  1156. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  1157. 16384, 0x03FFFFFF, 0, 128, 5,
  1158. &fb_div, &vclk_div, &dclk_div);
  1159. if (r)
  1160. return r;
  1161. /* set VCO_MODE to 1 */
  1162. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  1163. /* toggle UPLL_SLEEP to 1 then back to 0 */
  1164. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1165. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  1166. /* deassert UPLL_RESET */
  1167. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1168. mdelay(1);
  1169. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1170. if (r)
  1171. return r;
  1172. /* assert UPLL_RESET again */
  1173. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  1174. /* disable spread spectrum. */
  1175. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  1176. /* set feedback divider */
  1177. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  1178. /* set ref divider to 0 */
  1179. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  1180. if (fb_div < 307200)
  1181. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  1182. else
  1183. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  1184. /* set PDIV_A and PDIV_B */
  1185. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1186. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  1187. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  1188. /* give the PLL some time to settle */
  1189. mdelay(15);
  1190. /* deassert PLL_RESET */
  1191. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1192. mdelay(15);
  1193. /* switch from bypass mode to normal mode */
  1194. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  1195. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1196. if (r)
  1197. return r;
  1198. /* switch VCLK and DCLK selection */
  1199. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1200. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  1201. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1202. mdelay(100);
  1203. return 0;
  1204. }
  1205. void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
  1206. {
  1207. int readrq;
  1208. u16 v;
  1209. readrq = pcie_get_readrq(rdev->pdev);
  1210. v = ffs(readrq) - 8;
  1211. /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
  1212. * to avoid hangs or perfomance issues
  1213. */
  1214. if ((v == 0) || (v == 6) || (v == 7))
  1215. pcie_set_readrq(rdev->pdev, 512);
  1216. }
  1217. void dce4_program_fmt(struct drm_encoder *encoder)
  1218. {
  1219. struct drm_device *dev = encoder->dev;
  1220. struct radeon_device *rdev = dev->dev_private;
  1221. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1222. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1223. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1224. int bpc = 0;
  1225. u32 tmp = 0;
  1226. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  1227. if (connector) {
  1228. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1229. bpc = radeon_get_monitor_bpc(connector);
  1230. dither = radeon_connector->dither;
  1231. }
  1232. /* LVDS/eDP FMT is set up by atom */
  1233. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  1234. return;
  1235. /* not needed for analog */
  1236. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  1237. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  1238. return;
  1239. if (bpc == 0)
  1240. return;
  1241. switch (bpc) {
  1242. case 6:
  1243. if (dither == RADEON_FMT_DITHER_ENABLE)
  1244. /* XXX sort out optimal dither settings */
  1245. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1246. FMT_SPATIAL_DITHER_EN);
  1247. else
  1248. tmp |= FMT_TRUNCATE_EN;
  1249. break;
  1250. case 8:
  1251. if (dither == RADEON_FMT_DITHER_ENABLE)
  1252. /* XXX sort out optimal dither settings */
  1253. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1254. FMT_RGB_RANDOM_ENABLE |
  1255. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
  1256. else
  1257. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
  1258. break;
  1259. case 10:
  1260. default:
  1261. /* not needed */
  1262. break;
  1263. }
  1264. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  1265. }
  1266. static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
  1267. {
  1268. if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
  1269. return true;
  1270. else
  1271. return false;
  1272. }
  1273. static bool dce4_is_counter_moving(struct radeon_device *rdev, int crtc)
  1274. {
  1275. u32 pos1, pos2;
  1276. pos1 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1277. pos2 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1278. if (pos1 != pos2)
  1279. return true;
  1280. else
  1281. return false;
  1282. }
  1283. /**
  1284. * dce4_wait_for_vblank - vblank wait asic callback.
  1285. *
  1286. * @rdev: radeon_device pointer
  1287. * @crtc: crtc to wait for vblank on
  1288. *
  1289. * Wait for vblank on the requested crtc (evergreen+).
  1290. */
  1291. void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
  1292. {
  1293. unsigned i = 0;
  1294. if (crtc >= rdev->num_crtc)
  1295. return;
  1296. if (!(RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN))
  1297. return;
  1298. /* depending on when we hit vblank, we may be close to active; if so,
  1299. * wait for another frame.
  1300. */
  1301. while (dce4_is_in_vblank(rdev, crtc)) {
  1302. if (i++ % 100 == 0) {
  1303. if (!dce4_is_counter_moving(rdev, crtc))
  1304. break;
  1305. }
  1306. }
  1307. while (!dce4_is_in_vblank(rdev, crtc)) {
  1308. if (i++ % 100 == 0) {
  1309. if (!dce4_is_counter_moving(rdev, crtc))
  1310. break;
  1311. }
  1312. }
  1313. }
  1314. /**
  1315. * evergreen_page_flip - pageflip callback.
  1316. *
  1317. * @rdev: radeon_device pointer
  1318. * @crtc_id: crtc to cleanup pageflip on
  1319. * @crtc_base: new address of the crtc (GPU MC address)
  1320. *
  1321. * Triggers the actual pageflip by updating the primary
  1322. * surface base address (evergreen+).
  1323. */
  1324. void evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base,
  1325. bool async)
  1326. {
  1327. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1328. /* update the scanout addresses */
  1329. WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset,
  1330. async ? EVERGREEN_GRPH_SURFACE_UPDATE_H_RETRACE_EN : 0);
  1331. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1332. upper_32_bits(crtc_base));
  1333. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1334. (u32)crtc_base);
  1335. /* post the write */
  1336. RREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset);
  1337. }
  1338. /**
  1339. * evergreen_page_flip_pending - check if page flip is still pending
  1340. *
  1341. * @rdev: radeon_device pointer
  1342. * @crtc_id: crtc to check
  1343. *
  1344. * Returns the current update pending status.
  1345. */
  1346. bool evergreen_page_flip_pending(struct radeon_device *rdev, int crtc_id)
  1347. {
  1348. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1349. /* Return current update_pending status: */
  1350. return !!(RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) &
  1351. EVERGREEN_GRPH_SURFACE_UPDATE_PENDING);
  1352. }
  1353. /* get temperature in millidegrees */
  1354. int evergreen_get_temp(struct radeon_device *rdev)
  1355. {
  1356. u32 temp, toffset;
  1357. int actual_temp = 0;
  1358. if (rdev->family == CHIP_JUNIPER) {
  1359. toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
  1360. TOFFSET_SHIFT;
  1361. temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
  1362. TS0_ADC_DOUT_SHIFT;
  1363. if (toffset & 0x100)
  1364. actual_temp = temp / 2 - (0x200 - toffset);
  1365. else
  1366. actual_temp = temp / 2 + toffset;
  1367. actual_temp = actual_temp * 1000;
  1368. } else {
  1369. temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  1370. ASIC_T_SHIFT;
  1371. if (temp & 0x400)
  1372. actual_temp = -256;
  1373. else if (temp & 0x200)
  1374. actual_temp = 255;
  1375. else if (temp & 0x100) {
  1376. actual_temp = temp & 0x1ff;
  1377. actual_temp |= ~0x1ff;
  1378. } else
  1379. actual_temp = temp & 0xff;
  1380. actual_temp = (actual_temp * 1000) / 2;
  1381. }
  1382. return actual_temp;
  1383. }
  1384. int sumo_get_temp(struct radeon_device *rdev)
  1385. {
  1386. u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
  1387. int actual_temp = temp - 49;
  1388. return actual_temp * 1000;
  1389. }
  1390. /**
  1391. * sumo_pm_init_profile - Initialize power profiles callback.
  1392. *
  1393. * @rdev: radeon_device pointer
  1394. *
  1395. * Initialize the power states used in profile mode
  1396. * (sumo, trinity, SI).
  1397. * Used for profile mode only.
  1398. */
  1399. void sumo_pm_init_profile(struct radeon_device *rdev)
  1400. {
  1401. int idx;
  1402. /* default */
  1403. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1404. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1405. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1406. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  1407. /* low,mid sh/mh */
  1408. if (rdev->flags & RADEON_IS_MOBILITY)
  1409. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1410. else
  1411. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1412. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1413. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1414. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1415. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1416. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1417. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1418. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1419. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1420. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1421. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1422. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1423. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  1424. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1425. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1426. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1427. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  1428. /* high sh/mh */
  1429. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1430. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1431. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1432. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1433. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
  1434. rdev->pm.power_state[idx].num_clock_modes - 1;
  1435. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1436. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1437. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1438. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
  1439. rdev->pm.power_state[idx].num_clock_modes - 1;
  1440. }
  1441. /**
  1442. * btc_pm_init_profile - Initialize power profiles callback.
  1443. *
  1444. * @rdev: radeon_device pointer
  1445. *
  1446. * Initialize the power states used in profile mode
  1447. * (BTC, cayman).
  1448. * Used for profile mode only.
  1449. */
  1450. void btc_pm_init_profile(struct radeon_device *rdev)
  1451. {
  1452. int idx;
  1453. /* default */
  1454. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1455. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1456. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1457. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  1458. /* starting with BTC, there is one state that is used for both
  1459. * MH and SH. Difference is that we always use the high clock index for
  1460. * mclk.
  1461. */
  1462. if (rdev->flags & RADEON_IS_MOBILITY)
  1463. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1464. else
  1465. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1466. /* low sh */
  1467. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1468. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1469. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1470. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1471. /* mid sh */
  1472. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1473. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1474. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1475. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  1476. /* high sh */
  1477. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1478. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1479. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1480. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  1481. /* low mh */
  1482. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1483. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1484. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1485. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1486. /* mid mh */
  1487. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1488. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1489. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1490. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  1491. /* high mh */
  1492. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1493. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1494. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1495. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  1496. }
  1497. /**
  1498. * evergreen_pm_misc - set additional pm hw parameters callback.
  1499. *
  1500. * @rdev: radeon_device pointer
  1501. *
  1502. * Set non-clock parameters associated with a power state
  1503. * (voltage, etc.) (evergreen+).
  1504. */
  1505. void evergreen_pm_misc(struct radeon_device *rdev)
  1506. {
  1507. int req_ps_idx = rdev->pm.requested_power_state_index;
  1508. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  1509. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  1510. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  1511. if (voltage->type == VOLTAGE_SW) {
  1512. /* 0xff0x are flags rather then an actual voltage */
  1513. if ((voltage->voltage & 0xff00) == 0xff00)
  1514. return;
  1515. if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
  1516. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  1517. rdev->pm.current_vddc = voltage->voltage;
  1518. DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
  1519. }
  1520. /* starting with BTC, there is one state that is used for both
  1521. * MH and SH. Difference is that we always use the high clock index for
  1522. * mclk and vddci.
  1523. */
  1524. if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
  1525. (rdev->family >= CHIP_BARTS) &&
  1526. rdev->pm.active_crtc_count &&
  1527. ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
  1528. (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
  1529. voltage = &rdev->pm.power_state[req_ps_idx].
  1530. clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
  1531. /* 0xff0x are flags rather then an actual voltage */
  1532. if ((voltage->vddci & 0xff00) == 0xff00)
  1533. return;
  1534. if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
  1535. radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
  1536. rdev->pm.current_vddci = voltage->vddci;
  1537. DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
  1538. }
  1539. }
  1540. }
  1541. /**
  1542. * evergreen_pm_prepare - pre-power state change callback.
  1543. *
  1544. * @rdev: radeon_device pointer
  1545. *
  1546. * Prepare for a power state change (evergreen+).
  1547. */
  1548. void evergreen_pm_prepare(struct radeon_device *rdev)
  1549. {
  1550. struct drm_device *ddev = rdev->ddev;
  1551. struct drm_crtc *crtc;
  1552. struct radeon_crtc *radeon_crtc;
  1553. u32 tmp;
  1554. /* disable any active CRTCs */
  1555. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1556. radeon_crtc = to_radeon_crtc(crtc);
  1557. if (radeon_crtc->enabled) {
  1558. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1559. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1560. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1561. }
  1562. }
  1563. }
  1564. /**
  1565. * evergreen_pm_finish - post-power state change callback.
  1566. *
  1567. * @rdev: radeon_device pointer
  1568. *
  1569. * Clean up after a power state change (evergreen+).
  1570. */
  1571. void evergreen_pm_finish(struct radeon_device *rdev)
  1572. {
  1573. struct drm_device *ddev = rdev->ddev;
  1574. struct drm_crtc *crtc;
  1575. struct radeon_crtc *radeon_crtc;
  1576. u32 tmp;
  1577. /* enable any active CRTCs */
  1578. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1579. radeon_crtc = to_radeon_crtc(crtc);
  1580. if (radeon_crtc->enabled) {
  1581. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1582. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1583. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1584. }
  1585. }
  1586. }
  1587. /**
  1588. * evergreen_hpd_sense - hpd sense callback.
  1589. *
  1590. * @rdev: radeon_device pointer
  1591. * @hpd: hpd (hotplug detect) pin
  1592. *
  1593. * Checks if a digital monitor is connected (evergreen+).
  1594. * Returns true if connected, false if not connected.
  1595. */
  1596. bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  1597. {
  1598. bool connected = false;
  1599. switch (hpd) {
  1600. case RADEON_HPD_1:
  1601. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  1602. connected = true;
  1603. break;
  1604. case RADEON_HPD_2:
  1605. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  1606. connected = true;
  1607. break;
  1608. case RADEON_HPD_3:
  1609. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  1610. connected = true;
  1611. break;
  1612. case RADEON_HPD_4:
  1613. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  1614. connected = true;
  1615. break;
  1616. case RADEON_HPD_5:
  1617. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  1618. connected = true;
  1619. break;
  1620. case RADEON_HPD_6:
  1621. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  1622. connected = true;
  1623. break;
  1624. default:
  1625. break;
  1626. }
  1627. return connected;
  1628. }
  1629. /**
  1630. * evergreen_hpd_set_polarity - hpd set polarity callback.
  1631. *
  1632. * @rdev: radeon_device pointer
  1633. * @hpd: hpd (hotplug detect) pin
  1634. *
  1635. * Set the polarity of the hpd pin (evergreen+).
  1636. */
  1637. void evergreen_hpd_set_polarity(struct radeon_device *rdev,
  1638. enum radeon_hpd_id hpd)
  1639. {
  1640. u32 tmp;
  1641. bool connected = evergreen_hpd_sense(rdev, hpd);
  1642. switch (hpd) {
  1643. case RADEON_HPD_1:
  1644. tmp = RREG32(DC_HPD1_INT_CONTROL);
  1645. if (connected)
  1646. tmp &= ~DC_HPDx_INT_POLARITY;
  1647. else
  1648. tmp |= DC_HPDx_INT_POLARITY;
  1649. WREG32(DC_HPD1_INT_CONTROL, tmp);
  1650. break;
  1651. case RADEON_HPD_2:
  1652. tmp = RREG32(DC_HPD2_INT_CONTROL);
  1653. if (connected)
  1654. tmp &= ~DC_HPDx_INT_POLARITY;
  1655. else
  1656. tmp |= DC_HPDx_INT_POLARITY;
  1657. WREG32(DC_HPD2_INT_CONTROL, tmp);
  1658. break;
  1659. case RADEON_HPD_3:
  1660. tmp = RREG32(DC_HPD3_INT_CONTROL);
  1661. if (connected)
  1662. tmp &= ~DC_HPDx_INT_POLARITY;
  1663. else
  1664. tmp |= DC_HPDx_INT_POLARITY;
  1665. WREG32(DC_HPD3_INT_CONTROL, tmp);
  1666. break;
  1667. case RADEON_HPD_4:
  1668. tmp = RREG32(DC_HPD4_INT_CONTROL);
  1669. if (connected)
  1670. tmp &= ~DC_HPDx_INT_POLARITY;
  1671. else
  1672. tmp |= DC_HPDx_INT_POLARITY;
  1673. WREG32(DC_HPD4_INT_CONTROL, tmp);
  1674. break;
  1675. case RADEON_HPD_5:
  1676. tmp = RREG32(DC_HPD5_INT_CONTROL);
  1677. if (connected)
  1678. tmp &= ~DC_HPDx_INT_POLARITY;
  1679. else
  1680. tmp |= DC_HPDx_INT_POLARITY;
  1681. WREG32(DC_HPD5_INT_CONTROL, tmp);
  1682. break;
  1683. case RADEON_HPD_6:
  1684. tmp = RREG32(DC_HPD6_INT_CONTROL);
  1685. if (connected)
  1686. tmp &= ~DC_HPDx_INT_POLARITY;
  1687. else
  1688. tmp |= DC_HPDx_INT_POLARITY;
  1689. WREG32(DC_HPD6_INT_CONTROL, tmp);
  1690. break;
  1691. default:
  1692. break;
  1693. }
  1694. }
  1695. /**
  1696. * evergreen_hpd_init - hpd setup callback.
  1697. *
  1698. * @rdev: radeon_device pointer
  1699. *
  1700. * Setup the hpd pins used by the card (evergreen+).
  1701. * Enable the pin, set the polarity, and enable the hpd interrupts.
  1702. */
  1703. void evergreen_hpd_init(struct radeon_device *rdev)
  1704. {
  1705. struct drm_device *dev = rdev->ddev;
  1706. struct drm_connector *connector;
  1707. unsigned enabled = 0;
  1708. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
  1709. DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
  1710. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1711. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1712. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  1713. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  1714. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  1715. * aux dp channel on imac and help (but not completely fix)
  1716. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  1717. * also avoid interrupt storms during dpms.
  1718. */
  1719. continue;
  1720. }
  1721. switch (radeon_connector->hpd.hpd) {
  1722. case RADEON_HPD_1:
  1723. WREG32(DC_HPD1_CONTROL, tmp);
  1724. break;
  1725. case RADEON_HPD_2:
  1726. WREG32(DC_HPD2_CONTROL, tmp);
  1727. break;
  1728. case RADEON_HPD_3:
  1729. WREG32(DC_HPD3_CONTROL, tmp);
  1730. break;
  1731. case RADEON_HPD_4:
  1732. WREG32(DC_HPD4_CONTROL, tmp);
  1733. break;
  1734. case RADEON_HPD_5:
  1735. WREG32(DC_HPD5_CONTROL, tmp);
  1736. break;
  1737. case RADEON_HPD_6:
  1738. WREG32(DC_HPD6_CONTROL, tmp);
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  1744. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  1745. enabled |= 1 << radeon_connector->hpd.hpd;
  1746. }
  1747. radeon_irq_kms_enable_hpd(rdev, enabled);
  1748. }
  1749. /**
  1750. * evergreen_hpd_fini - hpd tear down callback.
  1751. *
  1752. * @rdev: radeon_device pointer
  1753. *
  1754. * Tear down the hpd pins used by the card (evergreen+).
  1755. * Disable the hpd interrupts.
  1756. */
  1757. void evergreen_hpd_fini(struct radeon_device *rdev)
  1758. {
  1759. struct drm_device *dev = rdev->ddev;
  1760. struct drm_connector *connector;
  1761. unsigned disabled = 0;
  1762. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1763. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1764. switch (radeon_connector->hpd.hpd) {
  1765. case RADEON_HPD_1:
  1766. WREG32(DC_HPD1_CONTROL, 0);
  1767. break;
  1768. case RADEON_HPD_2:
  1769. WREG32(DC_HPD2_CONTROL, 0);
  1770. break;
  1771. case RADEON_HPD_3:
  1772. WREG32(DC_HPD3_CONTROL, 0);
  1773. break;
  1774. case RADEON_HPD_4:
  1775. WREG32(DC_HPD4_CONTROL, 0);
  1776. break;
  1777. case RADEON_HPD_5:
  1778. WREG32(DC_HPD5_CONTROL, 0);
  1779. break;
  1780. case RADEON_HPD_6:
  1781. WREG32(DC_HPD6_CONTROL, 0);
  1782. break;
  1783. default:
  1784. break;
  1785. }
  1786. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  1787. disabled |= 1 << radeon_connector->hpd.hpd;
  1788. }
  1789. radeon_irq_kms_disable_hpd(rdev, disabled);
  1790. }
  1791. /* watermark setup */
  1792. static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
  1793. struct radeon_crtc *radeon_crtc,
  1794. struct drm_display_mode *mode,
  1795. struct drm_display_mode *other_mode)
  1796. {
  1797. u32 tmp, buffer_alloc, i;
  1798. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1799. /*
  1800. * Line Buffer Setup
  1801. * There are 3 line buffers, each one shared by 2 display controllers.
  1802. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1803. * the display controllers. The paritioning is done via one of four
  1804. * preset allocations specified in bits 2:0:
  1805. * first display controller
  1806. * 0 - first half of lb (3840 * 2)
  1807. * 1 - first 3/4 of lb (5760 * 2)
  1808. * 2 - whole lb (7680 * 2), other crtc must be disabled
  1809. * 3 - first 1/4 of lb (1920 * 2)
  1810. * second display controller
  1811. * 4 - second half of lb (3840 * 2)
  1812. * 5 - second 3/4 of lb (5760 * 2)
  1813. * 6 - whole lb (7680 * 2), other crtc must be disabled
  1814. * 7 - last 1/4 of lb (1920 * 2)
  1815. */
  1816. /* this can get tricky if we have two large displays on a paired group
  1817. * of crtcs. Ideally for multiple large displays we'd assign them to
  1818. * non-linked crtcs for maximum line buffer allocation.
  1819. */
  1820. if (radeon_crtc->base.enabled && mode) {
  1821. if (other_mode) {
  1822. tmp = 0; /* 1/2 */
  1823. buffer_alloc = 1;
  1824. } else {
  1825. tmp = 2; /* whole */
  1826. buffer_alloc = 2;
  1827. }
  1828. } else {
  1829. tmp = 0;
  1830. buffer_alloc = 0;
  1831. }
  1832. /* second controller of the pair uses second half of the lb */
  1833. if (radeon_crtc->crtc_id % 2)
  1834. tmp += 4;
  1835. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
  1836. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1837. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1838. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1839. for (i = 0; i < rdev->usec_timeout; i++) {
  1840. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1841. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1842. break;
  1843. udelay(1);
  1844. }
  1845. }
  1846. if (radeon_crtc->base.enabled && mode) {
  1847. switch (tmp) {
  1848. case 0:
  1849. case 4:
  1850. default:
  1851. if (ASIC_IS_DCE5(rdev))
  1852. return 4096 * 2;
  1853. else
  1854. return 3840 * 2;
  1855. case 1:
  1856. case 5:
  1857. if (ASIC_IS_DCE5(rdev))
  1858. return 6144 * 2;
  1859. else
  1860. return 5760 * 2;
  1861. case 2:
  1862. case 6:
  1863. if (ASIC_IS_DCE5(rdev))
  1864. return 8192 * 2;
  1865. else
  1866. return 7680 * 2;
  1867. case 3:
  1868. case 7:
  1869. if (ASIC_IS_DCE5(rdev))
  1870. return 2048 * 2;
  1871. else
  1872. return 1920 * 2;
  1873. }
  1874. }
  1875. /* controller not enabled, so no lb used */
  1876. return 0;
  1877. }
  1878. u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
  1879. {
  1880. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1881. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1882. case 0:
  1883. default:
  1884. return 1;
  1885. case 1:
  1886. return 2;
  1887. case 2:
  1888. return 4;
  1889. case 3:
  1890. return 8;
  1891. }
  1892. }
  1893. struct evergreen_wm_params {
  1894. u32 dram_channels; /* number of dram channels */
  1895. u32 yclk; /* bandwidth per dram data pin in kHz */
  1896. u32 sclk; /* engine clock in kHz */
  1897. u32 disp_clk; /* display clock in kHz */
  1898. u32 src_width; /* viewport width */
  1899. u32 active_time; /* active display time in ns */
  1900. u32 blank_time; /* blank time in ns */
  1901. bool interlaced; /* mode is interlaced */
  1902. fixed20_12 vsc; /* vertical scale ratio */
  1903. u32 num_heads; /* number of active crtcs */
  1904. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1905. u32 lb_size; /* line buffer allocated to pipe */
  1906. u32 vtaps; /* vertical scaler taps */
  1907. };
  1908. static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
  1909. {
  1910. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1911. fixed20_12 dram_efficiency; /* 0.7 */
  1912. fixed20_12 yclk, dram_channels, bandwidth;
  1913. fixed20_12 a;
  1914. a.full = dfixed_const(1000);
  1915. yclk.full = dfixed_const(wm->yclk);
  1916. yclk.full = dfixed_div(yclk, a);
  1917. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1918. a.full = dfixed_const(10);
  1919. dram_efficiency.full = dfixed_const(7);
  1920. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1921. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1922. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1923. return dfixed_trunc(bandwidth);
  1924. }
  1925. static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  1926. {
  1927. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1928. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1929. fixed20_12 yclk, dram_channels, bandwidth;
  1930. fixed20_12 a;
  1931. a.full = dfixed_const(1000);
  1932. yclk.full = dfixed_const(wm->yclk);
  1933. yclk.full = dfixed_div(yclk, a);
  1934. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1935. a.full = dfixed_const(10);
  1936. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1937. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1938. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1939. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1940. return dfixed_trunc(bandwidth);
  1941. }
  1942. static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
  1943. {
  1944. /* Calculate the display Data return Bandwidth */
  1945. fixed20_12 return_efficiency; /* 0.8 */
  1946. fixed20_12 sclk, bandwidth;
  1947. fixed20_12 a;
  1948. a.full = dfixed_const(1000);
  1949. sclk.full = dfixed_const(wm->sclk);
  1950. sclk.full = dfixed_div(sclk, a);
  1951. a.full = dfixed_const(10);
  1952. return_efficiency.full = dfixed_const(8);
  1953. return_efficiency.full = dfixed_div(return_efficiency, a);
  1954. a.full = dfixed_const(32);
  1955. bandwidth.full = dfixed_mul(a, sclk);
  1956. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1957. return dfixed_trunc(bandwidth);
  1958. }
  1959. static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
  1960. {
  1961. /* Calculate the DMIF Request Bandwidth */
  1962. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1963. fixed20_12 disp_clk, bandwidth;
  1964. fixed20_12 a;
  1965. a.full = dfixed_const(1000);
  1966. disp_clk.full = dfixed_const(wm->disp_clk);
  1967. disp_clk.full = dfixed_div(disp_clk, a);
  1968. a.full = dfixed_const(10);
  1969. disp_clk_request_efficiency.full = dfixed_const(8);
  1970. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1971. a.full = dfixed_const(32);
  1972. bandwidth.full = dfixed_mul(a, disp_clk);
  1973. bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
  1974. return dfixed_trunc(bandwidth);
  1975. }
  1976. static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
  1977. {
  1978. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1979. u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
  1980. u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
  1981. u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
  1982. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1983. }
  1984. static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
  1985. {
  1986. /* Calculate the display mode Average Bandwidth
  1987. * DisplayMode should contain the source and destination dimensions,
  1988. * timing, etc.
  1989. */
  1990. fixed20_12 bpp;
  1991. fixed20_12 line_time;
  1992. fixed20_12 src_width;
  1993. fixed20_12 bandwidth;
  1994. fixed20_12 a;
  1995. a.full = dfixed_const(1000);
  1996. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1997. line_time.full = dfixed_div(line_time, a);
  1998. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1999. src_width.full = dfixed_const(wm->src_width);
  2000. bandwidth.full = dfixed_mul(src_width, bpp);
  2001. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  2002. bandwidth.full = dfixed_div(bandwidth, line_time);
  2003. return dfixed_trunc(bandwidth);
  2004. }
  2005. static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
  2006. {
  2007. /* First calcualte the latency in ns */
  2008. u32 mc_latency = 2000; /* 2000 ns. */
  2009. u32 available_bandwidth = evergreen_available_bandwidth(wm);
  2010. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  2011. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  2012. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  2013. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  2014. (wm->num_heads * cursor_line_pair_return_time);
  2015. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  2016. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  2017. fixed20_12 a, b, c;
  2018. if (wm->num_heads == 0)
  2019. return 0;
  2020. a.full = dfixed_const(2);
  2021. b.full = dfixed_const(1);
  2022. if ((wm->vsc.full > a.full) ||
  2023. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  2024. (wm->vtaps >= 5) ||
  2025. ((wm->vsc.full >= a.full) && wm->interlaced))
  2026. max_src_lines_per_dst_line = 4;
  2027. else
  2028. max_src_lines_per_dst_line = 2;
  2029. a.full = dfixed_const(available_bandwidth);
  2030. b.full = dfixed_const(wm->num_heads);
  2031. a.full = dfixed_div(a, b);
  2032. b.full = dfixed_const(1000);
  2033. c.full = dfixed_const(wm->disp_clk);
  2034. b.full = dfixed_div(c, b);
  2035. c.full = dfixed_const(wm->bytes_per_pixel);
  2036. b.full = dfixed_mul(b, c);
  2037. lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
  2038. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  2039. b.full = dfixed_const(1000);
  2040. c.full = dfixed_const(lb_fill_bw);
  2041. b.full = dfixed_div(c, b);
  2042. a.full = dfixed_div(a, b);
  2043. line_fill_time = dfixed_trunc(a);
  2044. if (line_fill_time < wm->active_time)
  2045. return latency;
  2046. else
  2047. return latency + (line_fill_time - wm->active_time);
  2048. }
  2049. static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  2050. {
  2051. if (evergreen_average_bandwidth(wm) <=
  2052. (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
  2053. return true;
  2054. else
  2055. return false;
  2056. };
  2057. static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
  2058. {
  2059. if (evergreen_average_bandwidth(wm) <=
  2060. (evergreen_available_bandwidth(wm) / wm->num_heads))
  2061. return true;
  2062. else
  2063. return false;
  2064. };
  2065. static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
  2066. {
  2067. u32 lb_partitions = wm->lb_size / wm->src_width;
  2068. u32 line_time = wm->active_time + wm->blank_time;
  2069. u32 latency_tolerant_lines;
  2070. u32 latency_hiding;
  2071. fixed20_12 a;
  2072. a.full = dfixed_const(1);
  2073. if (wm->vsc.full > a.full)
  2074. latency_tolerant_lines = 1;
  2075. else {
  2076. if (lb_partitions <= (wm->vtaps + 1))
  2077. latency_tolerant_lines = 1;
  2078. else
  2079. latency_tolerant_lines = 2;
  2080. }
  2081. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  2082. if (evergreen_latency_watermark(wm) <= latency_hiding)
  2083. return true;
  2084. else
  2085. return false;
  2086. }
  2087. static void evergreen_program_watermarks(struct radeon_device *rdev,
  2088. struct radeon_crtc *radeon_crtc,
  2089. u32 lb_size, u32 num_heads)
  2090. {
  2091. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  2092. struct evergreen_wm_params wm_low, wm_high;
  2093. u32 dram_channels;
  2094. u32 pixel_period;
  2095. u32 line_time = 0;
  2096. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  2097. u32 priority_a_mark = 0, priority_b_mark = 0;
  2098. u32 priority_a_cnt = PRIORITY_OFF;
  2099. u32 priority_b_cnt = PRIORITY_OFF;
  2100. u32 pipe_offset = radeon_crtc->crtc_id * 16;
  2101. u32 tmp, arb_control3;
  2102. fixed20_12 a, b, c;
  2103. if (radeon_crtc->base.enabled && num_heads && mode) {
  2104. pixel_period = 1000000 / (u32)mode->clock;
  2105. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  2106. priority_a_cnt = 0;
  2107. priority_b_cnt = 0;
  2108. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  2109. /* watermark for high clocks */
  2110. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2111. wm_high.yclk =
  2112. radeon_dpm_get_mclk(rdev, false) * 10;
  2113. wm_high.sclk =
  2114. radeon_dpm_get_sclk(rdev, false) * 10;
  2115. } else {
  2116. wm_high.yclk = rdev->pm.current_mclk * 10;
  2117. wm_high.sclk = rdev->pm.current_sclk * 10;
  2118. }
  2119. wm_high.disp_clk = mode->clock;
  2120. wm_high.src_width = mode->crtc_hdisplay;
  2121. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  2122. wm_high.blank_time = line_time - wm_high.active_time;
  2123. wm_high.interlaced = false;
  2124. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2125. wm_high.interlaced = true;
  2126. wm_high.vsc = radeon_crtc->vsc;
  2127. wm_high.vtaps = 1;
  2128. if (radeon_crtc->rmx_type != RMX_OFF)
  2129. wm_high.vtaps = 2;
  2130. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2131. wm_high.lb_size = lb_size;
  2132. wm_high.dram_channels = dram_channels;
  2133. wm_high.num_heads = num_heads;
  2134. /* watermark for low clocks */
  2135. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2136. wm_low.yclk =
  2137. radeon_dpm_get_mclk(rdev, true) * 10;
  2138. wm_low.sclk =
  2139. radeon_dpm_get_sclk(rdev, true) * 10;
  2140. } else {
  2141. wm_low.yclk = rdev->pm.current_mclk * 10;
  2142. wm_low.sclk = rdev->pm.current_sclk * 10;
  2143. }
  2144. wm_low.disp_clk = mode->clock;
  2145. wm_low.src_width = mode->crtc_hdisplay;
  2146. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2147. wm_low.blank_time = line_time - wm_low.active_time;
  2148. wm_low.interlaced = false;
  2149. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2150. wm_low.interlaced = true;
  2151. wm_low.vsc = radeon_crtc->vsc;
  2152. wm_low.vtaps = 1;
  2153. if (radeon_crtc->rmx_type != RMX_OFF)
  2154. wm_low.vtaps = 2;
  2155. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2156. wm_low.lb_size = lb_size;
  2157. wm_low.dram_channels = dram_channels;
  2158. wm_low.num_heads = num_heads;
  2159. /* set for high clocks */
  2160. latency_watermark_a = min(evergreen_latency_watermark(&wm_high), (u32)65535);
  2161. /* set for low clocks */
  2162. latency_watermark_b = min(evergreen_latency_watermark(&wm_low), (u32)65535);
  2163. /* possibly force display priority to high */
  2164. /* should really do this at mode validation time... */
  2165. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2166. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2167. !evergreen_check_latency_hiding(&wm_high) ||
  2168. (rdev->disp_priority == 2)) {
  2169. DRM_DEBUG_KMS("force priority a to high\n");
  2170. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2171. }
  2172. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2173. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2174. !evergreen_check_latency_hiding(&wm_low) ||
  2175. (rdev->disp_priority == 2)) {
  2176. DRM_DEBUG_KMS("force priority b to high\n");
  2177. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2178. }
  2179. a.full = dfixed_const(1000);
  2180. b.full = dfixed_const(mode->clock);
  2181. b.full = dfixed_div(b, a);
  2182. c.full = dfixed_const(latency_watermark_a);
  2183. c.full = dfixed_mul(c, b);
  2184. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2185. c.full = dfixed_div(c, a);
  2186. a.full = dfixed_const(16);
  2187. c.full = dfixed_div(c, a);
  2188. priority_a_mark = dfixed_trunc(c);
  2189. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2190. a.full = dfixed_const(1000);
  2191. b.full = dfixed_const(mode->clock);
  2192. b.full = dfixed_div(b, a);
  2193. c.full = dfixed_const(latency_watermark_b);
  2194. c.full = dfixed_mul(c, b);
  2195. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2196. c.full = dfixed_div(c, a);
  2197. a.full = dfixed_const(16);
  2198. c.full = dfixed_div(c, a);
  2199. priority_b_mark = dfixed_trunc(c);
  2200. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2201. /* Save number of lines the linebuffer leads before the scanout */
  2202. radeon_crtc->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
  2203. }
  2204. /* select wm A */
  2205. arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2206. tmp = arb_control3;
  2207. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2208. tmp |= LATENCY_WATERMARK_MASK(1);
  2209. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2210. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2211. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2212. LATENCY_HIGH_WATERMARK(line_time)));
  2213. /* select wm B */
  2214. tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2215. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2216. tmp |= LATENCY_WATERMARK_MASK(2);
  2217. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2218. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2219. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2220. LATENCY_HIGH_WATERMARK(line_time)));
  2221. /* restore original selection */
  2222. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
  2223. /* write the priority marks */
  2224. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2225. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2226. /* save values for DPM */
  2227. radeon_crtc->line_time = line_time;
  2228. radeon_crtc->wm_high = latency_watermark_a;
  2229. radeon_crtc->wm_low = latency_watermark_b;
  2230. }
  2231. /**
  2232. * evergreen_bandwidth_update - update display watermarks callback.
  2233. *
  2234. * @rdev: radeon_device pointer
  2235. *
  2236. * Update the display watermarks based on the requested mode(s)
  2237. * (evergreen+).
  2238. */
  2239. void evergreen_bandwidth_update(struct radeon_device *rdev)
  2240. {
  2241. struct drm_display_mode *mode0 = NULL;
  2242. struct drm_display_mode *mode1 = NULL;
  2243. u32 num_heads = 0, lb_size;
  2244. int i;
  2245. if (!rdev->mode_info.mode_config_initialized)
  2246. return;
  2247. radeon_update_display_priority(rdev);
  2248. for (i = 0; i < rdev->num_crtc; i++) {
  2249. if (rdev->mode_info.crtcs[i]->base.enabled)
  2250. num_heads++;
  2251. }
  2252. for (i = 0; i < rdev->num_crtc; i += 2) {
  2253. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2254. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2255. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2256. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2257. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2258. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2259. }
  2260. }
  2261. /**
  2262. * evergreen_mc_wait_for_idle - wait for MC idle callback.
  2263. *
  2264. * @rdev: radeon_device pointer
  2265. *
  2266. * Wait for the MC (memory controller) to be idle.
  2267. * (evergreen+).
  2268. * Returns 0 if the MC is idle, -1 if not.
  2269. */
  2270. int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
  2271. {
  2272. unsigned i;
  2273. u32 tmp;
  2274. for (i = 0; i < rdev->usec_timeout; i++) {
  2275. /* read MC_STATUS */
  2276. tmp = RREG32(SRBM_STATUS) & 0x1F00;
  2277. if (!tmp)
  2278. return 0;
  2279. udelay(1);
  2280. }
  2281. return -1;
  2282. }
  2283. /*
  2284. * GART
  2285. */
  2286. void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
  2287. {
  2288. unsigned i;
  2289. u32 tmp;
  2290. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2291. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  2292. for (i = 0; i < rdev->usec_timeout; i++) {
  2293. /* read MC_STATUS */
  2294. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  2295. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  2296. if (tmp == 2) {
  2297. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  2298. return;
  2299. }
  2300. if (tmp) {
  2301. return;
  2302. }
  2303. udelay(1);
  2304. }
  2305. }
  2306. static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
  2307. {
  2308. u32 tmp;
  2309. int r;
  2310. if (rdev->gart.robj == NULL) {
  2311. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  2312. return -EINVAL;
  2313. }
  2314. r = radeon_gart_table_vram_pin(rdev);
  2315. if (r)
  2316. return r;
  2317. /* Setup L2 cache */
  2318. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2319. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2320. EFFECTIVE_L2_QUEUE_SIZE(7));
  2321. WREG32(VM_L2_CNTL2, 0);
  2322. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2323. /* Setup TLB control */
  2324. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2325. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2326. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2327. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2328. if (rdev->flags & RADEON_IS_IGP) {
  2329. WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
  2330. WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
  2331. WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
  2332. } else {
  2333. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2334. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2335. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2336. if ((rdev->family == CHIP_JUNIPER) ||
  2337. (rdev->family == CHIP_CYPRESS) ||
  2338. (rdev->family == CHIP_HEMLOCK) ||
  2339. (rdev->family == CHIP_BARTS))
  2340. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  2341. }
  2342. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2343. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2344. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2345. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2346. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  2347. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  2348. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  2349. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  2350. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  2351. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  2352. (u32)(rdev->dummy_page.addr >> 12));
  2353. WREG32(VM_CONTEXT1_CNTL, 0);
  2354. evergreen_pcie_gart_tlb_flush(rdev);
  2355. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  2356. (unsigned)(rdev->mc.gtt_size >> 20),
  2357. (unsigned long long)rdev->gart.table_addr);
  2358. rdev->gart.ready = true;
  2359. return 0;
  2360. }
  2361. static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
  2362. {
  2363. u32 tmp;
  2364. /* Disable all tables */
  2365. WREG32(VM_CONTEXT0_CNTL, 0);
  2366. WREG32(VM_CONTEXT1_CNTL, 0);
  2367. /* Setup L2 cache */
  2368. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  2369. EFFECTIVE_L2_QUEUE_SIZE(7));
  2370. WREG32(VM_L2_CNTL2, 0);
  2371. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2372. /* Setup TLB control */
  2373. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2374. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2375. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2376. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2377. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2378. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2379. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2380. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2381. radeon_gart_table_vram_unpin(rdev);
  2382. }
  2383. static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
  2384. {
  2385. evergreen_pcie_gart_disable(rdev);
  2386. radeon_gart_table_vram_free(rdev);
  2387. radeon_gart_fini(rdev);
  2388. }
  2389. static void evergreen_agp_enable(struct radeon_device *rdev)
  2390. {
  2391. u32 tmp;
  2392. /* Setup L2 cache */
  2393. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2394. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2395. EFFECTIVE_L2_QUEUE_SIZE(7));
  2396. WREG32(VM_L2_CNTL2, 0);
  2397. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2398. /* Setup TLB control */
  2399. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2400. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2401. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2402. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2403. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2404. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2405. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2406. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2407. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2408. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2409. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2410. WREG32(VM_CONTEXT0_CNTL, 0);
  2411. WREG32(VM_CONTEXT1_CNTL, 0);
  2412. }
  2413. static const unsigned ni_dig_offsets[] =
  2414. {
  2415. NI_DIG0_REGISTER_OFFSET,
  2416. NI_DIG1_REGISTER_OFFSET,
  2417. NI_DIG2_REGISTER_OFFSET,
  2418. NI_DIG3_REGISTER_OFFSET,
  2419. NI_DIG4_REGISTER_OFFSET,
  2420. NI_DIG5_REGISTER_OFFSET
  2421. };
  2422. static const unsigned ni_tx_offsets[] =
  2423. {
  2424. NI_DCIO_UNIPHY0_UNIPHY_TX_CONTROL1,
  2425. NI_DCIO_UNIPHY1_UNIPHY_TX_CONTROL1,
  2426. NI_DCIO_UNIPHY2_UNIPHY_TX_CONTROL1,
  2427. NI_DCIO_UNIPHY3_UNIPHY_TX_CONTROL1,
  2428. NI_DCIO_UNIPHY4_UNIPHY_TX_CONTROL1,
  2429. NI_DCIO_UNIPHY5_UNIPHY_TX_CONTROL1
  2430. };
  2431. static const unsigned evergreen_dp_offsets[] =
  2432. {
  2433. EVERGREEN_DP0_REGISTER_OFFSET,
  2434. EVERGREEN_DP1_REGISTER_OFFSET,
  2435. EVERGREEN_DP2_REGISTER_OFFSET,
  2436. EVERGREEN_DP3_REGISTER_OFFSET,
  2437. EVERGREEN_DP4_REGISTER_OFFSET,
  2438. EVERGREEN_DP5_REGISTER_OFFSET
  2439. };
  2440. /*
  2441. * Assumption is that EVERGREEN_CRTC_MASTER_EN enable for requested crtc
  2442. * We go from crtc to connector and it is not relible since it
  2443. * should be an opposite direction .If crtc is enable then
  2444. * find the dig_fe which selects this crtc and insure that it enable.
  2445. * if such dig_fe is found then find dig_be which selects found dig_be and
  2446. * insure that it enable and in DP_SST mode.
  2447. * if UNIPHY_PLL_CONTROL1.enable then we should disconnect timing
  2448. * from dp symbols clocks .
  2449. */
  2450. static bool evergreen_is_dp_sst_stream_enabled(struct radeon_device *rdev,
  2451. unsigned crtc_id, unsigned *ret_dig_fe)
  2452. {
  2453. unsigned i;
  2454. unsigned dig_fe;
  2455. unsigned dig_be;
  2456. unsigned dig_en_be;
  2457. unsigned uniphy_pll;
  2458. unsigned digs_fe_selected;
  2459. unsigned dig_be_mode;
  2460. unsigned dig_fe_mask;
  2461. bool is_enabled = false;
  2462. bool found_crtc = false;
  2463. /* loop through all running dig_fe to find selected crtc */
  2464. for (i = 0; i < ARRAY_SIZE(ni_dig_offsets); i++) {
  2465. dig_fe = RREG32(NI_DIG_FE_CNTL + ni_dig_offsets[i]);
  2466. if (dig_fe & NI_DIG_FE_CNTL_SYMCLK_FE_ON &&
  2467. crtc_id == NI_DIG_FE_CNTL_SOURCE_SELECT(dig_fe)) {
  2468. /* found running pipe */
  2469. found_crtc = true;
  2470. dig_fe_mask = 1 << i;
  2471. dig_fe = i;
  2472. break;
  2473. }
  2474. }
  2475. if (found_crtc) {
  2476. /* loop through all running dig_be to find selected dig_fe */
  2477. for (i = 0; i < ARRAY_SIZE(ni_dig_offsets); i++) {
  2478. dig_be = RREG32(NI_DIG_BE_CNTL + ni_dig_offsets[i]);
  2479. /* if dig_fe_selected by dig_be? */
  2480. digs_fe_selected = NI_DIG_BE_CNTL_FE_SOURCE_SELECT(dig_be);
  2481. dig_be_mode = NI_DIG_FE_CNTL_MODE(dig_be);
  2482. if (dig_fe_mask & digs_fe_selected &&
  2483. /* if dig_be in sst mode? */
  2484. dig_be_mode == NI_DIG_BE_DPSST) {
  2485. dig_en_be = RREG32(NI_DIG_BE_EN_CNTL +
  2486. ni_dig_offsets[i]);
  2487. uniphy_pll = RREG32(NI_DCIO_UNIPHY0_PLL_CONTROL1 +
  2488. ni_tx_offsets[i]);
  2489. /* dig_be enable and tx is running */
  2490. if (dig_en_be & NI_DIG_BE_EN_CNTL_ENABLE &&
  2491. dig_en_be & NI_DIG_BE_EN_CNTL_SYMBCLK_ON &&
  2492. uniphy_pll & NI_DCIO_UNIPHY0_PLL_CONTROL1_ENABLE) {
  2493. is_enabled = true;
  2494. *ret_dig_fe = dig_fe;
  2495. break;
  2496. }
  2497. }
  2498. }
  2499. }
  2500. return is_enabled;
  2501. }
  2502. /*
  2503. * Blank dig when in dp sst mode
  2504. * Dig ignores crtc timing
  2505. */
  2506. static void evergreen_blank_dp_output(struct radeon_device *rdev,
  2507. unsigned dig_fe)
  2508. {
  2509. unsigned stream_ctrl;
  2510. unsigned fifo_ctrl;
  2511. unsigned counter = 0;
  2512. if (dig_fe >= ARRAY_SIZE(evergreen_dp_offsets)) {
  2513. DRM_ERROR("invalid dig_fe %d\n", dig_fe);
  2514. return;
  2515. }
  2516. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2517. evergreen_dp_offsets[dig_fe]);
  2518. if (!(stream_ctrl & EVERGREEN_DP_VID_STREAM_CNTL_ENABLE)) {
  2519. DRM_ERROR("dig %d , should be enable\n", dig_fe);
  2520. return;
  2521. }
  2522. stream_ctrl &=~EVERGREEN_DP_VID_STREAM_CNTL_ENABLE;
  2523. WREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2524. evergreen_dp_offsets[dig_fe], stream_ctrl);
  2525. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2526. evergreen_dp_offsets[dig_fe]);
  2527. while (counter < 32 && stream_ctrl & EVERGREEN_DP_VID_STREAM_STATUS) {
  2528. msleep(1);
  2529. counter++;
  2530. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2531. evergreen_dp_offsets[dig_fe]);
  2532. }
  2533. if (counter >= 32 )
  2534. DRM_ERROR("counter exceeds %d\n", counter);
  2535. fifo_ctrl = RREG32(EVERGREEN_DP_STEER_FIFO + evergreen_dp_offsets[dig_fe]);
  2536. fifo_ctrl |= EVERGREEN_DP_STEER_FIFO_RESET;
  2537. WREG32(EVERGREEN_DP_STEER_FIFO + evergreen_dp_offsets[dig_fe], fifo_ctrl);
  2538. }
  2539. void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2540. {
  2541. u32 crtc_enabled, tmp, frame_count, blackout;
  2542. int i, j;
  2543. unsigned dig_fe;
  2544. if (!ASIC_IS_NODCE(rdev)) {
  2545. save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
  2546. save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
  2547. /* disable VGA render */
  2548. WREG32(VGA_RENDER_CONTROL, 0);
  2549. }
  2550. /* blank the display controllers */
  2551. for (i = 0; i < rdev->num_crtc; i++) {
  2552. crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
  2553. if (crtc_enabled) {
  2554. save->crtc_enabled[i] = true;
  2555. if (ASIC_IS_DCE6(rdev)) {
  2556. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2557. if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
  2558. radeon_wait_for_vblank(rdev, i);
  2559. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2560. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  2561. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2562. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2563. }
  2564. } else {
  2565. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2566. if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
  2567. radeon_wait_for_vblank(rdev, i);
  2568. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2569. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2570. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2571. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2572. }
  2573. }
  2574. /* wait for the next frame */
  2575. frame_count = radeon_get_vblank_counter(rdev, i);
  2576. for (j = 0; j < rdev->usec_timeout; j++) {
  2577. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2578. break;
  2579. udelay(1);
  2580. }
  2581. /*we should disable dig if it drives dp sst*/
  2582. /*but we are in radeon_device_init and the topology is unknown*/
  2583. /*and it is available after radeon_modeset_init*/
  2584. /*the following method radeon_atom_encoder_dpms_dig*/
  2585. /*does the job if we initialize it properly*/
  2586. /*for now we do it this manually*/
  2587. /**/
  2588. if (ASIC_IS_DCE5(rdev) &&
  2589. evergreen_is_dp_sst_stream_enabled(rdev, i ,&dig_fe))
  2590. evergreen_blank_dp_output(rdev, dig_fe);
  2591. /*we could remove 6 lines below*/
  2592. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  2593. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2594. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2595. tmp &= ~EVERGREEN_CRTC_MASTER_EN;
  2596. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2597. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2598. save->crtc_enabled[i] = false;
  2599. /* ***** */
  2600. } else {
  2601. save->crtc_enabled[i] = false;
  2602. }
  2603. }
  2604. radeon_mc_wait_for_idle(rdev);
  2605. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2606. if ((blackout & BLACKOUT_MODE_MASK) != 1) {
  2607. /* Block CPU access */
  2608. WREG32(BIF_FB_EN, 0);
  2609. /* blackout the MC */
  2610. blackout &= ~BLACKOUT_MODE_MASK;
  2611. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  2612. }
  2613. /* wait for the MC to settle */
  2614. udelay(100);
  2615. /* lock double buffered regs */
  2616. for (i = 0; i < rdev->num_crtc; i++) {
  2617. if (save->crtc_enabled[i]) {
  2618. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2619. if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
  2620. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  2621. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2622. }
  2623. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2624. if (!(tmp & 1)) {
  2625. tmp |= 1;
  2626. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2627. }
  2628. }
  2629. }
  2630. }
  2631. void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2632. {
  2633. u32 tmp, frame_count;
  2634. int i, j;
  2635. /* update crtc base addresses */
  2636. for (i = 0; i < rdev->num_crtc; i++) {
  2637. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2638. upper_32_bits(rdev->mc.vram_start));
  2639. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2640. upper_32_bits(rdev->mc.vram_start));
  2641. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  2642. (u32)rdev->mc.vram_start);
  2643. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  2644. (u32)rdev->mc.vram_start);
  2645. }
  2646. if (!ASIC_IS_NODCE(rdev)) {
  2647. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
  2648. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
  2649. }
  2650. /* unlock regs and wait for update */
  2651. for (i = 0; i < rdev->num_crtc; i++) {
  2652. if (save->crtc_enabled[i]) {
  2653. tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
  2654. if ((tmp & 0x7) != 0) {
  2655. tmp &= ~0x7;
  2656. WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  2657. }
  2658. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2659. if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
  2660. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  2661. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2662. }
  2663. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2664. if (tmp & 1) {
  2665. tmp &= ~1;
  2666. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2667. }
  2668. for (j = 0; j < rdev->usec_timeout; j++) {
  2669. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2670. if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
  2671. break;
  2672. udelay(1);
  2673. }
  2674. }
  2675. }
  2676. /* unblackout the MC */
  2677. tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2678. tmp &= ~BLACKOUT_MODE_MASK;
  2679. WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
  2680. /* allow CPU access */
  2681. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2682. for (i = 0; i < rdev->num_crtc; i++) {
  2683. if (save->crtc_enabled[i]) {
  2684. if (ASIC_IS_DCE6(rdev)) {
  2685. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2686. tmp &= ~EVERGREEN_CRTC_BLANK_DATA_EN;
  2687. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2688. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2689. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2690. } else {
  2691. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2692. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2693. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2694. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2695. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2696. }
  2697. /* wait for the next frame */
  2698. frame_count = radeon_get_vblank_counter(rdev, i);
  2699. for (j = 0; j < rdev->usec_timeout; j++) {
  2700. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2701. break;
  2702. udelay(1);
  2703. }
  2704. }
  2705. }
  2706. if (!ASIC_IS_NODCE(rdev)) {
  2707. /* Unlock vga access */
  2708. WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
  2709. mdelay(1);
  2710. WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
  2711. }
  2712. }
  2713. void evergreen_mc_program(struct radeon_device *rdev)
  2714. {
  2715. struct evergreen_mc_save save;
  2716. u32 tmp;
  2717. int i, j;
  2718. /* Initialize HDP */
  2719. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2720. WREG32((0x2c14 + j), 0x00000000);
  2721. WREG32((0x2c18 + j), 0x00000000);
  2722. WREG32((0x2c1c + j), 0x00000000);
  2723. WREG32((0x2c20 + j), 0x00000000);
  2724. WREG32((0x2c24 + j), 0x00000000);
  2725. }
  2726. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  2727. evergreen_mc_stop(rdev, &save);
  2728. if (evergreen_mc_wait_for_idle(rdev)) {
  2729. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2730. }
  2731. /* Lockout access through VGA aperture*/
  2732. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  2733. /* Update configuration */
  2734. if (rdev->flags & RADEON_IS_AGP) {
  2735. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  2736. /* VRAM before AGP */
  2737. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2738. rdev->mc.vram_start >> 12);
  2739. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2740. rdev->mc.gtt_end >> 12);
  2741. } else {
  2742. /* VRAM after AGP */
  2743. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2744. rdev->mc.gtt_start >> 12);
  2745. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2746. rdev->mc.vram_end >> 12);
  2747. }
  2748. } else {
  2749. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2750. rdev->mc.vram_start >> 12);
  2751. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2752. rdev->mc.vram_end >> 12);
  2753. }
  2754. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  2755. /* llano/ontario only */
  2756. if ((rdev->family == CHIP_PALM) ||
  2757. (rdev->family == CHIP_SUMO) ||
  2758. (rdev->family == CHIP_SUMO2)) {
  2759. tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
  2760. tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
  2761. tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
  2762. WREG32(MC_FUS_VM_FB_OFFSET, tmp);
  2763. }
  2764. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  2765. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  2766. WREG32(MC_VM_FB_LOCATION, tmp);
  2767. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  2768. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  2769. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  2770. if (rdev->flags & RADEON_IS_AGP) {
  2771. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  2772. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  2773. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  2774. } else {
  2775. WREG32(MC_VM_AGP_BASE, 0);
  2776. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  2777. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  2778. }
  2779. if (evergreen_mc_wait_for_idle(rdev)) {
  2780. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2781. }
  2782. evergreen_mc_resume(rdev, &save);
  2783. /* we need to own VRAM, so turn off the VGA renderer here
  2784. * to stop it overwriting our objects */
  2785. rv515_vga_render_disable(rdev);
  2786. }
  2787. /*
  2788. * CP.
  2789. */
  2790. void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2791. {
  2792. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2793. u32 next_rptr;
  2794. /* set to DX10/11 mode */
  2795. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  2796. radeon_ring_write(ring, 1);
  2797. if (ring->rptr_save_reg) {
  2798. next_rptr = ring->wptr + 3 + 4;
  2799. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2800. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2801. PACKET3_SET_CONFIG_REG_START) >> 2));
  2802. radeon_ring_write(ring, next_rptr);
  2803. } else if (rdev->wb.enabled) {
  2804. next_rptr = ring->wptr + 5 + 4;
  2805. radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
  2806. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2807. radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
  2808. radeon_ring_write(ring, next_rptr);
  2809. radeon_ring_write(ring, 0);
  2810. }
  2811. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2812. radeon_ring_write(ring,
  2813. #ifdef __BIG_ENDIAN
  2814. (2 << 0) |
  2815. #endif
  2816. (ib->gpu_addr & 0xFFFFFFFC));
  2817. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  2818. radeon_ring_write(ring, ib->length_dw);
  2819. }
  2820. static int evergreen_cp_load_microcode(struct radeon_device *rdev)
  2821. {
  2822. const __be32 *fw_data;
  2823. int i;
  2824. if (!rdev->me_fw || !rdev->pfp_fw)
  2825. return -EINVAL;
  2826. r700_cp_stop(rdev);
  2827. WREG32(CP_RB_CNTL,
  2828. #ifdef __BIG_ENDIAN
  2829. BUF_SWAP_32BIT |
  2830. #endif
  2831. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  2832. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2833. WREG32(CP_PFP_UCODE_ADDR, 0);
  2834. for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
  2835. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2836. WREG32(CP_PFP_UCODE_ADDR, 0);
  2837. fw_data = (const __be32 *)rdev->me_fw->data;
  2838. WREG32(CP_ME_RAM_WADDR, 0);
  2839. for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
  2840. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2841. WREG32(CP_PFP_UCODE_ADDR, 0);
  2842. WREG32(CP_ME_RAM_WADDR, 0);
  2843. WREG32(CP_ME_RAM_RADDR, 0);
  2844. return 0;
  2845. }
  2846. static int evergreen_cp_start(struct radeon_device *rdev)
  2847. {
  2848. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2849. int r, i;
  2850. uint32_t cp_me;
  2851. r = radeon_ring_lock(rdev, ring, 7);
  2852. if (r) {
  2853. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2854. return r;
  2855. }
  2856. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2857. radeon_ring_write(ring, 0x1);
  2858. radeon_ring_write(ring, 0x0);
  2859. radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
  2860. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2861. radeon_ring_write(ring, 0);
  2862. radeon_ring_write(ring, 0);
  2863. radeon_ring_unlock_commit(rdev, ring, false);
  2864. cp_me = 0xff;
  2865. WREG32(CP_ME_CNTL, cp_me);
  2866. r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
  2867. if (r) {
  2868. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2869. return r;
  2870. }
  2871. /* setup clear context state */
  2872. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2873. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2874. for (i = 0; i < evergreen_default_size; i++)
  2875. radeon_ring_write(ring, evergreen_default_state[i]);
  2876. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2877. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2878. /* set clear context state */
  2879. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2880. radeon_ring_write(ring, 0);
  2881. /* SQ_VTX_BASE_VTX_LOC */
  2882. radeon_ring_write(ring, 0xc0026f00);
  2883. radeon_ring_write(ring, 0x00000000);
  2884. radeon_ring_write(ring, 0x00000000);
  2885. radeon_ring_write(ring, 0x00000000);
  2886. /* Clear consts */
  2887. radeon_ring_write(ring, 0xc0036f00);
  2888. radeon_ring_write(ring, 0x00000bc4);
  2889. radeon_ring_write(ring, 0xffffffff);
  2890. radeon_ring_write(ring, 0xffffffff);
  2891. radeon_ring_write(ring, 0xffffffff);
  2892. radeon_ring_write(ring, 0xc0026900);
  2893. radeon_ring_write(ring, 0x00000316);
  2894. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2895. radeon_ring_write(ring, 0x00000010); /* */
  2896. radeon_ring_unlock_commit(rdev, ring, false);
  2897. return 0;
  2898. }
  2899. static int evergreen_cp_resume(struct radeon_device *rdev)
  2900. {
  2901. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2902. u32 tmp;
  2903. u32 rb_bufsz;
  2904. int r;
  2905. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2906. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2907. SOFT_RESET_PA |
  2908. SOFT_RESET_SH |
  2909. SOFT_RESET_VGT |
  2910. SOFT_RESET_SPI |
  2911. SOFT_RESET_SX));
  2912. RREG32(GRBM_SOFT_RESET);
  2913. mdelay(15);
  2914. WREG32(GRBM_SOFT_RESET, 0);
  2915. RREG32(GRBM_SOFT_RESET);
  2916. /* Set ring buffer size */
  2917. rb_bufsz = order_base_2(ring->ring_size / 8);
  2918. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2919. #ifdef __BIG_ENDIAN
  2920. tmp |= BUF_SWAP_32BIT;
  2921. #endif
  2922. WREG32(CP_RB_CNTL, tmp);
  2923. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2924. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2925. /* Set the write pointer delay */
  2926. WREG32(CP_RB_WPTR_DELAY, 0);
  2927. /* Initialize the ring buffer's read and write pointers */
  2928. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2929. WREG32(CP_RB_RPTR_WR, 0);
  2930. ring->wptr = 0;
  2931. WREG32(CP_RB_WPTR, ring->wptr);
  2932. /* set the wb address whether it's enabled or not */
  2933. WREG32(CP_RB_RPTR_ADDR,
  2934. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2935. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2936. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2937. if (rdev->wb.enabled)
  2938. WREG32(SCRATCH_UMSK, 0xff);
  2939. else {
  2940. tmp |= RB_NO_UPDATE;
  2941. WREG32(SCRATCH_UMSK, 0);
  2942. }
  2943. mdelay(1);
  2944. WREG32(CP_RB_CNTL, tmp);
  2945. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2946. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2947. evergreen_cp_start(rdev);
  2948. ring->ready = true;
  2949. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2950. if (r) {
  2951. ring->ready = false;
  2952. return r;
  2953. }
  2954. return 0;
  2955. }
  2956. /*
  2957. * Core functions
  2958. */
  2959. static void evergreen_gpu_init(struct radeon_device *rdev)
  2960. {
  2961. u32 gb_addr_config;
  2962. u32 mc_shared_chmap, mc_arb_ramcfg;
  2963. u32 sx_debug_1;
  2964. u32 smx_dc_ctl0;
  2965. u32 sq_config;
  2966. u32 sq_lds_resource_mgmt;
  2967. u32 sq_gpr_resource_mgmt_1;
  2968. u32 sq_gpr_resource_mgmt_2;
  2969. u32 sq_gpr_resource_mgmt_3;
  2970. u32 sq_thread_resource_mgmt;
  2971. u32 sq_thread_resource_mgmt_2;
  2972. u32 sq_stack_resource_mgmt_1;
  2973. u32 sq_stack_resource_mgmt_2;
  2974. u32 sq_stack_resource_mgmt_3;
  2975. u32 vgt_cache_invalidation;
  2976. u32 hdp_host_path_cntl, tmp;
  2977. u32 disabled_rb_mask;
  2978. int i, j, ps_thread_count;
  2979. switch (rdev->family) {
  2980. case CHIP_CYPRESS:
  2981. case CHIP_HEMLOCK:
  2982. rdev->config.evergreen.num_ses = 2;
  2983. rdev->config.evergreen.max_pipes = 4;
  2984. rdev->config.evergreen.max_tile_pipes = 8;
  2985. rdev->config.evergreen.max_simds = 10;
  2986. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2987. rdev->config.evergreen.max_gprs = 256;
  2988. rdev->config.evergreen.max_threads = 248;
  2989. rdev->config.evergreen.max_gs_threads = 32;
  2990. rdev->config.evergreen.max_stack_entries = 512;
  2991. rdev->config.evergreen.sx_num_of_sets = 4;
  2992. rdev->config.evergreen.sx_max_export_size = 256;
  2993. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2994. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2995. rdev->config.evergreen.max_hw_contexts = 8;
  2996. rdev->config.evergreen.sq_num_cf_insts = 2;
  2997. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2998. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2999. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3000. gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
  3001. break;
  3002. case CHIP_JUNIPER:
  3003. rdev->config.evergreen.num_ses = 1;
  3004. rdev->config.evergreen.max_pipes = 4;
  3005. rdev->config.evergreen.max_tile_pipes = 4;
  3006. rdev->config.evergreen.max_simds = 10;
  3007. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  3008. rdev->config.evergreen.max_gprs = 256;
  3009. rdev->config.evergreen.max_threads = 248;
  3010. rdev->config.evergreen.max_gs_threads = 32;
  3011. rdev->config.evergreen.max_stack_entries = 512;
  3012. rdev->config.evergreen.sx_num_of_sets = 4;
  3013. rdev->config.evergreen.sx_max_export_size = 256;
  3014. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3015. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3016. rdev->config.evergreen.max_hw_contexts = 8;
  3017. rdev->config.evergreen.sq_num_cf_insts = 2;
  3018. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3019. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3020. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3021. gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
  3022. break;
  3023. case CHIP_REDWOOD:
  3024. rdev->config.evergreen.num_ses = 1;
  3025. rdev->config.evergreen.max_pipes = 4;
  3026. rdev->config.evergreen.max_tile_pipes = 4;
  3027. rdev->config.evergreen.max_simds = 5;
  3028. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3029. rdev->config.evergreen.max_gprs = 256;
  3030. rdev->config.evergreen.max_threads = 248;
  3031. rdev->config.evergreen.max_gs_threads = 32;
  3032. rdev->config.evergreen.max_stack_entries = 256;
  3033. rdev->config.evergreen.sx_num_of_sets = 4;
  3034. rdev->config.evergreen.sx_max_export_size = 256;
  3035. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3036. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3037. rdev->config.evergreen.max_hw_contexts = 8;
  3038. rdev->config.evergreen.sq_num_cf_insts = 2;
  3039. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3040. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3041. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3042. gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
  3043. break;
  3044. case CHIP_CEDAR:
  3045. default:
  3046. rdev->config.evergreen.num_ses = 1;
  3047. rdev->config.evergreen.max_pipes = 2;
  3048. rdev->config.evergreen.max_tile_pipes = 2;
  3049. rdev->config.evergreen.max_simds = 2;
  3050. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3051. rdev->config.evergreen.max_gprs = 256;
  3052. rdev->config.evergreen.max_threads = 192;
  3053. rdev->config.evergreen.max_gs_threads = 16;
  3054. rdev->config.evergreen.max_stack_entries = 256;
  3055. rdev->config.evergreen.sx_num_of_sets = 4;
  3056. rdev->config.evergreen.sx_max_export_size = 128;
  3057. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3058. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3059. rdev->config.evergreen.max_hw_contexts = 4;
  3060. rdev->config.evergreen.sq_num_cf_insts = 1;
  3061. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3062. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3063. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3064. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  3065. break;
  3066. case CHIP_PALM:
  3067. rdev->config.evergreen.num_ses = 1;
  3068. rdev->config.evergreen.max_pipes = 2;
  3069. rdev->config.evergreen.max_tile_pipes = 2;
  3070. rdev->config.evergreen.max_simds = 2;
  3071. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3072. rdev->config.evergreen.max_gprs = 256;
  3073. rdev->config.evergreen.max_threads = 192;
  3074. rdev->config.evergreen.max_gs_threads = 16;
  3075. rdev->config.evergreen.max_stack_entries = 256;
  3076. rdev->config.evergreen.sx_num_of_sets = 4;
  3077. rdev->config.evergreen.sx_max_export_size = 128;
  3078. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3079. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3080. rdev->config.evergreen.max_hw_contexts = 4;
  3081. rdev->config.evergreen.sq_num_cf_insts = 1;
  3082. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3083. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3084. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3085. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  3086. break;
  3087. case CHIP_SUMO:
  3088. rdev->config.evergreen.num_ses = 1;
  3089. rdev->config.evergreen.max_pipes = 4;
  3090. rdev->config.evergreen.max_tile_pipes = 4;
  3091. if (rdev->pdev->device == 0x9648)
  3092. rdev->config.evergreen.max_simds = 3;
  3093. else if ((rdev->pdev->device == 0x9647) ||
  3094. (rdev->pdev->device == 0x964a))
  3095. rdev->config.evergreen.max_simds = 4;
  3096. else
  3097. rdev->config.evergreen.max_simds = 5;
  3098. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3099. rdev->config.evergreen.max_gprs = 256;
  3100. rdev->config.evergreen.max_threads = 248;
  3101. rdev->config.evergreen.max_gs_threads = 32;
  3102. rdev->config.evergreen.max_stack_entries = 256;
  3103. rdev->config.evergreen.sx_num_of_sets = 4;
  3104. rdev->config.evergreen.sx_max_export_size = 256;
  3105. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3106. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3107. rdev->config.evergreen.max_hw_contexts = 8;
  3108. rdev->config.evergreen.sq_num_cf_insts = 2;
  3109. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3110. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3111. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3112. gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
  3113. break;
  3114. case CHIP_SUMO2:
  3115. rdev->config.evergreen.num_ses = 1;
  3116. rdev->config.evergreen.max_pipes = 4;
  3117. rdev->config.evergreen.max_tile_pipes = 4;
  3118. rdev->config.evergreen.max_simds = 2;
  3119. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3120. rdev->config.evergreen.max_gprs = 256;
  3121. rdev->config.evergreen.max_threads = 248;
  3122. rdev->config.evergreen.max_gs_threads = 32;
  3123. rdev->config.evergreen.max_stack_entries = 512;
  3124. rdev->config.evergreen.sx_num_of_sets = 4;
  3125. rdev->config.evergreen.sx_max_export_size = 256;
  3126. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3127. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3128. rdev->config.evergreen.max_hw_contexts = 4;
  3129. rdev->config.evergreen.sq_num_cf_insts = 2;
  3130. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3131. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3132. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3133. gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
  3134. break;
  3135. case CHIP_BARTS:
  3136. rdev->config.evergreen.num_ses = 2;
  3137. rdev->config.evergreen.max_pipes = 4;
  3138. rdev->config.evergreen.max_tile_pipes = 8;
  3139. rdev->config.evergreen.max_simds = 7;
  3140. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  3141. rdev->config.evergreen.max_gprs = 256;
  3142. rdev->config.evergreen.max_threads = 248;
  3143. rdev->config.evergreen.max_gs_threads = 32;
  3144. rdev->config.evergreen.max_stack_entries = 512;
  3145. rdev->config.evergreen.sx_num_of_sets = 4;
  3146. rdev->config.evergreen.sx_max_export_size = 256;
  3147. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3148. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3149. rdev->config.evergreen.max_hw_contexts = 8;
  3150. rdev->config.evergreen.sq_num_cf_insts = 2;
  3151. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3152. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3153. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3154. gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
  3155. break;
  3156. case CHIP_TURKS:
  3157. rdev->config.evergreen.num_ses = 1;
  3158. rdev->config.evergreen.max_pipes = 4;
  3159. rdev->config.evergreen.max_tile_pipes = 4;
  3160. rdev->config.evergreen.max_simds = 6;
  3161. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3162. rdev->config.evergreen.max_gprs = 256;
  3163. rdev->config.evergreen.max_threads = 248;
  3164. rdev->config.evergreen.max_gs_threads = 32;
  3165. rdev->config.evergreen.max_stack_entries = 256;
  3166. rdev->config.evergreen.sx_num_of_sets = 4;
  3167. rdev->config.evergreen.sx_max_export_size = 256;
  3168. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3169. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3170. rdev->config.evergreen.max_hw_contexts = 8;
  3171. rdev->config.evergreen.sq_num_cf_insts = 2;
  3172. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3173. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3174. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3175. gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
  3176. break;
  3177. case CHIP_CAICOS:
  3178. rdev->config.evergreen.num_ses = 1;
  3179. rdev->config.evergreen.max_pipes = 2;
  3180. rdev->config.evergreen.max_tile_pipes = 2;
  3181. rdev->config.evergreen.max_simds = 2;
  3182. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3183. rdev->config.evergreen.max_gprs = 256;
  3184. rdev->config.evergreen.max_threads = 192;
  3185. rdev->config.evergreen.max_gs_threads = 16;
  3186. rdev->config.evergreen.max_stack_entries = 256;
  3187. rdev->config.evergreen.sx_num_of_sets = 4;
  3188. rdev->config.evergreen.sx_max_export_size = 128;
  3189. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3190. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3191. rdev->config.evergreen.max_hw_contexts = 4;
  3192. rdev->config.evergreen.sq_num_cf_insts = 1;
  3193. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3194. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3195. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3196. gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
  3197. break;
  3198. }
  3199. /* Initialize HDP */
  3200. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3201. WREG32((0x2c14 + j), 0x00000000);
  3202. WREG32((0x2c18 + j), 0x00000000);
  3203. WREG32((0x2c1c + j), 0x00000000);
  3204. WREG32((0x2c20 + j), 0x00000000);
  3205. WREG32((0x2c24 + j), 0x00000000);
  3206. }
  3207. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  3208. WREG32(SRBM_INT_CNTL, 0x1);
  3209. WREG32(SRBM_INT_ACK, 0x1);
  3210. evergreen_fix_pci_max_read_req_size(rdev);
  3211. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  3212. if ((rdev->family == CHIP_PALM) ||
  3213. (rdev->family == CHIP_SUMO) ||
  3214. (rdev->family == CHIP_SUMO2))
  3215. mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
  3216. else
  3217. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  3218. /* setup tiling info dword. gb_addr_config is not adequate since it does
  3219. * not have bank info, so create a custom tiling dword.
  3220. * bits 3:0 num_pipes
  3221. * bits 7:4 num_banks
  3222. * bits 11:8 group_size
  3223. * bits 15:12 row_size
  3224. */
  3225. rdev->config.evergreen.tile_config = 0;
  3226. switch (rdev->config.evergreen.max_tile_pipes) {
  3227. case 1:
  3228. default:
  3229. rdev->config.evergreen.tile_config |= (0 << 0);
  3230. break;
  3231. case 2:
  3232. rdev->config.evergreen.tile_config |= (1 << 0);
  3233. break;
  3234. case 4:
  3235. rdev->config.evergreen.tile_config |= (2 << 0);
  3236. break;
  3237. case 8:
  3238. rdev->config.evergreen.tile_config |= (3 << 0);
  3239. break;
  3240. }
  3241. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  3242. if (rdev->flags & RADEON_IS_IGP)
  3243. rdev->config.evergreen.tile_config |= 1 << 4;
  3244. else {
  3245. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  3246. case 0: /* four banks */
  3247. rdev->config.evergreen.tile_config |= 0 << 4;
  3248. break;
  3249. case 1: /* eight banks */
  3250. rdev->config.evergreen.tile_config |= 1 << 4;
  3251. break;
  3252. case 2: /* sixteen banks */
  3253. default:
  3254. rdev->config.evergreen.tile_config |= 2 << 4;
  3255. break;
  3256. }
  3257. }
  3258. rdev->config.evergreen.tile_config |= 0 << 8;
  3259. rdev->config.evergreen.tile_config |=
  3260. ((gb_addr_config & 0x30000000) >> 28) << 12;
  3261. if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
  3262. u32 efuse_straps_4;
  3263. u32 efuse_straps_3;
  3264. efuse_straps_4 = RREG32_RCU(0x204);
  3265. efuse_straps_3 = RREG32_RCU(0x203);
  3266. tmp = (((efuse_straps_4 & 0xf) << 4) |
  3267. ((efuse_straps_3 & 0xf0000000) >> 28));
  3268. } else {
  3269. tmp = 0;
  3270. for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
  3271. u32 rb_disable_bitmap;
  3272. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3273. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3274. rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
  3275. tmp <<= 4;
  3276. tmp |= rb_disable_bitmap;
  3277. }
  3278. }
  3279. /* enabled rb are just the one not disabled :) */
  3280. disabled_rb_mask = tmp;
  3281. tmp = 0;
  3282. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3283. tmp |= (1 << i);
  3284. /* if all the backends are disabled, fix it up here */
  3285. if ((disabled_rb_mask & tmp) == tmp) {
  3286. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3287. disabled_rb_mask &= ~(1 << i);
  3288. }
  3289. for (i = 0; i < rdev->config.evergreen.num_ses; i++) {
  3290. u32 simd_disable_bitmap;
  3291. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3292. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3293. simd_disable_bitmap = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  3294. simd_disable_bitmap |= 0xffffffff << rdev->config.evergreen.max_simds;
  3295. tmp <<= 16;
  3296. tmp |= simd_disable_bitmap;
  3297. }
  3298. rdev->config.evergreen.active_simds = hweight32(~tmp);
  3299. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3300. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3301. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  3302. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  3303. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  3304. WREG32(DMA_TILING_CONFIG, gb_addr_config);
  3305. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  3306. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  3307. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  3308. if ((rdev->config.evergreen.max_backends == 1) &&
  3309. (rdev->flags & RADEON_IS_IGP)) {
  3310. if ((disabled_rb_mask & 3) == 1) {
  3311. /* RB0 disabled, RB1 enabled */
  3312. tmp = 0x11111111;
  3313. } else {
  3314. /* RB1 disabled, RB0 enabled */
  3315. tmp = 0x00000000;
  3316. }
  3317. } else {
  3318. tmp = gb_addr_config & NUM_PIPES_MASK;
  3319. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
  3320. EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
  3321. }
  3322. WREG32(GB_BACKEND_MAP, tmp);
  3323. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  3324. WREG32(CGTS_TCC_DISABLE, 0);
  3325. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  3326. WREG32(CGTS_USER_TCC_DISABLE, 0);
  3327. /* set HW defaults for 3D engine */
  3328. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  3329. ROQ_IB2_START(0x2b)));
  3330. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  3331. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
  3332. SYNC_GRADIENT |
  3333. SYNC_WALKER |
  3334. SYNC_ALIGNER));
  3335. sx_debug_1 = RREG32(SX_DEBUG_1);
  3336. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  3337. WREG32(SX_DEBUG_1, sx_debug_1);
  3338. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  3339. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  3340. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
  3341. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  3342. if (rdev->family <= CHIP_SUMO2)
  3343. WREG32(SMX_SAR_CTL0, 0x00010000);
  3344. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
  3345. POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
  3346. SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
  3347. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
  3348. SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
  3349. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
  3350. WREG32(VGT_NUM_INSTANCES, 1);
  3351. WREG32(SPI_CONFIG_CNTL, 0);
  3352. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  3353. WREG32(CP_PERFMON_CNTL, 0);
  3354. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
  3355. FETCH_FIFO_HIWATER(0x4) |
  3356. DONE_FIFO_HIWATER(0xe0) |
  3357. ALU_UPDATE_FIFO_HIWATER(0x8)));
  3358. sq_config = RREG32(SQ_CONFIG);
  3359. sq_config &= ~(PS_PRIO(3) |
  3360. VS_PRIO(3) |
  3361. GS_PRIO(3) |
  3362. ES_PRIO(3));
  3363. sq_config |= (VC_ENABLE |
  3364. EXPORT_SRC_C |
  3365. PS_PRIO(0) |
  3366. VS_PRIO(1) |
  3367. GS_PRIO(2) |
  3368. ES_PRIO(3));
  3369. switch (rdev->family) {
  3370. case CHIP_CEDAR:
  3371. case CHIP_PALM:
  3372. case CHIP_SUMO:
  3373. case CHIP_SUMO2:
  3374. case CHIP_CAICOS:
  3375. /* no vertex cache */
  3376. sq_config &= ~VC_ENABLE;
  3377. break;
  3378. default:
  3379. break;
  3380. }
  3381. sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
  3382. sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
  3383. sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
  3384. sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
  3385. sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3386. sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3387. sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3388. sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3389. switch (rdev->family) {
  3390. case CHIP_CEDAR:
  3391. case CHIP_PALM:
  3392. case CHIP_SUMO:
  3393. case CHIP_SUMO2:
  3394. ps_thread_count = 96;
  3395. break;
  3396. default:
  3397. ps_thread_count = 128;
  3398. break;
  3399. }
  3400. sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
  3401. sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3402. sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3403. sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3404. sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3405. sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3406. sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3407. sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3408. sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3409. sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3410. sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3411. sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3412. WREG32(SQ_CONFIG, sq_config);
  3413. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  3414. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  3415. WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
  3416. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  3417. WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
  3418. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  3419. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  3420. WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
  3421. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
  3422. WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
  3423. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  3424. FORCE_EOV_MAX_REZ_CNT(255)));
  3425. switch (rdev->family) {
  3426. case CHIP_CEDAR:
  3427. case CHIP_PALM:
  3428. case CHIP_SUMO:
  3429. case CHIP_SUMO2:
  3430. case CHIP_CAICOS:
  3431. vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
  3432. break;
  3433. default:
  3434. vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
  3435. break;
  3436. }
  3437. vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
  3438. WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
  3439. WREG32(VGT_GS_VERTEX_REUSE, 16);
  3440. WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
  3441. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  3442. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
  3443. WREG32(VGT_OUT_DEALLOC_CNTL, 16);
  3444. WREG32(CB_PERF_CTR0_SEL_0, 0);
  3445. WREG32(CB_PERF_CTR0_SEL_1, 0);
  3446. WREG32(CB_PERF_CTR1_SEL_0, 0);
  3447. WREG32(CB_PERF_CTR1_SEL_1, 0);
  3448. WREG32(CB_PERF_CTR2_SEL_0, 0);
  3449. WREG32(CB_PERF_CTR2_SEL_1, 0);
  3450. WREG32(CB_PERF_CTR3_SEL_0, 0);
  3451. WREG32(CB_PERF_CTR3_SEL_1, 0);
  3452. /* clear render buffer base addresses */
  3453. WREG32(CB_COLOR0_BASE, 0);
  3454. WREG32(CB_COLOR1_BASE, 0);
  3455. WREG32(CB_COLOR2_BASE, 0);
  3456. WREG32(CB_COLOR3_BASE, 0);
  3457. WREG32(CB_COLOR4_BASE, 0);
  3458. WREG32(CB_COLOR5_BASE, 0);
  3459. WREG32(CB_COLOR6_BASE, 0);
  3460. WREG32(CB_COLOR7_BASE, 0);
  3461. WREG32(CB_COLOR8_BASE, 0);
  3462. WREG32(CB_COLOR9_BASE, 0);
  3463. WREG32(CB_COLOR10_BASE, 0);
  3464. WREG32(CB_COLOR11_BASE, 0);
  3465. /* set the shader const cache sizes to 0 */
  3466. for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
  3467. WREG32(i, 0);
  3468. for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
  3469. WREG32(i, 0);
  3470. tmp = RREG32(HDP_MISC_CNTL);
  3471. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  3472. WREG32(HDP_MISC_CNTL, tmp);
  3473. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  3474. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  3475. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  3476. udelay(50);
  3477. }
  3478. int evergreen_mc_init(struct radeon_device *rdev)
  3479. {
  3480. u32 tmp;
  3481. int chansize, numchan;
  3482. /* Get VRAM informations */
  3483. rdev->mc.vram_is_ddr = true;
  3484. if ((rdev->family == CHIP_PALM) ||
  3485. (rdev->family == CHIP_SUMO) ||
  3486. (rdev->family == CHIP_SUMO2))
  3487. tmp = RREG32(FUS_MC_ARB_RAMCFG);
  3488. else
  3489. tmp = RREG32(MC_ARB_RAMCFG);
  3490. if (tmp & CHANSIZE_OVERRIDE) {
  3491. chansize = 16;
  3492. } else if (tmp & CHANSIZE_MASK) {
  3493. chansize = 64;
  3494. } else {
  3495. chansize = 32;
  3496. }
  3497. tmp = RREG32(MC_SHARED_CHMAP);
  3498. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3499. case 0:
  3500. default:
  3501. numchan = 1;
  3502. break;
  3503. case 1:
  3504. numchan = 2;
  3505. break;
  3506. case 2:
  3507. numchan = 4;
  3508. break;
  3509. case 3:
  3510. numchan = 8;
  3511. break;
  3512. }
  3513. rdev->mc.vram_width = numchan * chansize;
  3514. /* Could aper size report 0 ? */
  3515. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3516. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3517. /* Setup GPU memory space */
  3518. if ((rdev->family == CHIP_PALM) ||
  3519. (rdev->family == CHIP_SUMO) ||
  3520. (rdev->family == CHIP_SUMO2)) {
  3521. /* size in bytes on fusion */
  3522. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  3523. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  3524. } else {
  3525. /* size in MB on evergreen/cayman/tn */
  3526. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3527. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3528. }
  3529. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3530. r700_vram_gtt_location(rdev, &rdev->mc);
  3531. radeon_update_bandwidth_info(rdev);
  3532. return 0;
  3533. }
  3534. void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
  3535. {
  3536. dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
  3537. RREG32(GRBM_STATUS));
  3538. dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
  3539. RREG32(GRBM_STATUS_SE0));
  3540. dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
  3541. RREG32(GRBM_STATUS_SE1));
  3542. dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
  3543. RREG32(SRBM_STATUS));
  3544. dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
  3545. RREG32(SRBM_STATUS2));
  3546. dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
  3547. RREG32(CP_STALLED_STAT1));
  3548. dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
  3549. RREG32(CP_STALLED_STAT2));
  3550. dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
  3551. RREG32(CP_BUSY_STAT));
  3552. dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
  3553. RREG32(CP_STAT));
  3554. dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
  3555. RREG32(DMA_STATUS_REG));
  3556. if (rdev->family >= CHIP_CAYMAN) {
  3557. dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
  3558. RREG32(DMA_STATUS_REG + 0x800));
  3559. }
  3560. }
  3561. bool evergreen_is_display_hung(struct radeon_device *rdev)
  3562. {
  3563. u32 crtc_hung = 0;
  3564. u32 crtc_status[6];
  3565. u32 i, j, tmp;
  3566. for (i = 0; i < rdev->num_crtc; i++) {
  3567. if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
  3568. crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3569. crtc_hung |= (1 << i);
  3570. }
  3571. }
  3572. for (j = 0; j < 10; j++) {
  3573. for (i = 0; i < rdev->num_crtc; i++) {
  3574. if (crtc_hung & (1 << i)) {
  3575. tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3576. if (tmp != crtc_status[i])
  3577. crtc_hung &= ~(1 << i);
  3578. }
  3579. }
  3580. if (crtc_hung == 0)
  3581. return false;
  3582. udelay(100);
  3583. }
  3584. return true;
  3585. }
  3586. u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
  3587. {
  3588. u32 reset_mask = 0;
  3589. u32 tmp;
  3590. /* GRBM_STATUS */
  3591. tmp = RREG32(GRBM_STATUS);
  3592. if (tmp & (PA_BUSY | SC_BUSY |
  3593. SH_BUSY | SX_BUSY |
  3594. TA_BUSY | VGT_BUSY |
  3595. DB_BUSY | CB_BUSY |
  3596. SPI_BUSY | VGT_BUSY_NO_DMA))
  3597. reset_mask |= RADEON_RESET_GFX;
  3598. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3599. CP_BUSY | CP_COHERENCY_BUSY))
  3600. reset_mask |= RADEON_RESET_CP;
  3601. if (tmp & GRBM_EE_BUSY)
  3602. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3603. /* DMA_STATUS_REG */
  3604. tmp = RREG32(DMA_STATUS_REG);
  3605. if (!(tmp & DMA_IDLE))
  3606. reset_mask |= RADEON_RESET_DMA;
  3607. /* SRBM_STATUS2 */
  3608. tmp = RREG32(SRBM_STATUS2);
  3609. if (tmp & DMA_BUSY)
  3610. reset_mask |= RADEON_RESET_DMA;
  3611. /* SRBM_STATUS */
  3612. tmp = RREG32(SRBM_STATUS);
  3613. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3614. reset_mask |= RADEON_RESET_RLC;
  3615. if (tmp & IH_BUSY)
  3616. reset_mask |= RADEON_RESET_IH;
  3617. if (tmp & SEM_BUSY)
  3618. reset_mask |= RADEON_RESET_SEM;
  3619. if (tmp & GRBM_RQ_PENDING)
  3620. reset_mask |= RADEON_RESET_GRBM;
  3621. if (tmp & VMC_BUSY)
  3622. reset_mask |= RADEON_RESET_VMC;
  3623. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3624. MCC_BUSY | MCD_BUSY))
  3625. reset_mask |= RADEON_RESET_MC;
  3626. if (evergreen_is_display_hung(rdev))
  3627. reset_mask |= RADEON_RESET_DISPLAY;
  3628. /* VM_L2_STATUS */
  3629. tmp = RREG32(VM_L2_STATUS);
  3630. if (tmp & L2_BUSY)
  3631. reset_mask |= RADEON_RESET_VMC;
  3632. /* Skip MC reset as it's mostly likely not hung, just busy */
  3633. if (reset_mask & RADEON_RESET_MC) {
  3634. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3635. reset_mask &= ~RADEON_RESET_MC;
  3636. }
  3637. return reset_mask;
  3638. }
  3639. static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3640. {
  3641. struct evergreen_mc_save save;
  3642. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3643. u32 tmp;
  3644. if (reset_mask == 0)
  3645. return;
  3646. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3647. evergreen_print_gpu_status_regs(rdev);
  3648. /* Disable CP parsing/prefetching */
  3649. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3650. if (reset_mask & RADEON_RESET_DMA) {
  3651. /* Disable DMA */
  3652. tmp = RREG32(DMA_RB_CNTL);
  3653. tmp &= ~DMA_RB_ENABLE;
  3654. WREG32(DMA_RB_CNTL, tmp);
  3655. }
  3656. udelay(50);
  3657. evergreen_mc_stop(rdev, &save);
  3658. if (evergreen_mc_wait_for_idle(rdev)) {
  3659. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3660. }
  3661. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  3662. grbm_soft_reset |= SOFT_RESET_DB |
  3663. SOFT_RESET_CB |
  3664. SOFT_RESET_PA |
  3665. SOFT_RESET_SC |
  3666. SOFT_RESET_SPI |
  3667. SOFT_RESET_SX |
  3668. SOFT_RESET_SH |
  3669. SOFT_RESET_TC |
  3670. SOFT_RESET_TA |
  3671. SOFT_RESET_VC |
  3672. SOFT_RESET_VGT;
  3673. }
  3674. if (reset_mask & RADEON_RESET_CP) {
  3675. grbm_soft_reset |= SOFT_RESET_CP |
  3676. SOFT_RESET_VGT;
  3677. srbm_soft_reset |= SOFT_RESET_GRBM;
  3678. }
  3679. if (reset_mask & RADEON_RESET_DMA)
  3680. srbm_soft_reset |= SOFT_RESET_DMA;
  3681. if (reset_mask & RADEON_RESET_DISPLAY)
  3682. srbm_soft_reset |= SOFT_RESET_DC;
  3683. if (reset_mask & RADEON_RESET_RLC)
  3684. srbm_soft_reset |= SOFT_RESET_RLC;
  3685. if (reset_mask & RADEON_RESET_SEM)
  3686. srbm_soft_reset |= SOFT_RESET_SEM;
  3687. if (reset_mask & RADEON_RESET_IH)
  3688. srbm_soft_reset |= SOFT_RESET_IH;
  3689. if (reset_mask & RADEON_RESET_GRBM)
  3690. srbm_soft_reset |= SOFT_RESET_GRBM;
  3691. if (reset_mask & RADEON_RESET_VMC)
  3692. srbm_soft_reset |= SOFT_RESET_VMC;
  3693. if (!(rdev->flags & RADEON_IS_IGP)) {
  3694. if (reset_mask & RADEON_RESET_MC)
  3695. srbm_soft_reset |= SOFT_RESET_MC;
  3696. }
  3697. if (grbm_soft_reset) {
  3698. tmp = RREG32(GRBM_SOFT_RESET);
  3699. tmp |= grbm_soft_reset;
  3700. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3701. WREG32(GRBM_SOFT_RESET, tmp);
  3702. tmp = RREG32(GRBM_SOFT_RESET);
  3703. udelay(50);
  3704. tmp &= ~grbm_soft_reset;
  3705. WREG32(GRBM_SOFT_RESET, tmp);
  3706. tmp = RREG32(GRBM_SOFT_RESET);
  3707. }
  3708. if (srbm_soft_reset) {
  3709. tmp = RREG32(SRBM_SOFT_RESET);
  3710. tmp |= srbm_soft_reset;
  3711. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3712. WREG32(SRBM_SOFT_RESET, tmp);
  3713. tmp = RREG32(SRBM_SOFT_RESET);
  3714. udelay(50);
  3715. tmp &= ~srbm_soft_reset;
  3716. WREG32(SRBM_SOFT_RESET, tmp);
  3717. tmp = RREG32(SRBM_SOFT_RESET);
  3718. }
  3719. /* Wait a little for things to settle down */
  3720. udelay(50);
  3721. evergreen_mc_resume(rdev, &save);
  3722. udelay(50);
  3723. evergreen_print_gpu_status_regs(rdev);
  3724. }
  3725. void evergreen_gpu_pci_config_reset(struct radeon_device *rdev)
  3726. {
  3727. struct evergreen_mc_save save;
  3728. u32 tmp, i;
  3729. dev_info(rdev->dev, "GPU pci config reset\n");
  3730. /* disable dpm? */
  3731. /* Disable CP parsing/prefetching */
  3732. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3733. udelay(50);
  3734. /* Disable DMA */
  3735. tmp = RREG32(DMA_RB_CNTL);
  3736. tmp &= ~DMA_RB_ENABLE;
  3737. WREG32(DMA_RB_CNTL, tmp);
  3738. /* XXX other engines? */
  3739. /* halt the rlc */
  3740. r600_rlc_stop(rdev);
  3741. udelay(50);
  3742. /* set mclk/sclk to bypass */
  3743. rv770_set_clk_bypass_mode(rdev);
  3744. /* disable BM */
  3745. pci_clear_master(rdev->pdev);
  3746. /* disable mem access */
  3747. evergreen_mc_stop(rdev, &save);
  3748. if (evergreen_mc_wait_for_idle(rdev)) {
  3749. dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
  3750. }
  3751. /* reset */
  3752. radeon_pci_config_reset(rdev);
  3753. /* wait for asic to come out of reset */
  3754. for (i = 0; i < rdev->usec_timeout; i++) {
  3755. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  3756. break;
  3757. udelay(1);
  3758. }
  3759. }
  3760. int evergreen_asic_reset(struct radeon_device *rdev, bool hard)
  3761. {
  3762. u32 reset_mask;
  3763. if (hard) {
  3764. evergreen_gpu_pci_config_reset(rdev);
  3765. return 0;
  3766. }
  3767. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3768. if (reset_mask)
  3769. r600_set_bios_scratch_engine_hung(rdev, true);
  3770. /* try soft reset */
  3771. evergreen_gpu_soft_reset(rdev, reset_mask);
  3772. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3773. /* try pci config reset */
  3774. if (reset_mask && radeon_hard_reset)
  3775. evergreen_gpu_pci_config_reset(rdev);
  3776. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3777. if (!reset_mask)
  3778. r600_set_bios_scratch_engine_hung(rdev, false);
  3779. return 0;
  3780. }
  3781. /**
  3782. * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
  3783. *
  3784. * @rdev: radeon_device pointer
  3785. * @ring: radeon_ring structure holding ring information
  3786. *
  3787. * Check if the GFX engine is locked up.
  3788. * Returns true if the engine appears to be locked up, false if not.
  3789. */
  3790. bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3791. {
  3792. u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3793. if (!(reset_mask & (RADEON_RESET_GFX |
  3794. RADEON_RESET_COMPUTE |
  3795. RADEON_RESET_CP))) {
  3796. radeon_ring_lockup_update(rdev, ring);
  3797. return false;
  3798. }
  3799. return radeon_ring_test_lockup(rdev, ring);
  3800. }
  3801. /*
  3802. * RLC
  3803. */
  3804. #define RLC_SAVE_RESTORE_LIST_END_MARKER 0x00000000
  3805. #define RLC_CLEAR_STATE_END_MARKER 0x00000001
  3806. void sumo_rlc_fini(struct radeon_device *rdev)
  3807. {
  3808. int r;
  3809. /* save restore block */
  3810. if (rdev->rlc.save_restore_obj) {
  3811. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3812. if (unlikely(r != 0))
  3813. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3814. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3815. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3816. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3817. rdev->rlc.save_restore_obj = NULL;
  3818. }
  3819. /* clear state block */
  3820. if (rdev->rlc.clear_state_obj) {
  3821. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3822. if (unlikely(r != 0))
  3823. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3824. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3825. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3826. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3827. rdev->rlc.clear_state_obj = NULL;
  3828. }
  3829. /* clear state block */
  3830. if (rdev->rlc.cp_table_obj) {
  3831. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3832. if (unlikely(r != 0))
  3833. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3834. radeon_bo_unpin(rdev->rlc.cp_table_obj);
  3835. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3836. radeon_bo_unref(&rdev->rlc.cp_table_obj);
  3837. rdev->rlc.cp_table_obj = NULL;
  3838. }
  3839. }
  3840. #define CP_ME_TABLE_SIZE 96
  3841. int sumo_rlc_init(struct radeon_device *rdev)
  3842. {
  3843. const u32 *src_ptr;
  3844. volatile u32 *dst_ptr;
  3845. u32 dws, data, i, j, k, reg_num;
  3846. u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index = 0;
  3847. u64 reg_list_mc_addr;
  3848. const struct cs_section_def *cs_data;
  3849. int r;
  3850. src_ptr = rdev->rlc.reg_list;
  3851. dws = rdev->rlc.reg_list_size;
  3852. if (rdev->family >= CHIP_BONAIRE) {
  3853. dws += (5 * 16) + 48 + 48 + 64;
  3854. }
  3855. cs_data = rdev->rlc.cs_data;
  3856. if (src_ptr) {
  3857. /* save restore block */
  3858. if (rdev->rlc.save_restore_obj == NULL) {
  3859. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3860. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3861. NULL, &rdev->rlc.save_restore_obj);
  3862. if (r) {
  3863. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3864. return r;
  3865. }
  3866. }
  3867. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3868. if (unlikely(r != 0)) {
  3869. sumo_rlc_fini(rdev);
  3870. return r;
  3871. }
  3872. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3873. &rdev->rlc.save_restore_gpu_addr);
  3874. if (r) {
  3875. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3876. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3877. sumo_rlc_fini(rdev);
  3878. return r;
  3879. }
  3880. r = radeon_bo_kmap(rdev->rlc.save_restore_obj, (void **)&rdev->rlc.sr_ptr);
  3881. if (r) {
  3882. dev_warn(rdev->dev, "(%d) map RLC sr bo failed\n", r);
  3883. sumo_rlc_fini(rdev);
  3884. return r;
  3885. }
  3886. /* write the sr buffer */
  3887. dst_ptr = rdev->rlc.sr_ptr;
  3888. if (rdev->family >= CHIP_TAHITI) {
  3889. /* SI */
  3890. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  3891. dst_ptr[i] = cpu_to_le32(src_ptr[i]);
  3892. } else {
  3893. /* ON/LN/TN */
  3894. /* format:
  3895. * dw0: (reg2 << 16) | reg1
  3896. * dw1: reg1 save space
  3897. * dw2: reg2 save space
  3898. */
  3899. for (i = 0; i < dws; i++) {
  3900. data = src_ptr[i] >> 2;
  3901. i++;
  3902. if (i < dws)
  3903. data |= (src_ptr[i] >> 2) << 16;
  3904. j = (((i - 1) * 3) / 2);
  3905. dst_ptr[j] = cpu_to_le32(data);
  3906. }
  3907. j = ((i * 3) / 2);
  3908. dst_ptr[j] = cpu_to_le32(RLC_SAVE_RESTORE_LIST_END_MARKER);
  3909. }
  3910. radeon_bo_kunmap(rdev->rlc.save_restore_obj);
  3911. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3912. }
  3913. if (cs_data) {
  3914. /* clear state block */
  3915. if (rdev->family >= CHIP_BONAIRE) {
  3916. rdev->rlc.clear_state_size = dws = cik_get_csb_size(rdev);
  3917. } else if (rdev->family >= CHIP_TAHITI) {
  3918. rdev->rlc.clear_state_size = si_get_csb_size(rdev);
  3919. dws = rdev->rlc.clear_state_size + (256 / 4);
  3920. } else {
  3921. reg_list_num = 0;
  3922. dws = 0;
  3923. for (i = 0; cs_data[i].section != NULL; i++) {
  3924. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3925. reg_list_num++;
  3926. dws += cs_data[i].section[j].reg_count;
  3927. }
  3928. }
  3929. reg_list_blk_index = (3 * reg_list_num + 2);
  3930. dws += reg_list_blk_index;
  3931. rdev->rlc.clear_state_size = dws;
  3932. }
  3933. if (rdev->rlc.clear_state_obj == NULL) {
  3934. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3935. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3936. NULL, &rdev->rlc.clear_state_obj);
  3937. if (r) {
  3938. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3939. sumo_rlc_fini(rdev);
  3940. return r;
  3941. }
  3942. }
  3943. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3944. if (unlikely(r != 0)) {
  3945. sumo_rlc_fini(rdev);
  3946. return r;
  3947. }
  3948. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3949. &rdev->rlc.clear_state_gpu_addr);
  3950. if (r) {
  3951. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3952. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3953. sumo_rlc_fini(rdev);
  3954. return r;
  3955. }
  3956. r = radeon_bo_kmap(rdev->rlc.clear_state_obj, (void **)&rdev->rlc.cs_ptr);
  3957. if (r) {
  3958. dev_warn(rdev->dev, "(%d) map RLC c bo failed\n", r);
  3959. sumo_rlc_fini(rdev);
  3960. return r;
  3961. }
  3962. /* set up the cs buffer */
  3963. dst_ptr = rdev->rlc.cs_ptr;
  3964. if (rdev->family >= CHIP_BONAIRE) {
  3965. cik_get_csb_buffer(rdev, dst_ptr);
  3966. } else if (rdev->family >= CHIP_TAHITI) {
  3967. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + 256;
  3968. dst_ptr[0] = cpu_to_le32(upper_32_bits(reg_list_mc_addr));
  3969. dst_ptr[1] = cpu_to_le32(lower_32_bits(reg_list_mc_addr));
  3970. dst_ptr[2] = cpu_to_le32(rdev->rlc.clear_state_size);
  3971. si_get_csb_buffer(rdev, &dst_ptr[(256/4)]);
  3972. } else {
  3973. reg_list_hdr_blk_index = 0;
  3974. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + (reg_list_blk_index * 4);
  3975. data = upper_32_bits(reg_list_mc_addr);
  3976. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3977. reg_list_hdr_blk_index++;
  3978. for (i = 0; cs_data[i].section != NULL; i++) {
  3979. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3980. reg_num = cs_data[i].section[j].reg_count;
  3981. data = reg_list_mc_addr & 0xffffffff;
  3982. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3983. reg_list_hdr_blk_index++;
  3984. data = (cs_data[i].section[j].reg_index * 4) & 0xffffffff;
  3985. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3986. reg_list_hdr_blk_index++;
  3987. data = 0x08000000 | (reg_num * 4);
  3988. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3989. reg_list_hdr_blk_index++;
  3990. for (k = 0; k < reg_num; k++) {
  3991. data = cs_data[i].section[j].extent[k];
  3992. dst_ptr[reg_list_blk_index + k] = cpu_to_le32(data);
  3993. }
  3994. reg_list_mc_addr += reg_num * 4;
  3995. reg_list_blk_index += reg_num;
  3996. }
  3997. }
  3998. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(RLC_CLEAR_STATE_END_MARKER);
  3999. }
  4000. radeon_bo_kunmap(rdev->rlc.clear_state_obj);
  4001. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  4002. }
  4003. if (rdev->rlc.cp_table_size) {
  4004. if (rdev->rlc.cp_table_obj == NULL) {
  4005. r = radeon_bo_create(rdev, rdev->rlc.cp_table_size,
  4006. PAGE_SIZE, true,
  4007. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  4008. NULL, &rdev->rlc.cp_table_obj);
  4009. if (r) {
  4010. dev_warn(rdev->dev, "(%d) create RLC cp table bo failed\n", r);
  4011. sumo_rlc_fini(rdev);
  4012. return r;
  4013. }
  4014. }
  4015. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  4016. if (unlikely(r != 0)) {
  4017. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  4018. sumo_rlc_fini(rdev);
  4019. return r;
  4020. }
  4021. r = radeon_bo_pin(rdev->rlc.cp_table_obj, RADEON_GEM_DOMAIN_VRAM,
  4022. &rdev->rlc.cp_table_gpu_addr);
  4023. if (r) {
  4024. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  4025. dev_warn(rdev->dev, "(%d) pin RLC cp_table bo failed\n", r);
  4026. sumo_rlc_fini(rdev);
  4027. return r;
  4028. }
  4029. r = radeon_bo_kmap(rdev->rlc.cp_table_obj, (void **)&rdev->rlc.cp_table_ptr);
  4030. if (r) {
  4031. dev_warn(rdev->dev, "(%d) map RLC cp table bo failed\n", r);
  4032. sumo_rlc_fini(rdev);
  4033. return r;
  4034. }
  4035. cik_init_cp_pg_table(rdev);
  4036. radeon_bo_kunmap(rdev->rlc.cp_table_obj);
  4037. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  4038. }
  4039. return 0;
  4040. }
  4041. static void evergreen_rlc_start(struct radeon_device *rdev)
  4042. {
  4043. u32 mask = RLC_ENABLE;
  4044. if (rdev->flags & RADEON_IS_IGP) {
  4045. mask |= GFX_POWER_GATING_ENABLE | GFX_POWER_GATING_SRC;
  4046. }
  4047. WREG32(RLC_CNTL, mask);
  4048. }
  4049. int evergreen_rlc_resume(struct radeon_device *rdev)
  4050. {
  4051. u32 i;
  4052. const __be32 *fw_data;
  4053. if (!rdev->rlc_fw)
  4054. return -EINVAL;
  4055. r600_rlc_stop(rdev);
  4056. WREG32(RLC_HB_CNTL, 0);
  4057. if (rdev->flags & RADEON_IS_IGP) {
  4058. if (rdev->family == CHIP_ARUBA) {
  4059. u32 always_on_bitmap =
  4060. 3 | (3 << (16 * rdev->config.cayman.max_shader_engines));
  4061. /* find out the number of active simds */
  4062. u32 tmp = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  4063. tmp |= 0xffffffff << rdev->config.cayman.max_simds_per_se;
  4064. tmp = hweight32(~tmp);
  4065. if (tmp == rdev->config.cayman.max_simds_per_se) {
  4066. WREG32(TN_RLC_LB_ALWAYS_ACTIVE_SIMD_MASK, always_on_bitmap);
  4067. WREG32(TN_RLC_LB_PARAMS, 0x00601004);
  4068. WREG32(TN_RLC_LB_INIT_SIMD_MASK, 0xffffffff);
  4069. WREG32(TN_RLC_LB_CNTR_INIT, 0x00000000);
  4070. WREG32(TN_RLC_LB_CNTR_MAX, 0x00002000);
  4071. }
  4072. } else {
  4073. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  4074. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  4075. }
  4076. WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4077. WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4078. } else {
  4079. WREG32(RLC_HB_BASE, 0);
  4080. WREG32(RLC_HB_RPTR, 0);
  4081. WREG32(RLC_HB_WPTR, 0);
  4082. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  4083. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  4084. }
  4085. WREG32(RLC_MC_CNTL, 0);
  4086. WREG32(RLC_UCODE_CNTL, 0);
  4087. fw_data = (const __be32 *)rdev->rlc_fw->data;
  4088. if (rdev->family >= CHIP_ARUBA) {
  4089. for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
  4090. WREG32(RLC_UCODE_ADDR, i);
  4091. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4092. }
  4093. } else if (rdev->family >= CHIP_CAYMAN) {
  4094. for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
  4095. WREG32(RLC_UCODE_ADDR, i);
  4096. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4097. }
  4098. } else {
  4099. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  4100. WREG32(RLC_UCODE_ADDR, i);
  4101. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4102. }
  4103. }
  4104. WREG32(RLC_UCODE_ADDR, 0);
  4105. evergreen_rlc_start(rdev);
  4106. return 0;
  4107. }
  4108. /* Interrupts */
  4109. u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
  4110. {
  4111. if (crtc >= rdev->num_crtc)
  4112. return 0;
  4113. else
  4114. return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  4115. }
  4116. void evergreen_disable_interrupt_state(struct radeon_device *rdev)
  4117. {
  4118. u32 tmp;
  4119. if (rdev->family >= CHIP_CAYMAN) {
  4120. cayman_cp_int_cntl_setup(rdev, 0,
  4121. CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4122. cayman_cp_int_cntl_setup(rdev, 1, 0);
  4123. cayman_cp_int_cntl_setup(rdev, 2, 0);
  4124. tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4125. WREG32(CAYMAN_DMA1_CNTL, tmp);
  4126. } else
  4127. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4128. tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4129. WREG32(DMA_CNTL, tmp);
  4130. WREG32(GRBM_INT_CNTL, 0);
  4131. WREG32(SRBM_INT_CNTL, 0);
  4132. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4133. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4134. if (rdev->num_crtc >= 4) {
  4135. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4136. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4137. }
  4138. if (rdev->num_crtc >= 6) {
  4139. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4140. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4141. }
  4142. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4143. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4144. if (rdev->num_crtc >= 4) {
  4145. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4146. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4147. }
  4148. if (rdev->num_crtc >= 6) {
  4149. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4150. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4151. }
  4152. /* only one DAC on DCE5 */
  4153. if (!ASIC_IS_DCE5(rdev))
  4154. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  4155. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  4156. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4157. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4158. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4159. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4160. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4161. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4162. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4163. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4164. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4165. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4166. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4167. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4168. }
  4169. int evergreen_irq_set(struct radeon_device *rdev)
  4170. {
  4171. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  4172. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  4173. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  4174. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  4175. u32 grbm_int_cntl = 0;
  4176. u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
  4177. u32 dma_cntl, dma_cntl1 = 0;
  4178. u32 thermal_int = 0;
  4179. if (!rdev->irq.installed) {
  4180. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  4181. return -EINVAL;
  4182. }
  4183. /* don't enable anything if the ih is disabled */
  4184. if (!rdev->ih.enabled) {
  4185. r600_disable_interrupts(rdev);
  4186. /* force the active interrupt state to all disabled */
  4187. evergreen_disable_interrupt_state(rdev);
  4188. return 0;
  4189. }
  4190. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4191. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4192. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4193. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4194. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4195. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4196. if (rdev->family == CHIP_ARUBA)
  4197. thermal_int = RREG32(TN_CG_THERMAL_INT_CTRL) &
  4198. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4199. else
  4200. thermal_int = RREG32(CG_THERMAL_INT) &
  4201. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4202. afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4203. afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4204. afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4205. afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4206. afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4207. afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4208. dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4209. if (rdev->family >= CHIP_CAYMAN) {
  4210. /* enable CP interrupts on all rings */
  4211. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4212. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4213. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4214. }
  4215. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4216. DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
  4217. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4218. }
  4219. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4220. DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
  4221. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4222. }
  4223. } else {
  4224. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4225. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4226. cp_int_cntl |= RB_INT_ENABLE;
  4227. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4228. }
  4229. }
  4230. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4231. DRM_DEBUG("r600_irq_set: sw int dma\n");
  4232. dma_cntl |= TRAP_ENABLE;
  4233. }
  4234. if (rdev->family >= CHIP_CAYMAN) {
  4235. dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4236. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4237. DRM_DEBUG("r600_irq_set: sw int dma1\n");
  4238. dma_cntl1 |= TRAP_ENABLE;
  4239. }
  4240. }
  4241. if (rdev->irq.dpm_thermal) {
  4242. DRM_DEBUG("dpm thermal\n");
  4243. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  4244. }
  4245. if (rdev->irq.crtc_vblank_int[0] ||
  4246. atomic_read(&rdev->irq.pflip[0])) {
  4247. DRM_DEBUG("evergreen_irq_set: vblank 0\n");
  4248. crtc1 |= VBLANK_INT_MASK;
  4249. }
  4250. if (rdev->irq.crtc_vblank_int[1] ||
  4251. atomic_read(&rdev->irq.pflip[1])) {
  4252. DRM_DEBUG("evergreen_irq_set: vblank 1\n");
  4253. crtc2 |= VBLANK_INT_MASK;
  4254. }
  4255. if (rdev->irq.crtc_vblank_int[2] ||
  4256. atomic_read(&rdev->irq.pflip[2])) {
  4257. DRM_DEBUG("evergreen_irq_set: vblank 2\n");
  4258. crtc3 |= VBLANK_INT_MASK;
  4259. }
  4260. if (rdev->irq.crtc_vblank_int[3] ||
  4261. atomic_read(&rdev->irq.pflip[3])) {
  4262. DRM_DEBUG("evergreen_irq_set: vblank 3\n");
  4263. crtc4 |= VBLANK_INT_MASK;
  4264. }
  4265. if (rdev->irq.crtc_vblank_int[4] ||
  4266. atomic_read(&rdev->irq.pflip[4])) {
  4267. DRM_DEBUG("evergreen_irq_set: vblank 4\n");
  4268. crtc5 |= VBLANK_INT_MASK;
  4269. }
  4270. if (rdev->irq.crtc_vblank_int[5] ||
  4271. atomic_read(&rdev->irq.pflip[5])) {
  4272. DRM_DEBUG("evergreen_irq_set: vblank 5\n");
  4273. crtc6 |= VBLANK_INT_MASK;
  4274. }
  4275. if (rdev->irq.hpd[0]) {
  4276. DRM_DEBUG("evergreen_irq_set: hpd 1\n");
  4277. hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4278. }
  4279. if (rdev->irq.hpd[1]) {
  4280. DRM_DEBUG("evergreen_irq_set: hpd 2\n");
  4281. hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4282. }
  4283. if (rdev->irq.hpd[2]) {
  4284. DRM_DEBUG("evergreen_irq_set: hpd 3\n");
  4285. hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4286. }
  4287. if (rdev->irq.hpd[3]) {
  4288. DRM_DEBUG("evergreen_irq_set: hpd 4\n");
  4289. hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4290. }
  4291. if (rdev->irq.hpd[4]) {
  4292. DRM_DEBUG("evergreen_irq_set: hpd 5\n");
  4293. hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4294. }
  4295. if (rdev->irq.hpd[5]) {
  4296. DRM_DEBUG("evergreen_irq_set: hpd 6\n");
  4297. hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4298. }
  4299. if (rdev->irq.afmt[0]) {
  4300. DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
  4301. afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4302. }
  4303. if (rdev->irq.afmt[1]) {
  4304. DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
  4305. afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4306. }
  4307. if (rdev->irq.afmt[2]) {
  4308. DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
  4309. afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4310. }
  4311. if (rdev->irq.afmt[3]) {
  4312. DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
  4313. afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4314. }
  4315. if (rdev->irq.afmt[4]) {
  4316. DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
  4317. afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4318. }
  4319. if (rdev->irq.afmt[5]) {
  4320. DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
  4321. afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4322. }
  4323. if (rdev->family >= CHIP_CAYMAN) {
  4324. cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
  4325. cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
  4326. cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
  4327. } else
  4328. WREG32(CP_INT_CNTL, cp_int_cntl);
  4329. WREG32(DMA_CNTL, dma_cntl);
  4330. if (rdev->family >= CHIP_CAYMAN)
  4331. WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
  4332. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4333. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4334. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4335. if (rdev->num_crtc >= 4) {
  4336. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4337. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4338. }
  4339. if (rdev->num_crtc >= 6) {
  4340. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4341. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4342. }
  4343. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
  4344. GRPH_PFLIP_INT_MASK);
  4345. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
  4346. GRPH_PFLIP_INT_MASK);
  4347. if (rdev->num_crtc >= 4) {
  4348. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
  4349. GRPH_PFLIP_INT_MASK);
  4350. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
  4351. GRPH_PFLIP_INT_MASK);
  4352. }
  4353. if (rdev->num_crtc >= 6) {
  4354. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
  4355. GRPH_PFLIP_INT_MASK);
  4356. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
  4357. GRPH_PFLIP_INT_MASK);
  4358. }
  4359. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4360. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4361. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4362. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4363. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4364. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4365. if (rdev->family == CHIP_ARUBA)
  4366. WREG32(TN_CG_THERMAL_INT_CTRL, thermal_int);
  4367. else
  4368. WREG32(CG_THERMAL_INT, thermal_int);
  4369. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
  4370. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
  4371. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
  4372. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
  4373. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
  4374. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
  4375. /* posting read */
  4376. RREG32(SRBM_STATUS);
  4377. return 0;
  4378. }
  4379. static void evergreen_irq_ack(struct radeon_device *rdev)
  4380. {
  4381. u32 tmp;
  4382. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4383. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4384. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4385. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4386. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4387. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4388. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4389. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4390. if (rdev->num_crtc >= 4) {
  4391. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4392. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4393. }
  4394. if (rdev->num_crtc >= 6) {
  4395. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4396. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4397. }
  4398. rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4399. rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4400. rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4401. rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4402. rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4403. rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4404. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4405. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4406. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4407. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4408. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4409. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4410. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4411. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4412. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4413. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4414. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4415. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4416. if (rdev->num_crtc >= 4) {
  4417. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4418. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4419. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4420. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4421. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4422. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4423. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4424. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4425. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4426. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4427. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4428. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4429. }
  4430. if (rdev->num_crtc >= 6) {
  4431. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4432. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4433. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4434. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4435. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4436. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4437. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4438. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4439. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4440. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4441. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4442. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4443. }
  4444. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4445. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4446. tmp |= DC_HPDx_INT_ACK;
  4447. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4448. }
  4449. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4450. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4451. tmp |= DC_HPDx_INT_ACK;
  4452. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4453. }
  4454. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4455. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4456. tmp |= DC_HPDx_INT_ACK;
  4457. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4458. }
  4459. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4460. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4461. tmp |= DC_HPDx_INT_ACK;
  4462. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4463. }
  4464. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4465. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4466. tmp |= DC_HPDx_INT_ACK;
  4467. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4468. }
  4469. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4470. tmp = RREG32(DC_HPD6_INT_CONTROL);
  4471. tmp |= DC_HPDx_INT_ACK;
  4472. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4473. }
  4474. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT) {
  4475. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4476. tmp |= DC_HPDx_RX_INT_ACK;
  4477. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4478. }
  4479. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
  4480. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4481. tmp |= DC_HPDx_RX_INT_ACK;
  4482. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4483. }
  4484. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
  4485. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4486. tmp |= DC_HPDx_RX_INT_ACK;
  4487. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4488. }
  4489. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
  4490. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4491. tmp |= DC_HPDx_RX_INT_ACK;
  4492. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4493. }
  4494. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
  4495. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4496. tmp |= DC_HPDx_RX_INT_ACK;
  4497. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4498. }
  4499. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
  4500. tmp = RREG32(DC_HPD6_INT_CONTROL);
  4501. tmp |= DC_HPDx_RX_INT_ACK;
  4502. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4503. }
  4504. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4505. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4506. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4507. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
  4508. }
  4509. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4510. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4511. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4512. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
  4513. }
  4514. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4515. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4516. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4517. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
  4518. }
  4519. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4520. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4521. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4522. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
  4523. }
  4524. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4525. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4526. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4527. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
  4528. }
  4529. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4530. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4531. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4532. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
  4533. }
  4534. }
  4535. static void evergreen_irq_disable(struct radeon_device *rdev)
  4536. {
  4537. r600_disable_interrupts(rdev);
  4538. /* Wait and acknowledge irq */
  4539. mdelay(1);
  4540. evergreen_irq_ack(rdev);
  4541. evergreen_disable_interrupt_state(rdev);
  4542. }
  4543. void evergreen_irq_suspend(struct radeon_device *rdev)
  4544. {
  4545. evergreen_irq_disable(rdev);
  4546. r600_rlc_stop(rdev);
  4547. }
  4548. static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
  4549. {
  4550. u32 wptr, tmp;
  4551. if (rdev->wb.enabled)
  4552. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4553. else
  4554. wptr = RREG32(IH_RB_WPTR);
  4555. if (wptr & RB_OVERFLOW) {
  4556. wptr &= ~RB_OVERFLOW;
  4557. /* When a ring buffer overflow happen start parsing interrupt
  4558. * from the last not overwritten vector (wptr + 16). Hopefully
  4559. * this should allow us to catchup.
  4560. */
  4561. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
  4562. wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
  4563. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4564. tmp = RREG32(IH_RB_CNTL);
  4565. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4566. WREG32(IH_RB_CNTL, tmp);
  4567. }
  4568. return (wptr & rdev->ih.ptr_mask);
  4569. }
  4570. int evergreen_irq_process(struct radeon_device *rdev)
  4571. {
  4572. u32 wptr;
  4573. u32 rptr;
  4574. u32 src_id, src_data;
  4575. u32 ring_index;
  4576. bool queue_hotplug = false;
  4577. bool queue_hdmi = false;
  4578. bool queue_dp = false;
  4579. bool queue_thermal = false;
  4580. u32 status, addr;
  4581. if (!rdev->ih.enabled || rdev->shutdown)
  4582. return IRQ_NONE;
  4583. wptr = evergreen_get_ih_wptr(rdev);
  4584. restart_ih:
  4585. /* is somebody else already processing irqs? */
  4586. if (atomic_xchg(&rdev->ih.lock, 1))
  4587. return IRQ_NONE;
  4588. rptr = rdev->ih.rptr;
  4589. DRM_DEBUG("evergreen_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4590. /* Order reading of wptr vs. reading of IH ring data */
  4591. rmb();
  4592. /* display interrupts */
  4593. evergreen_irq_ack(rdev);
  4594. while (rptr != wptr) {
  4595. /* wptr/rptr are in bytes! */
  4596. ring_index = rptr / 4;
  4597. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4598. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4599. switch (src_id) {
  4600. case 1: /* D1 vblank/vline */
  4601. switch (src_data) {
  4602. case 0: /* D1 vblank */
  4603. if (!(rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT))
  4604. DRM_DEBUG("IH: D1 vblank - IH event w/o asserted irq bit?\n");
  4605. if (rdev->irq.crtc_vblank_int[0]) {
  4606. drm_handle_vblank(rdev->ddev, 0);
  4607. rdev->pm.vblank_sync = true;
  4608. wake_up(&rdev->irq.vblank_queue);
  4609. }
  4610. if (atomic_read(&rdev->irq.pflip[0]))
  4611. radeon_crtc_handle_vblank(rdev, 0);
  4612. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4613. DRM_DEBUG("IH: D1 vblank\n");
  4614. break;
  4615. case 1: /* D1 vline */
  4616. if (!(rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT))
  4617. DRM_DEBUG("IH: D1 vline - IH event w/o asserted irq bit?\n");
  4618. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4619. DRM_DEBUG("IH: D1 vline\n");
  4620. break;
  4621. default:
  4622. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4623. break;
  4624. }
  4625. break;
  4626. case 2: /* D2 vblank/vline */
  4627. switch (src_data) {
  4628. case 0: /* D2 vblank */
  4629. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
  4630. DRM_DEBUG("IH: D2 vblank - IH event w/o asserted irq bit?\n");
  4631. if (rdev->irq.crtc_vblank_int[1]) {
  4632. drm_handle_vblank(rdev->ddev, 1);
  4633. rdev->pm.vblank_sync = true;
  4634. wake_up(&rdev->irq.vblank_queue);
  4635. }
  4636. if (atomic_read(&rdev->irq.pflip[1]))
  4637. radeon_crtc_handle_vblank(rdev, 1);
  4638. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4639. DRM_DEBUG("IH: D2 vblank\n");
  4640. break;
  4641. case 1: /* D2 vline */
  4642. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT))
  4643. DRM_DEBUG("IH: D2 vline - IH event w/o asserted irq bit?\n");
  4644. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4645. DRM_DEBUG("IH: D2 vline\n");
  4646. break;
  4647. default:
  4648. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4649. break;
  4650. }
  4651. break;
  4652. case 3: /* D3 vblank/vline */
  4653. switch (src_data) {
  4654. case 0: /* D3 vblank */
  4655. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
  4656. DRM_DEBUG("IH: D3 vblank - IH event w/o asserted irq bit?\n");
  4657. if (rdev->irq.crtc_vblank_int[2]) {
  4658. drm_handle_vblank(rdev->ddev, 2);
  4659. rdev->pm.vblank_sync = true;
  4660. wake_up(&rdev->irq.vblank_queue);
  4661. }
  4662. if (atomic_read(&rdev->irq.pflip[2]))
  4663. radeon_crtc_handle_vblank(rdev, 2);
  4664. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4665. DRM_DEBUG("IH: D3 vblank\n");
  4666. break;
  4667. case 1: /* D3 vline */
  4668. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
  4669. DRM_DEBUG("IH: D3 vline - IH event w/o asserted irq bit?\n");
  4670. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4671. DRM_DEBUG("IH: D3 vline\n");
  4672. break;
  4673. default:
  4674. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4675. break;
  4676. }
  4677. break;
  4678. case 4: /* D4 vblank/vline */
  4679. switch (src_data) {
  4680. case 0: /* D4 vblank */
  4681. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
  4682. DRM_DEBUG("IH: D4 vblank - IH event w/o asserted irq bit?\n");
  4683. if (rdev->irq.crtc_vblank_int[3]) {
  4684. drm_handle_vblank(rdev->ddev, 3);
  4685. rdev->pm.vblank_sync = true;
  4686. wake_up(&rdev->irq.vblank_queue);
  4687. }
  4688. if (atomic_read(&rdev->irq.pflip[3]))
  4689. radeon_crtc_handle_vblank(rdev, 3);
  4690. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4691. DRM_DEBUG("IH: D4 vblank\n");
  4692. break;
  4693. case 1: /* D4 vline */
  4694. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
  4695. DRM_DEBUG("IH: D4 vline - IH event w/o asserted irq bit?\n");
  4696. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4697. DRM_DEBUG("IH: D4 vline\n");
  4698. break;
  4699. default:
  4700. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4701. break;
  4702. }
  4703. break;
  4704. case 5: /* D5 vblank/vline */
  4705. switch (src_data) {
  4706. case 0: /* D5 vblank */
  4707. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
  4708. DRM_DEBUG("IH: D5 vblank - IH event w/o asserted irq bit?\n");
  4709. if (rdev->irq.crtc_vblank_int[4]) {
  4710. drm_handle_vblank(rdev->ddev, 4);
  4711. rdev->pm.vblank_sync = true;
  4712. wake_up(&rdev->irq.vblank_queue);
  4713. }
  4714. if (atomic_read(&rdev->irq.pflip[4]))
  4715. radeon_crtc_handle_vblank(rdev, 4);
  4716. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4717. DRM_DEBUG("IH: D5 vblank\n");
  4718. break;
  4719. case 1: /* D5 vline */
  4720. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
  4721. DRM_DEBUG("IH: D5 vline - IH event w/o asserted irq bit?\n");
  4722. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4723. DRM_DEBUG("IH: D5 vline\n");
  4724. break;
  4725. default:
  4726. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4727. break;
  4728. }
  4729. break;
  4730. case 6: /* D6 vblank/vline */
  4731. switch (src_data) {
  4732. case 0: /* D6 vblank */
  4733. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
  4734. DRM_DEBUG("IH: D6 vblank - IH event w/o asserted irq bit?\n");
  4735. if (rdev->irq.crtc_vblank_int[5]) {
  4736. drm_handle_vblank(rdev->ddev, 5);
  4737. rdev->pm.vblank_sync = true;
  4738. wake_up(&rdev->irq.vblank_queue);
  4739. }
  4740. if (atomic_read(&rdev->irq.pflip[5]))
  4741. radeon_crtc_handle_vblank(rdev, 5);
  4742. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4743. DRM_DEBUG("IH: D6 vblank\n");
  4744. break;
  4745. case 1: /* D6 vline */
  4746. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
  4747. DRM_DEBUG("IH: D6 vline - IH event w/o asserted irq bit?\n");
  4748. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4749. DRM_DEBUG("IH: D6 vline\n");
  4750. break;
  4751. default:
  4752. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4753. break;
  4754. }
  4755. break;
  4756. case 8: /* D1 page flip */
  4757. case 10: /* D2 page flip */
  4758. case 12: /* D3 page flip */
  4759. case 14: /* D4 page flip */
  4760. case 16: /* D5 page flip */
  4761. case 18: /* D6 page flip */
  4762. DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
  4763. if (radeon_use_pflipirq > 0)
  4764. radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
  4765. break;
  4766. case 42: /* HPD hotplug */
  4767. switch (src_data) {
  4768. case 0:
  4769. if (!(rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT))
  4770. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4771. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4772. queue_hotplug = true;
  4773. DRM_DEBUG("IH: HPD1\n");
  4774. break;
  4775. case 1:
  4776. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT))
  4777. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4778. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4779. queue_hotplug = true;
  4780. DRM_DEBUG("IH: HPD2\n");
  4781. break;
  4782. case 2:
  4783. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT))
  4784. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4785. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4786. queue_hotplug = true;
  4787. DRM_DEBUG("IH: HPD3\n");
  4788. break;
  4789. case 3:
  4790. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT))
  4791. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4792. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4793. queue_hotplug = true;
  4794. DRM_DEBUG("IH: HPD4\n");
  4795. break;
  4796. case 4:
  4797. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT))
  4798. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4799. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4800. queue_hotplug = true;
  4801. DRM_DEBUG("IH: HPD5\n");
  4802. break;
  4803. case 5:
  4804. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT))
  4805. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4806. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4807. queue_hotplug = true;
  4808. DRM_DEBUG("IH: HPD6\n");
  4809. break;
  4810. case 6:
  4811. if (!(rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT))
  4812. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4813. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_RX_INTERRUPT;
  4814. queue_dp = true;
  4815. DRM_DEBUG("IH: HPD_RX 1\n");
  4816. break;
  4817. case 7:
  4818. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT))
  4819. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4820. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
  4821. queue_dp = true;
  4822. DRM_DEBUG("IH: HPD_RX 2\n");
  4823. break;
  4824. case 8:
  4825. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
  4826. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4827. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
  4828. queue_dp = true;
  4829. DRM_DEBUG("IH: HPD_RX 3\n");
  4830. break;
  4831. case 9:
  4832. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
  4833. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4834. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
  4835. queue_dp = true;
  4836. DRM_DEBUG("IH: HPD_RX 4\n");
  4837. break;
  4838. case 10:
  4839. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
  4840. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4841. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
  4842. queue_dp = true;
  4843. DRM_DEBUG("IH: HPD_RX 5\n");
  4844. break;
  4845. case 11:
  4846. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
  4847. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4848. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
  4849. queue_dp = true;
  4850. DRM_DEBUG("IH: HPD_RX 6\n");
  4851. break;
  4852. default:
  4853. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4854. break;
  4855. }
  4856. break;
  4857. case 44: /* hdmi */
  4858. switch (src_data) {
  4859. case 0:
  4860. if (!(rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG))
  4861. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4862. rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
  4863. queue_hdmi = true;
  4864. DRM_DEBUG("IH: HDMI0\n");
  4865. break;
  4866. case 1:
  4867. if (!(rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG))
  4868. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4869. rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
  4870. queue_hdmi = true;
  4871. DRM_DEBUG("IH: HDMI1\n");
  4872. break;
  4873. case 2:
  4874. if (!(rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG))
  4875. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4876. rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
  4877. queue_hdmi = true;
  4878. DRM_DEBUG("IH: HDMI2\n");
  4879. break;
  4880. case 3:
  4881. if (!(rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG))
  4882. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4883. rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
  4884. queue_hdmi = true;
  4885. DRM_DEBUG("IH: HDMI3\n");
  4886. break;
  4887. case 4:
  4888. if (!(rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG))
  4889. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4890. rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
  4891. queue_hdmi = true;
  4892. DRM_DEBUG("IH: HDMI4\n");
  4893. break;
  4894. case 5:
  4895. if (!(rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG))
  4896. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4897. rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
  4898. queue_hdmi = true;
  4899. DRM_DEBUG("IH: HDMI5\n");
  4900. break;
  4901. default:
  4902. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  4903. break;
  4904. }
  4905. case 96:
  4906. DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
  4907. WREG32(SRBM_INT_ACK, 0x1);
  4908. break;
  4909. case 124: /* UVD */
  4910. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  4911. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  4912. break;
  4913. case 146:
  4914. case 147:
  4915. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  4916. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  4917. /* reset addr and status */
  4918. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4919. if (addr == 0x0 && status == 0x0)
  4920. break;
  4921. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4922. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4923. addr);
  4924. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4925. status);
  4926. cayman_vm_decode_fault(rdev, status, addr);
  4927. break;
  4928. case 176: /* CP_INT in ring buffer */
  4929. case 177: /* CP_INT in IB1 */
  4930. case 178: /* CP_INT in IB2 */
  4931. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  4932. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4933. break;
  4934. case 181: /* CP EOP event */
  4935. DRM_DEBUG("IH: CP EOP\n");
  4936. if (rdev->family >= CHIP_CAYMAN) {
  4937. switch (src_data) {
  4938. case 0:
  4939. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4940. break;
  4941. case 1:
  4942. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4943. break;
  4944. case 2:
  4945. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4946. break;
  4947. }
  4948. } else
  4949. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4950. break;
  4951. case 224: /* DMA trap event */
  4952. DRM_DEBUG("IH: DMA trap\n");
  4953. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4954. break;
  4955. case 230: /* thermal low to high */
  4956. DRM_DEBUG("IH: thermal low to high\n");
  4957. rdev->pm.dpm.thermal.high_to_low = false;
  4958. queue_thermal = true;
  4959. break;
  4960. case 231: /* thermal high to low */
  4961. DRM_DEBUG("IH: thermal high to low\n");
  4962. rdev->pm.dpm.thermal.high_to_low = true;
  4963. queue_thermal = true;
  4964. break;
  4965. case 233: /* GUI IDLE */
  4966. DRM_DEBUG("IH: GUI idle\n");
  4967. break;
  4968. case 244: /* DMA trap event */
  4969. if (rdev->family >= CHIP_CAYMAN) {
  4970. DRM_DEBUG("IH: DMA1 trap\n");
  4971. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4972. }
  4973. break;
  4974. default:
  4975. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4976. break;
  4977. }
  4978. /* wptr/rptr are in bytes! */
  4979. rptr += 16;
  4980. rptr &= rdev->ih.ptr_mask;
  4981. WREG32(IH_RB_RPTR, rptr);
  4982. }
  4983. if (queue_dp)
  4984. schedule_work(&rdev->dp_work);
  4985. if (queue_hotplug)
  4986. schedule_delayed_work(&rdev->hotplug_work, 0);
  4987. if (queue_hdmi)
  4988. schedule_work(&rdev->audio_work);
  4989. if (queue_thermal && rdev->pm.dpm_enabled)
  4990. schedule_work(&rdev->pm.dpm.thermal.work);
  4991. rdev->ih.rptr = rptr;
  4992. atomic_set(&rdev->ih.lock, 0);
  4993. /* make sure wptr hasn't changed while processing */
  4994. wptr = evergreen_get_ih_wptr(rdev);
  4995. if (wptr != rptr)
  4996. goto restart_ih;
  4997. return IRQ_HANDLED;
  4998. }
  4999. static void evergreen_uvd_init(struct radeon_device *rdev)
  5000. {
  5001. int r;
  5002. if (!rdev->has_uvd)
  5003. return;
  5004. r = radeon_uvd_init(rdev);
  5005. if (r) {
  5006. dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
  5007. /*
  5008. * At this point rdev->uvd.vcpu_bo is NULL which trickles down
  5009. * to early fails uvd_v2_2_resume() and thus nothing happens
  5010. * there. So it is pointless to try to go through that code
  5011. * hence why we disable uvd here.
  5012. */
  5013. rdev->has_uvd = 0;
  5014. return;
  5015. }
  5016. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  5017. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
  5018. }
  5019. static void evergreen_uvd_start(struct radeon_device *rdev)
  5020. {
  5021. int r;
  5022. if (!rdev->has_uvd)
  5023. return;
  5024. r = uvd_v2_2_resume(rdev);
  5025. if (r) {
  5026. dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
  5027. goto error;
  5028. }
  5029. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
  5030. if (r) {
  5031. dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
  5032. goto error;
  5033. }
  5034. return;
  5035. error:
  5036. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5037. }
  5038. static void evergreen_uvd_resume(struct radeon_device *rdev)
  5039. {
  5040. struct radeon_ring *ring;
  5041. int r;
  5042. if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
  5043. return;
  5044. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5045. r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
  5046. if (r) {
  5047. dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
  5048. return;
  5049. }
  5050. r = uvd_v1_0_init(rdev);
  5051. if (r) {
  5052. dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
  5053. return;
  5054. }
  5055. }
  5056. static int evergreen_startup(struct radeon_device *rdev)
  5057. {
  5058. struct radeon_ring *ring;
  5059. int r;
  5060. /* enable pcie gen2 link */
  5061. evergreen_pcie_gen2_enable(rdev);
  5062. /* enable aspm */
  5063. evergreen_program_aspm(rdev);
  5064. /* scratch needs to be initialized before MC */
  5065. r = r600_vram_scratch_init(rdev);
  5066. if (r)
  5067. return r;
  5068. evergreen_mc_program(rdev);
  5069. if (ASIC_IS_DCE5(rdev) && !rdev->pm.dpm_enabled) {
  5070. r = ni_mc_load_microcode(rdev);
  5071. if (r) {
  5072. DRM_ERROR("Failed to load MC firmware!\n");
  5073. return r;
  5074. }
  5075. }
  5076. if (rdev->flags & RADEON_IS_AGP) {
  5077. evergreen_agp_enable(rdev);
  5078. } else {
  5079. r = evergreen_pcie_gart_enable(rdev);
  5080. if (r)
  5081. return r;
  5082. }
  5083. evergreen_gpu_init(rdev);
  5084. /* allocate rlc buffers */
  5085. if (rdev->flags & RADEON_IS_IGP) {
  5086. rdev->rlc.reg_list = sumo_rlc_save_restore_register_list;
  5087. rdev->rlc.reg_list_size =
  5088. (u32)ARRAY_SIZE(sumo_rlc_save_restore_register_list);
  5089. rdev->rlc.cs_data = evergreen_cs_data;
  5090. r = sumo_rlc_init(rdev);
  5091. if (r) {
  5092. DRM_ERROR("Failed to init rlc BOs!\n");
  5093. return r;
  5094. }
  5095. }
  5096. /* allocate wb buffer */
  5097. r = radeon_wb_init(rdev);
  5098. if (r)
  5099. return r;
  5100. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5101. if (r) {
  5102. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5103. return r;
  5104. }
  5105. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  5106. if (r) {
  5107. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5108. return r;
  5109. }
  5110. evergreen_uvd_start(rdev);
  5111. /* Enable IRQ */
  5112. if (!rdev->irq.installed) {
  5113. r = radeon_irq_kms_init(rdev);
  5114. if (r)
  5115. return r;
  5116. }
  5117. r = r600_irq_init(rdev);
  5118. if (r) {
  5119. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5120. radeon_irq_kms_fini(rdev);
  5121. return r;
  5122. }
  5123. evergreen_irq_set(rdev);
  5124. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5125. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5126. RADEON_CP_PACKET2);
  5127. if (r)
  5128. return r;
  5129. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5130. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5131. DMA_PACKET(DMA_PACKET_NOP, 0, 0));
  5132. if (r)
  5133. return r;
  5134. r = evergreen_cp_load_microcode(rdev);
  5135. if (r)
  5136. return r;
  5137. r = evergreen_cp_resume(rdev);
  5138. if (r)
  5139. return r;
  5140. r = r600_dma_resume(rdev);
  5141. if (r)
  5142. return r;
  5143. evergreen_uvd_resume(rdev);
  5144. r = radeon_ib_pool_init(rdev);
  5145. if (r) {
  5146. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5147. return r;
  5148. }
  5149. r = radeon_audio_init(rdev);
  5150. if (r) {
  5151. DRM_ERROR("radeon: audio init failed\n");
  5152. return r;
  5153. }
  5154. return 0;
  5155. }
  5156. int evergreen_resume(struct radeon_device *rdev)
  5157. {
  5158. int r;
  5159. /* reset the asic, the gfx blocks are often in a bad state
  5160. * after the driver is unloaded or after a resume
  5161. */
  5162. if (radeon_asic_reset(rdev))
  5163. dev_warn(rdev->dev, "GPU reset failed !\n");
  5164. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5165. * posting will perform necessary task to bring back GPU into good
  5166. * shape.
  5167. */
  5168. /* post card */
  5169. atom_asic_init(rdev->mode_info.atom_context);
  5170. /* init golden registers */
  5171. evergreen_init_golden_registers(rdev);
  5172. if (rdev->pm.pm_method == PM_METHOD_DPM)
  5173. radeon_pm_resume(rdev);
  5174. rdev->accel_working = true;
  5175. r = evergreen_startup(rdev);
  5176. if (r) {
  5177. DRM_ERROR("evergreen startup failed on resume\n");
  5178. rdev->accel_working = false;
  5179. return r;
  5180. }
  5181. return r;
  5182. }
  5183. int evergreen_suspend(struct radeon_device *rdev)
  5184. {
  5185. radeon_pm_suspend(rdev);
  5186. radeon_audio_fini(rdev);
  5187. if (rdev->has_uvd) {
  5188. uvd_v1_0_fini(rdev);
  5189. radeon_uvd_suspend(rdev);
  5190. }
  5191. r700_cp_stop(rdev);
  5192. r600_dma_stop(rdev);
  5193. evergreen_irq_suspend(rdev);
  5194. radeon_wb_disable(rdev);
  5195. evergreen_pcie_gart_disable(rdev);
  5196. return 0;
  5197. }
  5198. /* Plan is to move initialization in that function and use
  5199. * helper function so that radeon_device_init pretty much
  5200. * do nothing more than calling asic specific function. This
  5201. * should also allow to remove a bunch of callback function
  5202. * like vram_info.
  5203. */
  5204. int evergreen_init(struct radeon_device *rdev)
  5205. {
  5206. int r;
  5207. /* Read BIOS */
  5208. if (!radeon_get_bios(rdev)) {
  5209. if (ASIC_IS_AVIVO(rdev))
  5210. return -EINVAL;
  5211. }
  5212. /* Must be an ATOMBIOS */
  5213. if (!rdev->is_atom_bios) {
  5214. dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
  5215. return -EINVAL;
  5216. }
  5217. r = radeon_atombios_init(rdev);
  5218. if (r)
  5219. return r;
  5220. /* reset the asic, the gfx blocks are often in a bad state
  5221. * after the driver is unloaded or after a resume
  5222. */
  5223. if (radeon_asic_reset(rdev))
  5224. dev_warn(rdev->dev, "GPU reset failed !\n");
  5225. /* Post card if necessary */
  5226. if (!radeon_card_posted(rdev)) {
  5227. if (!rdev->bios) {
  5228. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5229. return -EINVAL;
  5230. }
  5231. DRM_INFO("GPU not posted. posting now...\n");
  5232. atom_asic_init(rdev->mode_info.atom_context);
  5233. }
  5234. /* init golden registers */
  5235. evergreen_init_golden_registers(rdev);
  5236. /* Initialize scratch registers */
  5237. r600_scratch_init(rdev);
  5238. /* Initialize surface registers */
  5239. radeon_surface_init(rdev);
  5240. /* Initialize clocks */
  5241. radeon_get_clock_info(rdev->ddev);
  5242. /* Fence driver */
  5243. r = radeon_fence_driver_init(rdev);
  5244. if (r)
  5245. return r;
  5246. /* initialize AGP */
  5247. if (rdev->flags & RADEON_IS_AGP) {
  5248. r = radeon_agp_init(rdev);
  5249. if (r)
  5250. radeon_agp_disable(rdev);
  5251. }
  5252. /* initialize memory controller */
  5253. r = evergreen_mc_init(rdev);
  5254. if (r)
  5255. return r;
  5256. /* Memory manager */
  5257. r = radeon_bo_init(rdev);
  5258. if (r)
  5259. return r;
  5260. if (ASIC_IS_DCE5(rdev)) {
  5261. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  5262. r = ni_init_microcode(rdev);
  5263. if (r) {
  5264. DRM_ERROR("Failed to load firmware!\n");
  5265. return r;
  5266. }
  5267. }
  5268. } else {
  5269. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  5270. r = r600_init_microcode(rdev);
  5271. if (r) {
  5272. DRM_ERROR("Failed to load firmware!\n");
  5273. return r;
  5274. }
  5275. }
  5276. }
  5277. /* Initialize power management */
  5278. radeon_pm_init(rdev);
  5279. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  5280. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  5281. rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
  5282. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
  5283. evergreen_uvd_init(rdev);
  5284. rdev->ih.ring_obj = NULL;
  5285. r600_ih_ring_init(rdev, 64 * 1024);
  5286. r = r600_pcie_gart_init(rdev);
  5287. if (r)
  5288. return r;
  5289. rdev->accel_working = true;
  5290. r = evergreen_startup(rdev);
  5291. if (r) {
  5292. dev_err(rdev->dev, "disabling GPU acceleration\n");
  5293. r700_cp_fini(rdev);
  5294. r600_dma_fini(rdev);
  5295. r600_irq_fini(rdev);
  5296. if (rdev->flags & RADEON_IS_IGP)
  5297. sumo_rlc_fini(rdev);
  5298. radeon_wb_fini(rdev);
  5299. radeon_ib_pool_fini(rdev);
  5300. radeon_irq_kms_fini(rdev);
  5301. evergreen_pcie_gart_fini(rdev);
  5302. rdev->accel_working = false;
  5303. }
  5304. /* Don't start up if the MC ucode is missing on BTC parts.
  5305. * The default clocks and voltages before the MC ucode
  5306. * is loaded are not suffient for advanced operations.
  5307. */
  5308. if (ASIC_IS_DCE5(rdev)) {
  5309. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  5310. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  5311. return -EINVAL;
  5312. }
  5313. }
  5314. return 0;
  5315. }
  5316. void evergreen_fini(struct radeon_device *rdev)
  5317. {
  5318. radeon_pm_fini(rdev);
  5319. radeon_audio_fini(rdev);
  5320. r700_cp_fini(rdev);
  5321. r600_dma_fini(rdev);
  5322. r600_irq_fini(rdev);
  5323. if (rdev->flags & RADEON_IS_IGP)
  5324. sumo_rlc_fini(rdev);
  5325. radeon_wb_fini(rdev);
  5326. radeon_ib_pool_fini(rdev);
  5327. radeon_irq_kms_fini(rdev);
  5328. uvd_v1_0_fini(rdev);
  5329. radeon_uvd_fini(rdev);
  5330. evergreen_pcie_gart_fini(rdev);
  5331. r600_vram_scratch_fini(rdev);
  5332. radeon_gem_fini(rdev);
  5333. radeon_fence_driver_fini(rdev);
  5334. radeon_agp_fini(rdev);
  5335. radeon_bo_fini(rdev);
  5336. radeon_atombios_fini(rdev);
  5337. kfree(rdev->bios);
  5338. rdev->bios = NULL;
  5339. }
  5340. void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
  5341. {
  5342. u32 link_width_cntl, speed_cntl;
  5343. if (radeon_pcie_gen2 == 0)
  5344. return;
  5345. if (rdev->flags & RADEON_IS_IGP)
  5346. return;
  5347. if (!(rdev->flags & RADEON_IS_PCIE))
  5348. return;
  5349. /* x2 cards have a special sequence */
  5350. if (ASIC_IS_X2(rdev))
  5351. return;
  5352. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  5353. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  5354. return;
  5355. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5356. if (speed_cntl & LC_CURRENT_DATA_RATE) {
  5357. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  5358. return;
  5359. }
  5360. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  5361. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  5362. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  5363. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5364. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5365. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5366. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5367. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  5368. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5369. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5370. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  5371. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5372. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5373. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  5374. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5375. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5376. speed_cntl |= LC_GEN2_EN_STRAP;
  5377. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5378. } else {
  5379. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5380. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  5381. if (1)
  5382. link_width_cntl |= LC_UPCONFIGURE_DIS;
  5383. else
  5384. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5385. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5386. }
  5387. }
  5388. void evergreen_program_aspm(struct radeon_device *rdev)
  5389. {
  5390. u32 data, orig;
  5391. u32 pcie_lc_cntl, pcie_lc_cntl_old;
  5392. bool disable_l0s, disable_l1 = false, disable_plloff_in_l1 = false;
  5393. /* fusion_platform = true
  5394. * if the system is a fusion system
  5395. * (APU or DGPU in a fusion system).
  5396. * todo: check if the system is a fusion platform.
  5397. */
  5398. bool fusion_platform = false;
  5399. if (radeon_aspm == 0)
  5400. return;
  5401. if (!(rdev->flags & RADEON_IS_PCIE))
  5402. return;
  5403. switch (rdev->family) {
  5404. case CHIP_CYPRESS:
  5405. case CHIP_HEMLOCK:
  5406. case CHIP_JUNIPER:
  5407. case CHIP_REDWOOD:
  5408. case CHIP_CEDAR:
  5409. case CHIP_SUMO:
  5410. case CHIP_SUMO2:
  5411. case CHIP_PALM:
  5412. case CHIP_ARUBA:
  5413. disable_l0s = true;
  5414. break;
  5415. default:
  5416. disable_l0s = false;
  5417. break;
  5418. }
  5419. if (rdev->flags & RADEON_IS_IGP)
  5420. fusion_platform = true; /* XXX also dGPUs in a fusion system */
  5421. data = orig = RREG32_PIF_PHY0(PB0_PIF_PAIRING);
  5422. if (fusion_platform)
  5423. data &= ~MULTI_PIF;
  5424. else
  5425. data |= MULTI_PIF;
  5426. if (data != orig)
  5427. WREG32_PIF_PHY0(PB0_PIF_PAIRING, data);
  5428. data = orig = RREG32_PIF_PHY1(PB1_PIF_PAIRING);
  5429. if (fusion_platform)
  5430. data &= ~MULTI_PIF;
  5431. else
  5432. data |= MULTI_PIF;
  5433. if (data != orig)
  5434. WREG32_PIF_PHY1(PB1_PIF_PAIRING, data);
  5435. pcie_lc_cntl = pcie_lc_cntl_old = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5436. pcie_lc_cntl &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  5437. if (!disable_l0s) {
  5438. if (rdev->family >= CHIP_BARTS)
  5439. pcie_lc_cntl |= LC_L0S_INACTIVITY(7);
  5440. else
  5441. pcie_lc_cntl |= LC_L0S_INACTIVITY(3);
  5442. }
  5443. if (!disable_l1) {
  5444. if (rdev->family >= CHIP_BARTS)
  5445. pcie_lc_cntl |= LC_L1_INACTIVITY(7);
  5446. else
  5447. pcie_lc_cntl |= LC_L1_INACTIVITY(8);
  5448. if (!disable_plloff_in_l1) {
  5449. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5450. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5451. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5452. if (data != orig)
  5453. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5454. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5455. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5456. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5457. if (data != orig)
  5458. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5459. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5460. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5461. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5462. if (data != orig)
  5463. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5464. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5465. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5466. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5467. if (data != orig)
  5468. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5469. if (rdev->family >= CHIP_BARTS) {
  5470. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5471. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5472. data |= PLL_RAMP_UP_TIME_0(4);
  5473. if (data != orig)
  5474. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5475. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5476. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5477. data |= PLL_RAMP_UP_TIME_1(4);
  5478. if (data != orig)
  5479. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5480. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5481. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5482. data |= PLL_RAMP_UP_TIME_0(4);
  5483. if (data != orig)
  5484. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5485. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5486. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5487. data |= PLL_RAMP_UP_TIME_1(4);
  5488. if (data != orig)
  5489. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5490. }
  5491. data = orig = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5492. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  5493. data |= LC_DYN_LANES_PWR_STATE(3);
  5494. if (data != orig)
  5495. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  5496. if (rdev->family >= CHIP_BARTS) {
  5497. data = orig = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  5498. data &= ~LS2_EXIT_TIME_MASK;
  5499. data |= LS2_EXIT_TIME(1);
  5500. if (data != orig)
  5501. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  5502. data = orig = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  5503. data &= ~LS2_EXIT_TIME_MASK;
  5504. data |= LS2_EXIT_TIME(1);
  5505. if (data != orig)
  5506. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  5507. }
  5508. }
  5509. }
  5510. /* evergreen parts only */
  5511. if (rdev->family < CHIP_BARTS)
  5512. pcie_lc_cntl |= LC_PMI_TO_L1_DIS;
  5513. if (pcie_lc_cntl != pcie_lc_cntl_old)
  5514. WREG32_PCIE_PORT(PCIE_LC_CNTL, pcie_lc_cntl);
  5515. }