evergreen.c 161 KB

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