evergreen.c 171 KB

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