si.c 204 KB

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