si.c 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507
  1. /*
  2. * Copyright 2011 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 <linux/module.h>
  28. #include <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include <drm/radeon_drm.h>
  32. #include "sid.h"
  33. #include "atom.h"
  34. #include "si_blit_shaders.h"
  35. #define SI_PFP_UCODE_SIZE 2144
  36. #define SI_PM4_UCODE_SIZE 2144
  37. #define SI_CE_UCODE_SIZE 2144
  38. #define SI_RLC_UCODE_SIZE 2048
  39. #define SI_MC_UCODE_SIZE 7769
  40. #define OLAND_MC_UCODE_SIZE 7863
  41. MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
  42. MODULE_FIRMWARE("radeon/TAHITI_me.bin");
  43. MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
  44. MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
  45. MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
  46. MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
  47. MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
  48. MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
  49. MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
  50. MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
  51. MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
  52. MODULE_FIRMWARE("radeon/VERDE_me.bin");
  53. MODULE_FIRMWARE("radeon/VERDE_ce.bin");
  54. MODULE_FIRMWARE("radeon/VERDE_mc.bin");
  55. MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
  56. MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
  57. MODULE_FIRMWARE("radeon/OLAND_me.bin");
  58. MODULE_FIRMWARE("radeon/OLAND_ce.bin");
  59. MODULE_FIRMWARE("radeon/OLAND_mc.bin");
  60. MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
  61. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  62. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  63. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  64. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  65. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  66. extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
  67. extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
  68. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  69. static const u32 tahiti_golden_rlc_registers[] =
  70. {
  71. 0xc424, 0xffffffff, 0x00601005,
  72. 0xc47c, 0xffffffff, 0x10104040,
  73. 0xc488, 0xffffffff, 0x0100000a,
  74. 0xc314, 0xffffffff, 0x00000800,
  75. 0xc30c, 0xffffffff, 0x800000f4,
  76. 0xf4a8, 0xffffffff, 0x00000000
  77. };
  78. static const u32 tahiti_golden_registers[] =
  79. {
  80. 0x9a10, 0x00010000, 0x00018208,
  81. 0x9830, 0xffffffff, 0x00000000,
  82. 0x9834, 0xf00fffff, 0x00000400,
  83. 0x9838, 0x0002021c, 0x00020200,
  84. 0xc78, 0x00000080, 0x00000000,
  85. 0xd030, 0x000300c0, 0x00800040,
  86. 0xd830, 0x000300c0, 0x00800040,
  87. 0x5bb0, 0x000000f0, 0x00000070,
  88. 0x5bc0, 0x00200000, 0x50100000,
  89. 0x7030, 0x31000311, 0x00000011,
  90. 0x277c, 0x00000003, 0x000007ff,
  91. 0x240c, 0x000007ff, 0x00000000,
  92. 0x8a14, 0xf000001f, 0x00000007,
  93. 0x8b24, 0xffffffff, 0x00ffffff,
  94. 0x8b10, 0x0000ff0f, 0x00000000,
  95. 0x28a4c, 0x07ffffff, 0x4e000000,
  96. 0x28350, 0x3f3f3fff, 0x2a00126a,
  97. 0x30, 0x000000ff, 0x0040,
  98. 0x34, 0x00000040, 0x00004040,
  99. 0x9100, 0x07ffffff, 0x03000000,
  100. 0x8e88, 0x01ff1f3f, 0x00000000,
  101. 0x8e84, 0x01ff1f3f, 0x00000000,
  102. 0x9060, 0x0000007f, 0x00000020,
  103. 0x9508, 0x00010000, 0x00010000,
  104. 0xac14, 0x00000200, 0x000002fb,
  105. 0xac10, 0xffffffff, 0x0000543b,
  106. 0xac0c, 0xffffffff, 0xa9210876,
  107. 0x88d0, 0xffffffff, 0x000fff40,
  108. 0x88d4, 0x0000001f, 0x00000010,
  109. 0x1410, 0x20000000, 0x20fffed8,
  110. 0x15c0, 0x000c0fc0, 0x000c0400
  111. };
  112. static const u32 tahiti_golden_registers2[] =
  113. {
  114. 0xc64, 0x00000001, 0x00000001
  115. };
  116. static const u32 pitcairn_golden_rlc_registers[] =
  117. {
  118. 0xc424, 0xffffffff, 0x00601004,
  119. 0xc47c, 0xffffffff, 0x10102020,
  120. 0xc488, 0xffffffff, 0x01000020,
  121. 0xc314, 0xffffffff, 0x00000800,
  122. 0xc30c, 0xffffffff, 0x800000a4
  123. };
  124. static const u32 pitcairn_golden_registers[] =
  125. {
  126. 0x9a10, 0x00010000, 0x00018208,
  127. 0x9830, 0xffffffff, 0x00000000,
  128. 0x9834, 0xf00fffff, 0x00000400,
  129. 0x9838, 0x0002021c, 0x00020200,
  130. 0xc78, 0x00000080, 0x00000000,
  131. 0xd030, 0x000300c0, 0x00800040,
  132. 0xd830, 0x000300c0, 0x00800040,
  133. 0x5bb0, 0x000000f0, 0x00000070,
  134. 0x5bc0, 0x00200000, 0x50100000,
  135. 0x7030, 0x31000311, 0x00000011,
  136. 0x2ae4, 0x00073ffe, 0x000022a2,
  137. 0x240c, 0x000007ff, 0x00000000,
  138. 0x8a14, 0xf000001f, 0x00000007,
  139. 0x8b24, 0xffffffff, 0x00ffffff,
  140. 0x8b10, 0x0000ff0f, 0x00000000,
  141. 0x28a4c, 0x07ffffff, 0x4e000000,
  142. 0x28350, 0x3f3f3fff, 0x2a00126a,
  143. 0x30, 0x000000ff, 0x0040,
  144. 0x34, 0x00000040, 0x00004040,
  145. 0x9100, 0x07ffffff, 0x03000000,
  146. 0x9060, 0x0000007f, 0x00000020,
  147. 0x9508, 0x00010000, 0x00010000,
  148. 0xac14, 0x000003ff, 0x000000f7,
  149. 0xac10, 0xffffffff, 0x00000000,
  150. 0xac0c, 0xffffffff, 0x32761054,
  151. 0x88d4, 0x0000001f, 0x00000010,
  152. 0x15c0, 0x000c0fc0, 0x000c0400
  153. };
  154. static const u32 verde_golden_rlc_registers[] =
  155. {
  156. 0xc424, 0xffffffff, 0x033f1005,
  157. 0xc47c, 0xffffffff, 0x10808020,
  158. 0xc488, 0xffffffff, 0x00800008,
  159. 0xc314, 0xffffffff, 0x00001000,
  160. 0xc30c, 0xffffffff, 0x80010014
  161. };
  162. static const u32 verde_golden_registers[] =
  163. {
  164. 0x9a10, 0x00010000, 0x00018208,
  165. 0x9830, 0xffffffff, 0x00000000,
  166. 0x9834, 0xf00fffff, 0x00000400,
  167. 0x9838, 0x0002021c, 0x00020200,
  168. 0xc78, 0x00000080, 0x00000000,
  169. 0xd030, 0x000300c0, 0x00800040,
  170. 0xd030, 0x000300c0, 0x00800040,
  171. 0xd830, 0x000300c0, 0x00800040,
  172. 0xd830, 0x000300c0, 0x00800040,
  173. 0x5bb0, 0x000000f0, 0x00000070,
  174. 0x5bc0, 0x00200000, 0x50100000,
  175. 0x7030, 0x31000311, 0x00000011,
  176. 0x2ae4, 0x00073ffe, 0x000022a2,
  177. 0x2ae4, 0x00073ffe, 0x000022a2,
  178. 0x2ae4, 0x00073ffe, 0x000022a2,
  179. 0x240c, 0x000007ff, 0x00000000,
  180. 0x240c, 0x000007ff, 0x00000000,
  181. 0x240c, 0x000007ff, 0x00000000,
  182. 0x8a14, 0xf000001f, 0x00000007,
  183. 0x8a14, 0xf000001f, 0x00000007,
  184. 0x8a14, 0xf000001f, 0x00000007,
  185. 0x8b24, 0xffffffff, 0x00ffffff,
  186. 0x8b10, 0x0000ff0f, 0x00000000,
  187. 0x28a4c, 0x07ffffff, 0x4e000000,
  188. 0x28350, 0x3f3f3fff, 0x0000124a,
  189. 0x28350, 0x3f3f3fff, 0x0000124a,
  190. 0x28350, 0x3f3f3fff, 0x0000124a,
  191. 0x30, 0x000000ff, 0x0040,
  192. 0x34, 0x00000040, 0x00004040,
  193. 0x9100, 0x07ffffff, 0x03000000,
  194. 0x9100, 0x07ffffff, 0x03000000,
  195. 0x8e88, 0x01ff1f3f, 0x00000000,
  196. 0x8e88, 0x01ff1f3f, 0x00000000,
  197. 0x8e88, 0x01ff1f3f, 0x00000000,
  198. 0x8e84, 0x01ff1f3f, 0x00000000,
  199. 0x8e84, 0x01ff1f3f, 0x00000000,
  200. 0x8e84, 0x01ff1f3f, 0x00000000,
  201. 0x9060, 0x0000007f, 0x00000020,
  202. 0x9508, 0x00010000, 0x00010000,
  203. 0xac14, 0x000003ff, 0x00000003,
  204. 0xac14, 0x000003ff, 0x00000003,
  205. 0xac14, 0x000003ff, 0x00000003,
  206. 0xac10, 0xffffffff, 0x00000000,
  207. 0xac10, 0xffffffff, 0x00000000,
  208. 0xac10, 0xffffffff, 0x00000000,
  209. 0xac0c, 0xffffffff, 0x00001032,
  210. 0xac0c, 0xffffffff, 0x00001032,
  211. 0xac0c, 0xffffffff, 0x00001032,
  212. 0x88d4, 0x0000001f, 0x00000010,
  213. 0x88d4, 0x0000001f, 0x00000010,
  214. 0x88d4, 0x0000001f, 0x00000010,
  215. 0x15c0, 0x000c0fc0, 0x000c0400
  216. };
  217. static const u32 oland_golden_rlc_registers[] =
  218. {
  219. 0xc424, 0xffffffff, 0x00601005,
  220. 0xc47c, 0xffffffff, 0x10104040,
  221. 0xc488, 0xffffffff, 0x0100000a,
  222. 0xc314, 0xffffffff, 0x00000800,
  223. 0xc30c, 0xffffffff, 0x800000f4
  224. };
  225. static const u32 oland_golden_registers[] =
  226. {
  227. 0x9a10, 0x00010000, 0x00018208,
  228. 0x9830, 0xffffffff, 0x00000000,
  229. 0x9834, 0xf00fffff, 0x00000400,
  230. 0x9838, 0x0002021c, 0x00020200,
  231. 0xc78, 0x00000080, 0x00000000,
  232. 0xd030, 0x000300c0, 0x00800040,
  233. 0xd830, 0x000300c0, 0x00800040,
  234. 0x5bb0, 0x000000f0, 0x00000070,
  235. 0x5bc0, 0x00200000, 0x50100000,
  236. 0x7030, 0x31000311, 0x00000011,
  237. 0x2ae4, 0x00073ffe, 0x000022a2,
  238. 0x240c, 0x000007ff, 0x00000000,
  239. 0x8a14, 0xf000001f, 0x00000007,
  240. 0x8b24, 0xffffffff, 0x00ffffff,
  241. 0x8b10, 0x0000ff0f, 0x00000000,
  242. 0x28a4c, 0x07ffffff, 0x4e000000,
  243. 0x28350, 0x3f3f3fff, 0x00000082,
  244. 0x30, 0x000000ff, 0x0040,
  245. 0x34, 0x00000040, 0x00004040,
  246. 0x9100, 0x07ffffff, 0x03000000,
  247. 0x9060, 0x0000007f, 0x00000020,
  248. 0x9508, 0x00010000, 0x00010000,
  249. 0xac14, 0x000003ff, 0x000000f3,
  250. 0xac10, 0xffffffff, 0x00000000,
  251. 0xac0c, 0xffffffff, 0x00003210,
  252. 0x88d4, 0x0000001f, 0x00000010,
  253. 0x15c0, 0x000c0fc0, 0x000c0400
  254. };
  255. static const u32 tahiti_mgcg_cgcg_init[] =
  256. {
  257. 0xc400, 0xffffffff, 0xfffffffc,
  258. 0x802c, 0xffffffff, 0xe0000000,
  259. 0x9a60, 0xffffffff, 0x00000100,
  260. 0x92a4, 0xffffffff, 0x00000100,
  261. 0xc164, 0xffffffff, 0x00000100,
  262. 0x9774, 0xffffffff, 0x00000100,
  263. 0x8984, 0xffffffff, 0x06000100,
  264. 0x8a18, 0xffffffff, 0x00000100,
  265. 0x92a0, 0xffffffff, 0x00000100,
  266. 0xc380, 0xffffffff, 0x00000100,
  267. 0x8b28, 0xffffffff, 0x00000100,
  268. 0x9144, 0xffffffff, 0x00000100,
  269. 0x8d88, 0xffffffff, 0x00000100,
  270. 0x8d8c, 0xffffffff, 0x00000100,
  271. 0x9030, 0xffffffff, 0x00000100,
  272. 0x9034, 0xffffffff, 0x00000100,
  273. 0x9038, 0xffffffff, 0x00000100,
  274. 0x903c, 0xffffffff, 0x00000100,
  275. 0xad80, 0xffffffff, 0x00000100,
  276. 0xac54, 0xffffffff, 0x00000100,
  277. 0x897c, 0xffffffff, 0x06000100,
  278. 0x9868, 0xffffffff, 0x00000100,
  279. 0x9510, 0xffffffff, 0x00000100,
  280. 0xaf04, 0xffffffff, 0x00000100,
  281. 0xae04, 0xffffffff, 0x00000100,
  282. 0x949c, 0xffffffff, 0x00000100,
  283. 0x802c, 0xffffffff, 0xe0000000,
  284. 0x9160, 0xffffffff, 0x00010000,
  285. 0x9164, 0xffffffff, 0x00030002,
  286. 0x9168, 0xffffffff, 0x00040007,
  287. 0x916c, 0xffffffff, 0x00060005,
  288. 0x9170, 0xffffffff, 0x00090008,
  289. 0x9174, 0xffffffff, 0x00020001,
  290. 0x9178, 0xffffffff, 0x00040003,
  291. 0x917c, 0xffffffff, 0x00000007,
  292. 0x9180, 0xffffffff, 0x00060005,
  293. 0x9184, 0xffffffff, 0x00090008,
  294. 0x9188, 0xffffffff, 0x00030002,
  295. 0x918c, 0xffffffff, 0x00050004,
  296. 0x9190, 0xffffffff, 0x00000008,
  297. 0x9194, 0xffffffff, 0x00070006,
  298. 0x9198, 0xffffffff, 0x000a0009,
  299. 0x919c, 0xffffffff, 0x00040003,
  300. 0x91a0, 0xffffffff, 0x00060005,
  301. 0x91a4, 0xffffffff, 0x00000009,
  302. 0x91a8, 0xffffffff, 0x00080007,
  303. 0x91ac, 0xffffffff, 0x000b000a,
  304. 0x91b0, 0xffffffff, 0x00050004,
  305. 0x91b4, 0xffffffff, 0x00070006,
  306. 0x91b8, 0xffffffff, 0x0008000b,
  307. 0x91bc, 0xffffffff, 0x000a0009,
  308. 0x91c0, 0xffffffff, 0x000d000c,
  309. 0x91c4, 0xffffffff, 0x00060005,
  310. 0x91c8, 0xffffffff, 0x00080007,
  311. 0x91cc, 0xffffffff, 0x0000000b,
  312. 0x91d0, 0xffffffff, 0x000a0009,
  313. 0x91d4, 0xffffffff, 0x000d000c,
  314. 0x91d8, 0xffffffff, 0x00070006,
  315. 0x91dc, 0xffffffff, 0x00090008,
  316. 0x91e0, 0xffffffff, 0x0000000c,
  317. 0x91e4, 0xffffffff, 0x000b000a,
  318. 0x91e8, 0xffffffff, 0x000e000d,
  319. 0x91ec, 0xffffffff, 0x00080007,
  320. 0x91f0, 0xffffffff, 0x000a0009,
  321. 0x91f4, 0xffffffff, 0x0000000d,
  322. 0x91f8, 0xffffffff, 0x000c000b,
  323. 0x91fc, 0xffffffff, 0x000f000e,
  324. 0x9200, 0xffffffff, 0x00090008,
  325. 0x9204, 0xffffffff, 0x000b000a,
  326. 0x9208, 0xffffffff, 0x000c000f,
  327. 0x920c, 0xffffffff, 0x000e000d,
  328. 0x9210, 0xffffffff, 0x00110010,
  329. 0x9214, 0xffffffff, 0x000a0009,
  330. 0x9218, 0xffffffff, 0x000c000b,
  331. 0x921c, 0xffffffff, 0x0000000f,
  332. 0x9220, 0xffffffff, 0x000e000d,
  333. 0x9224, 0xffffffff, 0x00110010,
  334. 0x9228, 0xffffffff, 0x000b000a,
  335. 0x922c, 0xffffffff, 0x000d000c,
  336. 0x9230, 0xffffffff, 0x00000010,
  337. 0x9234, 0xffffffff, 0x000f000e,
  338. 0x9238, 0xffffffff, 0x00120011,
  339. 0x923c, 0xffffffff, 0x000c000b,
  340. 0x9240, 0xffffffff, 0x000e000d,
  341. 0x9244, 0xffffffff, 0x00000011,
  342. 0x9248, 0xffffffff, 0x0010000f,
  343. 0x924c, 0xffffffff, 0x00130012,
  344. 0x9250, 0xffffffff, 0x000d000c,
  345. 0x9254, 0xffffffff, 0x000f000e,
  346. 0x9258, 0xffffffff, 0x00100013,
  347. 0x925c, 0xffffffff, 0x00120011,
  348. 0x9260, 0xffffffff, 0x00150014,
  349. 0x9264, 0xffffffff, 0x000e000d,
  350. 0x9268, 0xffffffff, 0x0010000f,
  351. 0x926c, 0xffffffff, 0x00000013,
  352. 0x9270, 0xffffffff, 0x00120011,
  353. 0x9274, 0xffffffff, 0x00150014,
  354. 0x9278, 0xffffffff, 0x000f000e,
  355. 0x927c, 0xffffffff, 0x00110010,
  356. 0x9280, 0xffffffff, 0x00000014,
  357. 0x9284, 0xffffffff, 0x00130012,
  358. 0x9288, 0xffffffff, 0x00160015,
  359. 0x928c, 0xffffffff, 0x0010000f,
  360. 0x9290, 0xffffffff, 0x00120011,
  361. 0x9294, 0xffffffff, 0x00000015,
  362. 0x9298, 0xffffffff, 0x00140013,
  363. 0x929c, 0xffffffff, 0x00170016,
  364. 0x9150, 0xffffffff, 0x96940200,
  365. 0x8708, 0xffffffff, 0x00900100,
  366. 0xc478, 0xffffffff, 0x00000080,
  367. 0xc404, 0xffffffff, 0x0020003f,
  368. 0x30, 0xffffffff, 0x0000001c,
  369. 0x34, 0x000f0000, 0x000f0000,
  370. 0x160c, 0xffffffff, 0x00000100,
  371. 0x1024, 0xffffffff, 0x00000100,
  372. 0x102c, 0x00000101, 0x00000000,
  373. 0x20a8, 0xffffffff, 0x00000104,
  374. 0x264c, 0x000c0000, 0x000c0000,
  375. 0x2648, 0x000c0000, 0x000c0000,
  376. 0x55e4, 0xff000fff, 0x00000100,
  377. 0x55e8, 0x00000001, 0x00000001,
  378. 0x2f50, 0x00000001, 0x00000001,
  379. 0x30cc, 0xc0000fff, 0x00000104,
  380. 0xc1e4, 0x00000001, 0x00000001,
  381. 0xd0c0, 0xfffffff0, 0x00000100,
  382. 0xd8c0, 0xfffffff0, 0x00000100
  383. };
  384. static const u32 pitcairn_mgcg_cgcg_init[] =
  385. {
  386. 0xc400, 0xffffffff, 0xfffffffc,
  387. 0x802c, 0xffffffff, 0xe0000000,
  388. 0x9a60, 0xffffffff, 0x00000100,
  389. 0x92a4, 0xffffffff, 0x00000100,
  390. 0xc164, 0xffffffff, 0x00000100,
  391. 0x9774, 0xffffffff, 0x00000100,
  392. 0x8984, 0xffffffff, 0x06000100,
  393. 0x8a18, 0xffffffff, 0x00000100,
  394. 0x92a0, 0xffffffff, 0x00000100,
  395. 0xc380, 0xffffffff, 0x00000100,
  396. 0x8b28, 0xffffffff, 0x00000100,
  397. 0x9144, 0xffffffff, 0x00000100,
  398. 0x8d88, 0xffffffff, 0x00000100,
  399. 0x8d8c, 0xffffffff, 0x00000100,
  400. 0x9030, 0xffffffff, 0x00000100,
  401. 0x9034, 0xffffffff, 0x00000100,
  402. 0x9038, 0xffffffff, 0x00000100,
  403. 0x903c, 0xffffffff, 0x00000100,
  404. 0xad80, 0xffffffff, 0x00000100,
  405. 0xac54, 0xffffffff, 0x00000100,
  406. 0x897c, 0xffffffff, 0x06000100,
  407. 0x9868, 0xffffffff, 0x00000100,
  408. 0x9510, 0xffffffff, 0x00000100,
  409. 0xaf04, 0xffffffff, 0x00000100,
  410. 0xae04, 0xffffffff, 0x00000100,
  411. 0x949c, 0xffffffff, 0x00000100,
  412. 0x802c, 0xffffffff, 0xe0000000,
  413. 0x9160, 0xffffffff, 0x00010000,
  414. 0x9164, 0xffffffff, 0x00030002,
  415. 0x9168, 0xffffffff, 0x00040007,
  416. 0x916c, 0xffffffff, 0x00060005,
  417. 0x9170, 0xffffffff, 0x00090008,
  418. 0x9174, 0xffffffff, 0x00020001,
  419. 0x9178, 0xffffffff, 0x00040003,
  420. 0x917c, 0xffffffff, 0x00000007,
  421. 0x9180, 0xffffffff, 0x00060005,
  422. 0x9184, 0xffffffff, 0x00090008,
  423. 0x9188, 0xffffffff, 0x00030002,
  424. 0x918c, 0xffffffff, 0x00050004,
  425. 0x9190, 0xffffffff, 0x00000008,
  426. 0x9194, 0xffffffff, 0x00070006,
  427. 0x9198, 0xffffffff, 0x000a0009,
  428. 0x919c, 0xffffffff, 0x00040003,
  429. 0x91a0, 0xffffffff, 0x00060005,
  430. 0x91a4, 0xffffffff, 0x00000009,
  431. 0x91a8, 0xffffffff, 0x00080007,
  432. 0x91ac, 0xffffffff, 0x000b000a,
  433. 0x91b0, 0xffffffff, 0x00050004,
  434. 0x91b4, 0xffffffff, 0x00070006,
  435. 0x91b8, 0xffffffff, 0x0008000b,
  436. 0x91bc, 0xffffffff, 0x000a0009,
  437. 0x91c0, 0xffffffff, 0x000d000c,
  438. 0x9200, 0xffffffff, 0x00090008,
  439. 0x9204, 0xffffffff, 0x000b000a,
  440. 0x9208, 0xffffffff, 0x000c000f,
  441. 0x920c, 0xffffffff, 0x000e000d,
  442. 0x9210, 0xffffffff, 0x00110010,
  443. 0x9214, 0xffffffff, 0x000a0009,
  444. 0x9218, 0xffffffff, 0x000c000b,
  445. 0x921c, 0xffffffff, 0x0000000f,
  446. 0x9220, 0xffffffff, 0x000e000d,
  447. 0x9224, 0xffffffff, 0x00110010,
  448. 0x9228, 0xffffffff, 0x000b000a,
  449. 0x922c, 0xffffffff, 0x000d000c,
  450. 0x9230, 0xffffffff, 0x00000010,
  451. 0x9234, 0xffffffff, 0x000f000e,
  452. 0x9238, 0xffffffff, 0x00120011,
  453. 0x923c, 0xffffffff, 0x000c000b,
  454. 0x9240, 0xffffffff, 0x000e000d,
  455. 0x9244, 0xffffffff, 0x00000011,
  456. 0x9248, 0xffffffff, 0x0010000f,
  457. 0x924c, 0xffffffff, 0x00130012,
  458. 0x9250, 0xffffffff, 0x000d000c,
  459. 0x9254, 0xffffffff, 0x000f000e,
  460. 0x9258, 0xffffffff, 0x00100013,
  461. 0x925c, 0xffffffff, 0x00120011,
  462. 0x9260, 0xffffffff, 0x00150014,
  463. 0x9150, 0xffffffff, 0x96940200,
  464. 0x8708, 0xffffffff, 0x00900100,
  465. 0xc478, 0xffffffff, 0x00000080,
  466. 0xc404, 0xffffffff, 0x0020003f,
  467. 0x30, 0xffffffff, 0x0000001c,
  468. 0x34, 0x000f0000, 0x000f0000,
  469. 0x160c, 0xffffffff, 0x00000100,
  470. 0x1024, 0xffffffff, 0x00000100,
  471. 0x102c, 0x00000101, 0x00000000,
  472. 0x20a8, 0xffffffff, 0x00000104,
  473. 0x55e4, 0xff000fff, 0x00000100,
  474. 0x55e8, 0x00000001, 0x00000001,
  475. 0x2f50, 0x00000001, 0x00000001,
  476. 0x30cc, 0xc0000fff, 0x00000104,
  477. 0xc1e4, 0x00000001, 0x00000001,
  478. 0xd0c0, 0xfffffff0, 0x00000100,
  479. 0xd8c0, 0xfffffff0, 0x00000100
  480. };
  481. static const u32 verde_mgcg_cgcg_init[] =
  482. {
  483. 0xc400, 0xffffffff, 0xfffffffc,
  484. 0x802c, 0xffffffff, 0xe0000000,
  485. 0x9a60, 0xffffffff, 0x00000100,
  486. 0x92a4, 0xffffffff, 0x00000100,
  487. 0xc164, 0xffffffff, 0x00000100,
  488. 0x9774, 0xffffffff, 0x00000100,
  489. 0x8984, 0xffffffff, 0x06000100,
  490. 0x8a18, 0xffffffff, 0x00000100,
  491. 0x92a0, 0xffffffff, 0x00000100,
  492. 0xc380, 0xffffffff, 0x00000100,
  493. 0x8b28, 0xffffffff, 0x00000100,
  494. 0x9144, 0xffffffff, 0x00000100,
  495. 0x8d88, 0xffffffff, 0x00000100,
  496. 0x8d8c, 0xffffffff, 0x00000100,
  497. 0x9030, 0xffffffff, 0x00000100,
  498. 0x9034, 0xffffffff, 0x00000100,
  499. 0x9038, 0xffffffff, 0x00000100,
  500. 0x903c, 0xffffffff, 0x00000100,
  501. 0xad80, 0xffffffff, 0x00000100,
  502. 0xac54, 0xffffffff, 0x00000100,
  503. 0x897c, 0xffffffff, 0x06000100,
  504. 0x9868, 0xffffffff, 0x00000100,
  505. 0x9510, 0xffffffff, 0x00000100,
  506. 0xaf04, 0xffffffff, 0x00000100,
  507. 0xae04, 0xffffffff, 0x00000100,
  508. 0x949c, 0xffffffff, 0x00000100,
  509. 0x802c, 0xffffffff, 0xe0000000,
  510. 0x9160, 0xffffffff, 0x00010000,
  511. 0x9164, 0xffffffff, 0x00030002,
  512. 0x9168, 0xffffffff, 0x00040007,
  513. 0x916c, 0xffffffff, 0x00060005,
  514. 0x9170, 0xffffffff, 0x00090008,
  515. 0x9174, 0xffffffff, 0x00020001,
  516. 0x9178, 0xffffffff, 0x00040003,
  517. 0x917c, 0xffffffff, 0x00000007,
  518. 0x9180, 0xffffffff, 0x00060005,
  519. 0x9184, 0xffffffff, 0x00090008,
  520. 0x9188, 0xffffffff, 0x00030002,
  521. 0x918c, 0xffffffff, 0x00050004,
  522. 0x9190, 0xffffffff, 0x00000008,
  523. 0x9194, 0xffffffff, 0x00070006,
  524. 0x9198, 0xffffffff, 0x000a0009,
  525. 0x919c, 0xffffffff, 0x00040003,
  526. 0x91a0, 0xffffffff, 0x00060005,
  527. 0x91a4, 0xffffffff, 0x00000009,
  528. 0x91a8, 0xffffffff, 0x00080007,
  529. 0x91ac, 0xffffffff, 0x000b000a,
  530. 0x91b0, 0xffffffff, 0x00050004,
  531. 0x91b4, 0xffffffff, 0x00070006,
  532. 0x91b8, 0xffffffff, 0x0008000b,
  533. 0x91bc, 0xffffffff, 0x000a0009,
  534. 0x91c0, 0xffffffff, 0x000d000c,
  535. 0x9200, 0xffffffff, 0x00090008,
  536. 0x9204, 0xffffffff, 0x000b000a,
  537. 0x9208, 0xffffffff, 0x000c000f,
  538. 0x920c, 0xffffffff, 0x000e000d,
  539. 0x9210, 0xffffffff, 0x00110010,
  540. 0x9214, 0xffffffff, 0x000a0009,
  541. 0x9218, 0xffffffff, 0x000c000b,
  542. 0x921c, 0xffffffff, 0x0000000f,
  543. 0x9220, 0xffffffff, 0x000e000d,
  544. 0x9224, 0xffffffff, 0x00110010,
  545. 0x9228, 0xffffffff, 0x000b000a,
  546. 0x922c, 0xffffffff, 0x000d000c,
  547. 0x9230, 0xffffffff, 0x00000010,
  548. 0x9234, 0xffffffff, 0x000f000e,
  549. 0x9238, 0xffffffff, 0x00120011,
  550. 0x923c, 0xffffffff, 0x000c000b,
  551. 0x9240, 0xffffffff, 0x000e000d,
  552. 0x9244, 0xffffffff, 0x00000011,
  553. 0x9248, 0xffffffff, 0x0010000f,
  554. 0x924c, 0xffffffff, 0x00130012,
  555. 0x9250, 0xffffffff, 0x000d000c,
  556. 0x9254, 0xffffffff, 0x000f000e,
  557. 0x9258, 0xffffffff, 0x00100013,
  558. 0x925c, 0xffffffff, 0x00120011,
  559. 0x9260, 0xffffffff, 0x00150014,
  560. 0x9150, 0xffffffff, 0x96940200,
  561. 0x8708, 0xffffffff, 0x00900100,
  562. 0xc478, 0xffffffff, 0x00000080,
  563. 0xc404, 0xffffffff, 0x0020003f,
  564. 0x30, 0xffffffff, 0x0000001c,
  565. 0x34, 0x000f0000, 0x000f0000,
  566. 0x160c, 0xffffffff, 0x00000100,
  567. 0x1024, 0xffffffff, 0x00000100,
  568. 0x102c, 0x00000101, 0x00000000,
  569. 0x20a8, 0xffffffff, 0x00000104,
  570. 0x264c, 0x000c0000, 0x000c0000,
  571. 0x2648, 0x000c0000, 0x000c0000,
  572. 0x55e4, 0xff000fff, 0x00000100,
  573. 0x55e8, 0x00000001, 0x00000001,
  574. 0x2f50, 0x00000001, 0x00000001,
  575. 0x30cc, 0xc0000fff, 0x00000104,
  576. 0xc1e4, 0x00000001, 0x00000001,
  577. 0xd0c0, 0xfffffff0, 0x00000100,
  578. 0xd8c0, 0xfffffff0, 0x00000100
  579. };
  580. static const u32 oland_mgcg_cgcg_init[] =
  581. {
  582. 0xc400, 0xffffffff, 0xfffffffc,
  583. 0x802c, 0xffffffff, 0xe0000000,
  584. 0x9a60, 0xffffffff, 0x00000100,
  585. 0x92a4, 0xffffffff, 0x00000100,
  586. 0xc164, 0xffffffff, 0x00000100,
  587. 0x9774, 0xffffffff, 0x00000100,
  588. 0x8984, 0xffffffff, 0x06000100,
  589. 0x8a18, 0xffffffff, 0x00000100,
  590. 0x92a0, 0xffffffff, 0x00000100,
  591. 0xc380, 0xffffffff, 0x00000100,
  592. 0x8b28, 0xffffffff, 0x00000100,
  593. 0x9144, 0xffffffff, 0x00000100,
  594. 0x8d88, 0xffffffff, 0x00000100,
  595. 0x8d8c, 0xffffffff, 0x00000100,
  596. 0x9030, 0xffffffff, 0x00000100,
  597. 0x9034, 0xffffffff, 0x00000100,
  598. 0x9038, 0xffffffff, 0x00000100,
  599. 0x903c, 0xffffffff, 0x00000100,
  600. 0xad80, 0xffffffff, 0x00000100,
  601. 0xac54, 0xffffffff, 0x00000100,
  602. 0x897c, 0xffffffff, 0x06000100,
  603. 0x9868, 0xffffffff, 0x00000100,
  604. 0x9510, 0xffffffff, 0x00000100,
  605. 0xaf04, 0xffffffff, 0x00000100,
  606. 0xae04, 0xffffffff, 0x00000100,
  607. 0x949c, 0xffffffff, 0x00000100,
  608. 0x802c, 0xffffffff, 0xe0000000,
  609. 0x9160, 0xffffffff, 0x00010000,
  610. 0x9164, 0xffffffff, 0x00030002,
  611. 0x9168, 0xffffffff, 0x00040007,
  612. 0x916c, 0xffffffff, 0x00060005,
  613. 0x9170, 0xffffffff, 0x00090008,
  614. 0x9174, 0xffffffff, 0x00020001,
  615. 0x9178, 0xffffffff, 0x00040003,
  616. 0x917c, 0xffffffff, 0x00000007,
  617. 0x9180, 0xffffffff, 0x00060005,
  618. 0x9184, 0xffffffff, 0x00090008,
  619. 0x9188, 0xffffffff, 0x00030002,
  620. 0x918c, 0xffffffff, 0x00050004,
  621. 0x9190, 0xffffffff, 0x00000008,
  622. 0x9194, 0xffffffff, 0x00070006,
  623. 0x9198, 0xffffffff, 0x000a0009,
  624. 0x919c, 0xffffffff, 0x00040003,
  625. 0x91a0, 0xffffffff, 0x00060005,
  626. 0x91a4, 0xffffffff, 0x00000009,
  627. 0x91a8, 0xffffffff, 0x00080007,
  628. 0x91ac, 0xffffffff, 0x000b000a,
  629. 0x91b0, 0xffffffff, 0x00050004,
  630. 0x91b4, 0xffffffff, 0x00070006,
  631. 0x91b8, 0xffffffff, 0x0008000b,
  632. 0x91bc, 0xffffffff, 0x000a0009,
  633. 0x91c0, 0xffffffff, 0x000d000c,
  634. 0x91c4, 0xffffffff, 0x00060005,
  635. 0x91c8, 0xffffffff, 0x00080007,
  636. 0x91cc, 0xffffffff, 0x0000000b,
  637. 0x91d0, 0xffffffff, 0x000a0009,
  638. 0x91d4, 0xffffffff, 0x000d000c,
  639. 0x9150, 0xffffffff, 0x96940200,
  640. 0x8708, 0xffffffff, 0x00900100,
  641. 0xc478, 0xffffffff, 0x00000080,
  642. 0xc404, 0xffffffff, 0x0020003f,
  643. 0x30, 0xffffffff, 0x0000001c,
  644. 0x34, 0x000f0000, 0x000f0000,
  645. 0x160c, 0xffffffff, 0x00000100,
  646. 0x1024, 0xffffffff, 0x00000100,
  647. 0x102c, 0x00000101, 0x00000000,
  648. 0x20a8, 0xffffffff, 0x00000104,
  649. 0x264c, 0x000c0000, 0x000c0000,
  650. 0x2648, 0x000c0000, 0x000c0000,
  651. 0x55e4, 0xff000fff, 0x00000100,
  652. 0x55e8, 0x00000001, 0x00000001,
  653. 0x2f50, 0x00000001, 0x00000001,
  654. 0x30cc, 0xc0000fff, 0x00000104,
  655. 0xc1e4, 0x00000001, 0x00000001,
  656. 0xd0c0, 0xfffffff0, 0x00000100,
  657. 0xd8c0, 0xfffffff0, 0x00000100
  658. };
  659. static u32 verde_pg_init[] =
  660. {
  661. 0x353c, 0xffffffff, 0x40000,
  662. 0x3538, 0xffffffff, 0x200010ff,
  663. 0x353c, 0xffffffff, 0x0,
  664. 0x353c, 0xffffffff, 0x0,
  665. 0x353c, 0xffffffff, 0x0,
  666. 0x353c, 0xffffffff, 0x0,
  667. 0x353c, 0xffffffff, 0x0,
  668. 0x353c, 0xffffffff, 0x7007,
  669. 0x3538, 0xffffffff, 0x300010ff,
  670. 0x353c, 0xffffffff, 0x0,
  671. 0x353c, 0xffffffff, 0x0,
  672. 0x353c, 0xffffffff, 0x0,
  673. 0x353c, 0xffffffff, 0x0,
  674. 0x353c, 0xffffffff, 0x0,
  675. 0x353c, 0xffffffff, 0x400000,
  676. 0x3538, 0xffffffff, 0x100010ff,
  677. 0x353c, 0xffffffff, 0x0,
  678. 0x353c, 0xffffffff, 0x0,
  679. 0x353c, 0xffffffff, 0x0,
  680. 0x353c, 0xffffffff, 0x0,
  681. 0x353c, 0xffffffff, 0x0,
  682. 0x353c, 0xffffffff, 0x120200,
  683. 0x3538, 0xffffffff, 0x500010ff,
  684. 0x353c, 0xffffffff, 0x0,
  685. 0x353c, 0xffffffff, 0x0,
  686. 0x353c, 0xffffffff, 0x0,
  687. 0x353c, 0xffffffff, 0x0,
  688. 0x353c, 0xffffffff, 0x0,
  689. 0x353c, 0xffffffff, 0x1e1e16,
  690. 0x3538, 0xffffffff, 0x600010ff,
  691. 0x353c, 0xffffffff, 0x0,
  692. 0x353c, 0xffffffff, 0x0,
  693. 0x353c, 0xffffffff, 0x0,
  694. 0x353c, 0xffffffff, 0x0,
  695. 0x353c, 0xffffffff, 0x0,
  696. 0x353c, 0xffffffff, 0x171f1e,
  697. 0x3538, 0xffffffff, 0x700010ff,
  698. 0x353c, 0xffffffff, 0x0,
  699. 0x353c, 0xffffffff, 0x0,
  700. 0x353c, 0xffffffff, 0x0,
  701. 0x353c, 0xffffffff, 0x0,
  702. 0x353c, 0xffffffff, 0x0,
  703. 0x353c, 0xffffffff, 0x0,
  704. 0x3538, 0xffffffff, 0x9ff,
  705. 0x3500, 0xffffffff, 0x0,
  706. 0x3504, 0xffffffff, 0x10000800,
  707. 0x3504, 0xffffffff, 0xf,
  708. 0x3504, 0xffffffff, 0xf,
  709. 0x3500, 0xffffffff, 0x4,
  710. 0x3504, 0xffffffff, 0x1000051e,
  711. 0x3504, 0xffffffff, 0xffff,
  712. 0x3504, 0xffffffff, 0xffff,
  713. 0x3500, 0xffffffff, 0x8,
  714. 0x3504, 0xffffffff, 0x80500,
  715. 0x3500, 0xffffffff, 0x12,
  716. 0x3504, 0xffffffff, 0x9050c,
  717. 0x3500, 0xffffffff, 0x1d,
  718. 0x3504, 0xffffffff, 0xb052c,
  719. 0x3500, 0xffffffff, 0x2a,
  720. 0x3504, 0xffffffff, 0x1053e,
  721. 0x3500, 0xffffffff, 0x2d,
  722. 0x3504, 0xffffffff, 0x10546,
  723. 0x3500, 0xffffffff, 0x30,
  724. 0x3504, 0xffffffff, 0xa054e,
  725. 0x3500, 0xffffffff, 0x3c,
  726. 0x3504, 0xffffffff, 0x1055f,
  727. 0x3500, 0xffffffff, 0x3f,
  728. 0x3504, 0xffffffff, 0x10567,
  729. 0x3500, 0xffffffff, 0x42,
  730. 0x3504, 0xffffffff, 0x1056f,
  731. 0x3500, 0xffffffff, 0x45,
  732. 0x3504, 0xffffffff, 0x10572,
  733. 0x3500, 0xffffffff, 0x48,
  734. 0x3504, 0xffffffff, 0x20575,
  735. 0x3500, 0xffffffff, 0x4c,
  736. 0x3504, 0xffffffff, 0x190801,
  737. 0x3500, 0xffffffff, 0x67,
  738. 0x3504, 0xffffffff, 0x1082a,
  739. 0x3500, 0xffffffff, 0x6a,
  740. 0x3504, 0xffffffff, 0x1b082d,
  741. 0x3500, 0xffffffff, 0x87,
  742. 0x3504, 0xffffffff, 0x310851,
  743. 0x3500, 0xffffffff, 0xba,
  744. 0x3504, 0xffffffff, 0x891,
  745. 0x3500, 0xffffffff, 0xbc,
  746. 0x3504, 0xffffffff, 0x893,
  747. 0x3500, 0xffffffff, 0xbe,
  748. 0x3504, 0xffffffff, 0x20895,
  749. 0x3500, 0xffffffff, 0xc2,
  750. 0x3504, 0xffffffff, 0x20899,
  751. 0x3500, 0xffffffff, 0xc6,
  752. 0x3504, 0xffffffff, 0x2089d,
  753. 0x3500, 0xffffffff, 0xca,
  754. 0x3504, 0xffffffff, 0x8a1,
  755. 0x3500, 0xffffffff, 0xcc,
  756. 0x3504, 0xffffffff, 0x8a3,
  757. 0x3500, 0xffffffff, 0xce,
  758. 0x3504, 0xffffffff, 0x308a5,
  759. 0x3500, 0xffffffff, 0xd3,
  760. 0x3504, 0xffffffff, 0x6d08cd,
  761. 0x3500, 0xffffffff, 0x142,
  762. 0x3504, 0xffffffff, 0x2000095a,
  763. 0x3504, 0xffffffff, 0x1,
  764. 0x3500, 0xffffffff, 0x144,
  765. 0x3504, 0xffffffff, 0x301f095b,
  766. 0x3500, 0xffffffff, 0x165,
  767. 0x3504, 0xffffffff, 0xc094d,
  768. 0x3500, 0xffffffff, 0x173,
  769. 0x3504, 0xffffffff, 0xf096d,
  770. 0x3500, 0xffffffff, 0x184,
  771. 0x3504, 0xffffffff, 0x15097f,
  772. 0x3500, 0xffffffff, 0x19b,
  773. 0x3504, 0xffffffff, 0xc0998,
  774. 0x3500, 0xffffffff, 0x1a9,
  775. 0x3504, 0xffffffff, 0x409a7,
  776. 0x3500, 0xffffffff, 0x1af,
  777. 0x3504, 0xffffffff, 0xcdc,
  778. 0x3500, 0xffffffff, 0x1b1,
  779. 0x3504, 0xffffffff, 0x800,
  780. 0x3508, 0xffffffff, 0x6c9b2000,
  781. 0x3510, 0xfc00, 0x2000,
  782. 0x3544, 0xffffffff, 0xfc0,
  783. 0x28d4, 0x00000100, 0x100
  784. };
  785. static void si_init_golden_registers(struct radeon_device *rdev)
  786. {
  787. switch (rdev->family) {
  788. case CHIP_TAHITI:
  789. radeon_program_register_sequence(rdev,
  790. tahiti_golden_registers,
  791. (const u32)ARRAY_SIZE(tahiti_golden_registers));
  792. radeon_program_register_sequence(rdev,
  793. tahiti_golden_rlc_registers,
  794. (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
  795. radeon_program_register_sequence(rdev,
  796. tahiti_mgcg_cgcg_init,
  797. (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
  798. radeon_program_register_sequence(rdev,
  799. tahiti_golden_registers2,
  800. (const u32)ARRAY_SIZE(tahiti_golden_registers2));
  801. break;
  802. case CHIP_PITCAIRN:
  803. radeon_program_register_sequence(rdev,
  804. pitcairn_golden_registers,
  805. (const u32)ARRAY_SIZE(pitcairn_golden_registers));
  806. radeon_program_register_sequence(rdev,
  807. pitcairn_golden_rlc_registers,
  808. (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
  809. radeon_program_register_sequence(rdev,
  810. pitcairn_mgcg_cgcg_init,
  811. (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
  812. break;
  813. case CHIP_VERDE:
  814. radeon_program_register_sequence(rdev,
  815. verde_golden_registers,
  816. (const u32)ARRAY_SIZE(verde_golden_registers));
  817. radeon_program_register_sequence(rdev,
  818. verde_golden_rlc_registers,
  819. (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
  820. radeon_program_register_sequence(rdev,
  821. verde_mgcg_cgcg_init,
  822. (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
  823. radeon_program_register_sequence(rdev,
  824. verde_pg_init,
  825. (const u32)ARRAY_SIZE(verde_pg_init));
  826. break;
  827. case CHIP_OLAND:
  828. radeon_program_register_sequence(rdev,
  829. oland_golden_registers,
  830. (const u32)ARRAY_SIZE(oland_golden_registers));
  831. radeon_program_register_sequence(rdev,
  832. oland_golden_rlc_registers,
  833. (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
  834. radeon_program_register_sequence(rdev,
  835. oland_mgcg_cgcg_init,
  836. (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
  837. break;
  838. default:
  839. break;
  840. }
  841. }
  842. #define PCIE_BUS_CLK 10000
  843. #define TCLK (PCIE_BUS_CLK / 10)
  844. /**
  845. * si_get_xclk - get the xclk
  846. *
  847. * @rdev: radeon_device pointer
  848. *
  849. * Returns the reference clock used by the gfx engine
  850. * (SI).
  851. */
  852. u32 si_get_xclk(struct radeon_device *rdev)
  853. {
  854. u32 reference_clock = rdev->clock.spll.reference_freq;
  855. u32 tmp;
  856. tmp = RREG32(CG_CLKPIN_CNTL_2);
  857. if (tmp & MUX_TCLK_TO_XCLK)
  858. return TCLK;
  859. tmp = RREG32(CG_CLKPIN_CNTL);
  860. if (tmp & XTALIN_DIVIDE)
  861. return reference_clock / 4;
  862. return reference_clock;
  863. }
  864. /* get temperature in millidegrees */
  865. int si_get_temp(struct radeon_device *rdev)
  866. {
  867. u32 temp;
  868. int actual_temp = 0;
  869. temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  870. CTF_TEMP_SHIFT;
  871. if (temp & 0x200)
  872. actual_temp = 255;
  873. else
  874. actual_temp = temp & 0x1ff;
  875. actual_temp = (actual_temp * 1000);
  876. return actual_temp;
  877. }
  878. #define TAHITI_IO_MC_REGS_SIZE 36
  879. static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  880. {0x0000006f, 0x03044000},
  881. {0x00000070, 0x0480c018},
  882. {0x00000071, 0x00000040},
  883. {0x00000072, 0x01000000},
  884. {0x00000074, 0x000000ff},
  885. {0x00000075, 0x00143400},
  886. {0x00000076, 0x08ec0800},
  887. {0x00000077, 0x040000cc},
  888. {0x00000079, 0x00000000},
  889. {0x0000007a, 0x21000409},
  890. {0x0000007c, 0x00000000},
  891. {0x0000007d, 0xe8000000},
  892. {0x0000007e, 0x044408a8},
  893. {0x0000007f, 0x00000003},
  894. {0x00000080, 0x00000000},
  895. {0x00000081, 0x01000000},
  896. {0x00000082, 0x02000000},
  897. {0x00000083, 0x00000000},
  898. {0x00000084, 0xe3f3e4f4},
  899. {0x00000085, 0x00052024},
  900. {0x00000087, 0x00000000},
  901. {0x00000088, 0x66036603},
  902. {0x00000089, 0x01000000},
  903. {0x0000008b, 0x1c0a0000},
  904. {0x0000008c, 0xff010000},
  905. {0x0000008e, 0xffffefff},
  906. {0x0000008f, 0xfff3efff},
  907. {0x00000090, 0xfff3efbf},
  908. {0x00000094, 0x00101101},
  909. {0x00000095, 0x00000fff},
  910. {0x00000096, 0x00116fff},
  911. {0x00000097, 0x60010000},
  912. {0x00000098, 0x10010000},
  913. {0x00000099, 0x00006000},
  914. {0x0000009a, 0x00001000},
  915. {0x0000009f, 0x00a77400}
  916. };
  917. static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  918. {0x0000006f, 0x03044000},
  919. {0x00000070, 0x0480c018},
  920. {0x00000071, 0x00000040},
  921. {0x00000072, 0x01000000},
  922. {0x00000074, 0x000000ff},
  923. {0x00000075, 0x00143400},
  924. {0x00000076, 0x08ec0800},
  925. {0x00000077, 0x040000cc},
  926. {0x00000079, 0x00000000},
  927. {0x0000007a, 0x21000409},
  928. {0x0000007c, 0x00000000},
  929. {0x0000007d, 0xe8000000},
  930. {0x0000007e, 0x044408a8},
  931. {0x0000007f, 0x00000003},
  932. {0x00000080, 0x00000000},
  933. {0x00000081, 0x01000000},
  934. {0x00000082, 0x02000000},
  935. {0x00000083, 0x00000000},
  936. {0x00000084, 0xe3f3e4f4},
  937. {0x00000085, 0x00052024},
  938. {0x00000087, 0x00000000},
  939. {0x00000088, 0x66036603},
  940. {0x00000089, 0x01000000},
  941. {0x0000008b, 0x1c0a0000},
  942. {0x0000008c, 0xff010000},
  943. {0x0000008e, 0xffffefff},
  944. {0x0000008f, 0xfff3efff},
  945. {0x00000090, 0xfff3efbf},
  946. {0x00000094, 0x00101101},
  947. {0x00000095, 0x00000fff},
  948. {0x00000096, 0x00116fff},
  949. {0x00000097, 0x60010000},
  950. {0x00000098, 0x10010000},
  951. {0x00000099, 0x00006000},
  952. {0x0000009a, 0x00001000},
  953. {0x0000009f, 0x00a47400}
  954. };
  955. static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  956. {0x0000006f, 0x03044000},
  957. {0x00000070, 0x0480c018},
  958. {0x00000071, 0x00000040},
  959. {0x00000072, 0x01000000},
  960. {0x00000074, 0x000000ff},
  961. {0x00000075, 0x00143400},
  962. {0x00000076, 0x08ec0800},
  963. {0x00000077, 0x040000cc},
  964. {0x00000079, 0x00000000},
  965. {0x0000007a, 0x21000409},
  966. {0x0000007c, 0x00000000},
  967. {0x0000007d, 0xe8000000},
  968. {0x0000007e, 0x044408a8},
  969. {0x0000007f, 0x00000003},
  970. {0x00000080, 0x00000000},
  971. {0x00000081, 0x01000000},
  972. {0x00000082, 0x02000000},
  973. {0x00000083, 0x00000000},
  974. {0x00000084, 0xe3f3e4f4},
  975. {0x00000085, 0x00052024},
  976. {0x00000087, 0x00000000},
  977. {0x00000088, 0x66036603},
  978. {0x00000089, 0x01000000},
  979. {0x0000008b, 0x1c0a0000},
  980. {0x0000008c, 0xff010000},
  981. {0x0000008e, 0xffffefff},
  982. {0x0000008f, 0xfff3efff},
  983. {0x00000090, 0xfff3efbf},
  984. {0x00000094, 0x00101101},
  985. {0x00000095, 0x00000fff},
  986. {0x00000096, 0x00116fff},
  987. {0x00000097, 0x60010000},
  988. {0x00000098, 0x10010000},
  989. {0x00000099, 0x00006000},
  990. {0x0000009a, 0x00001000},
  991. {0x0000009f, 0x00a37400}
  992. };
  993. static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  994. {0x0000006f, 0x03044000},
  995. {0x00000070, 0x0480c018},
  996. {0x00000071, 0x00000040},
  997. {0x00000072, 0x01000000},
  998. {0x00000074, 0x000000ff},
  999. {0x00000075, 0x00143400},
  1000. {0x00000076, 0x08ec0800},
  1001. {0x00000077, 0x040000cc},
  1002. {0x00000079, 0x00000000},
  1003. {0x0000007a, 0x21000409},
  1004. {0x0000007c, 0x00000000},
  1005. {0x0000007d, 0xe8000000},
  1006. {0x0000007e, 0x044408a8},
  1007. {0x0000007f, 0x00000003},
  1008. {0x00000080, 0x00000000},
  1009. {0x00000081, 0x01000000},
  1010. {0x00000082, 0x02000000},
  1011. {0x00000083, 0x00000000},
  1012. {0x00000084, 0xe3f3e4f4},
  1013. {0x00000085, 0x00052024},
  1014. {0x00000087, 0x00000000},
  1015. {0x00000088, 0x66036603},
  1016. {0x00000089, 0x01000000},
  1017. {0x0000008b, 0x1c0a0000},
  1018. {0x0000008c, 0xff010000},
  1019. {0x0000008e, 0xffffefff},
  1020. {0x0000008f, 0xfff3efff},
  1021. {0x00000090, 0xfff3efbf},
  1022. {0x00000094, 0x00101101},
  1023. {0x00000095, 0x00000fff},
  1024. {0x00000096, 0x00116fff},
  1025. {0x00000097, 0x60010000},
  1026. {0x00000098, 0x10010000},
  1027. {0x00000099, 0x00006000},
  1028. {0x0000009a, 0x00001000},
  1029. {0x0000009f, 0x00a17730}
  1030. };
  1031. /* ucode loading */
  1032. static int si_mc_load_microcode(struct radeon_device *rdev)
  1033. {
  1034. const __be32 *fw_data;
  1035. u32 running, blackout = 0;
  1036. u32 *io_mc_regs;
  1037. int i, ucode_size, regs_size;
  1038. if (!rdev->mc_fw)
  1039. return -EINVAL;
  1040. switch (rdev->family) {
  1041. case CHIP_TAHITI:
  1042. io_mc_regs = (u32 *)&tahiti_io_mc_regs;
  1043. ucode_size = SI_MC_UCODE_SIZE;
  1044. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1045. break;
  1046. case CHIP_PITCAIRN:
  1047. io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
  1048. ucode_size = SI_MC_UCODE_SIZE;
  1049. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1050. break;
  1051. case CHIP_VERDE:
  1052. default:
  1053. io_mc_regs = (u32 *)&verde_io_mc_regs;
  1054. ucode_size = SI_MC_UCODE_SIZE;
  1055. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1056. break;
  1057. case CHIP_OLAND:
  1058. io_mc_regs = (u32 *)&oland_io_mc_regs;
  1059. ucode_size = OLAND_MC_UCODE_SIZE;
  1060. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1061. break;
  1062. }
  1063. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1064. if (running == 0) {
  1065. if (running) {
  1066. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1067. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1068. }
  1069. /* reset the engine and set to writable */
  1070. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1071. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1072. /* load mc io regs */
  1073. for (i = 0; i < regs_size; i++) {
  1074. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1075. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1076. }
  1077. /* load the MC ucode */
  1078. fw_data = (const __be32 *)rdev->mc_fw->data;
  1079. for (i = 0; i < ucode_size; i++)
  1080. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1081. /* put the engine back into the active state */
  1082. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1083. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1084. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1085. /* wait for training to complete */
  1086. for (i = 0; i < rdev->usec_timeout; i++) {
  1087. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1088. break;
  1089. udelay(1);
  1090. }
  1091. for (i = 0; i < rdev->usec_timeout; i++) {
  1092. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1093. break;
  1094. udelay(1);
  1095. }
  1096. if (running)
  1097. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1098. }
  1099. return 0;
  1100. }
  1101. static int si_init_microcode(struct radeon_device *rdev)
  1102. {
  1103. struct platform_device *pdev;
  1104. const char *chip_name;
  1105. const char *rlc_chip_name;
  1106. size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
  1107. char fw_name[30];
  1108. int err;
  1109. DRM_DEBUG("\n");
  1110. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1111. err = IS_ERR(pdev);
  1112. if (err) {
  1113. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1114. return -EINVAL;
  1115. }
  1116. switch (rdev->family) {
  1117. case CHIP_TAHITI:
  1118. chip_name = "TAHITI";
  1119. rlc_chip_name = "TAHITI";
  1120. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1121. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1122. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1123. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1124. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1125. break;
  1126. case CHIP_PITCAIRN:
  1127. chip_name = "PITCAIRN";
  1128. rlc_chip_name = "PITCAIRN";
  1129. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1130. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1131. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1132. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1133. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1134. break;
  1135. case CHIP_VERDE:
  1136. chip_name = "VERDE";
  1137. rlc_chip_name = "VERDE";
  1138. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1139. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1140. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1141. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1142. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1143. break;
  1144. case CHIP_OLAND:
  1145. chip_name = "OLAND";
  1146. rlc_chip_name = "OLAND";
  1147. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1148. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1149. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1150. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1151. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1152. break;
  1153. default: BUG();
  1154. }
  1155. DRM_INFO("Loading %s Microcode\n", chip_name);
  1156. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1157. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1158. if (err)
  1159. goto out;
  1160. if (rdev->pfp_fw->size != pfp_req_size) {
  1161. printk(KERN_ERR
  1162. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1163. rdev->pfp_fw->size, fw_name);
  1164. err = -EINVAL;
  1165. goto out;
  1166. }
  1167. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1168. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1169. if (err)
  1170. goto out;
  1171. if (rdev->me_fw->size != me_req_size) {
  1172. printk(KERN_ERR
  1173. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1174. rdev->me_fw->size, fw_name);
  1175. err = -EINVAL;
  1176. }
  1177. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1178. err = request_firmware(&rdev->ce_fw, fw_name, &pdev->dev);
  1179. if (err)
  1180. goto out;
  1181. if (rdev->ce_fw->size != ce_req_size) {
  1182. printk(KERN_ERR
  1183. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1184. rdev->ce_fw->size, fw_name);
  1185. err = -EINVAL;
  1186. }
  1187. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1188. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1189. if (err)
  1190. goto out;
  1191. if (rdev->rlc_fw->size != rlc_req_size) {
  1192. printk(KERN_ERR
  1193. "si_rlc: Bogus length %zu in firmware \"%s\"\n",
  1194. rdev->rlc_fw->size, fw_name);
  1195. err = -EINVAL;
  1196. }
  1197. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1198. err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
  1199. if (err)
  1200. goto out;
  1201. if (rdev->mc_fw->size != mc_req_size) {
  1202. printk(KERN_ERR
  1203. "si_mc: Bogus length %zu in firmware \"%s\"\n",
  1204. rdev->mc_fw->size, fw_name);
  1205. err = -EINVAL;
  1206. }
  1207. out:
  1208. platform_device_unregister(pdev);
  1209. if (err) {
  1210. if (err != -EINVAL)
  1211. printk(KERN_ERR
  1212. "si_cp: Failed to load firmware \"%s\"\n",
  1213. fw_name);
  1214. release_firmware(rdev->pfp_fw);
  1215. rdev->pfp_fw = NULL;
  1216. release_firmware(rdev->me_fw);
  1217. rdev->me_fw = NULL;
  1218. release_firmware(rdev->ce_fw);
  1219. rdev->ce_fw = NULL;
  1220. release_firmware(rdev->rlc_fw);
  1221. rdev->rlc_fw = NULL;
  1222. release_firmware(rdev->mc_fw);
  1223. rdev->mc_fw = NULL;
  1224. }
  1225. return err;
  1226. }
  1227. /* watermark setup */
  1228. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1229. struct radeon_crtc *radeon_crtc,
  1230. struct drm_display_mode *mode,
  1231. struct drm_display_mode *other_mode)
  1232. {
  1233. u32 tmp;
  1234. /*
  1235. * Line Buffer Setup
  1236. * There are 3 line buffers, each one shared by 2 display controllers.
  1237. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1238. * the display controllers. The paritioning is done via one of four
  1239. * preset allocations specified in bits 21:20:
  1240. * 0 - half lb
  1241. * 2 - whole lb, other crtc must be disabled
  1242. */
  1243. /* this can get tricky if we have two large displays on a paired group
  1244. * of crtcs. Ideally for multiple large displays we'd assign them to
  1245. * non-linked crtcs for maximum line buffer allocation.
  1246. */
  1247. if (radeon_crtc->base.enabled && mode) {
  1248. if (other_mode)
  1249. tmp = 0; /* 1/2 */
  1250. else
  1251. tmp = 2; /* whole */
  1252. } else
  1253. tmp = 0;
  1254. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1255. DC_LB_MEMORY_CONFIG(tmp));
  1256. if (radeon_crtc->base.enabled && mode) {
  1257. switch (tmp) {
  1258. case 0:
  1259. default:
  1260. return 4096 * 2;
  1261. case 2:
  1262. return 8192 * 2;
  1263. }
  1264. }
  1265. /* controller not enabled, so no lb used */
  1266. return 0;
  1267. }
  1268. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1269. {
  1270. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1271. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1272. case 0:
  1273. default:
  1274. return 1;
  1275. case 1:
  1276. return 2;
  1277. case 2:
  1278. return 4;
  1279. case 3:
  1280. return 8;
  1281. case 4:
  1282. return 3;
  1283. case 5:
  1284. return 6;
  1285. case 6:
  1286. return 10;
  1287. case 7:
  1288. return 12;
  1289. case 8:
  1290. return 16;
  1291. }
  1292. }
  1293. struct dce6_wm_params {
  1294. u32 dram_channels; /* number of dram channels */
  1295. u32 yclk; /* bandwidth per dram data pin in kHz */
  1296. u32 sclk; /* engine clock in kHz */
  1297. u32 disp_clk; /* display clock in kHz */
  1298. u32 src_width; /* viewport width */
  1299. u32 active_time; /* active display time in ns */
  1300. u32 blank_time; /* blank time in ns */
  1301. bool interlaced; /* mode is interlaced */
  1302. fixed20_12 vsc; /* vertical scale ratio */
  1303. u32 num_heads; /* number of active crtcs */
  1304. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1305. u32 lb_size; /* line buffer allocated to pipe */
  1306. u32 vtaps; /* vertical scaler taps */
  1307. };
  1308. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1309. {
  1310. /* Calculate raw DRAM Bandwidth */
  1311. fixed20_12 dram_efficiency; /* 0.7 */
  1312. fixed20_12 yclk, dram_channels, bandwidth;
  1313. fixed20_12 a;
  1314. a.full = dfixed_const(1000);
  1315. yclk.full = dfixed_const(wm->yclk);
  1316. yclk.full = dfixed_div(yclk, a);
  1317. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1318. a.full = dfixed_const(10);
  1319. dram_efficiency.full = dfixed_const(7);
  1320. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1321. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1322. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1323. return dfixed_trunc(bandwidth);
  1324. }
  1325. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1326. {
  1327. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1328. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1329. fixed20_12 yclk, dram_channels, bandwidth;
  1330. fixed20_12 a;
  1331. a.full = dfixed_const(1000);
  1332. yclk.full = dfixed_const(wm->yclk);
  1333. yclk.full = dfixed_div(yclk, a);
  1334. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1335. a.full = dfixed_const(10);
  1336. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1337. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1338. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1339. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1340. return dfixed_trunc(bandwidth);
  1341. }
  1342. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1343. {
  1344. /* Calculate the display Data return Bandwidth */
  1345. fixed20_12 return_efficiency; /* 0.8 */
  1346. fixed20_12 sclk, bandwidth;
  1347. fixed20_12 a;
  1348. a.full = dfixed_const(1000);
  1349. sclk.full = dfixed_const(wm->sclk);
  1350. sclk.full = dfixed_div(sclk, a);
  1351. a.full = dfixed_const(10);
  1352. return_efficiency.full = dfixed_const(8);
  1353. return_efficiency.full = dfixed_div(return_efficiency, a);
  1354. a.full = dfixed_const(32);
  1355. bandwidth.full = dfixed_mul(a, sclk);
  1356. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1357. return dfixed_trunc(bandwidth);
  1358. }
  1359. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1360. {
  1361. return 32;
  1362. }
  1363. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1364. {
  1365. /* Calculate the DMIF Request Bandwidth */
  1366. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1367. fixed20_12 disp_clk, sclk, bandwidth;
  1368. fixed20_12 a, b1, b2;
  1369. u32 min_bandwidth;
  1370. a.full = dfixed_const(1000);
  1371. disp_clk.full = dfixed_const(wm->disp_clk);
  1372. disp_clk.full = dfixed_div(disp_clk, a);
  1373. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1374. b1.full = dfixed_mul(a, disp_clk);
  1375. a.full = dfixed_const(1000);
  1376. sclk.full = dfixed_const(wm->sclk);
  1377. sclk.full = dfixed_div(sclk, a);
  1378. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1379. b2.full = dfixed_mul(a, sclk);
  1380. a.full = dfixed_const(10);
  1381. disp_clk_request_efficiency.full = dfixed_const(8);
  1382. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1383. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1384. a.full = dfixed_const(min_bandwidth);
  1385. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1386. return dfixed_trunc(bandwidth);
  1387. }
  1388. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1389. {
  1390. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1391. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1392. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1393. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1394. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1395. }
  1396. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1397. {
  1398. /* Calculate the display mode Average Bandwidth
  1399. * DisplayMode should contain the source and destination dimensions,
  1400. * timing, etc.
  1401. */
  1402. fixed20_12 bpp;
  1403. fixed20_12 line_time;
  1404. fixed20_12 src_width;
  1405. fixed20_12 bandwidth;
  1406. fixed20_12 a;
  1407. a.full = dfixed_const(1000);
  1408. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1409. line_time.full = dfixed_div(line_time, a);
  1410. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1411. src_width.full = dfixed_const(wm->src_width);
  1412. bandwidth.full = dfixed_mul(src_width, bpp);
  1413. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1414. bandwidth.full = dfixed_div(bandwidth, line_time);
  1415. return dfixed_trunc(bandwidth);
  1416. }
  1417. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1418. {
  1419. /* First calcualte the latency in ns */
  1420. u32 mc_latency = 2000; /* 2000 ns. */
  1421. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1422. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1423. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1424. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1425. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1426. (wm->num_heads * cursor_line_pair_return_time);
  1427. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1428. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1429. u32 tmp, dmif_size = 12288;
  1430. fixed20_12 a, b, c;
  1431. if (wm->num_heads == 0)
  1432. return 0;
  1433. a.full = dfixed_const(2);
  1434. b.full = dfixed_const(1);
  1435. if ((wm->vsc.full > a.full) ||
  1436. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1437. (wm->vtaps >= 5) ||
  1438. ((wm->vsc.full >= a.full) && wm->interlaced))
  1439. max_src_lines_per_dst_line = 4;
  1440. else
  1441. max_src_lines_per_dst_line = 2;
  1442. a.full = dfixed_const(available_bandwidth);
  1443. b.full = dfixed_const(wm->num_heads);
  1444. a.full = dfixed_div(a, b);
  1445. b.full = dfixed_const(mc_latency + 512);
  1446. c.full = dfixed_const(wm->disp_clk);
  1447. b.full = dfixed_div(b, c);
  1448. c.full = dfixed_const(dmif_size);
  1449. b.full = dfixed_div(c, b);
  1450. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1451. b.full = dfixed_const(1000);
  1452. c.full = dfixed_const(wm->disp_clk);
  1453. b.full = dfixed_div(c, b);
  1454. c.full = dfixed_const(wm->bytes_per_pixel);
  1455. b.full = dfixed_mul(b, c);
  1456. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1457. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1458. b.full = dfixed_const(1000);
  1459. c.full = dfixed_const(lb_fill_bw);
  1460. b.full = dfixed_div(c, b);
  1461. a.full = dfixed_div(a, b);
  1462. line_fill_time = dfixed_trunc(a);
  1463. if (line_fill_time < wm->active_time)
  1464. return latency;
  1465. else
  1466. return latency + (line_fill_time - wm->active_time);
  1467. }
  1468. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1469. {
  1470. if (dce6_average_bandwidth(wm) <=
  1471. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1472. return true;
  1473. else
  1474. return false;
  1475. };
  1476. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1477. {
  1478. if (dce6_average_bandwidth(wm) <=
  1479. (dce6_available_bandwidth(wm) / wm->num_heads))
  1480. return true;
  1481. else
  1482. return false;
  1483. };
  1484. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1485. {
  1486. u32 lb_partitions = wm->lb_size / wm->src_width;
  1487. u32 line_time = wm->active_time + wm->blank_time;
  1488. u32 latency_tolerant_lines;
  1489. u32 latency_hiding;
  1490. fixed20_12 a;
  1491. a.full = dfixed_const(1);
  1492. if (wm->vsc.full > a.full)
  1493. latency_tolerant_lines = 1;
  1494. else {
  1495. if (lb_partitions <= (wm->vtaps + 1))
  1496. latency_tolerant_lines = 1;
  1497. else
  1498. latency_tolerant_lines = 2;
  1499. }
  1500. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1501. if (dce6_latency_watermark(wm) <= latency_hiding)
  1502. return true;
  1503. else
  1504. return false;
  1505. }
  1506. static void dce6_program_watermarks(struct radeon_device *rdev,
  1507. struct radeon_crtc *radeon_crtc,
  1508. u32 lb_size, u32 num_heads)
  1509. {
  1510. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1511. struct dce6_wm_params wm;
  1512. u32 pixel_period;
  1513. u32 line_time = 0;
  1514. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1515. u32 priority_a_mark = 0, priority_b_mark = 0;
  1516. u32 priority_a_cnt = PRIORITY_OFF;
  1517. u32 priority_b_cnt = PRIORITY_OFF;
  1518. u32 tmp, arb_control3;
  1519. fixed20_12 a, b, c;
  1520. if (radeon_crtc->base.enabled && num_heads && mode) {
  1521. pixel_period = 1000000 / (u32)mode->clock;
  1522. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1523. priority_a_cnt = 0;
  1524. priority_b_cnt = 0;
  1525. wm.yclk = rdev->pm.current_mclk * 10;
  1526. wm.sclk = rdev->pm.current_sclk * 10;
  1527. wm.disp_clk = mode->clock;
  1528. wm.src_width = mode->crtc_hdisplay;
  1529. wm.active_time = mode->crtc_hdisplay * pixel_period;
  1530. wm.blank_time = line_time - wm.active_time;
  1531. wm.interlaced = false;
  1532. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1533. wm.interlaced = true;
  1534. wm.vsc = radeon_crtc->vsc;
  1535. wm.vtaps = 1;
  1536. if (radeon_crtc->rmx_type != RMX_OFF)
  1537. wm.vtaps = 2;
  1538. wm.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1539. wm.lb_size = lb_size;
  1540. if (rdev->family == CHIP_ARUBA)
  1541. wm.dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1542. else
  1543. wm.dram_channels = si_get_number_of_dram_channels(rdev);
  1544. wm.num_heads = num_heads;
  1545. /* set for high clocks */
  1546. latency_watermark_a = min(dce6_latency_watermark(&wm), (u32)65535);
  1547. /* set for low clocks */
  1548. /* wm.yclk = low clk; wm.sclk = low clk */
  1549. latency_watermark_b = min(dce6_latency_watermark(&wm), (u32)65535);
  1550. /* possibly force display priority to high */
  1551. /* should really do this at mode validation time... */
  1552. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
  1553. !dce6_average_bandwidth_vs_available_bandwidth(&wm) ||
  1554. !dce6_check_latency_hiding(&wm) ||
  1555. (rdev->disp_priority == 2)) {
  1556. DRM_DEBUG_KMS("force priority to high\n");
  1557. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  1558. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  1559. }
  1560. a.full = dfixed_const(1000);
  1561. b.full = dfixed_const(mode->clock);
  1562. b.full = dfixed_div(b, a);
  1563. c.full = dfixed_const(latency_watermark_a);
  1564. c.full = dfixed_mul(c, b);
  1565. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1566. c.full = dfixed_div(c, a);
  1567. a.full = dfixed_const(16);
  1568. c.full = dfixed_div(c, a);
  1569. priority_a_mark = dfixed_trunc(c);
  1570. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  1571. a.full = dfixed_const(1000);
  1572. b.full = dfixed_const(mode->clock);
  1573. b.full = dfixed_div(b, a);
  1574. c.full = dfixed_const(latency_watermark_b);
  1575. c.full = dfixed_mul(c, b);
  1576. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1577. c.full = dfixed_div(c, a);
  1578. a.full = dfixed_const(16);
  1579. c.full = dfixed_div(c, a);
  1580. priority_b_mark = dfixed_trunc(c);
  1581. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  1582. }
  1583. /* select wm A */
  1584. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1585. tmp = arb_control3;
  1586. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1587. tmp |= LATENCY_WATERMARK_MASK(1);
  1588. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1589. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1590. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  1591. LATENCY_HIGH_WATERMARK(line_time)));
  1592. /* select wm B */
  1593. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1594. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1595. tmp |= LATENCY_WATERMARK_MASK(2);
  1596. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1597. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1598. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  1599. LATENCY_HIGH_WATERMARK(line_time)));
  1600. /* restore original selection */
  1601. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  1602. /* write the priority marks */
  1603. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  1604. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  1605. }
  1606. void dce6_bandwidth_update(struct radeon_device *rdev)
  1607. {
  1608. struct drm_display_mode *mode0 = NULL;
  1609. struct drm_display_mode *mode1 = NULL;
  1610. u32 num_heads = 0, lb_size;
  1611. int i;
  1612. radeon_update_display_priority(rdev);
  1613. for (i = 0; i < rdev->num_crtc; i++) {
  1614. if (rdev->mode_info.crtcs[i]->base.enabled)
  1615. num_heads++;
  1616. }
  1617. for (i = 0; i < rdev->num_crtc; i += 2) {
  1618. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  1619. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  1620. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  1621. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  1622. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  1623. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  1624. }
  1625. }
  1626. /*
  1627. * Core functions
  1628. */
  1629. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  1630. {
  1631. const u32 num_tile_mode_states = 32;
  1632. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  1633. switch (rdev->config.si.mem_row_size_in_kb) {
  1634. case 1:
  1635. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  1636. break;
  1637. case 2:
  1638. default:
  1639. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  1640. break;
  1641. case 4:
  1642. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  1643. break;
  1644. }
  1645. if ((rdev->family == CHIP_TAHITI) ||
  1646. (rdev->family == CHIP_PITCAIRN)) {
  1647. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1648. switch (reg_offset) {
  1649. case 0: /* non-AA compressed depth or any compressed stencil */
  1650. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1651. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1652. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1653. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1654. NUM_BANKS(ADDR_SURF_16_BANK) |
  1655. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1656. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1657. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1658. break;
  1659. case 1: /* 2xAA/4xAA compressed depth only */
  1660. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1661. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1662. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1663. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1664. NUM_BANKS(ADDR_SURF_16_BANK) |
  1665. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1666. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1667. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1668. break;
  1669. case 2: /* 8xAA compressed depth only */
  1670. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1671. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1672. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1673. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1674. NUM_BANKS(ADDR_SURF_16_BANK) |
  1675. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1676. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1677. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1678. break;
  1679. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  1680. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1681. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1682. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1683. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1684. NUM_BANKS(ADDR_SURF_16_BANK) |
  1685. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1686. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1687. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1688. break;
  1689. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  1690. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1691. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1692. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1693. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1694. NUM_BANKS(ADDR_SURF_16_BANK) |
  1695. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1696. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1697. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1698. break;
  1699. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  1700. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1701. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1702. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1703. TILE_SPLIT(split_equal_to_row_size) |
  1704. NUM_BANKS(ADDR_SURF_16_BANK) |
  1705. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1706. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1707. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1708. break;
  1709. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  1710. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1711. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1712. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1713. TILE_SPLIT(split_equal_to_row_size) |
  1714. NUM_BANKS(ADDR_SURF_16_BANK) |
  1715. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1716. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1717. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1718. break;
  1719. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  1720. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1721. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1722. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1723. TILE_SPLIT(split_equal_to_row_size) |
  1724. NUM_BANKS(ADDR_SURF_16_BANK) |
  1725. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1726. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1727. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1728. break;
  1729. case 8: /* 1D and 1D Array Surfaces */
  1730. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1731. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1732. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1733. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1734. NUM_BANKS(ADDR_SURF_16_BANK) |
  1735. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1736. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1737. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1738. break;
  1739. case 9: /* Displayable maps. */
  1740. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1741. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1742. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1743. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1744. NUM_BANKS(ADDR_SURF_16_BANK) |
  1745. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1746. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1747. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1748. break;
  1749. case 10: /* Display 8bpp. */
  1750. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1751. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1752. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1753. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1754. NUM_BANKS(ADDR_SURF_16_BANK) |
  1755. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1756. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1757. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1758. break;
  1759. case 11: /* Display 16bpp. */
  1760. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1761. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1762. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1763. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1764. NUM_BANKS(ADDR_SURF_16_BANK) |
  1765. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1766. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1767. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1768. break;
  1769. case 12: /* Display 32bpp. */
  1770. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1771. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1772. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1773. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1774. NUM_BANKS(ADDR_SURF_16_BANK) |
  1775. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1776. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1777. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1778. break;
  1779. case 13: /* Thin. */
  1780. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1781. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1782. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1783. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1784. NUM_BANKS(ADDR_SURF_16_BANK) |
  1785. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1786. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1787. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1788. break;
  1789. case 14: /* Thin 8 bpp. */
  1790. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1791. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1792. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1793. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1794. NUM_BANKS(ADDR_SURF_16_BANK) |
  1795. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1796. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1797. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1798. break;
  1799. case 15: /* Thin 16 bpp. */
  1800. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1801. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1802. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1803. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1804. NUM_BANKS(ADDR_SURF_16_BANK) |
  1805. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1806. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1807. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1808. break;
  1809. case 16: /* Thin 32 bpp. */
  1810. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1811. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1812. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1813. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1814. NUM_BANKS(ADDR_SURF_16_BANK) |
  1815. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1816. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1817. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1818. break;
  1819. case 17: /* Thin 64 bpp. */
  1820. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1821. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1822. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1823. TILE_SPLIT(split_equal_to_row_size) |
  1824. NUM_BANKS(ADDR_SURF_16_BANK) |
  1825. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1826. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1827. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1828. break;
  1829. case 21: /* 8 bpp PRT. */
  1830. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1831. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1832. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1833. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1834. NUM_BANKS(ADDR_SURF_16_BANK) |
  1835. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1836. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1837. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1838. break;
  1839. case 22: /* 16 bpp PRT */
  1840. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1841. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1842. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1843. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1844. NUM_BANKS(ADDR_SURF_16_BANK) |
  1845. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1846. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1847. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1848. break;
  1849. case 23: /* 32 bpp PRT */
  1850. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1851. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1852. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1853. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1854. NUM_BANKS(ADDR_SURF_16_BANK) |
  1855. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1856. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1857. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1858. break;
  1859. case 24: /* 64 bpp PRT */
  1860. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1861. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1862. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1863. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1864. NUM_BANKS(ADDR_SURF_16_BANK) |
  1865. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1866. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1867. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1868. break;
  1869. case 25: /* 128 bpp PRT */
  1870. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1871. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1872. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1873. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  1874. NUM_BANKS(ADDR_SURF_8_BANK) |
  1875. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1876. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1877. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1878. break;
  1879. default:
  1880. gb_tile_moden = 0;
  1881. break;
  1882. }
  1883. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  1884. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  1885. }
  1886. } else if ((rdev->family == CHIP_VERDE) ||
  1887. (rdev->family == CHIP_OLAND)) {
  1888. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1889. switch (reg_offset) {
  1890. case 0: /* non-AA compressed depth or any compressed stencil */
  1891. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1892. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1893. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1894. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1895. NUM_BANKS(ADDR_SURF_16_BANK) |
  1896. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1897. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1898. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1899. break;
  1900. case 1: /* 2xAA/4xAA compressed depth only */
  1901. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1902. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1903. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1904. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1905. NUM_BANKS(ADDR_SURF_16_BANK) |
  1906. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1907. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1908. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1909. break;
  1910. case 2: /* 8xAA compressed depth only */
  1911. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1912. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1913. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1914. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1915. NUM_BANKS(ADDR_SURF_16_BANK) |
  1916. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1917. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1918. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1919. break;
  1920. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  1921. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1922. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1923. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1924. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1925. NUM_BANKS(ADDR_SURF_16_BANK) |
  1926. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1927. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1928. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1929. break;
  1930. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  1931. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1932. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1933. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1934. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1935. NUM_BANKS(ADDR_SURF_16_BANK) |
  1936. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1937. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1938. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1939. break;
  1940. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  1941. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1942. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1943. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1944. TILE_SPLIT(split_equal_to_row_size) |
  1945. NUM_BANKS(ADDR_SURF_16_BANK) |
  1946. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1947. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1948. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1949. break;
  1950. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  1951. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1952. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1953. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1954. TILE_SPLIT(split_equal_to_row_size) |
  1955. NUM_BANKS(ADDR_SURF_16_BANK) |
  1956. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1957. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1958. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1959. break;
  1960. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  1961. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1962. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1963. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1964. TILE_SPLIT(split_equal_to_row_size) |
  1965. NUM_BANKS(ADDR_SURF_16_BANK) |
  1966. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1967. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1968. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1969. break;
  1970. case 8: /* 1D and 1D Array Surfaces */
  1971. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1972. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1973. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1974. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1975. NUM_BANKS(ADDR_SURF_16_BANK) |
  1976. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1977. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1978. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1979. break;
  1980. case 9: /* Displayable maps. */
  1981. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1982. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1983. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1984. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1985. NUM_BANKS(ADDR_SURF_16_BANK) |
  1986. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1987. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1988. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1989. break;
  1990. case 10: /* Display 8bpp. */
  1991. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1992. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1993. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1994. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1995. NUM_BANKS(ADDR_SURF_16_BANK) |
  1996. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1997. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1998. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1999. break;
  2000. case 11: /* Display 16bpp. */
  2001. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2002. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2003. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2004. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2005. NUM_BANKS(ADDR_SURF_16_BANK) |
  2006. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2007. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2008. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2009. break;
  2010. case 12: /* Display 32bpp. */
  2011. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2012. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2013. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2014. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2015. NUM_BANKS(ADDR_SURF_16_BANK) |
  2016. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2017. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2018. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2019. break;
  2020. case 13: /* Thin. */
  2021. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2022. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2023. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2024. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2025. NUM_BANKS(ADDR_SURF_16_BANK) |
  2026. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2027. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2028. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2029. break;
  2030. case 14: /* Thin 8 bpp. */
  2031. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2032. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2033. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2034. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2035. NUM_BANKS(ADDR_SURF_16_BANK) |
  2036. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2037. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2038. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2039. break;
  2040. case 15: /* Thin 16 bpp. */
  2041. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2042. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2043. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2044. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2045. NUM_BANKS(ADDR_SURF_16_BANK) |
  2046. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2047. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2048. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2049. break;
  2050. case 16: /* Thin 32 bpp. */
  2051. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2052. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2053. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2054. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2055. NUM_BANKS(ADDR_SURF_16_BANK) |
  2056. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2057. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2058. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2059. break;
  2060. case 17: /* Thin 64 bpp. */
  2061. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2062. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2063. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2064. TILE_SPLIT(split_equal_to_row_size) |
  2065. NUM_BANKS(ADDR_SURF_16_BANK) |
  2066. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2067. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2068. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2069. break;
  2070. case 21: /* 8 bpp PRT. */
  2071. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2072. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2073. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2074. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2075. NUM_BANKS(ADDR_SURF_16_BANK) |
  2076. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2077. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2078. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2079. break;
  2080. case 22: /* 16 bpp PRT */
  2081. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2082. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2083. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2084. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2085. NUM_BANKS(ADDR_SURF_16_BANK) |
  2086. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2087. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2088. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2089. break;
  2090. case 23: /* 32 bpp PRT */
  2091. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2092. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2093. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2094. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2095. NUM_BANKS(ADDR_SURF_16_BANK) |
  2096. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2097. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2098. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2099. break;
  2100. case 24: /* 64 bpp PRT */
  2101. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2102. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2103. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2104. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2105. NUM_BANKS(ADDR_SURF_16_BANK) |
  2106. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2107. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2108. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2109. break;
  2110. case 25: /* 128 bpp PRT */
  2111. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2112. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2113. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2114. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2115. NUM_BANKS(ADDR_SURF_8_BANK) |
  2116. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2117. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2118. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2119. break;
  2120. default:
  2121. gb_tile_moden = 0;
  2122. break;
  2123. }
  2124. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2125. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2126. }
  2127. } else
  2128. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2129. }
  2130. static void si_select_se_sh(struct radeon_device *rdev,
  2131. u32 se_num, u32 sh_num)
  2132. {
  2133. u32 data = INSTANCE_BROADCAST_WRITES;
  2134. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2135. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2136. else if (se_num == 0xffffffff)
  2137. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2138. else if (sh_num == 0xffffffff)
  2139. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2140. else
  2141. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2142. WREG32(GRBM_GFX_INDEX, data);
  2143. }
  2144. static u32 si_create_bitmask(u32 bit_width)
  2145. {
  2146. u32 i, mask = 0;
  2147. for (i = 0; i < bit_width; i++) {
  2148. mask <<= 1;
  2149. mask |= 1;
  2150. }
  2151. return mask;
  2152. }
  2153. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2154. {
  2155. u32 data, mask;
  2156. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2157. if (data & 1)
  2158. data &= INACTIVE_CUS_MASK;
  2159. else
  2160. data = 0;
  2161. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2162. data >>= INACTIVE_CUS_SHIFT;
  2163. mask = si_create_bitmask(cu_per_sh);
  2164. return ~data & mask;
  2165. }
  2166. static void si_setup_spi(struct radeon_device *rdev,
  2167. u32 se_num, u32 sh_per_se,
  2168. u32 cu_per_sh)
  2169. {
  2170. int i, j, k;
  2171. u32 data, mask, active_cu;
  2172. for (i = 0; i < se_num; i++) {
  2173. for (j = 0; j < sh_per_se; j++) {
  2174. si_select_se_sh(rdev, i, j);
  2175. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2176. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2177. mask = 1;
  2178. for (k = 0; k < 16; k++) {
  2179. mask <<= k;
  2180. if (active_cu & mask) {
  2181. data &= ~mask;
  2182. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2183. break;
  2184. }
  2185. }
  2186. }
  2187. }
  2188. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2189. }
  2190. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2191. u32 max_rb_num, u32 se_num,
  2192. u32 sh_per_se)
  2193. {
  2194. u32 data, mask;
  2195. data = RREG32(CC_RB_BACKEND_DISABLE);
  2196. if (data & 1)
  2197. data &= BACKEND_DISABLE_MASK;
  2198. else
  2199. data = 0;
  2200. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2201. data >>= BACKEND_DISABLE_SHIFT;
  2202. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2203. return data & mask;
  2204. }
  2205. static void si_setup_rb(struct radeon_device *rdev,
  2206. u32 se_num, u32 sh_per_se,
  2207. u32 max_rb_num)
  2208. {
  2209. int i, j;
  2210. u32 data, mask;
  2211. u32 disabled_rbs = 0;
  2212. u32 enabled_rbs = 0;
  2213. for (i = 0; i < se_num; i++) {
  2214. for (j = 0; j < sh_per_se; j++) {
  2215. si_select_se_sh(rdev, i, j);
  2216. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2217. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2218. }
  2219. }
  2220. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2221. mask = 1;
  2222. for (i = 0; i < max_rb_num; i++) {
  2223. if (!(disabled_rbs & mask))
  2224. enabled_rbs |= mask;
  2225. mask <<= 1;
  2226. }
  2227. for (i = 0; i < se_num; i++) {
  2228. si_select_se_sh(rdev, i, 0xffffffff);
  2229. data = 0;
  2230. for (j = 0; j < sh_per_se; j++) {
  2231. switch (enabled_rbs & 3) {
  2232. case 1:
  2233. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2234. break;
  2235. case 2:
  2236. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2237. break;
  2238. case 3:
  2239. default:
  2240. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2241. break;
  2242. }
  2243. enabled_rbs >>= 2;
  2244. }
  2245. WREG32(PA_SC_RASTER_CONFIG, data);
  2246. }
  2247. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2248. }
  2249. static void si_gpu_init(struct radeon_device *rdev)
  2250. {
  2251. u32 gb_addr_config = 0;
  2252. u32 mc_shared_chmap, mc_arb_ramcfg;
  2253. u32 sx_debug_1;
  2254. u32 hdp_host_path_cntl;
  2255. u32 tmp;
  2256. int i, j;
  2257. switch (rdev->family) {
  2258. case CHIP_TAHITI:
  2259. rdev->config.si.max_shader_engines = 2;
  2260. rdev->config.si.max_tile_pipes = 12;
  2261. rdev->config.si.max_cu_per_sh = 8;
  2262. rdev->config.si.max_sh_per_se = 2;
  2263. rdev->config.si.max_backends_per_se = 4;
  2264. rdev->config.si.max_texture_channel_caches = 12;
  2265. rdev->config.si.max_gprs = 256;
  2266. rdev->config.si.max_gs_threads = 32;
  2267. rdev->config.si.max_hw_contexts = 8;
  2268. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2269. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2270. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2271. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2272. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2273. break;
  2274. case CHIP_PITCAIRN:
  2275. rdev->config.si.max_shader_engines = 2;
  2276. rdev->config.si.max_tile_pipes = 8;
  2277. rdev->config.si.max_cu_per_sh = 5;
  2278. rdev->config.si.max_sh_per_se = 2;
  2279. rdev->config.si.max_backends_per_se = 4;
  2280. rdev->config.si.max_texture_channel_caches = 8;
  2281. rdev->config.si.max_gprs = 256;
  2282. rdev->config.si.max_gs_threads = 32;
  2283. rdev->config.si.max_hw_contexts = 8;
  2284. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2285. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2286. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2287. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2288. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2289. break;
  2290. case CHIP_VERDE:
  2291. default:
  2292. rdev->config.si.max_shader_engines = 1;
  2293. rdev->config.si.max_tile_pipes = 4;
  2294. rdev->config.si.max_cu_per_sh = 2;
  2295. rdev->config.si.max_sh_per_se = 2;
  2296. rdev->config.si.max_backends_per_se = 4;
  2297. rdev->config.si.max_texture_channel_caches = 4;
  2298. rdev->config.si.max_gprs = 256;
  2299. rdev->config.si.max_gs_threads = 32;
  2300. rdev->config.si.max_hw_contexts = 8;
  2301. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2302. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2303. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2304. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2305. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2306. break;
  2307. case CHIP_OLAND:
  2308. rdev->config.si.max_shader_engines = 1;
  2309. rdev->config.si.max_tile_pipes = 4;
  2310. rdev->config.si.max_cu_per_sh = 6;
  2311. rdev->config.si.max_sh_per_se = 1;
  2312. rdev->config.si.max_backends_per_se = 2;
  2313. rdev->config.si.max_texture_channel_caches = 4;
  2314. rdev->config.si.max_gprs = 256;
  2315. rdev->config.si.max_gs_threads = 16;
  2316. rdev->config.si.max_hw_contexts = 8;
  2317. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2318. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2319. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2320. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2321. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2322. break;
  2323. }
  2324. /* Initialize HDP */
  2325. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2326. WREG32((0x2c14 + j), 0x00000000);
  2327. WREG32((0x2c18 + j), 0x00000000);
  2328. WREG32((0x2c1c + j), 0x00000000);
  2329. WREG32((0x2c20 + j), 0x00000000);
  2330. WREG32((0x2c24 + j), 0x00000000);
  2331. }
  2332. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2333. evergreen_fix_pci_max_read_req_size(rdev);
  2334. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2335. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2336. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2337. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2338. rdev->config.si.mem_max_burst_length_bytes = 256;
  2339. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2340. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2341. if (rdev->config.si.mem_row_size_in_kb > 4)
  2342. rdev->config.si.mem_row_size_in_kb = 4;
  2343. /* XXX use MC settings? */
  2344. rdev->config.si.shader_engine_tile_size = 32;
  2345. rdev->config.si.num_gpus = 1;
  2346. rdev->config.si.multi_gpu_tile_size = 64;
  2347. /* fix up row size */
  2348. gb_addr_config &= ~ROW_SIZE_MASK;
  2349. switch (rdev->config.si.mem_row_size_in_kb) {
  2350. case 1:
  2351. default:
  2352. gb_addr_config |= ROW_SIZE(0);
  2353. break;
  2354. case 2:
  2355. gb_addr_config |= ROW_SIZE(1);
  2356. break;
  2357. case 4:
  2358. gb_addr_config |= ROW_SIZE(2);
  2359. break;
  2360. }
  2361. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2362. * not have bank info, so create a custom tiling dword.
  2363. * bits 3:0 num_pipes
  2364. * bits 7:4 num_banks
  2365. * bits 11:8 group_size
  2366. * bits 15:12 row_size
  2367. */
  2368. rdev->config.si.tile_config = 0;
  2369. switch (rdev->config.si.num_tile_pipes) {
  2370. case 1:
  2371. rdev->config.si.tile_config |= (0 << 0);
  2372. break;
  2373. case 2:
  2374. rdev->config.si.tile_config |= (1 << 0);
  2375. break;
  2376. case 4:
  2377. rdev->config.si.tile_config |= (2 << 0);
  2378. break;
  2379. case 8:
  2380. default:
  2381. /* XXX what about 12? */
  2382. rdev->config.si.tile_config |= (3 << 0);
  2383. break;
  2384. }
  2385. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2386. case 0: /* four banks */
  2387. rdev->config.si.tile_config |= 0 << 4;
  2388. break;
  2389. case 1: /* eight banks */
  2390. rdev->config.si.tile_config |= 1 << 4;
  2391. break;
  2392. case 2: /* sixteen banks */
  2393. default:
  2394. rdev->config.si.tile_config |= 2 << 4;
  2395. break;
  2396. }
  2397. rdev->config.si.tile_config |=
  2398. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2399. rdev->config.si.tile_config |=
  2400. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2401. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2402. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2403. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2404. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2405. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2406. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2407. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2408. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2409. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2410. si_tiling_mode_table_init(rdev);
  2411. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2412. rdev->config.si.max_sh_per_se,
  2413. rdev->config.si.max_backends_per_se);
  2414. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2415. rdev->config.si.max_sh_per_se,
  2416. rdev->config.si.max_cu_per_sh);
  2417. /* set HW defaults for 3D engine */
  2418. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2419. ROQ_IB2_START(0x2b)));
  2420. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2421. sx_debug_1 = RREG32(SX_DEBUG_1);
  2422. WREG32(SX_DEBUG_1, sx_debug_1);
  2423. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2424. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2425. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2426. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2427. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2428. WREG32(VGT_NUM_INSTANCES, 1);
  2429. WREG32(CP_PERFMON_CNTL, 0);
  2430. WREG32(SQ_CONFIG, 0);
  2431. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2432. FORCE_EOV_MAX_REZ_CNT(255)));
  2433. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2434. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2435. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2436. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2437. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2438. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2439. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2440. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2441. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2442. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2443. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2444. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2445. tmp = RREG32(HDP_MISC_CNTL);
  2446. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2447. WREG32(HDP_MISC_CNTL, tmp);
  2448. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2449. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2450. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2451. udelay(50);
  2452. }
  2453. /*
  2454. * GPU scratch registers helpers function.
  2455. */
  2456. static void si_scratch_init(struct radeon_device *rdev)
  2457. {
  2458. int i;
  2459. rdev->scratch.num_reg = 7;
  2460. rdev->scratch.reg_base = SCRATCH_REG0;
  2461. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2462. rdev->scratch.free[i] = true;
  2463. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2464. }
  2465. }
  2466. void si_fence_ring_emit(struct radeon_device *rdev,
  2467. struct radeon_fence *fence)
  2468. {
  2469. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2470. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2471. /* flush read cache over gart */
  2472. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2473. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2474. radeon_ring_write(ring, 0);
  2475. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2476. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2477. PACKET3_TC_ACTION_ENA |
  2478. PACKET3_SH_KCACHE_ACTION_ENA |
  2479. PACKET3_SH_ICACHE_ACTION_ENA);
  2480. radeon_ring_write(ring, 0xFFFFFFFF);
  2481. radeon_ring_write(ring, 0);
  2482. radeon_ring_write(ring, 10); /* poll interval */
  2483. /* EVENT_WRITE_EOP - flush caches, send int */
  2484. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2485. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2486. radeon_ring_write(ring, addr & 0xffffffff);
  2487. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2488. radeon_ring_write(ring, fence->seq);
  2489. radeon_ring_write(ring, 0);
  2490. }
  2491. /*
  2492. * IB stuff
  2493. */
  2494. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2495. {
  2496. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2497. u32 header;
  2498. if (ib->is_const_ib) {
  2499. /* set switch buffer packet before const IB */
  2500. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2501. radeon_ring_write(ring, 0);
  2502. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  2503. } else {
  2504. u32 next_rptr;
  2505. if (ring->rptr_save_reg) {
  2506. next_rptr = ring->wptr + 3 + 4 + 8;
  2507. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2508. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2509. PACKET3_SET_CONFIG_REG_START) >> 2));
  2510. radeon_ring_write(ring, next_rptr);
  2511. } else if (rdev->wb.enabled) {
  2512. next_rptr = ring->wptr + 5 + 4 + 8;
  2513. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2514. radeon_ring_write(ring, (1 << 8));
  2515. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2516. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  2517. radeon_ring_write(ring, next_rptr);
  2518. }
  2519. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  2520. }
  2521. radeon_ring_write(ring, header);
  2522. radeon_ring_write(ring,
  2523. #ifdef __BIG_ENDIAN
  2524. (2 << 0) |
  2525. #endif
  2526. (ib->gpu_addr & 0xFFFFFFFC));
  2527. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2528. radeon_ring_write(ring, ib->length_dw |
  2529. (ib->vm ? (ib->vm->id << 24) : 0));
  2530. if (!ib->is_const_ib) {
  2531. /* flush read cache over gart for this vmid */
  2532. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2533. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2534. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  2535. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2536. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2537. PACKET3_TC_ACTION_ENA |
  2538. PACKET3_SH_KCACHE_ACTION_ENA |
  2539. PACKET3_SH_ICACHE_ACTION_ENA);
  2540. radeon_ring_write(ring, 0xFFFFFFFF);
  2541. radeon_ring_write(ring, 0);
  2542. radeon_ring_write(ring, 10); /* poll interval */
  2543. }
  2544. }
  2545. /*
  2546. * CP.
  2547. */
  2548. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  2549. {
  2550. if (enable)
  2551. WREG32(CP_ME_CNTL, 0);
  2552. else {
  2553. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  2554. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  2555. WREG32(SCRATCH_UMSK, 0);
  2556. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2557. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2558. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2559. }
  2560. udelay(50);
  2561. }
  2562. static int si_cp_load_microcode(struct radeon_device *rdev)
  2563. {
  2564. const __be32 *fw_data;
  2565. int i;
  2566. if (!rdev->me_fw || !rdev->pfp_fw)
  2567. return -EINVAL;
  2568. si_cp_enable(rdev, false);
  2569. /* PFP */
  2570. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2571. WREG32(CP_PFP_UCODE_ADDR, 0);
  2572. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  2573. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2574. WREG32(CP_PFP_UCODE_ADDR, 0);
  2575. /* CE */
  2576. fw_data = (const __be32 *)rdev->ce_fw->data;
  2577. WREG32(CP_CE_UCODE_ADDR, 0);
  2578. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  2579. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  2580. WREG32(CP_CE_UCODE_ADDR, 0);
  2581. /* ME */
  2582. fw_data = (const __be32 *)rdev->me_fw->data;
  2583. WREG32(CP_ME_RAM_WADDR, 0);
  2584. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  2585. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2586. WREG32(CP_ME_RAM_WADDR, 0);
  2587. WREG32(CP_PFP_UCODE_ADDR, 0);
  2588. WREG32(CP_CE_UCODE_ADDR, 0);
  2589. WREG32(CP_ME_RAM_WADDR, 0);
  2590. WREG32(CP_ME_RAM_RADDR, 0);
  2591. return 0;
  2592. }
  2593. static int si_cp_start(struct radeon_device *rdev)
  2594. {
  2595. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2596. int r, i;
  2597. r = radeon_ring_lock(rdev, ring, 7 + 4);
  2598. if (r) {
  2599. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2600. return r;
  2601. }
  2602. /* init the CP */
  2603. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2604. radeon_ring_write(ring, 0x1);
  2605. radeon_ring_write(ring, 0x0);
  2606. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  2607. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2608. radeon_ring_write(ring, 0);
  2609. radeon_ring_write(ring, 0);
  2610. /* init the CE partitions */
  2611. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  2612. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  2613. radeon_ring_write(ring, 0xc000);
  2614. radeon_ring_write(ring, 0xe000);
  2615. radeon_ring_unlock_commit(rdev, ring);
  2616. si_cp_enable(rdev, true);
  2617. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  2618. if (r) {
  2619. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2620. return r;
  2621. }
  2622. /* setup clear context state */
  2623. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2624. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2625. for (i = 0; i < si_default_size; i++)
  2626. radeon_ring_write(ring, si_default_state[i]);
  2627. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2628. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2629. /* set clear context state */
  2630. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2631. radeon_ring_write(ring, 0);
  2632. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  2633. radeon_ring_write(ring, 0x00000316);
  2634. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2635. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  2636. radeon_ring_unlock_commit(rdev, ring);
  2637. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  2638. ring = &rdev->ring[i];
  2639. r = radeon_ring_lock(rdev, ring, 2);
  2640. /* clear the compute context state */
  2641. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  2642. radeon_ring_write(ring, 0);
  2643. radeon_ring_unlock_commit(rdev, ring);
  2644. }
  2645. return 0;
  2646. }
  2647. static void si_cp_fini(struct radeon_device *rdev)
  2648. {
  2649. struct radeon_ring *ring;
  2650. si_cp_enable(rdev, false);
  2651. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2652. radeon_ring_fini(rdev, ring);
  2653. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2654. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2655. radeon_ring_fini(rdev, ring);
  2656. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2657. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2658. radeon_ring_fini(rdev, ring);
  2659. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2660. }
  2661. static int si_cp_resume(struct radeon_device *rdev)
  2662. {
  2663. struct radeon_ring *ring;
  2664. u32 tmp;
  2665. u32 rb_bufsz;
  2666. int r;
  2667. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2668. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2669. SOFT_RESET_PA |
  2670. SOFT_RESET_VGT |
  2671. SOFT_RESET_SPI |
  2672. SOFT_RESET_SX));
  2673. RREG32(GRBM_SOFT_RESET);
  2674. mdelay(15);
  2675. WREG32(GRBM_SOFT_RESET, 0);
  2676. RREG32(GRBM_SOFT_RESET);
  2677. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2678. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2679. /* Set the write pointer delay */
  2680. WREG32(CP_RB_WPTR_DELAY, 0);
  2681. WREG32(CP_DEBUG, 0);
  2682. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2683. /* ring 0 - compute and gfx */
  2684. /* Set ring buffer size */
  2685. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2686. rb_bufsz = drm_order(ring->ring_size / 8);
  2687. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2688. #ifdef __BIG_ENDIAN
  2689. tmp |= BUF_SWAP_32BIT;
  2690. #endif
  2691. WREG32(CP_RB0_CNTL, tmp);
  2692. /* Initialize the ring buffer's read and write pointers */
  2693. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  2694. ring->wptr = 0;
  2695. WREG32(CP_RB0_WPTR, ring->wptr);
  2696. /* set the wb address whether it's enabled or not */
  2697. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  2698. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2699. if (rdev->wb.enabled)
  2700. WREG32(SCRATCH_UMSK, 0xff);
  2701. else {
  2702. tmp |= RB_NO_UPDATE;
  2703. WREG32(SCRATCH_UMSK, 0);
  2704. }
  2705. mdelay(1);
  2706. WREG32(CP_RB0_CNTL, tmp);
  2707. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  2708. ring->rptr = RREG32(CP_RB0_RPTR);
  2709. /* ring1 - compute only */
  2710. /* Set ring buffer size */
  2711. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2712. rb_bufsz = drm_order(ring->ring_size / 8);
  2713. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2714. #ifdef __BIG_ENDIAN
  2715. tmp |= BUF_SWAP_32BIT;
  2716. #endif
  2717. WREG32(CP_RB1_CNTL, tmp);
  2718. /* Initialize the ring buffer's read and write pointers */
  2719. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  2720. ring->wptr = 0;
  2721. WREG32(CP_RB1_WPTR, ring->wptr);
  2722. /* set the wb address whether it's enabled or not */
  2723. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  2724. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  2725. mdelay(1);
  2726. WREG32(CP_RB1_CNTL, tmp);
  2727. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  2728. ring->rptr = RREG32(CP_RB1_RPTR);
  2729. /* ring2 - compute only */
  2730. /* Set ring buffer size */
  2731. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2732. rb_bufsz = drm_order(ring->ring_size / 8);
  2733. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2734. #ifdef __BIG_ENDIAN
  2735. tmp |= BUF_SWAP_32BIT;
  2736. #endif
  2737. WREG32(CP_RB2_CNTL, tmp);
  2738. /* Initialize the ring buffer's read and write pointers */
  2739. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  2740. ring->wptr = 0;
  2741. WREG32(CP_RB2_WPTR, ring->wptr);
  2742. /* set the wb address whether it's enabled or not */
  2743. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  2744. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  2745. mdelay(1);
  2746. WREG32(CP_RB2_CNTL, tmp);
  2747. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  2748. ring->rptr = RREG32(CP_RB2_RPTR);
  2749. /* start the rings */
  2750. si_cp_start(rdev);
  2751. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  2752. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  2753. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  2754. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2755. if (r) {
  2756. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2757. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2758. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2759. return r;
  2760. }
  2761. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  2762. if (r) {
  2763. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2764. }
  2765. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  2766. if (r) {
  2767. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2768. }
  2769. return 0;
  2770. }
  2771. static u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  2772. {
  2773. u32 reset_mask = 0;
  2774. u32 tmp;
  2775. /* GRBM_STATUS */
  2776. tmp = RREG32(GRBM_STATUS);
  2777. if (tmp & (PA_BUSY | SC_BUSY |
  2778. BCI_BUSY | SX_BUSY |
  2779. TA_BUSY | VGT_BUSY |
  2780. DB_BUSY | CB_BUSY |
  2781. GDS_BUSY | SPI_BUSY |
  2782. IA_BUSY | IA_BUSY_NO_DMA))
  2783. reset_mask |= RADEON_RESET_GFX;
  2784. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  2785. CP_BUSY | CP_COHERENCY_BUSY))
  2786. reset_mask |= RADEON_RESET_CP;
  2787. if (tmp & GRBM_EE_BUSY)
  2788. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  2789. /* GRBM_STATUS2 */
  2790. tmp = RREG32(GRBM_STATUS2);
  2791. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  2792. reset_mask |= RADEON_RESET_RLC;
  2793. /* DMA_STATUS_REG 0 */
  2794. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  2795. if (!(tmp & DMA_IDLE))
  2796. reset_mask |= RADEON_RESET_DMA;
  2797. /* DMA_STATUS_REG 1 */
  2798. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  2799. if (!(tmp & DMA_IDLE))
  2800. reset_mask |= RADEON_RESET_DMA1;
  2801. /* SRBM_STATUS2 */
  2802. tmp = RREG32(SRBM_STATUS2);
  2803. if (tmp & DMA_BUSY)
  2804. reset_mask |= RADEON_RESET_DMA;
  2805. if (tmp & DMA1_BUSY)
  2806. reset_mask |= RADEON_RESET_DMA1;
  2807. /* SRBM_STATUS */
  2808. tmp = RREG32(SRBM_STATUS);
  2809. if (tmp & IH_BUSY)
  2810. reset_mask |= RADEON_RESET_IH;
  2811. if (tmp & SEM_BUSY)
  2812. reset_mask |= RADEON_RESET_SEM;
  2813. if (tmp & GRBM_RQ_PENDING)
  2814. reset_mask |= RADEON_RESET_GRBM;
  2815. if (tmp & VMC_BUSY)
  2816. reset_mask |= RADEON_RESET_VMC;
  2817. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  2818. MCC_BUSY | MCD_BUSY))
  2819. reset_mask |= RADEON_RESET_MC;
  2820. if (evergreen_is_display_hung(rdev))
  2821. reset_mask |= RADEON_RESET_DISPLAY;
  2822. /* VM_L2_STATUS */
  2823. tmp = RREG32(VM_L2_STATUS);
  2824. if (tmp & L2_BUSY)
  2825. reset_mask |= RADEON_RESET_VMC;
  2826. /* Skip MC reset as it's mostly likely not hung, just busy */
  2827. if (reset_mask & RADEON_RESET_MC) {
  2828. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  2829. reset_mask &= ~RADEON_RESET_MC;
  2830. }
  2831. return reset_mask;
  2832. }
  2833. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  2834. {
  2835. struct evergreen_mc_save save;
  2836. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  2837. u32 tmp;
  2838. if (reset_mask == 0)
  2839. return;
  2840. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  2841. evergreen_print_gpu_status_regs(rdev);
  2842. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  2843. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  2844. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  2845. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  2846. /* Disable CP parsing/prefetching */
  2847. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  2848. if (reset_mask & RADEON_RESET_DMA) {
  2849. /* dma0 */
  2850. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  2851. tmp &= ~DMA_RB_ENABLE;
  2852. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  2853. }
  2854. if (reset_mask & RADEON_RESET_DMA1) {
  2855. /* dma1 */
  2856. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  2857. tmp &= ~DMA_RB_ENABLE;
  2858. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  2859. }
  2860. udelay(50);
  2861. evergreen_mc_stop(rdev, &save);
  2862. if (evergreen_mc_wait_for_idle(rdev)) {
  2863. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2864. }
  2865. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  2866. grbm_soft_reset = SOFT_RESET_CB |
  2867. SOFT_RESET_DB |
  2868. SOFT_RESET_GDS |
  2869. SOFT_RESET_PA |
  2870. SOFT_RESET_SC |
  2871. SOFT_RESET_BCI |
  2872. SOFT_RESET_SPI |
  2873. SOFT_RESET_SX |
  2874. SOFT_RESET_TC |
  2875. SOFT_RESET_TA |
  2876. SOFT_RESET_VGT |
  2877. SOFT_RESET_IA;
  2878. }
  2879. if (reset_mask & RADEON_RESET_CP) {
  2880. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  2881. srbm_soft_reset |= SOFT_RESET_GRBM;
  2882. }
  2883. if (reset_mask & RADEON_RESET_DMA)
  2884. srbm_soft_reset |= SOFT_RESET_DMA;
  2885. if (reset_mask & RADEON_RESET_DMA1)
  2886. srbm_soft_reset |= SOFT_RESET_DMA1;
  2887. if (reset_mask & RADEON_RESET_DISPLAY)
  2888. srbm_soft_reset |= SOFT_RESET_DC;
  2889. if (reset_mask & RADEON_RESET_RLC)
  2890. grbm_soft_reset |= SOFT_RESET_RLC;
  2891. if (reset_mask & RADEON_RESET_SEM)
  2892. srbm_soft_reset |= SOFT_RESET_SEM;
  2893. if (reset_mask & RADEON_RESET_IH)
  2894. srbm_soft_reset |= SOFT_RESET_IH;
  2895. if (reset_mask & RADEON_RESET_GRBM)
  2896. srbm_soft_reset |= SOFT_RESET_GRBM;
  2897. if (reset_mask & RADEON_RESET_VMC)
  2898. srbm_soft_reset |= SOFT_RESET_VMC;
  2899. if (reset_mask & RADEON_RESET_MC)
  2900. srbm_soft_reset |= SOFT_RESET_MC;
  2901. if (grbm_soft_reset) {
  2902. tmp = RREG32(GRBM_SOFT_RESET);
  2903. tmp |= grbm_soft_reset;
  2904. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  2905. WREG32(GRBM_SOFT_RESET, tmp);
  2906. tmp = RREG32(GRBM_SOFT_RESET);
  2907. udelay(50);
  2908. tmp &= ~grbm_soft_reset;
  2909. WREG32(GRBM_SOFT_RESET, tmp);
  2910. tmp = RREG32(GRBM_SOFT_RESET);
  2911. }
  2912. if (srbm_soft_reset) {
  2913. tmp = RREG32(SRBM_SOFT_RESET);
  2914. tmp |= srbm_soft_reset;
  2915. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  2916. WREG32(SRBM_SOFT_RESET, tmp);
  2917. tmp = RREG32(SRBM_SOFT_RESET);
  2918. udelay(50);
  2919. tmp &= ~srbm_soft_reset;
  2920. WREG32(SRBM_SOFT_RESET, tmp);
  2921. tmp = RREG32(SRBM_SOFT_RESET);
  2922. }
  2923. /* Wait a little for things to settle down */
  2924. udelay(50);
  2925. evergreen_mc_resume(rdev, &save);
  2926. udelay(50);
  2927. evergreen_print_gpu_status_regs(rdev);
  2928. }
  2929. int si_asic_reset(struct radeon_device *rdev)
  2930. {
  2931. u32 reset_mask;
  2932. reset_mask = si_gpu_check_soft_reset(rdev);
  2933. if (reset_mask)
  2934. r600_set_bios_scratch_engine_hung(rdev, true);
  2935. si_gpu_soft_reset(rdev, reset_mask);
  2936. reset_mask = si_gpu_check_soft_reset(rdev);
  2937. if (!reset_mask)
  2938. r600_set_bios_scratch_engine_hung(rdev, false);
  2939. return 0;
  2940. }
  2941. /**
  2942. * si_gfx_is_lockup - Check if the GFX engine is locked up
  2943. *
  2944. * @rdev: radeon_device pointer
  2945. * @ring: radeon_ring structure holding ring information
  2946. *
  2947. * Check if the GFX engine is locked up.
  2948. * Returns true if the engine appears to be locked up, false if not.
  2949. */
  2950. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  2951. {
  2952. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  2953. if (!(reset_mask & (RADEON_RESET_GFX |
  2954. RADEON_RESET_COMPUTE |
  2955. RADEON_RESET_CP))) {
  2956. radeon_ring_lockup_update(ring);
  2957. return false;
  2958. }
  2959. /* force CP activities */
  2960. radeon_ring_force_activity(rdev, ring);
  2961. return radeon_ring_test_lockup(rdev, ring);
  2962. }
  2963. /**
  2964. * si_dma_is_lockup - Check if the DMA engine is locked up
  2965. *
  2966. * @rdev: radeon_device pointer
  2967. * @ring: radeon_ring structure holding ring information
  2968. *
  2969. * Check if the async DMA engine is locked up.
  2970. * Returns true if the engine appears to be locked up, false if not.
  2971. */
  2972. bool si_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  2973. {
  2974. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  2975. u32 mask;
  2976. if (ring->idx == R600_RING_TYPE_DMA_INDEX)
  2977. mask = RADEON_RESET_DMA;
  2978. else
  2979. mask = RADEON_RESET_DMA1;
  2980. if (!(reset_mask & mask)) {
  2981. radeon_ring_lockup_update(ring);
  2982. return false;
  2983. }
  2984. /* force ring activities */
  2985. radeon_ring_force_activity(rdev, ring);
  2986. return radeon_ring_test_lockup(rdev, ring);
  2987. }
  2988. /* MC */
  2989. static void si_mc_program(struct radeon_device *rdev)
  2990. {
  2991. struct evergreen_mc_save save;
  2992. u32 tmp;
  2993. int i, j;
  2994. /* Initialize HDP */
  2995. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2996. WREG32((0x2c14 + j), 0x00000000);
  2997. WREG32((0x2c18 + j), 0x00000000);
  2998. WREG32((0x2c1c + j), 0x00000000);
  2999. WREG32((0x2c20 + j), 0x00000000);
  3000. WREG32((0x2c24 + j), 0x00000000);
  3001. }
  3002. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3003. evergreen_mc_stop(rdev, &save);
  3004. if (radeon_mc_wait_for_idle(rdev)) {
  3005. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3006. }
  3007. /* Lockout access through VGA aperture*/
  3008. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3009. /* Update configuration */
  3010. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3011. rdev->mc.vram_start >> 12);
  3012. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3013. rdev->mc.vram_end >> 12);
  3014. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3015. rdev->vram_scratch.gpu_addr >> 12);
  3016. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3017. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3018. WREG32(MC_VM_FB_LOCATION, tmp);
  3019. /* XXX double check these! */
  3020. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3021. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3022. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3023. WREG32(MC_VM_AGP_BASE, 0);
  3024. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3025. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3026. if (radeon_mc_wait_for_idle(rdev)) {
  3027. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3028. }
  3029. evergreen_mc_resume(rdev, &save);
  3030. /* we need to own VRAM, so turn off the VGA renderer here
  3031. * to stop it overwriting our objects */
  3032. rv515_vga_render_disable(rdev);
  3033. }
  3034. static void si_vram_gtt_location(struct radeon_device *rdev,
  3035. struct radeon_mc *mc)
  3036. {
  3037. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3038. /* leave room for at least 1024M GTT */
  3039. dev_warn(rdev->dev, "limiting VRAM\n");
  3040. mc->real_vram_size = 0xFFC0000000ULL;
  3041. mc->mc_vram_size = 0xFFC0000000ULL;
  3042. }
  3043. radeon_vram_location(rdev, &rdev->mc, 0);
  3044. rdev->mc.gtt_base_align = 0;
  3045. radeon_gtt_location(rdev, mc);
  3046. }
  3047. static int si_mc_init(struct radeon_device *rdev)
  3048. {
  3049. u32 tmp;
  3050. int chansize, numchan;
  3051. /* Get VRAM informations */
  3052. rdev->mc.vram_is_ddr = true;
  3053. tmp = RREG32(MC_ARB_RAMCFG);
  3054. if (tmp & CHANSIZE_OVERRIDE) {
  3055. chansize = 16;
  3056. } else if (tmp & CHANSIZE_MASK) {
  3057. chansize = 64;
  3058. } else {
  3059. chansize = 32;
  3060. }
  3061. tmp = RREG32(MC_SHARED_CHMAP);
  3062. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3063. case 0:
  3064. default:
  3065. numchan = 1;
  3066. break;
  3067. case 1:
  3068. numchan = 2;
  3069. break;
  3070. case 2:
  3071. numchan = 4;
  3072. break;
  3073. case 3:
  3074. numchan = 8;
  3075. break;
  3076. case 4:
  3077. numchan = 3;
  3078. break;
  3079. case 5:
  3080. numchan = 6;
  3081. break;
  3082. case 6:
  3083. numchan = 10;
  3084. break;
  3085. case 7:
  3086. numchan = 12;
  3087. break;
  3088. case 8:
  3089. numchan = 16;
  3090. break;
  3091. }
  3092. rdev->mc.vram_width = numchan * chansize;
  3093. /* Could aper size report 0 ? */
  3094. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3095. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3096. /* size in MB on si */
  3097. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3098. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3099. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3100. si_vram_gtt_location(rdev, &rdev->mc);
  3101. radeon_update_bandwidth_info(rdev);
  3102. return 0;
  3103. }
  3104. /*
  3105. * GART
  3106. */
  3107. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3108. {
  3109. /* flush hdp cache */
  3110. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3111. /* bits 0-15 are the VM contexts0-15 */
  3112. WREG32(VM_INVALIDATE_REQUEST, 1);
  3113. }
  3114. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3115. {
  3116. int r, i;
  3117. if (rdev->gart.robj == NULL) {
  3118. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3119. return -EINVAL;
  3120. }
  3121. r = radeon_gart_table_vram_pin(rdev);
  3122. if (r)
  3123. return r;
  3124. radeon_gart_restore(rdev);
  3125. /* Setup TLB control */
  3126. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3127. (0xA << 7) |
  3128. ENABLE_L1_TLB |
  3129. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3130. ENABLE_ADVANCED_DRIVER_MODEL |
  3131. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3132. /* Setup L2 cache */
  3133. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3134. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3135. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3136. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3137. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3138. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3139. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3140. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3141. /* setup context0 */
  3142. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3143. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3144. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3145. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3146. (u32)(rdev->dummy_page.addr >> 12));
  3147. WREG32(VM_CONTEXT0_CNTL2, 0);
  3148. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3149. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3150. WREG32(0x15D4, 0);
  3151. WREG32(0x15D8, 0);
  3152. WREG32(0x15DC, 0);
  3153. /* empty context1-15 */
  3154. /* set vm size, must be a multiple of 4 */
  3155. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3156. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3157. /* Assign the pt base to something valid for now; the pts used for
  3158. * the VMs are determined by the application and setup and assigned
  3159. * on the fly in the vm part of radeon_gart.c
  3160. */
  3161. for (i = 1; i < 16; i++) {
  3162. if (i < 8)
  3163. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3164. rdev->gart.table_addr >> 12);
  3165. else
  3166. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3167. rdev->gart.table_addr >> 12);
  3168. }
  3169. /* enable context1-15 */
  3170. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3171. (u32)(rdev->dummy_page.addr >> 12));
  3172. WREG32(VM_CONTEXT1_CNTL2, 4);
  3173. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3174. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3175. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3176. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3177. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3178. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3179. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3180. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3181. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3182. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3183. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3184. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3185. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3186. si_pcie_gart_tlb_flush(rdev);
  3187. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3188. (unsigned)(rdev->mc.gtt_size >> 20),
  3189. (unsigned long long)rdev->gart.table_addr);
  3190. rdev->gart.ready = true;
  3191. return 0;
  3192. }
  3193. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3194. {
  3195. /* Disable all tables */
  3196. WREG32(VM_CONTEXT0_CNTL, 0);
  3197. WREG32(VM_CONTEXT1_CNTL, 0);
  3198. /* Setup TLB control */
  3199. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3200. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3201. /* Setup L2 cache */
  3202. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3203. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3204. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3205. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3206. WREG32(VM_L2_CNTL2, 0);
  3207. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3208. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3209. radeon_gart_table_vram_unpin(rdev);
  3210. }
  3211. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3212. {
  3213. si_pcie_gart_disable(rdev);
  3214. radeon_gart_table_vram_free(rdev);
  3215. radeon_gart_fini(rdev);
  3216. }
  3217. /* vm parser */
  3218. static bool si_vm_reg_valid(u32 reg)
  3219. {
  3220. /* context regs are fine */
  3221. if (reg >= 0x28000)
  3222. return true;
  3223. /* check config regs */
  3224. switch (reg) {
  3225. case GRBM_GFX_INDEX:
  3226. case CP_STRMOUT_CNTL:
  3227. case VGT_VTX_VECT_EJECT_REG:
  3228. case VGT_CACHE_INVALIDATION:
  3229. case VGT_ESGS_RING_SIZE:
  3230. case VGT_GSVS_RING_SIZE:
  3231. case VGT_GS_VERTEX_REUSE:
  3232. case VGT_PRIMITIVE_TYPE:
  3233. case VGT_INDEX_TYPE:
  3234. case VGT_NUM_INDICES:
  3235. case VGT_NUM_INSTANCES:
  3236. case VGT_TF_RING_SIZE:
  3237. case VGT_HS_OFFCHIP_PARAM:
  3238. case VGT_TF_MEMORY_BASE:
  3239. case PA_CL_ENHANCE:
  3240. case PA_SU_LINE_STIPPLE_VALUE:
  3241. case PA_SC_LINE_STIPPLE_STATE:
  3242. case PA_SC_ENHANCE:
  3243. case SQC_CACHES:
  3244. case SPI_STATIC_THREAD_MGMT_1:
  3245. case SPI_STATIC_THREAD_MGMT_2:
  3246. case SPI_STATIC_THREAD_MGMT_3:
  3247. case SPI_PS_MAX_WAVE_ID:
  3248. case SPI_CONFIG_CNTL:
  3249. case SPI_CONFIG_CNTL_1:
  3250. case TA_CNTL_AUX:
  3251. return true;
  3252. default:
  3253. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3254. return false;
  3255. }
  3256. }
  3257. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3258. u32 *ib, struct radeon_cs_packet *pkt)
  3259. {
  3260. switch (pkt->opcode) {
  3261. case PACKET3_NOP:
  3262. case PACKET3_SET_BASE:
  3263. case PACKET3_SET_CE_DE_COUNTERS:
  3264. case PACKET3_LOAD_CONST_RAM:
  3265. case PACKET3_WRITE_CONST_RAM:
  3266. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3267. case PACKET3_DUMP_CONST_RAM:
  3268. case PACKET3_INCREMENT_CE_COUNTER:
  3269. case PACKET3_WAIT_ON_DE_COUNTER:
  3270. case PACKET3_CE_WRITE:
  3271. break;
  3272. default:
  3273. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3274. return -EINVAL;
  3275. }
  3276. return 0;
  3277. }
  3278. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3279. u32 *ib, struct radeon_cs_packet *pkt)
  3280. {
  3281. u32 idx = pkt->idx + 1;
  3282. u32 idx_value = ib[idx];
  3283. u32 start_reg, end_reg, reg, i;
  3284. u32 command, info;
  3285. switch (pkt->opcode) {
  3286. case PACKET3_NOP:
  3287. case PACKET3_SET_BASE:
  3288. case PACKET3_CLEAR_STATE:
  3289. case PACKET3_INDEX_BUFFER_SIZE:
  3290. case PACKET3_DISPATCH_DIRECT:
  3291. case PACKET3_DISPATCH_INDIRECT:
  3292. case PACKET3_ALLOC_GDS:
  3293. case PACKET3_WRITE_GDS_RAM:
  3294. case PACKET3_ATOMIC_GDS:
  3295. case PACKET3_ATOMIC:
  3296. case PACKET3_OCCLUSION_QUERY:
  3297. case PACKET3_SET_PREDICATION:
  3298. case PACKET3_COND_EXEC:
  3299. case PACKET3_PRED_EXEC:
  3300. case PACKET3_DRAW_INDIRECT:
  3301. case PACKET3_DRAW_INDEX_INDIRECT:
  3302. case PACKET3_INDEX_BASE:
  3303. case PACKET3_DRAW_INDEX_2:
  3304. case PACKET3_CONTEXT_CONTROL:
  3305. case PACKET3_INDEX_TYPE:
  3306. case PACKET3_DRAW_INDIRECT_MULTI:
  3307. case PACKET3_DRAW_INDEX_AUTO:
  3308. case PACKET3_DRAW_INDEX_IMMD:
  3309. case PACKET3_NUM_INSTANCES:
  3310. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3311. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3312. case PACKET3_DRAW_INDEX_OFFSET_2:
  3313. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3314. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3315. case PACKET3_MPEG_INDEX:
  3316. case PACKET3_WAIT_REG_MEM:
  3317. case PACKET3_MEM_WRITE:
  3318. case PACKET3_PFP_SYNC_ME:
  3319. case PACKET3_SURFACE_SYNC:
  3320. case PACKET3_EVENT_WRITE:
  3321. case PACKET3_EVENT_WRITE_EOP:
  3322. case PACKET3_EVENT_WRITE_EOS:
  3323. case PACKET3_SET_CONTEXT_REG:
  3324. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3325. case PACKET3_SET_SH_REG:
  3326. case PACKET3_SET_SH_REG_OFFSET:
  3327. case PACKET3_INCREMENT_DE_COUNTER:
  3328. case PACKET3_WAIT_ON_CE_COUNTER:
  3329. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3330. case PACKET3_ME_WRITE:
  3331. break;
  3332. case PACKET3_COPY_DATA:
  3333. if ((idx_value & 0xf00) == 0) {
  3334. reg = ib[idx + 3] * 4;
  3335. if (!si_vm_reg_valid(reg))
  3336. return -EINVAL;
  3337. }
  3338. break;
  3339. case PACKET3_WRITE_DATA:
  3340. if ((idx_value & 0xf00) == 0) {
  3341. start_reg = ib[idx + 1] * 4;
  3342. if (idx_value & 0x10000) {
  3343. if (!si_vm_reg_valid(start_reg))
  3344. return -EINVAL;
  3345. } else {
  3346. for (i = 0; i < (pkt->count - 2); i++) {
  3347. reg = start_reg + (4 * i);
  3348. if (!si_vm_reg_valid(reg))
  3349. return -EINVAL;
  3350. }
  3351. }
  3352. }
  3353. break;
  3354. case PACKET3_COND_WRITE:
  3355. if (idx_value & 0x100) {
  3356. reg = ib[idx + 5] * 4;
  3357. if (!si_vm_reg_valid(reg))
  3358. return -EINVAL;
  3359. }
  3360. break;
  3361. case PACKET3_COPY_DW:
  3362. if (idx_value & 0x2) {
  3363. reg = ib[idx + 3] * 4;
  3364. if (!si_vm_reg_valid(reg))
  3365. return -EINVAL;
  3366. }
  3367. break;
  3368. case PACKET3_SET_CONFIG_REG:
  3369. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3370. end_reg = 4 * pkt->count + start_reg - 4;
  3371. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3372. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3373. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3374. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3375. return -EINVAL;
  3376. }
  3377. for (i = 0; i < pkt->count; i++) {
  3378. reg = start_reg + (4 * i);
  3379. if (!si_vm_reg_valid(reg))
  3380. return -EINVAL;
  3381. }
  3382. break;
  3383. case PACKET3_CP_DMA:
  3384. command = ib[idx + 4];
  3385. info = ib[idx + 1];
  3386. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3387. /* src address space is register */
  3388. if (((info & 0x60000000) >> 29) == 0) {
  3389. start_reg = idx_value << 2;
  3390. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3391. reg = start_reg;
  3392. if (!si_vm_reg_valid(reg)) {
  3393. DRM_ERROR("CP DMA Bad SRC register\n");
  3394. return -EINVAL;
  3395. }
  3396. } else {
  3397. for (i = 0; i < (command & 0x1fffff); i++) {
  3398. reg = start_reg + (4 * i);
  3399. if (!si_vm_reg_valid(reg)) {
  3400. DRM_ERROR("CP DMA Bad SRC register\n");
  3401. return -EINVAL;
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3408. /* dst address space is register */
  3409. if (((info & 0x00300000) >> 20) == 0) {
  3410. start_reg = ib[idx + 2];
  3411. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3412. reg = start_reg;
  3413. if (!si_vm_reg_valid(reg)) {
  3414. DRM_ERROR("CP DMA Bad DST register\n");
  3415. return -EINVAL;
  3416. }
  3417. } else {
  3418. for (i = 0; i < (command & 0x1fffff); i++) {
  3419. reg = start_reg + (4 * i);
  3420. if (!si_vm_reg_valid(reg)) {
  3421. DRM_ERROR("CP DMA Bad DST register\n");
  3422. return -EINVAL;
  3423. }
  3424. }
  3425. }
  3426. }
  3427. }
  3428. break;
  3429. default:
  3430. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3431. return -EINVAL;
  3432. }
  3433. return 0;
  3434. }
  3435. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3436. u32 *ib, struct radeon_cs_packet *pkt)
  3437. {
  3438. u32 idx = pkt->idx + 1;
  3439. u32 idx_value = ib[idx];
  3440. u32 start_reg, reg, i;
  3441. switch (pkt->opcode) {
  3442. case PACKET3_NOP:
  3443. case PACKET3_SET_BASE:
  3444. case PACKET3_CLEAR_STATE:
  3445. case PACKET3_DISPATCH_DIRECT:
  3446. case PACKET3_DISPATCH_INDIRECT:
  3447. case PACKET3_ALLOC_GDS:
  3448. case PACKET3_WRITE_GDS_RAM:
  3449. case PACKET3_ATOMIC_GDS:
  3450. case PACKET3_ATOMIC:
  3451. case PACKET3_OCCLUSION_QUERY:
  3452. case PACKET3_SET_PREDICATION:
  3453. case PACKET3_COND_EXEC:
  3454. case PACKET3_PRED_EXEC:
  3455. case PACKET3_CONTEXT_CONTROL:
  3456. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3457. case PACKET3_WAIT_REG_MEM:
  3458. case PACKET3_MEM_WRITE:
  3459. case PACKET3_PFP_SYNC_ME:
  3460. case PACKET3_SURFACE_SYNC:
  3461. case PACKET3_EVENT_WRITE:
  3462. case PACKET3_EVENT_WRITE_EOP:
  3463. case PACKET3_EVENT_WRITE_EOS:
  3464. case PACKET3_SET_CONTEXT_REG:
  3465. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3466. case PACKET3_SET_SH_REG:
  3467. case PACKET3_SET_SH_REG_OFFSET:
  3468. case PACKET3_INCREMENT_DE_COUNTER:
  3469. case PACKET3_WAIT_ON_CE_COUNTER:
  3470. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3471. case PACKET3_ME_WRITE:
  3472. break;
  3473. case PACKET3_COPY_DATA:
  3474. if ((idx_value & 0xf00) == 0) {
  3475. reg = ib[idx + 3] * 4;
  3476. if (!si_vm_reg_valid(reg))
  3477. return -EINVAL;
  3478. }
  3479. break;
  3480. case PACKET3_WRITE_DATA:
  3481. if ((idx_value & 0xf00) == 0) {
  3482. start_reg = ib[idx + 1] * 4;
  3483. if (idx_value & 0x10000) {
  3484. if (!si_vm_reg_valid(start_reg))
  3485. return -EINVAL;
  3486. } else {
  3487. for (i = 0; i < (pkt->count - 2); i++) {
  3488. reg = start_reg + (4 * i);
  3489. if (!si_vm_reg_valid(reg))
  3490. return -EINVAL;
  3491. }
  3492. }
  3493. }
  3494. break;
  3495. case PACKET3_COND_WRITE:
  3496. if (idx_value & 0x100) {
  3497. reg = ib[idx + 5] * 4;
  3498. if (!si_vm_reg_valid(reg))
  3499. return -EINVAL;
  3500. }
  3501. break;
  3502. case PACKET3_COPY_DW:
  3503. if (idx_value & 0x2) {
  3504. reg = ib[idx + 3] * 4;
  3505. if (!si_vm_reg_valid(reg))
  3506. return -EINVAL;
  3507. }
  3508. break;
  3509. default:
  3510. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  3511. return -EINVAL;
  3512. }
  3513. return 0;
  3514. }
  3515. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3516. {
  3517. int ret = 0;
  3518. u32 idx = 0;
  3519. struct radeon_cs_packet pkt;
  3520. do {
  3521. pkt.idx = idx;
  3522. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  3523. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  3524. pkt.one_reg_wr = 0;
  3525. switch (pkt.type) {
  3526. case RADEON_PACKET_TYPE0:
  3527. dev_err(rdev->dev, "Packet0 not allowed!\n");
  3528. ret = -EINVAL;
  3529. break;
  3530. case RADEON_PACKET_TYPE2:
  3531. idx += 1;
  3532. break;
  3533. case RADEON_PACKET_TYPE3:
  3534. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  3535. if (ib->is_const_ib)
  3536. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  3537. else {
  3538. switch (ib->ring) {
  3539. case RADEON_RING_TYPE_GFX_INDEX:
  3540. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  3541. break;
  3542. case CAYMAN_RING_TYPE_CP1_INDEX:
  3543. case CAYMAN_RING_TYPE_CP2_INDEX:
  3544. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  3545. break;
  3546. default:
  3547. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  3548. ret = -EINVAL;
  3549. break;
  3550. }
  3551. }
  3552. idx += pkt.count + 2;
  3553. break;
  3554. default:
  3555. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  3556. ret = -EINVAL;
  3557. break;
  3558. }
  3559. if (ret)
  3560. break;
  3561. } while (idx < ib->length_dw);
  3562. return ret;
  3563. }
  3564. /*
  3565. * vm
  3566. */
  3567. int si_vm_init(struct radeon_device *rdev)
  3568. {
  3569. /* number of VMs */
  3570. rdev->vm_manager.nvm = 16;
  3571. /* base offset of vram pages */
  3572. rdev->vm_manager.vram_base_offset = 0;
  3573. return 0;
  3574. }
  3575. void si_vm_fini(struct radeon_device *rdev)
  3576. {
  3577. }
  3578. /**
  3579. * si_vm_set_page - update the page tables using the CP
  3580. *
  3581. * @rdev: radeon_device pointer
  3582. * @ib: indirect buffer to fill with commands
  3583. * @pe: addr of the page entry
  3584. * @addr: dst addr to write into pe
  3585. * @count: number of page entries to update
  3586. * @incr: increase next addr by incr bytes
  3587. * @flags: access flags
  3588. *
  3589. * Update the page tables using the CP (SI).
  3590. */
  3591. void si_vm_set_page(struct radeon_device *rdev,
  3592. struct radeon_ib *ib,
  3593. uint64_t pe,
  3594. uint64_t addr, unsigned count,
  3595. uint32_t incr, uint32_t flags)
  3596. {
  3597. uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
  3598. uint64_t value;
  3599. unsigned ndw;
  3600. if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
  3601. while (count) {
  3602. ndw = 2 + count * 2;
  3603. if (ndw > 0x3FFE)
  3604. ndw = 0x3FFE;
  3605. ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
  3606. ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
  3607. WRITE_DATA_DST_SEL(1));
  3608. ib->ptr[ib->length_dw++] = pe;
  3609. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  3610. for (; ndw > 2; ndw -= 2, --count, pe += 8) {
  3611. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3612. value = radeon_vm_map_gart(rdev, addr);
  3613. value &= 0xFFFFFFFFFFFFF000ULL;
  3614. } else if (flags & RADEON_VM_PAGE_VALID) {
  3615. value = addr;
  3616. } else {
  3617. value = 0;
  3618. }
  3619. addr += incr;
  3620. value |= r600_flags;
  3621. ib->ptr[ib->length_dw++] = value;
  3622. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3623. }
  3624. }
  3625. } else {
  3626. /* DMA */
  3627. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3628. while (count) {
  3629. ndw = count * 2;
  3630. if (ndw > 0xFFFFE)
  3631. ndw = 0xFFFFE;
  3632. /* for non-physically contiguous pages (system) */
  3633. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 0, ndw);
  3634. ib->ptr[ib->length_dw++] = pe;
  3635. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3636. for (; ndw > 0; ndw -= 2, --count, pe += 8) {
  3637. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3638. value = radeon_vm_map_gart(rdev, addr);
  3639. value &= 0xFFFFFFFFFFFFF000ULL;
  3640. } else if (flags & RADEON_VM_PAGE_VALID) {
  3641. value = addr;
  3642. } else {
  3643. value = 0;
  3644. }
  3645. addr += incr;
  3646. value |= r600_flags;
  3647. ib->ptr[ib->length_dw++] = value;
  3648. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3649. }
  3650. }
  3651. } else {
  3652. while (count) {
  3653. ndw = count * 2;
  3654. if (ndw > 0xFFFFE)
  3655. ndw = 0xFFFFE;
  3656. if (flags & RADEON_VM_PAGE_VALID)
  3657. value = addr;
  3658. else
  3659. value = 0;
  3660. /* for physically contiguous pages (vram) */
  3661. ib->ptr[ib->length_dw++] = DMA_PTE_PDE_PACKET(ndw);
  3662. ib->ptr[ib->length_dw++] = pe; /* dst addr */
  3663. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3664. ib->ptr[ib->length_dw++] = r600_flags; /* mask */
  3665. ib->ptr[ib->length_dw++] = 0;
  3666. ib->ptr[ib->length_dw++] = value; /* value */
  3667. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3668. ib->ptr[ib->length_dw++] = incr; /* increment size */
  3669. ib->ptr[ib->length_dw++] = 0;
  3670. pe += ndw * 4;
  3671. addr += (ndw / 2) * incr;
  3672. count -= ndw / 2;
  3673. }
  3674. }
  3675. while (ib->length_dw & 0x7)
  3676. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0);
  3677. }
  3678. }
  3679. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3680. {
  3681. struct radeon_ring *ring = &rdev->ring[ridx];
  3682. if (vm == NULL)
  3683. return;
  3684. /* write new base address */
  3685. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3686. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3687. WRITE_DATA_DST_SEL(0)));
  3688. if (vm->id < 8) {
  3689. radeon_ring_write(ring,
  3690. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  3691. } else {
  3692. radeon_ring_write(ring,
  3693. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  3694. }
  3695. radeon_ring_write(ring, 0);
  3696. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3697. /* flush hdp cache */
  3698. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3699. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3700. WRITE_DATA_DST_SEL(0)));
  3701. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  3702. radeon_ring_write(ring, 0);
  3703. radeon_ring_write(ring, 0x1);
  3704. /* bits 0-15 are the VM contexts0-15 */
  3705. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3706. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3707. WRITE_DATA_DST_SEL(0)));
  3708. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  3709. radeon_ring_write(ring, 0);
  3710. radeon_ring_write(ring, 1 << vm->id);
  3711. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  3712. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  3713. radeon_ring_write(ring, 0x0);
  3714. }
  3715. void si_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3716. {
  3717. struct radeon_ring *ring = &rdev->ring[ridx];
  3718. if (vm == NULL)
  3719. return;
  3720. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3721. if (vm->id < 8) {
  3722. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
  3723. } else {
  3724. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2));
  3725. }
  3726. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3727. /* flush hdp cache */
  3728. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3729. radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
  3730. radeon_ring_write(ring, 1);
  3731. /* bits 0-7 are the VM contexts0-7 */
  3732. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3733. radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
  3734. radeon_ring_write(ring, 1 << vm->id);
  3735. }
  3736. /*
  3737. * RLC
  3738. */
  3739. void si_rlc_fini(struct radeon_device *rdev)
  3740. {
  3741. int r;
  3742. /* save restore block */
  3743. if (rdev->rlc.save_restore_obj) {
  3744. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3745. if (unlikely(r != 0))
  3746. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3747. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3748. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3749. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3750. rdev->rlc.save_restore_obj = NULL;
  3751. }
  3752. /* clear state block */
  3753. if (rdev->rlc.clear_state_obj) {
  3754. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3755. if (unlikely(r != 0))
  3756. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3757. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3758. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3759. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3760. rdev->rlc.clear_state_obj = NULL;
  3761. }
  3762. }
  3763. int si_rlc_init(struct radeon_device *rdev)
  3764. {
  3765. int r;
  3766. /* save restore block */
  3767. if (rdev->rlc.save_restore_obj == NULL) {
  3768. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  3769. RADEON_GEM_DOMAIN_VRAM, NULL,
  3770. &rdev->rlc.save_restore_obj);
  3771. if (r) {
  3772. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3773. return r;
  3774. }
  3775. }
  3776. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3777. if (unlikely(r != 0)) {
  3778. si_rlc_fini(rdev);
  3779. return r;
  3780. }
  3781. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3782. &rdev->rlc.save_restore_gpu_addr);
  3783. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3784. if (r) {
  3785. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3786. si_rlc_fini(rdev);
  3787. return r;
  3788. }
  3789. /* clear state block */
  3790. if (rdev->rlc.clear_state_obj == NULL) {
  3791. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  3792. RADEON_GEM_DOMAIN_VRAM, NULL,
  3793. &rdev->rlc.clear_state_obj);
  3794. if (r) {
  3795. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3796. si_rlc_fini(rdev);
  3797. return r;
  3798. }
  3799. }
  3800. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3801. if (unlikely(r != 0)) {
  3802. si_rlc_fini(rdev);
  3803. return r;
  3804. }
  3805. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3806. &rdev->rlc.clear_state_gpu_addr);
  3807. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3808. if (r) {
  3809. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3810. si_rlc_fini(rdev);
  3811. return r;
  3812. }
  3813. return 0;
  3814. }
  3815. static void si_rlc_stop(struct radeon_device *rdev)
  3816. {
  3817. WREG32(RLC_CNTL, 0);
  3818. }
  3819. static void si_rlc_start(struct radeon_device *rdev)
  3820. {
  3821. WREG32(RLC_CNTL, RLC_ENABLE);
  3822. }
  3823. static int si_rlc_resume(struct radeon_device *rdev)
  3824. {
  3825. u32 i;
  3826. const __be32 *fw_data;
  3827. if (!rdev->rlc_fw)
  3828. return -EINVAL;
  3829. si_rlc_stop(rdev);
  3830. WREG32(RLC_RL_BASE, 0);
  3831. WREG32(RLC_RL_SIZE, 0);
  3832. WREG32(RLC_LB_CNTL, 0);
  3833. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  3834. WREG32(RLC_LB_CNTR_INIT, 0);
  3835. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  3836. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  3837. WREG32(RLC_MC_CNTL, 0);
  3838. WREG32(RLC_UCODE_CNTL, 0);
  3839. fw_data = (const __be32 *)rdev->rlc_fw->data;
  3840. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  3841. WREG32(RLC_UCODE_ADDR, i);
  3842. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3843. }
  3844. WREG32(RLC_UCODE_ADDR, 0);
  3845. si_rlc_start(rdev);
  3846. return 0;
  3847. }
  3848. static void si_enable_interrupts(struct radeon_device *rdev)
  3849. {
  3850. u32 ih_cntl = RREG32(IH_CNTL);
  3851. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3852. ih_cntl |= ENABLE_INTR;
  3853. ih_rb_cntl |= IH_RB_ENABLE;
  3854. WREG32(IH_CNTL, ih_cntl);
  3855. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3856. rdev->ih.enabled = true;
  3857. }
  3858. static void si_disable_interrupts(struct radeon_device *rdev)
  3859. {
  3860. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3861. u32 ih_cntl = RREG32(IH_CNTL);
  3862. ih_rb_cntl &= ~IH_RB_ENABLE;
  3863. ih_cntl &= ~ENABLE_INTR;
  3864. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3865. WREG32(IH_CNTL, ih_cntl);
  3866. /* set rptr, wptr to 0 */
  3867. WREG32(IH_RB_RPTR, 0);
  3868. WREG32(IH_RB_WPTR, 0);
  3869. rdev->ih.enabled = false;
  3870. rdev->ih.rptr = 0;
  3871. }
  3872. static void si_disable_interrupt_state(struct radeon_device *rdev)
  3873. {
  3874. u32 tmp;
  3875. WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3876. WREG32(CP_INT_CNTL_RING1, 0);
  3877. WREG32(CP_INT_CNTL_RING2, 0);
  3878. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  3879. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3880. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  3881. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3882. WREG32(GRBM_INT_CNTL, 0);
  3883. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3884. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3885. if (rdev->num_crtc >= 4) {
  3886. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3887. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3888. }
  3889. if (rdev->num_crtc >= 6) {
  3890. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3891. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3892. }
  3893. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3894. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3895. if (rdev->num_crtc >= 4) {
  3896. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3897. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3898. }
  3899. if (rdev->num_crtc >= 6) {
  3900. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3901. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3902. }
  3903. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  3904. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3905. WREG32(DC_HPD1_INT_CONTROL, tmp);
  3906. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3907. WREG32(DC_HPD2_INT_CONTROL, tmp);
  3908. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3909. WREG32(DC_HPD3_INT_CONTROL, tmp);
  3910. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3911. WREG32(DC_HPD4_INT_CONTROL, tmp);
  3912. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3913. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3914. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3915. WREG32(DC_HPD6_INT_CONTROL, tmp);
  3916. }
  3917. static int si_irq_init(struct radeon_device *rdev)
  3918. {
  3919. int ret = 0;
  3920. int rb_bufsz;
  3921. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  3922. /* allocate ring */
  3923. ret = r600_ih_ring_alloc(rdev);
  3924. if (ret)
  3925. return ret;
  3926. /* disable irqs */
  3927. si_disable_interrupts(rdev);
  3928. /* init rlc */
  3929. ret = si_rlc_resume(rdev);
  3930. if (ret) {
  3931. r600_ih_ring_fini(rdev);
  3932. return ret;
  3933. }
  3934. /* setup interrupt control */
  3935. /* set dummy read address to ring address */
  3936. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  3937. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  3938. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  3939. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  3940. */
  3941. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  3942. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  3943. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  3944. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  3945. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  3946. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  3947. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  3948. IH_WPTR_OVERFLOW_CLEAR |
  3949. (rb_bufsz << 1));
  3950. if (rdev->wb.enabled)
  3951. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  3952. /* set the writeback address whether it's enabled or not */
  3953. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  3954. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  3955. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3956. /* set rptr, wptr to 0 */
  3957. WREG32(IH_RB_RPTR, 0);
  3958. WREG32(IH_RB_WPTR, 0);
  3959. /* Default settings for IH_CNTL (disabled at first) */
  3960. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  3961. /* RPTR_REARM only works if msi's are enabled */
  3962. if (rdev->msi_enabled)
  3963. ih_cntl |= RPTR_REARM;
  3964. WREG32(IH_CNTL, ih_cntl);
  3965. /* force the active interrupt state to all disabled */
  3966. si_disable_interrupt_state(rdev);
  3967. pci_set_master(rdev->pdev);
  3968. /* enable irqs */
  3969. si_enable_interrupts(rdev);
  3970. return ret;
  3971. }
  3972. int si_irq_set(struct radeon_device *rdev)
  3973. {
  3974. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  3975. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  3976. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  3977. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  3978. u32 grbm_int_cntl = 0;
  3979. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  3980. u32 dma_cntl, dma_cntl1;
  3981. if (!rdev->irq.installed) {
  3982. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  3983. return -EINVAL;
  3984. }
  3985. /* don't enable anything if the ih is disabled */
  3986. if (!rdev->ih.enabled) {
  3987. si_disable_interrupts(rdev);
  3988. /* force the active interrupt state to all disabled */
  3989. si_disable_interrupt_state(rdev);
  3990. return 0;
  3991. }
  3992. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3993. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3994. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3995. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3996. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3997. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3998. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  3999. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4000. /* enable CP interrupts on all rings */
  4001. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4002. DRM_DEBUG("si_irq_set: sw int gfx\n");
  4003. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4004. }
  4005. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4006. DRM_DEBUG("si_irq_set: sw int cp1\n");
  4007. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4008. }
  4009. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4010. DRM_DEBUG("si_irq_set: sw int cp2\n");
  4011. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4012. }
  4013. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4014. DRM_DEBUG("si_irq_set: sw int dma\n");
  4015. dma_cntl |= TRAP_ENABLE;
  4016. }
  4017. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4018. DRM_DEBUG("si_irq_set: sw int dma1\n");
  4019. dma_cntl1 |= TRAP_ENABLE;
  4020. }
  4021. if (rdev->irq.crtc_vblank_int[0] ||
  4022. atomic_read(&rdev->irq.pflip[0])) {
  4023. DRM_DEBUG("si_irq_set: vblank 0\n");
  4024. crtc1 |= VBLANK_INT_MASK;
  4025. }
  4026. if (rdev->irq.crtc_vblank_int[1] ||
  4027. atomic_read(&rdev->irq.pflip[1])) {
  4028. DRM_DEBUG("si_irq_set: vblank 1\n");
  4029. crtc2 |= VBLANK_INT_MASK;
  4030. }
  4031. if (rdev->irq.crtc_vblank_int[2] ||
  4032. atomic_read(&rdev->irq.pflip[2])) {
  4033. DRM_DEBUG("si_irq_set: vblank 2\n");
  4034. crtc3 |= VBLANK_INT_MASK;
  4035. }
  4036. if (rdev->irq.crtc_vblank_int[3] ||
  4037. atomic_read(&rdev->irq.pflip[3])) {
  4038. DRM_DEBUG("si_irq_set: vblank 3\n");
  4039. crtc4 |= VBLANK_INT_MASK;
  4040. }
  4041. if (rdev->irq.crtc_vblank_int[4] ||
  4042. atomic_read(&rdev->irq.pflip[4])) {
  4043. DRM_DEBUG("si_irq_set: vblank 4\n");
  4044. crtc5 |= VBLANK_INT_MASK;
  4045. }
  4046. if (rdev->irq.crtc_vblank_int[5] ||
  4047. atomic_read(&rdev->irq.pflip[5])) {
  4048. DRM_DEBUG("si_irq_set: vblank 5\n");
  4049. crtc6 |= VBLANK_INT_MASK;
  4050. }
  4051. if (rdev->irq.hpd[0]) {
  4052. DRM_DEBUG("si_irq_set: hpd 1\n");
  4053. hpd1 |= DC_HPDx_INT_EN;
  4054. }
  4055. if (rdev->irq.hpd[1]) {
  4056. DRM_DEBUG("si_irq_set: hpd 2\n");
  4057. hpd2 |= DC_HPDx_INT_EN;
  4058. }
  4059. if (rdev->irq.hpd[2]) {
  4060. DRM_DEBUG("si_irq_set: hpd 3\n");
  4061. hpd3 |= DC_HPDx_INT_EN;
  4062. }
  4063. if (rdev->irq.hpd[3]) {
  4064. DRM_DEBUG("si_irq_set: hpd 4\n");
  4065. hpd4 |= DC_HPDx_INT_EN;
  4066. }
  4067. if (rdev->irq.hpd[4]) {
  4068. DRM_DEBUG("si_irq_set: hpd 5\n");
  4069. hpd5 |= DC_HPDx_INT_EN;
  4070. }
  4071. if (rdev->irq.hpd[5]) {
  4072. DRM_DEBUG("si_irq_set: hpd 6\n");
  4073. hpd6 |= DC_HPDx_INT_EN;
  4074. }
  4075. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  4076. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  4077. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  4078. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  4079. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  4080. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4081. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4082. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4083. if (rdev->num_crtc >= 4) {
  4084. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4085. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4086. }
  4087. if (rdev->num_crtc >= 6) {
  4088. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4089. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4090. }
  4091. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  4092. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  4093. if (rdev->num_crtc >= 4) {
  4094. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  4095. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  4096. }
  4097. if (rdev->num_crtc >= 6) {
  4098. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  4099. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  4100. }
  4101. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4102. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4103. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4104. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4105. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4106. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4107. return 0;
  4108. }
  4109. static inline void si_irq_ack(struct radeon_device *rdev)
  4110. {
  4111. u32 tmp;
  4112. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4113. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4114. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4115. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4116. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4117. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4118. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4119. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4120. if (rdev->num_crtc >= 4) {
  4121. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4122. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4123. }
  4124. if (rdev->num_crtc >= 6) {
  4125. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4126. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4127. }
  4128. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4129. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4130. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4131. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4132. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4133. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4134. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4135. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4136. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4137. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4138. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4139. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4140. if (rdev->num_crtc >= 4) {
  4141. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4142. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4143. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4144. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4145. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4146. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4147. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4148. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4149. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4150. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4151. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4152. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4153. }
  4154. if (rdev->num_crtc >= 6) {
  4155. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4156. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4157. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4158. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4159. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4160. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4161. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4162. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4163. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4164. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4165. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4166. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4167. }
  4168. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4169. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4170. tmp |= DC_HPDx_INT_ACK;
  4171. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4172. }
  4173. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4174. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4175. tmp |= DC_HPDx_INT_ACK;
  4176. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4177. }
  4178. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4179. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4180. tmp |= DC_HPDx_INT_ACK;
  4181. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4182. }
  4183. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4184. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4185. tmp |= DC_HPDx_INT_ACK;
  4186. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4187. }
  4188. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4189. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4190. tmp |= DC_HPDx_INT_ACK;
  4191. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4192. }
  4193. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4194. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4195. tmp |= DC_HPDx_INT_ACK;
  4196. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4197. }
  4198. }
  4199. static void si_irq_disable(struct radeon_device *rdev)
  4200. {
  4201. si_disable_interrupts(rdev);
  4202. /* Wait and acknowledge irq */
  4203. mdelay(1);
  4204. si_irq_ack(rdev);
  4205. si_disable_interrupt_state(rdev);
  4206. }
  4207. static void si_irq_suspend(struct radeon_device *rdev)
  4208. {
  4209. si_irq_disable(rdev);
  4210. si_rlc_stop(rdev);
  4211. }
  4212. static void si_irq_fini(struct radeon_device *rdev)
  4213. {
  4214. si_irq_suspend(rdev);
  4215. r600_ih_ring_fini(rdev);
  4216. }
  4217. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  4218. {
  4219. u32 wptr, tmp;
  4220. if (rdev->wb.enabled)
  4221. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4222. else
  4223. wptr = RREG32(IH_RB_WPTR);
  4224. if (wptr & RB_OVERFLOW) {
  4225. /* When a ring buffer overflow happen start parsing interrupt
  4226. * from the last not overwritten vector (wptr + 16). Hopefully
  4227. * this should allow us to catchup.
  4228. */
  4229. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  4230. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  4231. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4232. tmp = RREG32(IH_RB_CNTL);
  4233. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4234. WREG32(IH_RB_CNTL, tmp);
  4235. }
  4236. return (wptr & rdev->ih.ptr_mask);
  4237. }
  4238. /* SI IV Ring
  4239. * Each IV ring entry is 128 bits:
  4240. * [7:0] - interrupt source id
  4241. * [31:8] - reserved
  4242. * [59:32] - interrupt source data
  4243. * [63:60] - reserved
  4244. * [71:64] - RINGID
  4245. * [79:72] - VMID
  4246. * [127:80] - reserved
  4247. */
  4248. int si_irq_process(struct radeon_device *rdev)
  4249. {
  4250. u32 wptr;
  4251. u32 rptr;
  4252. u32 src_id, src_data, ring_id;
  4253. u32 ring_index;
  4254. bool queue_hotplug = false;
  4255. if (!rdev->ih.enabled || rdev->shutdown)
  4256. return IRQ_NONE;
  4257. wptr = si_get_ih_wptr(rdev);
  4258. restart_ih:
  4259. /* is somebody else already processing irqs? */
  4260. if (atomic_xchg(&rdev->ih.lock, 1))
  4261. return IRQ_NONE;
  4262. rptr = rdev->ih.rptr;
  4263. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4264. /* Order reading of wptr vs. reading of IH ring data */
  4265. rmb();
  4266. /* display interrupts */
  4267. si_irq_ack(rdev);
  4268. while (rptr != wptr) {
  4269. /* wptr/rptr are in bytes! */
  4270. ring_index = rptr / 4;
  4271. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4272. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4273. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  4274. switch (src_id) {
  4275. case 1: /* D1 vblank/vline */
  4276. switch (src_data) {
  4277. case 0: /* D1 vblank */
  4278. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  4279. if (rdev->irq.crtc_vblank_int[0]) {
  4280. drm_handle_vblank(rdev->ddev, 0);
  4281. rdev->pm.vblank_sync = true;
  4282. wake_up(&rdev->irq.vblank_queue);
  4283. }
  4284. if (atomic_read(&rdev->irq.pflip[0]))
  4285. radeon_crtc_handle_flip(rdev, 0);
  4286. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4287. DRM_DEBUG("IH: D1 vblank\n");
  4288. }
  4289. break;
  4290. case 1: /* D1 vline */
  4291. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  4292. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4293. DRM_DEBUG("IH: D1 vline\n");
  4294. }
  4295. break;
  4296. default:
  4297. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4298. break;
  4299. }
  4300. break;
  4301. case 2: /* D2 vblank/vline */
  4302. switch (src_data) {
  4303. case 0: /* D2 vblank */
  4304. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  4305. if (rdev->irq.crtc_vblank_int[1]) {
  4306. drm_handle_vblank(rdev->ddev, 1);
  4307. rdev->pm.vblank_sync = true;
  4308. wake_up(&rdev->irq.vblank_queue);
  4309. }
  4310. if (atomic_read(&rdev->irq.pflip[1]))
  4311. radeon_crtc_handle_flip(rdev, 1);
  4312. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4313. DRM_DEBUG("IH: D2 vblank\n");
  4314. }
  4315. break;
  4316. case 1: /* D2 vline */
  4317. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  4318. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4319. DRM_DEBUG("IH: D2 vline\n");
  4320. }
  4321. break;
  4322. default:
  4323. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4324. break;
  4325. }
  4326. break;
  4327. case 3: /* D3 vblank/vline */
  4328. switch (src_data) {
  4329. case 0: /* D3 vblank */
  4330. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  4331. if (rdev->irq.crtc_vblank_int[2]) {
  4332. drm_handle_vblank(rdev->ddev, 2);
  4333. rdev->pm.vblank_sync = true;
  4334. wake_up(&rdev->irq.vblank_queue);
  4335. }
  4336. if (atomic_read(&rdev->irq.pflip[2]))
  4337. radeon_crtc_handle_flip(rdev, 2);
  4338. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4339. DRM_DEBUG("IH: D3 vblank\n");
  4340. }
  4341. break;
  4342. case 1: /* D3 vline */
  4343. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  4344. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4345. DRM_DEBUG("IH: D3 vline\n");
  4346. }
  4347. break;
  4348. default:
  4349. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4350. break;
  4351. }
  4352. break;
  4353. case 4: /* D4 vblank/vline */
  4354. switch (src_data) {
  4355. case 0: /* D4 vblank */
  4356. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  4357. if (rdev->irq.crtc_vblank_int[3]) {
  4358. drm_handle_vblank(rdev->ddev, 3);
  4359. rdev->pm.vblank_sync = true;
  4360. wake_up(&rdev->irq.vblank_queue);
  4361. }
  4362. if (atomic_read(&rdev->irq.pflip[3]))
  4363. radeon_crtc_handle_flip(rdev, 3);
  4364. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4365. DRM_DEBUG("IH: D4 vblank\n");
  4366. }
  4367. break;
  4368. case 1: /* D4 vline */
  4369. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  4370. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4371. DRM_DEBUG("IH: D4 vline\n");
  4372. }
  4373. break;
  4374. default:
  4375. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4376. break;
  4377. }
  4378. break;
  4379. case 5: /* D5 vblank/vline */
  4380. switch (src_data) {
  4381. case 0: /* D5 vblank */
  4382. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  4383. if (rdev->irq.crtc_vblank_int[4]) {
  4384. drm_handle_vblank(rdev->ddev, 4);
  4385. rdev->pm.vblank_sync = true;
  4386. wake_up(&rdev->irq.vblank_queue);
  4387. }
  4388. if (atomic_read(&rdev->irq.pflip[4]))
  4389. radeon_crtc_handle_flip(rdev, 4);
  4390. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4391. DRM_DEBUG("IH: D5 vblank\n");
  4392. }
  4393. break;
  4394. case 1: /* D5 vline */
  4395. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  4396. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4397. DRM_DEBUG("IH: D5 vline\n");
  4398. }
  4399. break;
  4400. default:
  4401. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4402. break;
  4403. }
  4404. break;
  4405. case 6: /* D6 vblank/vline */
  4406. switch (src_data) {
  4407. case 0: /* D6 vblank */
  4408. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  4409. if (rdev->irq.crtc_vblank_int[5]) {
  4410. drm_handle_vblank(rdev->ddev, 5);
  4411. rdev->pm.vblank_sync = true;
  4412. wake_up(&rdev->irq.vblank_queue);
  4413. }
  4414. if (atomic_read(&rdev->irq.pflip[5]))
  4415. radeon_crtc_handle_flip(rdev, 5);
  4416. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4417. DRM_DEBUG("IH: D6 vblank\n");
  4418. }
  4419. break;
  4420. case 1: /* D6 vline */
  4421. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  4422. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4423. DRM_DEBUG("IH: D6 vline\n");
  4424. }
  4425. break;
  4426. default:
  4427. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4428. break;
  4429. }
  4430. break;
  4431. case 42: /* HPD hotplug */
  4432. switch (src_data) {
  4433. case 0:
  4434. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4435. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4436. queue_hotplug = true;
  4437. DRM_DEBUG("IH: HPD1\n");
  4438. }
  4439. break;
  4440. case 1:
  4441. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4442. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4443. queue_hotplug = true;
  4444. DRM_DEBUG("IH: HPD2\n");
  4445. }
  4446. break;
  4447. case 2:
  4448. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4449. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4450. queue_hotplug = true;
  4451. DRM_DEBUG("IH: HPD3\n");
  4452. }
  4453. break;
  4454. case 3:
  4455. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4456. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4457. queue_hotplug = true;
  4458. DRM_DEBUG("IH: HPD4\n");
  4459. }
  4460. break;
  4461. case 4:
  4462. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4463. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4464. queue_hotplug = true;
  4465. DRM_DEBUG("IH: HPD5\n");
  4466. }
  4467. break;
  4468. case 5:
  4469. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4470. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4471. queue_hotplug = true;
  4472. DRM_DEBUG("IH: HPD6\n");
  4473. }
  4474. break;
  4475. default:
  4476. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4477. break;
  4478. }
  4479. break;
  4480. case 146:
  4481. case 147:
  4482. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4483. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4484. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  4485. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4486. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  4487. /* reset addr and status */
  4488. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4489. break;
  4490. case 176: /* RINGID0 CP_INT */
  4491. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4492. break;
  4493. case 177: /* RINGID1 CP_INT */
  4494. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4495. break;
  4496. case 178: /* RINGID2 CP_INT */
  4497. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4498. break;
  4499. case 181: /* CP EOP event */
  4500. DRM_DEBUG("IH: CP EOP\n");
  4501. switch (ring_id) {
  4502. case 0:
  4503. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4504. break;
  4505. case 1:
  4506. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4507. break;
  4508. case 2:
  4509. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4510. break;
  4511. }
  4512. break;
  4513. case 224: /* DMA trap event */
  4514. DRM_DEBUG("IH: DMA trap\n");
  4515. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4516. break;
  4517. case 233: /* GUI IDLE */
  4518. DRM_DEBUG("IH: GUI idle\n");
  4519. break;
  4520. case 244: /* DMA trap event */
  4521. DRM_DEBUG("IH: DMA1 trap\n");
  4522. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4523. break;
  4524. default:
  4525. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4526. break;
  4527. }
  4528. /* wptr/rptr are in bytes! */
  4529. rptr += 16;
  4530. rptr &= rdev->ih.ptr_mask;
  4531. }
  4532. if (queue_hotplug)
  4533. schedule_work(&rdev->hotplug_work);
  4534. rdev->ih.rptr = rptr;
  4535. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  4536. atomic_set(&rdev->ih.lock, 0);
  4537. /* make sure wptr hasn't changed while processing */
  4538. wptr = si_get_ih_wptr(rdev);
  4539. if (wptr != rptr)
  4540. goto restart_ih;
  4541. return IRQ_HANDLED;
  4542. }
  4543. /**
  4544. * si_copy_dma - copy pages using the DMA engine
  4545. *
  4546. * @rdev: radeon_device pointer
  4547. * @src_offset: src GPU address
  4548. * @dst_offset: dst GPU address
  4549. * @num_gpu_pages: number of GPU pages to xfer
  4550. * @fence: radeon fence object
  4551. *
  4552. * Copy GPU paging using the DMA engine (SI).
  4553. * Used by the radeon ttm implementation to move pages if
  4554. * registered as the asic copy callback.
  4555. */
  4556. int si_copy_dma(struct radeon_device *rdev,
  4557. uint64_t src_offset, uint64_t dst_offset,
  4558. unsigned num_gpu_pages,
  4559. struct radeon_fence **fence)
  4560. {
  4561. struct radeon_semaphore *sem = NULL;
  4562. int ring_index = rdev->asic->copy.dma_ring_index;
  4563. struct radeon_ring *ring = &rdev->ring[ring_index];
  4564. u32 size_in_bytes, cur_size_in_bytes;
  4565. int i, num_loops;
  4566. int r = 0;
  4567. r = radeon_semaphore_create(rdev, &sem);
  4568. if (r) {
  4569. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4570. return r;
  4571. }
  4572. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  4573. num_loops = DIV_ROUND_UP(size_in_bytes, 0xfffff);
  4574. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
  4575. if (r) {
  4576. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4577. radeon_semaphore_free(rdev, &sem, NULL);
  4578. return r;
  4579. }
  4580. if (radeon_fence_need_sync(*fence, ring->idx)) {
  4581. radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
  4582. ring->idx);
  4583. radeon_fence_note_sync(*fence, ring->idx);
  4584. } else {
  4585. radeon_semaphore_free(rdev, &sem, NULL);
  4586. }
  4587. for (i = 0; i < num_loops; i++) {
  4588. cur_size_in_bytes = size_in_bytes;
  4589. if (cur_size_in_bytes > 0xFFFFF)
  4590. cur_size_in_bytes = 0xFFFFF;
  4591. size_in_bytes -= cur_size_in_bytes;
  4592. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 1, 0, 0, cur_size_in_bytes));
  4593. radeon_ring_write(ring, dst_offset & 0xffffffff);
  4594. radeon_ring_write(ring, src_offset & 0xffffffff);
  4595. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  4596. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  4597. src_offset += cur_size_in_bytes;
  4598. dst_offset += cur_size_in_bytes;
  4599. }
  4600. r = radeon_fence_emit(rdev, fence, ring->idx);
  4601. if (r) {
  4602. radeon_ring_unlock_undo(rdev, ring);
  4603. return r;
  4604. }
  4605. radeon_ring_unlock_commit(rdev, ring);
  4606. radeon_semaphore_free(rdev, &sem, *fence);
  4607. return r;
  4608. }
  4609. /*
  4610. * startup/shutdown callbacks
  4611. */
  4612. static int si_startup(struct radeon_device *rdev)
  4613. {
  4614. struct radeon_ring *ring;
  4615. int r;
  4616. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  4617. !rdev->rlc_fw || !rdev->mc_fw) {
  4618. r = si_init_microcode(rdev);
  4619. if (r) {
  4620. DRM_ERROR("Failed to load firmware!\n");
  4621. return r;
  4622. }
  4623. }
  4624. r = si_mc_load_microcode(rdev);
  4625. if (r) {
  4626. DRM_ERROR("Failed to load MC firmware!\n");
  4627. return r;
  4628. }
  4629. r = r600_vram_scratch_init(rdev);
  4630. if (r)
  4631. return r;
  4632. si_mc_program(rdev);
  4633. r = si_pcie_gart_enable(rdev);
  4634. if (r)
  4635. return r;
  4636. si_gpu_init(rdev);
  4637. /* allocate rlc buffers */
  4638. r = si_rlc_init(rdev);
  4639. if (r) {
  4640. DRM_ERROR("Failed to init rlc BOs!\n");
  4641. return r;
  4642. }
  4643. /* allocate wb buffer */
  4644. r = radeon_wb_init(rdev);
  4645. if (r)
  4646. return r;
  4647. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4648. if (r) {
  4649. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4650. return r;
  4651. }
  4652. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4653. if (r) {
  4654. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4655. return r;
  4656. }
  4657. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4658. if (r) {
  4659. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4660. return r;
  4661. }
  4662. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  4663. if (r) {
  4664. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4665. return r;
  4666. }
  4667. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4668. if (r) {
  4669. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4670. return r;
  4671. }
  4672. r = rv770_uvd_resume(rdev);
  4673. if (!r) {
  4674. r = radeon_fence_driver_start_ring(rdev,
  4675. R600_RING_TYPE_UVD_INDEX);
  4676. if (r)
  4677. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  4678. }
  4679. if (r)
  4680. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  4681. /* Enable IRQ */
  4682. r = si_irq_init(rdev);
  4683. if (r) {
  4684. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  4685. radeon_irq_kms_fini(rdev);
  4686. return r;
  4687. }
  4688. si_irq_set(rdev);
  4689. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4690. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  4691. CP_RB0_RPTR, CP_RB0_WPTR,
  4692. 0, 0xfffff, RADEON_CP_PACKET2);
  4693. if (r)
  4694. return r;
  4695. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  4696. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  4697. CP_RB1_RPTR, CP_RB1_WPTR,
  4698. 0, 0xfffff, RADEON_CP_PACKET2);
  4699. if (r)
  4700. return r;
  4701. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  4702. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  4703. CP_RB2_RPTR, CP_RB2_WPTR,
  4704. 0, 0xfffff, RADEON_CP_PACKET2);
  4705. if (r)
  4706. return r;
  4707. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4708. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  4709. DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
  4710. DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
  4711. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  4712. if (r)
  4713. return r;
  4714. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  4715. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  4716. DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
  4717. DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
  4718. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  4719. if (r)
  4720. return r;
  4721. r = si_cp_load_microcode(rdev);
  4722. if (r)
  4723. return r;
  4724. r = si_cp_resume(rdev);
  4725. if (r)
  4726. return r;
  4727. r = cayman_dma_resume(rdev);
  4728. if (r)
  4729. return r;
  4730. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4731. if (ring->ring_size) {
  4732. r = radeon_ring_init(rdev, ring, ring->ring_size,
  4733. R600_WB_UVD_RPTR_OFFSET,
  4734. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  4735. 0, 0xfffff, RADEON_CP_PACKET2);
  4736. if (!r)
  4737. r = r600_uvd_init(rdev);
  4738. if (r)
  4739. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  4740. }
  4741. r = radeon_ib_pool_init(rdev);
  4742. if (r) {
  4743. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  4744. return r;
  4745. }
  4746. r = radeon_vm_manager_init(rdev);
  4747. if (r) {
  4748. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  4749. return r;
  4750. }
  4751. return 0;
  4752. }
  4753. int si_resume(struct radeon_device *rdev)
  4754. {
  4755. int r;
  4756. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  4757. * posting will perform necessary task to bring back GPU into good
  4758. * shape.
  4759. */
  4760. /* post card */
  4761. atom_asic_init(rdev->mode_info.atom_context);
  4762. /* init golden registers */
  4763. si_init_golden_registers(rdev);
  4764. rdev->accel_working = true;
  4765. r = si_startup(rdev);
  4766. if (r) {
  4767. DRM_ERROR("si startup failed on resume\n");
  4768. rdev->accel_working = false;
  4769. return r;
  4770. }
  4771. return r;
  4772. }
  4773. int si_suspend(struct radeon_device *rdev)
  4774. {
  4775. radeon_vm_manager_fini(rdev);
  4776. si_cp_enable(rdev, false);
  4777. cayman_dma_stop(rdev);
  4778. r600_uvd_rbc_stop(rdev);
  4779. radeon_uvd_suspend(rdev);
  4780. si_irq_suspend(rdev);
  4781. radeon_wb_disable(rdev);
  4782. si_pcie_gart_disable(rdev);
  4783. return 0;
  4784. }
  4785. /* Plan is to move initialization in that function and use
  4786. * helper function so that radeon_device_init pretty much
  4787. * do nothing more than calling asic specific function. This
  4788. * should also allow to remove a bunch of callback function
  4789. * like vram_info.
  4790. */
  4791. int si_init(struct radeon_device *rdev)
  4792. {
  4793. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4794. int r;
  4795. /* Read BIOS */
  4796. if (!radeon_get_bios(rdev)) {
  4797. if (ASIC_IS_AVIVO(rdev))
  4798. return -EINVAL;
  4799. }
  4800. /* Must be an ATOMBIOS */
  4801. if (!rdev->is_atom_bios) {
  4802. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  4803. return -EINVAL;
  4804. }
  4805. r = radeon_atombios_init(rdev);
  4806. if (r)
  4807. return r;
  4808. /* Post card if necessary */
  4809. if (!radeon_card_posted(rdev)) {
  4810. if (!rdev->bios) {
  4811. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  4812. return -EINVAL;
  4813. }
  4814. DRM_INFO("GPU not posted. posting now...\n");
  4815. atom_asic_init(rdev->mode_info.atom_context);
  4816. }
  4817. /* init golden registers */
  4818. si_init_golden_registers(rdev);
  4819. /* Initialize scratch registers */
  4820. si_scratch_init(rdev);
  4821. /* Initialize surface registers */
  4822. radeon_surface_init(rdev);
  4823. /* Initialize clocks */
  4824. radeon_get_clock_info(rdev->ddev);
  4825. /* Fence driver */
  4826. r = radeon_fence_driver_init(rdev);
  4827. if (r)
  4828. return r;
  4829. /* initialize memory controller */
  4830. r = si_mc_init(rdev);
  4831. if (r)
  4832. return r;
  4833. /* Memory manager */
  4834. r = radeon_bo_init(rdev);
  4835. if (r)
  4836. return r;
  4837. r = radeon_irq_kms_init(rdev);
  4838. if (r)
  4839. return r;
  4840. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4841. ring->ring_obj = NULL;
  4842. r600_ring_init(rdev, ring, 1024 * 1024);
  4843. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  4844. ring->ring_obj = NULL;
  4845. r600_ring_init(rdev, ring, 1024 * 1024);
  4846. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  4847. ring->ring_obj = NULL;
  4848. r600_ring_init(rdev, ring, 1024 * 1024);
  4849. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4850. ring->ring_obj = NULL;
  4851. r600_ring_init(rdev, ring, 64 * 1024);
  4852. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  4853. ring->ring_obj = NULL;
  4854. r600_ring_init(rdev, ring, 64 * 1024);
  4855. r = radeon_uvd_init(rdev);
  4856. if (!r) {
  4857. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4858. ring->ring_obj = NULL;
  4859. r600_ring_init(rdev, ring, 4096);
  4860. }
  4861. rdev->ih.ring_obj = NULL;
  4862. r600_ih_ring_init(rdev, 64 * 1024);
  4863. r = r600_pcie_gart_init(rdev);
  4864. if (r)
  4865. return r;
  4866. rdev->accel_working = true;
  4867. r = si_startup(rdev);
  4868. if (r) {
  4869. dev_err(rdev->dev, "disabling GPU acceleration\n");
  4870. si_cp_fini(rdev);
  4871. cayman_dma_fini(rdev);
  4872. si_irq_fini(rdev);
  4873. si_rlc_fini(rdev);
  4874. radeon_wb_fini(rdev);
  4875. radeon_ib_pool_fini(rdev);
  4876. radeon_vm_manager_fini(rdev);
  4877. radeon_irq_kms_fini(rdev);
  4878. si_pcie_gart_fini(rdev);
  4879. rdev->accel_working = false;
  4880. }
  4881. /* Don't start up if the MC ucode is missing.
  4882. * The default clocks and voltages before the MC ucode
  4883. * is loaded are not suffient for advanced operations.
  4884. */
  4885. if (!rdev->mc_fw) {
  4886. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  4887. return -EINVAL;
  4888. }
  4889. return 0;
  4890. }
  4891. void si_fini(struct radeon_device *rdev)
  4892. {
  4893. si_cp_fini(rdev);
  4894. cayman_dma_fini(rdev);
  4895. si_irq_fini(rdev);
  4896. si_rlc_fini(rdev);
  4897. radeon_wb_fini(rdev);
  4898. radeon_vm_manager_fini(rdev);
  4899. radeon_ib_pool_fini(rdev);
  4900. radeon_irq_kms_fini(rdev);
  4901. radeon_uvd_fini(rdev);
  4902. si_pcie_gart_fini(rdev);
  4903. r600_vram_scratch_fini(rdev);
  4904. radeon_gem_fini(rdev);
  4905. radeon_fence_driver_fini(rdev);
  4906. radeon_bo_fini(rdev);
  4907. radeon_atombios_fini(rdev);
  4908. kfree(rdev->bios);
  4909. rdev->bios = NULL;
  4910. }
  4911. /**
  4912. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  4913. *
  4914. * @rdev: radeon_device pointer
  4915. *
  4916. * Fetches a GPU clock counter snapshot (SI).
  4917. * Returns the 64 bit clock counter snapshot.
  4918. */
  4919. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  4920. {
  4921. uint64_t clock;
  4922. mutex_lock(&rdev->gpu_clock_mutex);
  4923. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  4924. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  4925. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  4926. mutex_unlock(&rdev->gpu_clock_mutex);
  4927. return clock;
  4928. }
  4929. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  4930. {
  4931. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  4932. int r;
  4933. /* bypass vclk and dclk with bclk */
  4934. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  4935. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  4936. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  4937. /* put PLL in bypass mode */
  4938. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  4939. if (!vclk || !dclk) {
  4940. /* keep the Bypass mode, put PLL to sleep */
  4941. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  4942. return 0;
  4943. }
  4944. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  4945. 16384, 0x03FFFFFF, 0, 128, 5,
  4946. &fb_div, &vclk_div, &dclk_div);
  4947. if (r)
  4948. return r;
  4949. /* set RESET_ANTI_MUX to 0 */
  4950. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  4951. /* set VCO_MODE to 1 */
  4952. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  4953. /* toggle UPLL_SLEEP to 1 then back to 0 */
  4954. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  4955. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  4956. /* deassert UPLL_RESET */
  4957. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  4958. mdelay(1);
  4959. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  4960. if (r)
  4961. return r;
  4962. /* assert UPLL_RESET again */
  4963. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  4964. /* disable spread spectrum. */
  4965. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  4966. /* set feedback divider */
  4967. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  4968. /* set ref divider to 0 */
  4969. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  4970. if (fb_div < 307200)
  4971. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  4972. else
  4973. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  4974. /* set PDIV_A and PDIV_B */
  4975. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  4976. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  4977. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  4978. /* give the PLL some time to settle */
  4979. mdelay(15);
  4980. /* deassert PLL_RESET */
  4981. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  4982. mdelay(15);
  4983. /* switch from bypass mode to normal mode */
  4984. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  4985. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  4986. if (r)
  4987. return r;
  4988. /* switch VCLK and DCLK selection */
  4989. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  4990. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  4991. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  4992. mdelay(100);
  4993. return 0;
  4994. }