si.c 206 KB

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