evergreen.c 172 KB

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