si.c 202 KB

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