evergreen.c 176 KB

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