evergreen.c 171 KB

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