evergreen.c 169 KB

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