evergreen.c 172 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include <drm/drmP.h>
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include <drm/radeon_drm.h>
  31. #include "evergreend.h"
  32. #include "atom.h"
  33. #include "avivod.h"
  34. #include "evergreen_reg.h"
  35. #include "evergreen_blit_shaders.h"
  36. #include "radeon_ucode.h"
  37. static const u32 crtc_offsets[6] =
  38. {
  39. EVERGREEN_CRTC0_REGISTER_OFFSET,
  40. EVERGREEN_CRTC1_REGISTER_OFFSET,
  41. EVERGREEN_CRTC2_REGISTER_OFFSET,
  42. EVERGREEN_CRTC3_REGISTER_OFFSET,
  43. EVERGREEN_CRTC4_REGISTER_OFFSET,
  44. EVERGREEN_CRTC5_REGISTER_OFFSET
  45. };
  46. #include "clearstate_evergreen.h"
  47. static const u32 sumo_rlc_save_restore_register_list[] =
  48. {
  49. 0x98fc,
  50. 0x9830,
  51. 0x9834,
  52. 0x9838,
  53. 0x9870,
  54. 0x9874,
  55. 0x8a14,
  56. 0x8b24,
  57. 0x8bcc,
  58. 0x8b10,
  59. 0x8d00,
  60. 0x8d04,
  61. 0x8c00,
  62. 0x8c04,
  63. 0x8c08,
  64. 0x8c0c,
  65. 0x8d8c,
  66. 0x8c20,
  67. 0x8c24,
  68. 0x8c28,
  69. 0x8c18,
  70. 0x8c1c,
  71. 0x8cf0,
  72. 0x8e2c,
  73. 0x8e38,
  74. 0x8c30,
  75. 0x9508,
  76. 0x9688,
  77. 0x9608,
  78. 0x960c,
  79. 0x9610,
  80. 0x9614,
  81. 0x88c4,
  82. 0x88d4,
  83. 0xa008,
  84. 0x900c,
  85. 0x9100,
  86. 0x913c,
  87. 0x98f8,
  88. 0x98f4,
  89. 0x9b7c,
  90. 0x3f8c,
  91. 0x8950,
  92. 0x8954,
  93. 0x8a18,
  94. 0x8b28,
  95. 0x9144,
  96. 0x9148,
  97. 0x914c,
  98. 0x3f90,
  99. 0x3f94,
  100. 0x915c,
  101. 0x9160,
  102. 0x9178,
  103. 0x917c,
  104. 0x9180,
  105. 0x918c,
  106. 0x9190,
  107. 0x9194,
  108. 0x9198,
  109. 0x919c,
  110. 0x91a8,
  111. 0x91ac,
  112. 0x91b0,
  113. 0x91b4,
  114. 0x91b8,
  115. 0x91c4,
  116. 0x91c8,
  117. 0x91cc,
  118. 0x91d0,
  119. 0x91d4,
  120. 0x91e0,
  121. 0x91e4,
  122. 0x91ec,
  123. 0x91f0,
  124. 0x91f4,
  125. 0x9200,
  126. 0x9204,
  127. 0x929c,
  128. 0x9150,
  129. 0x802c,
  130. };
  131. static void evergreen_gpu_init(struct radeon_device *rdev);
  132. void evergreen_fini(struct radeon_device *rdev);
  133. void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  134. void evergreen_program_aspm(struct radeon_device *rdev);
  135. extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  136. int ring, u32 cp_int_cntl);
  137. extern void cayman_vm_decode_fault(struct radeon_device *rdev,
  138. u32 status, u32 addr);
  139. void cik_init_cp_pg_table(struct radeon_device *rdev);
  140. extern u32 si_get_csb_size(struct radeon_device *rdev);
  141. extern void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  142. extern u32 cik_get_csb_size(struct radeon_device *rdev);
  143. extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  144. extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
  145. static const u32 evergreen_golden_registers[] =
  146. {
  147. 0x3f90, 0xffff0000, 0xff000000,
  148. 0x9148, 0xffff0000, 0xff000000,
  149. 0x3f94, 0xffff0000, 0xff000000,
  150. 0x914c, 0xffff0000, 0xff000000,
  151. 0x9b7c, 0xffffffff, 0x00000000,
  152. 0x8a14, 0xffffffff, 0x00000007,
  153. 0x8b10, 0xffffffff, 0x00000000,
  154. 0x960c, 0xffffffff, 0x54763210,
  155. 0x88c4, 0xffffffff, 0x000000c2,
  156. 0x88d4, 0xffffffff, 0x00000010,
  157. 0x8974, 0xffffffff, 0x00000000,
  158. 0xc78, 0x00000080, 0x00000080,
  159. 0x5eb4, 0xffffffff, 0x00000002,
  160. 0x5e78, 0xffffffff, 0x001000f0,
  161. 0x6104, 0x01000300, 0x00000000,
  162. 0x5bc0, 0x00300000, 0x00000000,
  163. 0x7030, 0xffffffff, 0x00000011,
  164. 0x7c30, 0xffffffff, 0x00000011,
  165. 0x10830, 0xffffffff, 0x00000011,
  166. 0x11430, 0xffffffff, 0x00000011,
  167. 0x12030, 0xffffffff, 0x00000011,
  168. 0x12c30, 0xffffffff, 0x00000011,
  169. 0xd02c, 0xffffffff, 0x08421000,
  170. 0x240c, 0xffffffff, 0x00000380,
  171. 0x8b24, 0xffffffff, 0x00ff0fff,
  172. 0x28a4c, 0x06000000, 0x06000000,
  173. 0x10c, 0x00000001, 0x00000001,
  174. 0x8d00, 0xffffffff, 0x100e4848,
  175. 0x8d04, 0xffffffff, 0x00164745,
  176. 0x8c00, 0xffffffff, 0xe4000003,
  177. 0x8c04, 0xffffffff, 0x40600060,
  178. 0x8c08, 0xffffffff, 0x001c001c,
  179. 0x8cf0, 0xffffffff, 0x08e00620,
  180. 0x8c20, 0xffffffff, 0x00800080,
  181. 0x8c24, 0xffffffff, 0x00800080,
  182. 0x8c18, 0xffffffff, 0x20202078,
  183. 0x8c1c, 0xffffffff, 0x00001010,
  184. 0x28350, 0xffffffff, 0x00000000,
  185. 0xa008, 0xffffffff, 0x00010000,
  186. 0x5cc, 0xffffffff, 0x00000001,
  187. 0x9508, 0xffffffff, 0x00000002,
  188. 0x913c, 0x0000000f, 0x0000000a
  189. };
  190. static const u32 evergreen_golden_registers2[] =
  191. {
  192. 0x2f4c, 0xffffffff, 0x00000000,
  193. 0x54f4, 0xffffffff, 0x00000000,
  194. 0x54f0, 0xffffffff, 0x00000000,
  195. 0x5498, 0xffffffff, 0x00000000,
  196. 0x549c, 0xffffffff, 0x00000000,
  197. 0x5494, 0xffffffff, 0x00000000,
  198. 0x53cc, 0xffffffff, 0x00000000,
  199. 0x53c8, 0xffffffff, 0x00000000,
  200. 0x53c4, 0xffffffff, 0x00000000,
  201. 0x53c0, 0xffffffff, 0x00000000,
  202. 0x53bc, 0xffffffff, 0x00000000,
  203. 0x53b8, 0xffffffff, 0x00000000,
  204. 0x53b4, 0xffffffff, 0x00000000,
  205. 0x53b0, 0xffffffff, 0x00000000
  206. };
  207. static const u32 cypress_mgcg_init[] =
  208. {
  209. 0x802c, 0xffffffff, 0xc0000000,
  210. 0x5448, 0xffffffff, 0x00000100,
  211. 0x55e4, 0xffffffff, 0x00000100,
  212. 0x160c, 0xffffffff, 0x00000100,
  213. 0x5644, 0xffffffff, 0x00000100,
  214. 0xc164, 0xffffffff, 0x00000100,
  215. 0x8a18, 0xffffffff, 0x00000100,
  216. 0x897c, 0xffffffff, 0x06000100,
  217. 0x8b28, 0xffffffff, 0x00000100,
  218. 0x9144, 0xffffffff, 0x00000100,
  219. 0x9a60, 0xffffffff, 0x00000100,
  220. 0x9868, 0xffffffff, 0x00000100,
  221. 0x8d58, 0xffffffff, 0x00000100,
  222. 0x9510, 0xffffffff, 0x00000100,
  223. 0x949c, 0xffffffff, 0x00000100,
  224. 0x9654, 0xffffffff, 0x00000100,
  225. 0x9030, 0xffffffff, 0x00000100,
  226. 0x9034, 0xffffffff, 0x00000100,
  227. 0x9038, 0xffffffff, 0x00000100,
  228. 0x903c, 0xffffffff, 0x00000100,
  229. 0x9040, 0xffffffff, 0x00000100,
  230. 0xa200, 0xffffffff, 0x00000100,
  231. 0xa204, 0xffffffff, 0x00000100,
  232. 0xa208, 0xffffffff, 0x00000100,
  233. 0xa20c, 0xffffffff, 0x00000100,
  234. 0x971c, 0xffffffff, 0x00000100,
  235. 0x977c, 0xffffffff, 0x00000100,
  236. 0x3f80, 0xffffffff, 0x00000100,
  237. 0xa210, 0xffffffff, 0x00000100,
  238. 0xa214, 0xffffffff, 0x00000100,
  239. 0x4d8, 0xffffffff, 0x00000100,
  240. 0x9784, 0xffffffff, 0x00000100,
  241. 0x9698, 0xffffffff, 0x00000100,
  242. 0x4d4, 0xffffffff, 0x00000200,
  243. 0x30cc, 0xffffffff, 0x00000100,
  244. 0xd0c0, 0xffffffff, 0xff000100,
  245. 0x802c, 0xffffffff, 0x40000000,
  246. 0x915c, 0xffffffff, 0x00010000,
  247. 0x9160, 0xffffffff, 0x00030002,
  248. 0x9178, 0xffffffff, 0x00070000,
  249. 0x917c, 0xffffffff, 0x00030002,
  250. 0x9180, 0xffffffff, 0x00050004,
  251. 0x918c, 0xffffffff, 0x00010006,
  252. 0x9190, 0xffffffff, 0x00090008,
  253. 0x9194, 0xffffffff, 0x00070000,
  254. 0x9198, 0xffffffff, 0x00030002,
  255. 0x919c, 0xffffffff, 0x00050004,
  256. 0x91a8, 0xffffffff, 0x00010006,
  257. 0x91ac, 0xffffffff, 0x00090008,
  258. 0x91b0, 0xffffffff, 0x00070000,
  259. 0x91b4, 0xffffffff, 0x00030002,
  260. 0x91b8, 0xffffffff, 0x00050004,
  261. 0x91c4, 0xffffffff, 0x00010006,
  262. 0x91c8, 0xffffffff, 0x00090008,
  263. 0x91cc, 0xffffffff, 0x00070000,
  264. 0x91d0, 0xffffffff, 0x00030002,
  265. 0x91d4, 0xffffffff, 0x00050004,
  266. 0x91e0, 0xffffffff, 0x00010006,
  267. 0x91e4, 0xffffffff, 0x00090008,
  268. 0x91e8, 0xffffffff, 0x00000000,
  269. 0x91ec, 0xffffffff, 0x00070000,
  270. 0x91f0, 0xffffffff, 0x00030002,
  271. 0x91f4, 0xffffffff, 0x00050004,
  272. 0x9200, 0xffffffff, 0x00010006,
  273. 0x9204, 0xffffffff, 0x00090008,
  274. 0x9208, 0xffffffff, 0x00070000,
  275. 0x920c, 0xffffffff, 0x00030002,
  276. 0x9210, 0xffffffff, 0x00050004,
  277. 0x921c, 0xffffffff, 0x00010006,
  278. 0x9220, 0xffffffff, 0x00090008,
  279. 0x9224, 0xffffffff, 0x00070000,
  280. 0x9228, 0xffffffff, 0x00030002,
  281. 0x922c, 0xffffffff, 0x00050004,
  282. 0x9238, 0xffffffff, 0x00010006,
  283. 0x923c, 0xffffffff, 0x00090008,
  284. 0x9240, 0xffffffff, 0x00070000,
  285. 0x9244, 0xffffffff, 0x00030002,
  286. 0x9248, 0xffffffff, 0x00050004,
  287. 0x9254, 0xffffffff, 0x00010006,
  288. 0x9258, 0xffffffff, 0x00090008,
  289. 0x925c, 0xffffffff, 0x00070000,
  290. 0x9260, 0xffffffff, 0x00030002,
  291. 0x9264, 0xffffffff, 0x00050004,
  292. 0x9270, 0xffffffff, 0x00010006,
  293. 0x9274, 0xffffffff, 0x00090008,
  294. 0x9278, 0xffffffff, 0x00070000,
  295. 0x927c, 0xffffffff, 0x00030002,
  296. 0x9280, 0xffffffff, 0x00050004,
  297. 0x928c, 0xffffffff, 0x00010006,
  298. 0x9290, 0xffffffff, 0x00090008,
  299. 0x9294, 0xffffffff, 0x00000000,
  300. 0x929c, 0xffffffff, 0x00000001,
  301. 0x802c, 0xffffffff, 0x40010000,
  302. 0x915c, 0xffffffff, 0x00010000,
  303. 0x9160, 0xffffffff, 0x00030002,
  304. 0x9178, 0xffffffff, 0x00070000,
  305. 0x917c, 0xffffffff, 0x00030002,
  306. 0x9180, 0xffffffff, 0x00050004,
  307. 0x918c, 0xffffffff, 0x00010006,
  308. 0x9190, 0xffffffff, 0x00090008,
  309. 0x9194, 0xffffffff, 0x00070000,
  310. 0x9198, 0xffffffff, 0x00030002,
  311. 0x919c, 0xffffffff, 0x00050004,
  312. 0x91a8, 0xffffffff, 0x00010006,
  313. 0x91ac, 0xffffffff, 0x00090008,
  314. 0x91b0, 0xffffffff, 0x00070000,
  315. 0x91b4, 0xffffffff, 0x00030002,
  316. 0x91b8, 0xffffffff, 0x00050004,
  317. 0x91c4, 0xffffffff, 0x00010006,
  318. 0x91c8, 0xffffffff, 0x00090008,
  319. 0x91cc, 0xffffffff, 0x00070000,
  320. 0x91d0, 0xffffffff, 0x00030002,
  321. 0x91d4, 0xffffffff, 0x00050004,
  322. 0x91e0, 0xffffffff, 0x00010006,
  323. 0x91e4, 0xffffffff, 0x00090008,
  324. 0x91e8, 0xffffffff, 0x00000000,
  325. 0x91ec, 0xffffffff, 0x00070000,
  326. 0x91f0, 0xffffffff, 0x00030002,
  327. 0x91f4, 0xffffffff, 0x00050004,
  328. 0x9200, 0xffffffff, 0x00010006,
  329. 0x9204, 0xffffffff, 0x00090008,
  330. 0x9208, 0xffffffff, 0x00070000,
  331. 0x920c, 0xffffffff, 0x00030002,
  332. 0x9210, 0xffffffff, 0x00050004,
  333. 0x921c, 0xffffffff, 0x00010006,
  334. 0x9220, 0xffffffff, 0x00090008,
  335. 0x9224, 0xffffffff, 0x00070000,
  336. 0x9228, 0xffffffff, 0x00030002,
  337. 0x922c, 0xffffffff, 0x00050004,
  338. 0x9238, 0xffffffff, 0x00010006,
  339. 0x923c, 0xffffffff, 0x00090008,
  340. 0x9240, 0xffffffff, 0x00070000,
  341. 0x9244, 0xffffffff, 0x00030002,
  342. 0x9248, 0xffffffff, 0x00050004,
  343. 0x9254, 0xffffffff, 0x00010006,
  344. 0x9258, 0xffffffff, 0x00090008,
  345. 0x925c, 0xffffffff, 0x00070000,
  346. 0x9260, 0xffffffff, 0x00030002,
  347. 0x9264, 0xffffffff, 0x00050004,
  348. 0x9270, 0xffffffff, 0x00010006,
  349. 0x9274, 0xffffffff, 0x00090008,
  350. 0x9278, 0xffffffff, 0x00070000,
  351. 0x927c, 0xffffffff, 0x00030002,
  352. 0x9280, 0xffffffff, 0x00050004,
  353. 0x928c, 0xffffffff, 0x00010006,
  354. 0x9290, 0xffffffff, 0x00090008,
  355. 0x9294, 0xffffffff, 0x00000000,
  356. 0x929c, 0xffffffff, 0x00000001,
  357. 0x802c, 0xffffffff, 0xc0000000
  358. };
  359. static const u32 redwood_mgcg_init[] =
  360. {
  361. 0x802c, 0xffffffff, 0xc0000000,
  362. 0x5448, 0xffffffff, 0x00000100,
  363. 0x55e4, 0xffffffff, 0x00000100,
  364. 0x160c, 0xffffffff, 0x00000100,
  365. 0x5644, 0xffffffff, 0x00000100,
  366. 0xc164, 0xffffffff, 0x00000100,
  367. 0x8a18, 0xffffffff, 0x00000100,
  368. 0x897c, 0xffffffff, 0x06000100,
  369. 0x8b28, 0xffffffff, 0x00000100,
  370. 0x9144, 0xffffffff, 0x00000100,
  371. 0x9a60, 0xffffffff, 0x00000100,
  372. 0x9868, 0xffffffff, 0x00000100,
  373. 0x8d58, 0xffffffff, 0x00000100,
  374. 0x9510, 0xffffffff, 0x00000100,
  375. 0x949c, 0xffffffff, 0x00000100,
  376. 0x9654, 0xffffffff, 0x00000100,
  377. 0x9030, 0xffffffff, 0x00000100,
  378. 0x9034, 0xffffffff, 0x00000100,
  379. 0x9038, 0xffffffff, 0x00000100,
  380. 0x903c, 0xffffffff, 0x00000100,
  381. 0x9040, 0xffffffff, 0x00000100,
  382. 0xa200, 0xffffffff, 0x00000100,
  383. 0xa204, 0xffffffff, 0x00000100,
  384. 0xa208, 0xffffffff, 0x00000100,
  385. 0xa20c, 0xffffffff, 0x00000100,
  386. 0x971c, 0xffffffff, 0x00000100,
  387. 0x977c, 0xffffffff, 0x00000100,
  388. 0x3f80, 0xffffffff, 0x00000100,
  389. 0xa210, 0xffffffff, 0x00000100,
  390. 0xa214, 0xffffffff, 0x00000100,
  391. 0x4d8, 0xffffffff, 0x00000100,
  392. 0x9784, 0xffffffff, 0x00000100,
  393. 0x9698, 0xffffffff, 0x00000100,
  394. 0x4d4, 0xffffffff, 0x00000200,
  395. 0x30cc, 0xffffffff, 0x00000100,
  396. 0xd0c0, 0xffffffff, 0xff000100,
  397. 0x802c, 0xffffffff, 0x40000000,
  398. 0x915c, 0xffffffff, 0x00010000,
  399. 0x9160, 0xffffffff, 0x00030002,
  400. 0x9178, 0xffffffff, 0x00070000,
  401. 0x917c, 0xffffffff, 0x00030002,
  402. 0x9180, 0xffffffff, 0x00050004,
  403. 0x918c, 0xffffffff, 0x00010006,
  404. 0x9190, 0xffffffff, 0x00090008,
  405. 0x9194, 0xffffffff, 0x00070000,
  406. 0x9198, 0xffffffff, 0x00030002,
  407. 0x919c, 0xffffffff, 0x00050004,
  408. 0x91a8, 0xffffffff, 0x00010006,
  409. 0x91ac, 0xffffffff, 0x00090008,
  410. 0x91b0, 0xffffffff, 0x00070000,
  411. 0x91b4, 0xffffffff, 0x00030002,
  412. 0x91b8, 0xffffffff, 0x00050004,
  413. 0x91c4, 0xffffffff, 0x00010006,
  414. 0x91c8, 0xffffffff, 0x00090008,
  415. 0x91cc, 0xffffffff, 0x00070000,
  416. 0x91d0, 0xffffffff, 0x00030002,
  417. 0x91d4, 0xffffffff, 0x00050004,
  418. 0x91e0, 0xffffffff, 0x00010006,
  419. 0x91e4, 0xffffffff, 0x00090008,
  420. 0x91e8, 0xffffffff, 0x00000000,
  421. 0x91ec, 0xffffffff, 0x00070000,
  422. 0x91f0, 0xffffffff, 0x00030002,
  423. 0x91f4, 0xffffffff, 0x00050004,
  424. 0x9200, 0xffffffff, 0x00010006,
  425. 0x9204, 0xffffffff, 0x00090008,
  426. 0x9294, 0xffffffff, 0x00000000,
  427. 0x929c, 0xffffffff, 0x00000001,
  428. 0x802c, 0xffffffff, 0xc0000000
  429. };
  430. static const u32 cedar_golden_registers[] =
  431. {
  432. 0x3f90, 0xffff0000, 0xff000000,
  433. 0x9148, 0xffff0000, 0xff000000,
  434. 0x3f94, 0xffff0000, 0xff000000,
  435. 0x914c, 0xffff0000, 0xff000000,
  436. 0x9b7c, 0xffffffff, 0x00000000,
  437. 0x8a14, 0xffffffff, 0x00000007,
  438. 0x8b10, 0xffffffff, 0x00000000,
  439. 0x960c, 0xffffffff, 0x54763210,
  440. 0x88c4, 0xffffffff, 0x000000c2,
  441. 0x88d4, 0xffffffff, 0x00000000,
  442. 0x8974, 0xffffffff, 0x00000000,
  443. 0xc78, 0x00000080, 0x00000080,
  444. 0x5eb4, 0xffffffff, 0x00000002,
  445. 0x5e78, 0xffffffff, 0x001000f0,
  446. 0x6104, 0x01000300, 0x00000000,
  447. 0x5bc0, 0x00300000, 0x00000000,
  448. 0x7030, 0xffffffff, 0x00000011,
  449. 0x7c30, 0xffffffff, 0x00000011,
  450. 0x10830, 0xffffffff, 0x00000011,
  451. 0x11430, 0xffffffff, 0x00000011,
  452. 0xd02c, 0xffffffff, 0x08421000,
  453. 0x240c, 0xffffffff, 0x00000380,
  454. 0x8b24, 0xffffffff, 0x00ff0fff,
  455. 0x28a4c, 0x06000000, 0x06000000,
  456. 0x10c, 0x00000001, 0x00000001,
  457. 0x8d00, 0xffffffff, 0x100e4848,
  458. 0x8d04, 0xffffffff, 0x00164745,
  459. 0x8c00, 0xffffffff, 0xe4000003,
  460. 0x8c04, 0xffffffff, 0x40600060,
  461. 0x8c08, 0xffffffff, 0x001c001c,
  462. 0x8cf0, 0xffffffff, 0x08e00410,
  463. 0x8c20, 0xffffffff, 0x00800080,
  464. 0x8c24, 0xffffffff, 0x00800080,
  465. 0x8c18, 0xffffffff, 0x20202078,
  466. 0x8c1c, 0xffffffff, 0x00001010,
  467. 0x28350, 0xffffffff, 0x00000000,
  468. 0xa008, 0xffffffff, 0x00010000,
  469. 0x5cc, 0xffffffff, 0x00000001,
  470. 0x9508, 0xffffffff, 0x00000002
  471. };
  472. static const u32 cedar_mgcg_init[] =
  473. {
  474. 0x802c, 0xffffffff, 0xc0000000,
  475. 0x5448, 0xffffffff, 0x00000100,
  476. 0x55e4, 0xffffffff, 0x00000100,
  477. 0x160c, 0xffffffff, 0x00000100,
  478. 0x5644, 0xffffffff, 0x00000100,
  479. 0xc164, 0xffffffff, 0x00000100,
  480. 0x8a18, 0xffffffff, 0x00000100,
  481. 0x897c, 0xffffffff, 0x06000100,
  482. 0x8b28, 0xffffffff, 0x00000100,
  483. 0x9144, 0xffffffff, 0x00000100,
  484. 0x9a60, 0xffffffff, 0x00000100,
  485. 0x9868, 0xffffffff, 0x00000100,
  486. 0x8d58, 0xffffffff, 0x00000100,
  487. 0x9510, 0xffffffff, 0x00000100,
  488. 0x949c, 0xffffffff, 0x00000100,
  489. 0x9654, 0xffffffff, 0x00000100,
  490. 0x9030, 0xffffffff, 0x00000100,
  491. 0x9034, 0xffffffff, 0x00000100,
  492. 0x9038, 0xffffffff, 0x00000100,
  493. 0x903c, 0xffffffff, 0x00000100,
  494. 0x9040, 0xffffffff, 0x00000100,
  495. 0xa200, 0xffffffff, 0x00000100,
  496. 0xa204, 0xffffffff, 0x00000100,
  497. 0xa208, 0xffffffff, 0x00000100,
  498. 0xa20c, 0xffffffff, 0x00000100,
  499. 0x971c, 0xffffffff, 0x00000100,
  500. 0x977c, 0xffffffff, 0x00000100,
  501. 0x3f80, 0xffffffff, 0x00000100,
  502. 0xa210, 0xffffffff, 0x00000100,
  503. 0xa214, 0xffffffff, 0x00000100,
  504. 0x4d8, 0xffffffff, 0x00000100,
  505. 0x9784, 0xffffffff, 0x00000100,
  506. 0x9698, 0xffffffff, 0x00000100,
  507. 0x4d4, 0xffffffff, 0x00000200,
  508. 0x30cc, 0xffffffff, 0x00000100,
  509. 0xd0c0, 0xffffffff, 0xff000100,
  510. 0x802c, 0xffffffff, 0x40000000,
  511. 0x915c, 0xffffffff, 0x00010000,
  512. 0x9178, 0xffffffff, 0x00050000,
  513. 0x917c, 0xffffffff, 0x00030002,
  514. 0x918c, 0xffffffff, 0x00010004,
  515. 0x9190, 0xffffffff, 0x00070006,
  516. 0x9194, 0xffffffff, 0x00050000,
  517. 0x9198, 0xffffffff, 0x00030002,
  518. 0x91a8, 0xffffffff, 0x00010004,
  519. 0x91ac, 0xffffffff, 0x00070006,
  520. 0x91e8, 0xffffffff, 0x00000000,
  521. 0x9294, 0xffffffff, 0x00000000,
  522. 0x929c, 0xffffffff, 0x00000001,
  523. 0x802c, 0xffffffff, 0xc0000000
  524. };
  525. static const u32 juniper_mgcg_init[] =
  526. {
  527. 0x802c, 0xffffffff, 0xc0000000,
  528. 0x5448, 0xffffffff, 0x00000100,
  529. 0x55e4, 0xffffffff, 0x00000100,
  530. 0x160c, 0xffffffff, 0x00000100,
  531. 0x5644, 0xffffffff, 0x00000100,
  532. 0xc164, 0xffffffff, 0x00000100,
  533. 0x8a18, 0xffffffff, 0x00000100,
  534. 0x897c, 0xffffffff, 0x06000100,
  535. 0x8b28, 0xffffffff, 0x00000100,
  536. 0x9144, 0xffffffff, 0x00000100,
  537. 0x9a60, 0xffffffff, 0x00000100,
  538. 0x9868, 0xffffffff, 0x00000100,
  539. 0x8d58, 0xffffffff, 0x00000100,
  540. 0x9510, 0xffffffff, 0x00000100,
  541. 0x949c, 0xffffffff, 0x00000100,
  542. 0x9654, 0xffffffff, 0x00000100,
  543. 0x9030, 0xffffffff, 0x00000100,
  544. 0x9034, 0xffffffff, 0x00000100,
  545. 0x9038, 0xffffffff, 0x00000100,
  546. 0x903c, 0xffffffff, 0x00000100,
  547. 0x9040, 0xffffffff, 0x00000100,
  548. 0xa200, 0xffffffff, 0x00000100,
  549. 0xa204, 0xffffffff, 0x00000100,
  550. 0xa208, 0xffffffff, 0x00000100,
  551. 0xa20c, 0xffffffff, 0x00000100,
  552. 0x971c, 0xffffffff, 0x00000100,
  553. 0xd0c0, 0xffffffff, 0xff000100,
  554. 0x802c, 0xffffffff, 0x40000000,
  555. 0x915c, 0xffffffff, 0x00010000,
  556. 0x9160, 0xffffffff, 0x00030002,
  557. 0x9178, 0xffffffff, 0x00070000,
  558. 0x917c, 0xffffffff, 0x00030002,
  559. 0x9180, 0xffffffff, 0x00050004,
  560. 0x918c, 0xffffffff, 0x00010006,
  561. 0x9190, 0xffffffff, 0x00090008,
  562. 0x9194, 0xffffffff, 0x00070000,
  563. 0x9198, 0xffffffff, 0x00030002,
  564. 0x919c, 0xffffffff, 0x00050004,
  565. 0x91a8, 0xffffffff, 0x00010006,
  566. 0x91ac, 0xffffffff, 0x00090008,
  567. 0x91b0, 0xffffffff, 0x00070000,
  568. 0x91b4, 0xffffffff, 0x00030002,
  569. 0x91b8, 0xffffffff, 0x00050004,
  570. 0x91c4, 0xffffffff, 0x00010006,
  571. 0x91c8, 0xffffffff, 0x00090008,
  572. 0x91cc, 0xffffffff, 0x00070000,
  573. 0x91d0, 0xffffffff, 0x00030002,
  574. 0x91d4, 0xffffffff, 0x00050004,
  575. 0x91e0, 0xffffffff, 0x00010006,
  576. 0x91e4, 0xffffffff, 0x00090008,
  577. 0x91e8, 0xffffffff, 0x00000000,
  578. 0x91ec, 0xffffffff, 0x00070000,
  579. 0x91f0, 0xffffffff, 0x00030002,
  580. 0x91f4, 0xffffffff, 0x00050004,
  581. 0x9200, 0xffffffff, 0x00010006,
  582. 0x9204, 0xffffffff, 0x00090008,
  583. 0x9208, 0xffffffff, 0x00070000,
  584. 0x920c, 0xffffffff, 0x00030002,
  585. 0x9210, 0xffffffff, 0x00050004,
  586. 0x921c, 0xffffffff, 0x00010006,
  587. 0x9220, 0xffffffff, 0x00090008,
  588. 0x9224, 0xffffffff, 0x00070000,
  589. 0x9228, 0xffffffff, 0x00030002,
  590. 0x922c, 0xffffffff, 0x00050004,
  591. 0x9238, 0xffffffff, 0x00010006,
  592. 0x923c, 0xffffffff, 0x00090008,
  593. 0x9240, 0xffffffff, 0x00070000,
  594. 0x9244, 0xffffffff, 0x00030002,
  595. 0x9248, 0xffffffff, 0x00050004,
  596. 0x9254, 0xffffffff, 0x00010006,
  597. 0x9258, 0xffffffff, 0x00090008,
  598. 0x925c, 0xffffffff, 0x00070000,
  599. 0x9260, 0xffffffff, 0x00030002,
  600. 0x9264, 0xffffffff, 0x00050004,
  601. 0x9270, 0xffffffff, 0x00010006,
  602. 0x9274, 0xffffffff, 0x00090008,
  603. 0x9278, 0xffffffff, 0x00070000,
  604. 0x927c, 0xffffffff, 0x00030002,
  605. 0x9280, 0xffffffff, 0x00050004,
  606. 0x928c, 0xffffffff, 0x00010006,
  607. 0x9290, 0xffffffff, 0x00090008,
  608. 0x9294, 0xffffffff, 0x00000000,
  609. 0x929c, 0xffffffff, 0x00000001,
  610. 0x802c, 0xffffffff, 0xc0000000,
  611. 0x977c, 0xffffffff, 0x00000100,
  612. 0x3f80, 0xffffffff, 0x00000100,
  613. 0xa210, 0xffffffff, 0x00000100,
  614. 0xa214, 0xffffffff, 0x00000100,
  615. 0x4d8, 0xffffffff, 0x00000100,
  616. 0x9784, 0xffffffff, 0x00000100,
  617. 0x9698, 0xffffffff, 0x00000100,
  618. 0x4d4, 0xffffffff, 0x00000200,
  619. 0x30cc, 0xffffffff, 0x00000100,
  620. 0x802c, 0xffffffff, 0xc0000000
  621. };
  622. static const u32 supersumo_golden_registers[] =
  623. {
  624. 0x5eb4, 0xffffffff, 0x00000002,
  625. 0x5cc, 0xffffffff, 0x00000001,
  626. 0x7030, 0xffffffff, 0x00000011,
  627. 0x7c30, 0xffffffff, 0x00000011,
  628. 0x6104, 0x01000300, 0x00000000,
  629. 0x5bc0, 0x00300000, 0x00000000,
  630. 0x8c04, 0xffffffff, 0x40600060,
  631. 0x8c08, 0xffffffff, 0x001c001c,
  632. 0x8c20, 0xffffffff, 0x00800080,
  633. 0x8c24, 0xffffffff, 0x00800080,
  634. 0x8c18, 0xffffffff, 0x20202078,
  635. 0x8c1c, 0xffffffff, 0x00001010,
  636. 0x918c, 0xffffffff, 0x00010006,
  637. 0x91a8, 0xffffffff, 0x00010006,
  638. 0x91c4, 0xffffffff, 0x00010006,
  639. 0x91e0, 0xffffffff, 0x00010006,
  640. 0x9200, 0xffffffff, 0x00010006,
  641. 0x9150, 0xffffffff, 0x6e944040,
  642. 0x917c, 0xffffffff, 0x00030002,
  643. 0x9180, 0xffffffff, 0x00050004,
  644. 0x9198, 0xffffffff, 0x00030002,
  645. 0x919c, 0xffffffff, 0x00050004,
  646. 0x91b4, 0xffffffff, 0x00030002,
  647. 0x91b8, 0xffffffff, 0x00050004,
  648. 0x91d0, 0xffffffff, 0x00030002,
  649. 0x91d4, 0xffffffff, 0x00050004,
  650. 0x91f0, 0xffffffff, 0x00030002,
  651. 0x91f4, 0xffffffff, 0x00050004,
  652. 0x915c, 0xffffffff, 0x00010000,
  653. 0x9160, 0xffffffff, 0x00030002,
  654. 0x3f90, 0xffff0000, 0xff000000,
  655. 0x9178, 0xffffffff, 0x00070000,
  656. 0x9194, 0xffffffff, 0x00070000,
  657. 0x91b0, 0xffffffff, 0x00070000,
  658. 0x91cc, 0xffffffff, 0x00070000,
  659. 0x91ec, 0xffffffff, 0x00070000,
  660. 0x9148, 0xffff0000, 0xff000000,
  661. 0x9190, 0xffffffff, 0x00090008,
  662. 0x91ac, 0xffffffff, 0x00090008,
  663. 0x91c8, 0xffffffff, 0x00090008,
  664. 0x91e4, 0xffffffff, 0x00090008,
  665. 0x9204, 0xffffffff, 0x00090008,
  666. 0x3f94, 0xffff0000, 0xff000000,
  667. 0x914c, 0xffff0000, 0xff000000,
  668. 0x929c, 0xffffffff, 0x00000001,
  669. 0x8a18, 0xffffffff, 0x00000100,
  670. 0x8b28, 0xffffffff, 0x00000100,
  671. 0x9144, 0xffffffff, 0x00000100,
  672. 0x5644, 0xffffffff, 0x00000100,
  673. 0x9b7c, 0xffffffff, 0x00000000,
  674. 0x8030, 0xffffffff, 0x0000100a,
  675. 0x8a14, 0xffffffff, 0x00000007,
  676. 0x8b24, 0xffffffff, 0x00ff0fff,
  677. 0x8b10, 0xffffffff, 0x00000000,
  678. 0x28a4c, 0x06000000, 0x06000000,
  679. 0x4d8, 0xffffffff, 0x00000100,
  680. 0x913c, 0xffff000f, 0x0100000a,
  681. 0x960c, 0xffffffff, 0x54763210,
  682. 0x88c4, 0xffffffff, 0x000000c2,
  683. 0x88d4, 0xffffffff, 0x00000010,
  684. 0x8974, 0xffffffff, 0x00000000,
  685. 0xc78, 0x00000080, 0x00000080,
  686. 0x5e78, 0xffffffff, 0x001000f0,
  687. 0xd02c, 0xffffffff, 0x08421000,
  688. 0xa008, 0xffffffff, 0x00010000,
  689. 0x8d00, 0xffffffff, 0x100e4848,
  690. 0x8d04, 0xffffffff, 0x00164745,
  691. 0x8c00, 0xffffffff, 0xe4000003,
  692. 0x8cf0, 0x1fffffff, 0x08e00620,
  693. 0x28350, 0xffffffff, 0x00000000,
  694. 0x9508, 0xffffffff, 0x00000002
  695. };
  696. static const u32 sumo_golden_registers[] =
  697. {
  698. 0x900c, 0x00ffffff, 0x0017071f,
  699. 0x8c18, 0xffffffff, 0x10101060,
  700. 0x8c1c, 0xffffffff, 0x00001010,
  701. 0x8c30, 0x0000000f, 0x00000005,
  702. 0x9688, 0x0000000f, 0x00000007
  703. };
  704. static const u32 wrestler_golden_registers[] =
  705. {
  706. 0x5eb4, 0xffffffff, 0x00000002,
  707. 0x5cc, 0xffffffff, 0x00000001,
  708. 0x7030, 0xffffffff, 0x00000011,
  709. 0x7c30, 0xffffffff, 0x00000011,
  710. 0x6104, 0x01000300, 0x00000000,
  711. 0x5bc0, 0x00300000, 0x00000000,
  712. 0x918c, 0xffffffff, 0x00010006,
  713. 0x91a8, 0xffffffff, 0x00010006,
  714. 0x9150, 0xffffffff, 0x6e944040,
  715. 0x917c, 0xffffffff, 0x00030002,
  716. 0x9198, 0xffffffff, 0x00030002,
  717. 0x915c, 0xffffffff, 0x00010000,
  718. 0x3f90, 0xffff0000, 0xff000000,
  719. 0x9178, 0xffffffff, 0x00070000,
  720. 0x9194, 0xffffffff, 0x00070000,
  721. 0x9148, 0xffff0000, 0xff000000,
  722. 0x9190, 0xffffffff, 0x00090008,
  723. 0x91ac, 0xffffffff, 0x00090008,
  724. 0x3f94, 0xffff0000, 0xff000000,
  725. 0x914c, 0xffff0000, 0xff000000,
  726. 0x929c, 0xffffffff, 0x00000001,
  727. 0x8a18, 0xffffffff, 0x00000100,
  728. 0x8b28, 0xffffffff, 0x00000100,
  729. 0x9144, 0xffffffff, 0x00000100,
  730. 0x9b7c, 0xffffffff, 0x00000000,
  731. 0x8030, 0xffffffff, 0x0000100a,
  732. 0x8a14, 0xffffffff, 0x00000001,
  733. 0x8b24, 0xffffffff, 0x00ff0fff,
  734. 0x8b10, 0xffffffff, 0x00000000,
  735. 0x28a4c, 0x06000000, 0x06000000,
  736. 0x4d8, 0xffffffff, 0x00000100,
  737. 0x913c, 0xffff000f, 0x0100000a,
  738. 0x960c, 0xffffffff, 0x54763210,
  739. 0x88c4, 0xffffffff, 0x000000c2,
  740. 0x88d4, 0xffffffff, 0x00000010,
  741. 0x8974, 0xffffffff, 0x00000000,
  742. 0xc78, 0x00000080, 0x00000080,
  743. 0x5e78, 0xffffffff, 0x001000f0,
  744. 0xd02c, 0xffffffff, 0x08421000,
  745. 0xa008, 0xffffffff, 0x00010000,
  746. 0x8d00, 0xffffffff, 0x100e4848,
  747. 0x8d04, 0xffffffff, 0x00164745,
  748. 0x8c00, 0xffffffff, 0xe4000003,
  749. 0x8cf0, 0x1fffffff, 0x08e00410,
  750. 0x28350, 0xffffffff, 0x00000000,
  751. 0x9508, 0xffffffff, 0x00000002,
  752. 0x900c, 0xffffffff, 0x0017071f,
  753. 0x8c18, 0xffffffff, 0x10101060,
  754. 0x8c1c, 0xffffffff, 0x00001010
  755. };
  756. static const u32 barts_golden_registers[] =
  757. {
  758. 0x5eb4, 0xffffffff, 0x00000002,
  759. 0x5e78, 0x8f311ff1, 0x001000f0,
  760. 0x3f90, 0xffff0000, 0xff000000,
  761. 0x9148, 0xffff0000, 0xff000000,
  762. 0x3f94, 0xffff0000, 0xff000000,
  763. 0x914c, 0xffff0000, 0xff000000,
  764. 0xc78, 0x00000080, 0x00000080,
  765. 0xbd4, 0x70073777, 0x00010001,
  766. 0xd02c, 0xbfffff1f, 0x08421000,
  767. 0xd0b8, 0x03773777, 0x02011003,
  768. 0x5bc0, 0x00200000, 0x50100000,
  769. 0x98f8, 0x33773777, 0x02011003,
  770. 0x98fc, 0xffffffff, 0x76543210,
  771. 0x7030, 0x31000311, 0x00000011,
  772. 0x2f48, 0x00000007, 0x02011003,
  773. 0x6b28, 0x00000010, 0x00000012,
  774. 0x7728, 0x00000010, 0x00000012,
  775. 0x10328, 0x00000010, 0x00000012,
  776. 0x10f28, 0x00000010, 0x00000012,
  777. 0x11b28, 0x00000010, 0x00000012,
  778. 0x12728, 0x00000010, 0x00000012,
  779. 0x240c, 0x000007ff, 0x00000380,
  780. 0x8a14, 0xf000001f, 0x00000007,
  781. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  782. 0x8b10, 0x0000ff0f, 0x00000000,
  783. 0x28a4c, 0x07ffffff, 0x06000000,
  784. 0x10c, 0x00000001, 0x00010003,
  785. 0xa02c, 0xffffffff, 0x0000009b,
  786. 0x913c, 0x0000000f, 0x0100000a,
  787. 0x8d00, 0xffff7f7f, 0x100e4848,
  788. 0x8d04, 0x00ffffff, 0x00164745,
  789. 0x8c00, 0xfffc0003, 0xe4000003,
  790. 0x8c04, 0xf8ff00ff, 0x40600060,
  791. 0x8c08, 0x00ff00ff, 0x001c001c,
  792. 0x8cf0, 0x1fff1fff, 0x08e00620,
  793. 0x8c20, 0x0fff0fff, 0x00800080,
  794. 0x8c24, 0x0fff0fff, 0x00800080,
  795. 0x8c18, 0xffffffff, 0x20202078,
  796. 0x8c1c, 0x0000ffff, 0x00001010,
  797. 0x28350, 0x00000f01, 0x00000000,
  798. 0x9508, 0x3700001f, 0x00000002,
  799. 0x960c, 0xffffffff, 0x54763210,
  800. 0x88c4, 0x001f3ae3, 0x000000c2,
  801. 0x88d4, 0x0000001f, 0x00000010,
  802. 0x8974, 0xffffffff, 0x00000000
  803. };
  804. static const u32 turks_golden_registers[] =
  805. {
  806. 0x5eb4, 0xffffffff, 0x00000002,
  807. 0x5e78, 0x8f311ff1, 0x001000f0,
  808. 0x8c8, 0x00003000, 0x00001070,
  809. 0x8cc, 0x000fffff, 0x00040035,
  810. 0x3f90, 0xffff0000, 0xfff00000,
  811. 0x9148, 0xffff0000, 0xfff00000,
  812. 0x3f94, 0xffff0000, 0xfff00000,
  813. 0x914c, 0xffff0000, 0xfff00000,
  814. 0xc78, 0x00000080, 0x00000080,
  815. 0xbd4, 0x00073007, 0x00010002,
  816. 0xd02c, 0xbfffff1f, 0x08421000,
  817. 0xd0b8, 0x03773777, 0x02010002,
  818. 0x5bc0, 0x00200000, 0x50100000,
  819. 0x98f8, 0x33773777, 0x00010002,
  820. 0x98fc, 0xffffffff, 0x33221100,
  821. 0x7030, 0x31000311, 0x00000011,
  822. 0x2f48, 0x33773777, 0x00010002,
  823. 0x6b28, 0x00000010, 0x00000012,
  824. 0x7728, 0x00000010, 0x00000012,
  825. 0x10328, 0x00000010, 0x00000012,
  826. 0x10f28, 0x00000010, 0x00000012,
  827. 0x11b28, 0x00000010, 0x00000012,
  828. 0x12728, 0x00000010, 0x00000012,
  829. 0x240c, 0x000007ff, 0x00000380,
  830. 0x8a14, 0xf000001f, 0x00000007,
  831. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  832. 0x8b10, 0x0000ff0f, 0x00000000,
  833. 0x28a4c, 0x07ffffff, 0x06000000,
  834. 0x10c, 0x00000001, 0x00010003,
  835. 0xa02c, 0xffffffff, 0x0000009b,
  836. 0x913c, 0x0000000f, 0x0100000a,
  837. 0x8d00, 0xffff7f7f, 0x100e4848,
  838. 0x8d04, 0x00ffffff, 0x00164745,
  839. 0x8c00, 0xfffc0003, 0xe4000003,
  840. 0x8c04, 0xf8ff00ff, 0x40600060,
  841. 0x8c08, 0x00ff00ff, 0x001c001c,
  842. 0x8cf0, 0x1fff1fff, 0x08e00410,
  843. 0x8c20, 0x0fff0fff, 0x00800080,
  844. 0x8c24, 0x0fff0fff, 0x00800080,
  845. 0x8c18, 0xffffffff, 0x20202078,
  846. 0x8c1c, 0x0000ffff, 0x00001010,
  847. 0x28350, 0x00000f01, 0x00000000,
  848. 0x9508, 0x3700001f, 0x00000002,
  849. 0x960c, 0xffffffff, 0x54763210,
  850. 0x88c4, 0x001f3ae3, 0x000000c2,
  851. 0x88d4, 0x0000001f, 0x00000010,
  852. 0x8974, 0xffffffff, 0x00000000
  853. };
  854. static const u32 caicos_golden_registers[] =
  855. {
  856. 0x5eb4, 0xffffffff, 0x00000002,
  857. 0x5e78, 0x8f311ff1, 0x001000f0,
  858. 0x8c8, 0x00003420, 0x00001450,
  859. 0x8cc, 0x000fffff, 0x00040035,
  860. 0x3f90, 0xffff0000, 0xfffc0000,
  861. 0x9148, 0xffff0000, 0xfffc0000,
  862. 0x3f94, 0xffff0000, 0xfffc0000,
  863. 0x914c, 0xffff0000, 0xfffc0000,
  864. 0xc78, 0x00000080, 0x00000080,
  865. 0xbd4, 0x00073007, 0x00010001,
  866. 0xd02c, 0xbfffff1f, 0x08421000,
  867. 0xd0b8, 0x03773777, 0x02010001,
  868. 0x5bc0, 0x00200000, 0x50100000,
  869. 0x98f8, 0x33773777, 0x02010001,
  870. 0x98fc, 0xffffffff, 0x33221100,
  871. 0x7030, 0x31000311, 0x00000011,
  872. 0x2f48, 0x33773777, 0x02010001,
  873. 0x6b28, 0x00000010, 0x00000012,
  874. 0x7728, 0x00000010, 0x00000012,
  875. 0x10328, 0x00000010, 0x00000012,
  876. 0x10f28, 0x00000010, 0x00000012,
  877. 0x11b28, 0x00000010, 0x00000012,
  878. 0x12728, 0x00000010, 0x00000012,
  879. 0x240c, 0x000007ff, 0x00000380,
  880. 0x8a14, 0xf000001f, 0x00000001,
  881. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  882. 0x8b10, 0x0000ff0f, 0x00000000,
  883. 0x28a4c, 0x07ffffff, 0x06000000,
  884. 0x10c, 0x00000001, 0x00010003,
  885. 0xa02c, 0xffffffff, 0x0000009b,
  886. 0x913c, 0x0000000f, 0x0100000a,
  887. 0x8d00, 0xffff7f7f, 0x100e4848,
  888. 0x8d04, 0x00ffffff, 0x00164745,
  889. 0x8c00, 0xfffc0003, 0xe4000003,
  890. 0x8c04, 0xf8ff00ff, 0x40600060,
  891. 0x8c08, 0x00ff00ff, 0x001c001c,
  892. 0x8cf0, 0x1fff1fff, 0x08e00410,
  893. 0x8c20, 0x0fff0fff, 0x00800080,
  894. 0x8c24, 0x0fff0fff, 0x00800080,
  895. 0x8c18, 0xffffffff, 0x20202078,
  896. 0x8c1c, 0x0000ffff, 0x00001010,
  897. 0x28350, 0x00000f01, 0x00000000,
  898. 0x9508, 0x3700001f, 0x00000002,
  899. 0x960c, 0xffffffff, 0x54763210,
  900. 0x88c4, 0x001f3ae3, 0x000000c2,
  901. 0x88d4, 0x0000001f, 0x00000010,
  902. 0x8974, 0xffffffff, 0x00000000
  903. };
  904. static void evergreen_init_golden_registers(struct radeon_device *rdev)
  905. {
  906. switch (rdev->family) {
  907. case CHIP_CYPRESS:
  908. case CHIP_HEMLOCK:
  909. radeon_program_register_sequence(rdev,
  910. evergreen_golden_registers,
  911. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  912. radeon_program_register_sequence(rdev,
  913. evergreen_golden_registers2,
  914. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  915. radeon_program_register_sequence(rdev,
  916. cypress_mgcg_init,
  917. (const u32)ARRAY_SIZE(cypress_mgcg_init));
  918. break;
  919. case CHIP_JUNIPER:
  920. radeon_program_register_sequence(rdev,
  921. evergreen_golden_registers,
  922. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  923. radeon_program_register_sequence(rdev,
  924. evergreen_golden_registers2,
  925. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  926. radeon_program_register_sequence(rdev,
  927. juniper_mgcg_init,
  928. (const u32)ARRAY_SIZE(juniper_mgcg_init));
  929. break;
  930. case CHIP_REDWOOD:
  931. radeon_program_register_sequence(rdev,
  932. evergreen_golden_registers,
  933. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  934. radeon_program_register_sequence(rdev,
  935. evergreen_golden_registers2,
  936. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  937. radeon_program_register_sequence(rdev,
  938. redwood_mgcg_init,
  939. (const u32)ARRAY_SIZE(redwood_mgcg_init));
  940. break;
  941. case CHIP_CEDAR:
  942. radeon_program_register_sequence(rdev,
  943. cedar_golden_registers,
  944. (const u32)ARRAY_SIZE(cedar_golden_registers));
  945. radeon_program_register_sequence(rdev,
  946. evergreen_golden_registers2,
  947. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  948. radeon_program_register_sequence(rdev,
  949. cedar_mgcg_init,
  950. (const u32)ARRAY_SIZE(cedar_mgcg_init));
  951. break;
  952. case CHIP_PALM:
  953. radeon_program_register_sequence(rdev,
  954. wrestler_golden_registers,
  955. (const u32)ARRAY_SIZE(wrestler_golden_registers));
  956. break;
  957. case CHIP_SUMO:
  958. radeon_program_register_sequence(rdev,
  959. supersumo_golden_registers,
  960. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  961. break;
  962. case CHIP_SUMO2:
  963. radeon_program_register_sequence(rdev,
  964. supersumo_golden_registers,
  965. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  966. radeon_program_register_sequence(rdev,
  967. sumo_golden_registers,
  968. (const u32)ARRAY_SIZE(sumo_golden_registers));
  969. break;
  970. case CHIP_BARTS:
  971. radeon_program_register_sequence(rdev,
  972. barts_golden_registers,
  973. (const u32)ARRAY_SIZE(barts_golden_registers));
  974. break;
  975. case CHIP_TURKS:
  976. radeon_program_register_sequence(rdev,
  977. turks_golden_registers,
  978. (const u32)ARRAY_SIZE(turks_golden_registers));
  979. break;
  980. case CHIP_CAICOS:
  981. radeon_program_register_sequence(rdev,
  982. caicos_golden_registers,
  983. (const u32)ARRAY_SIZE(caicos_golden_registers));
  984. break;
  985. default:
  986. break;
  987. }
  988. }
  989. void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  990. unsigned *bankh, unsigned *mtaspect,
  991. unsigned *tile_split)
  992. {
  993. *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
  994. *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
  995. *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
  996. *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
  997. switch (*bankw) {
  998. default:
  999. case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
  1000. case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
  1001. case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
  1002. case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
  1003. }
  1004. switch (*bankh) {
  1005. default:
  1006. case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
  1007. case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
  1008. case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
  1009. case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
  1010. }
  1011. switch (*mtaspect) {
  1012. default:
  1013. case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
  1014. case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
  1015. case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
  1016. case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
  1017. }
  1018. }
  1019. static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  1020. u32 cntl_reg, u32 status_reg)
  1021. {
  1022. int r, i;
  1023. struct atom_clock_dividers dividers;
  1024. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1025. clock, false, &dividers);
  1026. if (r)
  1027. return r;
  1028. WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
  1029. for (i = 0; i < 100; i++) {
  1030. if (RREG32(status_reg) & DCLK_STATUS)
  1031. break;
  1032. mdelay(10);
  1033. }
  1034. if (i == 100)
  1035. return -ETIMEDOUT;
  1036. return 0;
  1037. }
  1038. int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1039. {
  1040. int r = 0;
  1041. u32 cg_scratch = RREG32(CG_SCRATCH1);
  1042. r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  1043. if (r)
  1044. goto done;
  1045. cg_scratch &= 0xffff0000;
  1046. cg_scratch |= vclk / 100; /* Mhz */
  1047. r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  1048. if (r)
  1049. goto done;
  1050. cg_scratch &= 0x0000ffff;
  1051. cg_scratch |= (dclk / 100) << 16; /* Mhz */
  1052. done:
  1053. WREG32(CG_SCRATCH1, cg_scratch);
  1054. return r;
  1055. }
  1056. int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1057. {
  1058. /* start off with something large */
  1059. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  1060. int r;
  1061. /* bypass vclk and dclk with bclk */
  1062. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1063. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  1064. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1065. /* put PLL in bypass mode */
  1066. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  1067. if (!vclk || !dclk) {
  1068. /* keep the Bypass mode, put PLL to sleep */
  1069. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1070. return 0;
  1071. }
  1072. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  1073. 16384, 0x03FFFFFF, 0, 128, 5,
  1074. &fb_div, &vclk_div, &dclk_div);
  1075. if (r)
  1076. return r;
  1077. /* set VCO_MODE to 1 */
  1078. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  1079. /* toggle UPLL_SLEEP to 1 then back to 0 */
  1080. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1081. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  1082. /* deassert UPLL_RESET */
  1083. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1084. mdelay(1);
  1085. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1086. if (r)
  1087. return r;
  1088. /* assert UPLL_RESET again */
  1089. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  1090. /* disable spread spectrum. */
  1091. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  1092. /* set feedback divider */
  1093. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  1094. /* set ref divider to 0 */
  1095. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  1096. if (fb_div < 307200)
  1097. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  1098. else
  1099. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  1100. /* set PDIV_A and PDIV_B */
  1101. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1102. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  1103. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  1104. /* give the PLL some time to settle */
  1105. mdelay(15);
  1106. /* deassert PLL_RESET */
  1107. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1108. mdelay(15);
  1109. /* switch from bypass mode to normal mode */
  1110. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  1111. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1112. if (r)
  1113. return r;
  1114. /* switch VCLK and DCLK selection */
  1115. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1116. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  1117. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1118. mdelay(100);
  1119. return 0;
  1120. }
  1121. void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
  1122. {
  1123. int readrq;
  1124. u16 v;
  1125. readrq = pcie_get_readrq(rdev->pdev);
  1126. v = ffs(readrq) - 8;
  1127. /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
  1128. * to avoid hangs or perfomance issues
  1129. */
  1130. if ((v == 0) || (v == 6) || (v == 7))
  1131. pcie_set_readrq(rdev->pdev, 512);
  1132. }
  1133. void dce4_program_fmt(struct drm_encoder *encoder)
  1134. {
  1135. struct drm_device *dev = encoder->dev;
  1136. struct radeon_device *rdev = dev->dev_private;
  1137. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1138. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1139. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1140. int bpc = 0;
  1141. u32 tmp = 0;
  1142. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  1143. if (connector) {
  1144. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1145. bpc = radeon_get_monitor_bpc(connector);
  1146. dither = radeon_connector->dither;
  1147. }
  1148. /* LVDS/eDP FMT is set up by atom */
  1149. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  1150. return;
  1151. /* not needed for analog */
  1152. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  1153. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  1154. return;
  1155. if (bpc == 0)
  1156. return;
  1157. switch (bpc) {
  1158. case 6:
  1159. if (dither == RADEON_FMT_DITHER_ENABLE)
  1160. /* XXX sort out optimal dither settings */
  1161. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1162. FMT_SPATIAL_DITHER_EN);
  1163. else
  1164. tmp |= FMT_TRUNCATE_EN;
  1165. break;
  1166. case 8:
  1167. if (dither == RADEON_FMT_DITHER_ENABLE)
  1168. /* XXX sort out optimal dither settings */
  1169. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1170. FMT_RGB_RANDOM_ENABLE |
  1171. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
  1172. else
  1173. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
  1174. break;
  1175. case 10:
  1176. default:
  1177. /* not needed */
  1178. break;
  1179. }
  1180. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  1181. }
  1182. static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
  1183. {
  1184. if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
  1185. return true;
  1186. else
  1187. return false;
  1188. }
  1189. static bool dce4_is_counter_moving(struct radeon_device *rdev, int crtc)
  1190. {
  1191. u32 pos1, pos2;
  1192. pos1 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1193. pos2 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1194. if (pos1 != pos2)
  1195. return true;
  1196. else
  1197. return false;
  1198. }
  1199. /**
  1200. * dce4_wait_for_vblank - vblank wait asic callback.
  1201. *
  1202. * @rdev: radeon_device pointer
  1203. * @crtc: crtc to wait for vblank on
  1204. *
  1205. * Wait for vblank on the requested crtc (evergreen+).
  1206. */
  1207. void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
  1208. {
  1209. unsigned i = 0;
  1210. if (crtc >= rdev->num_crtc)
  1211. return;
  1212. if (!(RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN))
  1213. return;
  1214. /* depending on when we hit vblank, we may be close to active; if so,
  1215. * wait for another frame.
  1216. */
  1217. while (dce4_is_in_vblank(rdev, crtc)) {
  1218. if (i++ % 100 == 0) {
  1219. if (!dce4_is_counter_moving(rdev, crtc))
  1220. break;
  1221. }
  1222. }
  1223. while (!dce4_is_in_vblank(rdev, crtc)) {
  1224. if (i++ % 100 == 0) {
  1225. if (!dce4_is_counter_moving(rdev, crtc))
  1226. break;
  1227. }
  1228. }
  1229. }
  1230. /**
  1231. * radeon_irq_kms_pflip_irq_get - pre-pageflip callback.
  1232. *
  1233. * @rdev: radeon_device pointer
  1234. * @crtc: crtc to prepare for pageflip on
  1235. *
  1236. * Pre-pageflip callback (evergreen+).
  1237. * Enables the pageflip irq (vblank irq).
  1238. */
  1239. void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc)
  1240. {
  1241. /* enable the pflip int */
  1242. radeon_irq_kms_pflip_irq_get(rdev, crtc);
  1243. }
  1244. /**
  1245. * evergreen_post_page_flip - pos-pageflip callback.
  1246. *
  1247. * @rdev: radeon_device pointer
  1248. * @crtc: crtc to cleanup pageflip on
  1249. *
  1250. * Post-pageflip callback (evergreen+).
  1251. * Disables the pageflip irq (vblank irq).
  1252. */
  1253. void evergreen_post_page_flip(struct radeon_device *rdev, int crtc)
  1254. {
  1255. /* disable the pflip int */
  1256. radeon_irq_kms_pflip_irq_put(rdev, crtc);
  1257. }
  1258. /**
  1259. * evergreen_page_flip - pageflip callback.
  1260. *
  1261. * @rdev: radeon_device pointer
  1262. * @crtc_id: crtc to cleanup pageflip on
  1263. * @crtc_base: new address of the crtc (GPU MC address)
  1264. *
  1265. * Does the actual pageflip (evergreen+).
  1266. * During vblank we take the crtc lock and wait for the update_pending
  1267. * bit to go high, when it does, we release the lock, and allow the
  1268. * double buffered update to take place.
  1269. * Returns the current update pending status.
  1270. */
  1271. u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
  1272. {
  1273. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1274. u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
  1275. int i;
  1276. /* Lock the graphics update lock */
  1277. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  1278. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  1279. /* update the scanout addresses */
  1280. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1281. upper_32_bits(crtc_base));
  1282. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1283. (u32)crtc_base);
  1284. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1285. upper_32_bits(crtc_base));
  1286. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1287. (u32)crtc_base);
  1288. /* Wait for update_pending to go high. */
  1289. for (i = 0; i < rdev->usec_timeout; i++) {
  1290. if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
  1291. break;
  1292. udelay(1);
  1293. }
  1294. DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
  1295. /* Unlock the lock, so double-buffering can take place inside vblank */
  1296. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  1297. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  1298. /* Return current update_pending status: */
  1299. return RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING;
  1300. }
  1301. /* get temperature in millidegrees */
  1302. int evergreen_get_temp(struct radeon_device *rdev)
  1303. {
  1304. u32 temp, toffset;
  1305. int actual_temp = 0;
  1306. if (rdev->family == CHIP_JUNIPER) {
  1307. toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
  1308. TOFFSET_SHIFT;
  1309. temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
  1310. TS0_ADC_DOUT_SHIFT;
  1311. if (toffset & 0x100)
  1312. actual_temp = temp / 2 - (0x200 - toffset);
  1313. else
  1314. actual_temp = temp / 2 + toffset;
  1315. actual_temp = actual_temp * 1000;
  1316. } else {
  1317. temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  1318. ASIC_T_SHIFT;
  1319. if (temp & 0x400)
  1320. actual_temp = -256;
  1321. else if (temp & 0x200)
  1322. actual_temp = 255;
  1323. else if (temp & 0x100) {
  1324. actual_temp = temp & 0x1ff;
  1325. actual_temp |= ~0x1ff;
  1326. } else
  1327. actual_temp = temp & 0xff;
  1328. actual_temp = (actual_temp * 1000) / 2;
  1329. }
  1330. return actual_temp;
  1331. }
  1332. int sumo_get_temp(struct radeon_device *rdev)
  1333. {
  1334. u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
  1335. int actual_temp = temp - 49;
  1336. return actual_temp * 1000;
  1337. }
  1338. /**
  1339. * sumo_pm_init_profile - Initialize power profiles callback.
  1340. *
  1341. * @rdev: radeon_device pointer
  1342. *
  1343. * Initialize the power states used in profile mode
  1344. * (sumo, trinity, SI).
  1345. * Used for profile mode only.
  1346. */
  1347. void sumo_pm_init_profile(struct radeon_device *rdev)
  1348. {
  1349. int idx;
  1350. /* default */
  1351. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1352. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1353. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1354. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  1355. /* low,mid sh/mh */
  1356. if (rdev->flags & RADEON_IS_MOBILITY)
  1357. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1358. else
  1359. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1360. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1361. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1362. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1363. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1364. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1365. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1366. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1367. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1368. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1369. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1370. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1371. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  1372. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1373. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1374. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1375. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  1376. /* high sh/mh */
  1377. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1378. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1379. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1380. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1381. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
  1382. rdev->pm.power_state[idx].num_clock_modes - 1;
  1383. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1384. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1385. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1386. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
  1387. rdev->pm.power_state[idx].num_clock_modes - 1;
  1388. }
  1389. /**
  1390. * btc_pm_init_profile - Initialize power profiles callback.
  1391. *
  1392. * @rdev: radeon_device pointer
  1393. *
  1394. * Initialize the power states used in profile mode
  1395. * (BTC, cayman).
  1396. * Used for profile mode only.
  1397. */
  1398. void btc_pm_init_profile(struct radeon_device *rdev)
  1399. {
  1400. int idx;
  1401. /* default */
  1402. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1403. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1404. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1405. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  1406. /* starting with BTC, there is one state that is used for both
  1407. * MH and SH. Difference is that we always use the high clock index for
  1408. * mclk.
  1409. */
  1410. if (rdev->flags & RADEON_IS_MOBILITY)
  1411. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1412. else
  1413. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1414. /* low sh */
  1415. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1416. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1417. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1418. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1419. /* mid sh */
  1420. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1421. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1422. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1423. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  1424. /* high sh */
  1425. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1426. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1427. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1428. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  1429. /* low mh */
  1430. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1431. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1432. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1433. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1434. /* mid mh */
  1435. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1436. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1437. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1438. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  1439. /* high mh */
  1440. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1441. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1442. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1443. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  1444. }
  1445. /**
  1446. * evergreen_pm_misc - set additional pm hw parameters callback.
  1447. *
  1448. * @rdev: radeon_device pointer
  1449. *
  1450. * Set non-clock parameters associated with a power state
  1451. * (voltage, etc.) (evergreen+).
  1452. */
  1453. void evergreen_pm_misc(struct radeon_device *rdev)
  1454. {
  1455. int req_ps_idx = rdev->pm.requested_power_state_index;
  1456. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  1457. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  1458. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  1459. if (voltage->type == VOLTAGE_SW) {
  1460. /* 0xff0x are flags rather then an actual voltage */
  1461. if ((voltage->voltage & 0xff00) == 0xff00)
  1462. return;
  1463. if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
  1464. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  1465. rdev->pm.current_vddc = voltage->voltage;
  1466. DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
  1467. }
  1468. /* starting with BTC, there is one state that is used for both
  1469. * MH and SH. Difference is that we always use the high clock index for
  1470. * mclk and vddci.
  1471. */
  1472. if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
  1473. (rdev->family >= CHIP_BARTS) &&
  1474. rdev->pm.active_crtc_count &&
  1475. ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
  1476. (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
  1477. voltage = &rdev->pm.power_state[req_ps_idx].
  1478. clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
  1479. /* 0xff0x are flags rather then an actual voltage */
  1480. if ((voltage->vddci & 0xff00) == 0xff00)
  1481. return;
  1482. if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
  1483. radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
  1484. rdev->pm.current_vddci = voltage->vddci;
  1485. DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
  1486. }
  1487. }
  1488. }
  1489. /**
  1490. * evergreen_pm_prepare - pre-power state change callback.
  1491. *
  1492. * @rdev: radeon_device pointer
  1493. *
  1494. * Prepare for a power state change (evergreen+).
  1495. */
  1496. void evergreen_pm_prepare(struct radeon_device *rdev)
  1497. {
  1498. struct drm_device *ddev = rdev->ddev;
  1499. struct drm_crtc *crtc;
  1500. struct radeon_crtc *radeon_crtc;
  1501. u32 tmp;
  1502. /* disable any active CRTCs */
  1503. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1504. radeon_crtc = to_radeon_crtc(crtc);
  1505. if (radeon_crtc->enabled) {
  1506. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1507. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1508. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1509. }
  1510. }
  1511. }
  1512. /**
  1513. * evergreen_pm_finish - post-power state change callback.
  1514. *
  1515. * @rdev: radeon_device pointer
  1516. *
  1517. * Clean up after a power state change (evergreen+).
  1518. */
  1519. void evergreen_pm_finish(struct radeon_device *rdev)
  1520. {
  1521. struct drm_device *ddev = rdev->ddev;
  1522. struct drm_crtc *crtc;
  1523. struct radeon_crtc *radeon_crtc;
  1524. u32 tmp;
  1525. /* enable any active CRTCs */
  1526. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1527. radeon_crtc = to_radeon_crtc(crtc);
  1528. if (radeon_crtc->enabled) {
  1529. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1530. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1531. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1532. }
  1533. }
  1534. }
  1535. /**
  1536. * evergreen_hpd_sense - hpd sense callback.
  1537. *
  1538. * @rdev: radeon_device pointer
  1539. * @hpd: hpd (hotplug detect) pin
  1540. *
  1541. * Checks if a digital monitor is connected (evergreen+).
  1542. * Returns true if connected, false if not connected.
  1543. */
  1544. bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  1545. {
  1546. bool connected = false;
  1547. switch (hpd) {
  1548. case RADEON_HPD_1:
  1549. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  1550. connected = true;
  1551. break;
  1552. case RADEON_HPD_2:
  1553. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  1554. connected = true;
  1555. break;
  1556. case RADEON_HPD_3:
  1557. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  1558. connected = true;
  1559. break;
  1560. case RADEON_HPD_4:
  1561. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  1562. connected = true;
  1563. break;
  1564. case RADEON_HPD_5:
  1565. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  1566. connected = true;
  1567. break;
  1568. case RADEON_HPD_6:
  1569. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  1570. connected = true;
  1571. break;
  1572. default:
  1573. break;
  1574. }
  1575. return connected;
  1576. }
  1577. /**
  1578. * evergreen_hpd_set_polarity - hpd set polarity callback.
  1579. *
  1580. * @rdev: radeon_device pointer
  1581. * @hpd: hpd (hotplug detect) pin
  1582. *
  1583. * Set the polarity of the hpd pin (evergreen+).
  1584. */
  1585. void evergreen_hpd_set_polarity(struct radeon_device *rdev,
  1586. enum radeon_hpd_id hpd)
  1587. {
  1588. u32 tmp;
  1589. bool connected = evergreen_hpd_sense(rdev, hpd);
  1590. switch (hpd) {
  1591. case RADEON_HPD_1:
  1592. tmp = RREG32(DC_HPD1_INT_CONTROL);
  1593. if (connected)
  1594. tmp &= ~DC_HPDx_INT_POLARITY;
  1595. else
  1596. tmp |= DC_HPDx_INT_POLARITY;
  1597. WREG32(DC_HPD1_INT_CONTROL, tmp);
  1598. break;
  1599. case RADEON_HPD_2:
  1600. tmp = RREG32(DC_HPD2_INT_CONTROL);
  1601. if (connected)
  1602. tmp &= ~DC_HPDx_INT_POLARITY;
  1603. else
  1604. tmp |= DC_HPDx_INT_POLARITY;
  1605. WREG32(DC_HPD2_INT_CONTROL, tmp);
  1606. break;
  1607. case RADEON_HPD_3:
  1608. tmp = RREG32(DC_HPD3_INT_CONTROL);
  1609. if (connected)
  1610. tmp &= ~DC_HPDx_INT_POLARITY;
  1611. else
  1612. tmp |= DC_HPDx_INT_POLARITY;
  1613. WREG32(DC_HPD3_INT_CONTROL, tmp);
  1614. break;
  1615. case RADEON_HPD_4:
  1616. tmp = RREG32(DC_HPD4_INT_CONTROL);
  1617. if (connected)
  1618. tmp &= ~DC_HPDx_INT_POLARITY;
  1619. else
  1620. tmp |= DC_HPDx_INT_POLARITY;
  1621. WREG32(DC_HPD4_INT_CONTROL, tmp);
  1622. break;
  1623. case RADEON_HPD_5:
  1624. tmp = RREG32(DC_HPD5_INT_CONTROL);
  1625. if (connected)
  1626. tmp &= ~DC_HPDx_INT_POLARITY;
  1627. else
  1628. tmp |= DC_HPDx_INT_POLARITY;
  1629. WREG32(DC_HPD5_INT_CONTROL, tmp);
  1630. break;
  1631. case RADEON_HPD_6:
  1632. tmp = RREG32(DC_HPD6_INT_CONTROL);
  1633. if (connected)
  1634. tmp &= ~DC_HPDx_INT_POLARITY;
  1635. else
  1636. tmp |= DC_HPDx_INT_POLARITY;
  1637. WREG32(DC_HPD6_INT_CONTROL, tmp);
  1638. break;
  1639. default:
  1640. break;
  1641. }
  1642. }
  1643. /**
  1644. * evergreen_hpd_init - hpd setup callback.
  1645. *
  1646. * @rdev: radeon_device pointer
  1647. *
  1648. * Setup the hpd pins used by the card (evergreen+).
  1649. * Enable the pin, set the polarity, and enable the hpd interrupts.
  1650. */
  1651. void evergreen_hpd_init(struct radeon_device *rdev)
  1652. {
  1653. struct drm_device *dev = rdev->ddev;
  1654. struct drm_connector *connector;
  1655. unsigned enabled = 0;
  1656. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
  1657. DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
  1658. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1659. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1660. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  1661. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  1662. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  1663. * aux dp channel on imac and help (but not completely fix)
  1664. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  1665. * also avoid interrupt storms during dpms.
  1666. */
  1667. continue;
  1668. }
  1669. switch (radeon_connector->hpd.hpd) {
  1670. case RADEON_HPD_1:
  1671. WREG32(DC_HPD1_CONTROL, tmp);
  1672. break;
  1673. case RADEON_HPD_2:
  1674. WREG32(DC_HPD2_CONTROL, tmp);
  1675. break;
  1676. case RADEON_HPD_3:
  1677. WREG32(DC_HPD3_CONTROL, tmp);
  1678. break;
  1679. case RADEON_HPD_4:
  1680. WREG32(DC_HPD4_CONTROL, tmp);
  1681. break;
  1682. case RADEON_HPD_5:
  1683. WREG32(DC_HPD5_CONTROL, tmp);
  1684. break;
  1685. case RADEON_HPD_6:
  1686. WREG32(DC_HPD6_CONTROL, tmp);
  1687. break;
  1688. default:
  1689. break;
  1690. }
  1691. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  1692. enabled |= 1 << radeon_connector->hpd.hpd;
  1693. }
  1694. radeon_irq_kms_enable_hpd(rdev, enabled);
  1695. }
  1696. /**
  1697. * evergreen_hpd_fini - hpd tear down callback.
  1698. *
  1699. * @rdev: radeon_device pointer
  1700. *
  1701. * Tear down the hpd pins used by the card (evergreen+).
  1702. * Disable the hpd interrupts.
  1703. */
  1704. void evergreen_hpd_fini(struct radeon_device *rdev)
  1705. {
  1706. struct drm_device *dev = rdev->ddev;
  1707. struct drm_connector *connector;
  1708. unsigned disabled = 0;
  1709. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1710. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1711. switch (radeon_connector->hpd.hpd) {
  1712. case RADEON_HPD_1:
  1713. WREG32(DC_HPD1_CONTROL, 0);
  1714. break;
  1715. case RADEON_HPD_2:
  1716. WREG32(DC_HPD2_CONTROL, 0);
  1717. break;
  1718. case RADEON_HPD_3:
  1719. WREG32(DC_HPD3_CONTROL, 0);
  1720. break;
  1721. case RADEON_HPD_4:
  1722. WREG32(DC_HPD4_CONTROL, 0);
  1723. break;
  1724. case RADEON_HPD_5:
  1725. WREG32(DC_HPD5_CONTROL, 0);
  1726. break;
  1727. case RADEON_HPD_6:
  1728. WREG32(DC_HPD6_CONTROL, 0);
  1729. break;
  1730. default:
  1731. break;
  1732. }
  1733. disabled |= 1 << radeon_connector->hpd.hpd;
  1734. }
  1735. radeon_irq_kms_disable_hpd(rdev, disabled);
  1736. }
  1737. /* watermark setup */
  1738. static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
  1739. struct radeon_crtc *radeon_crtc,
  1740. struct drm_display_mode *mode,
  1741. struct drm_display_mode *other_mode)
  1742. {
  1743. u32 tmp, buffer_alloc, i;
  1744. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1745. /*
  1746. * Line Buffer Setup
  1747. * There are 3 line buffers, each one shared by 2 display controllers.
  1748. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1749. * the display controllers. The paritioning is done via one of four
  1750. * preset allocations specified in bits 2:0:
  1751. * first display controller
  1752. * 0 - first half of lb (3840 * 2)
  1753. * 1 - first 3/4 of lb (5760 * 2)
  1754. * 2 - whole lb (7680 * 2), other crtc must be disabled
  1755. * 3 - first 1/4 of lb (1920 * 2)
  1756. * second display controller
  1757. * 4 - second half of lb (3840 * 2)
  1758. * 5 - second 3/4 of lb (5760 * 2)
  1759. * 6 - whole lb (7680 * 2), other crtc must be disabled
  1760. * 7 - last 1/4 of lb (1920 * 2)
  1761. */
  1762. /* this can get tricky if we have two large displays on a paired group
  1763. * of crtcs. Ideally for multiple large displays we'd assign them to
  1764. * non-linked crtcs for maximum line buffer allocation.
  1765. */
  1766. if (radeon_crtc->base.enabled && mode) {
  1767. if (other_mode) {
  1768. tmp = 0; /* 1/2 */
  1769. buffer_alloc = 1;
  1770. } else {
  1771. tmp = 2; /* whole */
  1772. buffer_alloc = 2;
  1773. }
  1774. } else {
  1775. tmp = 0;
  1776. buffer_alloc = 0;
  1777. }
  1778. /* second controller of the pair uses second half of the lb */
  1779. if (radeon_crtc->crtc_id % 2)
  1780. tmp += 4;
  1781. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
  1782. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1783. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1784. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1785. for (i = 0; i < rdev->usec_timeout; i++) {
  1786. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1787. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1788. break;
  1789. udelay(1);
  1790. }
  1791. }
  1792. if (radeon_crtc->base.enabled && mode) {
  1793. switch (tmp) {
  1794. case 0:
  1795. case 4:
  1796. default:
  1797. if (ASIC_IS_DCE5(rdev))
  1798. return 4096 * 2;
  1799. else
  1800. return 3840 * 2;
  1801. case 1:
  1802. case 5:
  1803. if (ASIC_IS_DCE5(rdev))
  1804. return 6144 * 2;
  1805. else
  1806. return 5760 * 2;
  1807. case 2:
  1808. case 6:
  1809. if (ASIC_IS_DCE5(rdev))
  1810. return 8192 * 2;
  1811. else
  1812. return 7680 * 2;
  1813. case 3:
  1814. case 7:
  1815. if (ASIC_IS_DCE5(rdev))
  1816. return 2048 * 2;
  1817. else
  1818. return 1920 * 2;
  1819. }
  1820. }
  1821. /* controller not enabled, so no lb used */
  1822. return 0;
  1823. }
  1824. u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
  1825. {
  1826. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1827. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1828. case 0:
  1829. default:
  1830. return 1;
  1831. case 1:
  1832. return 2;
  1833. case 2:
  1834. return 4;
  1835. case 3:
  1836. return 8;
  1837. }
  1838. }
  1839. struct evergreen_wm_params {
  1840. u32 dram_channels; /* number of dram channels */
  1841. u32 yclk; /* bandwidth per dram data pin in kHz */
  1842. u32 sclk; /* engine clock in kHz */
  1843. u32 disp_clk; /* display clock in kHz */
  1844. u32 src_width; /* viewport width */
  1845. u32 active_time; /* active display time in ns */
  1846. u32 blank_time; /* blank time in ns */
  1847. bool interlaced; /* mode is interlaced */
  1848. fixed20_12 vsc; /* vertical scale ratio */
  1849. u32 num_heads; /* number of active crtcs */
  1850. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1851. u32 lb_size; /* line buffer allocated to pipe */
  1852. u32 vtaps; /* vertical scaler taps */
  1853. };
  1854. static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
  1855. {
  1856. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1857. fixed20_12 dram_efficiency; /* 0.7 */
  1858. fixed20_12 yclk, dram_channels, bandwidth;
  1859. fixed20_12 a;
  1860. a.full = dfixed_const(1000);
  1861. yclk.full = dfixed_const(wm->yclk);
  1862. yclk.full = dfixed_div(yclk, a);
  1863. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1864. a.full = dfixed_const(10);
  1865. dram_efficiency.full = dfixed_const(7);
  1866. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1867. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1868. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1869. return dfixed_trunc(bandwidth);
  1870. }
  1871. static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  1872. {
  1873. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1874. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1875. fixed20_12 yclk, dram_channels, bandwidth;
  1876. fixed20_12 a;
  1877. a.full = dfixed_const(1000);
  1878. yclk.full = dfixed_const(wm->yclk);
  1879. yclk.full = dfixed_div(yclk, a);
  1880. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1881. a.full = dfixed_const(10);
  1882. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1883. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1884. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1885. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1886. return dfixed_trunc(bandwidth);
  1887. }
  1888. static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
  1889. {
  1890. /* Calculate the display Data return Bandwidth */
  1891. fixed20_12 return_efficiency; /* 0.8 */
  1892. fixed20_12 sclk, bandwidth;
  1893. fixed20_12 a;
  1894. a.full = dfixed_const(1000);
  1895. sclk.full = dfixed_const(wm->sclk);
  1896. sclk.full = dfixed_div(sclk, a);
  1897. a.full = dfixed_const(10);
  1898. return_efficiency.full = dfixed_const(8);
  1899. return_efficiency.full = dfixed_div(return_efficiency, a);
  1900. a.full = dfixed_const(32);
  1901. bandwidth.full = dfixed_mul(a, sclk);
  1902. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1903. return dfixed_trunc(bandwidth);
  1904. }
  1905. static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
  1906. {
  1907. /* Calculate the DMIF Request Bandwidth */
  1908. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1909. fixed20_12 disp_clk, bandwidth;
  1910. fixed20_12 a;
  1911. a.full = dfixed_const(1000);
  1912. disp_clk.full = dfixed_const(wm->disp_clk);
  1913. disp_clk.full = dfixed_div(disp_clk, a);
  1914. a.full = dfixed_const(10);
  1915. disp_clk_request_efficiency.full = dfixed_const(8);
  1916. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1917. a.full = dfixed_const(32);
  1918. bandwidth.full = dfixed_mul(a, disp_clk);
  1919. bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
  1920. return dfixed_trunc(bandwidth);
  1921. }
  1922. static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
  1923. {
  1924. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1925. u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
  1926. u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
  1927. u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
  1928. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1929. }
  1930. static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
  1931. {
  1932. /* Calculate the display mode Average Bandwidth
  1933. * DisplayMode should contain the source and destination dimensions,
  1934. * timing, etc.
  1935. */
  1936. fixed20_12 bpp;
  1937. fixed20_12 line_time;
  1938. fixed20_12 src_width;
  1939. fixed20_12 bandwidth;
  1940. fixed20_12 a;
  1941. a.full = dfixed_const(1000);
  1942. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1943. line_time.full = dfixed_div(line_time, a);
  1944. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1945. src_width.full = dfixed_const(wm->src_width);
  1946. bandwidth.full = dfixed_mul(src_width, bpp);
  1947. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1948. bandwidth.full = dfixed_div(bandwidth, line_time);
  1949. return dfixed_trunc(bandwidth);
  1950. }
  1951. static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
  1952. {
  1953. /* First calcualte the latency in ns */
  1954. u32 mc_latency = 2000; /* 2000 ns. */
  1955. u32 available_bandwidth = evergreen_available_bandwidth(wm);
  1956. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1957. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1958. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1959. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1960. (wm->num_heads * cursor_line_pair_return_time);
  1961. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1962. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1963. fixed20_12 a, b, c;
  1964. if (wm->num_heads == 0)
  1965. return 0;
  1966. a.full = dfixed_const(2);
  1967. b.full = dfixed_const(1);
  1968. if ((wm->vsc.full > a.full) ||
  1969. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1970. (wm->vtaps >= 5) ||
  1971. ((wm->vsc.full >= a.full) && wm->interlaced))
  1972. max_src_lines_per_dst_line = 4;
  1973. else
  1974. max_src_lines_per_dst_line = 2;
  1975. a.full = dfixed_const(available_bandwidth);
  1976. b.full = dfixed_const(wm->num_heads);
  1977. a.full = dfixed_div(a, b);
  1978. b.full = dfixed_const(1000);
  1979. c.full = dfixed_const(wm->disp_clk);
  1980. b.full = dfixed_div(c, b);
  1981. c.full = dfixed_const(wm->bytes_per_pixel);
  1982. b.full = dfixed_mul(b, c);
  1983. lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
  1984. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1985. b.full = dfixed_const(1000);
  1986. c.full = dfixed_const(lb_fill_bw);
  1987. b.full = dfixed_div(c, b);
  1988. a.full = dfixed_div(a, b);
  1989. line_fill_time = dfixed_trunc(a);
  1990. if (line_fill_time < wm->active_time)
  1991. return latency;
  1992. else
  1993. return latency + (line_fill_time - wm->active_time);
  1994. }
  1995. static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  1996. {
  1997. if (evergreen_average_bandwidth(wm) <=
  1998. (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
  1999. return true;
  2000. else
  2001. return false;
  2002. };
  2003. static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
  2004. {
  2005. if (evergreen_average_bandwidth(wm) <=
  2006. (evergreen_available_bandwidth(wm) / wm->num_heads))
  2007. return true;
  2008. else
  2009. return false;
  2010. };
  2011. static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
  2012. {
  2013. u32 lb_partitions = wm->lb_size / wm->src_width;
  2014. u32 line_time = wm->active_time + wm->blank_time;
  2015. u32 latency_tolerant_lines;
  2016. u32 latency_hiding;
  2017. fixed20_12 a;
  2018. a.full = dfixed_const(1);
  2019. if (wm->vsc.full > a.full)
  2020. latency_tolerant_lines = 1;
  2021. else {
  2022. if (lb_partitions <= (wm->vtaps + 1))
  2023. latency_tolerant_lines = 1;
  2024. else
  2025. latency_tolerant_lines = 2;
  2026. }
  2027. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  2028. if (evergreen_latency_watermark(wm) <= latency_hiding)
  2029. return true;
  2030. else
  2031. return false;
  2032. }
  2033. static void evergreen_program_watermarks(struct radeon_device *rdev,
  2034. struct radeon_crtc *radeon_crtc,
  2035. u32 lb_size, u32 num_heads)
  2036. {
  2037. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  2038. struct evergreen_wm_params wm_low, wm_high;
  2039. u32 dram_channels;
  2040. u32 pixel_period;
  2041. u32 line_time = 0;
  2042. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  2043. u32 priority_a_mark = 0, priority_b_mark = 0;
  2044. u32 priority_a_cnt = PRIORITY_OFF;
  2045. u32 priority_b_cnt = PRIORITY_OFF;
  2046. u32 pipe_offset = radeon_crtc->crtc_id * 16;
  2047. u32 tmp, arb_control3;
  2048. fixed20_12 a, b, c;
  2049. if (radeon_crtc->base.enabled && num_heads && mode) {
  2050. pixel_period = 1000000 / (u32)mode->clock;
  2051. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  2052. priority_a_cnt = 0;
  2053. priority_b_cnt = 0;
  2054. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  2055. /* watermark for high clocks */
  2056. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2057. wm_high.yclk =
  2058. radeon_dpm_get_mclk(rdev, false) * 10;
  2059. wm_high.sclk =
  2060. radeon_dpm_get_sclk(rdev, false) * 10;
  2061. } else {
  2062. wm_high.yclk = rdev->pm.current_mclk * 10;
  2063. wm_high.sclk = rdev->pm.current_sclk * 10;
  2064. }
  2065. wm_high.disp_clk = mode->clock;
  2066. wm_high.src_width = mode->crtc_hdisplay;
  2067. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  2068. wm_high.blank_time = line_time - wm_high.active_time;
  2069. wm_high.interlaced = false;
  2070. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2071. wm_high.interlaced = true;
  2072. wm_high.vsc = radeon_crtc->vsc;
  2073. wm_high.vtaps = 1;
  2074. if (radeon_crtc->rmx_type != RMX_OFF)
  2075. wm_high.vtaps = 2;
  2076. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2077. wm_high.lb_size = lb_size;
  2078. wm_high.dram_channels = dram_channels;
  2079. wm_high.num_heads = num_heads;
  2080. /* watermark for low clocks */
  2081. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2082. wm_low.yclk =
  2083. radeon_dpm_get_mclk(rdev, true) * 10;
  2084. wm_low.sclk =
  2085. radeon_dpm_get_sclk(rdev, true) * 10;
  2086. } else {
  2087. wm_low.yclk = rdev->pm.current_mclk * 10;
  2088. wm_low.sclk = rdev->pm.current_sclk * 10;
  2089. }
  2090. wm_low.disp_clk = mode->clock;
  2091. wm_low.src_width = mode->crtc_hdisplay;
  2092. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2093. wm_low.blank_time = line_time - wm_low.active_time;
  2094. wm_low.interlaced = false;
  2095. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2096. wm_low.interlaced = true;
  2097. wm_low.vsc = radeon_crtc->vsc;
  2098. wm_low.vtaps = 1;
  2099. if (radeon_crtc->rmx_type != RMX_OFF)
  2100. wm_low.vtaps = 2;
  2101. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2102. wm_low.lb_size = lb_size;
  2103. wm_low.dram_channels = dram_channels;
  2104. wm_low.num_heads = num_heads;
  2105. /* set for high clocks */
  2106. latency_watermark_a = min(evergreen_latency_watermark(&wm_high), (u32)65535);
  2107. /* set for low clocks */
  2108. latency_watermark_b = min(evergreen_latency_watermark(&wm_low), (u32)65535);
  2109. /* possibly force display priority to high */
  2110. /* should really do this at mode validation time... */
  2111. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2112. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2113. !evergreen_check_latency_hiding(&wm_high) ||
  2114. (rdev->disp_priority == 2)) {
  2115. DRM_DEBUG_KMS("force priority a to high\n");
  2116. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2117. }
  2118. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2119. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2120. !evergreen_check_latency_hiding(&wm_low) ||
  2121. (rdev->disp_priority == 2)) {
  2122. DRM_DEBUG_KMS("force priority b to high\n");
  2123. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2124. }
  2125. a.full = dfixed_const(1000);
  2126. b.full = dfixed_const(mode->clock);
  2127. b.full = dfixed_div(b, a);
  2128. c.full = dfixed_const(latency_watermark_a);
  2129. c.full = dfixed_mul(c, b);
  2130. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2131. c.full = dfixed_div(c, a);
  2132. a.full = dfixed_const(16);
  2133. c.full = dfixed_div(c, a);
  2134. priority_a_mark = dfixed_trunc(c);
  2135. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2136. a.full = dfixed_const(1000);
  2137. b.full = dfixed_const(mode->clock);
  2138. b.full = dfixed_div(b, a);
  2139. c.full = dfixed_const(latency_watermark_b);
  2140. c.full = dfixed_mul(c, b);
  2141. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2142. c.full = dfixed_div(c, a);
  2143. a.full = dfixed_const(16);
  2144. c.full = dfixed_div(c, a);
  2145. priority_b_mark = dfixed_trunc(c);
  2146. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2147. }
  2148. /* select wm A */
  2149. arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2150. tmp = arb_control3;
  2151. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2152. tmp |= LATENCY_WATERMARK_MASK(1);
  2153. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2154. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2155. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2156. LATENCY_HIGH_WATERMARK(line_time)));
  2157. /* select wm B */
  2158. tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2159. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2160. tmp |= LATENCY_WATERMARK_MASK(2);
  2161. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2162. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2163. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2164. LATENCY_HIGH_WATERMARK(line_time)));
  2165. /* restore original selection */
  2166. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
  2167. /* write the priority marks */
  2168. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2169. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2170. /* save values for DPM */
  2171. radeon_crtc->line_time = line_time;
  2172. radeon_crtc->wm_high = latency_watermark_a;
  2173. radeon_crtc->wm_low = latency_watermark_b;
  2174. }
  2175. /**
  2176. * evergreen_bandwidth_update - update display watermarks callback.
  2177. *
  2178. * @rdev: radeon_device pointer
  2179. *
  2180. * Update the display watermarks based on the requested mode(s)
  2181. * (evergreen+).
  2182. */
  2183. void evergreen_bandwidth_update(struct radeon_device *rdev)
  2184. {
  2185. struct drm_display_mode *mode0 = NULL;
  2186. struct drm_display_mode *mode1 = NULL;
  2187. u32 num_heads = 0, lb_size;
  2188. int i;
  2189. radeon_update_display_priority(rdev);
  2190. for (i = 0; i < rdev->num_crtc; i++) {
  2191. if (rdev->mode_info.crtcs[i]->base.enabled)
  2192. num_heads++;
  2193. }
  2194. for (i = 0; i < rdev->num_crtc; i += 2) {
  2195. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2196. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2197. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2198. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2199. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2200. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2201. }
  2202. }
  2203. /**
  2204. * evergreen_mc_wait_for_idle - wait for MC idle callback.
  2205. *
  2206. * @rdev: radeon_device pointer
  2207. *
  2208. * Wait for the MC (memory controller) to be idle.
  2209. * (evergreen+).
  2210. * Returns 0 if the MC is idle, -1 if not.
  2211. */
  2212. int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
  2213. {
  2214. unsigned i;
  2215. u32 tmp;
  2216. for (i = 0; i < rdev->usec_timeout; i++) {
  2217. /* read MC_STATUS */
  2218. tmp = RREG32(SRBM_STATUS) & 0x1F00;
  2219. if (!tmp)
  2220. return 0;
  2221. udelay(1);
  2222. }
  2223. return -1;
  2224. }
  2225. /*
  2226. * GART
  2227. */
  2228. void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
  2229. {
  2230. unsigned i;
  2231. u32 tmp;
  2232. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2233. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  2234. for (i = 0; i < rdev->usec_timeout; i++) {
  2235. /* read MC_STATUS */
  2236. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  2237. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  2238. if (tmp == 2) {
  2239. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  2240. return;
  2241. }
  2242. if (tmp) {
  2243. return;
  2244. }
  2245. udelay(1);
  2246. }
  2247. }
  2248. static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
  2249. {
  2250. u32 tmp;
  2251. int r;
  2252. if (rdev->gart.robj == NULL) {
  2253. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  2254. return -EINVAL;
  2255. }
  2256. r = radeon_gart_table_vram_pin(rdev);
  2257. if (r)
  2258. return r;
  2259. radeon_gart_restore(rdev);
  2260. /* Setup L2 cache */
  2261. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2262. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2263. EFFECTIVE_L2_QUEUE_SIZE(7));
  2264. WREG32(VM_L2_CNTL2, 0);
  2265. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2266. /* Setup TLB control */
  2267. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2268. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2269. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2270. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2271. if (rdev->flags & RADEON_IS_IGP) {
  2272. WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
  2273. WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
  2274. WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
  2275. } else {
  2276. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2277. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2278. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2279. if ((rdev->family == CHIP_JUNIPER) ||
  2280. (rdev->family == CHIP_CYPRESS) ||
  2281. (rdev->family == CHIP_HEMLOCK) ||
  2282. (rdev->family == CHIP_BARTS))
  2283. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  2284. }
  2285. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2286. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2287. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2288. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2289. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  2290. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  2291. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  2292. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  2293. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  2294. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  2295. (u32)(rdev->dummy_page.addr >> 12));
  2296. WREG32(VM_CONTEXT1_CNTL, 0);
  2297. evergreen_pcie_gart_tlb_flush(rdev);
  2298. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  2299. (unsigned)(rdev->mc.gtt_size >> 20),
  2300. (unsigned long long)rdev->gart.table_addr);
  2301. rdev->gart.ready = true;
  2302. return 0;
  2303. }
  2304. static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
  2305. {
  2306. u32 tmp;
  2307. /* Disable all tables */
  2308. WREG32(VM_CONTEXT0_CNTL, 0);
  2309. WREG32(VM_CONTEXT1_CNTL, 0);
  2310. /* Setup L2 cache */
  2311. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  2312. EFFECTIVE_L2_QUEUE_SIZE(7));
  2313. WREG32(VM_L2_CNTL2, 0);
  2314. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2315. /* Setup TLB control */
  2316. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2317. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2318. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2319. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2320. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2321. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2322. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2323. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2324. radeon_gart_table_vram_unpin(rdev);
  2325. }
  2326. static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
  2327. {
  2328. evergreen_pcie_gart_disable(rdev);
  2329. radeon_gart_table_vram_free(rdev);
  2330. radeon_gart_fini(rdev);
  2331. }
  2332. static void evergreen_agp_enable(struct radeon_device *rdev)
  2333. {
  2334. u32 tmp;
  2335. /* Setup L2 cache */
  2336. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2337. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2338. EFFECTIVE_L2_QUEUE_SIZE(7));
  2339. WREG32(VM_L2_CNTL2, 0);
  2340. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2341. /* Setup TLB control */
  2342. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2343. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2344. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2345. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2346. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2347. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2348. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2349. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2350. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2351. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2352. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2353. WREG32(VM_CONTEXT0_CNTL, 0);
  2354. WREG32(VM_CONTEXT1_CNTL, 0);
  2355. }
  2356. void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2357. {
  2358. u32 crtc_enabled, tmp, frame_count, blackout;
  2359. int i, j;
  2360. if (!ASIC_IS_NODCE(rdev)) {
  2361. save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
  2362. save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
  2363. /* disable VGA render */
  2364. WREG32(VGA_RENDER_CONTROL, 0);
  2365. }
  2366. /* blank the display controllers */
  2367. for (i = 0; i < rdev->num_crtc; i++) {
  2368. crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
  2369. if (crtc_enabled) {
  2370. save->crtc_enabled[i] = true;
  2371. if (ASIC_IS_DCE6(rdev)) {
  2372. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2373. if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
  2374. radeon_wait_for_vblank(rdev, i);
  2375. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2376. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  2377. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2378. }
  2379. } else {
  2380. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2381. if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
  2382. radeon_wait_for_vblank(rdev, i);
  2383. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2384. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2385. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2386. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2387. }
  2388. }
  2389. /* wait for the next frame */
  2390. frame_count = radeon_get_vblank_counter(rdev, i);
  2391. for (j = 0; j < rdev->usec_timeout; j++) {
  2392. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2393. break;
  2394. udelay(1);
  2395. }
  2396. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  2397. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2398. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2399. tmp &= ~EVERGREEN_CRTC_MASTER_EN;
  2400. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2401. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2402. save->crtc_enabled[i] = false;
  2403. /* ***** */
  2404. } else {
  2405. save->crtc_enabled[i] = false;
  2406. }
  2407. }
  2408. radeon_mc_wait_for_idle(rdev);
  2409. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2410. if ((blackout & BLACKOUT_MODE_MASK) != 1) {
  2411. /* Block CPU access */
  2412. WREG32(BIF_FB_EN, 0);
  2413. /* blackout the MC */
  2414. blackout &= ~BLACKOUT_MODE_MASK;
  2415. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  2416. }
  2417. /* wait for the MC to settle */
  2418. udelay(100);
  2419. /* lock double buffered regs */
  2420. for (i = 0; i < rdev->num_crtc; i++) {
  2421. if (save->crtc_enabled[i]) {
  2422. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2423. if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
  2424. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  2425. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2426. }
  2427. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2428. if (!(tmp & 1)) {
  2429. tmp |= 1;
  2430. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2431. }
  2432. }
  2433. }
  2434. }
  2435. void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2436. {
  2437. u32 tmp, frame_count;
  2438. int i, j;
  2439. /* update crtc base addresses */
  2440. for (i = 0; i < rdev->num_crtc; i++) {
  2441. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2442. upper_32_bits(rdev->mc.vram_start));
  2443. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2444. upper_32_bits(rdev->mc.vram_start));
  2445. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  2446. (u32)rdev->mc.vram_start);
  2447. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  2448. (u32)rdev->mc.vram_start);
  2449. }
  2450. if (!ASIC_IS_NODCE(rdev)) {
  2451. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
  2452. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
  2453. }
  2454. /* unlock regs and wait for update */
  2455. for (i = 0; i < rdev->num_crtc; i++) {
  2456. if (save->crtc_enabled[i]) {
  2457. tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
  2458. if ((tmp & 0x3) != 0) {
  2459. tmp &= ~0x3;
  2460. WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  2461. }
  2462. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2463. if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
  2464. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  2465. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2466. }
  2467. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2468. if (tmp & 1) {
  2469. tmp &= ~1;
  2470. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2471. }
  2472. for (j = 0; j < rdev->usec_timeout; j++) {
  2473. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2474. if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
  2475. break;
  2476. udelay(1);
  2477. }
  2478. }
  2479. }
  2480. /* unblackout the MC */
  2481. tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2482. tmp &= ~BLACKOUT_MODE_MASK;
  2483. WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
  2484. /* allow CPU access */
  2485. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2486. for (i = 0; i < rdev->num_crtc; i++) {
  2487. if (save->crtc_enabled[i]) {
  2488. if (ASIC_IS_DCE6(rdev)) {
  2489. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2490. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  2491. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2492. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2493. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2494. } else {
  2495. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2496. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2497. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2498. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2499. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2500. }
  2501. /* wait for the next frame */
  2502. frame_count = radeon_get_vblank_counter(rdev, i);
  2503. for (j = 0; j < rdev->usec_timeout; j++) {
  2504. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2505. break;
  2506. udelay(1);
  2507. }
  2508. }
  2509. }
  2510. if (!ASIC_IS_NODCE(rdev)) {
  2511. /* Unlock vga access */
  2512. WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
  2513. mdelay(1);
  2514. WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
  2515. }
  2516. }
  2517. void evergreen_mc_program(struct radeon_device *rdev)
  2518. {
  2519. struct evergreen_mc_save save;
  2520. u32 tmp;
  2521. int i, j;
  2522. /* Initialize HDP */
  2523. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2524. WREG32((0x2c14 + j), 0x00000000);
  2525. WREG32((0x2c18 + j), 0x00000000);
  2526. WREG32((0x2c1c + j), 0x00000000);
  2527. WREG32((0x2c20 + j), 0x00000000);
  2528. WREG32((0x2c24 + j), 0x00000000);
  2529. }
  2530. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  2531. evergreen_mc_stop(rdev, &save);
  2532. if (evergreen_mc_wait_for_idle(rdev)) {
  2533. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2534. }
  2535. /* Lockout access through VGA aperture*/
  2536. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  2537. /* Update configuration */
  2538. if (rdev->flags & RADEON_IS_AGP) {
  2539. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  2540. /* VRAM before AGP */
  2541. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2542. rdev->mc.vram_start >> 12);
  2543. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2544. rdev->mc.gtt_end >> 12);
  2545. } else {
  2546. /* VRAM after AGP */
  2547. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2548. rdev->mc.gtt_start >> 12);
  2549. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2550. rdev->mc.vram_end >> 12);
  2551. }
  2552. } else {
  2553. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2554. rdev->mc.vram_start >> 12);
  2555. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2556. rdev->mc.vram_end >> 12);
  2557. }
  2558. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  2559. /* llano/ontario only */
  2560. if ((rdev->family == CHIP_PALM) ||
  2561. (rdev->family == CHIP_SUMO) ||
  2562. (rdev->family == CHIP_SUMO2)) {
  2563. tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
  2564. tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
  2565. tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
  2566. WREG32(MC_FUS_VM_FB_OFFSET, tmp);
  2567. }
  2568. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  2569. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  2570. WREG32(MC_VM_FB_LOCATION, tmp);
  2571. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  2572. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  2573. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  2574. if (rdev->flags & RADEON_IS_AGP) {
  2575. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  2576. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  2577. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  2578. } else {
  2579. WREG32(MC_VM_AGP_BASE, 0);
  2580. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  2581. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  2582. }
  2583. if (evergreen_mc_wait_for_idle(rdev)) {
  2584. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2585. }
  2586. evergreen_mc_resume(rdev, &save);
  2587. /* we need to own VRAM, so turn off the VGA renderer here
  2588. * to stop it overwriting our objects */
  2589. rv515_vga_render_disable(rdev);
  2590. }
  2591. /*
  2592. * CP.
  2593. */
  2594. void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2595. {
  2596. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2597. u32 next_rptr;
  2598. /* set to DX10/11 mode */
  2599. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  2600. radeon_ring_write(ring, 1);
  2601. if (ring->rptr_save_reg) {
  2602. next_rptr = ring->wptr + 3 + 4;
  2603. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2604. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2605. PACKET3_SET_CONFIG_REG_START) >> 2));
  2606. radeon_ring_write(ring, next_rptr);
  2607. } else if (rdev->wb.enabled) {
  2608. next_rptr = ring->wptr + 5 + 4;
  2609. radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
  2610. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2611. radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
  2612. radeon_ring_write(ring, next_rptr);
  2613. radeon_ring_write(ring, 0);
  2614. }
  2615. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2616. radeon_ring_write(ring,
  2617. #ifdef __BIG_ENDIAN
  2618. (2 << 0) |
  2619. #endif
  2620. (ib->gpu_addr & 0xFFFFFFFC));
  2621. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  2622. radeon_ring_write(ring, ib->length_dw);
  2623. }
  2624. static int evergreen_cp_load_microcode(struct radeon_device *rdev)
  2625. {
  2626. const __be32 *fw_data;
  2627. int i;
  2628. if (!rdev->me_fw || !rdev->pfp_fw)
  2629. return -EINVAL;
  2630. r700_cp_stop(rdev);
  2631. WREG32(CP_RB_CNTL,
  2632. #ifdef __BIG_ENDIAN
  2633. BUF_SWAP_32BIT |
  2634. #endif
  2635. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  2636. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2637. WREG32(CP_PFP_UCODE_ADDR, 0);
  2638. for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
  2639. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2640. WREG32(CP_PFP_UCODE_ADDR, 0);
  2641. fw_data = (const __be32 *)rdev->me_fw->data;
  2642. WREG32(CP_ME_RAM_WADDR, 0);
  2643. for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
  2644. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2645. WREG32(CP_PFP_UCODE_ADDR, 0);
  2646. WREG32(CP_ME_RAM_WADDR, 0);
  2647. WREG32(CP_ME_RAM_RADDR, 0);
  2648. return 0;
  2649. }
  2650. static int evergreen_cp_start(struct radeon_device *rdev)
  2651. {
  2652. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2653. int r, i;
  2654. uint32_t cp_me;
  2655. r = radeon_ring_lock(rdev, ring, 7);
  2656. if (r) {
  2657. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2658. return r;
  2659. }
  2660. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2661. radeon_ring_write(ring, 0x1);
  2662. radeon_ring_write(ring, 0x0);
  2663. radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
  2664. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2665. radeon_ring_write(ring, 0);
  2666. radeon_ring_write(ring, 0);
  2667. radeon_ring_unlock_commit(rdev, ring);
  2668. cp_me = 0xff;
  2669. WREG32(CP_ME_CNTL, cp_me);
  2670. r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
  2671. if (r) {
  2672. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2673. return r;
  2674. }
  2675. /* setup clear context state */
  2676. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2677. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2678. for (i = 0; i < evergreen_default_size; i++)
  2679. radeon_ring_write(ring, evergreen_default_state[i]);
  2680. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2681. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2682. /* set clear context state */
  2683. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2684. radeon_ring_write(ring, 0);
  2685. /* SQ_VTX_BASE_VTX_LOC */
  2686. radeon_ring_write(ring, 0xc0026f00);
  2687. radeon_ring_write(ring, 0x00000000);
  2688. radeon_ring_write(ring, 0x00000000);
  2689. radeon_ring_write(ring, 0x00000000);
  2690. /* Clear consts */
  2691. radeon_ring_write(ring, 0xc0036f00);
  2692. radeon_ring_write(ring, 0x00000bc4);
  2693. radeon_ring_write(ring, 0xffffffff);
  2694. radeon_ring_write(ring, 0xffffffff);
  2695. radeon_ring_write(ring, 0xffffffff);
  2696. radeon_ring_write(ring, 0xc0026900);
  2697. radeon_ring_write(ring, 0x00000316);
  2698. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2699. radeon_ring_write(ring, 0x00000010); /* */
  2700. radeon_ring_unlock_commit(rdev, ring);
  2701. return 0;
  2702. }
  2703. static int evergreen_cp_resume(struct radeon_device *rdev)
  2704. {
  2705. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2706. u32 tmp;
  2707. u32 rb_bufsz;
  2708. int r;
  2709. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2710. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2711. SOFT_RESET_PA |
  2712. SOFT_RESET_SH |
  2713. SOFT_RESET_VGT |
  2714. SOFT_RESET_SPI |
  2715. SOFT_RESET_SX));
  2716. RREG32(GRBM_SOFT_RESET);
  2717. mdelay(15);
  2718. WREG32(GRBM_SOFT_RESET, 0);
  2719. RREG32(GRBM_SOFT_RESET);
  2720. /* Set ring buffer size */
  2721. rb_bufsz = order_base_2(ring->ring_size / 8);
  2722. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2723. #ifdef __BIG_ENDIAN
  2724. tmp |= BUF_SWAP_32BIT;
  2725. #endif
  2726. WREG32(CP_RB_CNTL, tmp);
  2727. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2728. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2729. /* Set the write pointer delay */
  2730. WREG32(CP_RB_WPTR_DELAY, 0);
  2731. /* Initialize the ring buffer's read and write pointers */
  2732. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2733. WREG32(CP_RB_RPTR_WR, 0);
  2734. ring->wptr = 0;
  2735. WREG32(CP_RB_WPTR, ring->wptr);
  2736. /* set the wb address whether it's enabled or not */
  2737. WREG32(CP_RB_RPTR_ADDR,
  2738. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2739. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2740. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2741. if (rdev->wb.enabled)
  2742. WREG32(SCRATCH_UMSK, 0xff);
  2743. else {
  2744. tmp |= RB_NO_UPDATE;
  2745. WREG32(SCRATCH_UMSK, 0);
  2746. }
  2747. mdelay(1);
  2748. WREG32(CP_RB_CNTL, tmp);
  2749. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2750. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2751. evergreen_cp_start(rdev);
  2752. ring->ready = true;
  2753. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2754. if (r) {
  2755. ring->ready = false;
  2756. return r;
  2757. }
  2758. return 0;
  2759. }
  2760. /*
  2761. * Core functions
  2762. */
  2763. static void evergreen_gpu_init(struct radeon_device *rdev)
  2764. {
  2765. u32 gb_addr_config;
  2766. u32 mc_shared_chmap, mc_arb_ramcfg;
  2767. u32 sx_debug_1;
  2768. u32 smx_dc_ctl0;
  2769. u32 sq_config;
  2770. u32 sq_lds_resource_mgmt;
  2771. u32 sq_gpr_resource_mgmt_1;
  2772. u32 sq_gpr_resource_mgmt_2;
  2773. u32 sq_gpr_resource_mgmt_3;
  2774. u32 sq_thread_resource_mgmt;
  2775. u32 sq_thread_resource_mgmt_2;
  2776. u32 sq_stack_resource_mgmt_1;
  2777. u32 sq_stack_resource_mgmt_2;
  2778. u32 sq_stack_resource_mgmt_3;
  2779. u32 vgt_cache_invalidation;
  2780. u32 hdp_host_path_cntl, tmp;
  2781. u32 disabled_rb_mask;
  2782. int i, j, num_shader_engines, ps_thread_count;
  2783. switch (rdev->family) {
  2784. case CHIP_CYPRESS:
  2785. case CHIP_HEMLOCK:
  2786. rdev->config.evergreen.num_ses = 2;
  2787. rdev->config.evergreen.max_pipes = 4;
  2788. rdev->config.evergreen.max_tile_pipes = 8;
  2789. rdev->config.evergreen.max_simds = 10;
  2790. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2791. rdev->config.evergreen.max_gprs = 256;
  2792. rdev->config.evergreen.max_threads = 248;
  2793. rdev->config.evergreen.max_gs_threads = 32;
  2794. rdev->config.evergreen.max_stack_entries = 512;
  2795. rdev->config.evergreen.sx_num_of_sets = 4;
  2796. rdev->config.evergreen.sx_max_export_size = 256;
  2797. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2798. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2799. rdev->config.evergreen.max_hw_contexts = 8;
  2800. rdev->config.evergreen.sq_num_cf_insts = 2;
  2801. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2802. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2803. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2804. gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
  2805. break;
  2806. case CHIP_JUNIPER:
  2807. rdev->config.evergreen.num_ses = 1;
  2808. rdev->config.evergreen.max_pipes = 4;
  2809. rdev->config.evergreen.max_tile_pipes = 4;
  2810. rdev->config.evergreen.max_simds = 10;
  2811. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2812. rdev->config.evergreen.max_gprs = 256;
  2813. rdev->config.evergreen.max_threads = 248;
  2814. rdev->config.evergreen.max_gs_threads = 32;
  2815. rdev->config.evergreen.max_stack_entries = 512;
  2816. rdev->config.evergreen.sx_num_of_sets = 4;
  2817. rdev->config.evergreen.sx_max_export_size = 256;
  2818. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2819. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2820. rdev->config.evergreen.max_hw_contexts = 8;
  2821. rdev->config.evergreen.sq_num_cf_insts = 2;
  2822. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2823. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2824. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2825. gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
  2826. break;
  2827. case CHIP_REDWOOD:
  2828. rdev->config.evergreen.num_ses = 1;
  2829. rdev->config.evergreen.max_pipes = 4;
  2830. rdev->config.evergreen.max_tile_pipes = 4;
  2831. rdev->config.evergreen.max_simds = 5;
  2832. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  2833. rdev->config.evergreen.max_gprs = 256;
  2834. rdev->config.evergreen.max_threads = 248;
  2835. rdev->config.evergreen.max_gs_threads = 32;
  2836. rdev->config.evergreen.max_stack_entries = 256;
  2837. rdev->config.evergreen.sx_num_of_sets = 4;
  2838. rdev->config.evergreen.sx_max_export_size = 256;
  2839. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2840. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2841. rdev->config.evergreen.max_hw_contexts = 8;
  2842. rdev->config.evergreen.sq_num_cf_insts = 2;
  2843. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2844. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2845. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2846. gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
  2847. break;
  2848. case CHIP_CEDAR:
  2849. default:
  2850. rdev->config.evergreen.num_ses = 1;
  2851. rdev->config.evergreen.max_pipes = 2;
  2852. rdev->config.evergreen.max_tile_pipes = 2;
  2853. rdev->config.evergreen.max_simds = 2;
  2854. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2855. rdev->config.evergreen.max_gprs = 256;
  2856. rdev->config.evergreen.max_threads = 192;
  2857. rdev->config.evergreen.max_gs_threads = 16;
  2858. rdev->config.evergreen.max_stack_entries = 256;
  2859. rdev->config.evergreen.sx_num_of_sets = 4;
  2860. rdev->config.evergreen.sx_max_export_size = 128;
  2861. rdev->config.evergreen.sx_max_export_pos_size = 32;
  2862. rdev->config.evergreen.sx_max_export_smx_size = 96;
  2863. rdev->config.evergreen.max_hw_contexts = 4;
  2864. rdev->config.evergreen.sq_num_cf_insts = 1;
  2865. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2866. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2867. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2868. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  2869. break;
  2870. case CHIP_PALM:
  2871. rdev->config.evergreen.num_ses = 1;
  2872. rdev->config.evergreen.max_pipes = 2;
  2873. rdev->config.evergreen.max_tile_pipes = 2;
  2874. rdev->config.evergreen.max_simds = 2;
  2875. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2876. rdev->config.evergreen.max_gprs = 256;
  2877. rdev->config.evergreen.max_threads = 192;
  2878. rdev->config.evergreen.max_gs_threads = 16;
  2879. rdev->config.evergreen.max_stack_entries = 256;
  2880. rdev->config.evergreen.sx_num_of_sets = 4;
  2881. rdev->config.evergreen.sx_max_export_size = 128;
  2882. rdev->config.evergreen.sx_max_export_pos_size = 32;
  2883. rdev->config.evergreen.sx_max_export_smx_size = 96;
  2884. rdev->config.evergreen.max_hw_contexts = 4;
  2885. rdev->config.evergreen.sq_num_cf_insts = 1;
  2886. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2887. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2888. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2889. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  2890. break;
  2891. case CHIP_SUMO:
  2892. rdev->config.evergreen.num_ses = 1;
  2893. rdev->config.evergreen.max_pipes = 4;
  2894. rdev->config.evergreen.max_tile_pipes = 4;
  2895. if (rdev->pdev->device == 0x9648)
  2896. rdev->config.evergreen.max_simds = 3;
  2897. else if ((rdev->pdev->device == 0x9647) ||
  2898. (rdev->pdev->device == 0x964a))
  2899. rdev->config.evergreen.max_simds = 4;
  2900. else
  2901. rdev->config.evergreen.max_simds = 5;
  2902. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  2903. rdev->config.evergreen.max_gprs = 256;
  2904. rdev->config.evergreen.max_threads = 248;
  2905. rdev->config.evergreen.max_gs_threads = 32;
  2906. rdev->config.evergreen.max_stack_entries = 256;
  2907. rdev->config.evergreen.sx_num_of_sets = 4;
  2908. rdev->config.evergreen.sx_max_export_size = 256;
  2909. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2910. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2911. rdev->config.evergreen.max_hw_contexts = 8;
  2912. rdev->config.evergreen.sq_num_cf_insts = 2;
  2913. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2914. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2915. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2916. gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
  2917. break;
  2918. case CHIP_SUMO2:
  2919. rdev->config.evergreen.num_ses = 1;
  2920. rdev->config.evergreen.max_pipes = 4;
  2921. rdev->config.evergreen.max_tile_pipes = 4;
  2922. rdev->config.evergreen.max_simds = 2;
  2923. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2924. rdev->config.evergreen.max_gprs = 256;
  2925. rdev->config.evergreen.max_threads = 248;
  2926. rdev->config.evergreen.max_gs_threads = 32;
  2927. rdev->config.evergreen.max_stack_entries = 512;
  2928. rdev->config.evergreen.sx_num_of_sets = 4;
  2929. rdev->config.evergreen.sx_max_export_size = 256;
  2930. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2931. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2932. rdev->config.evergreen.max_hw_contexts = 4;
  2933. rdev->config.evergreen.sq_num_cf_insts = 2;
  2934. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2935. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2936. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2937. gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
  2938. break;
  2939. case CHIP_BARTS:
  2940. rdev->config.evergreen.num_ses = 2;
  2941. rdev->config.evergreen.max_pipes = 4;
  2942. rdev->config.evergreen.max_tile_pipes = 8;
  2943. rdev->config.evergreen.max_simds = 7;
  2944. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2945. rdev->config.evergreen.max_gprs = 256;
  2946. rdev->config.evergreen.max_threads = 248;
  2947. rdev->config.evergreen.max_gs_threads = 32;
  2948. rdev->config.evergreen.max_stack_entries = 512;
  2949. rdev->config.evergreen.sx_num_of_sets = 4;
  2950. rdev->config.evergreen.sx_max_export_size = 256;
  2951. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2952. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2953. rdev->config.evergreen.max_hw_contexts = 8;
  2954. rdev->config.evergreen.sq_num_cf_insts = 2;
  2955. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2956. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2957. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2958. gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
  2959. break;
  2960. case CHIP_TURKS:
  2961. rdev->config.evergreen.num_ses = 1;
  2962. rdev->config.evergreen.max_pipes = 4;
  2963. rdev->config.evergreen.max_tile_pipes = 4;
  2964. rdev->config.evergreen.max_simds = 6;
  2965. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  2966. rdev->config.evergreen.max_gprs = 256;
  2967. rdev->config.evergreen.max_threads = 248;
  2968. rdev->config.evergreen.max_gs_threads = 32;
  2969. rdev->config.evergreen.max_stack_entries = 256;
  2970. rdev->config.evergreen.sx_num_of_sets = 4;
  2971. rdev->config.evergreen.sx_max_export_size = 256;
  2972. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2973. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2974. rdev->config.evergreen.max_hw_contexts = 8;
  2975. rdev->config.evergreen.sq_num_cf_insts = 2;
  2976. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2977. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2978. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2979. gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
  2980. break;
  2981. case CHIP_CAICOS:
  2982. rdev->config.evergreen.num_ses = 1;
  2983. rdev->config.evergreen.max_pipes = 2;
  2984. rdev->config.evergreen.max_tile_pipes = 2;
  2985. rdev->config.evergreen.max_simds = 2;
  2986. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2987. rdev->config.evergreen.max_gprs = 256;
  2988. rdev->config.evergreen.max_threads = 192;
  2989. rdev->config.evergreen.max_gs_threads = 16;
  2990. rdev->config.evergreen.max_stack_entries = 256;
  2991. rdev->config.evergreen.sx_num_of_sets = 4;
  2992. rdev->config.evergreen.sx_max_export_size = 128;
  2993. rdev->config.evergreen.sx_max_export_pos_size = 32;
  2994. rdev->config.evergreen.sx_max_export_smx_size = 96;
  2995. rdev->config.evergreen.max_hw_contexts = 4;
  2996. rdev->config.evergreen.sq_num_cf_insts = 1;
  2997. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2998. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2999. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3000. gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
  3001. break;
  3002. }
  3003. /* Initialize HDP */
  3004. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3005. WREG32((0x2c14 + j), 0x00000000);
  3006. WREG32((0x2c18 + j), 0x00000000);
  3007. WREG32((0x2c1c + j), 0x00000000);
  3008. WREG32((0x2c20 + j), 0x00000000);
  3009. WREG32((0x2c24 + j), 0x00000000);
  3010. }
  3011. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  3012. evergreen_fix_pci_max_read_req_size(rdev);
  3013. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  3014. if ((rdev->family == CHIP_PALM) ||
  3015. (rdev->family == CHIP_SUMO) ||
  3016. (rdev->family == CHIP_SUMO2))
  3017. mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
  3018. else
  3019. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  3020. /* setup tiling info dword. gb_addr_config is not adequate since it does
  3021. * not have bank info, so create a custom tiling dword.
  3022. * bits 3:0 num_pipes
  3023. * bits 7:4 num_banks
  3024. * bits 11:8 group_size
  3025. * bits 15:12 row_size
  3026. */
  3027. rdev->config.evergreen.tile_config = 0;
  3028. switch (rdev->config.evergreen.max_tile_pipes) {
  3029. case 1:
  3030. default:
  3031. rdev->config.evergreen.tile_config |= (0 << 0);
  3032. break;
  3033. case 2:
  3034. rdev->config.evergreen.tile_config |= (1 << 0);
  3035. break;
  3036. case 4:
  3037. rdev->config.evergreen.tile_config |= (2 << 0);
  3038. break;
  3039. case 8:
  3040. rdev->config.evergreen.tile_config |= (3 << 0);
  3041. break;
  3042. }
  3043. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  3044. if (rdev->flags & RADEON_IS_IGP)
  3045. rdev->config.evergreen.tile_config |= 1 << 4;
  3046. else {
  3047. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  3048. case 0: /* four banks */
  3049. rdev->config.evergreen.tile_config |= 0 << 4;
  3050. break;
  3051. case 1: /* eight banks */
  3052. rdev->config.evergreen.tile_config |= 1 << 4;
  3053. break;
  3054. case 2: /* sixteen banks */
  3055. default:
  3056. rdev->config.evergreen.tile_config |= 2 << 4;
  3057. break;
  3058. }
  3059. }
  3060. rdev->config.evergreen.tile_config |= 0 << 8;
  3061. rdev->config.evergreen.tile_config |=
  3062. ((gb_addr_config & 0x30000000) >> 28) << 12;
  3063. num_shader_engines = (gb_addr_config & NUM_SHADER_ENGINES(3) >> 12) + 1;
  3064. if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
  3065. u32 efuse_straps_4;
  3066. u32 efuse_straps_3;
  3067. efuse_straps_4 = RREG32_RCU(0x204);
  3068. efuse_straps_3 = RREG32_RCU(0x203);
  3069. tmp = (((efuse_straps_4 & 0xf) << 4) |
  3070. ((efuse_straps_3 & 0xf0000000) >> 28));
  3071. } else {
  3072. tmp = 0;
  3073. for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
  3074. u32 rb_disable_bitmap;
  3075. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3076. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3077. rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
  3078. tmp <<= 4;
  3079. tmp |= rb_disable_bitmap;
  3080. }
  3081. }
  3082. /* enabled rb are just the one not disabled :) */
  3083. disabled_rb_mask = tmp;
  3084. tmp = 0;
  3085. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3086. tmp |= (1 << i);
  3087. /* if all the backends are disabled, fix it up here */
  3088. if ((disabled_rb_mask & tmp) == tmp) {
  3089. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3090. disabled_rb_mask &= ~(1 << i);
  3091. }
  3092. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3093. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3094. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  3095. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  3096. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  3097. WREG32(DMA_TILING_CONFIG, gb_addr_config);
  3098. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  3099. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  3100. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  3101. if ((rdev->config.evergreen.max_backends == 1) &&
  3102. (rdev->flags & RADEON_IS_IGP)) {
  3103. if ((disabled_rb_mask & 3) == 1) {
  3104. /* RB0 disabled, RB1 enabled */
  3105. tmp = 0x11111111;
  3106. } else {
  3107. /* RB1 disabled, RB0 enabled */
  3108. tmp = 0x00000000;
  3109. }
  3110. } else {
  3111. tmp = gb_addr_config & NUM_PIPES_MASK;
  3112. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
  3113. EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
  3114. }
  3115. WREG32(GB_BACKEND_MAP, tmp);
  3116. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  3117. WREG32(CGTS_TCC_DISABLE, 0);
  3118. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  3119. WREG32(CGTS_USER_TCC_DISABLE, 0);
  3120. /* set HW defaults for 3D engine */
  3121. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  3122. ROQ_IB2_START(0x2b)));
  3123. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  3124. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
  3125. SYNC_GRADIENT |
  3126. SYNC_WALKER |
  3127. SYNC_ALIGNER));
  3128. sx_debug_1 = RREG32(SX_DEBUG_1);
  3129. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  3130. WREG32(SX_DEBUG_1, sx_debug_1);
  3131. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  3132. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  3133. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
  3134. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  3135. if (rdev->family <= CHIP_SUMO2)
  3136. WREG32(SMX_SAR_CTL0, 0x00010000);
  3137. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
  3138. POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
  3139. SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
  3140. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
  3141. SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
  3142. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
  3143. WREG32(VGT_NUM_INSTANCES, 1);
  3144. WREG32(SPI_CONFIG_CNTL, 0);
  3145. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  3146. WREG32(CP_PERFMON_CNTL, 0);
  3147. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
  3148. FETCH_FIFO_HIWATER(0x4) |
  3149. DONE_FIFO_HIWATER(0xe0) |
  3150. ALU_UPDATE_FIFO_HIWATER(0x8)));
  3151. sq_config = RREG32(SQ_CONFIG);
  3152. sq_config &= ~(PS_PRIO(3) |
  3153. VS_PRIO(3) |
  3154. GS_PRIO(3) |
  3155. ES_PRIO(3));
  3156. sq_config |= (VC_ENABLE |
  3157. EXPORT_SRC_C |
  3158. PS_PRIO(0) |
  3159. VS_PRIO(1) |
  3160. GS_PRIO(2) |
  3161. ES_PRIO(3));
  3162. switch (rdev->family) {
  3163. case CHIP_CEDAR:
  3164. case CHIP_PALM:
  3165. case CHIP_SUMO:
  3166. case CHIP_SUMO2:
  3167. case CHIP_CAICOS:
  3168. /* no vertex cache */
  3169. sq_config &= ~VC_ENABLE;
  3170. break;
  3171. default:
  3172. break;
  3173. }
  3174. sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
  3175. sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
  3176. sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
  3177. sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
  3178. sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3179. sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3180. sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3181. sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3182. switch (rdev->family) {
  3183. case CHIP_CEDAR:
  3184. case CHIP_PALM:
  3185. case CHIP_SUMO:
  3186. case CHIP_SUMO2:
  3187. ps_thread_count = 96;
  3188. break;
  3189. default:
  3190. ps_thread_count = 128;
  3191. break;
  3192. }
  3193. sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
  3194. sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3195. sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3196. sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3197. sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3198. sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3199. sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3200. sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3201. sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3202. sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3203. sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3204. sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3205. WREG32(SQ_CONFIG, sq_config);
  3206. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  3207. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  3208. WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
  3209. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  3210. WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
  3211. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  3212. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  3213. WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
  3214. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
  3215. WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
  3216. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  3217. FORCE_EOV_MAX_REZ_CNT(255)));
  3218. switch (rdev->family) {
  3219. case CHIP_CEDAR:
  3220. case CHIP_PALM:
  3221. case CHIP_SUMO:
  3222. case CHIP_SUMO2:
  3223. case CHIP_CAICOS:
  3224. vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
  3225. break;
  3226. default:
  3227. vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
  3228. break;
  3229. }
  3230. vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
  3231. WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
  3232. WREG32(VGT_GS_VERTEX_REUSE, 16);
  3233. WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
  3234. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  3235. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
  3236. WREG32(VGT_OUT_DEALLOC_CNTL, 16);
  3237. WREG32(CB_PERF_CTR0_SEL_0, 0);
  3238. WREG32(CB_PERF_CTR0_SEL_1, 0);
  3239. WREG32(CB_PERF_CTR1_SEL_0, 0);
  3240. WREG32(CB_PERF_CTR1_SEL_1, 0);
  3241. WREG32(CB_PERF_CTR2_SEL_0, 0);
  3242. WREG32(CB_PERF_CTR2_SEL_1, 0);
  3243. WREG32(CB_PERF_CTR3_SEL_0, 0);
  3244. WREG32(CB_PERF_CTR3_SEL_1, 0);
  3245. /* clear render buffer base addresses */
  3246. WREG32(CB_COLOR0_BASE, 0);
  3247. WREG32(CB_COLOR1_BASE, 0);
  3248. WREG32(CB_COLOR2_BASE, 0);
  3249. WREG32(CB_COLOR3_BASE, 0);
  3250. WREG32(CB_COLOR4_BASE, 0);
  3251. WREG32(CB_COLOR5_BASE, 0);
  3252. WREG32(CB_COLOR6_BASE, 0);
  3253. WREG32(CB_COLOR7_BASE, 0);
  3254. WREG32(CB_COLOR8_BASE, 0);
  3255. WREG32(CB_COLOR9_BASE, 0);
  3256. WREG32(CB_COLOR10_BASE, 0);
  3257. WREG32(CB_COLOR11_BASE, 0);
  3258. /* set the shader const cache sizes to 0 */
  3259. for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
  3260. WREG32(i, 0);
  3261. for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
  3262. WREG32(i, 0);
  3263. tmp = RREG32(HDP_MISC_CNTL);
  3264. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  3265. WREG32(HDP_MISC_CNTL, tmp);
  3266. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  3267. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  3268. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  3269. udelay(50);
  3270. }
  3271. int evergreen_mc_init(struct radeon_device *rdev)
  3272. {
  3273. u32 tmp;
  3274. int chansize, numchan;
  3275. /* Get VRAM informations */
  3276. rdev->mc.vram_is_ddr = true;
  3277. if ((rdev->family == CHIP_PALM) ||
  3278. (rdev->family == CHIP_SUMO) ||
  3279. (rdev->family == CHIP_SUMO2))
  3280. tmp = RREG32(FUS_MC_ARB_RAMCFG);
  3281. else
  3282. tmp = RREG32(MC_ARB_RAMCFG);
  3283. if (tmp & CHANSIZE_OVERRIDE) {
  3284. chansize = 16;
  3285. } else if (tmp & CHANSIZE_MASK) {
  3286. chansize = 64;
  3287. } else {
  3288. chansize = 32;
  3289. }
  3290. tmp = RREG32(MC_SHARED_CHMAP);
  3291. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3292. case 0:
  3293. default:
  3294. numchan = 1;
  3295. break;
  3296. case 1:
  3297. numchan = 2;
  3298. break;
  3299. case 2:
  3300. numchan = 4;
  3301. break;
  3302. case 3:
  3303. numchan = 8;
  3304. break;
  3305. }
  3306. rdev->mc.vram_width = numchan * chansize;
  3307. /* Could aper size report 0 ? */
  3308. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3309. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3310. /* Setup GPU memory space */
  3311. if ((rdev->family == CHIP_PALM) ||
  3312. (rdev->family == CHIP_SUMO) ||
  3313. (rdev->family == CHIP_SUMO2)) {
  3314. /* size in bytes on fusion */
  3315. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  3316. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  3317. } else {
  3318. /* size in MB on evergreen/cayman/tn */
  3319. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3320. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3321. }
  3322. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3323. r700_vram_gtt_location(rdev, &rdev->mc);
  3324. radeon_update_bandwidth_info(rdev);
  3325. return 0;
  3326. }
  3327. void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
  3328. {
  3329. dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
  3330. RREG32(GRBM_STATUS));
  3331. dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
  3332. RREG32(GRBM_STATUS_SE0));
  3333. dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
  3334. RREG32(GRBM_STATUS_SE1));
  3335. dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
  3336. RREG32(SRBM_STATUS));
  3337. dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
  3338. RREG32(SRBM_STATUS2));
  3339. dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
  3340. RREG32(CP_STALLED_STAT1));
  3341. dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
  3342. RREG32(CP_STALLED_STAT2));
  3343. dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
  3344. RREG32(CP_BUSY_STAT));
  3345. dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
  3346. RREG32(CP_STAT));
  3347. dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
  3348. RREG32(DMA_STATUS_REG));
  3349. if (rdev->family >= CHIP_CAYMAN) {
  3350. dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
  3351. RREG32(DMA_STATUS_REG + 0x800));
  3352. }
  3353. }
  3354. bool evergreen_is_display_hung(struct radeon_device *rdev)
  3355. {
  3356. u32 crtc_hung = 0;
  3357. u32 crtc_status[6];
  3358. u32 i, j, tmp;
  3359. for (i = 0; i < rdev->num_crtc; i++) {
  3360. if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
  3361. crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3362. crtc_hung |= (1 << i);
  3363. }
  3364. }
  3365. for (j = 0; j < 10; j++) {
  3366. for (i = 0; i < rdev->num_crtc; i++) {
  3367. if (crtc_hung & (1 << i)) {
  3368. tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3369. if (tmp != crtc_status[i])
  3370. crtc_hung &= ~(1 << i);
  3371. }
  3372. }
  3373. if (crtc_hung == 0)
  3374. return false;
  3375. udelay(100);
  3376. }
  3377. return true;
  3378. }
  3379. u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
  3380. {
  3381. u32 reset_mask = 0;
  3382. u32 tmp;
  3383. /* GRBM_STATUS */
  3384. tmp = RREG32(GRBM_STATUS);
  3385. if (tmp & (PA_BUSY | SC_BUSY |
  3386. SH_BUSY | SX_BUSY |
  3387. TA_BUSY | VGT_BUSY |
  3388. DB_BUSY | CB_BUSY |
  3389. SPI_BUSY | VGT_BUSY_NO_DMA))
  3390. reset_mask |= RADEON_RESET_GFX;
  3391. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3392. CP_BUSY | CP_COHERENCY_BUSY))
  3393. reset_mask |= RADEON_RESET_CP;
  3394. if (tmp & GRBM_EE_BUSY)
  3395. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3396. /* DMA_STATUS_REG */
  3397. tmp = RREG32(DMA_STATUS_REG);
  3398. if (!(tmp & DMA_IDLE))
  3399. reset_mask |= RADEON_RESET_DMA;
  3400. /* SRBM_STATUS2 */
  3401. tmp = RREG32(SRBM_STATUS2);
  3402. if (tmp & DMA_BUSY)
  3403. reset_mask |= RADEON_RESET_DMA;
  3404. /* SRBM_STATUS */
  3405. tmp = RREG32(SRBM_STATUS);
  3406. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3407. reset_mask |= RADEON_RESET_RLC;
  3408. if (tmp & IH_BUSY)
  3409. reset_mask |= RADEON_RESET_IH;
  3410. if (tmp & SEM_BUSY)
  3411. reset_mask |= RADEON_RESET_SEM;
  3412. if (tmp & GRBM_RQ_PENDING)
  3413. reset_mask |= RADEON_RESET_GRBM;
  3414. if (tmp & VMC_BUSY)
  3415. reset_mask |= RADEON_RESET_VMC;
  3416. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3417. MCC_BUSY | MCD_BUSY))
  3418. reset_mask |= RADEON_RESET_MC;
  3419. if (evergreen_is_display_hung(rdev))
  3420. reset_mask |= RADEON_RESET_DISPLAY;
  3421. /* VM_L2_STATUS */
  3422. tmp = RREG32(VM_L2_STATUS);
  3423. if (tmp & L2_BUSY)
  3424. reset_mask |= RADEON_RESET_VMC;
  3425. /* Skip MC reset as it's mostly likely not hung, just busy */
  3426. if (reset_mask & RADEON_RESET_MC) {
  3427. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3428. reset_mask &= ~RADEON_RESET_MC;
  3429. }
  3430. return reset_mask;
  3431. }
  3432. static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3433. {
  3434. struct evergreen_mc_save save;
  3435. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3436. u32 tmp;
  3437. if (reset_mask == 0)
  3438. return;
  3439. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3440. evergreen_print_gpu_status_regs(rdev);
  3441. /* Disable CP parsing/prefetching */
  3442. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3443. if (reset_mask & RADEON_RESET_DMA) {
  3444. /* Disable DMA */
  3445. tmp = RREG32(DMA_RB_CNTL);
  3446. tmp &= ~DMA_RB_ENABLE;
  3447. WREG32(DMA_RB_CNTL, tmp);
  3448. }
  3449. udelay(50);
  3450. evergreen_mc_stop(rdev, &save);
  3451. if (evergreen_mc_wait_for_idle(rdev)) {
  3452. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3453. }
  3454. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  3455. grbm_soft_reset |= SOFT_RESET_DB |
  3456. SOFT_RESET_CB |
  3457. SOFT_RESET_PA |
  3458. SOFT_RESET_SC |
  3459. SOFT_RESET_SPI |
  3460. SOFT_RESET_SX |
  3461. SOFT_RESET_SH |
  3462. SOFT_RESET_TC |
  3463. SOFT_RESET_TA |
  3464. SOFT_RESET_VC |
  3465. SOFT_RESET_VGT;
  3466. }
  3467. if (reset_mask & RADEON_RESET_CP) {
  3468. grbm_soft_reset |= SOFT_RESET_CP |
  3469. SOFT_RESET_VGT;
  3470. srbm_soft_reset |= SOFT_RESET_GRBM;
  3471. }
  3472. if (reset_mask & RADEON_RESET_DMA)
  3473. srbm_soft_reset |= SOFT_RESET_DMA;
  3474. if (reset_mask & RADEON_RESET_DISPLAY)
  3475. srbm_soft_reset |= SOFT_RESET_DC;
  3476. if (reset_mask & RADEON_RESET_RLC)
  3477. srbm_soft_reset |= SOFT_RESET_RLC;
  3478. if (reset_mask & RADEON_RESET_SEM)
  3479. srbm_soft_reset |= SOFT_RESET_SEM;
  3480. if (reset_mask & RADEON_RESET_IH)
  3481. srbm_soft_reset |= SOFT_RESET_IH;
  3482. if (reset_mask & RADEON_RESET_GRBM)
  3483. srbm_soft_reset |= SOFT_RESET_GRBM;
  3484. if (reset_mask & RADEON_RESET_VMC)
  3485. srbm_soft_reset |= SOFT_RESET_VMC;
  3486. if (!(rdev->flags & RADEON_IS_IGP)) {
  3487. if (reset_mask & RADEON_RESET_MC)
  3488. srbm_soft_reset |= SOFT_RESET_MC;
  3489. }
  3490. if (grbm_soft_reset) {
  3491. tmp = RREG32(GRBM_SOFT_RESET);
  3492. tmp |= grbm_soft_reset;
  3493. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3494. WREG32(GRBM_SOFT_RESET, tmp);
  3495. tmp = RREG32(GRBM_SOFT_RESET);
  3496. udelay(50);
  3497. tmp &= ~grbm_soft_reset;
  3498. WREG32(GRBM_SOFT_RESET, tmp);
  3499. tmp = RREG32(GRBM_SOFT_RESET);
  3500. }
  3501. if (srbm_soft_reset) {
  3502. tmp = RREG32(SRBM_SOFT_RESET);
  3503. tmp |= srbm_soft_reset;
  3504. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3505. WREG32(SRBM_SOFT_RESET, tmp);
  3506. tmp = RREG32(SRBM_SOFT_RESET);
  3507. udelay(50);
  3508. tmp &= ~srbm_soft_reset;
  3509. WREG32(SRBM_SOFT_RESET, tmp);
  3510. tmp = RREG32(SRBM_SOFT_RESET);
  3511. }
  3512. /* Wait a little for things to settle down */
  3513. udelay(50);
  3514. evergreen_mc_resume(rdev, &save);
  3515. udelay(50);
  3516. evergreen_print_gpu_status_regs(rdev);
  3517. }
  3518. void evergreen_gpu_pci_config_reset(struct radeon_device *rdev)
  3519. {
  3520. struct evergreen_mc_save save;
  3521. u32 tmp, i;
  3522. dev_info(rdev->dev, "GPU pci config reset\n");
  3523. /* disable dpm? */
  3524. /* Disable CP parsing/prefetching */
  3525. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3526. udelay(50);
  3527. /* Disable DMA */
  3528. tmp = RREG32(DMA_RB_CNTL);
  3529. tmp &= ~DMA_RB_ENABLE;
  3530. WREG32(DMA_RB_CNTL, tmp);
  3531. /* XXX other engines? */
  3532. /* halt the rlc */
  3533. r600_rlc_stop(rdev);
  3534. udelay(50);
  3535. /* set mclk/sclk to bypass */
  3536. rv770_set_clk_bypass_mode(rdev);
  3537. /* disable BM */
  3538. pci_clear_master(rdev->pdev);
  3539. /* disable mem access */
  3540. evergreen_mc_stop(rdev, &save);
  3541. if (evergreen_mc_wait_for_idle(rdev)) {
  3542. dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
  3543. }
  3544. /* reset */
  3545. radeon_pci_config_reset(rdev);
  3546. /* wait for asic to come out of reset */
  3547. for (i = 0; i < rdev->usec_timeout; i++) {
  3548. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  3549. break;
  3550. udelay(1);
  3551. }
  3552. }
  3553. int evergreen_asic_reset(struct radeon_device *rdev)
  3554. {
  3555. u32 reset_mask;
  3556. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3557. if (reset_mask)
  3558. r600_set_bios_scratch_engine_hung(rdev, true);
  3559. /* try soft reset */
  3560. evergreen_gpu_soft_reset(rdev, reset_mask);
  3561. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3562. /* try pci config reset */
  3563. if (reset_mask && radeon_hard_reset)
  3564. evergreen_gpu_pci_config_reset(rdev);
  3565. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3566. if (!reset_mask)
  3567. r600_set_bios_scratch_engine_hung(rdev, false);
  3568. return 0;
  3569. }
  3570. /**
  3571. * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
  3572. *
  3573. * @rdev: radeon_device pointer
  3574. * @ring: radeon_ring structure holding ring information
  3575. *
  3576. * Check if the GFX engine is locked up.
  3577. * Returns true if the engine appears to be locked up, false if not.
  3578. */
  3579. bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3580. {
  3581. u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3582. if (!(reset_mask & (RADEON_RESET_GFX |
  3583. RADEON_RESET_COMPUTE |
  3584. RADEON_RESET_CP))) {
  3585. radeon_ring_lockup_update(rdev, ring);
  3586. return false;
  3587. }
  3588. return radeon_ring_test_lockup(rdev, ring);
  3589. }
  3590. /*
  3591. * RLC
  3592. */
  3593. #define RLC_SAVE_RESTORE_LIST_END_MARKER 0x00000000
  3594. #define RLC_CLEAR_STATE_END_MARKER 0x00000001
  3595. void sumo_rlc_fini(struct radeon_device *rdev)
  3596. {
  3597. int r;
  3598. /* save restore block */
  3599. if (rdev->rlc.save_restore_obj) {
  3600. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3601. if (unlikely(r != 0))
  3602. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3603. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3604. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3605. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3606. rdev->rlc.save_restore_obj = NULL;
  3607. }
  3608. /* clear state block */
  3609. if (rdev->rlc.clear_state_obj) {
  3610. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3611. if (unlikely(r != 0))
  3612. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3613. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3614. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3615. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3616. rdev->rlc.clear_state_obj = NULL;
  3617. }
  3618. /* clear state block */
  3619. if (rdev->rlc.cp_table_obj) {
  3620. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3621. if (unlikely(r != 0))
  3622. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3623. radeon_bo_unpin(rdev->rlc.cp_table_obj);
  3624. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3625. radeon_bo_unref(&rdev->rlc.cp_table_obj);
  3626. rdev->rlc.cp_table_obj = NULL;
  3627. }
  3628. }
  3629. #define CP_ME_TABLE_SIZE 96
  3630. int sumo_rlc_init(struct radeon_device *rdev)
  3631. {
  3632. const u32 *src_ptr;
  3633. volatile u32 *dst_ptr;
  3634. u32 dws, data, i, j, k, reg_num;
  3635. u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index = 0;
  3636. u64 reg_list_mc_addr;
  3637. const struct cs_section_def *cs_data;
  3638. int r;
  3639. src_ptr = rdev->rlc.reg_list;
  3640. dws = rdev->rlc.reg_list_size;
  3641. if (rdev->family >= CHIP_BONAIRE) {
  3642. dws += (5 * 16) + 48 + 48 + 64;
  3643. }
  3644. cs_data = rdev->rlc.cs_data;
  3645. if (src_ptr) {
  3646. /* save restore block */
  3647. if (rdev->rlc.save_restore_obj == NULL) {
  3648. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3649. RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->rlc.save_restore_obj);
  3650. if (r) {
  3651. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3652. return r;
  3653. }
  3654. }
  3655. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3656. if (unlikely(r != 0)) {
  3657. sumo_rlc_fini(rdev);
  3658. return r;
  3659. }
  3660. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3661. &rdev->rlc.save_restore_gpu_addr);
  3662. if (r) {
  3663. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3664. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3665. sumo_rlc_fini(rdev);
  3666. return r;
  3667. }
  3668. r = radeon_bo_kmap(rdev->rlc.save_restore_obj, (void **)&rdev->rlc.sr_ptr);
  3669. if (r) {
  3670. dev_warn(rdev->dev, "(%d) map RLC sr bo failed\n", r);
  3671. sumo_rlc_fini(rdev);
  3672. return r;
  3673. }
  3674. /* write the sr buffer */
  3675. dst_ptr = rdev->rlc.sr_ptr;
  3676. if (rdev->family >= CHIP_TAHITI) {
  3677. /* SI */
  3678. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  3679. dst_ptr[i] = cpu_to_le32(src_ptr[i]);
  3680. } else {
  3681. /* ON/LN/TN */
  3682. /* format:
  3683. * dw0: (reg2 << 16) | reg1
  3684. * dw1: reg1 save space
  3685. * dw2: reg2 save space
  3686. */
  3687. for (i = 0; i < dws; i++) {
  3688. data = src_ptr[i] >> 2;
  3689. i++;
  3690. if (i < dws)
  3691. data |= (src_ptr[i] >> 2) << 16;
  3692. j = (((i - 1) * 3) / 2);
  3693. dst_ptr[j] = cpu_to_le32(data);
  3694. }
  3695. j = ((i * 3) / 2);
  3696. dst_ptr[j] = cpu_to_le32(RLC_SAVE_RESTORE_LIST_END_MARKER);
  3697. }
  3698. radeon_bo_kunmap(rdev->rlc.save_restore_obj);
  3699. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3700. }
  3701. if (cs_data) {
  3702. /* clear state block */
  3703. if (rdev->family >= CHIP_BONAIRE) {
  3704. rdev->rlc.clear_state_size = dws = cik_get_csb_size(rdev);
  3705. } else if (rdev->family >= CHIP_TAHITI) {
  3706. rdev->rlc.clear_state_size = si_get_csb_size(rdev);
  3707. dws = rdev->rlc.clear_state_size + (256 / 4);
  3708. } else {
  3709. reg_list_num = 0;
  3710. dws = 0;
  3711. for (i = 0; cs_data[i].section != NULL; i++) {
  3712. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3713. reg_list_num++;
  3714. dws += cs_data[i].section[j].reg_count;
  3715. }
  3716. }
  3717. reg_list_blk_index = (3 * reg_list_num + 2);
  3718. dws += reg_list_blk_index;
  3719. rdev->rlc.clear_state_size = dws;
  3720. }
  3721. if (rdev->rlc.clear_state_obj == NULL) {
  3722. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3723. RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->rlc.clear_state_obj);
  3724. if (r) {
  3725. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3726. sumo_rlc_fini(rdev);
  3727. return r;
  3728. }
  3729. }
  3730. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3731. if (unlikely(r != 0)) {
  3732. sumo_rlc_fini(rdev);
  3733. return r;
  3734. }
  3735. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3736. &rdev->rlc.clear_state_gpu_addr);
  3737. if (r) {
  3738. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3739. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3740. sumo_rlc_fini(rdev);
  3741. return r;
  3742. }
  3743. r = radeon_bo_kmap(rdev->rlc.clear_state_obj, (void **)&rdev->rlc.cs_ptr);
  3744. if (r) {
  3745. dev_warn(rdev->dev, "(%d) map RLC c bo failed\n", r);
  3746. sumo_rlc_fini(rdev);
  3747. return r;
  3748. }
  3749. /* set up the cs buffer */
  3750. dst_ptr = rdev->rlc.cs_ptr;
  3751. if (rdev->family >= CHIP_BONAIRE) {
  3752. cik_get_csb_buffer(rdev, dst_ptr);
  3753. } else if (rdev->family >= CHIP_TAHITI) {
  3754. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + 256;
  3755. dst_ptr[0] = cpu_to_le32(upper_32_bits(reg_list_mc_addr));
  3756. dst_ptr[1] = cpu_to_le32(lower_32_bits(reg_list_mc_addr));
  3757. dst_ptr[2] = cpu_to_le32(rdev->rlc.clear_state_size);
  3758. si_get_csb_buffer(rdev, &dst_ptr[(256/4)]);
  3759. } else {
  3760. reg_list_hdr_blk_index = 0;
  3761. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + (reg_list_blk_index * 4);
  3762. data = upper_32_bits(reg_list_mc_addr);
  3763. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3764. reg_list_hdr_blk_index++;
  3765. for (i = 0; cs_data[i].section != NULL; i++) {
  3766. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3767. reg_num = cs_data[i].section[j].reg_count;
  3768. data = reg_list_mc_addr & 0xffffffff;
  3769. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3770. reg_list_hdr_blk_index++;
  3771. data = (cs_data[i].section[j].reg_index * 4) & 0xffffffff;
  3772. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3773. reg_list_hdr_blk_index++;
  3774. data = 0x08000000 | (reg_num * 4);
  3775. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3776. reg_list_hdr_blk_index++;
  3777. for (k = 0; k < reg_num; k++) {
  3778. data = cs_data[i].section[j].extent[k];
  3779. dst_ptr[reg_list_blk_index + k] = cpu_to_le32(data);
  3780. }
  3781. reg_list_mc_addr += reg_num * 4;
  3782. reg_list_blk_index += reg_num;
  3783. }
  3784. }
  3785. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(RLC_CLEAR_STATE_END_MARKER);
  3786. }
  3787. radeon_bo_kunmap(rdev->rlc.clear_state_obj);
  3788. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3789. }
  3790. if (rdev->rlc.cp_table_size) {
  3791. if (rdev->rlc.cp_table_obj == NULL) {
  3792. r = radeon_bo_create(rdev, rdev->rlc.cp_table_size, PAGE_SIZE, true,
  3793. RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->rlc.cp_table_obj);
  3794. if (r) {
  3795. dev_warn(rdev->dev, "(%d) create RLC cp table bo failed\n", r);
  3796. sumo_rlc_fini(rdev);
  3797. return r;
  3798. }
  3799. }
  3800. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3801. if (unlikely(r != 0)) {
  3802. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3803. sumo_rlc_fini(rdev);
  3804. return r;
  3805. }
  3806. r = radeon_bo_pin(rdev->rlc.cp_table_obj, RADEON_GEM_DOMAIN_VRAM,
  3807. &rdev->rlc.cp_table_gpu_addr);
  3808. if (r) {
  3809. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3810. dev_warn(rdev->dev, "(%d) pin RLC cp_table bo failed\n", r);
  3811. sumo_rlc_fini(rdev);
  3812. return r;
  3813. }
  3814. r = radeon_bo_kmap(rdev->rlc.cp_table_obj, (void **)&rdev->rlc.cp_table_ptr);
  3815. if (r) {
  3816. dev_warn(rdev->dev, "(%d) map RLC cp table bo failed\n", r);
  3817. sumo_rlc_fini(rdev);
  3818. return r;
  3819. }
  3820. cik_init_cp_pg_table(rdev);
  3821. radeon_bo_kunmap(rdev->rlc.cp_table_obj);
  3822. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3823. }
  3824. return 0;
  3825. }
  3826. static void evergreen_rlc_start(struct radeon_device *rdev)
  3827. {
  3828. u32 mask = RLC_ENABLE;
  3829. if (rdev->flags & RADEON_IS_IGP) {
  3830. mask |= GFX_POWER_GATING_ENABLE | GFX_POWER_GATING_SRC;
  3831. }
  3832. WREG32(RLC_CNTL, mask);
  3833. }
  3834. int evergreen_rlc_resume(struct radeon_device *rdev)
  3835. {
  3836. u32 i;
  3837. const __be32 *fw_data;
  3838. if (!rdev->rlc_fw)
  3839. return -EINVAL;
  3840. r600_rlc_stop(rdev);
  3841. WREG32(RLC_HB_CNTL, 0);
  3842. if (rdev->flags & RADEON_IS_IGP) {
  3843. if (rdev->family == CHIP_ARUBA) {
  3844. u32 always_on_bitmap =
  3845. 3 | (3 << (16 * rdev->config.cayman.max_shader_engines));
  3846. /* find out the number of active simds */
  3847. u32 tmp = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  3848. tmp |= 0xffffffff << rdev->config.cayman.max_simds_per_se;
  3849. tmp = hweight32(~tmp);
  3850. if (tmp == rdev->config.cayman.max_simds_per_se) {
  3851. WREG32(TN_RLC_LB_ALWAYS_ACTIVE_SIMD_MASK, always_on_bitmap);
  3852. WREG32(TN_RLC_LB_PARAMS, 0x00601004);
  3853. WREG32(TN_RLC_LB_INIT_SIMD_MASK, 0xffffffff);
  3854. WREG32(TN_RLC_LB_CNTR_INIT, 0x00000000);
  3855. WREG32(TN_RLC_LB_CNTR_MAX, 0x00002000);
  3856. }
  3857. } else {
  3858. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  3859. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  3860. }
  3861. WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  3862. WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  3863. } else {
  3864. WREG32(RLC_HB_BASE, 0);
  3865. WREG32(RLC_HB_RPTR, 0);
  3866. WREG32(RLC_HB_WPTR, 0);
  3867. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  3868. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  3869. }
  3870. WREG32(RLC_MC_CNTL, 0);
  3871. WREG32(RLC_UCODE_CNTL, 0);
  3872. fw_data = (const __be32 *)rdev->rlc_fw->data;
  3873. if (rdev->family >= CHIP_ARUBA) {
  3874. for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
  3875. WREG32(RLC_UCODE_ADDR, i);
  3876. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3877. }
  3878. } else if (rdev->family >= CHIP_CAYMAN) {
  3879. for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
  3880. WREG32(RLC_UCODE_ADDR, i);
  3881. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3882. }
  3883. } else {
  3884. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  3885. WREG32(RLC_UCODE_ADDR, i);
  3886. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3887. }
  3888. }
  3889. WREG32(RLC_UCODE_ADDR, 0);
  3890. evergreen_rlc_start(rdev);
  3891. return 0;
  3892. }
  3893. /* Interrupts */
  3894. u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
  3895. {
  3896. if (crtc >= rdev->num_crtc)
  3897. return 0;
  3898. else
  3899. return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  3900. }
  3901. void evergreen_disable_interrupt_state(struct radeon_device *rdev)
  3902. {
  3903. u32 tmp;
  3904. if (rdev->family >= CHIP_CAYMAN) {
  3905. cayman_cp_int_cntl_setup(rdev, 0,
  3906. CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3907. cayman_cp_int_cntl_setup(rdev, 1, 0);
  3908. cayman_cp_int_cntl_setup(rdev, 2, 0);
  3909. tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  3910. WREG32(CAYMAN_DMA1_CNTL, tmp);
  3911. } else
  3912. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3913. tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  3914. WREG32(DMA_CNTL, tmp);
  3915. WREG32(GRBM_INT_CNTL, 0);
  3916. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3917. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3918. if (rdev->num_crtc >= 4) {
  3919. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3920. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3921. }
  3922. if (rdev->num_crtc >= 6) {
  3923. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3924. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3925. }
  3926. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3927. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3928. if (rdev->num_crtc >= 4) {
  3929. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3930. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3931. }
  3932. if (rdev->num_crtc >= 6) {
  3933. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3934. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3935. }
  3936. /* only one DAC on DCE5 */
  3937. if (!ASIC_IS_DCE5(rdev))
  3938. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  3939. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  3940. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3941. WREG32(DC_HPD1_INT_CONTROL, tmp);
  3942. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3943. WREG32(DC_HPD2_INT_CONTROL, tmp);
  3944. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3945. WREG32(DC_HPD3_INT_CONTROL, tmp);
  3946. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3947. WREG32(DC_HPD4_INT_CONTROL, tmp);
  3948. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3949. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3950. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3951. WREG32(DC_HPD6_INT_CONTROL, tmp);
  3952. }
  3953. int evergreen_irq_set(struct radeon_device *rdev)
  3954. {
  3955. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  3956. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  3957. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  3958. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  3959. u32 grbm_int_cntl = 0;
  3960. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  3961. u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
  3962. u32 dma_cntl, dma_cntl1 = 0;
  3963. u32 thermal_int = 0;
  3964. if (!rdev->irq.installed) {
  3965. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  3966. return -EINVAL;
  3967. }
  3968. /* don't enable anything if the ih is disabled */
  3969. if (!rdev->ih.enabled) {
  3970. r600_disable_interrupts(rdev);
  3971. /* force the active interrupt state to all disabled */
  3972. evergreen_disable_interrupt_state(rdev);
  3973. return 0;
  3974. }
  3975. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3976. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3977. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3978. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3979. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3980. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3981. if (rdev->family == CHIP_ARUBA)
  3982. thermal_int = RREG32(TN_CG_THERMAL_INT_CTRL) &
  3983. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  3984. else
  3985. thermal_int = RREG32(CG_THERMAL_INT) &
  3986. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  3987. afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3988. afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3989. afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3990. afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3991. afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3992. afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3993. dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  3994. if (rdev->family >= CHIP_CAYMAN) {
  3995. /* enable CP interrupts on all rings */
  3996. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  3997. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  3998. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  3999. }
  4000. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4001. DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
  4002. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4003. }
  4004. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4005. DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
  4006. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4007. }
  4008. } else {
  4009. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4010. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4011. cp_int_cntl |= RB_INT_ENABLE;
  4012. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4013. }
  4014. }
  4015. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4016. DRM_DEBUG("r600_irq_set: sw int dma\n");
  4017. dma_cntl |= TRAP_ENABLE;
  4018. }
  4019. if (rdev->family >= CHIP_CAYMAN) {
  4020. dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4021. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4022. DRM_DEBUG("r600_irq_set: sw int dma1\n");
  4023. dma_cntl1 |= TRAP_ENABLE;
  4024. }
  4025. }
  4026. if (rdev->irq.dpm_thermal) {
  4027. DRM_DEBUG("dpm thermal\n");
  4028. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  4029. }
  4030. if (rdev->irq.crtc_vblank_int[0] ||
  4031. atomic_read(&rdev->irq.pflip[0])) {
  4032. DRM_DEBUG("evergreen_irq_set: vblank 0\n");
  4033. crtc1 |= VBLANK_INT_MASK;
  4034. }
  4035. if (rdev->irq.crtc_vblank_int[1] ||
  4036. atomic_read(&rdev->irq.pflip[1])) {
  4037. DRM_DEBUG("evergreen_irq_set: vblank 1\n");
  4038. crtc2 |= VBLANK_INT_MASK;
  4039. }
  4040. if (rdev->irq.crtc_vblank_int[2] ||
  4041. atomic_read(&rdev->irq.pflip[2])) {
  4042. DRM_DEBUG("evergreen_irq_set: vblank 2\n");
  4043. crtc3 |= VBLANK_INT_MASK;
  4044. }
  4045. if (rdev->irq.crtc_vblank_int[3] ||
  4046. atomic_read(&rdev->irq.pflip[3])) {
  4047. DRM_DEBUG("evergreen_irq_set: vblank 3\n");
  4048. crtc4 |= VBLANK_INT_MASK;
  4049. }
  4050. if (rdev->irq.crtc_vblank_int[4] ||
  4051. atomic_read(&rdev->irq.pflip[4])) {
  4052. DRM_DEBUG("evergreen_irq_set: vblank 4\n");
  4053. crtc5 |= VBLANK_INT_MASK;
  4054. }
  4055. if (rdev->irq.crtc_vblank_int[5] ||
  4056. atomic_read(&rdev->irq.pflip[5])) {
  4057. DRM_DEBUG("evergreen_irq_set: vblank 5\n");
  4058. crtc6 |= VBLANK_INT_MASK;
  4059. }
  4060. if (rdev->irq.hpd[0]) {
  4061. DRM_DEBUG("evergreen_irq_set: hpd 1\n");
  4062. hpd1 |= DC_HPDx_INT_EN;
  4063. }
  4064. if (rdev->irq.hpd[1]) {
  4065. DRM_DEBUG("evergreen_irq_set: hpd 2\n");
  4066. hpd2 |= DC_HPDx_INT_EN;
  4067. }
  4068. if (rdev->irq.hpd[2]) {
  4069. DRM_DEBUG("evergreen_irq_set: hpd 3\n");
  4070. hpd3 |= DC_HPDx_INT_EN;
  4071. }
  4072. if (rdev->irq.hpd[3]) {
  4073. DRM_DEBUG("evergreen_irq_set: hpd 4\n");
  4074. hpd4 |= DC_HPDx_INT_EN;
  4075. }
  4076. if (rdev->irq.hpd[4]) {
  4077. DRM_DEBUG("evergreen_irq_set: hpd 5\n");
  4078. hpd5 |= DC_HPDx_INT_EN;
  4079. }
  4080. if (rdev->irq.hpd[5]) {
  4081. DRM_DEBUG("evergreen_irq_set: hpd 6\n");
  4082. hpd6 |= DC_HPDx_INT_EN;
  4083. }
  4084. if (rdev->irq.afmt[0]) {
  4085. DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
  4086. afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4087. }
  4088. if (rdev->irq.afmt[1]) {
  4089. DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
  4090. afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4091. }
  4092. if (rdev->irq.afmt[2]) {
  4093. DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
  4094. afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4095. }
  4096. if (rdev->irq.afmt[3]) {
  4097. DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
  4098. afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4099. }
  4100. if (rdev->irq.afmt[4]) {
  4101. DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
  4102. afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4103. }
  4104. if (rdev->irq.afmt[5]) {
  4105. DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
  4106. afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4107. }
  4108. if (rdev->family >= CHIP_CAYMAN) {
  4109. cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
  4110. cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
  4111. cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
  4112. } else
  4113. WREG32(CP_INT_CNTL, cp_int_cntl);
  4114. WREG32(DMA_CNTL, dma_cntl);
  4115. if (rdev->family >= CHIP_CAYMAN)
  4116. WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
  4117. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4118. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4119. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4120. if (rdev->num_crtc >= 4) {
  4121. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4122. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4123. }
  4124. if (rdev->num_crtc >= 6) {
  4125. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4126. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4127. }
  4128. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  4129. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  4130. if (rdev->num_crtc >= 4) {
  4131. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  4132. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  4133. }
  4134. if (rdev->num_crtc >= 6) {
  4135. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  4136. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  4137. }
  4138. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4139. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4140. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4141. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4142. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4143. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4144. if (rdev->family == CHIP_ARUBA)
  4145. WREG32(TN_CG_THERMAL_INT_CTRL, thermal_int);
  4146. else
  4147. WREG32(CG_THERMAL_INT, thermal_int);
  4148. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
  4149. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
  4150. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
  4151. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
  4152. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
  4153. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
  4154. return 0;
  4155. }
  4156. static void evergreen_irq_ack(struct radeon_device *rdev)
  4157. {
  4158. u32 tmp;
  4159. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4160. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4161. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4162. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4163. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4164. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4165. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4166. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4167. if (rdev->num_crtc >= 4) {
  4168. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4169. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4170. }
  4171. if (rdev->num_crtc >= 6) {
  4172. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4173. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4174. }
  4175. rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4176. rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4177. rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4178. rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4179. rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4180. rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4181. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4182. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4183. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4184. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4185. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4186. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4187. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4188. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4189. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4190. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4191. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4192. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4193. if (rdev->num_crtc >= 4) {
  4194. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4195. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4196. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4197. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4198. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4199. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4200. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4201. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4202. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4203. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4204. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4205. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4206. }
  4207. if (rdev->num_crtc >= 6) {
  4208. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4209. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4210. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4211. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4212. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4213. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4214. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4215. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4216. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4217. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4218. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4219. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4220. }
  4221. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4222. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4223. tmp |= DC_HPDx_INT_ACK;
  4224. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4225. }
  4226. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4227. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4228. tmp |= DC_HPDx_INT_ACK;
  4229. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4230. }
  4231. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4232. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4233. tmp |= DC_HPDx_INT_ACK;
  4234. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4235. }
  4236. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4237. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4238. tmp |= DC_HPDx_INT_ACK;
  4239. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4240. }
  4241. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4242. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4243. tmp |= DC_HPDx_INT_ACK;
  4244. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4245. }
  4246. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4247. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4248. tmp |= DC_HPDx_INT_ACK;
  4249. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4250. }
  4251. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4252. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4253. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4254. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
  4255. }
  4256. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4257. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4258. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4259. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
  4260. }
  4261. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4262. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4263. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4264. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
  4265. }
  4266. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4267. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4268. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4269. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
  4270. }
  4271. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4272. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4273. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4274. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
  4275. }
  4276. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4277. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4278. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4279. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
  4280. }
  4281. }
  4282. static void evergreen_irq_disable(struct radeon_device *rdev)
  4283. {
  4284. r600_disable_interrupts(rdev);
  4285. /* Wait and acknowledge irq */
  4286. mdelay(1);
  4287. evergreen_irq_ack(rdev);
  4288. evergreen_disable_interrupt_state(rdev);
  4289. }
  4290. void evergreen_irq_suspend(struct radeon_device *rdev)
  4291. {
  4292. evergreen_irq_disable(rdev);
  4293. r600_rlc_stop(rdev);
  4294. }
  4295. static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
  4296. {
  4297. u32 wptr, tmp;
  4298. if (rdev->wb.enabled)
  4299. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4300. else
  4301. wptr = RREG32(IH_RB_WPTR);
  4302. if (wptr & RB_OVERFLOW) {
  4303. /* When a ring buffer overflow happen start parsing interrupt
  4304. * from the last not overwritten vector (wptr + 16). Hopefully
  4305. * this should allow us to catchup.
  4306. */
  4307. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  4308. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  4309. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4310. tmp = RREG32(IH_RB_CNTL);
  4311. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4312. WREG32(IH_RB_CNTL, tmp);
  4313. }
  4314. return (wptr & rdev->ih.ptr_mask);
  4315. }
  4316. int evergreen_irq_process(struct radeon_device *rdev)
  4317. {
  4318. u32 wptr;
  4319. u32 rptr;
  4320. u32 src_id, src_data;
  4321. u32 ring_index;
  4322. bool queue_hotplug = false;
  4323. bool queue_hdmi = false;
  4324. bool queue_thermal = false;
  4325. u32 status, addr;
  4326. if (!rdev->ih.enabled || rdev->shutdown)
  4327. return IRQ_NONE;
  4328. wptr = evergreen_get_ih_wptr(rdev);
  4329. restart_ih:
  4330. /* is somebody else already processing irqs? */
  4331. if (atomic_xchg(&rdev->ih.lock, 1))
  4332. return IRQ_NONE;
  4333. rptr = rdev->ih.rptr;
  4334. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4335. /* Order reading of wptr vs. reading of IH ring data */
  4336. rmb();
  4337. /* display interrupts */
  4338. evergreen_irq_ack(rdev);
  4339. while (rptr != wptr) {
  4340. /* wptr/rptr are in bytes! */
  4341. ring_index = rptr / 4;
  4342. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4343. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4344. switch (src_id) {
  4345. case 1: /* D1 vblank/vline */
  4346. switch (src_data) {
  4347. case 0: /* D1 vblank */
  4348. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  4349. if (rdev->irq.crtc_vblank_int[0]) {
  4350. drm_handle_vblank(rdev->ddev, 0);
  4351. rdev->pm.vblank_sync = true;
  4352. wake_up(&rdev->irq.vblank_queue);
  4353. }
  4354. if (atomic_read(&rdev->irq.pflip[0]))
  4355. radeon_crtc_handle_flip(rdev, 0);
  4356. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4357. DRM_DEBUG("IH: D1 vblank\n");
  4358. }
  4359. break;
  4360. case 1: /* D1 vline */
  4361. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  4362. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4363. DRM_DEBUG("IH: D1 vline\n");
  4364. }
  4365. break;
  4366. default:
  4367. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4368. break;
  4369. }
  4370. break;
  4371. case 2: /* D2 vblank/vline */
  4372. switch (src_data) {
  4373. case 0: /* D2 vblank */
  4374. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  4375. if (rdev->irq.crtc_vblank_int[1]) {
  4376. drm_handle_vblank(rdev->ddev, 1);
  4377. rdev->pm.vblank_sync = true;
  4378. wake_up(&rdev->irq.vblank_queue);
  4379. }
  4380. if (atomic_read(&rdev->irq.pflip[1]))
  4381. radeon_crtc_handle_flip(rdev, 1);
  4382. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4383. DRM_DEBUG("IH: D2 vblank\n");
  4384. }
  4385. break;
  4386. case 1: /* D2 vline */
  4387. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  4388. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4389. DRM_DEBUG("IH: D2 vline\n");
  4390. }
  4391. break;
  4392. default:
  4393. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4394. break;
  4395. }
  4396. break;
  4397. case 3: /* D3 vblank/vline */
  4398. switch (src_data) {
  4399. case 0: /* D3 vblank */
  4400. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  4401. if (rdev->irq.crtc_vblank_int[2]) {
  4402. drm_handle_vblank(rdev->ddev, 2);
  4403. rdev->pm.vblank_sync = true;
  4404. wake_up(&rdev->irq.vblank_queue);
  4405. }
  4406. if (atomic_read(&rdev->irq.pflip[2]))
  4407. radeon_crtc_handle_flip(rdev, 2);
  4408. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4409. DRM_DEBUG("IH: D3 vblank\n");
  4410. }
  4411. break;
  4412. case 1: /* D3 vline */
  4413. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  4414. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4415. DRM_DEBUG("IH: D3 vline\n");
  4416. }
  4417. break;
  4418. default:
  4419. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4420. break;
  4421. }
  4422. break;
  4423. case 4: /* D4 vblank/vline */
  4424. switch (src_data) {
  4425. case 0: /* D4 vblank */
  4426. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  4427. if (rdev->irq.crtc_vblank_int[3]) {
  4428. drm_handle_vblank(rdev->ddev, 3);
  4429. rdev->pm.vblank_sync = true;
  4430. wake_up(&rdev->irq.vblank_queue);
  4431. }
  4432. if (atomic_read(&rdev->irq.pflip[3]))
  4433. radeon_crtc_handle_flip(rdev, 3);
  4434. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4435. DRM_DEBUG("IH: D4 vblank\n");
  4436. }
  4437. break;
  4438. case 1: /* D4 vline */
  4439. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  4440. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4441. DRM_DEBUG("IH: D4 vline\n");
  4442. }
  4443. break;
  4444. default:
  4445. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4446. break;
  4447. }
  4448. break;
  4449. case 5: /* D5 vblank/vline */
  4450. switch (src_data) {
  4451. case 0: /* D5 vblank */
  4452. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  4453. if (rdev->irq.crtc_vblank_int[4]) {
  4454. drm_handle_vblank(rdev->ddev, 4);
  4455. rdev->pm.vblank_sync = true;
  4456. wake_up(&rdev->irq.vblank_queue);
  4457. }
  4458. if (atomic_read(&rdev->irq.pflip[4]))
  4459. radeon_crtc_handle_flip(rdev, 4);
  4460. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4461. DRM_DEBUG("IH: D5 vblank\n");
  4462. }
  4463. break;
  4464. case 1: /* D5 vline */
  4465. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  4466. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4467. DRM_DEBUG("IH: D5 vline\n");
  4468. }
  4469. break;
  4470. default:
  4471. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4472. break;
  4473. }
  4474. break;
  4475. case 6: /* D6 vblank/vline */
  4476. switch (src_data) {
  4477. case 0: /* D6 vblank */
  4478. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  4479. if (rdev->irq.crtc_vblank_int[5]) {
  4480. drm_handle_vblank(rdev->ddev, 5);
  4481. rdev->pm.vblank_sync = true;
  4482. wake_up(&rdev->irq.vblank_queue);
  4483. }
  4484. if (atomic_read(&rdev->irq.pflip[5]))
  4485. radeon_crtc_handle_flip(rdev, 5);
  4486. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4487. DRM_DEBUG("IH: D6 vblank\n");
  4488. }
  4489. break;
  4490. case 1: /* D6 vline */
  4491. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  4492. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4493. DRM_DEBUG("IH: D6 vline\n");
  4494. }
  4495. break;
  4496. default:
  4497. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4498. break;
  4499. }
  4500. break;
  4501. case 42: /* HPD hotplug */
  4502. switch (src_data) {
  4503. case 0:
  4504. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4505. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4506. queue_hotplug = true;
  4507. DRM_DEBUG("IH: HPD1\n");
  4508. }
  4509. break;
  4510. case 1:
  4511. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4512. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4513. queue_hotplug = true;
  4514. DRM_DEBUG("IH: HPD2\n");
  4515. }
  4516. break;
  4517. case 2:
  4518. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4519. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4520. queue_hotplug = true;
  4521. DRM_DEBUG("IH: HPD3\n");
  4522. }
  4523. break;
  4524. case 3:
  4525. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4526. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4527. queue_hotplug = true;
  4528. DRM_DEBUG("IH: HPD4\n");
  4529. }
  4530. break;
  4531. case 4:
  4532. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4533. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4534. queue_hotplug = true;
  4535. DRM_DEBUG("IH: HPD5\n");
  4536. }
  4537. break;
  4538. case 5:
  4539. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4540. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4541. queue_hotplug = true;
  4542. DRM_DEBUG("IH: HPD6\n");
  4543. }
  4544. break;
  4545. default:
  4546. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4547. break;
  4548. }
  4549. break;
  4550. case 44: /* hdmi */
  4551. switch (src_data) {
  4552. case 0:
  4553. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4554. rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
  4555. queue_hdmi = true;
  4556. DRM_DEBUG("IH: HDMI0\n");
  4557. }
  4558. break;
  4559. case 1:
  4560. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4561. rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
  4562. queue_hdmi = true;
  4563. DRM_DEBUG("IH: HDMI1\n");
  4564. }
  4565. break;
  4566. case 2:
  4567. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4568. rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
  4569. queue_hdmi = true;
  4570. DRM_DEBUG("IH: HDMI2\n");
  4571. }
  4572. break;
  4573. case 3:
  4574. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4575. rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
  4576. queue_hdmi = true;
  4577. DRM_DEBUG("IH: HDMI3\n");
  4578. }
  4579. break;
  4580. case 4:
  4581. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4582. rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
  4583. queue_hdmi = true;
  4584. DRM_DEBUG("IH: HDMI4\n");
  4585. }
  4586. break;
  4587. case 5:
  4588. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4589. rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
  4590. queue_hdmi = true;
  4591. DRM_DEBUG("IH: HDMI5\n");
  4592. }
  4593. break;
  4594. default:
  4595. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  4596. break;
  4597. }
  4598. case 124: /* UVD */
  4599. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  4600. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  4601. break;
  4602. case 146:
  4603. case 147:
  4604. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  4605. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  4606. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4607. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4608. addr);
  4609. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4610. status);
  4611. cayman_vm_decode_fault(rdev, status, addr);
  4612. /* reset addr and status */
  4613. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4614. break;
  4615. case 176: /* CP_INT in ring buffer */
  4616. case 177: /* CP_INT in IB1 */
  4617. case 178: /* CP_INT in IB2 */
  4618. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  4619. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4620. break;
  4621. case 181: /* CP EOP event */
  4622. DRM_DEBUG("IH: CP EOP\n");
  4623. if (rdev->family >= CHIP_CAYMAN) {
  4624. switch (src_data) {
  4625. case 0:
  4626. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4627. break;
  4628. case 1:
  4629. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4630. break;
  4631. case 2:
  4632. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4633. break;
  4634. }
  4635. } else
  4636. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4637. break;
  4638. case 224: /* DMA trap event */
  4639. DRM_DEBUG("IH: DMA trap\n");
  4640. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4641. break;
  4642. case 230: /* thermal low to high */
  4643. DRM_DEBUG("IH: thermal low to high\n");
  4644. rdev->pm.dpm.thermal.high_to_low = false;
  4645. queue_thermal = true;
  4646. break;
  4647. case 231: /* thermal high to low */
  4648. DRM_DEBUG("IH: thermal high to low\n");
  4649. rdev->pm.dpm.thermal.high_to_low = true;
  4650. queue_thermal = true;
  4651. break;
  4652. case 233: /* GUI IDLE */
  4653. DRM_DEBUG("IH: GUI idle\n");
  4654. break;
  4655. case 244: /* DMA trap event */
  4656. if (rdev->family >= CHIP_CAYMAN) {
  4657. DRM_DEBUG("IH: DMA1 trap\n");
  4658. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4659. }
  4660. break;
  4661. default:
  4662. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4663. break;
  4664. }
  4665. /* wptr/rptr are in bytes! */
  4666. rptr += 16;
  4667. rptr &= rdev->ih.ptr_mask;
  4668. }
  4669. if (queue_hotplug)
  4670. schedule_work(&rdev->hotplug_work);
  4671. if (queue_hdmi)
  4672. schedule_work(&rdev->audio_work);
  4673. if (queue_thermal && rdev->pm.dpm_enabled)
  4674. schedule_work(&rdev->pm.dpm.thermal.work);
  4675. rdev->ih.rptr = rptr;
  4676. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  4677. atomic_set(&rdev->ih.lock, 0);
  4678. /* make sure wptr hasn't changed while processing */
  4679. wptr = evergreen_get_ih_wptr(rdev);
  4680. if (wptr != rptr)
  4681. goto restart_ih;
  4682. return IRQ_HANDLED;
  4683. }
  4684. static int evergreen_startup(struct radeon_device *rdev)
  4685. {
  4686. struct radeon_ring *ring;
  4687. int r;
  4688. /* enable pcie gen2 link */
  4689. evergreen_pcie_gen2_enable(rdev);
  4690. /* enable aspm */
  4691. evergreen_program_aspm(rdev);
  4692. /* scratch needs to be initialized before MC */
  4693. r = r600_vram_scratch_init(rdev);
  4694. if (r)
  4695. return r;
  4696. evergreen_mc_program(rdev);
  4697. if (ASIC_IS_DCE5(rdev) && !rdev->pm.dpm_enabled) {
  4698. r = ni_mc_load_microcode(rdev);
  4699. if (r) {
  4700. DRM_ERROR("Failed to load MC firmware!\n");
  4701. return r;
  4702. }
  4703. }
  4704. if (rdev->flags & RADEON_IS_AGP) {
  4705. evergreen_agp_enable(rdev);
  4706. } else {
  4707. r = evergreen_pcie_gart_enable(rdev);
  4708. if (r)
  4709. return r;
  4710. }
  4711. evergreen_gpu_init(rdev);
  4712. /* allocate rlc buffers */
  4713. if (rdev->flags & RADEON_IS_IGP) {
  4714. rdev->rlc.reg_list = sumo_rlc_save_restore_register_list;
  4715. rdev->rlc.reg_list_size =
  4716. (u32)ARRAY_SIZE(sumo_rlc_save_restore_register_list);
  4717. rdev->rlc.cs_data = evergreen_cs_data;
  4718. r = sumo_rlc_init(rdev);
  4719. if (r) {
  4720. DRM_ERROR("Failed to init rlc BOs!\n");
  4721. return r;
  4722. }
  4723. }
  4724. /* allocate wb buffer */
  4725. r = radeon_wb_init(rdev);
  4726. if (r)
  4727. return r;
  4728. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4729. if (r) {
  4730. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4731. return r;
  4732. }
  4733. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  4734. if (r) {
  4735. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4736. return r;
  4737. }
  4738. r = uvd_v2_2_resume(rdev);
  4739. if (!r) {
  4740. r = radeon_fence_driver_start_ring(rdev,
  4741. R600_RING_TYPE_UVD_INDEX);
  4742. if (r)
  4743. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  4744. }
  4745. if (r)
  4746. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  4747. /* Enable IRQ */
  4748. if (!rdev->irq.installed) {
  4749. r = radeon_irq_kms_init(rdev);
  4750. if (r)
  4751. return r;
  4752. }
  4753. r = r600_irq_init(rdev);
  4754. if (r) {
  4755. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  4756. radeon_irq_kms_fini(rdev);
  4757. return r;
  4758. }
  4759. evergreen_irq_set(rdev);
  4760. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4761. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  4762. RADEON_CP_PACKET2);
  4763. if (r)
  4764. return r;
  4765. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4766. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  4767. DMA_PACKET(DMA_PACKET_NOP, 0, 0));
  4768. if (r)
  4769. return r;
  4770. r = evergreen_cp_load_microcode(rdev);
  4771. if (r)
  4772. return r;
  4773. r = evergreen_cp_resume(rdev);
  4774. if (r)
  4775. return r;
  4776. r = r600_dma_resume(rdev);
  4777. if (r)
  4778. return r;
  4779. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4780. if (ring->ring_size) {
  4781. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  4782. RADEON_CP_PACKET2);
  4783. if (!r)
  4784. r = uvd_v1_0_init(rdev);
  4785. if (r)
  4786. DRM_ERROR("radeon: error initializing UVD (%d).\n", r);
  4787. }
  4788. r = radeon_ib_pool_init(rdev);
  4789. if (r) {
  4790. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  4791. return r;
  4792. }
  4793. r = r600_audio_init(rdev);
  4794. if (r) {
  4795. DRM_ERROR("radeon: audio init failed\n");
  4796. return r;
  4797. }
  4798. return 0;
  4799. }
  4800. int evergreen_resume(struct radeon_device *rdev)
  4801. {
  4802. int r;
  4803. /* reset the asic, the gfx blocks are often in a bad state
  4804. * after the driver is unloaded or after a resume
  4805. */
  4806. if (radeon_asic_reset(rdev))
  4807. dev_warn(rdev->dev, "GPU reset failed !\n");
  4808. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  4809. * posting will perform necessary task to bring back GPU into good
  4810. * shape.
  4811. */
  4812. /* post card */
  4813. atom_asic_init(rdev->mode_info.atom_context);
  4814. /* init golden registers */
  4815. evergreen_init_golden_registers(rdev);
  4816. radeon_pm_resume(rdev);
  4817. rdev->accel_working = true;
  4818. r = evergreen_startup(rdev);
  4819. if (r) {
  4820. DRM_ERROR("evergreen startup failed on resume\n");
  4821. rdev->accel_working = false;
  4822. return r;
  4823. }
  4824. return r;
  4825. }
  4826. int evergreen_suspend(struct radeon_device *rdev)
  4827. {
  4828. radeon_pm_suspend(rdev);
  4829. r600_audio_fini(rdev);
  4830. uvd_v1_0_fini(rdev);
  4831. radeon_uvd_suspend(rdev);
  4832. r700_cp_stop(rdev);
  4833. r600_dma_stop(rdev);
  4834. evergreen_irq_suspend(rdev);
  4835. radeon_wb_disable(rdev);
  4836. evergreen_pcie_gart_disable(rdev);
  4837. return 0;
  4838. }
  4839. /* Plan is to move initialization in that function and use
  4840. * helper function so that radeon_device_init pretty much
  4841. * do nothing more than calling asic specific function. This
  4842. * should also allow to remove a bunch of callback function
  4843. * like vram_info.
  4844. */
  4845. int evergreen_init(struct radeon_device *rdev)
  4846. {
  4847. int r;
  4848. /* Read BIOS */
  4849. if (!radeon_get_bios(rdev)) {
  4850. if (ASIC_IS_AVIVO(rdev))
  4851. return -EINVAL;
  4852. }
  4853. /* Must be an ATOMBIOS */
  4854. if (!rdev->is_atom_bios) {
  4855. dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
  4856. return -EINVAL;
  4857. }
  4858. r = radeon_atombios_init(rdev);
  4859. if (r)
  4860. return r;
  4861. /* reset the asic, the gfx blocks are often in a bad state
  4862. * after the driver is unloaded or after a resume
  4863. */
  4864. if (radeon_asic_reset(rdev))
  4865. dev_warn(rdev->dev, "GPU reset failed !\n");
  4866. /* Post card if necessary */
  4867. if (!radeon_card_posted(rdev)) {
  4868. if (!rdev->bios) {
  4869. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  4870. return -EINVAL;
  4871. }
  4872. DRM_INFO("GPU not posted. posting now...\n");
  4873. atom_asic_init(rdev->mode_info.atom_context);
  4874. }
  4875. /* init golden registers */
  4876. evergreen_init_golden_registers(rdev);
  4877. /* Initialize scratch registers */
  4878. r600_scratch_init(rdev);
  4879. /* Initialize surface registers */
  4880. radeon_surface_init(rdev);
  4881. /* Initialize clocks */
  4882. radeon_get_clock_info(rdev->ddev);
  4883. /* Fence driver */
  4884. r = radeon_fence_driver_init(rdev);
  4885. if (r)
  4886. return r;
  4887. /* initialize AGP */
  4888. if (rdev->flags & RADEON_IS_AGP) {
  4889. r = radeon_agp_init(rdev);
  4890. if (r)
  4891. radeon_agp_disable(rdev);
  4892. }
  4893. /* initialize memory controller */
  4894. r = evergreen_mc_init(rdev);
  4895. if (r)
  4896. return r;
  4897. /* Memory manager */
  4898. r = radeon_bo_init(rdev);
  4899. if (r)
  4900. return r;
  4901. if (ASIC_IS_DCE5(rdev)) {
  4902. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  4903. r = ni_init_microcode(rdev);
  4904. if (r) {
  4905. DRM_ERROR("Failed to load firmware!\n");
  4906. return r;
  4907. }
  4908. }
  4909. } else {
  4910. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  4911. r = r600_init_microcode(rdev);
  4912. if (r) {
  4913. DRM_ERROR("Failed to load firmware!\n");
  4914. return r;
  4915. }
  4916. }
  4917. }
  4918. /* Initialize power management */
  4919. radeon_pm_init(rdev);
  4920. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  4921. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  4922. rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
  4923. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
  4924. r = radeon_uvd_init(rdev);
  4925. if (!r) {
  4926. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  4927. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX],
  4928. 4096);
  4929. }
  4930. rdev->ih.ring_obj = NULL;
  4931. r600_ih_ring_init(rdev, 64 * 1024);
  4932. r = r600_pcie_gart_init(rdev);
  4933. if (r)
  4934. return r;
  4935. rdev->accel_working = true;
  4936. r = evergreen_startup(rdev);
  4937. if (r) {
  4938. dev_err(rdev->dev, "disabling GPU acceleration\n");
  4939. r700_cp_fini(rdev);
  4940. r600_dma_fini(rdev);
  4941. r600_irq_fini(rdev);
  4942. if (rdev->flags & RADEON_IS_IGP)
  4943. sumo_rlc_fini(rdev);
  4944. radeon_wb_fini(rdev);
  4945. radeon_ib_pool_fini(rdev);
  4946. radeon_irq_kms_fini(rdev);
  4947. evergreen_pcie_gart_fini(rdev);
  4948. rdev->accel_working = false;
  4949. }
  4950. /* Don't start up if the MC ucode is missing on BTC parts.
  4951. * The default clocks and voltages before the MC ucode
  4952. * is loaded are not suffient for advanced operations.
  4953. */
  4954. if (ASIC_IS_DCE5(rdev)) {
  4955. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  4956. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  4957. return -EINVAL;
  4958. }
  4959. }
  4960. return 0;
  4961. }
  4962. void evergreen_fini(struct radeon_device *rdev)
  4963. {
  4964. radeon_pm_fini(rdev);
  4965. r600_audio_fini(rdev);
  4966. r700_cp_fini(rdev);
  4967. r600_dma_fini(rdev);
  4968. r600_irq_fini(rdev);
  4969. if (rdev->flags & RADEON_IS_IGP)
  4970. sumo_rlc_fini(rdev);
  4971. radeon_wb_fini(rdev);
  4972. radeon_ib_pool_fini(rdev);
  4973. radeon_irq_kms_fini(rdev);
  4974. evergreen_pcie_gart_fini(rdev);
  4975. uvd_v1_0_fini(rdev);
  4976. radeon_uvd_fini(rdev);
  4977. r600_vram_scratch_fini(rdev);
  4978. radeon_gem_fini(rdev);
  4979. radeon_fence_driver_fini(rdev);
  4980. radeon_agp_fini(rdev);
  4981. radeon_bo_fini(rdev);
  4982. radeon_atombios_fini(rdev);
  4983. kfree(rdev->bios);
  4984. rdev->bios = NULL;
  4985. }
  4986. void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
  4987. {
  4988. u32 link_width_cntl, speed_cntl;
  4989. if (radeon_pcie_gen2 == 0)
  4990. return;
  4991. if (rdev->flags & RADEON_IS_IGP)
  4992. return;
  4993. if (!(rdev->flags & RADEON_IS_PCIE))
  4994. return;
  4995. /* x2 cards have a special sequence */
  4996. if (ASIC_IS_X2(rdev))
  4997. return;
  4998. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  4999. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  5000. return;
  5001. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5002. if (speed_cntl & LC_CURRENT_DATA_RATE) {
  5003. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  5004. return;
  5005. }
  5006. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  5007. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  5008. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  5009. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5010. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5011. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5012. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5013. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  5014. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5015. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5016. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  5017. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5018. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5019. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  5020. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5021. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5022. speed_cntl |= LC_GEN2_EN_STRAP;
  5023. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5024. } else {
  5025. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5026. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  5027. if (1)
  5028. link_width_cntl |= LC_UPCONFIGURE_DIS;
  5029. else
  5030. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5031. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5032. }
  5033. }
  5034. void evergreen_program_aspm(struct radeon_device *rdev)
  5035. {
  5036. u32 data, orig;
  5037. u32 pcie_lc_cntl, pcie_lc_cntl_old;
  5038. bool disable_l0s, disable_l1 = false, disable_plloff_in_l1 = false;
  5039. /* fusion_platform = true
  5040. * if the system is a fusion system
  5041. * (APU or DGPU in a fusion system).
  5042. * todo: check if the system is a fusion platform.
  5043. */
  5044. bool fusion_platform = false;
  5045. if (radeon_aspm == 0)
  5046. return;
  5047. if (!(rdev->flags & RADEON_IS_PCIE))
  5048. return;
  5049. switch (rdev->family) {
  5050. case CHIP_CYPRESS:
  5051. case CHIP_HEMLOCK:
  5052. case CHIP_JUNIPER:
  5053. case CHIP_REDWOOD:
  5054. case CHIP_CEDAR:
  5055. case CHIP_SUMO:
  5056. case CHIP_SUMO2:
  5057. case CHIP_PALM:
  5058. case CHIP_ARUBA:
  5059. disable_l0s = true;
  5060. break;
  5061. default:
  5062. disable_l0s = false;
  5063. break;
  5064. }
  5065. if (rdev->flags & RADEON_IS_IGP)
  5066. fusion_platform = true; /* XXX also dGPUs in a fusion system */
  5067. data = orig = RREG32_PIF_PHY0(PB0_PIF_PAIRING);
  5068. if (fusion_platform)
  5069. data &= ~MULTI_PIF;
  5070. else
  5071. data |= MULTI_PIF;
  5072. if (data != orig)
  5073. WREG32_PIF_PHY0(PB0_PIF_PAIRING, data);
  5074. data = orig = RREG32_PIF_PHY1(PB1_PIF_PAIRING);
  5075. if (fusion_platform)
  5076. data &= ~MULTI_PIF;
  5077. else
  5078. data |= MULTI_PIF;
  5079. if (data != orig)
  5080. WREG32_PIF_PHY1(PB1_PIF_PAIRING, data);
  5081. pcie_lc_cntl = pcie_lc_cntl_old = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5082. pcie_lc_cntl &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  5083. if (!disable_l0s) {
  5084. if (rdev->family >= CHIP_BARTS)
  5085. pcie_lc_cntl |= LC_L0S_INACTIVITY(7);
  5086. else
  5087. pcie_lc_cntl |= LC_L0S_INACTIVITY(3);
  5088. }
  5089. if (!disable_l1) {
  5090. if (rdev->family >= CHIP_BARTS)
  5091. pcie_lc_cntl |= LC_L1_INACTIVITY(7);
  5092. else
  5093. pcie_lc_cntl |= LC_L1_INACTIVITY(8);
  5094. if (!disable_plloff_in_l1) {
  5095. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5096. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5097. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5098. if (data != orig)
  5099. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5100. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5101. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5102. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5103. if (data != orig)
  5104. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5105. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5106. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5107. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5108. if (data != orig)
  5109. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5110. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5111. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5112. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5113. if (data != orig)
  5114. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5115. if (rdev->family >= CHIP_BARTS) {
  5116. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5117. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5118. data |= PLL_RAMP_UP_TIME_0(4);
  5119. if (data != orig)
  5120. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5121. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5122. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5123. data |= PLL_RAMP_UP_TIME_1(4);
  5124. if (data != orig)
  5125. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5126. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5127. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5128. data |= PLL_RAMP_UP_TIME_0(4);
  5129. if (data != orig)
  5130. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5131. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5132. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5133. data |= PLL_RAMP_UP_TIME_1(4);
  5134. if (data != orig)
  5135. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5136. }
  5137. data = orig = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5138. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  5139. data |= LC_DYN_LANES_PWR_STATE(3);
  5140. if (data != orig)
  5141. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  5142. if (rdev->family >= CHIP_BARTS) {
  5143. data = orig = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  5144. data &= ~LS2_EXIT_TIME_MASK;
  5145. data |= LS2_EXIT_TIME(1);
  5146. if (data != orig)
  5147. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  5148. data = orig = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  5149. data &= ~LS2_EXIT_TIME_MASK;
  5150. data |= LS2_EXIT_TIME(1);
  5151. if (data != orig)
  5152. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  5153. }
  5154. }
  5155. }
  5156. /* evergreen parts only */
  5157. if (rdev->family < CHIP_BARTS)
  5158. pcie_lc_cntl |= LC_PMI_TO_L1_DIS;
  5159. if (pcie_lc_cntl != pcie_lc_cntl_old)
  5160. WREG32_PCIE_PORT(PCIE_LC_CNTL, pcie_lc_cntl);
  5161. }