si.c 223 KB

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