evergreen.c 168 KB

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