evergreen.c 171 KB

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