si.c 200 KB

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