si.c 199 KB

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