evergreen.c 162 KB

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