evergreen.c 171 KB

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