evergreen.c 168 KB

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