si.c 200 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162
  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. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  79. bool enable);
  80. static void si_fini_pg(struct radeon_device *rdev);
  81. static void si_fini_cg(struct radeon_device *rdev);
  82. static void si_rlc_stop(struct radeon_device *rdev);
  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. 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. err = 0;
  1621. } else if (rdev->smc_fw->size != smc_req_size) {
  1622. printk(KERN_ERR
  1623. "si_smc: Bogus length %zu in firmware \"%s\"\n",
  1624. rdev->smc_fw->size, fw_name);
  1625. err = -EINVAL;
  1626. }
  1627. out:
  1628. if (err) {
  1629. if (err != -EINVAL)
  1630. printk(KERN_ERR
  1631. "si_cp: Failed to load firmware \"%s\"\n",
  1632. fw_name);
  1633. release_firmware(rdev->pfp_fw);
  1634. rdev->pfp_fw = NULL;
  1635. release_firmware(rdev->me_fw);
  1636. rdev->me_fw = NULL;
  1637. release_firmware(rdev->ce_fw);
  1638. rdev->ce_fw = NULL;
  1639. release_firmware(rdev->rlc_fw);
  1640. rdev->rlc_fw = NULL;
  1641. release_firmware(rdev->mc_fw);
  1642. rdev->mc_fw = NULL;
  1643. release_firmware(rdev->smc_fw);
  1644. rdev->smc_fw = NULL;
  1645. }
  1646. return err;
  1647. }
  1648. /* watermark setup */
  1649. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1650. struct radeon_crtc *radeon_crtc,
  1651. struct drm_display_mode *mode,
  1652. struct drm_display_mode *other_mode)
  1653. {
  1654. u32 tmp, buffer_alloc, i;
  1655. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1656. /*
  1657. * Line Buffer Setup
  1658. * There are 3 line buffers, each one shared by 2 display controllers.
  1659. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1660. * the display controllers. The paritioning is done via one of four
  1661. * preset allocations specified in bits 21:20:
  1662. * 0 - half lb
  1663. * 2 - whole lb, other crtc must be disabled
  1664. */
  1665. /* this can get tricky if we have two large displays on a paired group
  1666. * of crtcs. Ideally for multiple large displays we'd assign them to
  1667. * non-linked crtcs for maximum line buffer allocation.
  1668. */
  1669. if (radeon_crtc->base.enabled && mode) {
  1670. if (other_mode) {
  1671. tmp = 0; /* 1/2 */
  1672. buffer_alloc = 1;
  1673. } else {
  1674. tmp = 2; /* whole */
  1675. buffer_alloc = 2;
  1676. }
  1677. } else {
  1678. tmp = 0;
  1679. buffer_alloc = 0;
  1680. }
  1681. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1682. DC_LB_MEMORY_CONFIG(tmp));
  1683. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1684. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1685. for (i = 0; i < rdev->usec_timeout; i++) {
  1686. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1687. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1688. break;
  1689. udelay(1);
  1690. }
  1691. if (radeon_crtc->base.enabled && mode) {
  1692. switch (tmp) {
  1693. case 0:
  1694. default:
  1695. return 4096 * 2;
  1696. case 2:
  1697. return 8192 * 2;
  1698. }
  1699. }
  1700. /* controller not enabled, so no lb used */
  1701. return 0;
  1702. }
  1703. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1704. {
  1705. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1706. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1707. case 0:
  1708. default:
  1709. return 1;
  1710. case 1:
  1711. return 2;
  1712. case 2:
  1713. return 4;
  1714. case 3:
  1715. return 8;
  1716. case 4:
  1717. return 3;
  1718. case 5:
  1719. return 6;
  1720. case 6:
  1721. return 10;
  1722. case 7:
  1723. return 12;
  1724. case 8:
  1725. return 16;
  1726. }
  1727. }
  1728. struct dce6_wm_params {
  1729. u32 dram_channels; /* number of dram channels */
  1730. u32 yclk; /* bandwidth per dram data pin in kHz */
  1731. u32 sclk; /* engine clock in kHz */
  1732. u32 disp_clk; /* display clock in kHz */
  1733. u32 src_width; /* viewport width */
  1734. u32 active_time; /* active display time in ns */
  1735. u32 blank_time; /* blank time in ns */
  1736. bool interlaced; /* mode is interlaced */
  1737. fixed20_12 vsc; /* vertical scale ratio */
  1738. u32 num_heads; /* number of active crtcs */
  1739. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1740. u32 lb_size; /* line buffer allocated to pipe */
  1741. u32 vtaps; /* vertical scaler taps */
  1742. };
  1743. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1744. {
  1745. /* Calculate raw DRAM Bandwidth */
  1746. fixed20_12 dram_efficiency; /* 0.7 */
  1747. fixed20_12 yclk, dram_channels, bandwidth;
  1748. fixed20_12 a;
  1749. a.full = dfixed_const(1000);
  1750. yclk.full = dfixed_const(wm->yclk);
  1751. yclk.full = dfixed_div(yclk, a);
  1752. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1753. a.full = dfixed_const(10);
  1754. dram_efficiency.full = dfixed_const(7);
  1755. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1756. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1757. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1758. return dfixed_trunc(bandwidth);
  1759. }
  1760. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1761. {
  1762. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1763. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1764. fixed20_12 yclk, dram_channels, bandwidth;
  1765. fixed20_12 a;
  1766. a.full = dfixed_const(1000);
  1767. yclk.full = dfixed_const(wm->yclk);
  1768. yclk.full = dfixed_div(yclk, a);
  1769. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1770. a.full = dfixed_const(10);
  1771. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1772. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1773. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1774. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1775. return dfixed_trunc(bandwidth);
  1776. }
  1777. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1778. {
  1779. /* Calculate the display Data return Bandwidth */
  1780. fixed20_12 return_efficiency; /* 0.8 */
  1781. fixed20_12 sclk, bandwidth;
  1782. fixed20_12 a;
  1783. a.full = dfixed_const(1000);
  1784. sclk.full = dfixed_const(wm->sclk);
  1785. sclk.full = dfixed_div(sclk, a);
  1786. a.full = dfixed_const(10);
  1787. return_efficiency.full = dfixed_const(8);
  1788. return_efficiency.full = dfixed_div(return_efficiency, a);
  1789. a.full = dfixed_const(32);
  1790. bandwidth.full = dfixed_mul(a, sclk);
  1791. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1792. return dfixed_trunc(bandwidth);
  1793. }
  1794. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1795. {
  1796. return 32;
  1797. }
  1798. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1799. {
  1800. /* Calculate the DMIF Request Bandwidth */
  1801. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1802. fixed20_12 disp_clk, sclk, bandwidth;
  1803. fixed20_12 a, b1, b2;
  1804. u32 min_bandwidth;
  1805. a.full = dfixed_const(1000);
  1806. disp_clk.full = dfixed_const(wm->disp_clk);
  1807. disp_clk.full = dfixed_div(disp_clk, a);
  1808. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1809. b1.full = dfixed_mul(a, disp_clk);
  1810. a.full = dfixed_const(1000);
  1811. sclk.full = dfixed_const(wm->sclk);
  1812. sclk.full = dfixed_div(sclk, a);
  1813. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1814. b2.full = dfixed_mul(a, sclk);
  1815. a.full = dfixed_const(10);
  1816. disp_clk_request_efficiency.full = dfixed_const(8);
  1817. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1818. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1819. a.full = dfixed_const(min_bandwidth);
  1820. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1821. return dfixed_trunc(bandwidth);
  1822. }
  1823. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1824. {
  1825. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1826. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1827. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1828. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1829. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1830. }
  1831. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1832. {
  1833. /* Calculate the display mode Average Bandwidth
  1834. * DisplayMode should contain the source and destination dimensions,
  1835. * timing, etc.
  1836. */
  1837. fixed20_12 bpp;
  1838. fixed20_12 line_time;
  1839. fixed20_12 src_width;
  1840. fixed20_12 bandwidth;
  1841. fixed20_12 a;
  1842. a.full = dfixed_const(1000);
  1843. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1844. line_time.full = dfixed_div(line_time, a);
  1845. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1846. src_width.full = dfixed_const(wm->src_width);
  1847. bandwidth.full = dfixed_mul(src_width, bpp);
  1848. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1849. bandwidth.full = dfixed_div(bandwidth, line_time);
  1850. return dfixed_trunc(bandwidth);
  1851. }
  1852. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1853. {
  1854. /* First calcualte the latency in ns */
  1855. u32 mc_latency = 2000; /* 2000 ns. */
  1856. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1857. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1858. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1859. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1860. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1861. (wm->num_heads * cursor_line_pair_return_time);
  1862. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1863. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1864. u32 tmp, dmif_size = 12288;
  1865. fixed20_12 a, b, c;
  1866. if (wm->num_heads == 0)
  1867. return 0;
  1868. a.full = dfixed_const(2);
  1869. b.full = dfixed_const(1);
  1870. if ((wm->vsc.full > a.full) ||
  1871. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1872. (wm->vtaps >= 5) ||
  1873. ((wm->vsc.full >= a.full) && wm->interlaced))
  1874. max_src_lines_per_dst_line = 4;
  1875. else
  1876. max_src_lines_per_dst_line = 2;
  1877. a.full = dfixed_const(available_bandwidth);
  1878. b.full = dfixed_const(wm->num_heads);
  1879. a.full = dfixed_div(a, b);
  1880. b.full = dfixed_const(mc_latency + 512);
  1881. c.full = dfixed_const(wm->disp_clk);
  1882. b.full = dfixed_div(b, c);
  1883. c.full = dfixed_const(dmif_size);
  1884. b.full = dfixed_div(c, b);
  1885. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1886. b.full = dfixed_const(1000);
  1887. c.full = dfixed_const(wm->disp_clk);
  1888. b.full = dfixed_div(c, b);
  1889. c.full = dfixed_const(wm->bytes_per_pixel);
  1890. b.full = dfixed_mul(b, c);
  1891. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1892. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1893. b.full = dfixed_const(1000);
  1894. c.full = dfixed_const(lb_fill_bw);
  1895. b.full = dfixed_div(c, b);
  1896. a.full = dfixed_div(a, b);
  1897. line_fill_time = dfixed_trunc(a);
  1898. if (line_fill_time < wm->active_time)
  1899. return latency;
  1900. else
  1901. return latency + (line_fill_time - wm->active_time);
  1902. }
  1903. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1904. {
  1905. if (dce6_average_bandwidth(wm) <=
  1906. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1907. return true;
  1908. else
  1909. return false;
  1910. };
  1911. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1912. {
  1913. if (dce6_average_bandwidth(wm) <=
  1914. (dce6_available_bandwidth(wm) / wm->num_heads))
  1915. return true;
  1916. else
  1917. return false;
  1918. };
  1919. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1920. {
  1921. u32 lb_partitions = wm->lb_size / wm->src_width;
  1922. u32 line_time = wm->active_time + wm->blank_time;
  1923. u32 latency_tolerant_lines;
  1924. u32 latency_hiding;
  1925. fixed20_12 a;
  1926. a.full = dfixed_const(1);
  1927. if (wm->vsc.full > a.full)
  1928. latency_tolerant_lines = 1;
  1929. else {
  1930. if (lb_partitions <= (wm->vtaps + 1))
  1931. latency_tolerant_lines = 1;
  1932. else
  1933. latency_tolerant_lines = 2;
  1934. }
  1935. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1936. if (dce6_latency_watermark(wm) <= latency_hiding)
  1937. return true;
  1938. else
  1939. return false;
  1940. }
  1941. static void dce6_program_watermarks(struct radeon_device *rdev,
  1942. struct radeon_crtc *radeon_crtc,
  1943. u32 lb_size, u32 num_heads)
  1944. {
  1945. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1946. struct dce6_wm_params wm_low, wm_high;
  1947. u32 dram_channels;
  1948. u32 pixel_period;
  1949. u32 line_time = 0;
  1950. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1951. u32 priority_a_mark = 0, priority_b_mark = 0;
  1952. u32 priority_a_cnt = PRIORITY_OFF;
  1953. u32 priority_b_cnt = PRIORITY_OFF;
  1954. u32 tmp, arb_control3;
  1955. fixed20_12 a, b, c;
  1956. if (radeon_crtc->base.enabled && num_heads && mode) {
  1957. pixel_period = 1000000 / (u32)mode->clock;
  1958. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1959. priority_a_cnt = 0;
  1960. priority_b_cnt = 0;
  1961. if (rdev->family == CHIP_ARUBA)
  1962. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1963. else
  1964. dram_channels = si_get_number_of_dram_channels(rdev);
  1965. /* watermark for high clocks */
  1966. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1967. wm_high.yclk =
  1968. radeon_dpm_get_mclk(rdev, false) * 10;
  1969. wm_high.sclk =
  1970. radeon_dpm_get_sclk(rdev, false) * 10;
  1971. } else {
  1972. wm_high.yclk = rdev->pm.current_mclk * 10;
  1973. wm_high.sclk = rdev->pm.current_sclk * 10;
  1974. }
  1975. wm_high.disp_clk = mode->clock;
  1976. wm_high.src_width = mode->crtc_hdisplay;
  1977. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  1978. wm_high.blank_time = line_time - wm_high.active_time;
  1979. wm_high.interlaced = false;
  1980. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1981. wm_high.interlaced = true;
  1982. wm_high.vsc = radeon_crtc->vsc;
  1983. wm_high.vtaps = 1;
  1984. if (radeon_crtc->rmx_type != RMX_OFF)
  1985. wm_high.vtaps = 2;
  1986. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1987. wm_high.lb_size = lb_size;
  1988. wm_high.dram_channels = dram_channels;
  1989. wm_high.num_heads = num_heads;
  1990. /* watermark for low clocks */
  1991. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1992. wm_low.yclk =
  1993. radeon_dpm_get_mclk(rdev, true) * 10;
  1994. wm_low.sclk =
  1995. radeon_dpm_get_sclk(rdev, true) * 10;
  1996. } else {
  1997. wm_low.yclk = rdev->pm.current_mclk * 10;
  1998. wm_low.sclk = rdev->pm.current_sclk * 10;
  1999. }
  2000. wm_low.disp_clk = mode->clock;
  2001. wm_low.src_width = mode->crtc_hdisplay;
  2002. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2003. wm_low.blank_time = line_time - wm_low.active_time;
  2004. wm_low.interlaced = false;
  2005. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2006. wm_low.interlaced = true;
  2007. wm_low.vsc = radeon_crtc->vsc;
  2008. wm_low.vtaps = 1;
  2009. if (radeon_crtc->rmx_type != RMX_OFF)
  2010. wm_low.vtaps = 2;
  2011. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2012. wm_low.lb_size = lb_size;
  2013. wm_low.dram_channels = dram_channels;
  2014. wm_low.num_heads = num_heads;
  2015. /* set for high clocks */
  2016. latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
  2017. /* set for low clocks */
  2018. latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
  2019. /* possibly force display priority to high */
  2020. /* should really do this at mode validation time... */
  2021. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2022. !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2023. !dce6_check_latency_hiding(&wm_high) ||
  2024. (rdev->disp_priority == 2)) {
  2025. DRM_DEBUG_KMS("force priority to high\n");
  2026. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2027. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2028. }
  2029. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2030. !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2031. !dce6_check_latency_hiding(&wm_low) ||
  2032. (rdev->disp_priority == 2)) {
  2033. DRM_DEBUG_KMS("force priority to high\n");
  2034. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2035. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2036. }
  2037. a.full = dfixed_const(1000);
  2038. b.full = dfixed_const(mode->clock);
  2039. b.full = dfixed_div(b, a);
  2040. c.full = dfixed_const(latency_watermark_a);
  2041. c.full = dfixed_mul(c, b);
  2042. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2043. c.full = dfixed_div(c, a);
  2044. a.full = dfixed_const(16);
  2045. c.full = dfixed_div(c, a);
  2046. priority_a_mark = dfixed_trunc(c);
  2047. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2048. a.full = dfixed_const(1000);
  2049. b.full = dfixed_const(mode->clock);
  2050. b.full = dfixed_div(b, a);
  2051. c.full = dfixed_const(latency_watermark_b);
  2052. c.full = dfixed_mul(c, b);
  2053. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2054. c.full = dfixed_div(c, a);
  2055. a.full = dfixed_const(16);
  2056. c.full = dfixed_div(c, a);
  2057. priority_b_mark = dfixed_trunc(c);
  2058. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2059. }
  2060. /* select wm A */
  2061. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2062. tmp = arb_control3;
  2063. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2064. tmp |= LATENCY_WATERMARK_MASK(1);
  2065. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2066. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2067. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2068. LATENCY_HIGH_WATERMARK(line_time)));
  2069. /* select wm B */
  2070. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  2071. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2072. tmp |= LATENCY_WATERMARK_MASK(2);
  2073. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  2074. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  2075. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2076. LATENCY_HIGH_WATERMARK(line_time)));
  2077. /* restore original selection */
  2078. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  2079. /* write the priority marks */
  2080. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2081. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2082. /* save values for DPM */
  2083. radeon_crtc->line_time = line_time;
  2084. radeon_crtc->wm_high = latency_watermark_a;
  2085. radeon_crtc->wm_low = latency_watermark_b;
  2086. }
  2087. void dce6_bandwidth_update(struct radeon_device *rdev)
  2088. {
  2089. struct drm_display_mode *mode0 = NULL;
  2090. struct drm_display_mode *mode1 = NULL;
  2091. u32 num_heads = 0, lb_size;
  2092. int i;
  2093. radeon_update_display_priority(rdev);
  2094. for (i = 0; i < rdev->num_crtc; i++) {
  2095. if (rdev->mode_info.crtcs[i]->base.enabled)
  2096. num_heads++;
  2097. }
  2098. for (i = 0; i < rdev->num_crtc; i += 2) {
  2099. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2100. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2101. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2102. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2103. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2104. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2105. }
  2106. }
  2107. /*
  2108. * Core functions
  2109. */
  2110. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  2111. {
  2112. const u32 num_tile_mode_states = 32;
  2113. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  2114. switch (rdev->config.si.mem_row_size_in_kb) {
  2115. case 1:
  2116. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  2117. break;
  2118. case 2:
  2119. default:
  2120. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  2121. break;
  2122. case 4:
  2123. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  2124. break;
  2125. }
  2126. if ((rdev->family == CHIP_TAHITI) ||
  2127. (rdev->family == CHIP_PITCAIRN)) {
  2128. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2129. switch (reg_offset) {
  2130. case 0: /* non-AA compressed depth or any compressed stencil */
  2131. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2132. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2133. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2134. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2135. NUM_BANKS(ADDR_SURF_16_BANK) |
  2136. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2137. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2138. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2139. break;
  2140. case 1: /* 2xAA/4xAA compressed depth only */
  2141. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2142. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2143. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2144. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2145. NUM_BANKS(ADDR_SURF_16_BANK) |
  2146. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2147. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2148. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2149. break;
  2150. case 2: /* 8xAA compressed depth only */
  2151. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2152. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2153. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2154. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2155. NUM_BANKS(ADDR_SURF_16_BANK) |
  2156. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2157. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2158. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2159. break;
  2160. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2161. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2162. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2163. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2164. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2165. NUM_BANKS(ADDR_SURF_16_BANK) |
  2166. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2167. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2168. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2169. break;
  2170. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2171. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2172. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2173. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2174. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2175. NUM_BANKS(ADDR_SURF_16_BANK) |
  2176. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2177. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2178. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2179. break;
  2180. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2181. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2182. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2183. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2184. TILE_SPLIT(split_equal_to_row_size) |
  2185. NUM_BANKS(ADDR_SURF_16_BANK) |
  2186. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2187. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2188. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2189. break;
  2190. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2191. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2192. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2193. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2194. TILE_SPLIT(split_equal_to_row_size) |
  2195. NUM_BANKS(ADDR_SURF_16_BANK) |
  2196. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2197. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2198. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2199. break;
  2200. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2201. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2202. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2203. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2204. TILE_SPLIT(split_equal_to_row_size) |
  2205. NUM_BANKS(ADDR_SURF_16_BANK) |
  2206. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2207. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2208. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2209. break;
  2210. case 8: /* 1D and 1D Array Surfaces */
  2211. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2212. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2213. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2214. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2215. NUM_BANKS(ADDR_SURF_16_BANK) |
  2216. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2217. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2218. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2219. break;
  2220. case 9: /* Displayable maps. */
  2221. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2222. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2223. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2224. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2225. NUM_BANKS(ADDR_SURF_16_BANK) |
  2226. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2227. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2228. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2229. break;
  2230. case 10: /* Display 8bpp. */
  2231. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2232. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2233. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2234. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2235. NUM_BANKS(ADDR_SURF_16_BANK) |
  2236. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2237. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2238. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2239. break;
  2240. case 11: /* Display 16bpp. */
  2241. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2242. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2243. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2244. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2245. NUM_BANKS(ADDR_SURF_16_BANK) |
  2246. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2247. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2248. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2249. break;
  2250. case 12: /* Display 32bpp. */
  2251. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2252. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2253. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2254. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2255. NUM_BANKS(ADDR_SURF_16_BANK) |
  2256. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2257. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2258. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2259. break;
  2260. case 13: /* Thin. */
  2261. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2262. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2263. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2264. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2265. NUM_BANKS(ADDR_SURF_16_BANK) |
  2266. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2267. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2268. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2269. break;
  2270. case 14: /* Thin 8 bpp. */
  2271. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2272. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2273. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2274. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2275. NUM_BANKS(ADDR_SURF_16_BANK) |
  2276. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2277. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2278. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2279. break;
  2280. case 15: /* Thin 16 bpp. */
  2281. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2282. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2283. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2284. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2285. NUM_BANKS(ADDR_SURF_16_BANK) |
  2286. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2287. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2288. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2289. break;
  2290. case 16: /* Thin 32 bpp. */
  2291. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2292. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2293. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2294. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2295. NUM_BANKS(ADDR_SURF_16_BANK) |
  2296. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2297. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2298. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2299. break;
  2300. case 17: /* Thin 64 bpp. */
  2301. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2302. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2303. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2304. TILE_SPLIT(split_equal_to_row_size) |
  2305. NUM_BANKS(ADDR_SURF_16_BANK) |
  2306. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2307. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2308. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2309. break;
  2310. case 21: /* 8 bpp PRT. */
  2311. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2312. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2313. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2314. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2315. NUM_BANKS(ADDR_SURF_16_BANK) |
  2316. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2317. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2318. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2319. break;
  2320. case 22: /* 16 bpp PRT */
  2321. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2322. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2323. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2324. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2325. NUM_BANKS(ADDR_SURF_16_BANK) |
  2326. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2327. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2328. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2329. break;
  2330. case 23: /* 32 bpp PRT */
  2331. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2332. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2333. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2334. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2335. NUM_BANKS(ADDR_SURF_16_BANK) |
  2336. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2337. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2338. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2339. break;
  2340. case 24: /* 64 bpp PRT */
  2341. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2342. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2343. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2344. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2345. NUM_BANKS(ADDR_SURF_16_BANK) |
  2346. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2347. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2348. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2349. break;
  2350. case 25: /* 128 bpp PRT */
  2351. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2352. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2353. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2354. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2355. NUM_BANKS(ADDR_SURF_8_BANK) |
  2356. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2357. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2358. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2359. break;
  2360. default:
  2361. gb_tile_moden = 0;
  2362. break;
  2363. }
  2364. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2365. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2366. }
  2367. } else if ((rdev->family == CHIP_VERDE) ||
  2368. (rdev->family == CHIP_OLAND) ||
  2369. (rdev->family == CHIP_HAINAN)) {
  2370. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2371. switch (reg_offset) {
  2372. case 0: /* non-AA compressed depth or any compressed stencil */
  2373. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2374. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2375. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2376. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2377. NUM_BANKS(ADDR_SURF_16_BANK) |
  2378. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2379. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2380. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2381. break;
  2382. case 1: /* 2xAA/4xAA compressed depth only */
  2383. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2384. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2385. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2386. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2387. NUM_BANKS(ADDR_SURF_16_BANK) |
  2388. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2389. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2390. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2391. break;
  2392. case 2: /* 8xAA compressed depth only */
  2393. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2394. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2395. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2396. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2397. NUM_BANKS(ADDR_SURF_16_BANK) |
  2398. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2399. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2400. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2401. break;
  2402. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2403. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2404. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2405. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2406. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2407. NUM_BANKS(ADDR_SURF_16_BANK) |
  2408. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2409. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2410. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2411. break;
  2412. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2413. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2414. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2415. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2416. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2417. NUM_BANKS(ADDR_SURF_16_BANK) |
  2418. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2419. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2420. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2421. break;
  2422. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2423. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2424. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2425. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2426. TILE_SPLIT(split_equal_to_row_size) |
  2427. NUM_BANKS(ADDR_SURF_16_BANK) |
  2428. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2429. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2430. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2431. break;
  2432. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2433. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2434. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2435. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2436. TILE_SPLIT(split_equal_to_row_size) |
  2437. NUM_BANKS(ADDR_SURF_16_BANK) |
  2438. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2439. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2440. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2441. break;
  2442. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2443. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2444. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2445. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2446. TILE_SPLIT(split_equal_to_row_size) |
  2447. NUM_BANKS(ADDR_SURF_16_BANK) |
  2448. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2449. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2450. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2451. break;
  2452. case 8: /* 1D and 1D Array Surfaces */
  2453. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2454. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2455. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2456. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2457. NUM_BANKS(ADDR_SURF_16_BANK) |
  2458. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2459. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2460. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2461. break;
  2462. case 9: /* Displayable maps. */
  2463. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2464. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2465. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2466. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2467. NUM_BANKS(ADDR_SURF_16_BANK) |
  2468. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2469. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2470. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2471. break;
  2472. case 10: /* Display 8bpp. */
  2473. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2474. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2475. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2476. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2477. NUM_BANKS(ADDR_SURF_16_BANK) |
  2478. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2479. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2480. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2481. break;
  2482. case 11: /* Display 16bpp. */
  2483. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2484. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2485. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2486. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2487. NUM_BANKS(ADDR_SURF_16_BANK) |
  2488. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2489. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2490. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2491. break;
  2492. case 12: /* Display 32bpp. */
  2493. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2494. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2495. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2496. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2497. NUM_BANKS(ADDR_SURF_16_BANK) |
  2498. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2499. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2500. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2501. break;
  2502. case 13: /* Thin. */
  2503. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2504. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2505. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2506. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2507. NUM_BANKS(ADDR_SURF_16_BANK) |
  2508. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2509. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2510. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2511. break;
  2512. case 14: /* Thin 8 bpp. */
  2513. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2514. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2515. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2516. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2517. NUM_BANKS(ADDR_SURF_16_BANK) |
  2518. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2519. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2520. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2521. break;
  2522. case 15: /* Thin 16 bpp. */
  2523. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2524. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2525. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2526. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2527. NUM_BANKS(ADDR_SURF_16_BANK) |
  2528. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2529. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2530. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2531. break;
  2532. case 16: /* Thin 32 bpp. */
  2533. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2534. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2535. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2536. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2537. NUM_BANKS(ADDR_SURF_16_BANK) |
  2538. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2539. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2540. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2541. break;
  2542. case 17: /* Thin 64 bpp. */
  2543. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2544. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2545. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2546. TILE_SPLIT(split_equal_to_row_size) |
  2547. NUM_BANKS(ADDR_SURF_16_BANK) |
  2548. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2549. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2550. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2551. break;
  2552. case 21: /* 8 bpp PRT. */
  2553. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2554. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2555. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2556. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2557. NUM_BANKS(ADDR_SURF_16_BANK) |
  2558. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2559. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2560. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2561. break;
  2562. case 22: /* 16 bpp PRT */
  2563. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2564. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2565. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2566. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2567. NUM_BANKS(ADDR_SURF_16_BANK) |
  2568. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2569. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2570. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2571. break;
  2572. case 23: /* 32 bpp PRT */
  2573. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2574. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2575. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2576. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2577. NUM_BANKS(ADDR_SURF_16_BANK) |
  2578. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2579. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2580. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2581. break;
  2582. case 24: /* 64 bpp PRT */
  2583. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2584. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2585. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2586. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2587. NUM_BANKS(ADDR_SURF_16_BANK) |
  2588. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2589. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2590. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2591. break;
  2592. case 25: /* 128 bpp PRT */
  2593. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2594. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2595. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2596. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2597. NUM_BANKS(ADDR_SURF_8_BANK) |
  2598. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2599. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2600. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2601. break;
  2602. default:
  2603. gb_tile_moden = 0;
  2604. break;
  2605. }
  2606. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2607. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2608. }
  2609. } else
  2610. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2611. }
  2612. static void si_select_se_sh(struct radeon_device *rdev,
  2613. u32 se_num, u32 sh_num)
  2614. {
  2615. u32 data = INSTANCE_BROADCAST_WRITES;
  2616. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2617. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2618. else if (se_num == 0xffffffff)
  2619. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2620. else if (sh_num == 0xffffffff)
  2621. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2622. else
  2623. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2624. WREG32(GRBM_GFX_INDEX, data);
  2625. }
  2626. static u32 si_create_bitmask(u32 bit_width)
  2627. {
  2628. u32 i, mask = 0;
  2629. for (i = 0; i < bit_width; i++) {
  2630. mask <<= 1;
  2631. mask |= 1;
  2632. }
  2633. return mask;
  2634. }
  2635. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2636. {
  2637. u32 data, mask;
  2638. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2639. if (data & 1)
  2640. data &= INACTIVE_CUS_MASK;
  2641. else
  2642. data = 0;
  2643. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2644. data >>= INACTIVE_CUS_SHIFT;
  2645. mask = si_create_bitmask(cu_per_sh);
  2646. return ~data & mask;
  2647. }
  2648. static void si_setup_spi(struct radeon_device *rdev,
  2649. u32 se_num, u32 sh_per_se,
  2650. u32 cu_per_sh)
  2651. {
  2652. int i, j, k;
  2653. u32 data, mask, active_cu;
  2654. for (i = 0; i < se_num; i++) {
  2655. for (j = 0; j < sh_per_se; j++) {
  2656. si_select_se_sh(rdev, i, j);
  2657. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2658. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2659. mask = 1;
  2660. for (k = 0; k < 16; k++) {
  2661. mask <<= k;
  2662. if (active_cu & mask) {
  2663. data &= ~mask;
  2664. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2665. break;
  2666. }
  2667. }
  2668. }
  2669. }
  2670. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2671. }
  2672. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2673. u32 max_rb_num, u32 se_num,
  2674. u32 sh_per_se)
  2675. {
  2676. u32 data, mask;
  2677. data = RREG32(CC_RB_BACKEND_DISABLE);
  2678. if (data & 1)
  2679. data &= BACKEND_DISABLE_MASK;
  2680. else
  2681. data = 0;
  2682. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2683. data >>= BACKEND_DISABLE_SHIFT;
  2684. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2685. return data & mask;
  2686. }
  2687. static void si_setup_rb(struct radeon_device *rdev,
  2688. u32 se_num, u32 sh_per_se,
  2689. u32 max_rb_num)
  2690. {
  2691. int i, j;
  2692. u32 data, mask;
  2693. u32 disabled_rbs = 0;
  2694. u32 enabled_rbs = 0;
  2695. for (i = 0; i < se_num; i++) {
  2696. for (j = 0; j < sh_per_se; j++) {
  2697. si_select_se_sh(rdev, i, j);
  2698. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2699. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2700. }
  2701. }
  2702. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2703. mask = 1;
  2704. for (i = 0; i < max_rb_num; i++) {
  2705. if (!(disabled_rbs & mask))
  2706. enabled_rbs |= mask;
  2707. mask <<= 1;
  2708. }
  2709. for (i = 0; i < se_num; i++) {
  2710. si_select_se_sh(rdev, i, 0xffffffff);
  2711. data = 0;
  2712. for (j = 0; j < sh_per_se; j++) {
  2713. switch (enabled_rbs & 3) {
  2714. case 1:
  2715. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2716. break;
  2717. case 2:
  2718. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2719. break;
  2720. case 3:
  2721. default:
  2722. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2723. break;
  2724. }
  2725. enabled_rbs >>= 2;
  2726. }
  2727. WREG32(PA_SC_RASTER_CONFIG, data);
  2728. }
  2729. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2730. }
  2731. static void si_gpu_init(struct radeon_device *rdev)
  2732. {
  2733. u32 gb_addr_config = 0;
  2734. u32 mc_shared_chmap, mc_arb_ramcfg;
  2735. u32 sx_debug_1;
  2736. u32 hdp_host_path_cntl;
  2737. u32 tmp;
  2738. int i, j;
  2739. switch (rdev->family) {
  2740. case CHIP_TAHITI:
  2741. rdev->config.si.max_shader_engines = 2;
  2742. rdev->config.si.max_tile_pipes = 12;
  2743. rdev->config.si.max_cu_per_sh = 8;
  2744. rdev->config.si.max_sh_per_se = 2;
  2745. rdev->config.si.max_backends_per_se = 4;
  2746. rdev->config.si.max_texture_channel_caches = 12;
  2747. rdev->config.si.max_gprs = 256;
  2748. rdev->config.si.max_gs_threads = 32;
  2749. rdev->config.si.max_hw_contexts = 8;
  2750. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2751. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2752. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2753. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2754. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2755. break;
  2756. case CHIP_PITCAIRN:
  2757. rdev->config.si.max_shader_engines = 2;
  2758. rdev->config.si.max_tile_pipes = 8;
  2759. rdev->config.si.max_cu_per_sh = 5;
  2760. rdev->config.si.max_sh_per_se = 2;
  2761. rdev->config.si.max_backends_per_se = 4;
  2762. rdev->config.si.max_texture_channel_caches = 8;
  2763. rdev->config.si.max_gprs = 256;
  2764. rdev->config.si.max_gs_threads = 32;
  2765. rdev->config.si.max_hw_contexts = 8;
  2766. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2767. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2768. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2769. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2770. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2771. break;
  2772. case CHIP_VERDE:
  2773. default:
  2774. rdev->config.si.max_shader_engines = 1;
  2775. rdev->config.si.max_tile_pipes = 4;
  2776. rdev->config.si.max_cu_per_sh = 5;
  2777. rdev->config.si.max_sh_per_se = 2;
  2778. rdev->config.si.max_backends_per_se = 4;
  2779. rdev->config.si.max_texture_channel_caches = 4;
  2780. rdev->config.si.max_gprs = 256;
  2781. rdev->config.si.max_gs_threads = 32;
  2782. rdev->config.si.max_hw_contexts = 8;
  2783. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2784. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2785. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2786. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2787. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2788. break;
  2789. case CHIP_OLAND:
  2790. rdev->config.si.max_shader_engines = 1;
  2791. rdev->config.si.max_tile_pipes = 4;
  2792. rdev->config.si.max_cu_per_sh = 6;
  2793. rdev->config.si.max_sh_per_se = 1;
  2794. rdev->config.si.max_backends_per_se = 2;
  2795. rdev->config.si.max_texture_channel_caches = 4;
  2796. rdev->config.si.max_gprs = 256;
  2797. rdev->config.si.max_gs_threads = 16;
  2798. rdev->config.si.max_hw_contexts = 8;
  2799. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2800. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2801. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2802. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2803. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2804. break;
  2805. case CHIP_HAINAN:
  2806. rdev->config.si.max_shader_engines = 1;
  2807. rdev->config.si.max_tile_pipes = 4;
  2808. rdev->config.si.max_cu_per_sh = 5;
  2809. rdev->config.si.max_sh_per_se = 1;
  2810. rdev->config.si.max_backends_per_se = 1;
  2811. rdev->config.si.max_texture_channel_caches = 2;
  2812. rdev->config.si.max_gprs = 256;
  2813. rdev->config.si.max_gs_threads = 16;
  2814. rdev->config.si.max_hw_contexts = 8;
  2815. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2816. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2817. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2818. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2819. gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
  2820. break;
  2821. }
  2822. /* Initialize HDP */
  2823. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2824. WREG32((0x2c14 + j), 0x00000000);
  2825. WREG32((0x2c18 + j), 0x00000000);
  2826. WREG32((0x2c1c + j), 0x00000000);
  2827. WREG32((0x2c20 + j), 0x00000000);
  2828. WREG32((0x2c24 + j), 0x00000000);
  2829. }
  2830. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2831. evergreen_fix_pci_max_read_req_size(rdev);
  2832. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2833. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2834. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2835. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2836. rdev->config.si.mem_max_burst_length_bytes = 256;
  2837. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2838. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2839. if (rdev->config.si.mem_row_size_in_kb > 4)
  2840. rdev->config.si.mem_row_size_in_kb = 4;
  2841. /* XXX use MC settings? */
  2842. rdev->config.si.shader_engine_tile_size = 32;
  2843. rdev->config.si.num_gpus = 1;
  2844. rdev->config.si.multi_gpu_tile_size = 64;
  2845. /* fix up row size */
  2846. gb_addr_config &= ~ROW_SIZE_MASK;
  2847. switch (rdev->config.si.mem_row_size_in_kb) {
  2848. case 1:
  2849. default:
  2850. gb_addr_config |= ROW_SIZE(0);
  2851. break;
  2852. case 2:
  2853. gb_addr_config |= ROW_SIZE(1);
  2854. break;
  2855. case 4:
  2856. gb_addr_config |= ROW_SIZE(2);
  2857. break;
  2858. }
  2859. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2860. * not have bank info, so create a custom tiling dword.
  2861. * bits 3:0 num_pipes
  2862. * bits 7:4 num_banks
  2863. * bits 11:8 group_size
  2864. * bits 15:12 row_size
  2865. */
  2866. rdev->config.si.tile_config = 0;
  2867. switch (rdev->config.si.num_tile_pipes) {
  2868. case 1:
  2869. rdev->config.si.tile_config |= (0 << 0);
  2870. break;
  2871. case 2:
  2872. rdev->config.si.tile_config |= (1 << 0);
  2873. break;
  2874. case 4:
  2875. rdev->config.si.tile_config |= (2 << 0);
  2876. break;
  2877. case 8:
  2878. default:
  2879. /* XXX what about 12? */
  2880. rdev->config.si.tile_config |= (3 << 0);
  2881. break;
  2882. }
  2883. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2884. case 0: /* four banks */
  2885. rdev->config.si.tile_config |= 0 << 4;
  2886. break;
  2887. case 1: /* eight banks */
  2888. rdev->config.si.tile_config |= 1 << 4;
  2889. break;
  2890. case 2: /* sixteen banks */
  2891. default:
  2892. rdev->config.si.tile_config |= 2 << 4;
  2893. break;
  2894. }
  2895. rdev->config.si.tile_config |=
  2896. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2897. rdev->config.si.tile_config |=
  2898. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2899. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2900. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2901. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2902. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2903. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2904. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2905. if (rdev->has_uvd) {
  2906. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2907. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2908. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2909. }
  2910. si_tiling_mode_table_init(rdev);
  2911. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2912. rdev->config.si.max_sh_per_se,
  2913. rdev->config.si.max_backends_per_se);
  2914. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2915. rdev->config.si.max_sh_per_se,
  2916. rdev->config.si.max_cu_per_sh);
  2917. /* set HW defaults for 3D engine */
  2918. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2919. ROQ_IB2_START(0x2b)));
  2920. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2921. sx_debug_1 = RREG32(SX_DEBUG_1);
  2922. WREG32(SX_DEBUG_1, sx_debug_1);
  2923. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2924. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2925. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2926. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2927. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2928. WREG32(VGT_NUM_INSTANCES, 1);
  2929. WREG32(CP_PERFMON_CNTL, 0);
  2930. WREG32(SQ_CONFIG, 0);
  2931. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2932. FORCE_EOV_MAX_REZ_CNT(255)));
  2933. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2934. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2935. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2936. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2937. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2938. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2939. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2940. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2941. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2942. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2943. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2944. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2945. tmp = RREG32(HDP_MISC_CNTL);
  2946. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2947. WREG32(HDP_MISC_CNTL, tmp);
  2948. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2949. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2950. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2951. udelay(50);
  2952. }
  2953. /*
  2954. * GPU scratch registers helpers function.
  2955. */
  2956. static void si_scratch_init(struct radeon_device *rdev)
  2957. {
  2958. int i;
  2959. rdev->scratch.num_reg = 7;
  2960. rdev->scratch.reg_base = SCRATCH_REG0;
  2961. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2962. rdev->scratch.free[i] = true;
  2963. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2964. }
  2965. }
  2966. void si_fence_ring_emit(struct radeon_device *rdev,
  2967. struct radeon_fence *fence)
  2968. {
  2969. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2970. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2971. /* flush read cache over gart */
  2972. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2973. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2974. radeon_ring_write(ring, 0);
  2975. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2976. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2977. PACKET3_TC_ACTION_ENA |
  2978. PACKET3_SH_KCACHE_ACTION_ENA |
  2979. PACKET3_SH_ICACHE_ACTION_ENA);
  2980. radeon_ring_write(ring, 0xFFFFFFFF);
  2981. radeon_ring_write(ring, 0);
  2982. radeon_ring_write(ring, 10); /* poll interval */
  2983. /* EVENT_WRITE_EOP - flush caches, send int */
  2984. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2985. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2986. radeon_ring_write(ring, addr & 0xffffffff);
  2987. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2988. radeon_ring_write(ring, fence->seq);
  2989. radeon_ring_write(ring, 0);
  2990. }
  2991. /*
  2992. * IB stuff
  2993. */
  2994. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2995. {
  2996. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2997. u32 header;
  2998. if (ib->is_const_ib) {
  2999. /* set switch buffer packet before const IB */
  3000. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3001. radeon_ring_write(ring, 0);
  3002. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  3003. } else {
  3004. u32 next_rptr;
  3005. if (ring->rptr_save_reg) {
  3006. next_rptr = ring->wptr + 3 + 4 + 8;
  3007. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3008. radeon_ring_write(ring, ((ring->rptr_save_reg -
  3009. PACKET3_SET_CONFIG_REG_START) >> 2));
  3010. radeon_ring_write(ring, next_rptr);
  3011. } else if (rdev->wb.enabled) {
  3012. next_rptr = ring->wptr + 5 + 4 + 8;
  3013. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3014. radeon_ring_write(ring, (1 << 8));
  3015. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3016. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  3017. radeon_ring_write(ring, next_rptr);
  3018. }
  3019. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  3020. }
  3021. radeon_ring_write(ring, header);
  3022. radeon_ring_write(ring,
  3023. #ifdef __BIG_ENDIAN
  3024. (2 << 0) |
  3025. #endif
  3026. (ib->gpu_addr & 0xFFFFFFFC));
  3027. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  3028. radeon_ring_write(ring, ib->length_dw |
  3029. (ib->vm ? (ib->vm->id << 24) : 0));
  3030. if (!ib->is_const_ib) {
  3031. /* flush read cache over gart for this vmid */
  3032. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3033. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  3034. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  3035. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  3036. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  3037. PACKET3_TC_ACTION_ENA |
  3038. PACKET3_SH_KCACHE_ACTION_ENA |
  3039. PACKET3_SH_ICACHE_ACTION_ENA);
  3040. radeon_ring_write(ring, 0xFFFFFFFF);
  3041. radeon_ring_write(ring, 0);
  3042. radeon_ring_write(ring, 10); /* poll interval */
  3043. }
  3044. }
  3045. /*
  3046. * CP.
  3047. */
  3048. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  3049. {
  3050. if (enable)
  3051. WREG32(CP_ME_CNTL, 0);
  3052. else {
  3053. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  3054. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  3055. WREG32(SCRATCH_UMSK, 0);
  3056. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3057. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3058. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3059. }
  3060. udelay(50);
  3061. }
  3062. static int si_cp_load_microcode(struct radeon_device *rdev)
  3063. {
  3064. const __be32 *fw_data;
  3065. int i;
  3066. if (!rdev->me_fw || !rdev->pfp_fw)
  3067. return -EINVAL;
  3068. si_cp_enable(rdev, false);
  3069. /* PFP */
  3070. fw_data = (const __be32 *)rdev->pfp_fw->data;
  3071. WREG32(CP_PFP_UCODE_ADDR, 0);
  3072. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  3073. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  3074. WREG32(CP_PFP_UCODE_ADDR, 0);
  3075. /* CE */
  3076. fw_data = (const __be32 *)rdev->ce_fw->data;
  3077. WREG32(CP_CE_UCODE_ADDR, 0);
  3078. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  3079. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  3080. WREG32(CP_CE_UCODE_ADDR, 0);
  3081. /* ME */
  3082. fw_data = (const __be32 *)rdev->me_fw->data;
  3083. WREG32(CP_ME_RAM_WADDR, 0);
  3084. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  3085. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  3086. WREG32(CP_ME_RAM_WADDR, 0);
  3087. WREG32(CP_PFP_UCODE_ADDR, 0);
  3088. WREG32(CP_CE_UCODE_ADDR, 0);
  3089. WREG32(CP_ME_RAM_WADDR, 0);
  3090. WREG32(CP_ME_RAM_RADDR, 0);
  3091. return 0;
  3092. }
  3093. static int si_cp_start(struct radeon_device *rdev)
  3094. {
  3095. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3096. int r, i;
  3097. r = radeon_ring_lock(rdev, ring, 7 + 4);
  3098. if (r) {
  3099. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3100. return r;
  3101. }
  3102. /* init the CP */
  3103. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  3104. radeon_ring_write(ring, 0x1);
  3105. radeon_ring_write(ring, 0x0);
  3106. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  3107. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  3108. radeon_ring_write(ring, 0);
  3109. radeon_ring_write(ring, 0);
  3110. /* init the CE partitions */
  3111. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  3112. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  3113. radeon_ring_write(ring, 0xc000);
  3114. radeon_ring_write(ring, 0xe000);
  3115. radeon_ring_unlock_commit(rdev, ring);
  3116. si_cp_enable(rdev, true);
  3117. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  3118. if (r) {
  3119. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3120. return r;
  3121. }
  3122. /* setup clear context state */
  3123. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3124. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3125. for (i = 0; i < si_default_size; i++)
  3126. radeon_ring_write(ring, si_default_state[i]);
  3127. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3128. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  3129. /* set clear context state */
  3130. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  3131. radeon_ring_write(ring, 0);
  3132. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3133. radeon_ring_write(ring, 0x00000316);
  3134. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  3135. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  3136. radeon_ring_unlock_commit(rdev, ring);
  3137. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  3138. ring = &rdev->ring[i];
  3139. r = radeon_ring_lock(rdev, ring, 2);
  3140. /* clear the compute context state */
  3141. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  3142. radeon_ring_write(ring, 0);
  3143. radeon_ring_unlock_commit(rdev, ring);
  3144. }
  3145. return 0;
  3146. }
  3147. static void si_cp_fini(struct radeon_device *rdev)
  3148. {
  3149. struct radeon_ring *ring;
  3150. si_cp_enable(rdev, false);
  3151. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3152. radeon_ring_fini(rdev, ring);
  3153. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3154. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3155. radeon_ring_fini(rdev, ring);
  3156. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3157. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3158. radeon_ring_fini(rdev, ring);
  3159. radeon_scratch_free(rdev, ring->rptr_save_reg);
  3160. }
  3161. static int si_cp_resume(struct radeon_device *rdev)
  3162. {
  3163. struct radeon_ring *ring;
  3164. u32 tmp;
  3165. u32 rb_bufsz;
  3166. int r;
  3167. si_enable_gui_idle_interrupt(rdev, false);
  3168. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  3169. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  3170. /* Set the write pointer delay */
  3171. WREG32(CP_RB_WPTR_DELAY, 0);
  3172. WREG32(CP_DEBUG, 0);
  3173. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  3174. /* ring 0 - compute and gfx */
  3175. /* Set ring buffer size */
  3176. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3177. rb_bufsz = order_base_2(ring->ring_size / 8);
  3178. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3179. #ifdef __BIG_ENDIAN
  3180. tmp |= BUF_SWAP_32BIT;
  3181. #endif
  3182. WREG32(CP_RB0_CNTL, tmp);
  3183. /* Initialize the ring buffer's read and write pointers */
  3184. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  3185. ring->wptr = 0;
  3186. WREG32(CP_RB0_WPTR, ring->wptr);
  3187. /* set the wb address whether it's enabled or not */
  3188. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  3189. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  3190. if (rdev->wb.enabled)
  3191. WREG32(SCRATCH_UMSK, 0xff);
  3192. else {
  3193. tmp |= RB_NO_UPDATE;
  3194. WREG32(SCRATCH_UMSK, 0);
  3195. }
  3196. mdelay(1);
  3197. WREG32(CP_RB0_CNTL, tmp);
  3198. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  3199. ring->rptr = RREG32(CP_RB0_RPTR);
  3200. /* ring1 - compute only */
  3201. /* Set ring buffer size */
  3202. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  3203. rb_bufsz = order_base_2(ring->ring_size / 8);
  3204. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3205. #ifdef __BIG_ENDIAN
  3206. tmp |= BUF_SWAP_32BIT;
  3207. #endif
  3208. WREG32(CP_RB1_CNTL, tmp);
  3209. /* Initialize the ring buffer's read and write pointers */
  3210. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  3211. ring->wptr = 0;
  3212. WREG32(CP_RB1_WPTR, ring->wptr);
  3213. /* set the wb address whether it's enabled or not */
  3214. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  3215. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  3216. mdelay(1);
  3217. WREG32(CP_RB1_CNTL, tmp);
  3218. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  3219. ring->rptr = RREG32(CP_RB1_RPTR);
  3220. /* ring2 - compute only */
  3221. /* Set ring buffer size */
  3222. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  3223. rb_bufsz = order_base_2(ring->ring_size / 8);
  3224. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  3225. #ifdef __BIG_ENDIAN
  3226. tmp |= BUF_SWAP_32BIT;
  3227. #endif
  3228. WREG32(CP_RB2_CNTL, tmp);
  3229. /* Initialize the ring buffer's read and write pointers */
  3230. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  3231. ring->wptr = 0;
  3232. WREG32(CP_RB2_WPTR, ring->wptr);
  3233. /* set the wb address whether it's enabled or not */
  3234. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  3235. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  3236. mdelay(1);
  3237. WREG32(CP_RB2_CNTL, tmp);
  3238. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  3239. ring->rptr = RREG32(CP_RB2_RPTR);
  3240. /* start the rings */
  3241. si_cp_start(rdev);
  3242. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  3243. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  3244. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  3245. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  3246. if (r) {
  3247. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  3248. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3249. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3250. return r;
  3251. }
  3252. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  3253. if (r) {
  3254. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3255. }
  3256. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  3257. if (r) {
  3258. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3259. }
  3260. si_enable_gui_idle_interrupt(rdev, true);
  3261. return 0;
  3262. }
  3263. u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  3264. {
  3265. u32 reset_mask = 0;
  3266. u32 tmp;
  3267. /* GRBM_STATUS */
  3268. tmp = RREG32(GRBM_STATUS);
  3269. if (tmp & (PA_BUSY | SC_BUSY |
  3270. BCI_BUSY | SX_BUSY |
  3271. TA_BUSY | VGT_BUSY |
  3272. DB_BUSY | CB_BUSY |
  3273. GDS_BUSY | SPI_BUSY |
  3274. IA_BUSY | IA_BUSY_NO_DMA))
  3275. reset_mask |= RADEON_RESET_GFX;
  3276. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3277. CP_BUSY | CP_COHERENCY_BUSY))
  3278. reset_mask |= RADEON_RESET_CP;
  3279. if (tmp & GRBM_EE_BUSY)
  3280. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3281. /* GRBM_STATUS2 */
  3282. tmp = RREG32(GRBM_STATUS2);
  3283. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3284. reset_mask |= RADEON_RESET_RLC;
  3285. /* DMA_STATUS_REG 0 */
  3286. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  3287. if (!(tmp & DMA_IDLE))
  3288. reset_mask |= RADEON_RESET_DMA;
  3289. /* DMA_STATUS_REG 1 */
  3290. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  3291. if (!(tmp & DMA_IDLE))
  3292. reset_mask |= RADEON_RESET_DMA1;
  3293. /* SRBM_STATUS2 */
  3294. tmp = RREG32(SRBM_STATUS2);
  3295. if (tmp & DMA_BUSY)
  3296. reset_mask |= RADEON_RESET_DMA;
  3297. if (tmp & DMA1_BUSY)
  3298. reset_mask |= RADEON_RESET_DMA1;
  3299. /* SRBM_STATUS */
  3300. tmp = RREG32(SRBM_STATUS);
  3301. if (tmp & IH_BUSY)
  3302. reset_mask |= RADEON_RESET_IH;
  3303. if (tmp & SEM_BUSY)
  3304. reset_mask |= RADEON_RESET_SEM;
  3305. if (tmp & GRBM_RQ_PENDING)
  3306. reset_mask |= RADEON_RESET_GRBM;
  3307. if (tmp & VMC_BUSY)
  3308. reset_mask |= RADEON_RESET_VMC;
  3309. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3310. MCC_BUSY | MCD_BUSY))
  3311. reset_mask |= RADEON_RESET_MC;
  3312. if (evergreen_is_display_hung(rdev))
  3313. reset_mask |= RADEON_RESET_DISPLAY;
  3314. /* VM_L2_STATUS */
  3315. tmp = RREG32(VM_L2_STATUS);
  3316. if (tmp & L2_BUSY)
  3317. reset_mask |= RADEON_RESET_VMC;
  3318. /* Skip MC reset as it's mostly likely not hung, just busy */
  3319. if (reset_mask & RADEON_RESET_MC) {
  3320. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3321. reset_mask &= ~RADEON_RESET_MC;
  3322. }
  3323. return reset_mask;
  3324. }
  3325. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3326. {
  3327. struct evergreen_mc_save save;
  3328. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3329. u32 tmp;
  3330. if (reset_mask == 0)
  3331. return;
  3332. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3333. evergreen_print_gpu_status_regs(rdev);
  3334. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  3335. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  3336. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  3337. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  3338. /* disable PG/CG */
  3339. si_fini_pg(rdev);
  3340. si_fini_cg(rdev);
  3341. /* stop the rlc */
  3342. si_rlc_stop(rdev);
  3343. /* Disable CP parsing/prefetching */
  3344. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  3345. if (reset_mask & RADEON_RESET_DMA) {
  3346. /* dma0 */
  3347. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  3348. tmp &= ~DMA_RB_ENABLE;
  3349. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3350. }
  3351. if (reset_mask & RADEON_RESET_DMA1) {
  3352. /* dma1 */
  3353. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  3354. tmp &= ~DMA_RB_ENABLE;
  3355. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3356. }
  3357. udelay(50);
  3358. evergreen_mc_stop(rdev, &save);
  3359. if (evergreen_mc_wait_for_idle(rdev)) {
  3360. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3361. }
  3362. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  3363. grbm_soft_reset = SOFT_RESET_CB |
  3364. SOFT_RESET_DB |
  3365. SOFT_RESET_GDS |
  3366. SOFT_RESET_PA |
  3367. SOFT_RESET_SC |
  3368. SOFT_RESET_BCI |
  3369. SOFT_RESET_SPI |
  3370. SOFT_RESET_SX |
  3371. SOFT_RESET_TC |
  3372. SOFT_RESET_TA |
  3373. SOFT_RESET_VGT |
  3374. SOFT_RESET_IA;
  3375. }
  3376. if (reset_mask & RADEON_RESET_CP) {
  3377. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  3378. srbm_soft_reset |= SOFT_RESET_GRBM;
  3379. }
  3380. if (reset_mask & RADEON_RESET_DMA)
  3381. srbm_soft_reset |= SOFT_RESET_DMA;
  3382. if (reset_mask & RADEON_RESET_DMA1)
  3383. srbm_soft_reset |= SOFT_RESET_DMA1;
  3384. if (reset_mask & RADEON_RESET_DISPLAY)
  3385. srbm_soft_reset |= SOFT_RESET_DC;
  3386. if (reset_mask & RADEON_RESET_RLC)
  3387. grbm_soft_reset |= SOFT_RESET_RLC;
  3388. if (reset_mask & RADEON_RESET_SEM)
  3389. srbm_soft_reset |= SOFT_RESET_SEM;
  3390. if (reset_mask & RADEON_RESET_IH)
  3391. srbm_soft_reset |= SOFT_RESET_IH;
  3392. if (reset_mask & RADEON_RESET_GRBM)
  3393. srbm_soft_reset |= SOFT_RESET_GRBM;
  3394. if (reset_mask & RADEON_RESET_VMC)
  3395. srbm_soft_reset |= SOFT_RESET_VMC;
  3396. if (reset_mask & RADEON_RESET_MC)
  3397. srbm_soft_reset |= SOFT_RESET_MC;
  3398. if (grbm_soft_reset) {
  3399. tmp = RREG32(GRBM_SOFT_RESET);
  3400. tmp |= grbm_soft_reset;
  3401. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3402. WREG32(GRBM_SOFT_RESET, tmp);
  3403. tmp = RREG32(GRBM_SOFT_RESET);
  3404. udelay(50);
  3405. tmp &= ~grbm_soft_reset;
  3406. WREG32(GRBM_SOFT_RESET, tmp);
  3407. tmp = RREG32(GRBM_SOFT_RESET);
  3408. }
  3409. if (srbm_soft_reset) {
  3410. tmp = RREG32(SRBM_SOFT_RESET);
  3411. tmp |= srbm_soft_reset;
  3412. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3413. WREG32(SRBM_SOFT_RESET, tmp);
  3414. tmp = RREG32(SRBM_SOFT_RESET);
  3415. udelay(50);
  3416. tmp &= ~srbm_soft_reset;
  3417. WREG32(SRBM_SOFT_RESET, tmp);
  3418. tmp = RREG32(SRBM_SOFT_RESET);
  3419. }
  3420. /* Wait a little for things to settle down */
  3421. udelay(50);
  3422. evergreen_mc_resume(rdev, &save);
  3423. udelay(50);
  3424. evergreen_print_gpu_status_regs(rdev);
  3425. }
  3426. int si_asic_reset(struct radeon_device *rdev)
  3427. {
  3428. u32 reset_mask;
  3429. reset_mask = si_gpu_check_soft_reset(rdev);
  3430. if (reset_mask)
  3431. r600_set_bios_scratch_engine_hung(rdev, true);
  3432. si_gpu_soft_reset(rdev, reset_mask);
  3433. reset_mask = si_gpu_check_soft_reset(rdev);
  3434. if (!reset_mask)
  3435. r600_set_bios_scratch_engine_hung(rdev, false);
  3436. return 0;
  3437. }
  3438. /**
  3439. * si_gfx_is_lockup - Check if the GFX engine is locked up
  3440. *
  3441. * @rdev: radeon_device pointer
  3442. * @ring: radeon_ring structure holding ring information
  3443. *
  3444. * Check if the GFX engine is locked up.
  3445. * Returns true if the engine appears to be locked up, false if not.
  3446. */
  3447. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3448. {
  3449. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3450. if (!(reset_mask & (RADEON_RESET_GFX |
  3451. RADEON_RESET_COMPUTE |
  3452. RADEON_RESET_CP))) {
  3453. radeon_ring_lockup_update(ring);
  3454. return false;
  3455. }
  3456. /* force CP activities */
  3457. radeon_ring_force_activity(rdev, ring);
  3458. return radeon_ring_test_lockup(rdev, ring);
  3459. }
  3460. /* MC */
  3461. static void si_mc_program(struct radeon_device *rdev)
  3462. {
  3463. struct evergreen_mc_save save;
  3464. u32 tmp;
  3465. int i, j;
  3466. /* Initialize HDP */
  3467. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3468. WREG32((0x2c14 + j), 0x00000000);
  3469. WREG32((0x2c18 + j), 0x00000000);
  3470. WREG32((0x2c1c + j), 0x00000000);
  3471. WREG32((0x2c20 + j), 0x00000000);
  3472. WREG32((0x2c24 + j), 0x00000000);
  3473. }
  3474. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3475. evergreen_mc_stop(rdev, &save);
  3476. if (radeon_mc_wait_for_idle(rdev)) {
  3477. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3478. }
  3479. if (!ASIC_IS_NODCE(rdev))
  3480. /* Lockout access through VGA aperture*/
  3481. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3482. /* Update configuration */
  3483. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3484. rdev->mc.vram_start >> 12);
  3485. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3486. rdev->mc.vram_end >> 12);
  3487. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3488. rdev->vram_scratch.gpu_addr >> 12);
  3489. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3490. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3491. WREG32(MC_VM_FB_LOCATION, tmp);
  3492. /* XXX double check these! */
  3493. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3494. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3495. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3496. WREG32(MC_VM_AGP_BASE, 0);
  3497. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3498. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3499. if (radeon_mc_wait_for_idle(rdev)) {
  3500. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3501. }
  3502. evergreen_mc_resume(rdev, &save);
  3503. if (!ASIC_IS_NODCE(rdev)) {
  3504. /* we need to own VRAM, so turn off the VGA renderer here
  3505. * to stop it overwriting our objects */
  3506. rv515_vga_render_disable(rdev);
  3507. }
  3508. }
  3509. void si_vram_gtt_location(struct radeon_device *rdev,
  3510. struct radeon_mc *mc)
  3511. {
  3512. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3513. /* leave room for at least 1024M GTT */
  3514. dev_warn(rdev->dev, "limiting VRAM\n");
  3515. mc->real_vram_size = 0xFFC0000000ULL;
  3516. mc->mc_vram_size = 0xFFC0000000ULL;
  3517. }
  3518. radeon_vram_location(rdev, &rdev->mc, 0);
  3519. rdev->mc.gtt_base_align = 0;
  3520. radeon_gtt_location(rdev, mc);
  3521. }
  3522. static int si_mc_init(struct radeon_device *rdev)
  3523. {
  3524. u32 tmp;
  3525. int chansize, numchan;
  3526. /* Get VRAM informations */
  3527. rdev->mc.vram_is_ddr = true;
  3528. tmp = RREG32(MC_ARB_RAMCFG);
  3529. if (tmp & CHANSIZE_OVERRIDE) {
  3530. chansize = 16;
  3531. } else if (tmp & CHANSIZE_MASK) {
  3532. chansize = 64;
  3533. } else {
  3534. chansize = 32;
  3535. }
  3536. tmp = RREG32(MC_SHARED_CHMAP);
  3537. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3538. case 0:
  3539. default:
  3540. numchan = 1;
  3541. break;
  3542. case 1:
  3543. numchan = 2;
  3544. break;
  3545. case 2:
  3546. numchan = 4;
  3547. break;
  3548. case 3:
  3549. numchan = 8;
  3550. break;
  3551. case 4:
  3552. numchan = 3;
  3553. break;
  3554. case 5:
  3555. numchan = 6;
  3556. break;
  3557. case 6:
  3558. numchan = 10;
  3559. break;
  3560. case 7:
  3561. numchan = 12;
  3562. break;
  3563. case 8:
  3564. numchan = 16;
  3565. break;
  3566. }
  3567. rdev->mc.vram_width = numchan * chansize;
  3568. /* Could aper size report 0 ? */
  3569. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3570. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3571. /* size in MB on si */
  3572. tmp = RREG32(CONFIG_MEMSIZE);
  3573. /* some boards may have garbage in the upper 16 bits */
  3574. if (tmp & 0xffff0000) {
  3575. DRM_INFO("Probable bad vram size: 0x%08x\n", tmp);
  3576. if (tmp & 0xffff)
  3577. tmp &= 0xffff;
  3578. }
  3579. rdev->mc.mc_vram_size = tmp * 1024ULL * 1024ULL;
  3580. rdev->mc.real_vram_size = rdev->mc.mc_vram_size;
  3581. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3582. si_vram_gtt_location(rdev, &rdev->mc);
  3583. radeon_update_bandwidth_info(rdev);
  3584. return 0;
  3585. }
  3586. /*
  3587. * GART
  3588. */
  3589. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3590. {
  3591. /* flush hdp cache */
  3592. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3593. /* bits 0-15 are the VM contexts0-15 */
  3594. WREG32(VM_INVALIDATE_REQUEST, 1);
  3595. }
  3596. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3597. {
  3598. int r, i;
  3599. if (rdev->gart.robj == NULL) {
  3600. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3601. return -EINVAL;
  3602. }
  3603. r = radeon_gart_table_vram_pin(rdev);
  3604. if (r)
  3605. return r;
  3606. radeon_gart_restore(rdev);
  3607. /* Setup TLB control */
  3608. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3609. (0xA << 7) |
  3610. ENABLE_L1_TLB |
  3611. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3612. ENABLE_ADVANCED_DRIVER_MODEL |
  3613. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3614. /* Setup L2 cache */
  3615. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3616. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3617. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3618. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3619. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3620. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3621. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3622. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3623. /* setup context0 */
  3624. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3625. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3626. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3627. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3628. (u32)(rdev->dummy_page.addr >> 12));
  3629. WREG32(VM_CONTEXT0_CNTL2, 0);
  3630. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3631. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3632. WREG32(0x15D4, 0);
  3633. WREG32(0x15D8, 0);
  3634. WREG32(0x15DC, 0);
  3635. /* empty context1-15 */
  3636. /* set vm size, must be a multiple of 4 */
  3637. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3638. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3639. /* Assign the pt base to something valid for now; the pts used for
  3640. * the VMs are determined by the application and setup and assigned
  3641. * on the fly in the vm part of radeon_gart.c
  3642. */
  3643. for (i = 1; i < 16; i++) {
  3644. if (i < 8)
  3645. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3646. rdev->gart.table_addr >> 12);
  3647. else
  3648. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3649. rdev->gart.table_addr >> 12);
  3650. }
  3651. /* enable context1-15 */
  3652. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3653. (u32)(rdev->dummy_page.addr >> 12));
  3654. WREG32(VM_CONTEXT1_CNTL2, 4);
  3655. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3656. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3657. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3658. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3659. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3660. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3661. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3662. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3663. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3664. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3665. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3666. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3667. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3668. si_pcie_gart_tlb_flush(rdev);
  3669. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3670. (unsigned)(rdev->mc.gtt_size >> 20),
  3671. (unsigned long long)rdev->gart.table_addr);
  3672. rdev->gart.ready = true;
  3673. return 0;
  3674. }
  3675. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3676. {
  3677. /* Disable all tables */
  3678. WREG32(VM_CONTEXT0_CNTL, 0);
  3679. WREG32(VM_CONTEXT1_CNTL, 0);
  3680. /* Setup TLB control */
  3681. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3682. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3683. /* Setup L2 cache */
  3684. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3685. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3686. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3687. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3688. WREG32(VM_L2_CNTL2, 0);
  3689. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3690. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3691. radeon_gart_table_vram_unpin(rdev);
  3692. }
  3693. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3694. {
  3695. si_pcie_gart_disable(rdev);
  3696. radeon_gart_table_vram_free(rdev);
  3697. radeon_gart_fini(rdev);
  3698. }
  3699. /* vm parser */
  3700. static bool si_vm_reg_valid(u32 reg)
  3701. {
  3702. /* context regs are fine */
  3703. if (reg >= 0x28000)
  3704. return true;
  3705. /* check config regs */
  3706. switch (reg) {
  3707. case GRBM_GFX_INDEX:
  3708. case CP_STRMOUT_CNTL:
  3709. case VGT_VTX_VECT_EJECT_REG:
  3710. case VGT_CACHE_INVALIDATION:
  3711. case VGT_ESGS_RING_SIZE:
  3712. case VGT_GSVS_RING_SIZE:
  3713. case VGT_GS_VERTEX_REUSE:
  3714. case VGT_PRIMITIVE_TYPE:
  3715. case VGT_INDEX_TYPE:
  3716. case VGT_NUM_INDICES:
  3717. case VGT_NUM_INSTANCES:
  3718. case VGT_TF_RING_SIZE:
  3719. case VGT_HS_OFFCHIP_PARAM:
  3720. case VGT_TF_MEMORY_BASE:
  3721. case PA_CL_ENHANCE:
  3722. case PA_SU_LINE_STIPPLE_VALUE:
  3723. case PA_SC_LINE_STIPPLE_STATE:
  3724. case PA_SC_ENHANCE:
  3725. case SQC_CACHES:
  3726. case SPI_STATIC_THREAD_MGMT_1:
  3727. case SPI_STATIC_THREAD_MGMT_2:
  3728. case SPI_STATIC_THREAD_MGMT_3:
  3729. case SPI_PS_MAX_WAVE_ID:
  3730. case SPI_CONFIG_CNTL:
  3731. case SPI_CONFIG_CNTL_1:
  3732. case TA_CNTL_AUX:
  3733. return true;
  3734. default:
  3735. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3736. return false;
  3737. }
  3738. }
  3739. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3740. u32 *ib, struct radeon_cs_packet *pkt)
  3741. {
  3742. switch (pkt->opcode) {
  3743. case PACKET3_NOP:
  3744. case PACKET3_SET_BASE:
  3745. case PACKET3_SET_CE_DE_COUNTERS:
  3746. case PACKET3_LOAD_CONST_RAM:
  3747. case PACKET3_WRITE_CONST_RAM:
  3748. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3749. case PACKET3_DUMP_CONST_RAM:
  3750. case PACKET3_INCREMENT_CE_COUNTER:
  3751. case PACKET3_WAIT_ON_DE_COUNTER:
  3752. case PACKET3_CE_WRITE:
  3753. break;
  3754. default:
  3755. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3756. return -EINVAL;
  3757. }
  3758. return 0;
  3759. }
  3760. static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
  3761. {
  3762. u32 start_reg, reg, i;
  3763. u32 command = ib[idx + 4];
  3764. u32 info = ib[idx + 1];
  3765. u32 idx_value = ib[idx];
  3766. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3767. /* src address space is register */
  3768. if (((info & 0x60000000) >> 29) == 0) {
  3769. start_reg = idx_value << 2;
  3770. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3771. reg = start_reg;
  3772. if (!si_vm_reg_valid(reg)) {
  3773. DRM_ERROR("CP DMA Bad SRC register\n");
  3774. return -EINVAL;
  3775. }
  3776. } else {
  3777. for (i = 0; i < (command & 0x1fffff); i++) {
  3778. reg = start_reg + (4 * i);
  3779. if (!si_vm_reg_valid(reg)) {
  3780. DRM_ERROR("CP DMA Bad SRC register\n");
  3781. return -EINVAL;
  3782. }
  3783. }
  3784. }
  3785. }
  3786. }
  3787. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3788. /* dst address space is register */
  3789. if (((info & 0x00300000) >> 20) == 0) {
  3790. start_reg = ib[idx + 2];
  3791. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3792. reg = start_reg;
  3793. if (!si_vm_reg_valid(reg)) {
  3794. DRM_ERROR("CP DMA Bad DST register\n");
  3795. return -EINVAL;
  3796. }
  3797. } else {
  3798. for (i = 0; i < (command & 0x1fffff); i++) {
  3799. reg = start_reg + (4 * i);
  3800. if (!si_vm_reg_valid(reg)) {
  3801. DRM_ERROR("CP DMA Bad DST register\n");
  3802. return -EINVAL;
  3803. }
  3804. }
  3805. }
  3806. }
  3807. }
  3808. return 0;
  3809. }
  3810. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3811. u32 *ib, struct radeon_cs_packet *pkt)
  3812. {
  3813. int r;
  3814. u32 idx = pkt->idx + 1;
  3815. u32 idx_value = ib[idx];
  3816. u32 start_reg, end_reg, reg, i;
  3817. switch (pkt->opcode) {
  3818. case PACKET3_NOP:
  3819. case PACKET3_SET_BASE:
  3820. case PACKET3_CLEAR_STATE:
  3821. case PACKET3_INDEX_BUFFER_SIZE:
  3822. case PACKET3_DISPATCH_DIRECT:
  3823. case PACKET3_DISPATCH_INDIRECT:
  3824. case PACKET3_ALLOC_GDS:
  3825. case PACKET3_WRITE_GDS_RAM:
  3826. case PACKET3_ATOMIC_GDS:
  3827. case PACKET3_ATOMIC:
  3828. case PACKET3_OCCLUSION_QUERY:
  3829. case PACKET3_SET_PREDICATION:
  3830. case PACKET3_COND_EXEC:
  3831. case PACKET3_PRED_EXEC:
  3832. case PACKET3_DRAW_INDIRECT:
  3833. case PACKET3_DRAW_INDEX_INDIRECT:
  3834. case PACKET3_INDEX_BASE:
  3835. case PACKET3_DRAW_INDEX_2:
  3836. case PACKET3_CONTEXT_CONTROL:
  3837. case PACKET3_INDEX_TYPE:
  3838. case PACKET3_DRAW_INDIRECT_MULTI:
  3839. case PACKET3_DRAW_INDEX_AUTO:
  3840. case PACKET3_DRAW_INDEX_IMMD:
  3841. case PACKET3_NUM_INSTANCES:
  3842. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3843. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3844. case PACKET3_DRAW_INDEX_OFFSET_2:
  3845. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3846. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3847. case PACKET3_MPEG_INDEX:
  3848. case PACKET3_WAIT_REG_MEM:
  3849. case PACKET3_MEM_WRITE:
  3850. case PACKET3_PFP_SYNC_ME:
  3851. case PACKET3_SURFACE_SYNC:
  3852. case PACKET3_EVENT_WRITE:
  3853. case PACKET3_EVENT_WRITE_EOP:
  3854. case PACKET3_EVENT_WRITE_EOS:
  3855. case PACKET3_SET_CONTEXT_REG:
  3856. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3857. case PACKET3_SET_SH_REG:
  3858. case PACKET3_SET_SH_REG_OFFSET:
  3859. case PACKET3_INCREMENT_DE_COUNTER:
  3860. case PACKET3_WAIT_ON_CE_COUNTER:
  3861. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3862. case PACKET3_ME_WRITE:
  3863. break;
  3864. case PACKET3_COPY_DATA:
  3865. if ((idx_value & 0xf00) == 0) {
  3866. reg = ib[idx + 3] * 4;
  3867. if (!si_vm_reg_valid(reg))
  3868. return -EINVAL;
  3869. }
  3870. break;
  3871. case PACKET3_WRITE_DATA:
  3872. if ((idx_value & 0xf00) == 0) {
  3873. start_reg = ib[idx + 1] * 4;
  3874. if (idx_value & 0x10000) {
  3875. if (!si_vm_reg_valid(start_reg))
  3876. return -EINVAL;
  3877. } else {
  3878. for (i = 0; i < (pkt->count - 2); i++) {
  3879. reg = start_reg + (4 * i);
  3880. if (!si_vm_reg_valid(reg))
  3881. return -EINVAL;
  3882. }
  3883. }
  3884. }
  3885. break;
  3886. case PACKET3_COND_WRITE:
  3887. if (idx_value & 0x100) {
  3888. reg = ib[idx + 5] * 4;
  3889. if (!si_vm_reg_valid(reg))
  3890. return -EINVAL;
  3891. }
  3892. break;
  3893. case PACKET3_COPY_DW:
  3894. if (idx_value & 0x2) {
  3895. reg = ib[idx + 3] * 4;
  3896. if (!si_vm_reg_valid(reg))
  3897. return -EINVAL;
  3898. }
  3899. break;
  3900. case PACKET3_SET_CONFIG_REG:
  3901. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3902. end_reg = 4 * pkt->count + start_reg - 4;
  3903. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3904. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3905. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3906. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3907. return -EINVAL;
  3908. }
  3909. for (i = 0; i < pkt->count; i++) {
  3910. reg = start_reg + (4 * i);
  3911. if (!si_vm_reg_valid(reg))
  3912. return -EINVAL;
  3913. }
  3914. break;
  3915. case PACKET3_CP_DMA:
  3916. r = si_vm_packet3_cp_dma_check(ib, idx);
  3917. if (r)
  3918. return r;
  3919. break;
  3920. default:
  3921. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3922. return -EINVAL;
  3923. }
  3924. return 0;
  3925. }
  3926. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3927. u32 *ib, struct radeon_cs_packet *pkt)
  3928. {
  3929. int r;
  3930. u32 idx = pkt->idx + 1;
  3931. u32 idx_value = ib[idx];
  3932. u32 start_reg, reg, i;
  3933. switch (pkt->opcode) {
  3934. case PACKET3_NOP:
  3935. case PACKET3_SET_BASE:
  3936. case PACKET3_CLEAR_STATE:
  3937. case PACKET3_DISPATCH_DIRECT:
  3938. case PACKET3_DISPATCH_INDIRECT:
  3939. case PACKET3_ALLOC_GDS:
  3940. case PACKET3_WRITE_GDS_RAM:
  3941. case PACKET3_ATOMIC_GDS:
  3942. case PACKET3_ATOMIC:
  3943. case PACKET3_OCCLUSION_QUERY:
  3944. case PACKET3_SET_PREDICATION:
  3945. case PACKET3_COND_EXEC:
  3946. case PACKET3_PRED_EXEC:
  3947. case PACKET3_CONTEXT_CONTROL:
  3948. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3949. case PACKET3_WAIT_REG_MEM:
  3950. case PACKET3_MEM_WRITE:
  3951. case PACKET3_PFP_SYNC_ME:
  3952. case PACKET3_SURFACE_SYNC:
  3953. case PACKET3_EVENT_WRITE:
  3954. case PACKET3_EVENT_WRITE_EOP:
  3955. case PACKET3_EVENT_WRITE_EOS:
  3956. case PACKET3_SET_CONTEXT_REG:
  3957. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3958. case PACKET3_SET_SH_REG:
  3959. case PACKET3_SET_SH_REG_OFFSET:
  3960. case PACKET3_INCREMENT_DE_COUNTER:
  3961. case PACKET3_WAIT_ON_CE_COUNTER:
  3962. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3963. case PACKET3_ME_WRITE:
  3964. break;
  3965. case PACKET3_COPY_DATA:
  3966. if ((idx_value & 0xf00) == 0) {
  3967. reg = ib[idx + 3] * 4;
  3968. if (!si_vm_reg_valid(reg))
  3969. return -EINVAL;
  3970. }
  3971. break;
  3972. case PACKET3_WRITE_DATA:
  3973. if ((idx_value & 0xf00) == 0) {
  3974. start_reg = ib[idx + 1] * 4;
  3975. if (idx_value & 0x10000) {
  3976. if (!si_vm_reg_valid(start_reg))
  3977. return -EINVAL;
  3978. } else {
  3979. for (i = 0; i < (pkt->count - 2); i++) {
  3980. reg = start_reg + (4 * i);
  3981. if (!si_vm_reg_valid(reg))
  3982. return -EINVAL;
  3983. }
  3984. }
  3985. }
  3986. break;
  3987. case PACKET3_COND_WRITE:
  3988. if (idx_value & 0x100) {
  3989. reg = ib[idx + 5] * 4;
  3990. if (!si_vm_reg_valid(reg))
  3991. return -EINVAL;
  3992. }
  3993. break;
  3994. case PACKET3_COPY_DW:
  3995. if (idx_value & 0x2) {
  3996. reg = ib[idx + 3] * 4;
  3997. if (!si_vm_reg_valid(reg))
  3998. return -EINVAL;
  3999. }
  4000. break;
  4001. case PACKET3_CP_DMA:
  4002. r = si_vm_packet3_cp_dma_check(ib, idx);
  4003. if (r)
  4004. return r;
  4005. break;
  4006. default:
  4007. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  4008. return -EINVAL;
  4009. }
  4010. return 0;
  4011. }
  4012. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  4013. {
  4014. int ret = 0;
  4015. u32 idx = 0;
  4016. struct radeon_cs_packet pkt;
  4017. do {
  4018. pkt.idx = idx;
  4019. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  4020. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  4021. pkt.one_reg_wr = 0;
  4022. switch (pkt.type) {
  4023. case RADEON_PACKET_TYPE0:
  4024. dev_err(rdev->dev, "Packet0 not allowed!\n");
  4025. ret = -EINVAL;
  4026. break;
  4027. case RADEON_PACKET_TYPE2:
  4028. idx += 1;
  4029. break;
  4030. case RADEON_PACKET_TYPE3:
  4031. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  4032. if (ib->is_const_ib)
  4033. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  4034. else {
  4035. switch (ib->ring) {
  4036. case RADEON_RING_TYPE_GFX_INDEX:
  4037. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  4038. break;
  4039. case CAYMAN_RING_TYPE_CP1_INDEX:
  4040. case CAYMAN_RING_TYPE_CP2_INDEX:
  4041. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  4042. break;
  4043. default:
  4044. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  4045. ret = -EINVAL;
  4046. break;
  4047. }
  4048. }
  4049. idx += pkt.count + 2;
  4050. break;
  4051. default:
  4052. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  4053. ret = -EINVAL;
  4054. break;
  4055. }
  4056. if (ret)
  4057. break;
  4058. } while (idx < ib->length_dw);
  4059. return ret;
  4060. }
  4061. /*
  4062. * vm
  4063. */
  4064. int si_vm_init(struct radeon_device *rdev)
  4065. {
  4066. /* number of VMs */
  4067. rdev->vm_manager.nvm = 16;
  4068. /* base offset of vram pages */
  4069. rdev->vm_manager.vram_base_offset = 0;
  4070. return 0;
  4071. }
  4072. void si_vm_fini(struct radeon_device *rdev)
  4073. {
  4074. }
  4075. /**
  4076. * si_vm_decode_fault - print human readable fault info
  4077. *
  4078. * @rdev: radeon_device pointer
  4079. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  4080. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  4081. *
  4082. * Print human readable fault information (SI).
  4083. */
  4084. static void si_vm_decode_fault(struct radeon_device *rdev,
  4085. u32 status, u32 addr)
  4086. {
  4087. u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  4088. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  4089. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  4090. char *block;
  4091. if (rdev->family == CHIP_TAHITI) {
  4092. switch (mc_id) {
  4093. case 160:
  4094. case 144:
  4095. case 96:
  4096. case 80:
  4097. case 224:
  4098. case 208:
  4099. case 32:
  4100. case 16:
  4101. block = "CB";
  4102. break;
  4103. case 161:
  4104. case 145:
  4105. case 97:
  4106. case 81:
  4107. case 225:
  4108. case 209:
  4109. case 33:
  4110. case 17:
  4111. block = "CB_FMASK";
  4112. break;
  4113. case 162:
  4114. case 146:
  4115. case 98:
  4116. case 82:
  4117. case 226:
  4118. case 210:
  4119. case 34:
  4120. case 18:
  4121. block = "CB_CMASK";
  4122. break;
  4123. case 163:
  4124. case 147:
  4125. case 99:
  4126. case 83:
  4127. case 227:
  4128. case 211:
  4129. case 35:
  4130. case 19:
  4131. block = "CB_IMMED";
  4132. break;
  4133. case 164:
  4134. case 148:
  4135. case 100:
  4136. case 84:
  4137. case 228:
  4138. case 212:
  4139. case 36:
  4140. case 20:
  4141. block = "DB";
  4142. break;
  4143. case 165:
  4144. case 149:
  4145. case 101:
  4146. case 85:
  4147. case 229:
  4148. case 213:
  4149. case 37:
  4150. case 21:
  4151. block = "DB_HTILE";
  4152. break;
  4153. case 167:
  4154. case 151:
  4155. case 103:
  4156. case 87:
  4157. case 231:
  4158. case 215:
  4159. case 39:
  4160. case 23:
  4161. block = "DB_STEN";
  4162. break;
  4163. case 72:
  4164. case 68:
  4165. case 64:
  4166. case 8:
  4167. case 4:
  4168. case 0:
  4169. case 136:
  4170. case 132:
  4171. case 128:
  4172. case 200:
  4173. case 196:
  4174. case 192:
  4175. block = "TC";
  4176. break;
  4177. case 112:
  4178. case 48:
  4179. block = "CP";
  4180. break;
  4181. case 49:
  4182. case 177:
  4183. case 50:
  4184. case 178:
  4185. block = "SH";
  4186. break;
  4187. case 53:
  4188. case 190:
  4189. block = "VGT";
  4190. break;
  4191. case 117:
  4192. block = "IH";
  4193. break;
  4194. case 51:
  4195. case 115:
  4196. block = "RLC";
  4197. break;
  4198. case 119:
  4199. case 183:
  4200. block = "DMA0";
  4201. break;
  4202. case 61:
  4203. block = "DMA1";
  4204. break;
  4205. case 248:
  4206. case 120:
  4207. block = "HDP";
  4208. break;
  4209. default:
  4210. block = "unknown";
  4211. break;
  4212. }
  4213. } else {
  4214. switch (mc_id) {
  4215. case 32:
  4216. case 16:
  4217. case 96:
  4218. case 80:
  4219. case 160:
  4220. case 144:
  4221. case 224:
  4222. case 208:
  4223. block = "CB";
  4224. break;
  4225. case 33:
  4226. case 17:
  4227. case 97:
  4228. case 81:
  4229. case 161:
  4230. case 145:
  4231. case 225:
  4232. case 209:
  4233. block = "CB_FMASK";
  4234. break;
  4235. case 34:
  4236. case 18:
  4237. case 98:
  4238. case 82:
  4239. case 162:
  4240. case 146:
  4241. case 226:
  4242. case 210:
  4243. block = "CB_CMASK";
  4244. break;
  4245. case 35:
  4246. case 19:
  4247. case 99:
  4248. case 83:
  4249. case 163:
  4250. case 147:
  4251. case 227:
  4252. case 211:
  4253. block = "CB_IMMED";
  4254. break;
  4255. case 36:
  4256. case 20:
  4257. case 100:
  4258. case 84:
  4259. case 164:
  4260. case 148:
  4261. case 228:
  4262. case 212:
  4263. block = "DB";
  4264. break;
  4265. case 37:
  4266. case 21:
  4267. case 101:
  4268. case 85:
  4269. case 165:
  4270. case 149:
  4271. case 229:
  4272. case 213:
  4273. block = "DB_HTILE";
  4274. break;
  4275. case 39:
  4276. case 23:
  4277. case 103:
  4278. case 87:
  4279. case 167:
  4280. case 151:
  4281. case 231:
  4282. case 215:
  4283. block = "DB_STEN";
  4284. break;
  4285. case 72:
  4286. case 68:
  4287. case 8:
  4288. case 4:
  4289. case 136:
  4290. case 132:
  4291. case 200:
  4292. case 196:
  4293. block = "TC";
  4294. break;
  4295. case 112:
  4296. case 48:
  4297. block = "CP";
  4298. break;
  4299. case 49:
  4300. case 177:
  4301. case 50:
  4302. case 178:
  4303. block = "SH";
  4304. break;
  4305. case 53:
  4306. block = "VGT";
  4307. break;
  4308. case 117:
  4309. block = "IH";
  4310. break;
  4311. case 51:
  4312. case 115:
  4313. block = "RLC";
  4314. break;
  4315. case 119:
  4316. case 183:
  4317. block = "DMA0";
  4318. break;
  4319. case 61:
  4320. block = "DMA1";
  4321. break;
  4322. case 248:
  4323. case 120:
  4324. block = "HDP";
  4325. break;
  4326. default:
  4327. block = "unknown";
  4328. break;
  4329. }
  4330. }
  4331. printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
  4332. protections, vmid, addr,
  4333. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  4334. block, mc_id);
  4335. }
  4336. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  4337. {
  4338. struct radeon_ring *ring = &rdev->ring[ridx];
  4339. if (vm == NULL)
  4340. return;
  4341. /* write new base address */
  4342. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4343. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4344. WRITE_DATA_DST_SEL(0)));
  4345. if (vm->id < 8) {
  4346. radeon_ring_write(ring,
  4347. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  4348. } else {
  4349. radeon_ring_write(ring,
  4350. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  4351. }
  4352. radeon_ring_write(ring, 0);
  4353. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  4354. /* flush hdp cache */
  4355. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4356. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4357. WRITE_DATA_DST_SEL(0)));
  4358. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  4359. radeon_ring_write(ring, 0);
  4360. radeon_ring_write(ring, 0x1);
  4361. /* bits 0-15 are the VM contexts0-15 */
  4362. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4363. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4364. WRITE_DATA_DST_SEL(0)));
  4365. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  4366. radeon_ring_write(ring, 0);
  4367. radeon_ring_write(ring, 1 << vm->id);
  4368. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  4369. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  4370. radeon_ring_write(ring, 0x0);
  4371. }
  4372. /*
  4373. * Power and clock gating
  4374. */
  4375. static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
  4376. {
  4377. int i;
  4378. for (i = 0; i < rdev->usec_timeout; i++) {
  4379. if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
  4380. break;
  4381. udelay(1);
  4382. }
  4383. for (i = 0; i < rdev->usec_timeout; i++) {
  4384. if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
  4385. break;
  4386. udelay(1);
  4387. }
  4388. }
  4389. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  4390. bool enable)
  4391. {
  4392. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  4393. u32 mask;
  4394. int i;
  4395. if (enable)
  4396. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4397. else
  4398. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4399. WREG32(CP_INT_CNTL_RING0, tmp);
  4400. if (!enable) {
  4401. /* read a gfx register */
  4402. tmp = RREG32(DB_DEPTH_INFO);
  4403. mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
  4404. for (i = 0; i < rdev->usec_timeout; i++) {
  4405. if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
  4406. break;
  4407. udelay(1);
  4408. }
  4409. }
  4410. }
  4411. static void si_set_uvd_dcm(struct radeon_device *rdev,
  4412. bool sw_mode)
  4413. {
  4414. u32 tmp, tmp2;
  4415. tmp = RREG32(UVD_CGC_CTRL);
  4416. tmp &= ~(CLK_OD_MASK | CG_DT_MASK);
  4417. tmp |= DCM | CG_DT(1) | CLK_OD(4);
  4418. if (sw_mode) {
  4419. tmp &= ~0x7ffff800;
  4420. tmp2 = DYN_OR_EN | DYN_RR_EN | G_DIV_ID(7);
  4421. } else {
  4422. tmp |= 0x7ffff800;
  4423. tmp2 = 0;
  4424. }
  4425. WREG32(UVD_CGC_CTRL, tmp);
  4426. WREG32_UVD_CTX(UVD_CGC_CTRL2, tmp2);
  4427. }
  4428. void si_init_uvd_internal_cg(struct radeon_device *rdev)
  4429. {
  4430. bool hw_mode = true;
  4431. if (hw_mode) {
  4432. si_set_uvd_dcm(rdev, false);
  4433. } else {
  4434. u32 tmp = RREG32(UVD_CGC_CTRL);
  4435. tmp &= ~DCM;
  4436. WREG32(UVD_CGC_CTRL, tmp);
  4437. }
  4438. }
  4439. static u32 si_halt_rlc(struct radeon_device *rdev)
  4440. {
  4441. u32 data, orig;
  4442. orig = data = RREG32(RLC_CNTL);
  4443. if (data & RLC_ENABLE) {
  4444. data &= ~RLC_ENABLE;
  4445. WREG32(RLC_CNTL, data);
  4446. si_wait_for_rlc_serdes(rdev);
  4447. }
  4448. return orig;
  4449. }
  4450. static void si_update_rlc(struct radeon_device *rdev, u32 rlc)
  4451. {
  4452. u32 tmp;
  4453. tmp = RREG32(RLC_CNTL);
  4454. if (tmp != rlc)
  4455. WREG32(RLC_CNTL, rlc);
  4456. }
  4457. static void si_enable_dma_pg(struct radeon_device *rdev, bool enable)
  4458. {
  4459. u32 data, orig;
  4460. orig = data = RREG32(DMA_PG);
  4461. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA))
  4462. data |= PG_CNTL_ENABLE;
  4463. else
  4464. data &= ~PG_CNTL_ENABLE;
  4465. if (orig != data)
  4466. WREG32(DMA_PG, data);
  4467. }
  4468. static void si_init_dma_pg(struct radeon_device *rdev)
  4469. {
  4470. u32 tmp;
  4471. WREG32(DMA_PGFSM_WRITE, 0x00002000);
  4472. WREG32(DMA_PGFSM_CONFIG, 0x100010ff);
  4473. for (tmp = 0; tmp < 5; tmp++)
  4474. WREG32(DMA_PGFSM_WRITE, 0);
  4475. }
  4476. static void si_enable_gfx_cgpg(struct radeon_device *rdev,
  4477. bool enable)
  4478. {
  4479. u32 tmp;
  4480. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
  4481. tmp = RLC_PUD(0x10) | RLC_PDD(0x10) | RLC_TTPD(0x10) | RLC_MSD(0x10);
  4482. WREG32(RLC_TTOP_D, tmp);
  4483. tmp = RREG32(RLC_PG_CNTL);
  4484. tmp |= GFX_PG_ENABLE;
  4485. WREG32(RLC_PG_CNTL, tmp);
  4486. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4487. tmp |= AUTO_PG_EN;
  4488. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4489. } else {
  4490. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4491. tmp &= ~AUTO_PG_EN;
  4492. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4493. tmp = RREG32(DB_RENDER_CONTROL);
  4494. }
  4495. }
  4496. static void si_init_gfx_cgpg(struct radeon_device *rdev)
  4497. {
  4498. u32 tmp;
  4499. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4500. tmp = RREG32(RLC_PG_CNTL);
  4501. tmp |= GFX_PG_SRC;
  4502. WREG32(RLC_PG_CNTL, tmp);
  4503. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4504. tmp = RREG32(RLC_AUTO_PG_CTRL);
  4505. tmp &= ~GRBM_REG_SGIT_MASK;
  4506. tmp |= GRBM_REG_SGIT(0x700);
  4507. tmp &= ~PG_AFTER_GRBM_REG_ST_MASK;
  4508. WREG32(RLC_AUTO_PG_CTRL, tmp);
  4509. }
  4510. static u32 si_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
  4511. {
  4512. u32 mask = 0, tmp, tmp1;
  4513. int i;
  4514. si_select_se_sh(rdev, se, sh);
  4515. tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  4516. tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  4517. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4518. tmp &= 0xffff0000;
  4519. tmp |= tmp1;
  4520. tmp >>= 16;
  4521. for (i = 0; i < rdev->config.si.max_cu_per_sh; i ++) {
  4522. mask <<= 1;
  4523. mask |= 1;
  4524. }
  4525. return (~tmp) & mask;
  4526. }
  4527. static void si_init_ao_cu_mask(struct radeon_device *rdev)
  4528. {
  4529. u32 i, j, k, active_cu_number = 0;
  4530. u32 mask, counter, cu_bitmap;
  4531. u32 tmp = 0;
  4532. for (i = 0; i < rdev->config.si.max_shader_engines; i++) {
  4533. for (j = 0; j < rdev->config.si.max_sh_per_se; j++) {
  4534. mask = 1;
  4535. cu_bitmap = 0;
  4536. counter = 0;
  4537. for (k = 0; k < rdev->config.si.max_cu_per_sh; k++) {
  4538. if (si_get_cu_active_bitmap(rdev, i, j) & mask) {
  4539. if (counter < 2)
  4540. cu_bitmap |= mask;
  4541. counter++;
  4542. }
  4543. mask <<= 1;
  4544. }
  4545. active_cu_number += counter;
  4546. tmp |= (cu_bitmap << (i * 16 + j * 8));
  4547. }
  4548. }
  4549. WREG32(RLC_PG_AO_CU_MASK, tmp);
  4550. tmp = RREG32(RLC_MAX_PG_CU);
  4551. tmp &= ~MAX_PU_CU_MASK;
  4552. tmp |= MAX_PU_CU(active_cu_number);
  4553. WREG32(RLC_MAX_PG_CU, tmp);
  4554. }
  4555. static void si_enable_cgcg(struct radeon_device *rdev,
  4556. bool enable)
  4557. {
  4558. u32 data, orig, tmp;
  4559. orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
  4560. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
  4561. si_enable_gui_idle_interrupt(rdev, true);
  4562. WREG32(RLC_GCPM_GENERAL_3, 0x00000080);
  4563. tmp = si_halt_rlc(rdev);
  4564. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4565. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4566. WREG32(RLC_SERDES_WR_CTRL, 0x00b000ff);
  4567. si_wait_for_rlc_serdes(rdev);
  4568. si_update_rlc(rdev, tmp);
  4569. WREG32(RLC_SERDES_WR_CTRL, 0x007000ff);
  4570. data |= CGCG_EN | CGLS_EN;
  4571. } else {
  4572. si_enable_gui_idle_interrupt(rdev, false);
  4573. RREG32(CB_CGTT_SCLK_CTRL);
  4574. RREG32(CB_CGTT_SCLK_CTRL);
  4575. RREG32(CB_CGTT_SCLK_CTRL);
  4576. RREG32(CB_CGTT_SCLK_CTRL);
  4577. data &= ~(CGCG_EN | CGLS_EN);
  4578. }
  4579. if (orig != data)
  4580. WREG32(RLC_CGCG_CGLS_CTRL, data);
  4581. }
  4582. static void si_enable_mgcg(struct radeon_device *rdev,
  4583. bool enable)
  4584. {
  4585. u32 data, orig, tmp = 0;
  4586. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
  4587. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4588. data = 0x96940200;
  4589. if (orig != data)
  4590. WREG32(CGTS_SM_CTRL_REG, data);
  4591. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
  4592. orig = data = RREG32(CP_MEM_SLP_CNTL);
  4593. data |= CP_MEM_LS_EN;
  4594. if (orig != data)
  4595. WREG32(CP_MEM_SLP_CNTL, data);
  4596. }
  4597. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4598. data &= 0xffffffc0;
  4599. if (orig != data)
  4600. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4601. tmp = si_halt_rlc(rdev);
  4602. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4603. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4604. WREG32(RLC_SERDES_WR_CTRL, 0x00d000ff);
  4605. si_update_rlc(rdev, tmp);
  4606. } else {
  4607. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  4608. data |= 0x00000003;
  4609. if (orig != data)
  4610. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  4611. data = RREG32(CP_MEM_SLP_CNTL);
  4612. if (data & CP_MEM_LS_EN) {
  4613. data &= ~CP_MEM_LS_EN;
  4614. WREG32(CP_MEM_SLP_CNTL, data);
  4615. }
  4616. orig = data = RREG32(CGTS_SM_CTRL_REG);
  4617. data |= LS_OVERRIDE | OVERRIDE;
  4618. if (orig != data)
  4619. WREG32(CGTS_SM_CTRL_REG, data);
  4620. tmp = si_halt_rlc(rdev);
  4621. WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
  4622. WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
  4623. WREG32(RLC_SERDES_WR_CTRL, 0x00e000ff);
  4624. si_update_rlc(rdev, tmp);
  4625. }
  4626. }
  4627. static void si_enable_uvd_mgcg(struct radeon_device *rdev,
  4628. bool enable)
  4629. {
  4630. u32 orig, data, tmp;
  4631. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
  4632. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4633. tmp |= 0x3fff;
  4634. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4635. orig = data = RREG32(UVD_CGC_CTRL);
  4636. data |= DCM;
  4637. if (orig != data)
  4638. WREG32(UVD_CGC_CTRL, data);
  4639. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0);
  4640. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0);
  4641. } else {
  4642. tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  4643. tmp &= ~0x3fff;
  4644. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
  4645. orig = data = RREG32(UVD_CGC_CTRL);
  4646. data &= ~DCM;
  4647. if (orig != data)
  4648. WREG32(UVD_CGC_CTRL, data);
  4649. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0xffffffff);
  4650. WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0xffffffff);
  4651. }
  4652. }
  4653. static const u32 mc_cg_registers[] =
  4654. {
  4655. MC_HUB_MISC_HUB_CG,
  4656. MC_HUB_MISC_SIP_CG,
  4657. MC_HUB_MISC_VM_CG,
  4658. MC_XPB_CLK_GAT,
  4659. ATC_MISC_CG,
  4660. MC_CITF_MISC_WR_CG,
  4661. MC_CITF_MISC_RD_CG,
  4662. MC_CITF_MISC_VM_CG,
  4663. VM_L2_CG,
  4664. };
  4665. static void si_enable_mc_ls(struct radeon_device *rdev,
  4666. bool enable)
  4667. {
  4668. int i;
  4669. u32 orig, data;
  4670. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4671. orig = data = RREG32(mc_cg_registers[i]);
  4672. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
  4673. data |= MC_LS_ENABLE;
  4674. else
  4675. data &= ~MC_LS_ENABLE;
  4676. if (data != orig)
  4677. WREG32(mc_cg_registers[i], data);
  4678. }
  4679. }
  4680. static void si_enable_mc_mgcg(struct radeon_device *rdev,
  4681. bool enable)
  4682. {
  4683. int i;
  4684. u32 orig, data;
  4685. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  4686. orig = data = RREG32(mc_cg_registers[i]);
  4687. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
  4688. data |= MC_CG_ENABLE;
  4689. else
  4690. data &= ~MC_CG_ENABLE;
  4691. if (data != orig)
  4692. WREG32(mc_cg_registers[i], data);
  4693. }
  4694. }
  4695. static void si_enable_dma_mgcg(struct radeon_device *rdev,
  4696. bool enable)
  4697. {
  4698. u32 orig, data, offset;
  4699. int i;
  4700. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
  4701. for (i = 0; i < 2; i++) {
  4702. if (i == 0)
  4703. offset = DMA0_REGISTER_OFFSET;
  4704. else
  4705. offset = DMA1_REGISTER_OFFSET;
  4706. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4707. data &= ~MEM_POWER_OVERRIDE;
  4708. if (data != orig)
  4709. WREG32(DMA_POWER_CNTL + offset, data);
  4710. WREG32(DMA_CLK_CTRL + offset, 0x00000100);
  4711. }
  4712. } else {
  4713. for (i = 0; i < 2; i++) {
  4714. if (i == 0)
  4715. offset = DMA0_REGISTER_OFFSET;
  4716. else
  4717. offset = DMA1_REGISTER_OFFSET;
  4718. orig = data = RREG32(DMA_POWER_CNTL + offset);
  4719. data |= MEM_POWER_OVERRIDE;
  4720. if (data != orig)
  4721. WREG32(DMA_POWER_CNTL + offset, data);
  4722. orig = data = RREG32(DMA_CLK_CTRL + offset);
  4723. data = 0xff000000;
  4724. if (data != orig)
  4725. WREG32(DMA_CLK_CTRL + offset, data);
  4726. }
  4727. }
  4728. }
  4729. static void si_enable_bif_mgls(struct radeon_device *rdev,
  4730. bool enable)
  4731. {
  4732. u32 orig, data;
  4733. orig = data = RREG32_PCIE(PCIE_CNTL2);
  4734. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
  4735. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4736. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
  4737. else
  4738. data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
  4739. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
  4740. if (orig != data)
  4741. WREG32_PCIE(PCIE_CNTL2, data);
  4742. }
  4743. static void si_enable_hdp_mgcg(struct radeon_device *rdev,
  4744. bool enable)
  4745. {
  4746. u32 orig, data;
  4747. orig = data = RREG32(HDP_HOST_PATH_CNTL);
  4748. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
  4749. data &= ~CLOCK_GATING_DIS;
  4750. else
  4751. data |= CLOCK_GATING_DIS;
  4752. if (orig != data)
  4753. WREG32(HDP_HOST_PATH_CNTL, data);
  4754. }
  4755. static void si_enable_hdp_ls(struct radeon_device *rdev,
  4756. bool enable)
  4757. {
  4758. u32 orig, data;
  4759. orig = data = RREG32(HDP_MEM_POWER_LS);
  4760. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
  4761. data |= HDP_LS_ENABLE;
  4762. else
  4763. data &= ~HDP_LS_ENABLE;
  4764. if (orig != data)
  4765. WREG32(HDP_MEM_POWER_LS, data);
  4766. }
  4767. static void si_update_cg(struct radeon_device *rdev,
  4768. u32 block, bool enable)
  4769. {
  4770. if (block & RADEON_CG_BLOCK_GFX) {
  4771. si_enable_gui_idle_interrupt(rdev, false);
  4772. /* order matters! */
  4773. if (enable) {
  4774. si_enable_mgcg(rdev, true);
  4775. si_enable_cgcg(rdev, true);
  4776. } else {
  4777. si_enable_cgcg(rdev, false);
  4778. si_enable_mgcg(rdev, false);
  4779. }
  4780. si_enable_gui_idle_interrupt(rdev, true);
  4781. }
  4782. if (block & RADEON_CG_BLOCK_MC) {
  4783. si_enable_mc_mgcg(rdev, enable);
  4784. si_enable_mc_ls(rdev, enable);
  4785. }
  4786. if (block & RADEON_CG_BLOCK_SDMA) {
  4787. si_enable_dma_mgcg(rdev, enable);
  4788. }
  4789. if (block & RADEON_CG_BLOCK_BIF) {
  4790. si_enable_bif_mgls(rdev, enable);
  4791. }
  4792. if (block & RADEON_CG_BLOCK_UVD) {
  4793. if (rdev->has_uvd) {
  4794. si_enable_uvd_mgcg(rdev, enable);
  4795. }
  4796. }
  4797. if (block & RADEON_CG_BLOCK_HDP) {
  4798. si_enable_hdp_mgcg(rdev, enable);
  4799. si_enable_hdp_ls(rdev, enable);
  4800. }
  4801. }
  4802. static void si_init_cg(struct radeon_device *rdev)
  4803. {
  4804. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4805. RADEON_CG_BLOCK_MC |
  4806. RADEON_CG_BLOCK_SDMA |
  4807. RADEON_CG_BLOCK_BIF |
  4808. RADEON_CG_BLOCK_HDP), true);
  4809. if (rdev->has_uvd) {
  4810. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
  4811. si_init_uvd_internal_cg(rdev);
  4812. }
  4813. }
  4814. static void si_fini_cg(struct radeon_device *rdev)
  4815. {
  4816. if (rdev->has_uvd) {
  4817. si_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
  4818. }
  4819. si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
  4820. RADEON_CG_BLOCK_MC |
  4821. RADEON_CG_BLOCK_SDMA |
  4822. RADEON_CG_BLOCK_BIF |
  4823. RADEON_CG_BLOCK_HDP), false);
  4824. }
  4825. u32 si_get_csb_size(struct radeon_device *rdev)
  4826. {
  4827. u32 count = 0;
  4828. const struct cs_section_def *sect = NULL;
  4829. const struct cs_extent_def *ext = NULL;
  4830. if (rdev->rlc.cs_data == NULL)
  4831. return 0;
  4832. /* begin clear state */
  4833. count += 2;
  4834. /* context control state */
  4835. count += 3;
  4836. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4837. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4838. if (sect->id == SECT_CONTEXT)
  4839. count += 2 + ext->reg_count;
  4840. else
  4841. return 0;
  4842. }
  4843. }
  4844. /* pa_sc_raster_config */
  4845. count += 3;
  4846. /* end clear state */
  4847. count += 2;
  4848. /* clear state */
  4849. count += 2;
  4850. return count;
  4851. }
  4852. void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
  4853. {
  4854. u32 count = 0, i;
  4855. const struct cs_section_def *sect = NULL;
  4856. const struct cs_extent_def *ext = NULL;
  4857. if (rdev->rlc.cs_data == NULL)
  4858. return;
  4859. if (buffer == NULL)
  4860. return;
  4861. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4862. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  4863. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  4864. buffer[count++] = cpu_to_le32(0x80000000);
  4865. buffer[count++] = cpu_to_le32(0x80000000);
  4866. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  4867. for (ext = sect->section; ext->extent != NULL; ++ext) {
  4868. if (sect->id == SECT_CONTEXT) {
  4869. buffer[count++] =
  4870. cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  4871. buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
  4872. for (i = 0; i < ext->reg_count; i++)
  4873. buffer[count++] = cpu_to_le32(ext->extent[i]);
  4874. } else {
  4875. return;
  4876. }
  4877. }
  4878. }
  4879. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  4880. buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  4881. switch (rdev->family) {
  4882. case CHIP_TAHITI:
  4883. case CHIP_PITCAIRN:
  4884. buffer[count++] = cpu_to_le32(0x2a00126a);
  4885. break;
  4886. case CHIP_VERDE:
  4887. buffer[count++] = cpu_to_le32(0x0000124a);
  4888. break;
  4889. case CHIP_OLAND:
  4890. buffer[count++] = cpu_to_le32(0x00000082);
  4891. break;
  4892. case CHIP_HAINAN:
  4893. buffer[count++] = cpu_to_le32(0x00000000);
  4894. break;
  4895. default:
  4896. buffer[count++] = cpu_to_le32(0x00000000);
  4897. break;
  4898. }
  4899. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4900. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
  4901. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
  4902. buffer[count++] = cpu_to_le32(0);
  4903. }
  4904. static void si_init_pg(struct radeon_device *rdev)
  4905. {
  4906. if (rdev->pg_flags) {
  4907. if (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA) {
  4908. si_init_dma_pg(rdev);
  4909. }
  4910. si_init_ao_cu_mask(rdev);
  4911. if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
  4912. si_init_gfx_cgpg(rdev);
  4913. }
  4914. si_enable_dma_pg(rdev, true);
  4915. si_enable_gfx_cgpg(rdev, true);
  4916. } else {
  4917. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4918. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4919. }
  4920. }
  4921. static void si_fini_pg(struct radeon_device *rdev)
  4922. {
  4923. if (rdev->pg_flags) {
  4924. si_enable_dma_pg(rdev, false);
  4925. si_enable_gfx_cgpg(rdev, false);
  4926. }
  4927. }
  4928. /*
  4929. * RLC
  4930. */
  4931. void si_rlc_reset(struct radeon_device *rdev)
  4932. {
  4933. u32 tmp = RREG32(GRBM_SOFT_RESET);
  4934. tmp |= SOFT_RESET_RLC;
  4935. WREG32(GRBM_SOFT_RESET, tmp);
  4936. udelay(50);
  4937. tmp &= ~SOFT_RESET_RLC;
  4938. WREG32(GRBM_SOFT_RESET, tmp);
  4939. udelay(50);
  4940. }
  4941. static void si_rlc_stop(struct radeon_device *rdev)
  4942. {
  4943. WREG32(RLC_CNTL, 0);
  4944. si_enable_gui_idle_interrupt(rdev, false);
  4945. si_wait_for_rlc_serdes(rdev);
  4946. }
  4947. static void si_rlc_start(struct radeon_device *rdev)
  4948. {
  4949. WREG32(RLC_CNTL, RLC_ENABLE);
  4950. si_enable_gui_idle_interrupt(rdev, true);
  4951. udelay(50);
  4952. }
  4953. static bool si_lbpw_supported(struct radeon_device *rdev)
  4954. {
  4955. u32 tmp;
  4956. /* Enable LBPW only for DDR3 */
  4957. tmp = RREG32(MC_SEQ_MISC0);
  4958. if ((tmp & 0xF0000000) == 0xB0000000)
  4959. return true;
  4960. return false;
  4961. }
  4962. static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
  4963. {
  4964. u32 tmp;
  4965. tmp = RREG32(RLC_LB_CNTL);
  4966. if (enable)
  4967. tmp |= LOAD_BALANCE_ENABLE;
  4968. else
  4969. tmp &= ~LOAD_BALANCE_ENABLE;
  4970. WREG32(RLC_LB_CNTL, tmp);
  4971. if (!enable) {
  4972. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4973. WREG32(SPI_LB_CU_MASK, 0x00ff);
  4974. }
  4975. }
  4976. static int si_rlc_resume(struct radeon_device *rdev)
  4977. {
  4978. u32 i;
  4979. const __be32 *fw_data;
  4980. if (!rdev->rlc_fw)
  4981. return -EINVAL;
  4982. si_rlc_stop(rdev);
  4983. si_rlc_reset(rdev);
  4984. si_init_pg(rdev);
  4985. si_init_cg(rdev);
  4986. WREG32(RLC_RL_BASE, 0);
  4987. WREG32(RLC_RL_SIZE, 0);
  4988. WREG32(RLC_LB_CNTL, 0);
  4989. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  4990. WREG32(RLC_LB_CNTR_INIT, 0);
  4991. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  4992. WREG32(RLC_MC_CNTL, 0);
  4993. WREG32(RLC_UCODE_CNTL, 0);
  4994. fw_data = (const __be32 *)rdev->rlc_fw->data;
  4995. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  4996. WREG32(RLC_UCODE_ADDR, i);
  4997. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4998. }
  4999. WREG32(RLC_UCODE_ADDR, 0);
  5000. si_enable_lbpw(rdev, si_lbpw_supported(rdev));
  5001. si_rlc_start(rdev);
  5002. return 0;
  5003. }
  5004. static void si_enable_interrupts(struct radeon_device *rdev)
  5005. {
  5006. u32 ih_cntl = RREG32(IH_CNTL);
  5007. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5008. ih_cntl |= ENABLE_INTR;
  5009. ih_rb_cntl |= IH_RB_ENABLE;
  5010. WREG32(IH_CNTL, ih_cntl);
  5011. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5012. rdev->ih.enabled = true;
  5013. }
  5014. static void si_disable_interrupts(struct radeon_device *rdev)
  5015. {
  5016. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  5017. u32 ih_cntl = RREG32(IH_CNTL);
  5018. ih_rb_cntl &= ~IH_RB_ENABLE;
  5019. ih_cntl &= ~ENABLE_INTR;
  5020. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5021. WREG32(IH_CNTL, ih_cntl);
  5022. /* set rptr, wptr to 0 */
  5023. WREG32(IH_RB_RPTR, 0);
  5024. WREG32(IH_RB_WPTR, 0);
  5025. rdev->ih.enabled = false;
  5026. rdev->ih.rptr = 0;
  5027. }
  5028. static void si_disable_interrupt_state(struct radeon_device *rdev)
  5029. {
  5030. u32 tmp;
  5031. tmp = RREG32(CP_INT_CNTL_RING0) &
  5032. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5033. WREG32(CP_INT_CNTL_RING0, tmp);
  5034. WREG32(CP_INT_CNTL_RING1, 0);
  5035. WREG32(CP_INT_CNTL_RING2, 0);
  5036. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5037. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  5038. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5039. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  5040. WREG32(GRBM_INT_CNTL, 0);
  5041. if (rdev->num_crtc >= 2) {
  5042. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5043. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5044. }
  5045. if (rdev->num_crtc >= 4) {
  5046. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5047. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5048. }
  5049. if (rdev->num_crtc >= 6) {
  5050. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5051. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5052. }
  5053. if (rdev->num_crtc >= 2) {
  5054. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  5055. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  5056. }
  5057. if (rdev->num_crtc >= 4) {
  5058. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  5059. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  5060. }
  5061. if (rdev->num_crtc >= 6) {
  5062. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  5063. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  5064. }
  5065. if (!ASIC_IS_NODCE(rdev)) {
  5066. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  5067. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5068. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5069. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5070. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5071. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5072. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5073. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5074. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5075. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5076. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5077. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  5078. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5079. }
  5080. }
  5081. static int si_irq_init(struct radeon_device *rdev)
  5082. {
  5083. int ret = 0;
  5084. int rb_bufsz;
  5085. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  5086. /* allocate ring */
  5087. ret = r600_ih_ring_alloc(rdev);
  5088. if (ret)
  5089. return ret;
  5090. /* disable irqs */
  5091. si_disable_interrupts(rdev);
  5092. /* init rlc */
  5093. ret = si_rlc_resume(rdev);
  5094. if (ret) {
  5095. r600_ih_ring_fini(rdev);
  5096. return ret;
  5097. }
  5098. /* setup interrupt control */
  5099. /* set dummy read address to ring address */
  5100. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  5101. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  5102. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  5103. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  5104. */
  5105. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  5106. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  5107. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  5108. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  5109. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  5110. rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
  5111. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  5112. IH_WPTR_OVERFLOW_CLEAR |
  5113. (rb_bufsz << 1));
  5114. if (rdev->wb.enabled)
  5115. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  5116. /* set the writeback address whether it's enabled or not */
  5117. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  5118. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  5119. WREG32(IH_RB_CNTL, ih_rb_cntl);
  5120. /* set rptr, wptr to 0 */
  5121. WREG32(IH_RB_RPTR, 0);
  5122. WREG32(IH_RB_WPTR, 0);
  5123. /* Default settings for IH_CNTL (disabled at first) */
  5124. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  5125. /* RPTR_REARM only works if msi's are enabled */
  5126. if (rdev->msi_enabled)
  5127. ih_cntl |= RPTR_REARM;
  5128. WREG32(IH_CNTL, ih_cntl);
  5129. /* force the active interrupt state to all disabled */
  5130. si_disable_interrupt_state(rdev);
  5131. pci_set_master(rdev->pdev);
  5132. /* enable irqs */
  5133. si_enable_interrupts(rdev);
  5134. return ret;
  5135. }
  5136. int si_irq_set(struct radeon_device *rdev)
  5137. {
  5138. u32 cp_int_cntl;
  5139. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  5140. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  5141. u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  5142. u32 grbm_int_cntl = 0;
  5143. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  5144. u32 dma_cntl, dma_cntl1;
  5145. u32 thermal_int = 0;
  5146. if (!rdev->irq.installed) {
  5147. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  5148. return -EINVAL;
  5149. }
  5150. /* don't enable anything if the ih is disabled */
  5151. if (!rdev->ih.enabled) {
  5152. si_disable_interrupts(rdev);
  5153. /* force the active interrupt state to all disabled */
  5154. si_disable_interrupt_state(rdev);
  5155. return 0;
  5156. }
  5157. cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
  5158. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5159. if (!ASIC_IS_NODCE(rdev)) {
  5160. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5161. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5162. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5163. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5164. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5165. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  5166. }
  5167. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5168. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  5169. thermal_int = RREG32(CG_THERMAL_INT) &
  5170. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  5171. /* enable CP interrupts on all rings */
  5172. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  5173. DRM_DEBUG("si_irq_set: sw int gfx\n");
  5174. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  5175. }
  5176. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  5177. DRM_DEBUG("si_irq_set: sw int cp1\n");
  5178. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  5179. }
  5180. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  5181. DRM_DEBUG("si_irq_set: sw int cp2\n");
  5182. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  5183. }
  5184. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  5185. DRM_DEBUG("si_irq_set: sw int dma\n");
  5186. dma_cntl |= TRAP_ENABLE;
  5187. }
  5188. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  5189. DRM_DEBUG("si_irq_set: sw int dma1\n");
  5190. dma_cntl1 |= TRAP_ENABLE;
  5191. }
  5192. if (rdev->irq.crtc_vblank_int[0] ||
  5193. atomic_read(&rdev->irq.pflip[0])) {
  5194. DRM_DEBUG("si_irq_set: vblank 0\n");
  5195. crtc1 |= VBLANK_INT_MASK;
  5196. }
  5197. if (rdev->irq.crtc_vblank_int[1] ||
  5198. atomic_read(&rdev->irq.pflip[1])) {
  5199. DRM_DEBUG("si_irq_set: vblank 1\n");
  5200. crtc2 |= VBLANK_INT_MASK;
  5201. }
  5202. if (rdev->irq.crtc_vblank_int[2] ||
  5203. atomic_read(&rdev->irq.pflip[2])) {
  5204. DRM_DEBUG("si_irq_set: vblank 2\n");
  5205. crtc3 |= VBLANK_INT_MASK;
  5206. }
  5207. if (rdev->irq.crtc_vblank_int[3] ||
  5208. atomic_read(&rdev->irq.pflip[3])) {
  5209. DRM_DEBUG("si_irq_set: vblank 3\n");
  5210. crtc4 |= VBLANK_INT_MASK;
  5211. }
  5212. if (rdev->irq.crtc_vblank_int[4] ||
  5213. atomic_read(&rdev->irq.pflip[4])) {
  5214. DRM_DEBUG("si_irq_set: vblank 4\n");
  5215. crtc5 |= VBLANK_INT_MASK;
  5216. }
  5217. if (rdev->irq.crtc_vblank_int[5] ||
  5218. atomic_read(&rdev->irq.pflip[5])) {
  5219. DRM_DEBUG("si_irq_set: vblank 5\n");
  5220. crtc6 |= VBLANK_INT_MASK;
  5221. }
  5222. if (rdev->irq.hpd[0]) {
  5223. DRM_DEBUG("si_irq_set: hpd 1\n");
  5224. hpd1 |= DC_HPDx_INT_EN;
  5225. }
  5226. if (rdev->irq.hpd[1]) {
  5227. DRM_DEBUG("si_irq_set: hpd 2\n");
  5228. hpd2 |= DC_HPDx_INT_EN;
  5229. }
  5230. if (rdev->irq.hpd[2]) {
  5231. DRM_DEBUG("si_irq_set: hpd 3\n");
  5232. hpd3 |= DC_HPDx_INT_EN;
  5233. }
  5234. if (rdev->irq.hpd[3]) {
  5235. DRM_DEBUG("si_irq_set: hpd 4\n");
  5236. hpd4 |= DC_HPDx_INT_EN;
  5237. }
  5238. if (rdev->irq.hpd[4]) {
  5239. DRM_DEBUG("si_irq_set: hpd 5\n");
  5240. hpd5 |= DC_HPDx_INT_EN;
  5241. }
  5242. if (rdev->irq.hpd[5]) {
  5243. DRM_DEBUG("si_irq_set: hpd 6\n");
  5244. hpd6 |= DC_HPDx_INT_EN;
  5245. }
  5246. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  5247. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  5248. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  5249. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  5250. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  5251. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  5252. if (rdev->irq.dpm_thermal) {
  5253. DRM_DEBUG("dpm thermal\n");
  5254. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  5255. }
  5256. if (rdev->num_crtc >= 2) {
  5257. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  5258. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  5259. }
  5260. if (rdev->num_crtc >= 4) {
  5261. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  5262. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  5263. }
  5264. if (rdev->num_crtc >= 6) {
  5265. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  5266. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  5267. }
  5268. if (rdev->num_crtc >= 2) {
  5269. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  5270. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  5271. }
  5272. if (rdev->num_crtc >= 4) {
  5273. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  5274. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  5275. }
  5276. if (rdev->num_crtc >= 6) {
  5277. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  5278. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  5279. }
  5280. if (!ASIC_IS_NODCE(rdev)) {
  5281. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  5282. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  5283. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  5284. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  5285. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  5286. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  5287. }
  5288. WREG32(CG_THERMAL_INT, thermal_int);
  5289. return 0;
  5290. }
  5291. static inline void si_irq_ack(struct radeon_device *rdev)
  5292. {
  5293. u32 tmp;
  5294. if (ASIC_IS_NODCE(rdev))
  5295. return;
  5296. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  5297. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  5298. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  5299. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  5300. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  5301. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  5302. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  5303. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  5304. if (rdev->num_crtc >= 4) {
  5305. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  5306. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  5307. }
  5308. if (rdev->num_crtc >= 6) {
  5309. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  5310. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  5311. }
  5312. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  5313. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5314. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  5315. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5316. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  5317. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  5318. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  5319. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  5320. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  5321. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  5322. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  5323. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  5324. if (rdev->num_crtc >= 4) {
  5325. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  5326. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5327. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  5328. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5329. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  5330. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  5331. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  5332. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  5333. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  5334. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  5335. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  5336. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  5337. }
  5338. if (rdev->num_crtc >= 6) {
  5339. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  5340. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5341. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  5342. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  5343. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  5344. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  5345. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  5346. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  5347. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  5348. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  5349. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  5350. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  5351. }
  5352. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5353. tmp = RREG32(DC_HPD1_INT_CONTROL);
  5354. tmp |= DC_HPDx_INT_ACK;
  5355. WREG32(DC_HPD1_INT_CONTROL, tmp);
  5356. }
  5357. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5358. tmp = RREG32(DC_HPD2_INT_CONTROL);
  5359. tmp |= DC_HPDx_INT_ACK;
  5360. WREG32(DC_HPD2_INT_CONTROL, tmp);
  5361. }
  5362. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5363. tmp = RREG32(DC_HPD3_INT_CONTROL);
  5364. tmp |= DC_HPDx_INT_ACK;
  5365. WREG32(DC_HPD3_INT_CONTROL, tmp);
  5366. }
  5367. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5368. tmp = RREG32(DC_HPD4_INT_CONTROL);
  5369. tmp |= DC_HPDx_INT_ACK;
  5370. WREG32(DC_HPD4_INT_CONTROL, tmp);
  5371. }
  5372. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5373. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5374. tmp |= DC_HPDx_INT_ACK;
  5375. WREG32(DC_HPD5_INT_CONTROL, tmp);
  5376. }
  5377. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5378. tmp = RREG32(DC_HPD5_INT_CONTROL);
  5379. tmp |= DC_HPDx_INT_ACK;
  5380. WREG32(DC_HPD6_INT_CONTROL, tmp);
  5381. }
  5382. }
  5383. static void si_irq_disable(struct radeon_device *rdev)
  5384. {
  5385. si_disable_interrupts(rdev);
  5386. /* Wait and acknowledge irq */
  5387. mdelay(1);
  5388. si_irq_ack(rdev);
  5389. si_disable_interrupt_state(rdev);
  5390. }
  5391. static void si_irq_suspend(struct radeon_device *rdev)
  5392. {
  5393. si_irq_disable(rdev);
  5394. si_rlc_stop(rdev);
  5395. }
  5396. static void si_irq_fini(struct radeon_device *rdev)
  5397. {
  5398. si_irq_suspend(rdev);
  5399. r600_ih_ring_fini(rdev);
  5400. }
  5401. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  5402. {
  5403. u32 wptr, tmp;
  5404. if (rdev->wb.enabled)
  5405. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  5406. else
  5407. wptr = RREG32(IH_RB_WPTR);
  5408. if (wptr & RB_OVERFLOW) {
  5409. /* When a ring buffer overflow happen start parsing interrupt
  5410. * from the last not overwritten vector (wptr + 16). Hopefully
  5411. * this should allow us to catchup.
  5412. */
  5413. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  5414. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  5415. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  5416. tmp = RREG32(IH_RB_CNTL);
  5417. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  5418. WREG32(IH_RB_CNTL, tmp);
  5419. }
  5420. return (wptr & rdev->ih.ptr_mask);
  5421. }
  5422. /* SI IV Ring
  5423. * Each IV ring entry is 128 bits:
  5424. * [7:0] - interrupt source id
  5425. * [31:8] - reserved
  5426. * [59:32] - interrupt source data
  5427. * [63:60] - reserved
  5428. * [71:64] - RINGID
  5429. * [79:72] - VMID
  5430. * [127:80] - reserved
  5431. */
  5432. int si_irq_process(struct radeon_device *rdev)
  5433. {
  5434. u32 wptr;
  5435. u32 rptr;
  5436. u32 src_id, src_data, ring_id;
  5437. u32 ring_index;
  5438. bool queue_hotplug = false;
  5439. bool queue_thermal = false;
  5440. u32 status, addr;
  5441. if (!rdev->ih.enabled || rdev->shutdown)
  5442. return IRQ_NONE;
  5443. wptr = si_get_ih_wptr(rdev);
  5444. restart_ih:
  5445. /* is somebody else already processing irqs? */
  5446. if (atomic_xchg(&rdev->ih.lock, 1))
  5447. return IRQ_NONE;
  5448. rptr = rdev->ih.rptr;
  5449. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  5450. /* Order reading of wptr vs. reading of IH ring data */
  5451. rmb();
  5452. /* display interrupts */
  5453. si_irq_ack(rdev);
  5454. while (rptr != wptr) {
  5455. /* wptr/rptr are in bytes! */
  5456. ring_index = rptr / 4;
  5457. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  5458. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  5459. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  5460. switch (src_id) {
  5461. case 1: /* D1 vblank/vline */
  5462. switch (src_data) {
  5463. case 0: /* D1 vblank */
  5464. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  5465. if (rdev->irq.crtc_vblank_int[0]) {
  5466. drm_handle_vblank(rdev->ddev, 0);
  5467. rdev->pm.vblank_sync = true;
  5468. wake_up(&rdev->irq.vblank_queue);
  5469. }
  5470. if (atomic_read(&rdev->irq.pflip[0]))
  5471. radeon_crtc_handle_flip(rdev, 0);
  5472. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  5473. DRM_DEBUG("IH: D1 vblank\n");
  5474. }
  5475. break;
  5476. case 1: /* D1 vline */
  5477. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  5478. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  5479. DRM_DEBUG("IH: D1 vline\n");
  5480. }
  5481. break;
  5482. default:
  5483. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5484. break;
  5485. }
  5486. break;
  5487. case 2: /* D2 vblank/vline */
  5488. switch (src_data) {
  5489. case 0: /* D2 vblank */
  5490. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  5491. if (rdev->irq.crtc_vblank_int[1]) {
  5492. drm_handle_vblank(rdev->ddev, 1);
  5493. rdev->pm.vblank_sync = true;
  5494. wake_up(&rdev->irq.vblank_queue);
  5495. }
  5496. if (atomic_read(&rdev->irq.pflip[1]))
  5497. radeon_crtc_handle_flip(rdev, 1);
  5498. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  5499. DRM_DEBUG("IH: D2 vblank\n");
  5500. }
  5501. break;
  5502. case 1: /* D2 vline */
  5503. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  5504. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  5505. DRM_DEBUG("IH: D2 vline\n");
  5506. }
  5507. break;
  5508. default:
  5509. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5510. break;
  5511. }
  5512. break;
  5513. case 3: /* D3 vblank/vline */
  5514. switch (src_data) {
  5515. case 0: /* D3 vblank */
  5516. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  5517. if (rdev->irq.crtc_vblank_int[2]) {
  5518. drm_handle_vblank(rdev->ddev, 2);
  5519. rdev->pm.vblank_sync = true;
  5520. wake_up(&rdev->irq.vblank_queue);
  5521. }
  5522. if (atomic_read(&rdev->irq.pflip[2]))
  5523. radeon_crtc_handle_flip(rdev, 2);
  5524. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  5525. DRM_DEBUG("IH: D3 vblank\n");
  5526. }
  5527. break;
  5528. case 1: /* D3 vline */
  5529. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  5530. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  5531. DRM_DEBUG("IH: D3 vline\n");
  5532. }
  5533. break;
  5534. default:
  5535. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5536. break;
  5537. }
  5538. break;
  5539. case 4: /* D4 vblank/vline */
  5540. switch (src_data) {
  5541. case 0: /* D4 vblank */
  5542. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  5543. if (rdev->irq.crtc_vblank_int[3]) {
  5544. drm_handle_vblank(rdev->ddev, 3);
  5545. rdev->pm.vblank_sync = true;
  5546. wake_up(&rdev->irq.vblank_queue);
  5547. }
  5548. if (atomic_read(&rdev->irq.pflip[3]))
  5549. radeon_crtc_handle_flip(rdev, 3);
  5550. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  5551. DRM_DEBUG("IH: D4 vblank\n");
  5552. }
  5553. break;
  5554. case 1: /* D4 vline */
  5555. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  5556. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  5557. DRM_DEBUG("IH: D4 vline\n");
  5558. }
  5559. break;
  5560. default:
  5561. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5562. break;
  5563. }
  5564. break;
  5565. case 5: /* D5 vblank/vline */
  5566. switch (src_data) {
  5567. case 0: /* D5 vblank */
  5568. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  5569. if (rdev->irq.crtc_vblank_int[4]) {
  5570. drm_handle_vblank(rdev->ddev, 4);
  5571. rdev->pm.vblank_sync = true;
  5572. wake_up(&rdev->irq.vblank_queue);
  5573. }
  5574. if (atomic_read(&rdev->irq.pflip[4]))
  5575. radeon_crtc_handle_flip(rdev, 4);
  5576. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  5577. DRM_DEBUG("IH: D5 vblank\n");
  5578. }
  5579. break;
  5580. case 1: /* D5 vline */
  5581. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  5582. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  5583. DRM_DEBUG("IH: D5 vline\n");
  5584. }
  5585. break;
  5586. default:
  5587. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5588. break;
  5589. }
  5590. break;
  5591. case 6: /* D6 vblank/vline */
  5592. switch (src_data) {
  5593. case 0: /* D6 vblank */
  5594. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  5595. if (rdev->irq.crtc_vblank_int[5]) {
  5596. drm_handle_vblank(rdev->ddev, 5);
  5597. rdev->pm.vblank_sync = true;
  5598. wake_up(&rdev->irq.vblank_queue);
  5599. }
  5600. if (atomic_read(&rdev->irq.pflip[5]))
  5601. radeon_crtc_handle_flip(rdev, 5);
  5602. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  5603. DRM_DEBUG("IH: D6 vblank\n");
  5604. }
  5605. break;
  5606. case 1: /* D6 vline */
  5607. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  5608. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  5609. DRM_DEBUG("IH: D6 vline\n");
  5610. }
  5611. break;
  5612. default:
  5613. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5614. break;
  5615. }
  5616. break;
  5617. case 42: /* HPD hotplug */
  5618. switch (src_data) {
  5619. case 0:
  5620. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  5621. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  5622. queue_hotplug = true;
  5623. DRM_DEBUG("IH: HPD1\n");
  5624. }
  5625. break;
  5626. case 1:
  5627. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  5628. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  5629. queue_hotplug = true;
  5630. DRM_DEBUG("IH: HPD2\n");
  5631. }
  5632. break;
  5633. case 2:
  5634. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  5635. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  5636. queue_hotplug = true;
  5637. DRM_DEBUG("IH: HPD3\n");
  5638. }
  5639. break;
  5640. case 3:
  5641. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  5642. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  5643. queue_hotplug = true;
  5644. DRM_DEBUG("IH: HPD4\n");
  5645. }
  5646. break;
  5647. case 4:
  5648. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  5649. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  5650. queue_hotplug = true;
  5651. DRM_DEBUG("IH: HPD5\n");
  5652. }
  5653. break;
  5654. case 5:
  5655. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  5656. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  5657. queue_hotplug = true;
  5658. DRM_DEBUG("IH: HPD6\n");
  5659. }
  5660. break;
  5661. default:
  5662. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5663. break;
  5664. }
  5665. break;
  5666. case 146:
  5667. case 147:
  5668. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  5669. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  5670. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  5671. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  5672. addr);
  5673. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  5674. status);
  5675. si_vm_decode_fault(rdev, status, addr);
  5676. /* reset addr and status */
  5677. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  5678. break;
  5679. case 176: /* RINGID0 CP_INT */
  5680. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5681. break;
  5682. case 177: /* RINGID1 CP_INT */
  5683. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5684. break;
  5685. case 178: /* RINGID2 CP_INT */
  5686. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5687. break;
  5688. case 181: /* CP EOP event */
  5689. DRM_DEBUG("IH: CP EOP\n");
  5690. switch (ring_id) {
  5691. case 0:
  5692. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5693. break;
  5694. case 1:
  5695. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5696. break;
  5697. case 2:
  5698. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5699. break;
  5700. }
  5701. break;
  5702. case 224: /* DMA trap event */
  5703. DRM_DEBUG("IH: DMA trap\n");
  5704. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  5705. break;
  5706. case 230: /* thermal low to high */
  5707. DRM_DEBUG("IH: thermal low to high\n");
  5708. rdev->pm.dpm.thermal.high_to_low = false;
  5709. queue_thermal = true;
  5710. break;
  5711. case 231: /* thermal high to low */
  5712. DRM_DEBUG("IH: thermal high to low\n");
  5713. rdev->pm.dpm.thermal.high_to_low = true;
  5714. queue_thermal = true;
  5715. break;
  5716. case 233: /* GUI IDLE */
  5717. DRM_DEBUG("IH: GUI idle\n");
  5718. break;
  5719. case 244: /* DMA trap event */
  5720. DRM_DEBUG("IH: DMA1 trap\n");
  5721. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5722. break;
  5723. default:
  5724. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  5725. break;
  5726. }
  5727. /* wptr/rptr are in bytes! */
  5728. rptr += 16;
  5729. rptr &= rdev->ih.ptr_mask;
  5730. }
  5731. if (queue_hotplug)
  5732. schedule_work(&rdev->hotplug_work);
  5733. if (queue_thermal && rdev->pm.dpm_enabled)
  5734. schedule_work(&rdev->pm.dpm.thermal.work);
  5735. rdev->ih.rptr = rptr;
  5736. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  5737. atomic_set(&rdev->ih.lock, 0);
  5738. /* make sure wptr hasn't changed while processing */
  5739. wptr = si_get_ih_wptr(rdev);
  5740. if (wptr != rptr)
  5741. goto restart_ih;
  5742. return IRQ_HANDLED;
  5743. }
  5744. /*
  5745. * startup/shutdown callbacks
  5746. */
  5747. static int si_startup(struct radeon_device *rdev)
  5748. {
  5749. struct radeon_ring *ring;
  5750. int r;
  5751. /* enable pcie gen2/3 link */
  5752. si_pcie_gen3_enable(rdev);
  5753. /* enable aspm */
  5754. si_program_aspm(rdev);
  5755. /* scratch needs to be initialized before MC */
  5756. r = r600_vram_scratch_init(rdev);
  5757. if (r)
  5758. return r;
  5759. si_mc_program(rdev);
  5760. if (!rdev->pm.dpm_enabled) {
  5761. r = si_mc_load_microcode(rdev);
  5762. if (r) {
  5763. DRM_ERROR("Failed to load MC firmware!\n");
  5764. return r;
  5765. }
  5766. }
  5767. r = si_pcie_gart_enable(rdev);
  5768. if (r)
  5769. return r;
  5770. si_gpu_init(rdev);
  5771. /* allocate rlc buffers */
  5772. if (rdev->family == CHIP_VERDE) {
  5773. rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
  5774. rdev->rlc.reg_list_size =
  5775. (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
  5776. }
  5777. rdev->rlc.cs_data = si_cs_data;
  5778. r = sumo_rlc_init(rdev);
  5779. if (r) {
  5780. DRM_ERROR("Failed to init rlc BOs!\n");
  5781. return r;
  5782. }
  5783. /* allocate wb buffer */
  5784. r = radeon_wb_init(rdev);
  5785. if (r)
  5786. return r;
  5787. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5788. if (r) {
  5789. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5790. return r;
  5791. }
  5792. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  5793. if (r) {
  5794. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5795. return r;
  5796. }
  5797. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  5798. if (r) {
  5799. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5800. return r;
  5801. }
  5802. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  5803. if (r) {
  5804. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5805. return r;
  5806. }
  5807. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  5808. if (r) {
  5809. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5810. return r;
  5811. }
  5812. if (rdev->has_uvd) {
  5813. r = uvd_v2_2_resume(rdev);
  5814. if (!r) {
  5815. r = radeon_fence_driver_start_ring(rdev,
  5816. R600_RING_TYPE_UVD_INDEX);
  5817. if (r)
  5818. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  5819. }
  5820. if (r)
  5821. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5822. }
  5823. /* Enable IRQ */
  5824. if (!rdev->irq.installed) {
  5825. r = radeon_irq_kms_init(rdev);
  5826. if (r)
  5827. return r;
  5828. }
  5829. r = si_irq_init(rdev);
  5830. if (r) {
  5831. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5832. radeon_irq_kms_fini(rdev);
  5833. return r;
  5834. }
  5835. si_irq_set(rdev);
  5836. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5837. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5838. RADEON_CP_PACKET2);
  5839. if (r)
  5840. return r;
  5841. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5842. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  5843. RADEON_CP_PACKET2);
  5844. if (r)
  5845. return r;
  5846. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5847. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  5848. RADEON_CP_PACKET2);
  5849. if (r)
  5850. return r;
  5851. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5852. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5853. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5854. if (r)
  5855. return r;
  5856. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  5857. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  5858. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5859. if (r)
  5860. return r;
  5861. r = si_cp_load_microcode(rdev);
  5862. if (r)
  5863. return r;
  5864. r = si_cp_resume(rdev);
  5865. if (r)
  5866. return r;
  5867. r = cayman_dma_resume(rdev);
  5868. if (r)
  5869. return r;
  5870. if (rdev->has_uvd) {
  5871. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5872. if (ring->ring_size) {
  5873. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  5874. RADEON_CP_PACKET2);
  5875. if (!r)
  5876. r = uvd_v1_0_init(rdev);
  5877. if (r)
  5878. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  5879. }
  5880. }
  5881. r = radeon_ib_pool_init(rdev);
  5882. if (r) {
  5883. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5884. return r;
  5885. }
  5886. r = radeon_vm_manager_init(rdev);
  5887. if (r) {
  5888. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  5889. return r;
  5890. }
  5891. r = dce6_audio_init(rdev);
  5892. if (r)
  5893. return r;
  5894. return 0;
  5895. }
  5896. int si_resume(struct radeon_device *rdev)
  5897. {
  5898. int r;
  5899. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5900. * posting will perform necessary task to bring back GPU into good
  5901. * shape.
  5902. */
  5903. /* post card */
  5904. atom_asic_init(rdev->mode_info.atom_context);
  5905. /* init golden registers */
  5906. si_init_golden_registers(rdev);
  5907. radeon_pm_resume(rdev);
  5908. rdev->accel_working = true;
  5909. r = si_startup(rdev);
  5910. if (r) {
  5911. DRM_ERROR("si startup failed on resume\n");
  5912. rdev->accel_working = false;
  5913. return r;
  5914. }
  5915. return r;
  5916. }
  5917. int si_suspend(struct radeon_device *rdev)
  5918. {
  5919. radeon_pm_suspend(rdev);
  5920. dce6_audio_fini(rdev);
  5921. radeon_vm_manager_fini(rdev);
  5922. si_cp_enable(rdev, false);
  5923. cayman_dma_stop(rdev);
  5924. if (rdev->has_uvd) {
  5925. uvd_v1_0_fini(rdev);
  5926. radeon_uvd_suspend(rdev);
  5927. }
  5928. si_fini_pg(rdev);
  5929. si_fini_cg(rdev);
  5930. si_irq_suspend(rdev);
  5931. radeon_wb_disable(rdev);
  5932. si_pcie_gart_disable(rdev);
  5933. return 0;
  5934. }
  5935. /* Plan is to move initialization in that function and use
  5936. * helper function so that radeon_device_init pretty much
  5937. * do nothing more than calling asic specific function. This
  5938. * should also allow to remove a bunch of callback function
  5939. * like vram_info.
  5940. */
  5941. int si_init(struct radeon_device *rdev)
  5942. {
  5943. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5944. int r;
  5945. /* Read BIOS */
  5946. if (!radeon_get_bios(rdev)) {
  5947. if (ASIC_IS_AVIVO(rdev))
  5948. return -EINVAL;
  5949. }
  5950. /* Must be an ATOMBIOS */
  5951. if (!rdev->is_atom_bios) {
  5952. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  5953. return -EINVAL;
  5954. }
  5955. r = radeon_atombios_init(rdev);
  5956. if (r)
  5957. return r;
  5958. /* Post card if necessary */
  5959. if (!radeon_card_posted(rdev)) {
  5960. if (!rdev->bios) {
  5961. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5962. return -EINVAL;
  5963. }
  5964. DRM_INFO("GPU not posted. posting now...\n");
  5965. atom_asic_init(rdev->mode_info.atom_context);
  5966. }
  5967. /* init golden registers */
  5968. si_init_golden_registers(rdev);
  5969. /* Initialize scratch registers */
  5970. si_scratch_init(rdev);
  5971. /* Initialize surface registers */
  5972. radeon_surface_init(rdev);
  5973. /* Initialize clocks */
  5974. radeon_get_clock_info(rdev->ddev);
  5975. /* Fence driver */
  5976. r = radeon_fence_driver_init(rdev);
  5977. if (r)
  5978. return r;
  5979. /* initialize memory controller */
  5980. r = si_mc_init(rdev);
  5981. if (r)
  5982. return r;
  5983. /* Memory manager */
  5984. r = radeon_bo_init(rdev);
  5985. if (r)
  5986. return r;
  5987. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  5988. !rdev->rlc_fw || !rdev->mc_fw) {
  5989. r = si_init_microcode(rdev);
  5990. if (r) {
  5991. DRM_ERROR("Failed to load firmware!\n");
  5992. return r;
  5993. }
  5994. }
  5995. /* Initialize power management */
  5996. radeon_pm_init(rdev);
  5997. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5998. ring->ring_obj = NULL;
  5999. r600_ring_init(rdev, ring, 1024 * 1024);
  6000. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6001. ring->ring_obj = NULL;
  6002. r600_ring_init(rdev, ring, 1024 * 1024);
  6003. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6004. ring->ring_obj = NULL;
  6005. r600_ring_init(rdev, ring, 1024 * 1024);
  6006. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  6007. ring->ring_obj = NULL;
  6008. r600_ring_init(rdev, ring, 64 * 1024);
  6009. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  6010. ring->ring_obj = NULL;
  6011. r600_ring_init(rdev, ring, 64 * 1024);
  6012. if (rdev->has_uvd) {
  6013. r = radeon_uvd_init(rdev);
  6014. if (!r) {
  6015. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  6016. ring->ring_obj = NULL;
  6017. r600_ring_init(rdev, ring, 4096);
  6018. }
  6019. }
  6020. rdev->ih.ring_obj = NULL;
  6021. r600_ih_ring_init(rdev, 64 * 1024);
  6022. r = r600_pcie_gart_init(rdev);
  6023. if (r)
  6024. return r;
  6025. rdev->accel_working = true;
  6026. r = si_startup(rdev);
  6027. if (r) {
  6028. dev_err(rdev->dev, "disabling GPU acceleration\n");
  6029. si_cp_fini(rdev);
  6030. cayman_dma_fini(rdev);
  6031. si_irq_fini(rdev);
  6032. sumo_rlc_fini(rdev);
  6033. radeon_wb_fini(rdev);
  6034. radeon_ib_pool_fini(rdev);
  6035. radeon_vm_manager_fini(rdev);
  6036. radeon_irq_kms_fini(rdev);
  6037. si_pcie_gart_fini(rdev);
  6038. rdev->accel_working = false;
  6039. }
  6040. /* Don't start up if the MC ucode is missing.
  6041. * The default clocks and voltages before the MC ucode
  6042. * is loaded are not suffient for advanced operations.
  6043. */
  6044. if (!rdev->mc_fw) {
  6045. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  6046. return -EINVAL;
  6047. }
  6048. return 0;
  6049. }
  6050. void si_fini(struct radeon_device *rdev)
  6051. {
  6052. radeon_pm_fini(rdev);
  6053. si_cp_fini(rdev);
  6054. cayman_dma_fini(rdev);
  6055. si_fini_pg(rdev);
  6056. si_fini_cg(rdev);
  6057. si_irq_fini(rdev);
  6058. sumo_rlc_fini(rdev);
  6059. radeon_wb_fini(rdev);
  6060. radeon_vm_manager_fini(rdev);
  6061. radeon_ib_pool_fini(rdev);
  6062. radeon_irq_kms_fini(rdev);
  6063. if (rdev->has_uvd) {
  6064. uvd_v1_0_fini(rdev);
  6065. radeon_uvd_fini(rdev);
  6066. }
  6067. si_pcie_gart_fini(rdev);
  6068. r600_vram_scratch_fini(rdev);
  6069. radeon_gem_fini(rdev);
  6070. radeon_fence_driver_fini(rdev);
  6071. radeon_bo_fini(rdev);
  6072. radeon_atombios_fini(rdev);
  6073. kfree(rdev->bios);
  6074. rdev->bios = NULL;
  6075. }
  6076. /**
  6077. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  6078. *
  6079. * @rdev: radeon_device pointer
  6080. *
  6081. * Fetches a GPU clock counter snapshot (SI).
  6082. * Returns the 64 bit clock counter snapshot.
  6083. */
  6084. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  6085. {
  6086. uint64_t clock;
  6087. mutex_lock(&rdev->gpu_clock_mutex);
  6088. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  6089. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  6090. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  6091. mutex_unlock(&rdev->gpu_clock_mutex);
  6092. return clock;
  6093. }
  6094. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  6095. {
  6096. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  6097. int r;
  6098. /* bypass vclk and dclk with bclk */
  6099. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6100. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  6101. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6102. /* put PLL in bypass mode */
  6103. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  6104. if (!vclk || !dclk) {
  6105. /* keep the Bypass mode, put PLL to sleep */
  6106. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6107. return 0;
  6108. }
  6109. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  6110. 16384, 0x03FFFFFF, 0, 128, 5,
  6111. &fb_div, &vclk_div, &dclk_div);
  6112. if (r)
  6113. return r;
  6114. /* set RESET_ANTI_MUX to 0 */
  6115. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  6116. /* set VCO_MODE to 1 */
  6117. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  6118. /* toggle UPLL_SLEEP to 1 then back to 0 */
  6119. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  6120. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  6121. /* deassert UPLL_RESET */
  6122. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6123. mdelay(1);
  6124. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6125. if (r)
  6126. return r;
  6127. /* assert UPLL_RESET again */
  6128. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  6129. /* disable spread spectrum. */
  6130. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  6131. /* set feedback divider */
  6132. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  6133. /* set ref divider to 0 */
  6134. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  6135. if (fb_div < 307200)
  6136. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  6137. else
  6138. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  6139. /* set PDIV_A and PDIV_B */
  6140. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6141. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  6142. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  6143. /* give the PLL some time to settle */
  6144. mdelay(15);
  6145. /* deassert PLL_RESET */
  6146. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  6147. mdelay(15);
  6148. /* switch from bypass mode to normal mode */
  6149. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  6150. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  6151. if (r)
  6152. return r;
  6153. /* switch VCLK and DCLK selection */
  6154. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  6155. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  6156. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  6157. mdelay(100);
  6158. return 0;
  6159. }
  6160. static void si_pcie_gen3_enable(struct radeon_device *rdev)
  6161. {
  6162. struct pci_dev *root = rdev->pdev->bus->self;
  6163. int bridge_pos, gpu_pos;
  6164. u32 speed_cntl, mask, current_data_rate;
  6165. int ret, i;
  6166. u16 tmp16;
  6167. if (radeon_pcie_gen2 == 0)
  6168. return;
  6169. if (rdev->flags & RADEON_IS_IGP)
  6170. return;
  6171. if (!(rdev->flags & RADEON_IS_PCIE))
  6172. return;
  6173. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  6174. if (ret != 0)
  6175. return;
  6176. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  6177. return;
  6178. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6179. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  6180. LC_CURRENT_DATA_RATE_SHIFT;
  6181. if (mask & DRM_PCIE_SPEED_80) {
  6182. if (current_data_rate == 2) {
  6183. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  6184. return;
  6185. }
  6186. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  6187. } else if (mask & DRM_PCIE_SPEED_50) {
  6188. if (current_data_rate == 1) {
  6189. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  6190. return;
  6191. }
  6192. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  6193. }
  6194. bridge_pos = pci_pcie_cap(root);
  6195. if (!bridge_pos)
  6196. return;
  6197. gpu_pos = pci_pcie_cap(rdev->pdev);
  6198. if (!gpu_pos)
  6199. return;
  6200. if (mask & DRM_PCIE_SPEED_80) {
  6201. /* re-try equalization if gen3 is not already enabled */
  6202. if (current_data_rate != 2) {
  6203. u16 bridge_cfg, gpu_cfg;
  6204. u16 bridge_cfg2, gpu_cfg2;
  6205. u32 max_lw, current_lw, tmp;
  6206. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6207. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6208. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  6209. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6210. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  6211. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6212. tmp = RREG32_PCIE(PCIE_LC_STATUS1);
  6213. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  6214. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  6215. if (current_lw < max_lw) {
  6216. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6217. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  6218. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  6219. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  6220. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  6221. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  6222. }
  6223. }
  6224. for (i = 0; i < 10; i++) {
  6225. /* check status */
  6226. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  6227. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  6228. break;
  6229. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  6230. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  6231. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  6232. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  6233. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6234. tmp |= LC_SET_QUIESCE;
  6235. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6236. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6237. tmp |= LC_REDO_EQ;
  6238. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6239. mdelay(100);
  6240. /* linkctl */
  6241. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  6242. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6243. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  6244. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  6245. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  6246. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  6247. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  6248. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  6249. /* linkctl2 */
  6250. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  6251. tmp16 &= ~((1 << 4) | (7 << 9));
  6252. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  6253. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  6254. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6255. tmp16 &= ~((1 << 4) | (7 << 9));
  6256. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  6257. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6258. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  6259. tmp &= ~LC_SET_QUIESCE;
  6260. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  6261. }
  6262. }
  6263. }
  6264. /* set the link speed */
  6265. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  6266. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  6267. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6268. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  6269. tmp16 &= ~0xf;
  6270. if (mask & DRM_PCIE_SPEED_80)
  6271. tmp16 |= 3; /* gen3 */
  6272. else if (mask & DRM_PCIE_SPEED_50)
  6273. tmp16 |= 2; /* gen2 */
  6274. else
  6275. tmp16 |= 1; /* gen1 */
  6276. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  6277. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6278. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  6279. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  6280. for (i = 0; i < rdev->usec_timeout; i++) {
  6281. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  6282. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  6283. break;
  6284. udelay(1);
  6285. }
  6286. }
  6287. static void si_program_aspm(struct radeon_device *rdev)
  6288. {
  6289. u32 data, orig;
  6290. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  6291. bool disable_clkreq = false;
  6292. if (radeon_aspm == 0)
  6293. return;
  6294. if (!(rdev->flags & RADEON_IS_PCIE))
  6295. return;
  6296. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6297. data &= ~LC_XMIT_N_FTS_MASK;
  6298. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  6299. if (orig != data)
  6300. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  6301. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  6302. data |= LC_GO_TO_RECOVERY;
  6303. if (orig != data)
  6304. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  6305. orig = data = RREG32_PCIE(PCIE_P_CNTL);
  6306. data |= P_IGNORE_EDB_ERR;
  6307. if (orig != data)
  6308. WREG32_PCIE(PCIE_P_CNTL, data);
  6309. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6310. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  6311. data |= LC_PMI_TO_L1_DIS;
  6312. if (!disable_l0s)
  6313. data |= LC_L0S_INACTIVITY(7);
  6314. if (!disable_l1) {
  6315. data |= LC_L1_INACTIVITY(7);
  6316. data &= ~LC_PMI_TO_L1_DIS;
  6317. if (orig != data)
  6318. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6319. if (!disable_plloff_in_l1) {
  6320. bool clk_req_support;
  6321. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6322. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6323. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6324. if (orig != data)
  6325. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6326. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6327. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6328. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6329. if (orig != data)
  6330. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6331. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6332. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  6333. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  6334. if (orig != data)
  6335. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6336. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6337. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  6338. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  6339. if (orig != data)
  6340. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6341. if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
  6342. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  6343. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6344. if (orig != data)
  6345. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  6346. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  6347. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6348. if (orig != data)
  6349. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  6350. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
  6351. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6352. if (orig != data)
  6353. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
  6354. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
  6355. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6356. if (orig != data)
  6357. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
  6358. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  6359. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  6360. if (orig != data)
  6361. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  6362. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  6363. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  6364. if (orig != data)
  6365. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  6366. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
  6367. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  6368. if (orig != data)
  6369. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
  6370. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
  6371. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  6372. if (orig != data)
  6373. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
  6374. }
  6375. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  6376. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  6377. data |= LC_DYN_LANES_PWR_STATE(3);
  6378. if (orig != data)
  6379. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  6380. orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  6381. data &= ~LS2_EXIT_TIME_MASK;
  6382. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6383. data |= LS2_EXIT_TIME(5);
  6384. if (orig != data)
  6385. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  6386. orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  6387. data &= ~LS2_EXIT_TIME_MASK;
  6388. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  6389. data |= LS2_EXIT_TIME(5);
  6390. if (orig != data)
  6391. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  6392. if (!disable_clkreq) {
  6393. struct pci_dev *root = rdev->pdev->bus->self;
  6394. u32 lnkcap;
  6395. clk_req_support = false;
  6396. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  6397. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  6398. clk_req_support = true;
  6399. } else {
  6400. clk_req_support = false;
  6401. }
  6402. if (clk_req_support) {
  6403. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  6404. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  6405. if (orig != data)
  6406. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  6407. orig = data = RREG32(THM_CLK_CNTL);
  6408. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  6409. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  6410. if (orig != data)
  6411. WREG32(THM_CLK_CNTL, data);
  6412. orig = data = RREG32(MISC_CLK_CNTL);
  6413. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  6414. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  6415. if (orig != data)
  6416. WREG32(MISC_CLK_CNTL, data);
  6417. orig = data = RREG32(CG_CLKPIN_CNTL);
  6418. data &= ~BCLK_AS_XCLK;
  6419. if (orig != data)
  6420. WREG32(CG_CLKPIN_CNTL, data);
  6421. orig = data = RREG32(CG_CLKPIN_CNTL_2);
  6422. data &= ~FORCE_BIF_REFCLK_EN;
  6423. if (orig != data)
  6424. WREG32(CG_CLKPIN_CNTL_2, data);
  6425. orig = data = RREG32(MPLL_BYPASSCLK_SEL);
  6426. data &= ~MPLL_CLKOUT_SEL_MASK;
  6427. data |= MPLL_CLKOUT_SEL(4);
  6428. if (orig != data)
  6429. WREG32(MPLL_BYPASSCLK_SEL, data);
  6430. orig = data = RREG32(SPLL_CNTL_MODE);
  6431. data &= ~SPLL_REFCLK_SEL_MASK;
  6432. if (orig != data)
  6433. WREG32(SPLL_CNTL_MODE, data);
  6434. }
  6435. }
  6436. } else {
  6437. if (orig != data)
  6438. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6439. }
  6440. orig = data = RREG32_PCIE(PCIE_CNTL2);
  6441. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  6442. if (orig != data)
  6443. WREG32_PCIE(PCIE_CNTL2, data);
  6444. if (!disable_l0s) {
  6445. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  6446. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  6447. data = RREG32_PCIE(PCIE_LC_STATUS1);
  6448. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  6449. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  6450. data &= ~LC_L0S_INACTIVITY_MASK;
  6451. if (orig != data)
  6452. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  6453. }
  6454. }
  6455. }
  6456. }