evergreen.c 169 KB

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