si.c 201 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189
  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/slab.h>
  26. #include <linux/module.h>
  27. #include <drm/drmP.h>
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include <drm/radeon_drm.h>
  31. #include "sid.h"
  32. #include "atom.h"
  33. #include "si_blit_shaders.h"
  34. #include "clearstate_si.h"
  35. #include "radeon_ucode.h"
  36. MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
  37. MODULE_FIRMWARE("radeon/TAHITI_me.bin");
  38. MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
  39. MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
  40. MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
  41. MODULE_FIRMWARE("radeon/TAHITI_smc.bin");
  42. MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
  43. MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
  44. MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
  45. MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
  46. MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
  47. MODULE_FIRMWARE("radeon/PITCAIRN_smc.bin");
  48. MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
  49. MODULE_FIRMWARE("radeon/VERDE_me.bin");
  50. MODULE_FIRMWARE("radeon/VERDE_ce.bin");
  51. MODULE_FIRMWARE("radeon/VERDE_mc.bin");
  52. MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
  53. MODULE_FIRMWARE("radeon/VERDE_smc.bin");
  54. MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
  55. MODULE_FIRMWARE("radeon/OLAND_me.bin");
  56. MODULE_FIRMWARE("radeon/OLAND_ce.bin");
  57. MODULE_FIRMWARE("radeon/OLAND_mc.bin");
  58. MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
  59. MODULE_FIRMWARE("radeon/OLAND_smc.bin");
  60. MODULE_FIRMWARE("radeon/HAINAN_pfp.bin");
  61. MODULE_FIRMWARE("radeon/HAINAN_me.bin");
  62. MODULE_FIRMWARE("radeon/HAINAN_ce.bin");
  63. MODULE_FIRMWARE("radeon/HAINAN_mc.bin");
  64. MODULE_FIRMWARE("radeon/HAINAN_rlc.bin");
  65. MODULE_FIRMWARE("radeon/HAINAN_smc.bin");
  66. static void si_pcie_gen3_enable(struct radeon_device *rdev);
  67. static void si_program_aspm(struct radeon_device *rdev);
  68. extern void sumo_rlc_fini(struct radeon_device *rdev);
  69. extern int sumo_rlc_init(struct radeon_device *rdev);
  70. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  71. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  72. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  73. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  74. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  75. extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
  76. extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
  77. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  78. extern void si_dma_vm_set_page(struct radeon_device *rdev,
  79. struct radeon_ib *ib,
  80. uint64_t pe,
  81. uint64_t addr, unsigned count,
  82. uint32_t incr, uint32_t flags);
  83. static const u32 verde_rlc_save_restore_register_list[] =
  84. {
  85. (0x8000 << 16) | (0x98f4 >> 2),
  86. 0x00000000,
  87. (0x8040 << 16) | (0x98f4 >> 2),
  88. 0x00000000,
  89. (0x8000 << 16) | (0xe80 >> 2),
  90. 0x00000000,
  91. (0x8040 << 16) | (0xe80 >> 2),
  92. 0x00000000,
  93. (0x8000 << 16) | (0x89bc >> 2),
  94. 0x00000000,
  95. (0x8040 << 16) | (0x89bc >> 2),
  96. 0x00000000,
  97. (0x8000 << 16) | (0x8c1c >> 2),
  98. 0x00000000,
  99. (0x8040 << 16) | (0x8c1c >> 2),
  100. 0x00000000,
  101. (0x9c00 << 16) | (0x98f0 >> 2),
  102. 0x00000000,
  103. (0x9c00 << 16) | (0xe7c >> 2),
  104. 0x00000000,
  105. (0x8000 << 16) | (0x9148 >> 2),
  106. 0x00000000,
  107. (0x8040 << 16) | (0x9148 >> 2),
  108. 0x00000000,
  109. (0x9c00 << 16) | (0x9150 >> 2),
  110. 0x00000000,
  111. (0x9c00 << 16) | (0x897c >> 2),
  112. 0x00000000,
  113. (0x9c00 << 16) | (0x8d8c >> 2),
  114. 0x00000000,
  115. (0x9c00 << 16) | (0xac54 >> 2),
  116. 0X00000000,
  117. 0x3,
  118. (0x9c00 << 16) | (0x98f8 >> 2),
  119. 0x00000000,
  120. (0x9c00 << 16) | (0x9910 >> 2),
  121. 0x00000000,
  122. (0x9c00 << 16) | (0x9914 >> 2),
  123. 0x00000000,
  124. (0x9c00 << 16) | (0x9918 >> 2),
  125. 0x00000000,
  126. (0x9c00 << 16) | (0x991c >> 2),
  127. 0x00000000,
  128. (0x9c00 << 16) | (0x9920 >> 2),
  129. 0x00000000,
  130. (0x9c00 << 16) | (0x9924 >> 2),
  131. 0x00000000,
  132. (0x9c00 << 16) | (0x9928 >> 2),
  133. 0x00000000,
  134. (0x9c00 << 16) | (0x992c >> 2),
  135. 0x00000000,
  136. (0x9c00 << 16) | (0x9930 >> 2),
  137. 0x00000000,
  138. (0x9c00 << 16) | (0x9934 >> 2),
  139. 0x00000000,
  140. (0x9c00 << 16) | (0x9938 >> 2),
  141. 0x00000000,
  142. (0x9c00 << 16) | (0x993c >> 2),
  143. 0x00000000,
  144. (0x9c00 << 16) | (0x9940 >> 2),
  145. 0x00000000,
  146. (0x9c00 << 16) | (0x9944 >> 2),
  147. 0x00000000,
  148. (0x9c00 << 16) | (0x9948 >> 2),
  149. 0x00000000,
  150. (0x9c00 << 16) | (0x994c >> 2),
  151. 0x00000000,
  152. (0x9c00 << 16) | (0x9950 >> 2),
  153. 0x00000000,
  154. (0x9c00 << 16) | (0x9954 >> 2),
  155. 0x00000000,
  156. (0x9c00 << 16) | (0x9958 >> 2),
  157. 0x00000000,
  158. (0x9c00 << 16) | (0x995c >> 2),
  159. 0x00000000,
  160. (0x9c00 << 16) | (0x9960 >> 2),
  161. 0x00000000,
  162. (0x9c00 << 16) | (0x9964 >> 2),
  163. 0x00000000,
  164. (0x9c00 << 16) | (0x9968 >> 2),
  165. 0x00000000,
  166. (0x9c00 << 16) | (0x996c >> 2),
  167. 0x00000000,
  168. (0x9c00 << 16) | (0x9970 >> 2),
  169. 0x00000000,
  170. (0x9c00 << 16) | (0x9974 >> 2),
  171. 0x00000000,
  172. (0x9c00 << 16) | (0x9978 >> 2),
  173. 0x00000000,
  174. (0x9c00 << 16) | (0x997c >> 2),
  175. 0x00000000,
  176. (0x9c00 << 16) | (0x9980 >> 2),
  177. 0x00000000,
  178. (0x9c00 << 16) | (0x9984 >> 2),
  179. 0x00000000,
  180. (0x9c00 << 16) | (0x9988 >> 2),
  181. 0x00000000,
  182. (0x9c00 << 16) | (0x998c >> 2),
  183. 0x00000000,
  184. (0x9c00 << 16) | (0x8c00 >> 2),
  185. 0x00000000,
  186. (0x9c00 << 16) | (0x8c14 >> 2),
  187. 0x00000000,
  188. (0x9c00 << 16) | (0x8c04 >> 2),
  189. 0x00000000,
  190. (0x9c00 << 16) | (0x8c08 >> 2),
  191. 0x00000000,
  192. (0x8000 << 16) | (0x9b7c >> 2),
  193. 0x00000000,
  194. (0x8040 << 16) | (0x9b7c >> 2),
  195. 0x00000000,
  196. (0x8000 << 16) | (0xe84 >> 2),
  197. 0x00000000,
  198. (0x8040 << 16) | (0xe84 >> 2),
  199. 0x00000000,
  200. (0x8000 << 16) | (0x89c0 >> 2),
  201. 0x00000000,
  202. (0x8040 << 16) | (0x89c0 >> 2),
  203. 0x00000000,
  204. (0x8000 << 16) | (0x914c >> 2),
  205. 0x00000000,
  206. (0x8040 << 16) | (0x914c >> 2),
  207. 0x00000000,
  208. (0x8000 << 16) | (0x8c20 >> 2),
  209. 0x00000000,
  210. (0x8040 << 16) | (0x8c20 >> 2),
  211. 0x00000000,
  212. (0x8000 << 16) | (0x9354 >> 2),
  213. 0x00000000,
  214. (0x8040 << 16) | (0x9354 >> 2),
  215. 0x00000000,
  216. (0x9c00 << 16) | (0x9060 >> 2),
  217. 0x00000000,
  218. (0x9c00 << 16) | (0x9364 >> 2),
  219. 0x00000000,
  220. (0x9c00 << 16) | (0x9100 >> 2),
  221. 0x00000000,
  222. (0x9c00 << 16) | (0x913c >> 2),
  223. 0x00000000,
  224. (0x8000 << 16) | (0x90e0 >> 2),
  225. 0x00000000,
  226. (0x8000 << 16) | (0x90e4 >> 2),
  227. 0x00000000,
  228. (0x8000 << 16) | (0x90e8 >> 2),
  229. 0x00000000,
  230. (0x8040 << 16) | (0x90e0 >> 2),
  231. 0x00000000,
  232. (0x8040 << 16) | (0x90e4 >> 2),
  233. 0x00000000,
  234. (0x8040 << 16) | (0x90e8 >> 2),
  235. 0x00000000,
  236. (0x9c00 << 16) | (0x8bcc >> 2),
  237. 0x00000000,
  238. (0x9c00 << 16) | (0x8b24 >> 2),
  239. 0x00000000,
  240. (0x9c00 << 16) | (0x88c4 >> 2),
  241. 0x00000000,
  242. (0x9c00 << 16) | (0x8e50 >> 2),
  243. 0x00000000,
  244. (0x9c00 << 16) | (0x8c0c >> 2),
  245. 0x00000000,
  246. (0x9c00 << 16) | (0x8e58 >> 2),
  247. 0x00000000,
  248. (0x9c00 << 16) | (0x8e5c >> 2),
  249. 0x00000000,
  250. (0x9c00 << 16) | (0x9508 >> 2),
  251. 0x00000000,
  252. (0x9c00 << 16) | (0x950c >> 2),
  253. 0x00000000,
  254. (0x9c00 << 16) | (0x9494 >> 2),
  255. 0x00000000,
  256. (0x9c00 << 16) | (0xac0c >> 2),
  257. 0x00000000,
  258. (0x9c00 << 16) | (0xac10 >> 2),
  259. 0x00000000,
  260. (0x9c00 << 16) | (0xac14 >> 2),
  261. 0x00000000,
  262. (0x9c00 << 16) | (0xae00 >> 2),
  263. 0x00000000,
  264. (0x9c00 << 16) | (0xac08 >> 2),
  265. 0x00000000,
  266. (0x9c00 << 16) | (0x88d4 >> 2),
  267. 0x00000000,
  268. (0x9c00 << 16) | (0x88c8 >> 2),
  269. 0x00000000,
  270. (0x9c00 << 16) | (0x88cc >> 2),
  271. 0x00000000,
  272. (0x9c00 << 16) | (0x89b0 >> 2),
  273. 0x00000000,
  274. (0x9c00 << 16) | (0x8b10 >> 2),
  275. 0x00000000,
  276. (0x9c00 << 16) | (0x8a14 >> 2),
  277. 0x00000000,
  278. (0x9c00 << 16) | (0x9830 >> 2),
  279. 0x00000000,
  280. (0x9c00 << 16) | (0x9834 >> 2),
  281. 0x00000000,
  282. (0x9c00 << 16) | (0x9838 >> 2),
  283. 0x00000000,
  284. (0x9c00 << 16) | (0x9a10 >> 2),
  285. 0x00000000,
  286. (0x8000 << 16) | (0x9870 >> 2),
  287. 0x00000000,
  288. (0x8000 << 16) | (0x9874 >> 2),
  289. 0x00000000,
  290. (0x8001 << 16) | (0x9870 >> 2),
  291. 0x00000000,
  292. (0x8001 << 16) | (0x9874 >> 2),
  293. 0x00000000,
  294. (0x8040 << 16) | (0x9870 >> 2),
  295. 0x00000000,
  296. (0x8040 << 16) | (0x9874 >> 2),
  297. 0x00000000,
  298. (0x8041 << 16) | (0x9870 >> 2),
  299. 0x00000000,
  300. (0x8041 << 16) | (0x9874 >> 2),
  301. 0x00000000,
  302. 0x00000000
  303. };
  304. static const u32 tahiti_golden_rlc_registers[] =
  305. {
  306. 0xc424, 0xffffffff, 0x00601005,
  307. 0xc47c, 0xffffffff, 0x10104040,
  308. 0xc488, 0xffffffff, 0x0100000a,
  309. 0xc314, 0xffffffff, 0x00000800,
  310. 0xc30c, 0xffffffff, 0x800000f4,
  311. 0xf4a8, 0xffffffff, 0x00000000
  312. };
  313. static const u32 tahiti_golden_registers[] =
  314. {
  315. 0x9a10, 0x00010000, 0x00018208,
  316. 0x9830, 0xffffffff, 0x00000000,
  317. 0x9834, 0xf00fffff, 0x00000400,
  318. 0x9838, 0x0002021c, 0x00020200,
  319. 0xc78, 0x00000080, 0x00000000,
  320. 0xd030, 0x000300c0, 0x00800040,
  321. 0xd830, 0x000300c0, 0x00800040,
  322. 0x5bb0, 0x000000f0, 0x00000070,
  323. 0x5bc0, 0x00200000, 0x50100000,
  324. 0x7030, 0x31000311, 0x00000011,
  325. 0x277c, 0x00000003, 0x000007ff,
  326. 0x240c, 0x000007ff, 0x00000000,
  327. 0x8a14, 0xf000001f, 0x00000007,
  328. 0x8b24, 0xffffffff, 0x00ffffff,
  329. 0x8b10, 0x0000ff0f, 0x00000000,
  330. 0x28a4c, 0x07ffffff, 0x4e000000,
  331. 0x28350, 0x3f3f3fff, 0x2a00126a,
  332. 0x30, 0x000000ff, 0x0040,
  333. 0x34, 0x00000040, 0x00004040,
  334. 0x9100, 0x07ffffff, 0x03000000,
  335. 0x8e88, 0x01ff1f3f, 0x00000000,
  336. 0x8e84, 0x01ff1f3f, 0x00000000,
  337. 0x9060, 0x0000007f, 0x00000020,
  338. 0x9508, 0x00010000, 0x00010000,
  339. 0xac14, 0x00000200, 0x000002fb,
  340. 0xac10, 0xffffffff, 0x0000543b,
  341. 0xac0c, 0xffffffff, 0xa9210876,
  342. 0x88d0, 0xffffffff, 0x000fff40,
  343. 0x88d4, 0x0000001f, 0x00000010,
  344. 0x1410, 0x20000000, 0x20fffed8,
  345. 0x15c0, 0x000c0fc0, 0x000c0400
  346. };
  347. static const u32 tahiti_golden_registers2[] =
  348. {
  349. 0xc64, 0x00000001, 0x00000001
  350. };
  351. static const u32 pitcairn_golden_rlc_registers[] =
  352. {
  353. 0xc424, 0xffffffff, 0x00601004,
  354. 0xc47c, 0xffffffff, 0x10102020,
  355. 0xc488, 0xffffffff, 0x01000020,
  356. 0xc314, 0xffffffff, 0x00000800,
  357. 0xc30c, 0xffffffff, 0x800000a4
  358. };
  359. static const u32 pitcairn_golden_registers[] =
  360. {
  361. 0x9a10, 0x00010000, 0x00018208,
  362. 0x9830, 0xffffffff, 0x00000000,
  363. 0x9834, 0xf00fffff, 0x00000400,
  364. 0x9838, 0x0002021c, 0x00020200,
  365. 0xc78, 0x00000080, 0x00000000,
  366. 0xd030, 0x000300c0, 0x00800040,
  367. 0xd830, 0x000300c0, 0x00800040,
  368. 0x5bb0, 0x000000f0, 0x00000070,
  369. 0x5bc0, 0x00200000, 0x50100000,
  370. 0x7030, 0x31000311, 0x00000011,
  371. 0x2ae4, 0x00073ffe, 0x000022a2,
  372. 0x240c, 0x000007ff, 0x00000000,
  373. 0x8a14, 0xf000001f, 0x00000007,
  374. 0x8b24, 0xffffffff, 0x00ffffff,
  375. 0x8b10, 0x0000ff0f, 0x00000000,
  376. 0x28a4c, 0x07ffffff, 0x4e000000,
  377. 0x28350, 0x3f3f3fff, 0x2a00126a,
  378. 0x30, 0x000000ff, 0x0040,
  379. 0x34, 0x00000040, 0x00004040,
  380. 0x9100, 0x07ffffff, 0x03000000,
  381. 0x9060, 0x0000007f, 0x00000020,
  382. 0x9508, 0x00010000, 0x00010000,
  383. 0xac14, 0x000003ff, 0x000000f7,
  384. 0xac10, 0xffffffff, 0x00000000,
  385. 0xac0c, 0xffffffff, 0x32761054,
  386. 0x88d4, 0x0000001f, 0x00000010,
  387. 0x15c0, 0x000c0fc0, 0x000c0400
  388. };
  389. static const u32 verde_golden_rlc_registers[] =
  390. {
  391. 0xc424, 0xffffffff, 0x033f1005,
  392. 0xc47c, 0xffffffff, 0x10808020,
  393. 0xc488, 0xffffffff, 0x00800008,
  394. 0xc314, 0xffffffff, 0x00001000,
  395. 0xc30c, 0xffffffff, 0x80010014
  396. };
  397. static const u32 verde_golden_registers[] =
  398. {
  399. 0x9a10, 0x00010000, 0x00018208,
  400. 0x9830, 0xffffffff, 0x00000000,
  401. 0x9834, 0xf00fffff, 0x00000400,
  402. 0x9838, 0x0002021c, 0x00020200,
  403. 0xc78, 0x00000080, 0x00000000,
  404. 0xd030, 0x000300c0, 0x00800040,
  405. 0xd030, 0x000300c0, 0x00800040,
  406. 0xd830, 0x000300c0, 0x00800040,
  407. 0xd830, 0x000300c0, 0x00800040,
  408. 0x5bb0, 0x000000f0, 0x00000070,
  409. 0x5bc0, 0x00200000, 0x50100000,
  410. 0x7030, 0x31000311, 0x00000011,
  411. 0x2ae4, 0x00073ffe, 0x000022a2,
  412. 0x2ae4, 0x00073ffe, 0x000022a2,
  413. 0x2ae4, 0x00073ffe, 0x000022a2,
  414. 0x240c, 0x000007ff, 0x00000000,
  415. 0x240c, 0x000007ff, 0x00000000,
  416. 0x240c, 0x000007ff, 0x00000000,
  417. 0x8a14, 0xf000001f, 0x00000007,
  418. 0x8a14, 0xf000001f, 0x00000007,
  419. 0x8a14, 0xf000001f, 0x00000007,
  420. 0x8b24, 0xffffffff, 0x00ffffff,
  421. 0x8b10, 0x0000ff0f, 0x00000000,
  422. 0x28a4c, 0x07ffffff, 0x4e000000,
  423. 0x28350, 0x3f3f3fff, 0x0000124a,
  424. 0x28350, 0x3f3f3fff, 0x0000124a,
  425. 0x28350, 0x3f3f3fff, 0x0000124a,
  426. 0x30, 0x000000ff, 0x0040,
  427. 0x34, 0x00000040, 0x00004040,
  428. 0x9100, 0x07ffffff, 0x03000000,
  429. 0x9100, 0x07ffffff, 0x03000000,
  430. 0x8e88, 0x01ff1f3f, 0x00000000,
  431. 0x8e88, 0x01ff1f3f, 0x00000000,
  432. 0x8e88, 0x01ff1f3f, 0x00000000,
  433. 0x8e84, 0x01ff1f3f, 0x00000000,
  434. 0x8e84, 0x01ff1f3f, 0x00000000,
  435. 0x8e84, 0x01ff1f3f, 0x00000000,
  436. 0x9060, 0x0000007f, 0x00000020,
  437. 0x9508, 0x00010000, 0x00010000,
  438. 0xac14, 0x000003ff, 0x00000003,
  439. 0xac14, 0x000003ff, 0x00000003,
  440. 0xac14, 0x000003ff, 0x00000003,
  441. 0xac10, 0xffffffff, 0x00000000,
  442. 0xac10, 0xffffffff, 0x00000000,
  443. 0xac10, 0xffffffff, 0x00000000,
  444. 0xac0c, 0xffffffff, 0x00001032,
  445. 0xac0c, 0xffffffff, 0x00001032,
  446. 0xac0c, 0xffffffff, 0x00001032,
  447. 0x88d4, 0x0000001f, 0x00000010,
  448. 0x88d4, 0x0000001f, 0x00000010,
  449. 0x88d4, 0x0000001f, 0x00000010,
  450. 0x15c0, 0x000c0fc0, 0x000c0400
  451. };
  452. static const u32 oland_golden_rlc_registers[] =
  453. {
  454. 0xc424, 0xffffffff, 0x00601005,
  455. 0xc47c, 0xffffffff, 0x10104040,
  456. 0xc488, 0xffffffff, 0x0100000a,
  457. 0xc314, 0xffffffff, 0x00000800,
  458. 0xc30c, 0xffffffff, 0x800000f4
  459. };
  460. static const u32 oland_golden_registers[] =
  461. {
  462. 0x9a10, 0x00010000, 0x00018208,
  463. 0x9830, 0xffffffff, 0x00000000,
  464. 0x9834, 0xf00fffff, 0x00000400,
  465. 0x9838, 0x0002021c, 0x00020200,
  466. 0xc78, 0x00000080, 0x00000000,
  467. 0xd030, 0x000300c0, 0x00800040,
  468. 0xd830, 0x000300c0, 0x00800040,
  469. 0x5bb0, 0x000000f0, 0x00000070,
  470. 0x5bc0, 0x00200000, 0x50100000,
  471. 0x7030, 0x31000311, 0x00000011,
  472. 0x2ae4, 0x00073ffe, 0x000022a2,
  473. 0x240c, 0x000007ff, 0x00000000,
  474. 0x8a14, 0xf000001f, 0x00000007,
  475. 0x8b24, 0xffffffff, 0x00ffffff,
  476. 0x8b10, 0x0000ff0f, 0x00000000,
  477. 0x28a4c, 0x07ffffff, 0x4e000000,
  478. 0x28350, 0x3f3f3fff, 0x00000082,
  479. 0x30, 0x000000ff, 0x0040,
  480. 0x34, 0x00000040, 0x00004040,
  481. 0x9100, 0x07ffffff, 0x03000000,
  482. 0x9060, 0x0000007f, 0x00000020,
  483. 0x9508, 0x00010000, 0x00010000,
  484. 0xac14, 0x000003ff, 0x000000f3,
  485. 0xac10, 0xffffffff, 0x00000000,
  486. 0xac0c, 0xffffffff, 0x00003210,
  487. 0x88d4, 0x0000001f, 0x00000010,
  488. 0x15c0, 0x000c0fc0, 0x000c0400
  489. };
  490. static const u32 hainan_golden_registers[] =
  491. {
  492. 0x9a10, 0x00010000, 0x00018208,
  493. 0x9830, 0xffffffff, 0x00000000,
  494. 0x9834, 0xf00fffff, 0x00000400,
  495. 0x9838, 0x0002021c, 0x00020200,
  496. 0xd0c0, 0xff000fff, 0x00000100,
  497. 0xd030, 0x000300c0, 0x00800040,
  498. 0xd8c0, 0xff000fff, 0x00000100,
  499. 0xd830, 0x000300c0, 0x00800040,
  500. 0x2ae4, 0x00073ffe, 0x000022a2,
  501. 0x240c, 0x000007ff, 0x00000000,
  502. 0x8a14, 0xf000001f, 0x00000007,
  503. 0x8b24, 0xffffffff, 0x00ffffff,
  504. 0x8b10, 0x0000ff0f, 0x00000000,
  505. 0x28a4c, 0x07ffffff, 0x4e000000,
  506. 0x28350, 0x3f3f3fff, 0x00000000,
  507. 0x30, 0x000000ff, 0x0040,
  508. 0x34, 0x00000040, 0x00004040,
  509. 0x9100, 0x03e00000, 0x03600000,
  510. 0x9060, 0x0000007f, 0x00000020,
  511. 0x9508, 0x00010000, 0x00010000,
  512. 0xac14, 0x000003ff, 0x000000f1,
  513. 0xac10, 0xffffffff, 0x00000000,
  514. 0xac0c, 0xffffffff, 0x00003210,
  515. 0x88d4, 0x0000001f, 0x00000010,
  516. 0x15c0, 0x000c0fc0, 0x000c0400
  517. };
  518. static const u32 hainan_golden_registers2[] =
  519. {
  520. 0x98f8, 0xffffffff, 0x02010001
  521. };
  522. static const u32 tahiti_mgcg_cgcg_init[] =
  523. {
  524. 0xc400, 0xffffffff, 0xfffffffc,
  525. 0x802c, 0xffffffff, 0xe0000000,
  526. 0x9a60, 0xffffffff, 0x00000100,
  527. 0x92a4, 0xffffffff, 0x00000100,
  528. 0xc164, 0xffffffff, 0x00000100,
  529. 0x9774, 0xffffffff, 0x00000100,
  530. 0x8984, 0xffffffff, 0x06000100,
  531. 0x8a18, 0xffffffff, 0x00000100,
  532. 0x92a0, 0xffffffff, 0x00000100,
  533. 0xc380, 0xffffffff, 0x00000100,
  534. 0x8b28, 0xffffffff, 0x00000100,
  535. 0x9144, 0xffffffff, 0x00000100,
  536. 0x8d88, 0xffffffff, 0x00000100,
  537. 0x8d8c, 0xffffffff, 0x00000100,
  538. 0x9030, 0xffffffff, 0x00000100,
  539. 0x9034, 0xffffffff, 0x00000100,
  540. 0x9038, 0xffffffff, 0x00000100,
  541. 0x903c, 0xffffffff, 0x00000100,
  542. 0xad80, 0xffffffff, 0x00000100,
  543. 0xac54, 0xffffffff, 0x00000100,
  544. 0x897c, 0xffffffff, 0x06000100,
  545. 0x9868, 0xffffffff, 0x00000100,
  546. 0x9510, 0xffffffff, 0x00000100,
  547. 0xaf04, 0xffffffff, 0x00000100,
  548. 0xae04, 0xffffffff, 0x00000100,
  549. 0x949c, 0xffffffff, 0x00000100,
  550. 0x802c, 0xffffffff, 0xe0000000,
  551. 0x9160, 0xffffffff, 0x00010000,
  552. 0x9164, 0xffffffff, 0x00030002,
  553. 0x9168, 0xffffffff, 0x00040007,
  554. 0x916c, 0xffffffff, 0x00060005,
  555. 0x9170, 0xffffffff, 0x00090008,
  556. 0x9174, 0xffffffff, 0x00020001,
  557. 0x9178, 0xffffffff, 0x00040003,
  558. 0x917c, 0xffffffff, 0x00000007,
  559. 0x9180, 0xffffffff, 0x00060005,
  560. 0x9184, 0xffffffff, 0x00090008,
  561. 0x9188, 0xffffffff, 0x00030002,
  562. 0x918c, 0xffffffff, 0x00050004,
  563. 0x9190, 0xffffffff, 0x00000008,
  564. 0x9194, 0xffffffff, 0x00070006,
  565. 0x9198, 0xffffffff, 0x000a0009,
  566. 0x919c, 0xffffffff, 0x00040003,
  567. 0x91a0, 0xffffffff, 0x00060005,
  568. 0x91a4, 0xffffffff, 0x00000009,
  569. 0x91a8, 0xffffffff, 0x00080007,
  570. 0x91ac, 0xffffffff, 0x000b000a,
  571. 0x91b0, 0xffffffff, 0x00050004,
  572. 0x91b4, 0xffffffff, 0x00070006,
  573. 0x91b8, 0xffffffff, 0x0008000b,
  574. 0x91bc, 0xffffffff, 0x000a0009,
  575. 0x91c0, 0xffffffff, 0x000d000c,
  576. 0x91c4, 0xffffffff, 0x00060005,
  577. 0x91c8, 0xffffffff, 0x00080007,
  578. 0x91cc, 0xffffffff, 0x0000000b,
  579. 0x91d0, 0xffffffff, 0x000a0009,
  580. 0x91d4, 0xffffffff, 0x000d000c,
  581. 0x91d8, 0xffffffff, 0x00070006,
  582. 0x91dc, 0xffffffff, 0x00090008,
  583. 0x91e0, 0xffffffff, 0x0000000c,
  584. 0x91e4, 0xffffffff, 0x000b000a,
  585. 0x91e8, 0xffffffff, 0x000e000d,
  586. 0x91ec, 0xffffffff, 0x00080007,
  587. 0x91f0, 0xffffffff, 0x000a0009,
  588. 0x91f4, 0xffffffff, 0x0000000d,
  589. 0x91f8, 0xffffffff, 0x000c000b,
  590. 0x91fc, 0xffffffff, 0x000f000e,
  591. 0x9200, 0xffffffff, 0x00090008,
  592. 0x9204, 0xffffffff, 0x000b000a,
  593. 0x9208, 0xffffffff, 0x000c000f,
  594. 0x920c, 0xffffffff, 0x000e000d,
  595. 0x9210, 0xffffffff, 0x00110010,
  596. 0x9214, 0xffffffff, 0x000a0009,
  597. 0x9218, 0xffffffff, 0x000c000b,
  598. 0x921c, 0xffffffff, 0x0000000f,
  599. 0x9220, 0xffffffff, 0x000e000d,
  600. 0x9224, 0xffffffff, 0x00110010,
  601. 0x9228, 0xffffffff, 0x000b000a,
  602. 0x922c, 0xffffffff, 0x000d000c,
  603. 0x9230, 0xffffffff, 0x00000010,
  604. 0x9234, 0xffffffff, 0x000f000e,
  605. 0x9238, 0xffffffff, 0x00120011,
  606. 0x923c, 0xffffffff, 0x000c000b,
  607. 0x9240, 0xffffffff, 0x000e000d,
  608. 0x9244, 0xffffffff, 0x00000011,
  609. 0x9248, 0xffffffff, 0x0010000f,
  610. 0x924c, 0xffffffff, 0x00130012,
  611. 0x9250, 0xffffffff, 0x000d000c,
  612. 0x9254, 0xffffffff, 0x000f000e,
  613. 0x9258, 0xffffffff, 0x00100013,
  614. 0x925c, 0xffffffff, 0x00120011,
  615. 0x9260, 0xffffffff, 0x00150014,
  616. 0x9264, 0xffffffff, 0x000e000d,
  617. 0x9268, 0xffffffff, 0x0010000f,
  618. 0x926c, 0xffffffff, 0x00000013,
  619. 0x9270, 0xffffffff, 0x00120011,
  620. 0x9274, 0xffffffff, 0x00150014,
  621. 0x9278, 0xffffffff, 0x000f000e,
  622. 0x927c, 0xffffffff, 0x00110010,
  623. 0x9280, 0xffffffff, 0x00000014,
  624. 0x9284, 0xffffffff, 0x00130012,
  625. 0x9288, 0xffffffff, 0x00160015,
  626. 0x928c, 0xffffffff, 0x0010000f,
  627. 0x9290, 0xffffffff, 0x00120011,
  628. 0x9294, 0xffffffff, 0x00000015,
  629. 0x9298, 0xffffffff, 0x00140013,
  630. 0x929c, 0xffffffff, 0x00170016,
  631. 0x9150, 0xffffffff, 0x96940200,
  632. 0x8708, 0xffffffff, 0x00900100,
  633. 0xc478, 0xffffffff, 0x00000080,
  634. 0xc404, 0xffffffff, 0x0020003f,
  635. 0x30, 0xffffffff, 0x0000001c,
  636. 0x34, 0x000f0000, 0x000f0000,
  637. 0x160c, 0xffffffff, 0x00000100,
  638. 0x1024, 0xffffffff, 0x00000100,
  639. 0x102c, 0x00000101, 0x00000000,
  640. 0x20a8, 0xffffffff, 0x00000104,
  641. 0x264c, 0x000c0000, 0x000c0000,
  642. 0x2648, 0x000c0000, 0x000c0000,
  643. 0x55e4, 0xff000fff, 0x00000100,
  644. 0x55e8, 0x00000001, 0x00000001,
  645. 0x2f50, 0x00000001, 0x00000001,
  646. 0x30cc, 0xc0000fff, 0x00000104,
  647. 0xc1e4, 0x00000001, 0x00000001,
  648. 0xd0c0, 0xfffffff0, 0x00000100,
  649. 0xd8c0, 0xfffffff0, 0x00000100
  650. };
  651. static const u32 pitcairn_mgcg_cgcg_init[] =
  652. {
  653. 0xc400, 0xffffffff, 0xfffffffc,
  654. 0x802c, 0xffffffff, 0xe0000000,
  655. 0x9a60, 0xffffffff, 0x00000100,
  656. 0x92a4, 0xffffffff, 0x00000100,
  657. 0xc164, 0xffffffff, 0x00000100,
  658. 0x9774, 0xffffffff, 0x00000100,
  659. 0x8984, 0xffffffff, 0x06000100,
  660. 0x8a18, 0xffffffff, 0x00000100,
  661. 0x92a0, 0xffffffff, 0x00000100,
  662. 0xc380, 0xffffffff, 0x00000100,
  663. 0x8b28, 0xffffffff, 0x00000100,
  664. 0x9144, 0xffffffff, 0x00000100,
  665. 0x8d88, 0xffffffff, 0x00000100,
  666. 0x8d8c, 0xffffffff, 0x00000100,
  667. 0x9030, 0xffffffff, 0x00000100,
  668. 0x9034, 0xffffffff, 0x00000100,
  669. 0x9038, 0xffffffff, 0x00000100,
  670. 0x903c, 0xffffffff, 0x00000100,
  671. 0xad80, 0xffffffff, 0x00000100,
  672. 0xac54, 0xffffffff, 0x00000100,
  673. 0x897c, 0xffffffff, 0x06000100,
  674. 0x9868, 0xffffffff, 0x00000100,
  675. 0x9510, 0xffffffff, 0x00000100,
  676. 0xaf04, 0xffffffff, 0x00000100,
  677. 0xae04, 0xffffffff, 0x00000100,
  678. 0x949c, 0xffffffff, 0x00000100,
  679. 0x802c, 0xffffffff, 0xe0000000,
  680. 0x9160, 0xffffffff, 0x00010000,
  681. 0x9164, 0xffffffff, 0x00030002,
  682. 0x9168, 0xffffffff, 0x00040007,
  683. 0x916c, 0xffffffff, 0x00060005,
  684. 0x9170, 0xffffffff, 0x00090008,
  685. 0x9174, 0xffffffff, 0x00020001,
  686. 0x9178, 0xffffffff, 0x00040003,
  687. 0x917c, 0xffffffff, 0x00000007,
  688. 0x9180, 0xffffffff, 0x00060005,
  689. 0x9184, 0xffffffff, 0x00090008,
  690. 0x9188, 0xffffffff, 0x00030002,
  691. 0x918c, 0xffffffff, 0x00050004,
  692. 0x9190, 0xffffffff, 0x00000008,
  693. 0x9194, 0xffffffff, 0x00070006,
  694. 0x9198, 0xffffffff, 0x000a0009,
  695. 0x919c, 0xffffffff, 0x00040003,
  696. 0x91a0, 0xffffffff, 0x00060005,
  697. 0x91a4, 0xffffffff, 0x00000009,
  698. 0x91a8, 0xffffffff, 0x00080007,
  699. 0x91ac, 0xffffffff, 0x000b000a,
  700. 0x91b0, 0xffffffff, 0x00050004,
  701. 0x91b4, 0xffffffff, 0x00070006,
  702. 0x91b8, 0xffffffff, 0x0008000b,
  703. 0x91bc, 0xffffffff, 0x000a0009,
  704. 0x91c0, 0xffffffff, 0x000d000c,
  705. 0x9200, 0xffffffff, 0x00090008,
  706. 0x9204, 0xffffffff, 0x000b000a,
  707. 0x9208, 0xffffffff, 0x000c000f,
  708. 0x920c, 0xffffffff, 0x000e000d,
  709. 0x9210, 0xffffffff, 0x00110010,
  710. 0x9214, 0xffffffff, 0x000a0009,
  711. 0x9218, 0xffffffff, 0x000c000b,
  712. 0x921c, 0xffffffff, 0x0000000f,
  713. 0x9220, 0xffffffff, 0x000e000d,
  714. 0x9224, 0xffffffff, 0x00110010,
  715. 0x9228, 0xffffffff, 0x000b000a,
  716. 0x922c, 0xffffffff, 0x000d000c,
  717. 0x9230, 0xffffffff, 0x00000010,
  718. 0x9234, 0xffffffff, 0x000f000e,
  719. 0x9238, 0xffffffff, 0x00120011,
  720. 0x923c, 0xffffffff, 0x000c000b,
  721. 0x9240, 0xffffffff, 0x000e000d,
  722. 0x9244, 0xffffffff, 0x00000011,
  723. 0x9248, 0xffffffff, 0x0010000f,
  724. 0x924c, 0xffffffff, 0x00130012,
  725. 0x9250, 0xffffffff, 0x000d000c,
  726. 0x9254, 0xffffffff, 0x000f000e,
  727. 0x9258, 0xffffffff, 0x00100013,
  728. 0x925c, 0xffffffff, 0x00120011,
  729. 0x9260, 0xffffffff, 0x00150014,
  730. 0x9150, 0xffffffff, 0x96940200,
  731. 0x8708, 0xffffffff, 0x00900100,
  732. 0xc478, 0xffffffff, 0x00000080,
  733. 0xc404, 0xffffffff, 0x0020003f,
  734. 0x30, 0xffffffff, 0x0000001c,
  735. 0x34, 0x000f0000, 0x000f0000,
  736. 0x160c, 0xffffffff, 0x00000100,
  737. 0x1024, 0xffffffff, 0x00000100,
  738. 0x102c, 0x00000101, 0x00000000,
  739. 0x20a8, 0xffffffff, 0x00000104,
  740. 0x55e4, 0xff000fff, 0x00000100,
  741. 0x55e8, 0x00000001, 0x00000001,
  742. 0x2f50, 0x00000001, 0x00000001,
  743. 0x30cc, 0xc0000fff, 0x00000104,
  744. 0xc1e4, 0x00000001, 0x00000001,
  745. 0xd0c0, 0xfffffff0, 0x00000100,
  746. 0xd8c0, 0xfffffff0, 0x00000100
  747. };
  748. static const u32 verde_mgcg_cgcg_init[] =
  749. {
  750. 0xc400, 0xffffffff, 0xfffffffc,
  751. 0x802c, 0xffffffff, 0xe0000000,
  752. 0x9a60, 0xffffffff, 0x00000100,
  753. 0x92a4, 0xffffffff, 0x00000100,
  754. 0xc164, 0xffffffff, 0x00000100,
  755. 0x9774, 0xffffffff, 0x00000100,
  756. 0x8984, 0xffffffff, 0x06000100,
  757. 0x8a18, 0xffffffff, 0x00000100,
  758. 0x92a0, 0xffffffff, 0x00000100,
  759. 0xc380, 0xffffffff, 0x00000100,
  760. 0x8b28, 0xffffffff, 0x00000100,
  761. 0x9144, 0xffffffff, 0x00000100,
  762. 0x8d88, 0xffffffff, 0x00000100,
  763. 0x8d8c, 0xffffffff, 0x00000100,
  764. 0x9030, 0xffffffff, 0x00000100,
  765. 0x9034, 0xffffffff, 0x00000100,
  766. 0x9038, 0xffffffff, 0x00000100,
  767. 0x903c, 0xffffffff, 0x00000100,
  768. 0xad80, 0xffffffff, 0x00000100,
  769. 0xac54, 0xffffffff, 0x00000100,
  770. 0x897c, 0xffffffff, 0x06000100,
  771. 0x9868, 0xffffffff, 0x00000100,
  772. 0x9510, 0xffffffff, 0x00000100,
  773. 0xaf04, 0xffffffff, 0x00000100,
  774. 0xae04, 0xffffffff, 0x00000100,
  775. 0x949c, 0xffffffff, 0x00000100,
  776. 0x802c, 0xffffffff, 0xe0000000,
  777. 0x9160, 0xffffffff, 0x00010000,
  778. 0x9164, 0xffffffff, 0x00030002,
  779. 0x9168, 0xffffffff, 0x00040007,
  780. 0x916c, 0xffffffff, 0x00060005,
  781. 0x9170, 0xffffffff, 0x00090008,
  782. 0x9174, 0xffffffff, 0x00020001,
  783. 0x9178, 0xffffffff, 0x00040003,
  784. 0x917c, 0xffffffff, 0x00000007,
  785. 0x9180, 0xffffffff, 0x00060005,
  786. 0x9184, 0xffffffff, 0x00090008,
  787. 0x9188, 0xffffffff, 0x00030002,
  788. 0x918c, 0xffffffff, 0x00050004,
  789. 0x9190, 0xffffffff, 0x00000008,
  790. 0x9194, 0xffffffff, 0x00070006,
  791. 0x9198, 0xffffffff, 0x000a0009,
  792. 0x919c, 0xffffffff, 0x00040003,
  793. 0x91a0, 0xffffffff, 0x00060005,
  794. 0x91a4, 0xffffffff, 0x00000009,
  795. 0x91a8, 0xffffffff, 0x00080007,
  796. 0x91ac, 0xffffffff, 0x000b000a,
  797. 0x91b0, 0xffffffff, 0x00050004,
  798. 0x91b4, 0xffffffff, 0x00070006,
  799. 0x91b8, 0xffffffff, 0x0008000b,
  800. 0x91bc, 0xffffffff, 0x000a0009,
  801. 0x91c0, 0xffffffff, 0x000d000c,
  802. 0x9200, 0xffffffff, 0x00090008,
  803. 0x9204, 0xffffffff, 0x000b000a,
  804. 0x9208, 0xffffffff, 0x000c000f,
  805. 0x920c, 0xffffffff, 0x000e000d,
  806. 0x9210, 0xffffffff, 0x00110010,
  807. 0x9214, 0xffffffff, 0x000a0009,
  808. 0x9218, 0xffffffff, 0x000c000b,
  809. 0x921c, 0xffffffff, 0x0000000f,
  810. 0x9220, 0xffffffff, 0x000e000d,
  811. 0x9224, 0xffffffff, 0x00110010,
  812. 0x9228, 0xffffffff, 0x000b000a,
  813. 0x922c, 0xffffffff, 0x000d000c,
  814. 0x9230, 0xffffffff, 0x00000010,
  815. 0x9234, 0xffffffff, 0x000f000e,
  816. 0x9238, 0xffffffff, 0x00120011,
  817. 0x923c, 0xffffffff, 0x000c000b,
  818. 0x9240, 0xffffffff, 0x000e000d,
  819. 0x9244, 0xffffffff, 0x00000011,
  820. 0x9248, 0xffffffff, 0x0010000f,
  821. 0x924c, 0xffffffff, 0x00130012,
  822. 0x9250, 0xffffffff, 0x000d000c,
  823. 0x9254, 0xffffffff, 0x000f000e,
  824. 0x9258, 0xffffffff, 0x00100013,
  825. 0x925c, 0xffffffff, 0x00120011,
  826. 0x9260, 0xffffffff, 0x00150014,
  827. 0x9150, 0xffffffff, 0x96940200,
  828. 0x8708, 0xffffffff, 0x00900100,
  829. 0xc478, 0xffffffff, 0x00000080,
  830. 0xc404, 0xffffffff, 0x0020003f,
  831. 0x30, 0xffffffff, 0x0000001c,
  832. 0x34, 0x000f0000, 0x000f0000,
  833. 0x160c, 0xffffffff, 0x00000100,
  834. 0x1024, 0xffffffff, 0x00000100,
  835. 0x102c, 0x00000101, 0x00000000,
  836. 0x20a8, 0xffffffff, 0x00000104,
  837. 0x264c, 0x000c0000, 0x000c0000,
  838. 0x2648, 0x000c0000, 0x000c0000,
  839. 0x55e4, 0xff000fff, 0x00000100,
  840. 0x55e8, 0x00000001, 0x00000001,
  841. 0x2f50, 0x00000001, 0x00000001,
  842. 0x30cc, 0xc0000fff, 0x00000104,
  843. 0xc1e4, 0x00000001, 0x00000001,
  844. 0xd0c0, 0xfffffff0, 0x00000100,
  845. 0xd8c0, 0xfffffff0, 0x00000100
  846. };
  847. static const u32 oland_mgcg_cgcg_init[] =
  848. {
  849. 0xc400, 0xffffffff, 0xfffffffc,
  850. 0x802c, 0xffffffff, 0xe0000000,
  851. 0x9a60, 0xffffffff, 0x00000100,
  852. 0x92a4, 0xffffffff, 0x00000100,
  853. 0xc164, 0xffffffff, 0x00000100,
  854. 0x9774, 0xffffffff, 0x00000100,
  855. 0x8984, 0xffffffff, 0x06000100,
  856. 0x8a18, 0xffffffff, 0x00000100,
  857. 0x92a0, 0xffffffff, 0x00000100,
  858. 0xc380, 0xffffffff, 0x00000100,
  859. 0x8b28, 0xffffffff, 0x00000100,
  860. 0x9144, 0xffffffff, 0x00000100,
  861. 0x8d88, 0xffffffff, 0x00000100,
  862. 0x8d8c, 0xffffffff, 0x00000100,
  863. 0x9030, 0xffffffff, 0x00000100,
  864. 0x9034, 0xffffffff, 0x00000100,
  865. 0x9038, 0xffffffff, 0x00000100,
  866. 0x903c, 0xffffffff, 0x00000100,
  867. 0xad80, 0xffffffff, 0x00000100,
  868. 0xac54, 0xffffffff, 0x00000100,
  869. 0x897c, 0xffffffff, 0x06000100,
  870. 0x9868, 0xffffffff, 0x00000100,
  871. 0x9510, 0xffffffff, 0x00000100,
  872. 0xaf04, 0xffffffff, 0x00000100,
  873. 0xae04, 0xffffffff, 0x00000100,
  874. 0x949c, 0xffffffff, 0x00000100,
  875. 0x802c, 0xffffffff, 0xe0000000,
  876. 0x9160, 0xffffffff, 0x00010000,
  877. 0x9164, 0xffffffff, 0x00030002,
  878. 0x9168, 0xffffffff, 0x00040007,
  879. 0x916c, 0xffffffff, 0x00060005,
  880. 0x9170, 0xffffffff, 0x00090008,
  881. 0x9174, 0xffffffff, 0x00020001,
  882. 0x9178, 0xffffffff, 0x00040003,
  883. 0x917c, 0xffffffff, 0x00000007,
  884. 0x9180, 0xffffffff, 0x00060005,
  885. 0x9184, 0xffffffff, 0x00090008,
  886. 0x9188, 0xffffffff, 0x00030002,
  887. 0x918c, 0xffffffff, 0x00050004,
  888. 0x9190, 0xffffffff, 0x00000008,
  889. 0x9194, 0xffffffff, 0x00070006,
  890. 0x9198, 0xffffffff, 0x000a0009,
  891. 0x919c, 0xffffffff, 0x00040003,
  892. 0x91a0, 0xffffffff, 0x00060005,
  893. 0x91a4, 0xffffffff, 0x00000009,
  894. 0x91a8, 0xffffffff, 0x00080007,
  895. 0x91ac, 0xffffffff, 0x000b000a,
  896. 0x91b0, 0xffffffff, 0x00050004,
  897. 0x91b4, 0xffffffff, 0x00070006,
  898. 0x91b8, 0xffffffff, 0x0008000b,
  899. 0x91bc, 0xffffffff, 0x000a0009,
  900. 0x91c0, 0xffffffff, 0x000d000c,
  901. 0x91c4, 0xffffffff, 0x00060005,
  902. 0x91c8, 0xffffffff, 0x00080007,
  903. 0x91cc, 0xffffffff, 0x0000000b,
  904. 0x91d0, 0xffffffff, 0x000a0009,
  905. 0x91d4, 0xffffffff, 0x000d000c,
  906. 0x9150, 0xffffffff, 0x96940200,
  907. 0x8708, 0xffffffff, 0x00900100,
  908. 0xc478, 0xffffffff, 0x00000080,
  909. 0xc404, 0xffffffff, 0x0020003f,
  910. 0x30, 0xffffffff, 0x0000001c,
  911. 0x34, 0x000f0000, 0x000f0000,
  912. 0x160c, 0xffffffff, 0x00000100,
  913. 0x1024, 0xffffffff, 0x00000100,
  914. 0x102c, 0x00000101, 0x00000000,
  915. 0x20a8, 0xffffffff, 0x00000104,
  916. 0x264c, 0x000c0000, 0x000c0000,
  917. 0x2648, 0x000c0000, 0x000c0000,
  918. 0x55e4, 0xff000fff, 0x00000100,
  919. 0x55e8, 0x00000001, 0x00000001,
  920. 0x2f50, 0x00000001, 0x00000001,
  921. 0x30cc, 0xc0000fff, 0x00000104,
  922. 0xc1e4, 0x00000001, 0x00000001,
  923. 0xd0c0, 0xfffffff0, 0x00000100,
  924. 0xd8c0, 0xfffffff0, 0x00000100
  925. };
  926. static const u32 hainan_mgcg_cgcg_init[] =
  927. {
  928. 0xc400, 0xffffffff, 0xfffffffc,
  929. 0x802c, 0xffffffff, 0xe0000000,
  930. 0x9a60, 0xffffffff, 0x00000100,
  931. 0x92a4, 0xffffffff, 0x00000100,
  932. 0xc164, 0xffffffff, 0x00000100,
  933. 0x9774, 0xffffffff, 0x00000100,
  934. 0x8984, 0xffffffff, 0x06000100,
  935. 0x8a18, 0xffffffff, 0x00000100,
  936. 0x92a0, 0xffffffff, 0x00000100,
  937. 0xc380, 0xffffffff, 0x00000100,
  938. 0x8b28, 0xffffffff, 0x00000100,
  939. 0x9144, 0xffffffff, 0x00000100,
  940. 0x8d88, 0xffffffff, 0x00000100,
  941. 0x8d8c, 0xffffffff, 0x00000100,
  942. 0x9030, 0xffffffff, 0x00000100,
  943. 0x9034, 0xffffffff, 0x00000100,
  944. 0x9038, 0xffffffff, 0x00000100,
  945. 0x903c, 0xffffffff, 0x00000100,
  946. 0xad80, 0xffffffff, 0x00000100,
  947. 0xac54, 0xffffffff, 0x00000100,
  948. 0x897c, 0xffffffff, 0x06000100,
  949. 0x9868, 0xffffffff, 0x00000100,
  950. 0x9510, 0xffffffff, 0x00000100,
  951. 0xaf04, 0xffffffff, 0x00000100,
  952. 0xae04, 0xffffffff, 0x00000100,
  953. 0x949c, 0xffffffff, 0x00000100,
  954. 0x802c, 0xffffffff, 0xe0000000,
  955. 0x9160, 0xffffffff, 0x00010000,
  956. 0x9164, 0xffffffff, 0x00030002,
  957. 0x9168, 0xffffffff, 0x00040007,
  958. 0x916c, 0xffffffff, 0x00060005,
  959. 0x9170, 0xffffffff, 0x00090008,
  960. 0x9174, 0xffffffff, 0x00020001,
  961. 0x9178, 0xffffffff, 0x00040003,
  962. 0x917c, 0xffffffff, 0x00000007,
  963. 0x9180, 0xffffffff, 0x00060005,
  964. 0x9184, 0xffffffff, 0x00090008,
  965. 0x9188, 0xffffffff, 0x00030002,
  966. 0x918c, 0xffffffff, 0x00050004,
  967. 0x9190, 0xffffffff, 0x00000008,
  968. 0x9194, 0xffffffff, 0x00070006,
  969. 0x9198, 0xffffffff, 0x000a0009,
  970. 0x919c, 0xffffffff, 0x00040003,
  971. 0x91a0, 0xffffffff, 0x00060005,
  972. 0x91a4, 0xffffffff, 0x00000009,
  973. 0x91a8, 0xffffffff, 0x00080007,
  974. 0x91ac, 0xffffffff, 0x000b000a,
  975. 0x91b0, 0xffffffff, 0x00050004,
  976. 0x91b4, 0xffffffff, 0x00070006,
  977. 0x91b8, 0xffffffff, 0x0008000b,
  978. 0x91bc, 0xffffffff, 0x000a0009,
  979. 0x91c0, 0xffffffff, 0x000d000c,
  980. 0x91c4, 0xffffffff, 0x00060005,
  981. 0x91c8, 0xffffffff, 0x00080007,
  982. 0x91cc, 0xffffffff, 0x0000000b,
  983. 0x91d0, 0xffffffff, 0x000a0009,
  984. 0x91d4, 0xffffffff, 0x000d000c,
  985. 0x9150, 0xffffffff, 0x96940200,
  986. 0x8708, 0xffffffff, 0x00900100,
  987. 0xc478, 0xffffffff, 0x00000080,
  988. 0xc404, 0xffffffff, 0x0020003f,
  989. 0x30, 0xffffffff, 0x0000001c,
  990. 0x34, 0x000f0000, 0x000f0000,
  991. 0x160c, 0xffffffff, 0x00000100,
  992. 0x1024, 0xffffffff, 0x00000100,
  993. 0x20a8, 0xffffffff, 0x00000104,
  994. 0x264c, 0x000c0000, 0x000c0000,
  995. 0x2648, 0x000c0000, 0x000c0000,
  996. 0x2f50, 0x00000001, 0x00000001,
  997. 0x30cc, 0xc0000fff, 0x00000104,
  998. 0xc1e4, 0x00000001, 0x00000001,
  999. 0xd0c0, 0xfffffff0, 0x00000100,
  1000. 0xd8c0, 0xfffffff0, 0x00000100
  1001. };
  1002. static u32 verde_pg_init[] =
  1003. {
  1004. 0x353c, 0xffffffff, 0x40000,
  1005. 0x3538, 0xffffffff, 0x200010ff,
  1006. 0x353c, 0xffffffff, 0x0,
  1007. 0x353c, 0xffffffff, 0x0,
  1008. 0x353c, 0xffffffff, 0x0,
  1009. 0x353c, 0xffffffff, 0x0,
  1010. 0x353c, 0xffffffff, 0x0,
  1011. 0x353c, 0xffffffff, 0x7007,
  1012. 0x3538, 0xffffffff, 0x300010ff,
  1013. 0x353c, 0xffffffff, 0x0,
  1014. 0x353c, 0xffffffff, 0x0,
  1015. 0x353c, 0xffffffff, 0x0,
  1016. 0x353c, 0xffffffff, 0x0,
  1017. 0x353c, 0xffffffff, 0x0,
  1018. 0x353c, 0xffffffff, 0x400000,
  1019. 0x3538, 0xffffffff, 0x100010ff,
  1020. 0x353c, 0xffffffff, 0x0,
  1021. 0x353c, 0xffffffff, 0x0,
  1022. 0x353c, 0xffffffff, 0x0,
  1023. 0x353c, 0xffffffff, 0x0,
  1024. 0x353c, 0xffffffff, 0x0,
  1025. 0x353c, 0xffffffff, 0x120200,
  1026. 0x3538, 0xffffffff, 0x500010ff,
  1027. 0x353c, 0xffffffff, 0x0,
  1028. 0x353c, 0xffffffff, 0x0,
  1029. 0x353c, 0xffffffff, 0x0,
  1030. 0x353c, 0xffffffff, 0x0,
  1031. 0x353c, 0xffffffff, 0x0,
  1032. 0x353c, 0xffffffff, 0x1e1e16,
  1033. 0x3538, 0xffffffff, 0x600010ff,
  1034. 0x353c, 0xffffffff, 0x0,
  1035. 0x353c, 0xffffffff, 0x0,
  1036. 0x353c, 0xffffffff, 0x0,
  1037. 0x353c, 0xffffffff, 0x0,
  1038. 0x353c, 0xffffffff, 0x0,
  1039. 0x353c, 0xffffffff, 0x171f1e,
  1040. 0x3538, 0xffffffff, 0x700010ff,
  1041. 0x353c, 0xffffffff, 0x0,
  1042. 0x353c, 0xffffffff, 0x0,
  1043. 0x353c, 0xffffffff, 0x0,
  1044. 0x353c, 0xffffffff, 0x0,
  1045. 0x353c, 0xffffffff, 0x0,
  1046. 0x353c, 0xffffffff, 0x0,
  1047. 0x3538, 0xffffffff, 0x9ff,
  1048. 0x3500, 0xffffffff, 0x0,
  1049. 0x3504, 0xffffffff, 0x10000800,
  1050. 0x3504, 0xffffffff, 0xf,
  1051. 0x3504, 0xffffffff, 0xf,
  1052. 0x3500, 0xffffffff, 0x4,
  1053. 0x3504, 0xffffffff, 0x1000051e,
  1054. 0x3504, 0xffffffff, 0xffff,
  1055. 0x3504, 0xffffffff, 0xffff,
  1056. 0x3500, 0xffffffff, 0x8,
  1057. 0x3504, 0xffffffff, 0x80500,
  1058. 0x3500, 0xffffffff, 0x12,
  1059. 0x3504, 0xffffffff, 0x9050c,
  1060. 0x3500, 0xffffffff, 0x1d,
  1061. 0x3504, 0xffffffff, 0xb052c,
  1062. 0x3500, 0xffffffff, 0x2a,
  1063. 0x3504, 0xffffffff, 0x1053e,
  1064. 0x3500, 0xffffffff, 0x2d,
  1065. 0x3504, 0xffffffff, 0x10546,
  1066. 0x3500, 0xffffffff, 0x30,
  1067. 0x3504, 0xffffffff, 0xa054e,
  1068. 0x3500, 0xffffffff, 0x3c,
  1069. 0x3504, 0xffffffff, 0x1055f,
  1070. 0x3500, 0xffffffff, 0x3f,
  1071. 0x3504, 0xffffffff, 0x10567,
  1072. 0x3500, 0xffffffff, 0x42,
  1073. 0x3504, 0xffffffff, 0x1056f,
  1074. 0x3500, 0xffffffff, 0x45,
  1075. 0x3504, 0xffffffff, 0x10572,
  1076. 0x3500, 0xffffffff, 0x48,
  1077. 0x3504, 0xffffffff, 0x20575,
  1078. 0x3500, 0xffffffff, 0x4c,
  1079. 0x3504, 0xffffffff, 0x190801,
  1080. 0x3500, 0xffffffff, 0x67,
  1081. 0x3504, 0xffffffff, 0x1082a,
  1082. 0x3500, 0xffffffff, 0x6a,
  1083. 0x3504, 0xffffffff, 0x1b082d,
  1084. 0x3500, 0xffffffff, 0x87,
  1085. 0x3504, 0xffffffff, 0x310851,
  1086. 0x3500, 0xffffffff, 0xba,
  1087. 0x3504, 0xffffffff, 0x891,
  1088. 0x3500, 0xffffffff, 0xbc,
  1089. 0x3504, 0xffffffff, 0x893,
  1090. 0x3500, 0xffffffff, 0xbe,
  1091. 0x3504, 0xffffffff, 0x20895,
  1092. 0x3500, 0xffffffff, 0xc2,
  1093. 0x3504, 0xffffffff, 0x20899,
  1094. 0x3500, 0xffffffff, 0xc6,
  1095. 0x3504, 0xffffffff, 0x2089d,
  1096. 0x3500, 0xffffffff, 0xca,
  1097. 0x3504, 0xffffffff, 0x8a1,
  1098. 0x3500, 0xffffffff, 0xcc,
  1099. 0x3504, 0xffffffff, 0x8a3,
  1100. 0x3500, 0xffffffff, 0xce,
  1101. 0x3504, 0xffffffff, 0x308a5,
  1102. 0x3500, 0xffffffff, 0xd3,
  1103. 0x3504, 0xffffffff, 0x6d08cd,
  1104. 0x3500, 0xffffffff, 0x142,
  1105. 0x3504, 0xffffffff, 0x2000095a,
  1106. 0x3504, 0xffffffff, 0x1,
  1107. 0x3500, 0xffffffff, 0x144,
  1108. 0x3504, 0xffffffff, 0x301f095b,
  1109. 0x3500, 0xffffffff, 0x165,
  1110. 0x3504, 0xffffffff, 0xc094d,
  1111. 0x3500, 0xffffffff, 0x173,
  1112. 0x3504, 0xffffffff, 0xf096d,
  1113. 0x3500, 0xffffffff, 0x184,
  1114. 0x3504, 0xffffffff, 0x15097f,
  1115. 0x3500, 0xffffffff, 0x19b,
  1116. 0x3504, 0xffffffff, 0xc0998,
  1117. 0x3500, 0xffffffff, 0x1a9,
  1118. 0x3504, 0xffffffff, 0x409a7,
  1119. 0x3500, 0xffffffff, 0x1af,
  1120. 0x3504, 0xffffffff, 0xcdc,
  1121. 0x3500, 0xffffffff, 0x1b1,
  1122. 0x3504, 0xffffffff, 0x800,
  1123. 0x3508, 0xffffffff, 0x6c9b2000,
  1124. 0x3510, 0xfc00, 0x2000,
  1125. 0x3544, 0xffffffff, 0xfc0,
  1126. 0x28d4, 0x00000100, 0x100
  1127. };
  1128. static void si_init_golden_registers(struct radeon_device *rdev)
  1129. {
  1130. switch (rdev->family) {
  1131. case CHIP_TAHITI:
  1132. radeon_program_register_sequence(rdev,
  1133. tahiti_golden_registers,
  1134. (const u32)ARRAY_SIZE(tahiti_golden_registers));
  1135. radeon_program_register_sequence(rdev,
  1136. tahiti_golden_rlc_registers,
  1137. (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
  1138. radeon_program_register_sequence(rdev,
  1139. tahiti_mgcg_cgcg_init,
  1140. (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
  1141. radeon_program_register_sequence(rdev,
  1142. tahiti_golden_registers2,
  1143. (const u32)ARRAY_SIZE(tahiti_golden_registers2));
  1144. break;
  1145. case CHIP_PITCAIRN:
  1146. radeon_program_register_sequence(rdev,
  1147. pitcairn_golden_registers,
  1148. (const u32)ARRAY_SIZE(pitcairn_golden_registers));
  1149. radeon_program_register_sequence(rdev,
  1150. pitcairn_golden_rlc_registers,
  1151. (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
  1152. radeon_program_register_sequence(rdev,
  1153. pitcairn_mgcg_cgcg_init,
  1154. (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
  1155. break;
  1156. case CHIP_VERDE:
  1157. radeon_program_register_sequence(rdev,
  1158. verde_golden_registers,
  1159. (const u32)ARRAY_SIZE(verde_golden_registers));
  1160. radeon_program_register_sequence(rdev,
  1161. verde_golden_rlc_registers,
  1162. (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
  1163. radeon_program_register_sequence(rdev,
  1164. verde_mgcg_cgcg_init,
  1165. (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
  1166. radeon_program_register_sequence(rdev,
  1167. verde_pg_init,
  1168. (const u32)ARRAY_SIZE(verde_pg_init));
  1169. break;
  1170. case CHIP_OLAND:
  1171. radeon_program_register_sequence(rdev,
  1172. oland_golden_registers,
  1173. (const u32)ARRAY_SIZE(oland_golden_registers));
  1174. radeon_program_register_sequence(rdev,
  1175. oland_golden_rlc_registers,
  1176. (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
  1177. radeon_program_register_sequence(rdev,
  1178. oland_mgcg_cgcg_init,
  1179. (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
  1180. break;
  1181. case CHIP_HAINAN:
  1182. radeon_program_register_sequence(rdev,
  1183. hainan_golden_registers,
  1184. (const u32)ARRAY_SIZE(hainan_golden_registers));
  1185. radeon_program_register_sequence(rdev,
  1186. hainan_golden_registers2,
  1187. (const u32)ARRAY_SIZE(hainan_golden_registers2));
  1188. radeon_program_register_sequence(rdev,
  1189. hainan_mgcg_cgcg_init,
  1190. (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
  1191. break;
  1192. default:
  1193. break;
  1194. }
  1195. }
  1196. #define PCIE_BUS_CLK 10000
  1197. #define TCLK (PCIE_BUS_CLK / 10)
  1198. /**
  1199. * si_get_xclk - get the xclk
  1200. *
  1201. * @rdev: radeon_device pointer
  1202. *
  1203. * Returns the reference clock used by the gfx engine
  1204. * (SI).
  1205. */
  1206. u32 si_get_xclk(struct radeon_device *rdev)
  1207. {
  1208. u32 reference_clock = rdev->clock.spll.reference_freq;
  1209. u32 tmp;
  1210. tmp = RREG32(CG_CLKPIN_CNTL_2);
  1211. if (tmp & MUX_TCLK_TO_XCLK)
  1212. return TCLK;
  1213. tmp = RREG32(CG_CLKPIN_CNTL);
  1214. if (tmp & XTALIN_DIVIDE)
  1215. return reference_clock / 4;
  1216. return reference_clock;
  1217. }
  1218. /* get temperature in millidegrees */
  1219. int si_get_temp(struct radeon_device *rdev)
  1220. {
  1221. u32 temp;
  1222. int actual_temp = 0;
  1223. temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  1224. CTF_TEMP_SHIFT;
  1225. if (temp & 0x200)
  1226. actual_temp = 255;
  1227. else
  1228. actual_temp = temp & 0x1ff;
  1229. actual_temp = (actual_temp * 1000);
  1230. return actual_temp;
  1231. }
  1232. #define TAHITI_IO_MC_REGS_SIZE 36
  1233. static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1234. {0x0000006f, 0x03044000},
  1235. {0x00000070, 0x0480c018},
  1236. {0x00000071, 0x00000040},
  1237. {0x00000072, 0x01000000},
  1238. {0x00000074, 0x000000ff},
  1239. {0x00000075, 0x00143400},
  1240. {0x00000076, 0x08ec0800},
  1241. {0x00000077, 0x040000cc},
  1242. {0x00000079, 0x00000000},
  1243. {0x0000007a, 0x21000409},
  1244. {0x0000007c, 0x00000000},
  1245. {0x0000007d, 0xe8000000},
  1246. {0x0000007e, 0x044408a8},
  1247. {0x0000007f, 0x00000003},
  1248. {0x00000080, 0x00000000},
  1249. {0x00000081, 0x01000000},
  1250. {0x00000082, 0x02000000},
  1251. {0x00000083, 0x00000000},
  1252. {0x00000084, 0xe3f3e4f4},
  1253. {0x00000085, 0x00052024},
  1254. {0x00000087, 0x00000000},
  1255. {0x00000088, 0x66036603},
  1256. {0x00000089, 0x01000000},
  1257. {0x0000008b, 0x1c0a0000},
  1258. {0x0000008c, 0xff010000},
  1259. {0x0000008e, 0xffffefff},
  1260. {0x0000008f, 0xfff3efff},
  1261. {0x00000090, 0xfff3efbf},
  1262. {0x00000094, 0x00101101},
  1263. {0x00000095, 0x00000fff},
  1264. {0x00000096, 0x00116fff},
  1265. {0x00000097, 0x60010000},
  1266. {0x00000098, 0x10010000},
  1267. {0x00000099, 0x00006000},
  1268. {0x0000009a, 0x00001000},
  1269. {0x0000009f, 0x00a77400}
  1270. };
  1271. static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1272. {0x0000006f, 0x03044000},
  1273. {0x00000070, 0x0480c018},
  1274. {0x00000071, 0x00000040},
  1275. {0x00000072, 0x01000000},
  1276. {0x00000074, 0x000000ff},
  1277. {0x00000075, 0x00143400},
  1278. {0x00000076, 0x08ec0800},
  1279. {0x00000077, 0x040000cc},
  1280. {0x00000079, 0x00000000},
  1281. {0x0000007a, 0x21000409},
  1282. {0x0000007c, 0x00000000},
  1283. {0x0000007d, 0xe8000000},
  1284. {0x0000007e, 0x044408a8},
  1285. {0x0000007f, 0x00000003},
  1286. {0x00000080, 0x00000000},
  1287. {0x00000081, 0x01000000},
  1288. {0x00000082, 0x02000000},
  1289. {0x00000083, 0x00000000},
  1290. {0x00000084, 0xe3f3e4f4},
  1291. {0x00000085, 0x00052024},
  1292. {0x00000087, 0x00000000},
  1293. {0x00000088, 0x66036603},
  1294. {0x00000089, 0x01000000},
  1295. {0x0000008b, 0x1c0a0000},
  1296. {0x0000008c, 0xff010000},
  1297. {0x0000008e, 0xffffefff},
  1298. {0x0000008f, 0xfff3efff},
  1299. {0x00000090, 0xfff3efbf},
  1300. {0x00000094, 0x00101101},
  1301. {0x00000095, 0x00000fff},
  1302. {0x00000096, 0x00116fff},
  1303. {0x00000097, 0x60010000},
  1304. {0x00000098, 0x10010000},
  1305. {0x00000099, 0x00006000},
  1306. {0x0000009a, 0x00001000},
  1307. {0x0000009f, 0x00a47400}
  1308. };
  1309. static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1310. {0x0000006f, 0x03044000},
  1311. {0x00000070, 0x0480c018},
  1312. {0x00000071, 0x00000040},
  1313. {0x00000072, 0x01000000},
  1314. {0x00000074, 0x000000ff},
  1315. {0x00000075, 0x00143400},
  1316. {0x00000076, 0x08ec0800},
  1317. {0x00000077, 0x040000cc},
  1318. {0x00000079, 0x00000000},
  1319. {0x0000007a, 0x21000409},
  1320. {0x0000007c, 0x00000000},
  1321. {0x0000007d, 0xe8000000},
  1322. {0x0000007e, 0x044408a8},
  1323. {0x0000007f, 0x00000003},
  1324. {0x00000080, 0x00000000},
  1325. {0x00000081, 0x01000000},
  1326. {0x00000082, 0x02000000},
  1327. {0x00000083, 0x00000000},
  1328. {0x00000084, 0xe3f3e4f4},
  1329. {0x00000085, 0x00052024},
  1330. {0x00000087, 0x00000000},
  1331. {0x00000088, 0x66036603},
  1332. {0x00000089, 0x01000000},
  1333. {0x0000008b, 0x1c0a0000},
  1334. {0x0000008c, 0xff010000},
  1335. {0x0000008e, 0xffffefff},
  1336. {0x0000008f, 0xfff3efff},
  1337. {0x00000090, 0xfff3efbf},
  1338. {0x00000094, 0x00101101},
  1339. {0x00000095, 0x00000fff},
  1340. {0x00000096, 0x00116fff},
  1341. {0x00000097, 0x60010000},
  1342. {0x00000098, 0x10010000},
  1343. {0x00000099, 0x00006000},
  1344. {0x0000009a, 0x00001000},
  1345. {0x0000009f, 0x00a37400}
  1346. };
  1347. static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1348. {0x0000006f, 0x03044000},
  1349. {0x00000070, 0x0480c018},
  1350. {0x00000071, 0x00000040},
  1351. {0x00000072, 0x01000000},
  1352. {0x00000074, 0x000000ff},
  1353. {0x00000075, 0x00143400},
  1354. {0x00000076, 0x08ec0800},
  1355. {0x00000077, 0x040000cc},
  1356. {0x00000079, 0x00000000},
  1357. {0x0000007a, 0x21000409},
  1358. {0x0000007c, 0x00000000},
  1359. {0x0000007d, 0xe8000000},
  1360. {0x0000007e, 0x044408a8},
  1361. {0x0000007f, 0x00000003},
  1362. {0x00000080, 0x00000000},
  1363. {0x00000081, 0x01000000},
  1364. {0x00000082, 0x02000000},
  1365. {0x00000083, 0x00000000},
  1366. {0x00000084, 0xe3f3e4f4},
  1367. {0x00000085, 0x00052024},
  1368. {0x00000087, 0x00000000},
  1369. {0x00000088, 0x66036603},
  1370. {0x00000089, 0x01000000},
  1371. {0x0000008b, 0x1c0a0000},
  1372. {0x0000008c, 0xff010000},
  1373. {0x0000008e, 0xffffefff},
  1374. {0x0000008f, 0xfff3efff},
  1375. {0x00000090, 0xfff3efbf},
  1376. {0x00000094, 0x00101101},
  1377. {0x00000095, 0x00000fff},
  1378. {0x00000096, 0x00116fff},
  1379. {0x00000097, 0x60010000},
  1380. {0x00000098, 0x10010000},
  1381. {0x00000099, 0x00006000},
  1382. {0x0000009a, 0x00001000},
  1383. {0x0000009f, 0x00a17730}
  1384. };
  1385. static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1386. {0x0000006f, 0x03044000},
  1387. {0x00000070, 0x0480c018},
  1388. {0x00000071, 0x00000040},
  1389. {0x00000072, 0x01000000},
  1390. {0x00000074, 0x000000ff},
  1391. {0x00000075, 0x00143400},
  1392. {0x00000076, 0x08ec0800},
  1393. {0x00000077, 0x040000cc},
  1394. {0x00000079, 0x00000000},
  1395. {0x0000007a, 0x21000409},
  1396. {0x0000007c, 0x00000000},
  1397. {0x0000007d, 0xe8000000},
  1398. {0x0000007e, 0x044408a8},
  1399. {0x0000007f, 0x00000003},
  1400. {0x00000080, 0x00000000},
  1401. {0x00000081, 0x01000000},
  1402. {0x00000082, 0x02000000},
  1403. {0x00000083, 0x00000000},
  1404. {0x00000084, 0xe3f3e4f4},
  1405. {0x00000085, 0x00052024},
  1406. {0x00000087, 0x00000000},
  1407. {0x00000088, 0x66036603},
  1408. {0x00000089, 0x01000000},
  1409. {0x0000008b, 0x1c0a0000},
  1410. {0x0000008c, 0xff010000},
  1411. {0x0000008e, 0xffffefff},
  1412. {0x0000008f, 0xfff3efff},
  1413. {0x00000090, 0xfff3efbf},
  1414. {0x00000094, 0x00101101},
  1415. {0x00000095, 0x00000fff},
  1416. {0x00000096, 0x00116fff},
  1417. {0x00000097, 0x60010000},
  1418. {0x00000098, 0x10010000},
  1419. {0x00000099, 0x00006000},
  1420. {0x0000009a, 0x00001000},
  1421. {0x0000009f, 0x00a07730}
  1422. };
  1423. /* ucode loading */
  1424. static int si_mc_load_microcode(struct radeon_device *rdev)
  1425. {
  1426. const __be32 *fw_data;
  1427. u32 running, blackout = 0;
  1428. u32 *io_mc_regs;
  1429. int i, ucode_size, regs_size;
  1430. if (!rdev->mc_fw)
  1431. return -EINVAL;
  1432. switch (rdev->family) {
  1433. case CHIP_TAHITI:
  1434. io_mc_regs = (u32 *)&tahiti_io_mc_regs;
  1435. ucode_size = SI_MC_UCODE_SIZE;
  1436. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1437. break;
  1438. case CHIP_PITCAIRN:
  1439. io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
  1440. ucode_size = SI_MC_UCODE_SIZE;
  1441. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1442. break;
  1443. case CHIP_VERDE:
  1444. default:
  1445. io_mc_regs = (u32 *)&verde_io_mc_regs;
  1446. ucode_size = SI_MC_UCODE_SIZE;
  1447. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1448. break;
  1449. case CHIP_OLAND:
  1450. io_mc_regs = (u32 *)&oland_io_mc_regs;
  1451. ucode_size = OLAND_MC_UCODE_SIZE;
  1452. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1453. break;
  1454. case CHIP_HAINAN:
  1455. io_mc_regs = (u32 *)&hainan_io_mc_regs;
  1456. ucode_size = OLAND_MC_UCODE_SIZE;
  1457. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1458. break;
  1459. }
  1460. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1461. if (running == 0) {
  1462. if (running) {
  1463. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1464. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1465. }
  1466. /* reset the engine and set to writable */
  1467. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1468. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1469. /* load mc io regs */
  1470. for (i = 0; i < regs_size; i++) {
  1471. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1472. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1473. }
  1474. /* load the MC ucode */
  1475. fw_data = (const __be32 *)rdev->mc_fw->data;
  1476. for (i = 0; i < ucode_size; i++)
  1477. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1478. /* put the engine back into the active state */
  1479. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1480. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1481. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1482. /* wait for training to complete */
  1483. for (i = 0; i < rdev->usec_timeout; i++) {
  1484. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1485. break;
  1486. udelay(1);
  1487. }
  1488. for (i = 0; i < rdev->usec_timeout; i++) {
  1489. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1490. break;
  1491. udelay(1);
  1492. }
  1493. if (running)
  1494. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1495. }
  1496. return 0;
  1497. }
  1498. static int si_init_microcode(struct radeon_device *rdev)
  1499. {
  1500. const char *chip_name;
  1501. const char *rlc_chip_name;
  1502. size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
  1503. size_t smc_req_size;
  1504. char fw_name[30];
  1505. int err;
  1506. DRM_DEBUG("\n");
  1507. switch (rdev->family) {
  1508. case CHIP_TAHITI:
  1509. chip_name = "TAHITI";
  1510. rlc_chip_name = "TAHITI";
  1511. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1512. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1513. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1514. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1515. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1516. smc_req_size = ALIGN(TAHITI_SMC_UCODE_SIZE, 4);
  1517. break;
  1518. case CHIP_PITCAIRN:
  1519. chip_name = "PITCAIRN";
  1520. rlc_chip_name = "PITCAIRN";
  1521. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1522. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1523. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1524. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1525. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1526. smc_req_size = ALIGN(PITCAIRN_SMC_UCODE_SIZE, 4);
  1527. break;
  1528. case CHIP_VERDE:
  1529. chip_name = "VERDE";
  1530. rlc_chip_name = "VERDE";
  1531. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1532. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1533. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1534. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1535. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1536. smc_req_size = ALIGN(VERDE_SMC_UCODE_SIZE, 4);
  1537. break;
  1538. case CHIP_OLAND:
  1539. chip_name = "OLAND";
  1540. rlc_chip_name = "OLAND";
  1541. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1542. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1543. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1544. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1545. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1546. smc_req_size = ALIGN(OLAND_SMC_UCODE_SIZE, 4);
  1547. break;
  1548. case CHIP_HAINAN:
  1549. chip_name = "HAINAN";
  1550. rlc_chip_name = "HAINAN";
  1551. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1552. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1553. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1554. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1555. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1556. smc_req_size = ALIGN(HAINAN_SMC_UCODE_SIZE, 4);
  1557. break;
  1558. default: BUG();
  1559. }
  1560. DRM_INFO("Loading %s Microcode\n", chip_name);
  1561. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1562. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  1563. if (err)
  1564. goto out;
  1565. if (rdev->pfp_fw->size != pfp_req_size) {
  1566. printk(KERN_ERR
  1567. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1568. rdev->pfp_fw->size, fw_name);
  1569. err = -EINVAL;
  1570. goto out;
  1571. }
  1572. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1573. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  1574. if (err)
  1575. goto out;
  1576. if (rdev->me_fw->size != me_req_size) {
  1577. printk(KERN_ERR
  1578. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1579. rdev->me_fw->size, fw_name);
  1580. err = -EINVAL;
  1581. }
  1582. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1583. err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
  1584. if (err)
  1585. goto out;
  1586. if (rdev->ce_fw->size != ce_req_size) {
  1587. printk(KERN_ERR
  1588. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1589. rdev->ce_fw->size, fw_name);
  1590. err = -EINVAL;
  1591. }
  1592. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1593. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  1594. if (err)
  1595. goto out;
  1596. if (rdev->rlc_fw->size != rlc_req_size) {
  1597. printk(KERN_ERR
  1598. "si_rlc: Bogus length %zu in firmware \"%s\"\n",
  1599. rdev->rlc_fw->size, fw_name);
  1600. err = -EINVAL;
  1601. }
  1602. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1603. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  1604. if (err)
  1605. goto out;
  1606. if (rdev->mc_fw->size != mc_req_size) {
  1607. printk(KERN_ERR
  1608. "si_mc: Bogus length %zu in firmware \"%s\"\n",
  1609. rdev->mc_fw->size, fw_name);
  1610. err = -EINVAL;
  1611. }
  1612. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
  1613. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  1614. if (err) {
  1615. printk(KERN_ERR
  1616. "smc: error loading firmware \"%s\"\n",
  1617. fw_name);
  1618. release_firmware(rdev->smc_fw);
  1619. rdev->smc_fw = NULL;
  1620. } else if (rdev->smc_fw->size != smc_req_size) {
  1621. printk(KERN_ERR
  1622. "si_smc: Bogus length %zu in firmware \"%s\"\n",
  1623. rdev->smc_fw->size, fw_name);
  1624. err = -EINVAL;
  1625. }
  1626. out:
  1627. if (err) {
  1628. if (err != -EINVAL)
  1629. printk(KERN_ERR
  1630. "si_cp: Failed to load firmware \"%s\"\n",
  1631. fw_name);
  1632. release_firmware(rdev->pfp_fw);
  1633. rdev->pfp_fw = NULL;
  1634. release_firmware(rdev->me_fw);
  1635. rdev->me_fw = NULL;
  1636. release_firmware(rdev->ce_fw);
  1637. rdev->ce_fw = NULL;
  1638. release_firmware(rdev->rlc_fw);
  1639. rdev->rlc_fw = NULL;
  1640. release_firmware(rdev->mc_fw);
  1641. rdev->mc_fw = NULL;
  1642. release_firmware(rdev->smc_fw);
  1643. rdev->smc_fw = NULL;
  1644. }
  1645. return err;
  1646. }
  1647. /* watermark setup */
  1648. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1649. struct radeon_crtc *radeon_crtc,
  1650. struct drm_display_mode *mode,
  1651. struct drm_display_mode *other_mode)
  1652. {
  1653. u32 tmp, buffer_alloc, i;
  1654. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1655. /*
  1656. * Line Buffer Setup
  1657. * There are 3 line buffers, each one shared by 2 display controllers.
  1658. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1659. * the display controllers. The paritioning is done via one of four
  1660. * preset allocations specified in bits 21:20:
  1661. * 0 - half lb
  1662. * 2 - whole lb, other crtc must be disabled
  1663. */
  1664. /* this can get tricky if we have two large displays on a paired group
  1665. * of crtcs. Ideally for multiple large displays we'd assign them to
  1666. * non-linked crtcs for maximum line buffer allocation.
  1667. */
  1668. if (radeon_crtc->base.enabled && mode) {
  1669. if (other_mode) {
  1670. tmp = 0; /* 1/2 */
  1671. buffer_alloc = 1;
  1672. } else {
  1673. tmp = 2; /* whole */
  1674. buffer_alloc = 2;
  1675. }
  1676. } else {
  1677. tmp = 0;
  1678. buffer_alloc = 0;
  1679. }
  1680. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1681. DC_LB_MEMORY_CONFIG(tmp));
  1682. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1683. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1684. for (i = 0; i < rdev->usec_timeout; i++) {
  1685. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1686. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1687. break;
  1688. udelay(1);
  1689. }
  1690. if (radeon_crtc->base.enabled && mode) {
  1691. switch (tmp) {
  1692. case 0:
  1693. default:
  1694. return 4096 * 2;
  1695. case 2:
  1696. return 8192 * 2;
  1697. }
  1698. }
  1699. /* controller not enabled, so no lb used */
  1700. return 0;
  1701. }
  1702. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1703. {
  1704. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1705. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1706. case 0:
  1707. default:
  1708. return 1;
  1709. case 1:
  1710. return 2;
  1711. case 2:
  1712. return 4;
  1713. case 3:
  1714. return 8;
  1715. case 4:
  1716. return 3;
  1717. case 5:
  1718. return 6;
  1719. case 6:
  1720. return 10;
  1721. case 7:
  1722. return 12;
  1723. case 8:
  1724. return 16;
  1725. }
  1726. }
  1727. struct dce6_wm_params {
  1728. u32 dram_channels; /* number of dram channels */
  1729. u32 yclk; /* bandwidth per dram data pin in kHz */
  1730. u32 sclk; /* engine clock in kHz */
  1731. u32 disp_clk; /* display clock in kHz */
  1732. u32 src_width; /* viewport width */
  1733. u32 active_time; /* active display time in ns */
  1734. u32 blank_time; /* blank time in ns */
  1735. bool interlaced; /* mode is interlaced */
  1736. fixed20_12 vsc; /* vertical scale ratio */
  1737. u32 num_heads; /* number of active crtcs */
  1738. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1739. u32 lb_size; /* line buffer allocated to pipe */
  1740. u32 vtaps; /* vertical scaler taps */
  1741. };
  1742. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1743. {
  1744. /* Calculate raw DRAM Bandwidth */
  1745. fixed20_12 dram_efficiency; /* 0.7 */
  1746. fixed20_12 yclk, dram_channels, bandwidth;
  1747. fixed20_12 a;
  1748. a.full = dfixed_const(1000);
  1749. yclk.full = dfixed_const(wm->yclk);
  1750. yclk.full = dfixed_div(yclk, a);
  1751. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1752. a.full = dfixed_const(10);
  1753. dram_efficiency.full = dfixed_const(7);
  1754. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1755. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1756. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1757. return dfixed_trunc(bandwidth);
  1758. }
  1759. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1760. {
  1761. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1762. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1763. fixed20_12 yclk, dram_channels, bandwidth;
  1764. fixed20_12 a;
  1765. a.full = dfixed_const(1000);
  1766. yclk.full = dfixed_const(wm->yclk);
  1767. yclk.full = dfixed_div(yclk, a);
  1768. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1769. a.full = dfixed_const(10);
  1770. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1771. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1772. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1773. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1774. return dfixed_trunc(bandwidth);
  1775. }
  1776. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1777. {
  1778. /* Calculate the display Data return Bandwidth */
  1779. fixed20_12 return_efficiency; /* 0.8 */
  1780. fixed20_12 sclk, bandwidth;
  1781. fixed20_12 a;
  1782. a.full = dfixed_const(1000);
  1783. sclk.full = dfixed_const(wm->sclk);
  1784. sclk.full = dfixed_div(sclk, a);
  1785. a.full = dfixed_const(10);
  1786. return_efficiency.full = dfixed_const(8);
  1787. return_efficiency.full = dfixed_div(return_efficiency, a);
  1788. a.full = dfixed_const(32);
  1789. bandwidth.full = dfixed_mul(a, sclk);
  1790. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1791. return dfixed_trunc(bandwidth);
  1792. }
  1793. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1794. {
  1795. return 32;
  1796. }
  1797. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1798. {
  1799. /* Calculate the DMIF Request Bandwidth */
  1800. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1801. fixed20_12 disp_clk, sclk, bandwidth;
  1802. fixed20_12 a, b1, b2;
  1803. u32 min_bandwidth;
  1804. a.full = dfixed_const(1000);
  1805. disp_clk.full = dfixed_const(wm->disp_clk);
  1806. disp_clk.full = dfixed_div(disp_clk, a);
  1807. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1808. b1.full = dfixed_mul(a, disp_clk);
  1809. a.full = dfixed_const(1000);
  1810. sclk.full = dfixed_const(wm->sclk);
  1811. sclk.full = dfixed_div(sclk, a);
  1812. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1813. b2.full = dfixed_mul(a, sclk);
  1814. a.full = dfixed_const(10);
  1815. disp_clk_request_efficiency.full = dfixed_const(8);
  1816. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1817. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1818. a.full = dfixed_const(min_bandwidth);
  1819. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1820. return dfixed_trunc(bandwidth);
  1821. }
  1822. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1823. {
  1824. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1825. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1826. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1827. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1828. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1829. }
  1830. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1831. {
  1832. /* Calculate the display mode Average Bandwidth
  1833. * DisplayMode should contain the source and destination dimensions,
  1834. * timing, etc.
  1835. */
  1836. fixed20_12 bpp;
  1837. fixed20_12 line_time;
  1838. fixed20_12 src_width;
  1839. fixed20_12 bandwidth;
  1840. fixed20_12 a;
  1841. a.full = dfixed_const(1000);
  1842. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1843. line_time.full = dfixed_div(line_time, a);
  1844. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1845. src_width.full = dfixed_const(wm->src_width);
  1846. bandwidth.full = dfixed_mul(src_width, bpp);
  1847. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1848. bandwidth.full = dfixed_div(bandwidth, line_time);
  1849. return dfixed_trunc(bandwidth);
  1850. }
  1851. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1852. {
  1853. /* First calcualte the latency in ns */
  1854. u32 mc_latency = 2000; /* 2000 ns. */
  1855. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1856. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1857. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1858. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1859. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1860. (wm->num_heads * cursor_line_pair_return_time);
  1861. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1862. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1863. u32 tmp, dmif_size = 12288;
  1864. fixed20_12 a, b, c;
  1865. if (wm->num_heads == 0)
  1866. return 0;
  1867. a.full = dfixed_const(2);
  1868. b.full = dfixed_const(1);
  1869. if ((wm->vsc.full > a.full) ||
  1870. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1871. (wm->vtaps >= 5) ||
  1872. ((wm->vsc.full >= a.full) && wm->interlaced))
  1873. max_src_lines_per_dst_line = 4;
  1874. else
  1875. max_src_lines_per_dst_line = 2;
  1876. a.full = dfixed_const(available_bandwidth);
  1877. b.full = dfixed_const(wm->num_heads);
  1878. a.full = dfixed_div(a, b);
  1879. b.full = dfixed_const(mc_latency + 512);
  1880. c.full = dfixed_const(wm->disp_clk);
  1881. b.full = dfixed_div(b, c);
  1882. c.full = dfixed_const(dmif_size);
  1883. b.full = dfixed_div(c, b);
  1884. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1885. b.full = dfixed_const(1000);
  1886. c.full = dfixed_const(wm->disp_clk);
  1887. b.full = dfixed_div(c, b);
  1888. c.full = dfixed_const(wm->bytes_per_pixel);
  1889. b.full = dfixed_mul(b, c);
  1890. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1891. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1892. b.full = dfixed_const(1000);
  1893. c.full = dfixed_const(lb_fill_bw);
  1894. b.full = dfixed_div(c, b);
  1895. a.full = dfixed_div(a, b);
  1896. line_fill_time = dfixed_trunc(a);
  1897. if (line_fill_time < wm->active_time)
  1898. return latency;
  1899. else
  1900. return latency + (line_fill_time - wm->active_time);
  1901. }
  1902. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1903. {
  1904. if (dce6_average_bandwidth(wm) <=
  1905. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1906. return true;
  1907. else
  1908. return false;
  1909. };
  1910. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1911. {
  1912. if (dce6_average_bandwidth(wm) <=
  1913. (dce6_available_bandwidth(wm) / wm->num_heads))
  1914. return true;
  1915. else
  1916. return false;
  1917. };
  1918. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1919. {
  1920. u32 lb_partitions = wm->lb_size / wm->src_width;
  1921. u32 line_time = wm->active_time + wm->blank_time;
  1922. u32 latency_tolerant_lines;
  1923. u32 latency_hiding;
  1924. fixed20_12 a;
  1925. a.full = dfixed_const(1);
  1926. if (wm->vsc.full > a.full)
  1927. latency_tolerant_lines = 1;
  1928. else {
  1929. if (lb_partitions <= (wm->vtaps + 1))
  1930. latency_tolerant_lines = 1;
  1931. else
  1932. latency_tolerant_lines = 2;
  1933. }
  1934. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1935. if (dce6_latency_watermark(wm) <= latency_hiding)
  1936. return true;
  1937. else
  1938. return false;
  1939. }
  1940. static void dce6_program_watermarks(struct radeon_device *rdev,
  1941. struct radeon_crtc *radeon_crtc,
  1942. u32 lb_size, u32 num_heads)
  1943. {
  1944. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1945. struct dce6_wm_params wm_low, wm_high;
  1946. u32 dram_channels;
  1947. u32 pixel_period;
  1948. u32 line_time = 0;
  1949. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1950. u32 priority_a_mark = 0, priority_b_mark = 0;
  1951. u32 priority_a_cnt = PRIORITY_OFF;
  1952. u32 priority_b_cnt = PRIORITY_OFF;
  1953. u32 tmp, arb_control3;
  1954. fixed20_12 a, b, c;
  1955. if (radeon_crtc->base.enabled && num_heads && mode) {
  1956. pixel_period = 1000000 / (u32)mode->clock;
  1957. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1958. priority_a_cnt = 0;
  1959. priority_b_cnt = 0;
  1960. if (rdev->family == CHIP_ARUBA)
  1961. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1962. else
  1963. dram_channels = si_get_number_of_dram_channels(rdev);
  1964. /* watermark for high clocks */
  1965. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1966. wm_high.yclk =
  1967. radeon_dpm_get_mclk(rdev, false) * 10;
  1968. wm_high.sclk =
  1969. radeon_dpm_get_sclk(rdev, false) * 10;
  1970. } else {
  1971. wm_high.yclk = rdev->pm.current_mclk * 10;
  1972. wm_high.sclk = rdev->pm.current_sclk * 10;
  1973. }
  1974. wm_high.disp_clk = mode->clock;
  1975. wm_high.src_width = mode->crtc_hdisplay;
  1976. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  1977. wm_high.blank_time = line_time - wm_high.active_time;
  1978. wm_high.interlaced = false;
  1979. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1980. wm_high.interlaced = true;
  1981. wm_high.vsc = radeon_crtc->vsc;
  1982. wm_high.vtaps = 1;
  1983. if (radeon_crtc->rmx_type != RMX_OFF)
  1984. wm_high.vtaps = 2;
  1985. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1986. wm_high.lb_size = lb_size;
  1987. wm_high.dram_channels = dram_channels;
  1988. wm_high.num_heads = num_heads;
  1989. /* watermark for low clocks */
  1990. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1991. wm_low.yclk =
  1992. radeon_dpm_get_mclk(rdev, true) * 10;
  1993. wm_low.sclk =
  1994. radeon_dpm_get_sclk(rdev, true) * 10;
  1995. } else {
  1996. wm_low.yclk = rdev->pm.current_mclk * 10;
  1997. wm_low.sclk = rdev->pm.current_sclk * 10;
  1998. }
  1999. wm_low.disp_clk = mode->clock;
  2000. wm_low.src_width = mode->crtc_hdisplay;
  2001. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2002. wm_low.blank_time = line_time - wm_low.active_time;
  2003. wm_low.interlaced = false;
  2004. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2005. wm_low.interlaced = true;
  2006. wm_low.vsc = radeon_crtc->vsc;
  2007. wm_low.vtaps = 1;
  2008. if (radeon_crtc->rmx_type != RMX_OFF)
  2009. wm_low.vtaps = 2;
  2010. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2011. wm_low.lb_size = lb_size;
  2012. wm_low.dram_channels = dram_channels;
  2013. wm_low.num_heads = num_heads;
  2014. /* set for high clocks */
  2015. latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
  2016. /* set for low clocks */
  2017. latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
  2018. /* possibly force display priority to high */
  2019. /* should really do this at mode validation time... */
  2020. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2021. !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2022. !dce6_check_latency_hiding(&wm_high) ||
  2023. (rdev->disp_priority == 2)) {
  2024. DRM_DEBUG_KMS("force priority to high\n");
  2025. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2026. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2027. }
  2028. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2029. !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2030. !dce6_check_latency_hiding(&wm_low) ||
  2031. (rdev->disp_priority == 2)) {
  2032. DRM_DEBUG_KMS("force priority to high\n");
  2033. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2034. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2035. }
  2036. a.full = dfixed_const(1000);
  2037. b.full = dfixed_const(mode->clock);
  2038. b.full = dfixed_div(b, a);
  2039. c.full = dfixed_const(latency_watermark_a);
  2040. c.full = dfixed_mul(c, b);
  2041. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2042. c.full = dfixed_div(c, a);
  2043. a.full = dfixed_const(16);
  2044. c.full = dfixed_div(c, a);
  2045. priority_a_mark = dfixed_trunc(c);
  2046. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2047. a.full = dfixed_const(1000);
  2048. b.full = dfixed_const(mode->clock);
  2049. b.full = dfixed_div(b, a);
  2050. c.full = dfixed_const(latency_watermark_b);
  2051. c.full = dfixed_mul(c, b);
  2052. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2053. c.full = dfixed_div(c, a);
  2054. a.full = dfixed_const(16);
  2055. c.full = dfixed_div(c, a);
  2056. priority_b_mark = dfixed_trunc(c);
  2057. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2058. }
  2059. /* select wm A */
  2060. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2061. tmp = arb_control3;
  2062. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2063. tmp |= LATENCY_WATERMARK_MASK(1);
  2064. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2065. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2066. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2067. LATENCY_HIGH_WATERMARK(line_time)));
  2068. /* select wm B */
  2069. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2070. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2071. tmp |= LATENCY_WATERMARK_MASK(2);
  2072. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2073. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2074. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2075. LATENCY_HIGH_WATERMARK(line_time)));
  2076. /* restore original selection */
  2077. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  2078. /* write the priority marks */
  2079. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2080. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2081. /* save values for DPM */
  2082. radeon_crtc->line_time = line_time;
  2083. radeon_crtc->wm_high = latency_watermark_a;
  2084. radeon_crtc->wm_low = latency_watermark_b;
  2085. }
  2086. void dce6_bandwidth_update(struct radeon_device *rdev)
  2087. {
  2088. struct drm_display_mode *mode0 = NULL;
  2089. struct drm_display_mode *mode1 = NULL;
  2090. u32 num_heads = 0, lb_size;
  2091. int i;
  2092. radeon_update_display_priority(rdev);
  2093. for (i = 0; i < rdev->num_crtc; i++) {
  2094. if (rdev->mode_info.crtcs[i]->base.enabled)
  2095. num_heads++;
  2096. }
  2097. for (i = 0; i < rdev->num_crtc; i += 2) {
  2098. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2099. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2100. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2101. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2102. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2103. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2104. }
  2105. }
  2106. /*
  2107. * Core functions
  2108. */
  2109. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  2110. {
  2111. const u32 num_tile_mode_states = 32;
  2112. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  2113. switch (rdev->config.si.mem_row_size_in_kb) {
  2114. case 1:
  2115. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  2116. break;
  2117. case 2:
  2118. default:
  2119. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  2120. break;
  2121. case 4:
  2122. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  2123. break;
  2124. }
  2125. if ((rdev->family == CHIP_TAHITI) ||
  2126. (rdev->family == CHIP_PITCAIRN)) {
  2127. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2128. switch (reg_offset) {
  2129. case 0: /* non-AA compressed depth or any compressed stencil */
  2130. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2131. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2132. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2133. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2134. NUM_BANKS(ADDR_SURF_16_BANK) |
  2135. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2136. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2137. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2138. break;
  2139. case 1: /* 2xAA/4xAA compressed depth only */
  2140. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2141. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2142. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2143. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2144. NUM_BANKS(ADDR_SURF_16_BANK) |
  2145. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2146. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2147. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2148. break;
  2149. case 2: /* 8xAA compressed depth only */
  2150. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2151. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2152. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2153. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2154. NUM_BANKS(ADDR_SURF_16_BANK) |
  2155. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2156. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2157. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2158. break;
  2159. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2160. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2161. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2162. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2163. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2164. NUM_BANKS(ADDR_SURF_16_BANK) |
  2165. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2166. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2167. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2168. break;
  2169. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2170. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2171. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2172. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2173. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2174. NUM_BANKS(ADDR_SURF_16_BANK) |
  2175. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2176. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2177. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2178. break;
  2179. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2180. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2181. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2182. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2183. TILE_SPLIT(split_equal_to_row_size) |
  2184. NUM_BANKS(ADDR_SURF_16_BANK) |
  2185. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2186. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2187. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2188. break;
  2189. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2190. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2191. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2192. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2193. TILE_SPLIT(split_equal_to_row_size) |
  2194. NUM_BANKS(ADDR_SURF_16_BANK) |
  2195. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2196. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2197. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2198. break;
  2199. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2200. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2201. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2202. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2203. TILE_SPLIT(split_equal_to_row_size) |
  2204. NUM_BANKS(ADDR_SURF_16_BANK) |
  2205. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2206. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2207. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2208. break;
  2209. case 8: /* 1D and 1D Array Surfaces */
  2210. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2211. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2212. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2213. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2214. NUM_BANKS(ADDR_SURF_16_BANK) |
  2215. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2216. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2217. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2218. break;
  2219. case 9: /* Displayable maps. */
  2220. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2221. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2222. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2223. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2224. NUM_BANKS(ADDR_SURF_16_BANK) |
  2225. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2226. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2227. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2228. break;
  2229. case 10: /* Display 8bpp. */
  2230. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2231. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2232. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2233. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2234. NUM_BANKS(ADDR_SURF_16_BANK) |
  2235. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2236. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2237. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2238. break;
  2239. case 11: /* Display 16bpp. */
  2240. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2241. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2242. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2243. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2244. NUM_BANKS(ADDR_SURF_16_BANK) |
  2245. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2246. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2247. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2248. break;
  2249. case 12: /* Display 32bpp. */
  2250. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2251. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2252. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2253. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2254. NUM_BANKS(ADDR_SURF_16_BANK) |
  2255. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2256. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2257. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2258. break;
  2259. case 13: /* Thin. */
  2260. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2261. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2262. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2263. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2264. NUM_BANKS(ADDR_SURF_16_BANK) |
  2265. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2266. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2267. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2268. break;
  2269. case 14: /* Thin 8 bpp. */
  2270. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2271. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2272. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2273. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2274. NUM_BANKS(ADDR_SURF_16_BANK) |
  2275. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2276. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2277. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2278. break;
  2279. case 15: /* Thin 16 bpp. */
  2280. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2281. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2282. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2283. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2284. NUM_BANKS(ADDR_SURF_16_BANK) |
  2285. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2286. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2287. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2288. break;
  2289. case 16: /* Thin 32 bpp. */
  2290. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2291. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2292. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2293. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2294. NUM_BANKS(ADDR_SURF_16_BANK) |
  2295. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2296. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2297. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2298. break;
  2299. case 17: /* Thin 64 bpp. */
  2300. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2301. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2302. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2303. TILE_SPLIT(split_equal_to_row_size) |
  2304. NUM_BANKS(ADDR_SURF_16_BANK) |
  2305. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2306. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2307. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2308. break;
  2309. case 21: /* 8 bpp PRT. */
  2310. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2311. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2312. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2313. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2314. NUM_BANKS(ADDR_SURF_16_BANK) |
  2315. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2316. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2317. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2318. break;
  2319. case 22: /* 16 bpp PRT */
  2320. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2321. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2322. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2323. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2324. NUM_BANKS(ADDR_SURF_16_BANK) |
  2325. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2326. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2327. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2328. break;
  2329. case 23: /* 32 bpp PRT */
  2330. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2331. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2332. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2333. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2334. NUM_BANKS(ADDR_SURF_16_BANK) |
  2335. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2336. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2337. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2338. break;
  2339. case 24: /* 64 bpp PRT */
  2340. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2341. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2342. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2343. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2344. NUM_BANKS(ADDR_SURF_16_BANK) |
  2345. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2346. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2347. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2348. break;
  2349. case 25: /* 128 bpp PRT */
  2350. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2351. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2352. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2353. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2354. NUM_BANKS(ADDR_SURF_8_BANK) |
  2355. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2356. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2357. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2358. break;
  2359. default:
  2360. gb_tile_moden = 0;
  2361. break;
  2362. }
  2363. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2364. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2365. }
  2366. } else if ((rdev->family == CHIP_VERDE) ||
  2367. (rdev->family == CHIP_OLAND) ||
  2368. (rdev->family == CHIP_HAINAN)) {
  2369. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2370. switch (reg_offset) {
  2371. case 0: /* non-AA compressed depth or any compressed stencil */
  2372. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2373. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2374. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2375. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2376. NUM_BANKS(ADDR_SURF_16_BANK) |
  2377. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2378. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2379. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2380. break;
  2381. case 1: /* 2xAA/4xAA compressed depth only */
  2382. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2383. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2384. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2385. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2386. NUM_BANKS(ADDR_SURF_16_BANK) |
  2387. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2388. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2389. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2390. break;
  2391. case 2: /* 8xAA compressed depth only */
  2392. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2393. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2394. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2395. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2396. NUM_BANKS(ADDR_SURF_16_BANK) |
  2397. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2398. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2399. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2400. break;
  2401. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2402. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2403. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2404. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2405. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2406. NUM_BANKS(ADDR_SURF_16_BANK) |
  2407. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2408. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2409. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2410. break;
  2411. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2412. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2413. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2414. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2415. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2416. NUM_BANKS(ADDR_SURF_16_BANK) |
  2417. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2418. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2419. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2420. break;
  2421. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2422. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2423. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2424. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2425. TILE_SPLIT(split_equal_to_row_size) |
  2426. NUM_BANKS(ADDR_SURF_16_BANK) |
  2427. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2428. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2429. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2430. break;
  2431. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2432. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2433. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2434. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2435. TILE_SPLIT(split_equal_to_row_size) |
  2436. NUM_BANKS(ADDR_SURF_16_BANK) |
  2437. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2438. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2439. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2440. break;
  2441. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2442. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2443. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2444. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2445. TILE_SPLIT(split_equal_to_row_size) |
  2446. NUM_BANKS(ADDR_SURF_16_BANK) |
  2447. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2448. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2449. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2450. break;
  2451. case 8: /* 1D and 1D Array Surfaces */
  2452. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2453. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2454. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2455. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2456. NUM_BANKS(ADDR_SURF_16_BANK) |
  2457. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2458. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2459. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2460. break;
  2461. case 9: /* Displayable maps. */
  2462. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2463. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2464. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2465. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2466. NUM_BANKS(ADDR_SURF_16_BANK) |
  2467. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2468. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2469. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2470. break;
  2471. case 10: /* Display 8bpp. */
  2472. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2473. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2474. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2475. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2476. NUM_BANKS(ADDR_SURF_16_BANK) |
  2477. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2478. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2479. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2480. break;
  2481. case 11: /* Display 16bpp. */
  2482. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2483. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2484. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2485. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2486. NUM_BANKS(ADDR_SURF_16_BANK) |
  2487. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2488. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2489. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2490. break;
  2491. case 12: /* Display 32bpp. */
  2492. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2493. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2494. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2495. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2496. NUM_BANKS(ADDR_SURF_16_BANK) |
  2497. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2498. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2499. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2500. break;
  2501. case 13: /* Thin. */
  2502. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2503. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2504. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2505. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2506. NUM_BANKS(ADDR_SURF_16_BANK) |
  2507. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2508. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2509. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2510. break;
  2511. case 14: /* Thin 8 bpp. */
  2512. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2513. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2514. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2515. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2516. NUM_BANKS(ADDR_SURF_16_BANK) |
  2517. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2518. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2519. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2520. break;
  2521. case 15: /* Thin 16 bpp. */
  2522. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2523. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2524. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2525. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2526. NUM_BANKS(ADDR_SURF_16_BANK) |
  2527. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2528. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2529. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2530. break;
  2531. case 16: /* Thin 32 bpp. */
  2532. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2533. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2534. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2535. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2536. NUM_BANKS(ADDR_SURF_16_BANK) |
  2537. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2538. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2539. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2540. break;
  2541. case 17: /* Thin 64 bpp. */
  2542. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2543. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2544. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2545. TILE_SPLIT(split_equal_to_row_size) |
  2546. NUM_BANKS(ADDR_SURF_16_BANK) |
  2547. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2548. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2549. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2550. break;
  2551. case 21: /* 8 bpp PRT. */
  2552. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2553. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2554. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2555. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2556. NUM_BANKS(ADDR_SURF_16_BANK) |
  2557. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2558. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2559. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2560. break;
  2561. case 22: /* 16 bpp PRT */
  2562. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2563. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2564. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2565. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2566. NUM_BANKS(ADDR_SURF_16_BANK) |
  2567. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2568. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2569. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2570. break;
  2571. case 23: /* 32 bpp PRT */
  2572. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2573. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2574. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2575. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2576. NUM_BANKS(ADDR_SURF_16_BANK) |
  2577. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2578. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2579. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2580. break;
  2581. case 24: /* 64 bpp PRT */
  2582. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2583. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2584. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2585. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2586. NUM_BANKS(ADDR_SURF_16_BANK) |
  2587. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2588. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2589. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2590. break;
  2591. case 25: /* 128 bpp PRT */
  2592. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2593. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2594. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2595. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2596. NUM_BANKS(ADDR_SURF_8_BANK) |
  2597. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2598. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2599. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2600. break;
  2601. default:
  2602. gb_tile_moden = 0;
  2603. break;
  2604. }
  2605. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2606. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2607. }
  2608. } else
  2609. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2610. }
  2611. static void si_select_se_sh(struct radeon_device *rdev,
  2612. u32 se_num, u32 sh_num)
  2613. {
  2614. u32 data = INSTANCE_BROADCAST_WRITES;
  2615. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2616. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2617. else if (se_num == 0xffffffff)
  2618. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2619. else if (sh_num == 0xffffffff)
  2620. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2621. else
  2622. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2623. WREG32(GRBM_GFX_INDEX, data);
  2624. }
  2625. static u32 si_create_bitmask(u32 bit_width)
  2626. {
  2627. u32 i, mask = 0;
  2628. for (i = 0; i < bit_width; i++) {
  2629. mask <<= 1;
  2630. mask |= 1;
  2631. }
  2632. return mask;
  2633. }
  2634. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2635. {
  2636. u32 data, mask;
  2637. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2638. if (data & 1)
  2639. data &= INACTIVE_CUS_MASK;
  2640. else
  2641. data = 0;
  2642. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2643. data >>= INACTIVE_CUS_SHIFT;
  2644. mask = si_create_bitmask(cu_per_sh);
  2645. return ~data & mask;
  2646. }
  2647. static void si_setup_spi(struct radeon_device *rdev,
  2648. u32 se_num, u32 sh_per_se,
  2649. u32 cu_per_sh)
  2650. {
  2651. int i, j, k;
  2652. u32 data, mask, active_cu;
  2653. for (i = 0; i < se_num; i++) {
  2654. for (j = 0; j < sh_per_se; j++) {
  2655. si_select_se_sh(rdev, i, j);
  2656. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2657. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2658. mask = 1;
  2659. for (k = 0; k < 16; k++) {
  2660. mask <<= k;
  2661. if (active_cu & mask) {
  2662. data &= ~mask;
  2663. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2664. break;
  2665. }
  2666. }
  2667. }
  2668. }
  2669. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2670. }
  2671. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2672. u32 max_rb_num, u32 se_num,
  2673. u32 sh_per_se)
  2674. {
  2675. u32 data, mask;
  2676. data = RREG32(CC_RB_BACKEND_DISABLE);
  2677. if (data & 1)
  2678. data &= BACKEND_DISABLE_MASK;
  2679. else
  2680. data = 0;
  2681. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2682. data >>= BACKEND_DISABLE_SHIFT;
  2683. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2684. return data & mask;
  2685. }
  2686. static void si_setup_rb(struct radeon_device *rdev,
  2687. u32 se_num, u32 sh_per_se,
  2688. u32 max_rb_num)
  2689. {
  2690. int i, j;
  2691. u32 data, mask;
  2692. u32 disabled_rbs = 0;
  2693. u32 enabled_rbs = 0;
  2694. for (i = 0; i < se_num; i++) {
  2695. for (j = 0; j < sh_per_se; j++) {
  2696. si_select_se_sh(rdev, i, j);
  2697. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2698. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2699. }
  2700. }
  2701. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2702. mask = 1;
  2703. for (i = 0; i < max_rb_num; i++) {
  2704. if (!(disabled_rbs & mask))
  2705. enabled_rbs |= mask;
  2706. mask <<= 1;
  2707. }
  2708. for (i = 0; i < se_num; i++) {
  2709. si_select_se_sh(rdev, i, 0xffffffff);
  2710. data = 0;
  2711. for (j = 0; j < sh_per_se; j++) {
  2712. switch (enabled_rbs & 3) {
  2713. case 1:
  2714. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2715. break;
  2716. case 2:
  2717. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2718. break;
  2719. case 3:
  2720. default:
  2721. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2722. break;
  2723. }
  2724. enabled_rbs >>= 2;
  2725. }
  2726. WREG32(PA_SC_RASTER_CONFIG, data);
  2727. }
  2728. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2729. }
  2730. static void si_gpu_init(struct radeon_device *rdev)
  2731. {
  2732. u32 gb_addr_config = 0;
  2733. u32 mc_shared_chmap, mc_arb_ramcfg;
  2734. u32 sx_debug_1;
  2735. u32 hdp_host_path_cntl;
  2736. u32 tmp;
  2737. int i, j;
  2738. switch (rdev->family) {
  2739. case CHIP_TAHITI:
  2740. rdev->config.si.max_shader_engines = 2;
  2741. rdev->config.si.max_tile_pipes = 12;
  2742. rdev->config.si.max_cu_per_sh = 8;
  2743. rdev->config.si.max_sh_per_se = 2;
  2744. rdev->config.si.max_backends_per_se = 4;
  2745. rdev->config.si.max_texture_channel_caches = 12;
  2746. rdev->config.si.max_gprs = 256;
  2747. rdev->config.si.max_gs_threads = 32;
  2748. rdev->config.si.max_hw_contexts = 8;
  2749. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2750. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2751. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2752. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2753. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2754. break;
  2755. case CHIP_PITCAIRN:
  2756. rdev->config.si.max_shader_engines = 2;
  2757. rdev->config.si.max_tile_pipes = 8;
  2758. rdev->config.si.max_cu_per_sh = 5;
  2759. rdev->config.si.max_sh_per_se = 2;
  2760. rdev->config.si.max_backends_per_se = 4;
  2761. rdev->config.si.max_texture_channel_caches = 8;
  2762. rdev->config.si.max_gprs = 256;
  2763. rdev->config.si.max_gs_threads = 32;
  2764. rdev->config.si.max_hw_contexts = 8;
  2765. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2766. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2767. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2768. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2769. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2770. break;
  2771. case CHIP_VERDE:
  2772. default:
  2773. rdev->config.si.max_shader_engines = 1;
  2774. rdev->config.si.max_tile_pipes = 4;
  2775. rdev->config.si.max_cu_per_sh = 5;
  2776. rdev->config.si.max_sh_per_se = 2;
  2777. rdev->config.si.max_backends_per_se = 4;
  2778. rdev->config.si.max_texture_channel_caches = 4;
  2779. rdev->config.si.max_gprs = 256;
  2780. rdev->config.si.max_gs_threads = 32;
  2781. rdev->config.si.max_hw_contexts = 8;
  2782. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2783. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2784. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2785. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2786. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2787. break;
  2788. case CHIP_OLAND:
  2789. rdev->config.si.max_shader_engines = 1;
  2790. rdev->config.si.max_tile_pipes = 4;
  2791. rdev->config.si.max_cu_per_sh = 6;
  2792. rdev->config.si.max_sh_per_se = 1;
  2793. rdev->config.si.max_backends_per_se = 2;
  2794. rdev->config.si.max_texture_channel_caches = 4;
  2795. rdev->config.si.max_gprs = 256;
  2796. rdev->config.si.max_gs_threads = 16;
  2797. rdev->config.si.max_hw_contexts = 8;
  2798. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2799. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2800. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2801. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2802. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2803. break;
  2804. case CHIP_HAINAN:
  2805. rdev->config.si.max_shader_engines = 1;
  2806. rdev->config.si.max_tile_pipes = 4;
  2807. rdev->config.si.max_cu_per_sh = 5;
  2808. rdev->config.si.max_sh_per_se = 1;
  2809. rdev->config.si.max_backends_per_se = 1;
  2810. rdev->config.si.max_texture_channel_caches = 2;
  2811. rdev->config.si.max_gprs = 256;
  2812. rdev->config.si.max_gs_threads = 16;
  2813. rdev->config.si.max_hw_contexts = 8;
  2814. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2815. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2816. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2817. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2818. gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
  2819. break;
  2820. }
  2821. /* Initialize HDP */
  2822. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2823. WREG32((0x2c14 + j), 0x00000000);
  2824. WREG32((0x2c18 + j), 0x00000000);
  2825. WREG32((0x2c1c + j), 0x00000000);
  2826. WREG32((0x2c20 + j), 0x00000000);
  2827. WREG32((0x2c24 + j), 0x00000000);
  2828. }
  2829. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2830. evergreen_fix_pci_max_read_req_size(rdev);
  2831. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2832. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2833. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2834. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2835. rdev->config.si.mem_max_burst_length_bytes = 256;
  2836. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2837. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2838. if (rdev->config.si.mem_row_size_in_kb > 4)
  2839. rdev->config.si.mem_row_size_in_kb = 4;
  2840. /* XXX use MC settings? */
  2841. rdev->config.si.shader_engine_tile_size = 32;
  2842. rdev->config.si.num_gpus = 1;
  2843. rdev->config.si.multi_gpu_tile_size = 64;
  2844. /* fix up row size */
  2845. gb_addr_config &= ~ROW_SIZE_MASK;
  2846. switch (rdev->config.si.mem_row_size_in_kb) {
  2847. case 1:
  2848. default:
  2849. gb_addr_config |= ROW_SIZE(0);
  2850. break;
  2851. case 2:
  2852. gb_addr_config |= ROW_SIZE(1);
  2853. break;
  2854. case 4:
  2855. gb_addr_config |= ROW_SIZE(2);
  2856. break;
  2857. }
  2858. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2859. * not have bank info, so create a custom tiling dword.
  2860. * bits 3:0 num_pipes
  2861. * bits 7:4 num_banks
  2862. * bits 11:8 group_size
  2863. * bits 15:12 row_size
  2864. */
  2865. rdev->config.si.tile_config = 0;
  2866. switch (rdev->config.si.num_tile_pipes) {
  2867. case 1:
  2868. rdev->config.si.tile_config |= (0 << 0);
  2869. break;
  2870. case 2:
  2871. rdev->config.si.tile_config |= (1 << 0);
  2872. break;
  2873. case 4:
  2874. rdev->config.si.tile_config |= (2 << 0);
  2875. break;
  2876. case 8:
  2877. default:
  2878. /* XXX what about 12? */
  2879. rdev->config.si.tile_config |= (3 << 0);
  2880. break;
  2881. }
  2882. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2883. case 0: /* four banks */
  2884. rdev->config.si.tile_config |= 0 << 4;
  2885. break;
  2886. case 1: /* eight banks */
  2887. rdev->config.si.tile_config |= 1 << 4;
  2888. break;
  2889. case 2: /* sixteen banks */
  2890. default:
  2891. rdev->config.si.tile_config |= 2 << 4;
  2892. break;
  2893. }
  2894. rdev->config.si.tile_config |=
  2895. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2896. rdev->config.si.tile_config |=
  2897. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2898. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2899. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2900. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2901. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2902. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2903. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2904. if (rdev->has_uvd) {
  2905. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2906. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2907. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2908. }
  2909. si_tiling_mode_table_init(rdev);
  2910. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2911. rdev->config.si.max_sh_per_se,
  2912. rdev->config.si.max_backends_per_se);
  2913. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2914. rdev->config.si.max_sh_per_se,
  2915. rdev->config.si.max_cu_per_sh);
  2916. /* set HW defaults for 3D engine */
  2917. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2918. ROQ_IB2_START(0x2b)));
  2919. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2920. sx_debug_1 = RREG32(SX_DEBUG_1);
  2921. WREG32(SX_DEBUG_1, sx_debug_1);
  2922. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2923. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2924. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2925. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2926. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2927. WREG32(VGT_NUM_INSTANCES, 1);
  2928. WREG32(CP_PERFMON_CNTL, 0);
  2929. WREG32(SQ_CONFIG, 0);
  2930. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2931. FORCE_EOV_MAX_REZ_CNT(255)));
  2932. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2933. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2934. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2935. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2936. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2937. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2938. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2939. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2940. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2941. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2942. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2943. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2944. tmp = RREG32(HDP_MISC_CNTL);
  2945. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2946. WREG32(HDP_MISC_CNTL, tmp);
  2947. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2948. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2949. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2950. udelay(50);
  2951. }
  2952. /*
  2953. * GPU scratch registers helpers function.
  2954. */
  2955. static void si_scratch_init(struct radeon_device *rdev)
  2956. {
  2957. int i;
  2958. rdev->scratch.num_reg = 7;
  2959. rdev->scratch.reg_base = SCRATCH_REG0;
  2960. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2961. rdev->scratch.free[i] = true;
  2962. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2963. }
  2964. }
  2965. void si_fence_ring_emit(struct radeon_device *rdev,
  2966. struct radeon_fence *fence)
  2967. {
  2968. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2969. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2970. /* flush read cache over gart */
  2971. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2972. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2973. radeon_ring_write(ring, 0);
  2974. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2975. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2976. PACKET3_TC_ACTION_ENA |
  2977. PACKET3_SH_KCACHE_ACTION_ENA |
  2978. PACKET3_SH_ICACHE_ACTION_ENA);
  2979. radeon_ring_write(ring, 0xFFFFFFFF);
  2980. radeon_ring_write(ring, 0);
  2981. radeon_ring_write(ring, 10); /* poll interval */
  2982. /* EVENT_WRITE_EOP - flush caches, send int */
  2983. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2984. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2985. radeon_ring_write(ring, addr & 0xffffffff);
  2986. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2987. radeon_ring_write(ring, fence->seq);
  2988. radeon_ring_write(ring, 0);
  2989. }
  2990. /*
  2991. * IB stuff
  2992. */
  2993. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2994. {
  2995. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2996. u32 header;
  2997. if (ib->is_const_ib) {
  2998. /* set switch buffer packet before const IB */
  2999. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3000. radeon_ring_write(ring, 0);
  3001. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  3002. } else {
  3003. u32 next_rptr;
  3004. if (ring->rptr_save_reg) {
  3005. next_rptr = ring->wptr + 3 + 4 + 8;
  3006. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3007. radeon_ring_write(ring, ((ring->rptr_save_reg -
  3008. PACKET3_SET_CONFIG_REG_START) >> 2));
  3009. radeon_ring_write(ring, next_rptr);
  3010. } else if (rdev->wb.enabled) {
  3011. next_rptr = ring->wptr + 5 + 4 + 8;
  3012. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3013. radeon_ring_write(ring, (1 << 8));
  3014. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3015. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  3016. radeon_ring_write(ring, next_rptr);
  3017. }
  3018. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  3019. }
  3020. radeon_ring_write(ring, header);
  3021. radeon_ring_write(ring,
  3022. #ifdef __BIG_ENDIAN
  3023. (2 << 0) |
  3024. #endif
  3025. (ib->gpu_addr & 0xFFFFFFFC));
  3026. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  3027. radeon_ring_write(ring, ib->length_dw |
  3028. (ib->vm ? (ib->vm->id << 24) : 0));
  3029. if (!ib->is_const_ib) {
  3030. /* flush read cache over gart for this vmid */
  3031. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3032. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  3033. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  3034. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  3035. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  3036. PACKET3_TC_ACTION_ENA |
  3037. PACKET3_SH_KCACHE_ACTION_ENA |
  3038. PACKET3_SH_ICACHE_ACTION_ENA);
  3039. radeon_ring_write(ring, 0xFFFFFFFF);
  3040. radeon_ring_write(ring, 0);
  3041. radeon_ring_write(ring, 10); /* poll interval */
  3042. }
  3043. }
  3044. /*
  3045. * CP.
  3046. */
  3047. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  3048. {
  3049. if (enable)
  3050. WREG32(CP_ME_CNTL, 0);
  3051. else {
  3052. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  3053. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  3054. WREG32(SCRATCH_UMSK, 0);
  3055. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3056. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3057. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3058. }
  3059. udelay(50);
  3060. }
  3061. static int si_cp_load_microcode(struct radeon_device *rdev)
  3062. {
  3063. const __be32 *fw_data;
  3064. int i;
  3065. if (!rdev->me_fw || !rdev->pfp_fw)
  3066. return -EINVAL;
  3067. si_cp_enable(rdev, false);
  3068. /* PFP */
  3069. fw_data = (const __be32 *)rdev->pfp_fw->data;
  3070. WREG32(CP_PFP_UCODE_ADDR, 0);
  3071. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  3072. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  3073. WREG32(CP_PFP_UCODE_ADDR, 0);
  3074. /* CE */
  3075. fw_data = (const __be32 *)rdev->ce_fw->data;
  3076. WREG32(CP_CE_UCODE_ADDR, 0);
  3077. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  3078. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  3079. WREG32(CP_CE_UCODE_ADDR, 0);
  3080. /* ME */
  3081. fw_data = (const __be32 *)rdev->me_fw->data;
  3082. WREG32(CP_ME_RAM_WADDR, 0);
  3083. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  3084. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  3085. WREG32(CP_ME_RAM_WADDR, 0);
  3086. WREG32(CP_PFP_UCODE_ADDR, 0);
  3087. WREG32(CP_CE_UCODE_ADDR, 0);
  3088. WREG32(CP_ME_RAM_WADDR, 0);
  3089. WREG32(CP_ME_RAM_RADDR, 0);
  3090. return 0;
  3091. }
  3092. static int si_cp_start(struct radeon_device *rdev)
  3093. {
  3094. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3095. int r, i;
  3096. r = radeon_ring_lock(rdev, ring, 7 + 4);
  3097. if (r) {
  3098. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3099. return r;
  3100. }
  3101. /* init the CP */
  3102. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  3103. radeon_ring_write(ring, 0x1);
  3104. radeon_ring_write(ring, 0x0);
  3105. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  3106. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  3107. radeon_ring_write(ring, 0);
  3108. radeon_ring_write(ring, 0);
  3109. /* init the CE partitions */
  3110. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  3111. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  3112. radeon_ring_write(ring, 0xc000);
  3113. radeon_ring_write(ring, 0xe000);
  3114. radeon_ring_unlock_commit(rdev, ring);
  3115. si_cp_enable(rdev, true);
  3116. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  3117. if (r) {
  3118. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3119. return r;
  3120. }
  3121. /* setup clear context state */
  3122. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3123. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3124. for (i = 0; i < si_default_size; i++)
  3125. radeon_ring_write(ring, si_default_state[i]);
  3126. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3127. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  3128. /* set clear context state */
  3129. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  3130. radeon_ring_write(ring, 0);
  3131. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3132. radeon_ring_write(ring, 0x00000316);
  3133. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  3134. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  3135. radeon_ring_unlock_commit(rdev, ring);
  3136. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  3137. ring = &rdev->ring[i];
  3138. r = radeon_ring_lock(rdev, ring, 2);
  3139. /* clear the compute context state */
  3140. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  3141. radeon_ring_write(ring, 0);
  3142. radeon_ring_unlock_commit(rdev, ring);
  3143. }
  3144. return 0;
  3145. }
  3146. static void si_cp_fini(struct radeon_device *rdev)
  3147. {
  3148. struct radeon_ring *ring;
  3149. si_cp_enable(rdev, false);
  3150. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3151. radeon_ring_fini(rdev, ring);
  3152. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3153. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3154. radeon_ring_fini(rdev, ring);
  3155. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3156. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3157. radeon_ring_fini(rdev, ring);
  3158. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3159. }
  3160. static int si_cp_resume(struct radeon_device *rdev)
  3161. {
  3162. struct radeon_ring *ring;
  3163. u32 tmp;
  3164. u32 rb_bufsz;
  3165. int r;
  3166. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  3167. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  3168. /* Set the write pointer delay */
  3169. WREG32(CP_RB_WPTR_DELAY, 0);
  3170. WREG32(CP_DEBUG, 0);
  3171. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  3172. /* ring 0 - compute and gfx */
  3173. /* Set ring buffer size */
  3174. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3175. rb_bufsz = order_base_2(ring->ring_size / 8);
  3176. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3177. #ifdef __BIG_ENDIAN
  3178. tmp |= BUF_SWAP_32BIT;
  3179. #endif
  3180. WREG32(CP_RB0_CNTL, tmp);
  3181. /* Initialize the ring buffer's read and write pointers */
  3182. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  3183. ring->wptr = 0;
  3184. WREG32(CP_RB0_WPTR, ring->wptr);
  3185. /* set the wb address whether it's enabled or not */
  3186. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  3187. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  3188. if (rdev->wb.enabled)
  3189. WREG32(SCRATCH_UMSK, 0xff);
  3190. else {
  3191. tmp |= RB_NO_UPDATE;
  3192. WREG32(SCRATCH_UMSK, 0);
  3193. }
  3194. mdelay(1);
  3195. WREG32(CP_RB0_CNTL, tmp);
  3196. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  3197. ring->rptr = RREG32(CP_RB0_RPTR);
  3198. /* ring1 - compute only */
  3199. /* Set ring buffer size */
  3200. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3201. rb_bufsz = order_base_2(ring->ring_size / 8);
  3202. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3203. #ifdef __BIG_ENDIAN
  3204. tmp |= BUF_SWAP_32BIT;
  3205. #endif
  3206. WREG32(CP_RB1_CNTL, tmp);
  3207. /* Initialize the ring buffer's read and write pointers */
  3208. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  3209. ring->wptr = 0;
  3210. WREG32(CP_RB1_WPTR, ring->wptr);
  3211. /* set the wb address whether it's enabled or not */
  3212. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  3213. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  3214. mdelay(1);
  3215. WREG32(CP_RB1_CNTL, tmp);
  3216. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  3217. ring->rptr = RREG32(CP_RB1_RPTR);
  3218. /* ring2 - compute only */
  3219. /* Set ring buffer size */
  3220. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3221. rb_bufsz = order_base_2(ring->ring_size / 8);
  3222. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3223. #ifdef __BIG_ENDIAN
  3224. tmp |= BUF_SWAP_32BIT;
  3225. #endif
  3226. WREG32(CP_RB2_CNTL, tmp);
  3227. /* Initialize the ring buffer's read and write pointers */
  3228. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  3229. ring->wptr = 0;
  3230. WREG32(CP_RB2_WPTR, ring->wptr);
  3231. /* set the wb address whether it's enabled or not */
  3232. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  3233. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  3234. mdelay(1);
  3235. WREG32(CP_RB2_CNTL, tmp);
  3236. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  3237. ring->rptr = RREG32(CP_RB2_RPTR);
  3238. /* start the rings */
  3239. si_cp_start(rdev);
  3240. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  3241. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  3242. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  3243. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  3244. if (r) {
  3245. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3246. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3247. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3248. return r;
  3249. }
  3250. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  3251. if (r) {
  3252. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3253. }
  3254. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  3255. if (r) {
  3256. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3257. }
  3258. return 0;
  3259. }
  3260. u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  3261. {
  3262. u32 reset_mask = 0;
  3263. u32 tmp;
  3264. /* GRBM_STATUS */
  3265. tmp = RREG32(GRBM_STATUS);
  3266. if (tmp & (PA_BUSY | SC_BUSY |
  3267. BCI_BUSY | SX_BUSY |
  3268. TA_BUSY | VGT_BUSY |
  3269. DB_BUSY | CB_BUSY |
  3270. GDS_BUSY | SPI_BUSY |
  3271. IA_BUSY | IA_BUSY_NO_DMA))
  3272. reset_mask |= RADEON_RESET_GFX;
  3273. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3274. CP_BUSY | CP_COHERENCY_BUSY))
  3275. reset_mask |= RADEON_RESET_CP;
  3276. if (tmp & GRBM_EE_BUSY)
  3277. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3278. /* GRBM_STATUS2 */
  3279. tmp = RREG32(GRBM_STATUS2);
  3280. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3281. reset_mask |= RADEON_RESET_RLC;
  3282. /* DMA_STATUS_REG 0 */
  3283. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  3284. if (!(tmp & DMA_IDLE))
  3285. reset_mask |= RADEON_RESET_DMA;
  3286. /* DMA_STATUS_REG 1 */
  3287. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  3288. if (!(tmp & DMA_IDLE))
  3289. reset_mask |= RADEON_RESET_DMA1;
  3290. /* SRBM_STATUS2 */
  3291. tmp = RREG32(SRBM_STATUS2);
  3292. if (tmp & DMA_BUSY)
  3293. reset_mask |= RADEON_RESET_DMA;
  3294. if (tmp & DMA1_BUSY)
  3295. reset_mask |= RADEON_RESET_DMA1;
  3296. /* SRBM_STATUS */
  3297. tmp = RREG32(SRBM_STATUS);
  3298. if (tmp & IH_BUSY)
  3299. reset_mask |= RADEON_RESET_IH;
  3300. if (tmp & SEM_BUSY)
  3301. reset_mask |= RADEON_RESET_SEM;
  3302. if (tmp & GRBM_RQ_PENDING)
  3303. reset_mask |= RADEON_RESET_GRBM;
  3304. if (tmp & VMC_BUSY)
  3305. reset_mask |= RADEON_RESET_VMC;
  3306. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3307. MCC_BUSY | MCD_BUSY))
  3308. reset_mask |= RADEON_RESET_MC;
  3309. if (evergreen_is_display_hung(rdev))
  3310. reset_mask |= RADEON_RESET_DISPLAY;
  3311. /* VM_L2_STATUS */
  3312. tmp = RREG32(VM_L2_STATUS);
  3313. if (tmp & L2_BUSY)
  3314. reset_mask |= RADEON_RESET_VMC;
  3315. /* Skip MC reset as it's mostly likely not hung, just busy */
  3316. if (reset_mask & RADEON_RESET_MC) {
  3317. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3318. reset_mask &= ~RADEON_RESET_MC;
  3319. }
  3320. return reset_mask;
  3321. }
  3322. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3323. {
  3324. struct evergreen_mc_save save;
  3325. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3326. u32 tmp;
  3327. if (reset_mask == 0)
  3328. return;
  3329. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3330. evergreen_print_gpu_status_regs(rdev);
  3331. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  3332. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  3333. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  3334. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  3335. /* Disable CP parsing/prefetching */
  3336. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  3337. if (reset_mask & RADEON_RESET_DMA) {
  3338. /* dma0 */
  3339. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  3340. tmp &= ~DMA_RB_ENABLE;
  3341. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3342. }
  3343. if (reset_mask & RADEON_RESET_DMA1) {
  3344. /* dma1 */
  3345. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  3346. tmp &= ~DMA_RB_ENABLE;
  3347. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3348. }
  3349. udelay(50);
  3350. evergreen_mc_stop(rdev, &save);
  3351. if (evergreen_mc_wait_for_idle(rdev)) {
  3352. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3353. }
  3354. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  3355. grbm_soft_reset = SOFT_RESET_CB |
  3356. SOFT_RESET_DB |
  3357. SOFT_RESET_GDS |
  3358. SOFT_RESET_PA |
  3359. SOFT_RESET_SC |
  3360. SOFT_RESET_BCI |
  3361. SOFT_RESET_SPI |
  3362. SOFT_RESET_SX |
  3363. SOFT_RESET_TC |
  3364. SOFT_RESET_TA |
  3365. SOFT_RESET_VGT |
  3366. SOFT_RESET_IA;
  3367. }
  3368. if (reset_mask & RADEON_RESET_CP) {
  3369. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  3370. srbm_soft_reset |= SOFT_RESET_GRBM;
  3371. }
  3372. if (reset_mask & RADEON_RESET_DMA)
  3373. srbm_soft_reset |= SOFT_RESET_DMA;
  3374. if (reset_mask & RADEON_RESET_DMA1)
  3375. srbm_soft_reset |= SOFT_RESET_DMA1;
  3376. if (reset_mask & RADEON_RESET_DISPLAY)
  3377. srbm_soft_reset |= SOFT_RESET_DC;
  3378. if (reset_mask & RADEON_RESET_RLC)
  3379. grbm_soft_reset |= SOFT_RESET_RLC;
  3380. if (reset_mask & RADEON_RESET_SEM)
  3381. srbm_soft_reset |= SOFT_RESET_SEM;
  3382. if (reset_mask & RADEON_RESET_IH)
  3383. srbm_soft_reset |= SOFT_RESET_IH;
  3384. if (reset_mask & RADEON_RESET_GRBM)
  3385. srbm_soft_reset |= SOFT_RESET_GRBM;
  3386. if (reset_mask & RADEON_RESET_VMC)
  3387. srbm_soft_reset |= SOFT_RESET_VMC;
  3388. if (reset_mask & RADEON_RESET_MC)
  3389. srbm_soft_reset |= SOFT_RESET_MC;
  3390. if (grbm_soft_reset) {
  3391. tmp = RREG32(GRBM_SOFT_RESET);
  3392. tmp |= grbm_soft_reset;
  3393. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3394. WREG32(GRBM_SOFT_RESET, tmp);
  3395. tmp = RREG32(GRBM_SOFT_RESET);
  3396. udelay(50);
  3397. tmp &= ~grbm_soft_reset;
  3398. WREG32(GRBM_SOFT_RESET, tmp);
  3399. tmp = RREG32(GRBM_SOFT_RESET);
  3400. }
  3401. if (srbm_soft_reset) {
  3402. tmp = RREG32(SRBM_SOFT_RESET);
  3403. tmp |= srbm_soft_reset;
  3404. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3405. WREG32(SRBM_SOFT_RESET, tmp);
  3406. tmp = RREG32(SRBM_SOFT_RESET);
  3407. udelay(50);
  3408. tmp &= ~srbm_soft_reset;
  3409. WREG32(SRBM_SOFT_RESET, tmp);
  3410. tmp = RREG32(SRBM_SOFT_RESET);
  3411. }
  3412. /* Wait a little for things to settle down */
  3413. udelay(50);
  3414. evergreen_mc_resume(rdev, &save);
  3415. udelay(50);
  3416. evergreen_print_gpu_status_regs(rdev);
  3417. }
  3418. int si_asic_reset(struct radeon_device *rdev)
  3419. {
  3420. u32 reset_mask;
  3421. reset_mask = si_gpu_check_soft_reset(rdev);
  3422. if (reset_mask)
  3423. r600_set_bios_scratch_engine_hung(rdev, true);
  3424. si_gpu_soft_reset(rdev, reset_mask);
  3425. reset_mask = si_gpu_check_soft_reset(rdev);
  3426. if (!reset_mask)
  3427. r600_set_bios_scratch_engine_hung(rdev, false);
  3428. return 0;
  3429. }
  3430. /**
  3431. * si_gfx_is_lockup - Check if the GFX engine is locked up
  3432. *
  3433. * @rdev: radeon_device pointer
  3434. * @ring: radeon_ring structure holding ring information
  3435. *
  3436. * Check if the GFX engine is locked up.
  3437. * Returns true if the engine appears to be locked up, false if not.
  3438. */
  3439. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3440. {
  3441. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3442. if (!(reset_mask & (RADEON_RESET_GFX |
  3443. RADEON_RESET_COMPUTE |
  3444. RADEON_RESET_CP))) {
  3445. radeon_ring_lockup_update(ring);
  3446. return false;
  3447. }
  3448. /* force CP activities */
  3449. radeon_ring_force_activity(rdev, ring);
  3450. return radeon_ring_test_lockup(rdev, ring);
  3451. }
  3452. /* MC */
  3453. static void si_mc_program(struct radeon_device *rdev)
  3454. {
  3455. struct evergreen_mc_save save;
  3456. u32 tmp;
  3457. int i, j;
  3458. /* Initialize HDP */
  3459. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3460. WREG32((0x2c14 + j), 0x00000000);
  3461. WREG32((0x2c18 + j), 0x00000000);
  3462. WREG32((0x2c1c + j), 0x00000000);
  3463. WREG32((0x2c20 + j), 0x00000000);
  3464. WREG32((0x2c24 + j), 0x00000000);
  3465. }
  3466. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3467. evergreen_mc_stop(rdev, &save);
  3468. if (radeon_mc_wait_for_idle(rdev)) {
  3469. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3470. }
  3471. if (!ASIC_IS_NODCE(rdev))
  3472. /* Lockout access through VGA aperture*/
  3473. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3474. /* Update configuration */
  3475. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3476. rdev->mc.vram_start >> 12);
  3477. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3478. rdev->mc.vram_end >> 12);
  3479. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3480. rdev->vram_scratch.gpu_addr >> 12);
  3481. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3482. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3483. WREG32(MC_VM_FB_LOCATION, tmp);
  3484. /* XXX double check these! */
  3485. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3486. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3487. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3488. WREG32(MC_VM_AGP_BASE, 0);
  3489. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3490. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3491. if (radeon_mc_wait_for_idle(rdev)) {
  3492. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3493. }
  3494. evergreen_mc_resume(rdev, &save);
  3495. if (!ASIC_IS_NODCE(rdev)) {
  3496. /* we need to own VRAM, so turn off the VGA renderer here
  3497. * to stop it overwriting our objects */
  3498. rv515_vga_render_disable(rdev);
  3499. }
  3500. }
  3501. void si_vram_gtt_location(struct radeon_device *rdev,
  3502. struct radeon_mc *mc)
  3503. {
  3504. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3505. /* leave room for at least 1024M GTT */
  3506. dev_warn(rdev->dev, "limiting VRAM\n");
  3507. mc->real_vram_size = 0xFFC0000000ULL;
  3508. mc->mc_vram_size = 0xFFC0000000ULL;
  3509. }
  3510. radeon_vram_location(rdev, &rdev->mc, 0);
  3511. rdev->mc.gtt_base_align = 0;
  3512. radeon_gtt_location(rdev, mc);
  3513. }
  3514. static int si_mc_init(struct radeon_device *rdev)
  3515. {
  3516. u32 tmp;
  3517. int chansize, numchan;
  3518. /* Get VRAM informations */
  3519. rdev->mc.vram_is_ddr = true;
  3520. tmp = RREG32(MC_ARB_RAMCFG);
  3521. if (tmp & CHANSIZE_OVERRIDE) {
  3522. chansize = 16;
  3523. } else if (tmp & CHANSIZE_MASK) {
  3524. chansize = 64;
  3525. } else {
  3526. chansize = 32;
  3527. }
  3528. tmp = RREG32(MC_SHARED_CHMAP);
  3529. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3530. case 0:
  3531. default:
  3532. numchan = 1;
  3533. break;
  3534. case 1:
  3535. numchan = 2;
  3536. break;
  3537. case 2:
  3538. numchan = 4;
  3539. break;
  3540. case 3:
  3541. numchan = 8;
  3542. break;
  3543. case 4:
  3544. numchan = 3;
  3545. break;
  3546. case 5:
  3547. numchan = 6;
  3548. break;
  3549. case 6:
  3550. numchan = 10;
  3551. break;
  3552. case 7:
  3553. numchan = 12;
  3554. break;
  3555. case 8:
  3556. numchan = 16;
  3557. break;
  3558. }
  3559. rdev->mc.vram_width = numchan * chansize;
  3560. /* Could aper size report 0 ? */
  3561. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3562. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3563. /* size in MB on si */
  3564. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3565. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3566. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3567. si_vram_gtt_location(rdev, &rdev->mc);
  3568. radeon_update_bandwidth_info(rdev);
  3569. return 0;
  3570. }
  3571. /*
  3572. * GART
  3573. */
  3574. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3575. {
  3576. /* flush hdp cache */
  3577. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3578. /* bits 0-15 are the VM contexts0-15 */
  3579. WREG32(VM_INVALIDATE_REQUEST, 1);
  3580. }
  3581. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3582. {
  3583. int r, i;
  3584. if (rdev->gart.robj == NULL) {
  3585. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3586. return -EINVAL;
  3587. }
  3588. r = radeon_gart_table_vram_pin(rdev);
  3589. if (r)
  3590. return r;
  3591. radeon_gart_restore(rdev);
  3592. /* Setup TLB control */
  3593. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3594. (0xA << 7) |
  3595. ENABLE_L1_TLB |
  3596. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3597. ENABLE_ADVANCED_DRIVER_MODEL |
  3598. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3599. /* Setup L2 cache */
  3600. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3601. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3602. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3603. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3604. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3605. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3606. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3607. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3608. /* setup context0 */
  3609. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3610. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3611. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3612. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3613. (u32)(rdev->dummy_page.addr >> 12));
  3614. WREG32(VM_CONTEXT0_CNTL2, 0);
  3615. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3616. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3617. WREG32(0x15D4, 0);
  3618. WREG32(0x15D8, 0);
  3619. WREG32(0x15DC, 0);
  3620. /* empty context1-15 */
  3621. /* set vm size, must be a multiple of 4 */
  3622. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3623. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3624. /* Assign the pt base to something valid for now; the pts used for
  3625. * the VMs are determined by the application and setup and assigned
  3626. * on the fly in the vm part of radeon_gart.c
  3627. */
  3628. for (i = 1; i < 16; i++) {
  3629. if (i < 8)
  3630. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3631. rdev->gart.table_addr >> 12);
  3632. else
  3633. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3634. rdev->gart.table_addr >> 12);
  3635. }
  3636. /* enable context1-15 */
  3637. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3638. (u32)(rdev->dummy_page.addr >> 12));
  3639. WREG32(VM_CONTEXT1_CNTL2, 4);
  3640. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3641. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3642. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3643. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3644. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3645. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3646. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3647. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3648. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3649. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3650. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3651. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3652. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3653. si_pcie_gart_tlb_flush(rdev);
  3654. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3655. (unsigned)(rdev->mc.gtt_size >> 20),
  3656. (unsigned long long)rdev->gart.table_addr);
  3657. rdev->gart.ready = true;
  3658. return 0;
  3659. }
  3660. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3661. {
  3662. /* Disable all tables */
  3663. WREG32(VM_CONTEXT0_CNTL, 0);
  3664. WREG32(VM_CONTEXT1_CNTL, 0);
  3665. /* Setup TLB control */
  3666. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3667. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3668. /* Setup L2 cache */
  3669. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3670. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3671. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3672. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3673. WREG32(VM_L2_CNTL2, 0);
  3674. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3675. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3676. radeon_gart_table_vram_unpin(rdev);
  3677. }
  3678. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3679. {
  3680. si_pcie_gart_disable(rdev);
  3681. radeon_gart_table_vram_free(rdev);
  3682. radeon_gart_fini(rdev);
  3683. }
  3684. /* vm parser */
  3685. static bool si_vm_reg_valid(u32 reg)
  3686. {
  3687. /* context regs are fine */
  3688. if (reg >= 0x28000)
  3689. return true;
  3690. /* check config regs */
  3691. switch (reg) {
  3692. case GRBM_GFX_INDEX:
  3693. case CP_STRMOUT_CNTL:
  3694. case VGT_VTX_VECT_EJECT_REG:
  3695. case VGT_CACHE_INVALIDATION:
  3696. case VGT_ESGS_RING_SIZE:
  3697. case VGT_GSVS_RING_SIZE:
  3698. case VGT_GS_VERTEX_REUSE:
  3699. case VGT_PRIMITIVE_TYPE:
  3700. case VGT_INDEX_TYPE:
  3701. case VGT_NUM_INDICES:
  3702. case VGT_NUM_INSTANCES:
  3703. case VGT_TF_RING_SIZE:
  3704. case VGT_HS_OFFCHIP_PARAM:
  3705. case VGT_TF_MEMORY_BASE:
  3706. case PA_CL_ENHANCE:
  3707. case PA_SU_LINE_STIPPLE_VALUE:
  3708. case PA_SC_LINE_STIPPLE_STATE:
  3709. case PA_SC_ENHANCE:
  3710. case SQC_CACHES:
  3711. case SPI_STATIC_THREAD_MGMT_1:
  3712. case SPI_STATIC_THREAD_MGMT_2:
  3713. case SPI_STATIC_THREAD_MGMT_3:
  3714. case SPI_PS_MAX_WAVE_ID:
  3715. case SPI_CONFIG_CNTL:
  3716. case SPI_CONFIG_CNTL_1:
  3717. case TA_CNTL_AUX:
  3718. return true;
  3719. default:
  3720. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3721. return false;
  3722. }
  3723. }
  3724. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3725. u32 *ib, struct radeon_cs_packet *pkt)
  3726. {
  3727. switch (pkt->opcode) {
  3728. case PACKET3_NOP:
  3729. case PACKET3_SET_BASE:
  3730. case PACKET3_SET_CE_DE_COUNTERS:
  3731. case PACKET3_LOAD_CONST_RAM:
  3732. case PACKET3_WRITE_CONST_RAM:
  3733. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3734. case PACKET3_DUMP_CONST_RAM:
  3735. case PACKET3_INCREMENT_CE_COUNTER:
  3736. case PACKET3_WAIT_ON_DE_COUNTER:
  3737. case PACKET3_CE_WRITE:
  3738. break;
  3739. default:
  3740. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3741. return -EINVAL;
  3742. }
  3743. return 0;
  3744. }
  3745. static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
  3746. {
  3747. u32 start_reg, reg, i;
  3748. u32 command = ib[idx + 4];
  3749. u32 info = ib[idx + 1];
  3750. u32 idx_value = ib[idx];
  3751. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3752. /* src address space is register */
  3753. if (((info & 0x60000000) >> 29) == 0) {
  3754. start_reg = idx_value << 2;
  3755. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3756. reg = start_reg;
  3757. if (!si_vm_reg_valid(reg)) {
  3758. DRM_ERROR("CP DMA Bad SRC register\n");
  3759. return -EINVAL;
  3760. }
  3761. } else {
  3762. for (i = 0; i < (command & 0x1fffff); i++) {
  3763. reg = start_reg + (4 * i);
  3764. if (!si_vm_reg_valid(reg)) {
  3765. DRM_ERROR("CP DMA Bad SRC register\n");
  3766. return -EINVAL;
  3767. }
  3768. }
  3769. }
  3770. }
  3771. }
  3772. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3773. /* dst address space is register */
  3774. if (((info & 0x00300000) >> 20) == 0) {
  3775. start_reg = ib[idx + 2];
  3776. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3777. reg = start_reg;
  3778. if (!si_vm_reg_valid(reg)) {
  3779. DRM_ERROR("CP DMA Bad DST register\n");
  3780. return -EINVAL;
  3781. }
  3782. } else {
  3783. for (i = 0; i < (command & 0x1fffff); i++) {
  3784. reg = start_reg + (4 * i);
  3785. if (!si_vm_reg_valid(reg)) {
  3786. DRM_ERROR("CP DMA Bad DST register\n");
  3787. return -EINVAL;
  3788. }
  3789. }
  3790. }
  3791. }
  3792. }
  3793. return 0;
  3794. }
  3795. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3796. u32 *ib, struct radeon_cs_packet *pkt)
  3797. {
  3798. int r;
  3799. u32 idx = pkt->idx + 1;
  3800. u32 idx_value = ib[idx];
  3801. u32 start_reg, end_reg, reg, i;
  3802. switch (pkt->opcode) {
  3803. case PACKET3_NOP:
  3804. case PACKET3_SET_BASE:
  3805. case PACKET3_CLEAR_STATE:
  3806. case PACKET3_INDEX_BUFFER_SIZE:
  3807. case PACKET3_DISPATCH_DIRECT:
  3808. case PACKET3_DISPATCH_INDIRECT:
  3809. case PACKET3_ALLOC_GDS:
  3810. case PACKET3_WRITE_GDS_RAM:
  3811. case PACKET3_ATOMIC_GDS:
  3812. case PACKET3_ATOMIC:
  3813. case PACKET3_OCCLUSION_QUERY:
  3814. case PACKET3_SET_PREDICATION:
  3815. case PACKET3_COND_EXEC:
  3816. case PACKET3_PRED_EXEC:
  3817. case PACKET3_DRAW_INDIRECT:
  3818. case PACKET3_DRAW_INDEX_INDIRECT:
  3819. case PACKET3_INDEX_BASE:
  3820. case PACKET3_DRAW_INDEX_2:
  3821. case PACKET3_CONTEXT_CONTROL:
  3822. case PACKET3_INDEX_TYPE:
  3823. case PACKET3_DRAW_INDIRECT_MULTI:
  3824. case PACKET3_DRAW_INDEX_AUTO:
  3825. case PACKET3_DRAW_INDEX_IMMD:
  3826. case PACKET3_NUM_INSTANCES:
  3827. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3828. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3829. case PACKET3_DRAW_INDEX_OFFSET_2:
  3830. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3831. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3832. case PACKET3_MPEG_INDEX:
  3833. case PACKET3_WAIT_REG_MEM:
  3834. case PACKET3_MEM_WRITE:
  3835. case PACKET3_PFP_SYNC_ME:
  3836. case PACKET3_SURFACE_SYNC:
  3837. case PACKET3_EVENT_WRITE:
  3838. case PACKET3_EVENT_WRITE_EOP:
  3839. case PACKET3_EVENT_WRITE_EOS:
  3840. case PACKET3_SET_CONTEXT_REG:
  3841. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3842. case PACKET3_SET_SH_REG:
  3843. case PACKET3_SET_SH_REG_OFFSET:
  3844. case PACKET3_INCREMENT_DE_COUNTER:
  3845. case PACKET3_WAIT_ON_CE_COUNTER:
  3846. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3847. case PACKET3_ME_WRITE:
  3848. break;
  3849. case PACKET3_COPY_DATA:
  3850. if ((idx_value & 0xf00) == 0) {
  3851. reg = ib[idx + 3] * 4;
  3852. if (!si_vm_reg_valid(reg))
  3853. return -EINVAL;
  3854. }
  3855. break;
  3856. case PACKET3_WRITE_DATA:
  3857. if ((idx_value & 0xf00) == 0) {
  3858. start_reg = ib[idx + 1] * 4;
  3859. if (idx_value & 0x10000) {
  3860. if (!si_vm_reg_valid(start_reg))
  3861. return -EINVAL;
  3862. } else {
  3863. for (i = 0; i < (pkt->count - 2); i++) {
  3864. reg = start_reg + (4 * i);
  3865. if (!si_vm_reg_valid(reg))
  3866. return -EINVAL;
  3867. }
  3868. }
  3869. }
  3870. break;
  3871. case PACKET3_COND_WRITE:
  3872. if (idx_value & 0x100) {
  3873. reg = ib[idx + 5] * 4;
  3874. if (!si_vm_reg_valid(reg))
  3875. return -EINVAL;
  3876. }
  3877. break;
  3878. case PACKET3_COPY_DW:
  3879. if (idx_value & 0x2) {
  3880. reg = ib[idx + 3] * 4;
  3881. if (!si_vm_reg_valid(reg))
  3882. return -EINVAL;
  3883. }
  3884. break;
  3885. case PACKET3_SET_CONFIG_REG:
  3886. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3887. end_reg = 4 * pkt->count + start_reg - 4;
  3888. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3889. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3890. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3891. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3892. return -EINVAL;
  3893. }
  3894. for (i = 0; i < pkt->count; i++) {
  3895. reg = start_reg + (4 * i);
  3896. if (!si_vm_reg_valid(reg))
  3897. return -EINVAL;
  3898. }
  3899. break;
  3900. case PACKET3_CP_DMA:
  3901. r = si_vm_packet3_cp_dma_check(ib, idx);
  3902. if (r)
  3903. return r;
  3904. break;
  3905. default:
  3906. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3907. return -EINVAL;
  3908. }
  3909. return 0;
  3910. }
  3911. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3912. u32 *ib, struct radeon_cs_packet *pkt)
  3913. {
  3914. int r;
  3915. u32 idx = pkt->idx + 1;
  3916. u32 idx_value = ib[idx];
  3917. u32 start_reg, reg, i;
  3918. switch (pkt->opcode) {
  3919. case PACKET3_NOP:
  3920. case PACKET3_SET_BASE:
  3921. case PACKET3_CLEAR_STATE:
  3922. case PACKET3_DISPATCH_DIRECT:
  3923. case PACKET3_DISPATCH_INDIRECT:
  3924. case PACKET3_ALLOC_GDS:
  3925. case PACKET3_WRITE_GDS_RAM:
  3926. case PACKET3_ATOMIC_GDS:
  3927. case PACKET3_ATOMIC:
  3928. case PACKET3_OCCLUSION_QUERY:
  3929. case PACKET3_SET_PREDICATION:
  3930. case PACKET3_COND_EXEC:
  3931. case PACKET3_PRED_EXEC:
  3932. case PACKET3_CONTEXT_CONTROL:
  3933. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3934. case PACKET3_WAIT_REG_MEM:
  3935. case PACKET3_MEM_WRITE:
  3936. case PACKET3_PFP_SYNC_ME:
  3937. case PACKET3_SURFACE_SYNC:
  3938. case PACKET3_EVENT_WRITE:
  3939. case PACKET3_EVENT_WRITE_EOP:
  3940. case PACKET3_EVENT_WRITE_EOS:
  3941. case PACKET3_SET_CONTEXT_REG:
  3942. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3943. case PACKET3_SET_SH_REG:
  3944. case PACKET3_SET_SH_REG_OFFSET:
  3945. case PACKET3_INCREMENT_DE_COUNTER:
  3946. case PACKET3_WAIT_ON_CE_COUNTER:
  3947. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3948. case PACKET3_ME_WRITE:
  3949. break;
  3950. case PACKET3_COPY_DATA:
  3951. if ((idx_value & 0xf00) == 0) {
  3952. reg = ib[idx + 3] * 4;
  3953. if (!si_vm_reg_valid(reg))
  3954. return -EINVAL;
  3955. }
  3956. break;
  3957. case PACKET3_WRITE_DATA:
  3958. if ((idx_value & 0xf00) == 0) {
  3959. start_reg = ib[idx + 1] * 4;
  3960. if (idx_value & 0x10000) {
  3961. if (!si_vm_reg_valid(start_reg))
  3962. return -EINVAL;
  3963. } else {
  3964. for (i = 0; i < (pkt->count - 2); i++) {
  3965. reg = start_reg + (4 * i);
  3966. if (!si_vm_reg_valid(reg))
  3967. return -EINVAL;
  3968. }
  3969. }
  3970. }
  3971. break;
  3972. case PACKET3_COND_WRITE:
  3973. if (idx_value & 0x100) {
  3974. reg = ib[idx + 5] * 4;
  3975. if (!si_vm_reg_valid(reg))
  3976. return -EINVAL;
  3977. }
  3978. break;
  3979. case PACKET3_COPY_DW:
  3980. if (idx_value & 0x2) {
  3981. reg = ib[idx + 3] * 4;
  3982. if (!si_vm_reg_valid(reg))
  3983. return -EINVAL;
  3984. }
  3985. break;
  3986. case PACKET3_CP_DMA:
  3987. r = si_vm_packet3_cp_dma_check(ib, idx);
  3988. if (r)
  3989. return r;
  3990. break;
  3991. default:
  3992. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  3993. return -EINVAL;
  3994. }
  3995. return 0;
  3996. }
  3997. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3998. {
  3999. int ret = 0;
  4000. u32 idx = 0;
  4001. struct radeon_cs_packet pkt;
  4002. do {
  4003. pkt.idx = idx;
  4004. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  4005. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  4006. pkt.one_reg_wr = 0;
  4007. switch (pkt.type) {
  4008. case RADEON_PACKET_TYPE0:
  4009. dev_err(rdev->dev, "Packet0 not allowed!\n");
  4010. ret = -EINVAL;
  4011. break;
  4012. case RADEON_PACKET_TYPE2:
  4013. idx += 1;
  4014. break;
  4015. case RADEON_PACKET_TYPE3:
  4016. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  4017. if (ib->is_const_ib)
  4018. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  4019. else {
  4020. switch (ib->ring) {
  4021. case RADEON_RING_TYPE_GFX_INDEX:
  4022. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  4023. break;
  4024. case CAYMAN_RING_TYPE_CP1_INDEX:
  4025. case CAYMAN_RING_TYPE_CP2_INDEX:
  4026. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  4027. break;
  4028. default:
  4029. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  4030. ret = -EINVAL;
  4031. break;
  4032. }
  4033. }
  4034. idx += pkt.count + 2;
  4035. break;
  4036. default:
  4037. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  4038. ret = -EINVAL;
  4039. break;
  4040. }
  4041. if (ret)
  4042. break;
  4043. } while (idx < ib->length_dw);
  4044. return ret;
  4045. }
  4046. /*
  4047. * vm
  4048. */
  4049. int si_vm_init(struct radeon_device *rdev)
  4050. {
  4051. /* number of VMs */
  4052. rdev->vm_manager.nvm = 16;
  4053. /* base offset of vram pages */
  4054. rdev->vm_manager.vram_base_offset = 0;
  4055. return 0;
  4056. }
  4057. void si_vm_fini(struct radeon_device *rdev)
  4058. {
  4059. }
  4060. /**
  4061. * si_vm_decode_fault - print human readable fault info
  4062. *
  4063. * @rdev: radeon_device pointer
  4064. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  4065. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  4066. *
  4067. * Print human readable fault information (SI).
  4068. */
  4069. static void si_vm_decode_fault(struct radeon_device *rdev,
  4070. u32 status, u32 addr)
  4071. {
  4072. u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  4073. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  4074. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  4075. char *block;
  4076. if (rdev->family == CHIP_TAHITI) {
  4077. switch (mc_id) {
  4078. case 160:
  4079. case 144:
  4080. case 96:
  4081. case 80:
  4082. case 224:
  4083. case 208:
  4084. case 32:
  4085. case 16:
  4086. block = "CB";
  4087. break;
  4088. case 161:
  4089. case 145:
  4090. case 97:
  4091. case 81:
  4092. case 225:
  4093. case 209:
  4094. case 33:
  4095. case 17:
  4096. block = "CB_FMASK";
  4097. break;
  4098. case 162:
  4099. case 146:
  4100. case 98:
  4101. case 82:
  4102. case 226:
  4103. case 210:
  4104. case 34:
  4105. case 18:
  4106. block = "CB_CMASK";
  4107. break;
  4108. case 163:
  4109. case 147:
  4110. case 99:
  4111. case 83:
  4112. case 227:
  4113. case 211:
  4114. case 35:
  4115. case 19:
  4116. block = "CB_IMMED";
  4117. break;
  4118. case 164:
  4119. case 148:
  4120. case 100:
  4121. case 84:
  4122. case 228:
  4123. case 212:
  4124. case 36:
  4125. case 20:
  4126. block = "DB";
  4127. break;
  4128. case 165:
  4129. case 149:
  4130. case 101:
  4131. case 85:
  4132. case 229:
  4133. case 213:
  4134. case 37:
  4135. case 21:
  4136. block = "DB_HTILE";
  4137. break;
  4138. case 167:
  4139. case 151:
  4140. case 103:
  4141. case 87:
  4142. case 231:
  4143. case 215:
  4144. case 39:
  4145. case 23:
  4146. block = "DB_STEN";
  4147. break;
  4148. case 72:
  4149. case 68:
  4150. case 64:
  4151. case 8:
  4152. case 4:
  4153. case 0:
  4154. case 136:
  4155. case 132:
  4156. case 128:
  4157. case 200:
  4158. case 196:
  4159. case 192:
  4160. block = "TC";
  4161. break;
  4162. case 112:
  4163. case 48:
  4164. block = "CP";
  4165. break;
  4166. case 49:
  4167. case 177:
  4168. case 50:
  4169. case 178:
  4170. block = "SH";
  4171. break;
  4172. case 53:
  4173. case 190:
  4174. block = "VGT";
  4175. break;
  4176. case 117:
  4177. block = "IH";
  4178. break;
  4179. case 51:
  4180. case 115:
  4181. block = "RLC";
  4182. break;
  4183. case 119:
  4184. case 183:
  4185. block = "DMA0";
  4186. break;
  4187. case 61:
  4188. block = "DMA1";
  4189. break;
  4190. case 248:
  4191. case 120:
  4192. block = "HDP";
  4193. break;
  4194. default:
  4195. block = "unknown";
  4196. break;
  4197. }
  4198. } else {
  4199. switch (mc_id) {
  4200. case 32:
  4201. case 16:
  4202. case 96:
  4203. case 80:
  4204. case 160:
  4205. case 144:
  4206. case 224:
  4207. case 208:
  4208. block = "CB";
  4209. break;
  4210. case 33:
  4211. case 17:
  4212. case 97:
  4213. case 81:
  4214. case 161:
  4215. case 145:
  4216. case 225:
  4217. case 209:
  4218. block = "CB_FMASK";
  4219. break;
  4220. case 34:
  4221. case 18:
  4222. case 98:
  4223. case 82:
  4224. case 162:
  4225. case 146:
  4226. case 226:
  4227. case 210:
  4228. block = "CB_CMASK";
  4229. break;
  4230. case 35:
  4231. case 19:
  4232. case 99:
  4233. case 83:
  4234. case 163:
  4235. case 147:
  4236. case 227:
  4237. case 211:
  4238. block = "CB_IMMED";
  4239. break;
  4240. case 36:
  4241. case 20:
  4242. case 100:
  4243. case 84:
  4244. case 164:
  4245. case 148:
  4246. case 228:
  4247. case 212:
  4248. block = "DB";
  4249. break;
  4250. case 37:
  4251. case 21:
  4252. case 101:
  4253. case 85:
  4254. case 165:
  4255. case 149:
  4256. case 229:
  4257. case 213:
  4258. block = "DB_HTILE";
  4259. break;
  4260. case 39:
  4261. case 23:
  4262. case 103:
  4263. case 87:
  4264. case 167:
  4265. case 151:
  4266. case 231:
  4267. case 215:
  4268. block = "DB_STEN";
  4269. break;
  4270. case 72:
  4271. case 68:
  4272. case 8:
  4273. case 4:
  4274. case 136:
  4275. case 132:
  4276. case 200:
  4277. case 196:
  4278. block = "TC";
  4279. break;
  4280. case 112:
  4281. case 48:
  4282. block = "CP";
  4283. break;
  4284. case 49:
  4285. case 177:
  4286. case 50:
  4287. case 178:
  4288. block = "SH";
  4289. break;
  4290. case 53:
  4291. block = "VGT";
  4292. break;
  4293. case 117:
  4294. block = "IH";
  4295. break;
  4296. case 51:
  4297. case 115:
  4298. block = "RLC";
  4299. break;
  4300. case 119:
  4301. case 183:
  4302. block = "DMA0";
  4303. break;
  4304. case 61:
  4305. block = "DMA1";
  4306. break;
  4307. case 248:
  4308. case 120:
  4309. block = "HDP";
  4310. break;
  4311. default:
  4312. block = "unknown";
  4313. break;
  4314. }
  4315. }
  4316. printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
  4317. protections, vmid, addr,
  4318. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  4319. block, mc_id);
  4320. }
  4321. /**
  4322. * si_vm_set_page - update the page tables using the CP
  4323. *
  4324. * @rdev: radeon_device pointer
  4325. * @ib: indirect buffer to fill with commands
  4326. * @pe: addr of the page entry
  4327. * @addr: dst addr to write into pe
  4328. * @count: number of page entries to update
  4329. * @incr: increase next addr by incr bytes
  4330. * @flags: access flags
  4331. *
  4332. * Update the page tables using the CP (SI).
  4333. */
  4334. void si_vm_set_page(struct radeon_device *rdev,
  4335. struct radeon_ib *ib,
  4336. uint64_t pe,
  4337. uint64_t addr, unsigned count,
  4338. uint32_t incr, uint32_t flags)
  4339. {
  4340. uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
  4341. uint64_t value;
  4342. unsigned ndw;
  4343. if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
  4344. while (count) {
  4345. ndw = 2 + count * 2;
  4346. if (ndw > 0x3FFE)
  4347. ndw = 0x3FFE;
  4348. ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
  4349. ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
  4350. WRITE_DATA_DST_SEL(1));
  4351. ib->ptr[ib->length_dw++] = pe;
  4352. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  4353. for (; ndw > 2; ndw -= 2, --count, pe += 8) {
  4354. if (flags & RADEON_VM_PAGE_SYSTEM) {
  4355. value = radeon_vm_map_gart(rdev, addr);
  4356. value &= 0xFFFFFFFFFFFFF000ULL;
  4357. } else if (flags & RADEON_VM_PAGE_VALID) {
  4358. value = addr;
  4359. } else {
  4360. value = 0;
  4361. }
  4362. addr += incr;
  4363. value |= r600_flags;
  4364. ib->ptr[ib->length_dw++] = value;
  4365. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  4366. }
  4367. }
  4368. } else {
  4369. /* DMA */
  4370. si_dma_vm_set_page(rdev, ib, pe, addr, count, incr, flags);
  4371. }
  4372. }
  4373. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  4374. {
  4375. struct radeon_ring *ring = &rdev->ring[ridx];
  4376. if (vm == NULL)
  4377. return;
  4378. /* write new base address */
  4379. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4380. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4381. WRITE_DATA_DST_SEL(0)));
  4382. if (vm->id < 8) {
  4383. radeon_ring_write(ring,
  4384. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  4385. } else {
  4386. radeon_ring_write(ring,
  4387. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  4388. }
  4389. radeon_ring_write(ring, 0);
  4390. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  4391. /* flush hdp cache */
  4392. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4393. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4394. WRITE_DATA_DST_SEL(0)));
  4395. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  4396. radeon_ring_write(ring, 0);
  4397. radeon_ring_write(ring, 0x1);
  4398. /* bits 0-15 are the VM contexts0-15 */
  4399. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4400. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4401. WRITE_DATA_DST_SEL(0)));
  4402. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  4403. radeon_ring_write(ring, 0);
  4404. radeon_ring_write(ring, 1 << vm->id);
  4405. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  4406. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  4407. radeon_ring_write(ring, 0x0);
  4408. }
  4409. /*
  4410. * Power and clock gating
  4411. */
  4412. static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
  4413. {
  4414. int i;
  4415. for (i = 0; i < rdev->usec_timeout; i++) {
  4416. if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
  4417. break;
  4418. udelay(1);
  4419. }
  4420. for (i = 0; i < rdev->usec_timeout; i++) {
  4421. if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
  4422. break;
  4423. udelay(1);
  4424. }
  4425. }
  4426. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  4427. bool enable)
  4428. {
  4429. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  4430. u32 mask;
  4431. int i;
  4432. if (enable)
  4433. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4434. else
  4435. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4436. WREG32(CP_INT_CNTL_RING0, tmp);
  4437. if (!enable) {
  4438. /* read a gfx register */
  4439. tmp = RREG32(DB_DEPTH_INFO);
  4440. mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
  4441. for (i = 0; i < rdev->usec_timeout; i++) {
  4442. if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
  4443. break;
  4444. udelay(1);
  4445. }
  4446. }
  4447. }
  4448. static void si_set_uvd_dcm(struct radeon_device *rdev,
  4449. bool sw_mode)
  4450. {
  4451. u32 tmp, tmp2;
  4452. tmp = RREG32(UVD_CGC_CTRL);
  4453. tmp &= ~(CLK_OD_MASK | CG_DT_MASK);
  4454. tmp |= DCM | CG_DT(1) | CLK_OD(4);
  4455. if (sw_mode) {
  4456. tmp &= ~0x7ffff800;
  4457. tmp2 = DYN_OR_EN | DYN_RR_EN | G_DIV_ID(7);
  4458. } else {
  4459. tmp |= 0x7ffff800;
  4460. tmp2 = 0;
  4461. }
  4462. WREG32(UVD_CGC_CTRL, tmp);
  4463. WREG32_UVD_CTX(UVD_CGC_CTRL2, tmp2);
  4464. }
  4465. void si_init_uvd_internal_cg(struct radeon_device *rdev)
  4466. {
  4467. bool hw_mode = true;
  4468. if (hw_mode) {
  4469. si_set_uvd_dcm(rdev, false);
  4470. } else {
  4471. u32 tmp = RREG32(UVD_CGC_CTRL);
  4472. tmp &= ~DCM;
  4473. WREG32(UVD_CGC_CTRL, tmp);
  4474. }
  4475. }
  4476. static u32 si_halt_rlc(struct radeon_device *rdev)
  4477. {
  4478. u32 data, orig;
  4479. orig = data = RREG32(RLC_CNTL);
  4480. if (data & RLC_ENABLE) {
  4481. data &= ~RLC_ENABLE;
  4482. WREG32(RLC_CNTL, data);
  4483. si_wait_for_rlc_serdes(rdev);
  4484. }
  4485. return orig;
  4486. }
  4487. static void si_update_rlc(struct radeon_device *rdev, u32 rlc)
  4488. {
  4489. u32 tmp;
  4490. tmp = RREG32(RLC_CNTL);
  4491. if (tmp != rlc)
  4492. WREG32(RLC_CNTL, rlc);
  4493. }
  4494. static void si_enable_dma_pg(struct radeon_device *rdev, bool enable)
  4495. {
  4496. u32 data, orig;
  4497. orig = data = RREG32(DMA_PG);
  4498. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA))
  4499. data |= PG_CNTL_ENABLE;
  4500. else
  4501. data &= ~PG_CNTL_ENABLE;
  4502. if (orig != data)
  4503. WREG32(DMA_PG, data);
  4504. }
  4505. static void si_init_dma_pg(struct radeon_device *rdev)
  4506. {
  4507. u32 tmp;
  4508. WREG32(DMA_PGFSM_WRITE, 0x00002000);
  4509. WREG32(DMA_PGFSM_CONFIG, 0x100010ff);
  4510. for (tmp = 0; tmp < 5; tmp++)
  4511. WREG32(DMA_PGFSM_WRITE, 0);
  4512. }
  4513. static void si_enable_gfx_cgpg(struct radeon_device *rdev,
  4514. bool enable)
  4515. {
  4516. u32 tmp;
  4517. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_CG)) {
  4518. tmp = RLC_PUD(0x10) | RLC_PDD(0x10) | RLC_TTPD(0x10) | RLC_MSD(0x10);
  4519. WREG32(RLC_TTOP_D, tmp);
  4520. tmp = RREG32(RLC_PG_CNTL);
  4521. tmp |= GFX_PG_ENABLE;
  4522. WREG32(RLC_PG_CNTL, tmp);
  4523. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4524. tmp |= AUTO_PG_EN;
  4525. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4526. } else {
  4527. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4528. tmp &= ~AUTO_PG_EN;
  4529. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4530. tmp = RREG32(DB_RENDER_CONTROL);
  4531. }
  4532. }
  4533. static void si_init_gfx_cgpg(struct radeon_device *rdev)
  4534. {
  4535. u32 tmp;
  4536. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4537. tmp = RREG32(RLC_PG_CNTL);
  4538. tmp |= GFX_PG_SRC;
  4539. WREG32(RLC_PG_CNTL, tmp);
  4540. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4541. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4542. tmp &= ~GRBM_REG_SGIT_MASK;
  4543. tmp |= GRBM_REG_SGIT(0x700);
  4544. tmp &= ~PG_AFTER_GRBM_REG_ST_MASK;
  4545. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4546. }
  4547. static u32 si_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
  4548. {
  4549. u32 mask = 0, tmp, tmp1;
  4550. int i;
  4551. si_select_se_sh(rdev, se, sh);
  4552. tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  4553. tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  4554. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4555. tmp &= 0xffff0000;
  4556. tmp |= tmp1;
  4557. tmp >>= 16;
  4558. for (i = 0; i < rdev->config.si.max_cu_per_sh; i ++) {
  4559. mask <<= 1;
  4560. mask |= 1;
  4561. }
  4562. return (~tmp) & mask;
  4563. }
  4564. static void si_init_ao_cu_mask(struct radeon_device *rdev)
  4565. {
  4566. u32 i, j, k, active_cu_number = 0;
  4567. u32 mask, counter, cu_bitmap;
  4568. u32 tmp = 0;
  4569. for (i = 0; i < rdev->config.si.max_shader_engines; i++) {
  4570. for (j = 0; j < rdev->config.si.max_sh_per_se; j++) {
  4571. mask = 1;
  4572. cu_bitmap = 0;
  4573. counter = 0;
  4574. for (k = 0; k < rdev->config.si.max_cu_per_sh; k++) {
  4575. if (si_get_cu_active_bitmap(rdev, i, j) & mask) {
  4576. if (counter < 2)
  4577. cu_bitmap |= mask;
  4578. counter++;
  4579. }
  4580. mask <<= 1;
  4581. }
  4582. active_cu_number += counter;
  4583. tmp |= (cu_bitmap << (i * 16 + j * 8));
  4584. }
  4585. }
  4586. WREG32(RLC_PG_AO_CU_MASK, tmp);
  4587. tmp = RREG32(RLC_MAX_PG_CU);
  4588. tmp &= ~MAX_PU_CU_MASK;
  4589. tmp |= MAX_PU_CU(active_cu_number);
  4590. WREG32(RLC_MAX_PG_CU, tmp);
  4591. }
  4592. static void si_enable_cgcg(struct radeon_device *rdev,
  4593. bool enable)
  4594. {
  4595. u32 data, orig, tmp;
  4596. orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
  4597. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
  4598. si_enable_gui_idle_interrupt(rdev, true);
  4599. WREG32(RLC_GCPM_GENERAL_3, 0x00000080);
  4600. tmp = si_halt_rlc(rdev);
  4601. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4602. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4603. WREG32(RLC_SERDES_WR_CTRL, 0x00b000ff);
  4604. si_wait_for_rlc_serdes(rdev);
  4605. si_update_rlc(rdev, tmp);
  4606. WREG32(RLC_SERDES_WR_CTRL, 0x007000ff);
  4607. data |= CGCG_EN | CGLS_EN;
  4608. } else {
  4609. si_enable_gui_idle_interrupt(rdev, false);
  4610. RREG32(CB_CGTT_SCLK_CTRL);
  4611. RREG32(CB_CGTT_SCLK_CTRL);
  4612. RREG32(CB_CGTT_SCLK_CTRL);
  4613. RREG32(CB_CGTT_SCLK_CTRL);
  4614. data &= ~(CGCG_EN | CGLS_EN);
  4615. }
  4616. if (orig != data)
  4617. WREG32(RLC_CGCG_CGLS_CTRL, data);
  4618. }
  4619. static void si_enable_mgcg(struct radeon_device *rdev,
  4620. bool enable)
  4621. {
  4622. u32 data, orig, tmp = 0;
  4623. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
  4624. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4625. data = 0x96940200;
  4626. if (orig != data)
  4627. WREG32(CGTS_SM_CTRL_REG, data);
  4628. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
  4629. orig = data = RREG32(CP_MEM_SLP_CNTL);
  4630. data |= CP_MEM_LS_EN;
  4631. if (orig != data)
  4632. WREG32(CP_MEM_SLP_CNTL, data);
  4633. }
  4634. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4635. data &= 0xffffffc0;
  4636. if (orig != data)
  4637. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4638. tmp = si_halt_rlc(rdev);
  4639. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4640. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4641. WREG32(RLC_SERDES_WR_CTRL, 0x00d000ff);
  4642. si_update_rlc(rdev, tmp);
  4643. } else {
  4644. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4645. data |= 0x00000003;
  4646. if (orig != data)
  4647. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4648. data = RREG32(CP_MEM_SLP_CNTL);
  4649. if (data & CP_MEM_LS_EN) {
  4650. data &= ~CP_MEM_LS_EN;
  4651. WREG32(CP_MEM_SLP_CNTL, data);
  4652. }
  4653. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4654. data |= LS_OVERRIDE | OVERRIDE;
  4655. if (orig != data)
  4656. WREG32(CGTS_SM_CTRL_REG, data);
  4657. tmp = si_halt_rlc(rdev);
  4658. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4659. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4660. WREG32(RLC_SERDES_WR_CTRL, 0x00e000ff);
  4661. si_update_rlc(rdev, tmp);
  4662. }
  4663. }
  4664. static void si_enable_uvd_mgcg(struct radeon_device *rdev,
  4665. bool enable)
  4666. {
  4667. u32 orig, data, tmp;
  4668. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
  4669. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4670. tmp |= 0x3fff;
  4671. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4672. orig = data = RREG32(UVD_CGC_CTRL);
  4673. data |= DCM;
  4674. if (orig != data)
  4675. WREG32(UVD_CGC_CTRL, data);
  4676. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0);
  4677. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0);
  4678. } else {
  4679. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4680. tmp &= ~0x3fff;
  4681. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4682. orig = data = RREG32(UVD_CGC_CTRL);
  4683. data &= ~DCM;
  4684. if (orig != data)
  4685. WREG32(UVD_CGC_CTRL, data);
  4686. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0xffffffff);
  4687. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0xffffffff);
  4688. }
  4689. }
  4690. static const u32 mc_cg_registers[] =
  4691. {
  4692. MC_HUB_MISC_HUB_CG,
  4693. MC_HUB_MISC_SIP_CG,
  4694. MC_HUB_MISC_VM_CG,
  4695. MC_XPB_CLK_GAT,
  4696. ATC_MISC_CG,
  4697. MC_CITF_MISC_WR_CG,
  4698. MC_CITF_MISC_RD_CG,
  4699. MC_CITF_MISC_VM_CG,
  4700. VM_L2_CG,
  4701. };
  4702. static void si_enable_mc_ls(struct radeon_device *rdev,
  4703. bool enable)
  4704. {
  4705. int i;
  4706. u32 orig, data;
  4707. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4708. orig = data = RREG32(mc_cg_registers[i]);
  4709. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
  4710. data |= MC_LS_ENABLE;
  4711. else
  4712. data &= ~MC_LS_ENABLE;
  4713. if (data != orig)
  4714. WREG32(mc_cg_registers[i], data);
  4715. }
  4716. }
  4717. static void si_enable_mc_mgcg(struct radeon_device *rdev,
  4718. bool enable)
  4719. {
  4720. int i;
  4721. u32 orig, data;
  4722. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4723. orig = data = RREG32(mc_cg_registers[i]);
  4724. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
  4725. data |= MC_CG_ENABLE;
  4726. else
  4727. data &= ~MC_CG_ENABLE;
  4728. if (data != orig)
  4729. WREG32(mc_cg_registers[i], data);
  4730. }
  4731. }
  4732. static void si_enable_dma_mgcg(struct radeon_device *rdev,
  4733. bool enable)
  4734. {
  4735. u32 orig, data, offset;
  4736. int i;
  4737. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
  4738. for (i = 0; i < 2; i++) {
  4739. if (i == 0)
  4740. offset = DMA0_REGISTER_OFFSET;
  4741. else
  4742. offset = DMA1_REGISTER_OFFSET;
  4743. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4744. data &= ~MEM_POWER_OVERRIDE;
  4745. if (data != orig)
  4746. WREG32(DMA_POWER_CNTL + offset, data);
  4747. WREG32(DMA_CLK_CTRL + offset, 0x00000100);
  4748. }
  4749. } else {
  4750. for (i = 0; i < 2; i++) {
  4751. if (i == 0)
  4752. offset = DMA0_REGISTER_OFFSET;
  4753. else
  4754. offset = DMA1_REGISTER_OFFSET;
  4755. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4756. data |= MEM_POWER_OVERRIDE;
  4757. if (data != orig)
  4758. WREG32(DMA_POWER_CNTL + offset, data);
  4759. orig = data = RREG32(DMA_CLK_CTRL + offset);
  4760. data = 0xff000000;
  4761. if (data != orig)
  4762. WREG32(DMA_CLK_CTRL + offset, data);
  4763. }
  4764. }
  4765. }
  4766. static void si_enable_bif_mgls(struct radeon_device *rdev,
  4767. bool enable)
  4768. {
  4769. u32 orig, data;
  4770. orig = data = RREG32_PCIE(PCIE_CNTL2);
  4771. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
  4772. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4773. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
  4774. else
  4775. data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4776. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
  4777. if (orig != data)
  4778. WREG32_PCIE(PCIE_CNTL2, data);
  4779. }
  4780. static void si_enable_hdp_mgcg(struct radeon_device *rdev,
  4781. bool enable)
  4782. {
  4783. u32 orig, data;
  4784. orig = data = RREG32(HDP_HOST_PATH_CNTL);
  4785. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
  4786. data &= ~CLOCK_GATING_DIS;
  4787. else
  4788. data |= CLOCK_GATING_DIS;
  4789. if (orig != data)
  4790. WREG32(HDP_HOST_PATH_CNTL, data);
  4791. }
  4792. static void si_enable_hdp_ls(struct radeon_device *rdev,
  4793. bool enable)
  4794. {
  4795. u32 orig, data;
  4796. orig = data = RREG32(HDP_MEM_POWER_LS);
  4797. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
  4798. data |= HDP_LS_ENABLE;
  4799. else
  4800. data &= ~HDP_LS_ENABLE;
  4801. if (orig != data)
  4802. WREG32(HDP_MEM_POWER_LS, data);
  4803. }
  4804. void si_update_cg(struct radeon_device *rdev,
  4805. u32 block, bool enable)
  4806. {
  4807. if (block & RADEON_CG_BLOCK_GFX) {
  4808. /* order matters! */
  4809. if (enable) {
  4810. si_enable_mgcg(rdev, true);
  4811. si_enable_cgcg(rdev, true);
  4812. } else {
  4813. si_enable_cgcg(rdev, false);
  4814. si_enable_mgcg(rdev, false);
  4815. }
  4816. }
  4817. if (block & RADEON_CG_BLOCK_MC) {
  4818. si_enable_mc_mgcg(rdev, enable);
  4819. si_enable_mc_ls(rdev, enable);
  4820. }
  4821. if (block & RADEON_CG_BLOCK_SDMA) {
  4822. si_enable_dma_mgcg(rdev, enable);
  4823. }
  4824. if (block & RADEON_CG_BLOCK_BIF) {
  4825. si_enable_bif_mgls(rdev, enable);
  4826. }
  4827. if (block & RADEON_CG_BLOCK_UVD) {
  4828. if (rdev->has_uvd) {
  4829. si_enable_uvd_mgcg(rdev, enable);
  4830. }
  4831. }
  4832. if (block & RADEON_CG_BLOCK_HDP) {
  4833. si_enable_hdp_mgcg(rdev, enable);
  4834. si_enable_hdp_ls(rdev, enable);
  4835. }
  4836. }
  4837. static void si_init_cg(struct radeon_device *rdev)
  4838. {
  4839. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4840. RADEON_CG_BLOCK_MC |
  4841. RADEON_CG_BLOCK_SDMA |
  4842. RADEON_CG_BLOCK_BIF |
  4843. RADEON_CG_BLOCK_HDP), true);
  4844. if (rdev->has_uvd) {
  4845. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
  4846. si_init_uvd_internal_cg(rdev);
  4847. }
  4848. }
  4849. static void si_fini_cg(struct radeon_device *rdev)
  4850. {
  4851. if (rdev->has_uvd) {
  4852. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
  4853. }
  4854. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4855. RADEON_CG_BLOCK_MC |
  4856. RADEON_CG_BLOCK_SDMA |
  4857. RADEON_CG_BLOCK_BIF |
  4858. RADEON_CG_BLOCK_HDP), false);
  4859. }
  4860. u32 si_get_csb_size(struct radeon_device *rdev)
  4861. {
  4862. u32 count = 0;
  4863. const struct cs_section_def *sect = NULL;
  4864. const struct cs_extent_def *ext = NULL;
  4865. if (rdev->rlc.cs_data == NULL)
  4866. return 0;
  4867. /* begin clear state */
  4868. count += 2;
  4869. /* context control state */
  4870. count += 3;
  4871. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4872. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4873. if (sect->id == SECT_CONTEXT)
  4874. count += 2 + ext->reg_count;
  4875. else
  4876. return 0;
  4877. }
  4878. }
  4879. /* pa_sc_raster_config */
  4880. count += 3;
  4881. /* end clear state */
  4882. count += 2;
  4883. /* clear state */
  4884. count += 2;
  4885. return count;
  4886. }
  4887. void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
  4888. {
  4889. u32 count = 0, i;
  4890. const struct cs_section_def *sect = NULL;
  4891. const struct cs_extent_def *ext = NULL;
  4892. if (rdev->rlc.cs_data == NULL)
  4893. return;
  4894. if (buffer == NULL)
  4895. return;
  4896. buffer[count++] = PACKET3(PACKET3_PREAMBLE_CNTL, 0);
  4897. buffer[count++] = PACKET3_PREAMBLE_BEGIN_CLEAR_STATE;
  4898. buffer[count++] = PACKET3(PACKET3_CONTEXT_CONTROL, 1);
  4899. buffer[count++] = 0x80000000;
  4900. buffer[count++] = 0x80000000;
  4901. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4902. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4903. if (sect->id == SECT_CONTEXT) {
  4904. buffer[count++] = PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count);
  4905. buffer[count++] = ext->reg_index - 0xa000;
  4906. for (i = 0; i < ext->reg_count; i++)
  4907. buffer[count++] = ext->extent[i];
  4908. } else {
  4909. return;
  4910. }
  4911. }
  4912. }
  4913. buffer[count++] = PACKET3(PACKET3_SET_CONTEXT_REG, 1);
  4914. buffer[count++] = PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START;
  4915. switch (rdev->family) {
  4916. case CHIP_TAHITI:
  4917. case CHIP_PITCAIRN:
  4918. buffer[count++] = 0x2a00126a;
  4919. break;
  4920. case CHIP_VERDE:
  4921. buffer[count++] = 0x0000124a;
  4922. break;
  4923. case CHIP_OLAND:
  4924. buffer[count++] = 0x00000082;
  4925. break;
  4926. case CHIP_HAINAN:
  4927. buffer[count++] = 0x00000000;
  4928. break;
  4929. default:
  4930. buffer[count++] = 0x00000000;
  4931. break;
  4932. }
  4933. buffer[count++] = PACKET3(PACKET3_PREAMBLE_CNTL, 0);
  4934. buffer[count++] = PACKET3_PREAMBLE_END_CLEAR_STATE;
  4935. buffer[count++] = PACKET3(PACKET3_CLEAR_STATE, 0);
  4936. buffer[count++] = 0;
  4937. }
  4938. static void si_init_pg(struct radeon_device *rdev)
  4939. {
  4940. if (rdev->pg_flags) {
  4941. if (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA) {
  4942. si_init_dma_pg(rdev);
  4943. }
  4944. si_init_ao_cu_mask(rdev);
  4945. if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_CG) {
  4946. si_init_gfx_cgpg(rdev);
  4947. }
  4948. si_enable_dma_pg(rdev, true);
  4949. si_enable_gfx_cgpg(rdev, true);
  4950. } else {
  4951. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4952. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4953. }
  4954. }
  4955. static void si_fini_pg(struct radeon_device *rdev)
  4956. {
  4957. if (rdev->pg_flags) {
  4958. si_enable_dma_pg(rdev, false);
  4959. si_enable_gfx_cgpg(rdev, false);
  4960. }
  4961. }
  4962. /*
  4963. * RLC
  4964. */
  4965. void si_rlc_reset(struct radeon_device *rdev)
  4966. {
  4967. u32 tmp = RREG32(GRBM_SOFT_RESET);
  4968. tmp |= SOFT_RESET_RLC;
  4969. WREG32(GRBM_SOFT_RESET, tmp);
  4970. udelay(50);
  4971. tmp &= ~SOFT_RESET_RLC;
  4972. WREG32(GRBM_SOFT_RESET, tmp);
  4973. udelay(50);
  4974. }
  4975. static void si_rlc_stop(struct radeon_device *rdev)
  4976. {
  4977. WREG32(RLC_CNTL, 0);
  4978. si_enable_gui_idle_interrupt(rdev, false);
  4979. si_wait_for_rlc_serdes(rdev);
  4980. }
  4981. static void si_rlc_start(struct radeon_device *rdev)
  4982. {
  4983. WREG32(RLC_CNTL, RLC_ENABLE);
  4984. si_enable_gui_idle_interrupt(rdev, true);
  4985. udelay(50);
  4986. }
  4987. static bool si_lbpw_supported(struct radeon_device *rdev)
  4988. {
  4989. u32 tmp;
  4990. /* Enable LBPW only for DDR3 */
  4991. tmp = RREG32(MC_SEQ_MISC0);
  4992. if ((tmp & 0xF0000000) == 0xB0000000)
  4993. return true;
  4994. return false;
  4995. }
  4996. static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
  4997. {
  4998. u32 tmp;
  4999. tmp = RREG32(RLC_LB_CNTL);
  5000. if (enable)
  5001. tmp |= LOAD_BALANCE_ENABLE;
  5002. else
  5003. tmp &= ~LOAD_BALANCE_ENABLE;
  5004. WREG32(RLC_LB_CNTL, tmp);
  5005. if (!enable) {
  5006. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5007. WREG32(SPI_LB_CU_MASK, 0x00ff);
  5008. }
  5009. }
  5010. static int si_rlc_resume(struct radeon_device *rdev)
  5011. {
  5012. u32 i;
  5013. const __be32 *fw_data;
  5014. if (!rdev->rlc_fw)
  5015. return -EINVAL;
  5016. si_rlc_stop(rdev);
  5017. si_rlc_reset(rdev);
  5018. si_init_pg(rdev);
  5019. si_init_cg(rdev);
  5020. WREG32(RLC_RL_BASE, 0);
  5021. WREG32(RLC_RL_SIZE, 0);
  5022. WREG32(RLC_LB_CNTL, 0);
  5023. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  5024. WREG32(RLC_LB_CNTR_INIT, 0);
  5025. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  5026. WREG32(RLC_MC_CNTL, 0);
  5027. WREG32(RLC_UCODE_CNTL, 0);
  5028. fw_data = (const __be32 *)rdev->rlc_fw->data;
  5029. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  5030. WREG32(RLC_UCODE_ADDR, i);
  5031. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  5032. }
  5033. WREG32(RLC_UCODE_ADDR, 0);
  5034. si_enable_lbpw(rdev, si_lbpw_supported(rdev));
  5035. si_rlc_start(rdev);
  5036. return 0;
  5037. }
  5038. static void si_enable_interrupts(struct radeon_device *rdev)
  5039. {
  5040. u32 ih_cntl = RREG32(IH_CNTL);
  5041. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5042. ih_cntl |= ENABLE_INTR;
  5043. ih_rb_cntl |= IH_RB_ENABLE;
  5044. WREG32(IH_CNTL, ih_cntl);
  5045. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5046. rdev->ih.enabled = true;
  5047. }
  5048. static void si_disable_interrupts(struct radeon_device *rdev)
  5049. {
  5050. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5051. u32 ih_cntl = RREG32(IH_CNTL);
  5052. ih_rb_cntl &= ~IH_RB_ENABLE;
  5053. ih_cntl &= ~ENABLE_INTR;
  5054. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5055. WREG32(IH_CNTL, ih_cntl);
  5056. /* set rptr, wptr to 0 */
  5057. WREG32(IH_RB_RPTR, 0);
  5058. WREG32(IH_RB_WPTR, 0);
  5059. rdev->ih.enabled = false;
  5060. rdev->ih.rptr = 0;
  5061. }
  5062. static void si_disable_interrupt_state(struct radeon_device *rdev)
  5063. {
  5064. u32 tmp;
  5065. WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5066. WREG32(CP_INT_CNTL_RING1, 0);
  5067. WREG32(CP_INT_CNTL_RING2, 0);
  5068. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5069. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  5070. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5071. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  5072. WREG32(GRBM_INT_CNTL, 0);
  5073. if (rdev->num_crtc >= 2) {
  5074. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5075. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5076. }
  5077. if (rdev->num_crtc >= 4) {
  5078. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5079. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5080. }
  5081. if (rdev->num_crtc >= 6) {
  5082. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5083. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5084. }
  5085. if (rdev->num_crtc >= 2) {
  5086. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5087. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5088. }
  5089. if (rdev->num_crtc >= 4) {
  5090. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5091. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5092. }
  5093. if (rdev->num_crtc >= 6) {
  5094. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5095. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5096. }
  5097. if (!ASIC_IS_NODCE(rdev)) {
  5098. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  5099. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5100. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5101. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5102. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5103. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5104. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5105. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5106. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5107. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5108. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5109. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5110. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5111. }
  5112. }
  5113. static int si_irq_init(struct radeon_device *rdev)
  5114. {
  5115. int ret = 0;
  5116. int rb_bufsz;
  5117. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  5118. /* allocate ring */
  5119. ret = r600_ih_ring_alloc(rdev);
  5120. if (ret)
  5121. return ret;
  5122. /* disable irqs */
  5123. si_disable_interrupts(rdev);
  5124. /* init rlc */
  5125. ret = si_rlc_resume(rdev);
  5126. if (ret) {
  5127. r600_ih_ring_fini(rdev);
  5128. return ret;
  5129. }
  5130. /* setup interrupt control */
  5131. /* set dummy read address to ring address */
  5132. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  5133. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  5134. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  5135. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  5136. */
  5137. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  5138. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  5139. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  5140. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  5141. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  5142. rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
  5143. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  5144. IH_WPTR_OVERFLOW_CLEAR |
  5145. (rb_bufsz << 1));
  5146. if (rdev->wb.enabled)
  5147. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  5148. /* set the writeback address whether it's enabled or not */
  5149. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  5150. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  5151. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5152. /* set rptr, wptr to 0 */
  5153. WREG32(IH_RB_RPTR, 0);
  5154. WREG32(IH_RB_WPTR, 0);
  5155. /* Default settings for IH_CNTL (disabled at first) */
  5156. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  5157. /* RPTR_REARM only works if msi's are enabled */
  5158. if (rdev->msi_enabled)
  5159. ih_cntl |= RPTR_REARM;
  5160. WREG32(IH_CNTL, ih_cntl);
  5161. /* force the active interrupt state to all disabled */
  5162. si_disable_interrupt_state(rdev);
  5163. pci_set_master(rdev->pdev);
  5164. /* enable irqs */
  5165. si_enable_interrupts(rdev);
  5166. return ret;
  5167. }
  5168. int si_irq_set(struct radeon_device *rdev)
  5169. {
  5170. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  5171. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  5172. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  5173. u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  5174. u32 grbm_int_cntl = 0;
  5175. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  5176. u32 dma_cntl, dma_cntl1;
  5177. u32 thermal_int = 0;
  5178. if (!rdev->irq.installed) {
  5179. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  5180. return -EINVAL;
  5181. }
  5182. /* don't enable anything if the ih is disabled */
  5183. if (!rdev->ih.enabled) {
  5184. si_disable_interrupts(rdev);
  5185. /* force the active interrupt state to all disabled */
  5186. si_disable_interrupt_state(rdev);
  5187. return 0;
  5188. }
  5189. if (!ASIC_IS_NODCE(rdev)) {
  5190. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5191. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5192. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5193. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5194. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5195. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5196. }
  5197. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5198. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5199. thermal_int = RREG32(CG_THERMAL_INT) &
  5200. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  5201. /* enable CP interrupts on all rings */
  5202. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  5203. DRM_DEBUG("si_irq_set: sw int gfx\n");
  5204. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  5205. }
  5206. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  5207. DRM_DEBUG("si_irq_set: sw int cp1\n");
  5208. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  5209. }
  5210. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  5211. DRM_DEBUG("si_irq_set: sw int cp2\n");
  5212. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  5213. }
  5214. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  5215. DRM_DEBUG("si_irq_set: sw int dma\n");
  5216. dma_cntl |= TRAP_ENABLE;
  5217. }
  5218. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  5219. DRM_DEBUG("si_irq_set: sw int dma1\n");
  5220. dma_cntl1 |= TRAP_ENABLE;
  5221. }
  5222. if (rdev->irq.crtc_vblank_int[0] ||
  5223. atomic_read(&rdev->irq.pflip[0])) {
  5224. DRM_DEBUG("si_irq_set: vblank 0\n");
  5225. crtc1 |= VBLANK_INT_MASK;
  5226. }
  5227. if (rdev->irq.crtc_vblank_int[1] ||
  5228. atomic_read(&rdev->irq.pflip[1])) {
  5229. DRM_DEBUG("si_irq_set: vblank 1\n");
  5230. crtc2 |= VBLANK_INT_MASK;
  5231. }
  5232. if (rdev->irq.crtc_vblank_int[2] ||
  5233. atomic_read(&rdev->irq.pflip[2])) {
  5234. DRM_DEBUG("si_irq_set: vblank 2\n");
  5235. crtc3 |= VBLANK_INT_MASK;
  5236. }
  5237. if (rdev->irq.crtc_vblank_int[3] ||
  5238. atomic_read(&rdev->irq.pflip[3])) {
  5239. DRM_DEBUG("si_irq_set: vblank 3\n");
  5240. crtc4 |= VBLANK_INT_MASK;
  5241. }
  5242. if (rdev->irq.crtc_vblank_int[4] ||
  5243. atomic_read(&rdev->irq.pflip[4])) {
  5244. DRM_DEBUG("si_irq_set: vblank 4\n");
  5245. crtc5 |= VBLANK_INT_MASK;
  5246. }
  5247. if (rdev->irq.crtc_vblank_int[5] ||
  5248. atomic_read(&rdev->irq.pflip[5])) {
  5249. DRM_DEBUG("si_irq_set: vblank 5\n");
  5250. crtc6 |= VBLANK_INT_MASK;
  5251. }
  5252. if (rdev->irq.hpd[0]) {
  5253. DRM_DEBUG("si_irq_set: hpd 1\n");
  5254. hpd1 |= DC_HPDx_INT_EN;
  5255. }
  5256. if (rdev->irq.hpd[1]) {
  5257. DRM_DEBUG("si_irq_set: hpd 2\n");
  5258. hpd2 |= DC_HPDx_INT_EN;
  5259. }
  5260. if (rdev->irq.hpd[2]) {
  5261. DRM_DEBUG("si_irq_set: hpd 3\n");
  5262. hpd3 |= DC_HPDx_INT_EN;
  5263. }
  5264. if (rdev->irq.hpd[3]) {
  5265. DRM_DEBUG("si_irq_set: hpd 4\n");
  5266. hpd4 |= DC_HPDx_INT_EN;
  5267. }
  5268. if (rdev->irq.hpd[4]) {
  5269. DRM_DEBUG("si_irq_set: hpd 5\n");
  5270. hpd5 |= DC_HPDx_INT_EN;
  5271. }
  5272. if (rdev->irq.hpd[5]) {
  5273. DRM_DEBUG("si_irq_set: hpd 6\n");
  5274. hpd6 |= DC_HPDx_INT_EN;
  5275. }
  5276. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  5277. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  5278. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  5279. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  5280. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  5281. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  5282. if (rdev->irq.dpm_thermal) {
  5283. DRM_DEBUG("dpm thermal\n");
  5284. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  5285. }
  5286. if (rdev->num_crtc >= 2) {
  5287. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  5288. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  5289. }
  5290. if (rdev->num_crtc >= 4) {
  5291. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  5292. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  5293. }
  5294. if (rdev->num_crtc >= 6) {
  5295. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  5296. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  5297. }
  5298. if (rdev->num_crtc >= 2) {
  5299. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  5300. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  5301. }
  5302. if (rdev->num_crtc >= 4) {
  5303. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  5304. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  5305. }
  5306. if (rdev->num_crtc >= 6) {
  5307. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  5308. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  5309. }
  5310. if (!ASIC_IS_NODCE(rdev)) {
  5311. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  5312. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  5313. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  5314. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  5315. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  5316. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  5317. }
  5318. WREG32(CG_THERMAL_INT, thermal_int);
  5319. return 0;
  5320. }
  5321. static inline void si_irq_ack(struct radeon_device *rdev)
  5322. {
  5323. u32 tmp;
  5324. if (ASIC_IS_NODCE(rdev))
  5325. return;
  5326. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  5327. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  5328. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  5329. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  5330. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  5331. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  5332. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  5333. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  5334. if (rdev->num_crtc >= 4) {
  5335. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  5336. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  5337. }
  5338. if (rdev->num_crtc >= 6) {
  5339. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  5340. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  5341. }
  5342. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  5343. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5344. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  5345. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5346. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  5347. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  5348. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  5349. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  5350. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  5351. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  5352. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  5353. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  5354. if (rdev->num_crtc >= 4) {
  5355. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  5356. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5357. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  5358. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5359. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  5360. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  5361. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  5362. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  5363. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  5364. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  5365. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  5366. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  5367. }
  5368. if (rdev->num_crtc >= 6) {
  5369. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  5370. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5371. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  5372. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5373. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  5374. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  5375. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  5376. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  5377. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  5378. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  5379. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  5380. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  5381. }
  5382. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5383. tmp = RREG32(DC_HPD1_INT_CONTROL);
  5384. tmp |= DC_HPDx_INT_ACK;
  5385. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5386. }
  5387. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5388. tmp = RREG32(DC_HPD2_INT_CONTROL);
  5389. tmp |= DC_HPDx_INT_ACK;
  5390. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5391. }
  5392. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5393. tmp = RREG32(DC_HPD3_INT_CONTROL);
  5394. tmp |= DC_HPDx_INT_ACK;
  5395. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5396. }
  5397. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5398. tmp = RREG32(DC_HPD4_INT_CONTROL);
  5399. tmp |= DC_HPDx_INT_ACK;
  5400. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5401. }
  5402. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5403. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5404. tmp |= DC_HPDx_INT_ACK;
  5405. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5406. }
  5407. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5408. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5409. tmp |= DC_HPDx_INT_ACK;
  5410. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5411. }
  5412. }
  5413. static void si_irq_disable(struct radeon_device *rdev)
  5414. {
  5415. si_disable_interrupts(rdev);
  5416. /* Wait and acknowledge irq */
  5417. mdelay(1);
  5418. si_irq_ack(rdev);
  5419. si_disable_interrupt_state(rdev);
  5420. }
  5421. static void si_irq_suspend(struct radeon_device *rdev)
  5422. {
  5423. si_irq_disable(rdev);
  5424. si_rlc_stop(rdev);
  5425. }
  5426. static void si_irq_fini(struct radeon_device *rdev)
  5427. {
  5428. si_irq_suspend(rdev);
  5429. r600_ih_ring_fini(rdev);
  5430. }
  5431. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  5432. {
  5433. u32 wptr, tmp;
  5434. if (rdev->wb.enabled)
  5435. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  5436. else
  5437. wptr = RREG32(IH_RB_WPTR);
  5438. if (wptr & RB_OVERFLOW) {
  5439. /* When a ring buffer overflow happen start parsing interrupt
  5440. * from the last not overwritten vector (wptr + 16). Hopefully
  5441. * this should allow us to catchup.
  5442. */
  5443. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  5444. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  5445. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  5446. tmp = RREG32(IH_RB_CNTL);
  5447. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  5448. WREG32(IH_RB_CNTL, tmp);
  5449. }
  5450. return (wptr & rdev->ih.ptr_mask);
  5451. }
  5452. /* SI IV Ring
  5453. * Each IV ring entry is 128 bits:
  5454. * [7:0] - interrupt source id
  5455. * [31:8] - reserved
  5456. * [59:32] - interrupt source data
  5457. * [63:60] - reserved
  5458. * [71:64] - RINGID
  5459. * [79:72] - VMID
  5460. * [127:80] - reserved
  5461. */
  5462. int si_irq_process(struct radeon_device *rdev)
  5463. {
  5464. u32 wptr;
  5465. u32 rptr;
  5466. u32 src_id, src_data, ring_id;
  5467. u32 ring_index;
  5468. bool queue_hotplug = false;
  5469. bool queue_thermal = false;
  5470. u32 status, addr;
  5471. if (!rdev->ih.enabled || rdev->shutdown)
  5472. return IRQ_NONE;
  5473. wptr = si_get_ih_wptr(rdev);
  5474. restart_ih:
  5475. /* is somebody else already processing irqs? */
  5476. if (atomic_xchg(&rdev->ih.lock, 1))
  5477. return IRQ_NONE;
  5478. rptr = rdev->ih.rptr;
  5479. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  5480. /* Order reading of wptr vs. reading of IH ring data */
  5481. rmb();
  5482. /* display interrupts */
  5483. si_irq_ack(rdev);
  5484. while (rptr != wptr) {
  5485. /* wptr/rptr are in bytes! */
  5486. ring_index = rptr / 4;
  5487. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  5488. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  5489. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  5490. switch (src_id) {
  5491. case 1: /* D1 vblank/vline */
  5492. switch (src_data) {
  5493. case 0: /* D1 vblank */
  5494. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  5495. if (rdev->irq.crtc_vblank_int[0]) {
  5496. drm_handle_vblank(rdev->ddev, 0);
  5497. rdev->pm.vblank_sync = true;
  5498. wake_up(&rdev->irq.vblank_queue);
  5499. }
  5500. if (atomic_read(&rdev->irq.pflip[0]))
  5501. radeon_crtc_handle_flip(rdev, 0);
  5502. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  5503. DRM_DEBUG("IH: D1 vblank\n");
  5504. }
  5505. break;
  5506. case 1: /* D1 vline */
  5507. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  5508. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  5509. DRM_DEBUG("IH: D1 vline\n");
  5510. }
  5511. break;
  5512. default:
  5513. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5514. break;
  5515. }
  5516. break;
  5517. case 2: /* D2 vblank/vline */
  5518. switch (src_data) {
  5519. case 0: /* D2 vblank */
  5520. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  5521. if (rdev->irq.crtc_vblank_int[1]) {
  5522. drm_handle_vblank(rdev->ddev, 1);
  5523. rdev->pm.vblank_sync = true;
  5524. wake_up(&rdev->irq.vblank_queue);
  5525. }
  5526. if (atomic_read(&rdev->irq.pflip[1]))
  5527. radeon_crtc_handle_flip(rdev, 1);
  5528. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  5529. DRM_DEBUG("IH: D2 vblank\n");
  5530. }
  5531. break;
  5532. case 1: /* D2 vline */
  5533. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  5534. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  5535. DRM_DEBUG("IH: D2 vline\n");
  5536. }
  5537. break;
  5538. default:
  5539. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5540. break;
  5541. }
  5542. break;
  5543. case 3: /* D3 vblank/vline */
  5544. switch (src_data) {
  5545. case 0: /* D3 vblank */
  5546. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  5547. if (rdev->irq.crtc_vblank_int[2]) {
  5548. drm_handle_vblank(rdev->ddev, 2);
  5549. rdev->pm.vblank_sync = true;
  5550. wake_up(&rdev->irq.vblank_queue);
  5551. }
  5552. if (atomic_read(&rdev->irq.pflip[2]))
  5553. radeon_crtc_handle_flip(rdev, 2);
  5554. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  5555. DRM_DEBUG("IH: D3 vblank\n");
  5556. }
  5557. break;
  5558. case 1: /* D3 vline */
  5559. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  5560. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  5561. DRM_DEBUG("IH: D3 vline\n");
  5562. }
  5563. break;
  5564. default:
  5565. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5566. break;
  5567. }
  5568. break;
  5569. case 4: /* D4 vblank/vline */
  5570. switch (src_data) {
  5571. case 0: /* D4 vblank */
  5572. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  5573. if (rdev->irq.crtc_vblank_int[3]) {
  5574. drm_handle_vblank(rdev->ddev, 3);
  5575. rdev->pm.vblank_sync = true;
  5576. wake_up(&rdev->irq.vblank_queue);
  5577. }
  5578. if (atomic_read(&rdev->irq.pflip[3]))
  5579. radeon_crtc_handle_flip(rdev, 3);
  5580. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  5581. DRM_DEBUG("IH: D4 vblank\n");
  5582. }
  5583. break;
  5584. case 1: /* D4 vline */
  5585. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  5586. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  5587. DRM_DEBUG("IH: D4 vline\n");
  5588. }
  5589. break;
  5590. default:
  5591. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5592. break;
  5593. }
  5594. break;
  5595. case 5: /* D5 vblank/vline */
  5596. switch (src_data) {
  5597. case 0: /* D5 vblank */
  5598. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  5599. if (rdev->irq.crtc_vblank_int[4]) {
  5600. drm_handle_vblank(rdev->ddev, 4);
  5601. rdev->pm.vblank_sync = true;
  5602. wake_up(&rdev->irq.vblank_queue);
  5603. }
  5604. if (atomic_read(&rdev->irq.pflip[4]))
  5605. radeon_crtc_handle_flip(rdev, 4);
  5606. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  5607. DRM_DEBUG("IH: D5 vblank\n");
  5608. }
  5609. break;
  5610. case 1: /* D5 vline */
  5611. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  5612. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  5613. DRM_DEBUG("IH: D5 vline\n");
  5614. }
  5615. break;
  5616. default:
  5617. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5618. break;
  5619. }
  5620. break;
  5621. case 6: /* D6 vblank/vline */
  5622. switch (src_data) {
  5623. case 0: /* D6 vblank */
  5624. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  5625. if (rdev->irq.crtc_vblank_int[5]) {
  5626. drm_handle_vblank(rdev->ddev, 5);
  5627. rdev->pm.vblank_sync = true;
  5628. wake_up(&rdev->irq.vblank_queue);
  5629. }
  5630. if (atomic_read(&rdev->irq.pflip[5]))
  5631. radeon_crtc_handle_flip(rdev, 5);
  5632. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  5633. DRM_DEBUG("IH: D6 vblank\n");
  5634. }
  5635. break;
  5636. case 1: /* D6 vline */
  5637. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  5638. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  5639. DRM_DEBUG("IH: D6 vline\n");
  5640. }
  5641. break;
  5642. default:
  5643. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5644. break;
  5645. }
  5646. break;
  5647. case 42: /* HPD hotplug */
  5648. switch (src_data) {
  5649. case 0:
  5650. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5651. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  5652. queue_hotplug = true;
  5653. DRM_DEBUG("IH: HPD1\n");
  5654. }
  5655. break;
  5656. case 1:
  5657. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5658. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  5659. queue_hotplug = true;
  5660. DRM_DEBUG("IH: HPD2\n");
  5661. }
  5662. break;
  5663. case 2:
  5664. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5665. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  5666. queue_hotplug = true;
  5667. DRM_DEBUG("IH: HPD3\n");
  5668. }
  5669. break;
  5670. case 3:
  5671. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5672. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  5673. queue_hotplug = true;
  5674. DRM_DEBUG("IH: HPD4\n");
  5675. }
  5676. break;
  5677. case 4:
  5678. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5679. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  5680. queue_hotplug = true;
  5681. DRM_DEBUG("IH: HPD5\n");
  5682. }
  5683. break;
  5684. case 5:
  5685. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5686. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  5687. queue_hotplug = true;
  5688. DRM_DEBUG("IH: HPD6\n");
  5689. }
  5690. break;
  5691. default:
  5692. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5693. break;
  5694. }
  5695. break;
  5696. case 146:
  5697. case 147:
  5698. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  5699. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  5700. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  5701. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  5702. addr);
  5703. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  5704. status);
  5705. si_vm_decode_fault(rdev, status, addr);
  5706. /* reset addr and status */
  5707. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  5708. break;
  5709. case 176: /* RINGID0 CP_INT */
  5710. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5711. break;
  5712. case 177: /* RINGID1 CP_INT */
  5713. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5714. break;
  5715. case 178: /* RINGID2 CP_INT */
  5716. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5717. break;
  5718. case 181: /* CP EOP event */
  5719. DRM_DEBUG("IH: CP EOP\n");
  5720. switch (ring_id) {
  5721. case 0:
  5722. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5723. break;
  5724. case 1:
  5725. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5726. break;
  5727. case 2:
  5728. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5729. break;
  5730. }
  5731. break;
  5732. case 224: /* DMA trap event */
  5733. DRM_DEBUG("IH: DMA trap\n");
  5734. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  5735. break;
  5736. case 230: /* thermal low to high */
  5737. DRM_DEBUG("IH: thermal low to high\n");
  5738. rdev->pm.dpm.thermal.high_to_low = false;
  5739. queue_thermal = true;
  5740. break;
  5741. case 231: /* thermal high to low */
  5742. DRM_DEBUG("IH: thermal high to low\n");
  5743. rdev->pm.dpm.thermal.high_to_low = true;
  5744. queue_thermal = true;
  5745. break;
  5746. case 233: /* GUI IDLE */
  5747. DRM_DEBUG("IH: GUI idle\n");
  5748. break;
  5749. case 244: /* DMA trap event */
  5750. DRM_DEBUG("IH: DMA1 trap\n");
  5751. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5752. break;
  5753. default:
  5754. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5755. break;
  5756. }
  5757. /* wptr/rptr are in bytes! */
  5758. rptr += 16;
  5759. rptr &= rdev->ih.ptr_mask;
  5760. }
  5761. if (queue_hotplug)
  5762. schedule_work(&rdev->hotplug_work);
  5763. if (queue_thermal && rdev->pm.dpm_enabled)
  5764. schedule_work(&rdev->pm.dpm.thermal.work);
  5765. rdev->ih.rptr = rptr;
  5766. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  5767. atomic_set(&rdev->ih.lock, 0);
  5768. /* make sure wptr hasn't changed while processing */
  5769. wptr = si_get_ih_wptr(rdev);
  5770. if (wptr != rptr)
  5771. goto restart_ih;
  5772. return IRQ_HANDLED;
  5773. }
  5774. /*
  5775. * startup/shutdown callbacks
  5776. */
  5777. static int si_startup(struct radeon_device *rdev)
  5778. {
  5779. struct radeon_ring *ring;
  5780. int r;
  5781. /* enable pcie gen2/3 link */
  5782. si_pcie_gen3_enable(rdev);
  5783. /* enable aspm */
  5784. si_program_aspm(rdev);
  5785. /* scratch needs to be initialized before MC */
  5786. r = r600_vram_scratch_init(rdev);
  5787. if (r)
  5788. return r;
  5789. si_mc_program(rdev);
  5790. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  5791. !rdev->rlc_fw || !rdev->mc_fw) {
  5792. r = si_init_microcode(rdev);
  5793. if (r) {
  5794. DRM_ERROR("Failed to load firmware!\n");
  5795. return r;
  5796. }
  5797. }
  5798. r = si_mc_load_microcode(rdev);
  5799. if (r) {
  5800. DRM_ERROR("Failed to load MC firmware!\n");
  5801. return r;
  5802. }
  5803. r = si_pcie_gart_enable(rdev);
  5804. if (r)
  5805. return r;
  5806. si_gpu_init(rdev);
  5807. /* allocate rlc buffers */
  5808. if (rdev->family == CHIP_VERDE) {
  5809. rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
  5810. rdev->rlc.reg_list_size =
  5811. (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
  5812. }
  5813. rdev->rlc.cs_data = si_cs_data;
  5814. r = sumo_rlc_init(rdev);
  5815. if (r) {
  5816. DRM_ERROR("Failed to init rlc BOs!\n");
  5817. return r;
  5818. }
  5819. /* allocate wb buffer */
  5820. r = radeon_wb_init(rdev);
  5821. if (r)
  5822. return r;
  5823. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5824. if (r) {
  5825. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5826. return r;
  5827. }
  5828. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5829. if (r) {
  5830. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5831. return r;
  5832. }
  5833. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5834. if (r) {
  5835. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5836. return r;
  5837. }
  5838. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  5839. if (r) {
  5840. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5841. return r;
  5842. }
  5843. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5844. if (r) {
  5845. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5846. return r;
  5847. }
  5848. if (rdev->has_uvd) {
  5849. r = uvd_v2_2_resume(rdev);
  5850. if (!r) {
  5851. r = radeon_fence_driver_start_ring(rdev,
  5852. R600_RING_TYPE_UVD_INDEX);
  5853. if (r)
  5854. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  5855. }
  5856. if (r)
  5857. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5858. }
  5859. /* Enable IRQ */
  5860. if (!rdev->irq.installed) {
  5861. r = radeon_irq_kms_init(rdev);
  5862. if (r)
  5863. return r;
  5864. }
  5865. r = si_irq_init(rdev);
  5866. if (r) {
  5867. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5868. radeon_irq_kms_fini(rdev);
  5869. return r;
  5870. }
  5871. si_irq_set(rdev);
  5872. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5873. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5874. CP_RB0_RPTR, CP_RB0_WPTR,
  5875. RADEON_CP_PACKET2);
  5876. if (r)
  5877. return r;
  5878. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5879. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  5880. CP_RB1_RPTR, CP_RB1_WPTR,
  5881. RADEON_CP_PACKET2);
  5882. if (r)
  5883. return r;
  5884. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5885. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  5886. CP_RB2_RPTR, CP_RB2_WPTR,
  5887. RADEON_CP_PACKET2);
  5888. if (r)
  5889. return r;
  5890. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5891. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5892. DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
  5893. DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
  5894. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5895. if (r)
  5896. return r;
  5897. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  5898. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  5899. DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
  5900. DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
  5901. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5902. if (r)
  5903. return r;
  5904. r = si_cp_load_microcode(rdev);
  5905. if (r)
  5906. return r;
  5907. r = si_cp_resume(rdev);
  5908. if (r)
  5909. return r;
  5910. r = cayman_dma_resume(rdev);
  5911. if (r)
  5912. return r;
  5913. if (rdev->has_uvd) {
  5914. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5915. if (ring->ring_size) {
  5916. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  5917. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  5918. RADEON_CP_PACKET2);
  5919. if (!r)
  5920. r = uvd_v1_0_init(rdev);
  5921. if (r)
  5922. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  5923. }
  5924. }
  5925. r = radeon_ib_pool_init(rdev);
  5926. if (r) {
  5927. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5928. return r;
  5929. }
  5930. r = radeon_vm_manager_init(rdev);
  5931. if (r) {
  5932. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  5933. return r;
  5934. }
  5935. r = dce6_audio_init(rdev);
  5936. if (r)
  5937. return r;
  5938. return 0;
  5939. }
  5940. int si_resume(struct radeon_device *rdev)
  5941. {
  5942. int r;
  5943. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5944. * posting will perform necessary task to bring back GPU into good
  5945. * shape.
  5946. */
  5947. /* post card */
  5948. atom_asic_init(rdev->mode_info.atom_context);
  5949. /* init golden registers */
  5950. si_init_golden_registers(rdev);
  5951. rdev->accel_working = true;
  5952. r = si_startup(rdev);
  5953. if (r) {
  5954. DRM_ERROR("si startup failed on resume\n");
  5955. rdev->accel_working = false;
  5956. return r;
  5957. }
  5958. return r;
  5959. }
  5960. int si_suspend(struct radeon_device *rdev)
  5961. {
  5962. dce6_audio_fini(rdev);
  5963. radeon_vm_manager_fini(rdev);
  5964. si_cp_enable(rdev, false);
  5965. cayman_dma_stop(rdev);
  5966. if (rdev->has_uvd) {
  5967. uvd_v1_0_fini(rdev);
  5968. radeon_uvd_suspend(rdev);
  5969. }
  5970. si_fini_pg(rdev);
  5971. si_fini_cg(rdev);
  5972. si_irq_suspend(rdev);
  5973. radeon_wb_disable(rdev);
  5974. si_pcie_gart_disable(rdev);
  5975. return 0;
  5976. }
  5977. /* Plan is to move initialization in that function and use
  5978. * helper function so that radeon_device_init pretty much
  5979. * do nothing more than calling asic specific function. This
  5980. * should also allow to remove a bunch of callback function
  5981. * like vram_info.
  5982. */
  5983. int si_init(struct radeon_device *rdev)
  5984. {
  5985. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5986. int r;
  5987. /* Read BIOS */
  5988. if (!radeon_get_bios(rdev)) {
  5989. if (ASIC_IS_AVIVO(rdev))
  5990. return -EINVAL;
  5991. }
  5992. /* Must be an ATOMBIOS */
  5993. if (!rdev->is_atom_bios) {
  5994. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  5995. return -EINVAL;
  5996. }
  5997. r = radeon_atombios_init(rdev);
  5998. if (r)
  5999. return r;
  6000. /* Post card if necessary */
  6001. if (!radeon_card_posted(rdev)) {
  6002. if (!rdev->bios) {
  6003. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  6004. return -EINVAL;
  6005. }
  6006. DRM_INFO("GPU not posted. posting now...\n");
  6007. atom_asic_init(rdev->mode_info.atom_context);
  6008. }
  6009. /* init golden registers */
  6010. si_init_golden_registers(rdev);
  6011. /* Initialize scratch registers */
  6012. si_scratch_init(rdev);
  6013. /* Initialize surface registers */
  6014. radeon_surface_init(rdev);
  6015. /* Initialize clocks */
  6016. radeon_get_clock_info(rdev->ddev);
  6017. /* Fence driver */
  6018. r = radeon_fence_driver_init(rdev);
  6019. if (r)
  6020. return r;
  6021. /* initialize memory controller */
  6022. r = si_mc_init(rdev);
  6023. if (r)
  6024. return r;
  6025. /* Memory manager */
  6026. r = radeon_bo_init(rdev);
  6027. if (r)
  6028. return r;
  6029. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  6030. ring->ring_obj = NULL;
  6031. r600_ring_init(rdev, ring, 1024 * 1024);
  6032. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6033. ring->ring_obj = NULL;
  6034. r600_ring_init(rdev, ring, 1024 * 1024);
  6035. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6036. ring->ring_obj = NULL;
  6037. r600_ring_init(rdev, ring, 1024 * 1024);
  6038. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  6039. ring->ring_obj = NULL;
  6040. r600_ring_init(rdev, ring, 64 * 1024);
  6041. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  6042. ring->ring_obj = NULL;
  6043. r600_ring_init(rdev, ring, 64 * 1024);
  6044. if (rdev->has_uvd) {
  6045. r = radeon_uvd_init(rdev);
  6046. if (!r) {
  6047. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  6048. ring->ring_obj = NULL;
  6049. r600_ring_init(rdev, ring, 4096);
  6050. }
  6051. }
  6052. rdev->ih.ring_obj = NULL;
  6053. r600_ih_ring_init(rdev, 64 * 1024);
  6054. r = r600_pcie_gart_init(rdev);
  6055. if (r)
  6056. return r;
  6057. rdev->accel_working = true;
  6058. r = si_startup(rdev);
  6059. if (r) {
  6060. dev_err(rdev->dev, "disabling GPU acceleration\n");
  6061. si_cp_fini(rdev);
  6062. cayman_dma_fini(rdev);
  6063. si_irq_fini(rdev);
  6064. sumo_rlc_fini(rdev);
  6065. radeon_wb_fini(rdev);
  6066. radeon_ib_pool_fini(rdev);
  6067. radeon_vm_manager_fini(rdev);
  6068. radeon_irq_kms_fini(rdev);
  6069. si_pcie_gart_fini(rdev);
  6070. rdev->accel_working = false;
  6071. }
  6072. /* Don't start up if the MC ucode is missing.
  6073. * The default clocks and voltages before the MC ucode
  6074. * is loaded are not suffient for advanced operations.
  6075. */
  6076. if (!rdev->mc_fw) {
  6077. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  6078. return -EINVAL;
  6079. }
  6080. return 0;
  6081. }
  6082. void si_fini(struct radeon_device *rdev)
  6083. {
  6084. si_cp_fini(rdev);
  6085. cayman_dma_fini(rdev);
  6086. si_fini_pg(rdev);
  6087. si_fini_cg(rdev);
  6088. si_irq_fini(rdev);
  6089. sumo_rlc_fini(rdev);
  6090. radeon_wb_fini(rdev);
  6091. radeon_vm_manager_fini(rdev);
  6092. radeon_ib_pool_fini(rdev);
  6093. radeon_irq_kms_fini(rdev);
  6094. if (rdev->has_uvd) {
  6095. uvd_v1_0_fini(rdev);
  6096. radeon_uvd_fini(rdev);
  6097. }
  6098. si_pcie_gart_fini(rdev);
  6099. r600_vram_scratch_fini(rdev);
  6100. radeon_gem_fini(rdev);
  6101. radeon_fence_driver_fini(rdev);
  6102. radeon_bo_fini(rdev);
  6103. radeon_atombios_fini(rdev);
  6104. kfree(rdev->bios);
  6105. rdev->bios = NULL;
  6106. }
  6107. /**
  6108. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  6109. *
  6110. * @rdev: radeon_device pointer
  6111. *
  6112. * Fetches a GPU clock counter snapshot (SI).
  6113. * Returns the 64 bit clock counter snapshot.
  6114. */
  6115. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  6116. {
  6117. uint64_t clock;
  6118. mutex_lock(&rdev->gpu_clock_mutex);
  6119. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  6120. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  6121. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  6122. mutex_unlock(&rdev->gpu_clock_mutex);
  6123. return clock;
  6124. }
  6125. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  6126. {
  6127. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  6128. int r;
  6129. /* bypass vclk and dclk with bclk */
  6130. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6131. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  6132. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6133. /* put PLL in bypass mode */
  6134. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  6135. if (!vclk || !dclk) {
  6136. /* keep the Bypass mode, put PLL to sleep */
  6137. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6138. return 0;
  6139. }
  6140. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  6141. 16384, 0x03FFFFFF, 0, 128, 5,
  6142. &fb_div, &vclk_div, &dclk_div);
  6143. if (r)
  6144. return r;
  6145. /* set RESET_ANTI_MUX to 0 */
  6146. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  6147. /* set VCO_MODE to 1 */
  6148. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  6149. /* toggle UPLL_SLEEP to 1 then back to 0 */
  6150. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6151. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  6152. /* deassert UPLL_RESET */
  6153. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6154. mdelay(1);
  6155. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6156. if (r)
  6157. return r;
  6158. /* assert UPLL_RESET again */
  6159. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  6160. /* disable spread spectrum. */
  6161. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  6162. /* set feedback divider */
  6163. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  6164. /* set ref divider to 0 */
  6165. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  6166. if (fb_div < 307200)
  6167. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  6168. else
  6169. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  6170. /* set PDIV_A and PDIV_B */
  6171. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6172. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  6173. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  6174. /* give the PLL some time to settle */
  6175. mdelay(15);
  6176. /* deassert PLL_RESET */
  6177. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6178. mdelay(15);
  6179. /* switch from bypass mode to normal mode */
  6180. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  6181. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6182. if (r)
  6183. return r;
  6184. /* switch VCLK and DCLK selection */
  6185. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6186. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  6187. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6188. mdelay(100);
  6189. return 0;
  6190. }
  6191. static void si_pcie_gen3_enable(struct radeon_device *rdev)
  6192. {
  6193. struct pci_dev *root = rdev->pdev->bus->self;
  6194. int bridge_pos, gpu_pos;
  6195. u32 speed_cntl, mask, current_data_rate;
  6196. int ret, i;
  6197. u16 tmp16;
  6198. if (radeon_pcie_gen2 == 0)
  6199. return;
  6200. if (rdev->flags & RADEON_IS_IGP)
  6201. return;
  6202. if (!(rdev->flags & RADEON_IS_PCIE))
  6203. return;
  6204. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  6205. if (ret != 0)
  6206. return;
  6207. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  6208. return;
  6209. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6210. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  6211. LC_CURRENT_DATA_RATE_SHIFT;
  6212. if (mask & DRM_PCIE_SPEED_80) {
  6213. if (current_data_rate == 2) {
  6214. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  6215. return;
  6216. }
  6217. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  6218. } else if (mask & DRM_PCIE_SPEED_50) {
  6219. if (current_data_rate == 1) {
  6220. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  6221. return;
  6222. }
  6223. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  6224. }
  6225. bridge_pos = pci_pcie_cap(root);
  6226. if (!bridge_pos)
  6227. return;
  6228. gpu_pos = pci_pcie_cap(rdev->pdev);
  6229. if (!gpu_pos)
  6230. return;
  6231. if (mask & DRM_PCIE_SPEED_80) {
  6232. /* re-try equalization if gen3 is not already enabled */
  6233. if (current_data_rate != 2) {
  6234. u16 bridge_cfg, gpu_cfg;
  6235. u16 bridge_cfg2, gpu_cfg2;
  6236. u32 max_lw, current_lw, tmp;
  6237. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6238. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6239. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  6240. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6241. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  6242. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6243. tmp = RREG32_PCIE(PCIE_LC_STATUS1);
  6244. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  6245. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  6246. if (current_lw < max_lw) {
  6247. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6248. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  6249. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  6250. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  6251. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  6252. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  6253. }
  6254. }
  6255. for (i = 0; i < 10; i++) {
  6256. /* check status */
  6257. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  6258. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  6259. break;
  6260. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6261. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6262. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  6263. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  6264. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6265. tmp |= LC_SET_QUIESCE;
  6266. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6267. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6268. tmp |= LC_REDO_EQ;
  6269. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6270. mdelay(100);
  6271. /* linkctl */
  6272. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  6273. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6274. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  6275. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6276. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  6277. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6278. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  6279. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6280. /* linkctl2 */
  6281. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  6282. tmp16 &= ~((1 << 4) | (7 << 9));
  6283. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  6284. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  6285. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6286. tmp16 &= ~((1 << 4) | (7 << 9));
  6287. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  6288. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6289. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6290. tmp &= ~LC_SET_QUIESCE;
  6291. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6292. }
  6293. }
  6294. }
  6295. /* set the link speed */
  6296. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  6297. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  6298. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6299. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6300. tmp16 &= ~0xf;
  6301. if (mask & DRM_PCIE_SPEED_80)
  6302. tmp16 |= 3; /* gen3 */
  6303. else if (mask & DRM_PCIE_SPEED_50)
  6304. tmp16 |= 2; /* gen2 */
  6305. else
  6306. tmp16 |= 1; /* gen1 */
  6307. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6308. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6309. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  6310. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6311. for (i = 0; i < rdev->usec_timeout; i++) {
  6312. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6313. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  6314. break;
  6315. udelay(1);
  6316. }
  6317. }
  6318. static void si_program_aspm(struct radeon_device *rdev)
  6319. {
  6320. u32 data, orig;
  6321. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  6322. bool disable_clkreq = false;
  6323. if (radeon_aspm == 0)
  6324. return;
  6325. if (!(rdev->flags & RADEON_IS_PCIE))
  6326. return;
  6327. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6328. data &= ~LC_XMIT_N_FTS_MASK;
  6329. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  6330. if (orig != data)
  6331. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  6332. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  6333. data |= LC_GO_TO_RECOVERY;
  6334. if (orig != data)
  6335. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  6336. orig = data = RREG32_PCIE(PCIE_P_CNTL);
  6337. data |= P_IGNORE_EDB_ERR;
  6338. if (orig != data)
  6339. WREG32_PCIE(PCIE_P_CNTL, data);
  6340. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6341. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  6342. data |= LC_PMI_TO_L1_DIS;
  6343. if (!disable_l0s)
  6344. data |= LC_L0S_INACTIVITY(7);
  6345. if (!disable_l1) {
  6346. data |= LC_L1_INACTIVITY(7);
  6347. data &= ~LC_PMI_TO_L1_DIS;
  6348. if (orig != data)
  6349. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6350. if (!disable_plloff_in_l1) {
  6351. bool clk_req_support;
  6352. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6353. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6354. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6355. if (orig != data)
  6356. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6357. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6358. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6359. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6360. if (orig != data)
  6361. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6362. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6363. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6364. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6365. if (orig != data)
  6366. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6367. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6368. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6369. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6370. if (orig != data)
  6371. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6372. if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
  6373. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6374. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6375. if (orig != data)
  6376. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6377. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6378. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6379. if (orig != data)
  6380. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6381. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
  6382. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6383. if (orig != data)
  6384. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
  6385. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
  6386. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6387. if (orig != data)
  6388. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
  6389. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6390. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6391. if (orig != data)
  6392. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6393. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6394. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6395. if (orig != data)
  6396. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6397. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
  6398. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6399. if (orig != data)
  6400. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
  6401. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
  6402. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6403. if (orig != data)
  6404. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
  6405. }
  6406. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6407. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  6408. data |= LC_DYN_LANES_PWR_STATE(3);
  6409. if (orig != data)
  6410. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  6411. orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  6412. data &= ~LS2_EXIT_TIME_MASK;
  6413. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6414. data |= LS2_EXIT_TIME(5);
  6415. if (orig != data)
  6416. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  6417. orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  6418. data &= ~LS2_EXIT_TIME_MASK;
  6419. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6420. data |= LS2_EXIT_TIME(5);
  6421. if (orig != data)
  6422. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  6423. if (!disable_clkreq) {
  6424. struct pci_dev *root = rdev->pdev->bus->self;
  6425. u32 lnkcap;
  6426. clk_req_support = false;
  6427. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  6428. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  6429. clk_req_support = true;
  6430. } else {
  6431. clk_req_support = false;
  6432. }
  6433. if (clk_req_support) {
  6434. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  6435. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  6436. if (orig != data)
  6437. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  6438. orig = data = RREG32(THM_CLK_CNTL);
  6439. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  6440. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  6441. if (orig != data)
  6442. WREG32(THM_CLK_CNTL, data);
  6443. orig = data = RREG32(MISC_CLK_CNTL);
  6444. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  6445. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  6446. if (orig != data)
  6447. WREG32(MISC_CLK_CNTL, data);
  6448. orig = data = RREG32(CG_CLKPIN_CNTL);
  6449. data &= ~BCLK_AS_XCLK;
  6450. if (orig != data)
  6451. WREG32(CG_CLKPIN_CNTL, data);
  6452. orig = data = RREG32(CG_CLKPIN_CNTL_2);
  6453. data &= ~FORCE_BIF_REFCLK_EN;
  6454. if (orig != data)
  6455. WREG32(CG_CLKPIN_CNTL_2, data);
  6456. orig = data = RREG32(MPLL_BYPASSCLK_SEL);
  6457. data &= ~MPLL_CLKOUT_SEL_MASK;
  6458. data |= MPLL_CLKOUT_SEL(4);
  6459. if (orig != data)
  6460. WREG32(MPLL_BYPASSCLK_SEL, data);
  6461. orig = data = RREG32(SPLL_CNTL_MODE);
  6462. data &= ~SPLL_REFCLK_SEL_MASK;
  6463. if (orig != data)
  6464. WREG32(SPLL_CNTL_MODE, data);
  6465. }
  6466. }
  6467. } else {
  6468. if (orig != data)
  6469. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6470. }
  6471. orig = data = RREG32_PCIE(PCIE_CNTL2);
  6472. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  6473. if (orig != data)
  6474. WREG32_PCIE(PCIE_CNTL2, data);
  6475. if (!disable_l0s) {
  6476. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6477. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  6478. data = RREG32_PCIE(PCIE_LC_STATUS1);
  6479. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  6480. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6481. data &= ~LC_L0S_INACTIVITY_MASK;
  6482. if (orig != data)
  6483. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6484. }
  6485. }
  6486. }
  6487. }