evergreen.c 165 KB

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