evergreen.c 156 KB

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