r600.c 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/slab.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/firmware.h>
  31. #include <linux/module.h>
  32. #include <drm/drmP.h>
  33. #include <drm/radeon_drm.h>
  34. #include "radeon.h"
  35. #include "radeon_asic.h"
  36. #include "radeon_audio.h"
  37. #include "radeon_mode.h"
  38. #include "r600d.h"
  39. #include "atom.h"
  40. #include "avivod.h"
  41. #include "radeon_ucode.h"
  42. /* Firmware Names */
  43. MODULE_FIRMWARE("radeon/R600_pfp.bin");
  44. MODULE_FIRMWARE("radeon/R600_me.bin");
  45. MODULE_FIRMWARE("radeon/RV610_pfp.bin");
  46. MODULE_FIRMWARE("radeon/RV610_me.bin");
  47. MODULE_FIRMWARE("radeon/RV630_pfp.bin");
  48. MODULE_FIRMWARE("radeon/RV630_me.bin");
  49. MODULE_FIRMWARE("radeon/RV620_pfp.bin");
  50. MODULE_FIRMWARE("radeon/RV620_me.bin");
  51. MODULE_FIRMWARE("radeon/RV635_pfp.bin");
  52. MODULE_FIRMWARE("radeon/RV635_me.bin");
  53. MODULE_FIRMWARE("radeon/RV670_pfp.bin");
  54. MODULE_FIRMWARE("radeon/RV670_me.bin");
  55. MODULE_FIRMWARE("radeon/RS780_pfp.bin");
  56. MODULE_FIRMWARE("radeon/RS780_me.bin");
  57. MODULE_FIRMWARE("radeon/RV770_pfp.bin");
  58. MODULE_FIRMWARE("radeon/RV770_me.bin");
  59. MODULE_FIRMWARE("radeon/RV770_smc.bin");
  60. MODULE_FIRMWARE("radeon/RV730_pfp.bin");
  61. MODULE_FIRMWARE("radeon/RV730_me.bin");
  62. MODULE_FIRMWARE("radeon/RV730_smc.bin");
  63. MODULE_FIRMWARE("radeon/RV740_smc.bin");
  64. MODULE_FIRMWARE("radeon/RV710_pfp.bin");
  65. MODULE_FIRMWARE("radeon/RV710_me.bin");
  66. MODULE_FIRMWARE("radeon/RV710_smc.bin");
  67. MODULE_FIRMWARE("radeon/R600_rlc.bin");
  68. MODULE_FIRMWARE("radeon/R700_rlc.bin");
  69. MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
  70. MODULE_FIRMWARE("radeon/CEDAR_me.bin");
  71. MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
  72. MODULE_FIRMWARE("radeon/CEDAR_smc.bin");
  73. MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
  74. MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
  75. MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
  76. MODULE_FIRMWARE("radeon/REDWOOD_smc.bin");
  77. MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
  78. MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
  79. MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
  80. MODULE_FIRMWARE("radeon/JUNIPER_smc.bin");
  81. MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
  82. MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
  83. MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
  84. MODULE_FIRMWARE("radeon/CYPRESS_smc.bin");
  85. MODULE_FIRMWARE("radeon/PALM_pfp.bin");
  86. MODULE_FIRMWARE("radeon/PALM_me.bin");
  87. MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
  88. MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
  89. MODULE_FIRMWARE("radeon/SUMO_me.bin");
  90. MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
  91. MODULE_FIRMWARE("radeon/SUMO2_me.bin");
  92. static const u32 crtc_offsets[2] =
  93. {
  94. 0,
  95. AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
  96. };
  97. int r600_debugfs_mc_info_init(struct radeon_device *rdev);
  98. /* r600,rv610,rv630,rv620,rv635,rv670 */
  99. int r600_mc_wait_for_idle(struct radeon_device *rdev);
  100. static void r600_gpu_init(struct radeon_device *rdev);
  101. void r600_fini(struct radeon_device *rdev);
  102. void r600_irq_disable(struct radeon_device *rdev);
  103. static void r600_pcie_gen2_enable(struct radeon_device *rdev);
  104. extern int evergreen_rlc_resume(struct radeon_device *rdev);
  105. extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
  106. /*
  107. * Indirect registers accessor
  108. */
  109. u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
  110. {
  111. unsigned long flags;
  112. u32 r;
  113. spin_lock_irqsave(&rdev->rcu_idx_lock, flags);
  114. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  115. r = RREG32(R600_RCU_DATA);
  116. spin_unlock_irqrestore(&rdev->rcu_idx_lock, flags);
  117. return r;
  118. }
  119. void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  120. {
  121. unsigned long flags;
  122. spin_lock_irqsave(&rdev->rcu_idx_lock, flags);
  123. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  124. WREG32(R600_RCU_DATA, (v));
  125. spin_unlock_irqrestore(&rdev->rcu_idx_lock, flags);
  126. }
  127. u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
  128. {
  129. unsigned long flags;
  130. u32 r;
  131. spin_lock_irqsave(&rdev->uvd_idx_lock, flags);
  132. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  133. r = RREG32(R600_UVD_CTX_DATA);
  134. spin_unlock_irqrestore(&rdev->uvd_idx_lock, flags);
  135. return r;
  136. }
  137. void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  138. {
  139. unsigned long flags;
  140. spin_lock_irqsave(&rdev->uvd_idx_lock, flags);
  141. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  142. WREG32(R600_UVD_CTX_DATA, (v));
  143. spin_unlock_irqrestore(&rdev->uvd_idx_lock, flags);
  144. }
  145. /**
  146. * r600_get_allowed_info_register - fetch the register for the info ioctl
  147. *
  148. * @rdev: radeon_device pointer
  149. * @reg: register offset in bytes
  150. * @val: register value
  151. *
  152. * Returns 0 for success or -EINVAL for an invalid register
  153. *
  154. */
  155. int r600_get_allowed_info_register(struct radeon_device *rdev,
  156. u32 reg, u32 *val)
  157. {
  158. switch (reg) {
  159. case GRBM_STATUS:
  160. case GRBM_STATUS2:
  161. case R_000E50_SRBM_STATUS:
  162. case DMA_STATUS_REG:
  163. case UVD_STATUS:
  164. *val = RREG32(reg);
  165. return 0;
  166. default:
  167. return -EINVAL;
  168. }
  169. }
  170. /**
  171. * r600_get_xclk - get the xclk
  172. *
  173. * @rdev: radeon_device pointer
  174. *
  175. * Returns the reference clock used by the gfx engine
  176. * (r6xx, IGPs, APUs).
  177. */
  178. u32 r600_get_xclk(struct radeon_device *rdev)
  179. {
  180. return rdev->clock.spll.reference_freq;
  181. }
  182. int r600_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  183. {
  184. unsigned fb_div = 0, ref_div, vclk_div = 0, dclk_div = 0;
  185. int r;
  186. /* bypass vclk and dclk with bclk */
  187. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  188. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  189. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  190. /* assert BYPASS_EN, deassert UPLL_RESET, UPLL_SLEEP and UPLL_CTLREQ */
  191. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~(
  192. UPLL_RESET_MASK | UPLL_SLEEP_MASK | UPLL_CTLREQ_MASK));
  193. if (rdev->family >= CHIP_RS780)
  194. WREG32_P(GFX_MACRO_BYPASS_CNTL, UPLL_BYPASS_CNTL,
  195. ~UPLL_BYPASS_CNTL);
  196. if (!vclk || !dclk) {
  197. /* keep the Bypass mode, put PLL to sleep */
  198. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  199. return 0;
  200. }
  201. if (rdev->clock.spll.reference_freq == 10000)
  202. ref_div = 34;
  203. else
  204. ref_div = 4;
  205. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 50000, 160000,
  206. ref_div + 1, 0xFFF, 2, 30, ~0,
  207. &fb_div, &vclk_div, &dclk_div);
  208. if (r)
  209. return r;
  210. if (rdev->family >= CHIP_RV670 && rdev->family < CHIP_RS780)
  211. fb_div >>= 1;
  212. else
  213. fb_div |= 1;
  214. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  215. if (r)
  216. return r;
  217. /* assert PLL_RESET */
  218. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  219. /* For RS780 we have to choose ref clk */
  220. if (rdev->family >= CHIP_RS780)
  221. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_REFCLK_SRC_SEL_MASK,
  222. ~UPLL_REFCLK_SRC_SEL_MASK);
  223. /* set the required fb, ref and post divder values */
  224. WREG32_P(CG_UPLL_FUNC_CNTL,
  225. UPLL_FB_DIV(fb_div) |
  226. UPLL_REF_DIV(ref_div),
  227. ~(UPLL_FB_DIV_MASK | UPLL_REF_DIV_MASK));
  228. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  229. UPLL_SW_HILEN(vclk_div >> 1) |
  230. UPLL_SW_LOLEN((vclk_div >> 1) + (vclk_div & 1)) |
  231. UPLL_SW_HILEN2(dclk_div >> 1) |
  232. UPLL_SW_LOLEN2((dclk_div >> 1) + (dclk_div & 1)) |
  233. UPLL_DIVEN_MASK | UPLL_DIVEN2_MASK,
  234. ~UPLL_SW_MASK);
  235. /* give the PLL some time to settle */
  236. mdelay(15);
  237. /* deassert PLL_RESET */
  238. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  239. mdelay(15);
  240. /* deassert BYPASS EN */
  241. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  242. if (rdev->family >= CHIP_RS780)
  243. WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~UPLL_BYPASS_CNTL);
  244. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  245. if (r)
  246. return r;
  247. /* switch VCLK and DCLK selection */
  248. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  249. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  250. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  251. mdelay(100);
  252. return 0;
  253. }
  254. void dce3_program_fmt(struct drm_encoder *encoder)
  255. {
  256. struct drm_device *dev = encoder->dev;
  257. struct radeon_device *rdev = dev->dev_private;
  258. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  259. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  260. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  261. int bpc = 0;
  262. u32 tmp = 0;
  263. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  264. if (connector) {
  265. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  266. bpc = radeon_get_monitor_bpc(connector);
  267. dither = radeon_connector->dither;
  268. }
  269. /* LVDS FMT is set up by atom */
  270. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  271. return;
  272. /* not needed for analog */
  273. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  274. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  275. return;
  276. if (bpc == 0)
  277. return;
  278. switch (bpc) {
  279. case 6:
  280. if (dither == RADEON_FMT_DITHER_ENABLE)
  281. /* XXX sort out optimal dither settings */
  282. tmp |= FMT_SPATIAL_DITHER_EN;
  283. else
  284. tmp |= FMT_TRUNCATE_EN;
  285. break;
  286. case 8:
  287. if (dither == RADEON_FMT_DITHER_ENABLE)
  288. /* XXX sort out optimal dither settings */
  289. tmp |= (FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
  290. else
  291. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
  292. break;
  293. case 10:
  294. default:
  295. /* not needed */
  296. break;
  297. }
  298. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  299. }
  300. /* get temperature in millidegrees */
  301. int rv6xx_get_temp(struct radeon_device *rdev)
  302. {
  303. u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
  304. ASIC_T_SHIFT;
  305. int actual_temp = temp & 0xff;
  306. if (temp & 0x100)
  307. actual_temp -= 256;
  308. return actual_temp * 1000;
  309. }
  310. void r600_pm_get_dynpm_state(struct radeon_device *rdev)
  311. {
  312. int i;
  313. rdev->pm.dynpm_can_upclock = true;
  314. rdev->pm.dynpm_can_downclock = true;
  315. /* power state array is low to high, default is first */
  316. if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
  317. int min_power_state_index = 0;
  318. if (rdev->pm.num_power_states > 2)
  319. min_power_state_index = 1;
  320. switch (rdev->pm.dynpm_planned_action) {
  321. case DYNPM_ACTION_MINIMUM:
  322. rdev->pm.requested_power_state_index = min_power_state_index;
  323. rdev->pm.requested_clock_mode_index = 0;
  324. rdev->pm.dynpm_can_downclock = false;
  325. break;
  326. case DYNPM_ACTION_DOWNCLOCK:
  327. if (rdev->pm.current_power_state_index == min_power_state_index) {
  328. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  329. rdev->pm.dynpm_can_downclock = false;
  330. } else {
  331. if (rdev->pm.active_crtc_count > 1) {
  332. for (i = 0; i < rdev->pm.num_power_states; i++) {
  333. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  334. continue;
  335. else if (i >= rdev->pm.current_power_state_index) {
  336. rdev->pm.requested_power_state_index =
  337. rdev->pm.current_power_state_index;
  338. break;
  339. } else {
  340. rdev->pm.requested_power_state_index = i;
  341. break;
  342. }
  343. }
  344. } else {
  345. if (rdev->pm.current_power_state_index == 0)
  346. rdev->pm.requested_power_state_index =
  347. rdev->pm.num_power_states - 1;
  348. else
  349. rdev->pm.requested_power_state_index =
  350. rdev->pm.current_power_state_index - 1;
  351. }
  352. }
  353. rdev->pm.requested_clock_mode_index = 0;
  354. /* don't use the power state if crtcs are active and no display flag is set */
  355. if ((rdev->pm.active_crtc_count > 0) &&
  356. (rdev->pm.power_state[rdev->pm.requested_power_state_index].
  357. clock_info[rdev->pm.requested_clock_mode_index].flags &
  358. RADEON_PM_MODE_NO_DISPLAY)) {
  359. rdev->pm.requested_power_state_index++;
  360. }
  361. break;
  362. case DYNPM_ACTION_UPCLOCK:
  363. if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
  364. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  365. rdev->pm.dynpm_can_upclock = false;
  366. } else {
  367. if (rdev->pm.active_crtc_count > 1) {
  368. for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
  369. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  370. continue;
  371. else if (i <= rdev->pm.current_power_state_index) {
  372. rdev->pm.requested_power_state_index =
  373. rdev->pm.current_power_state_index;
  374. break;
  375. } else {
  376. rdev->pm.requested_power_state_index = i;
  377. break;
  378. }
  379. }
  380. } else
  381. rdev->pm.requested_power_state_index =
  382. rdev->pm.current_power_state_index + 1;
  383. }
  384. rdev->pm.requested_clock_mode_index = 0;
  385. break;
  386. case DYNPM_ACTION_DEFAULT:
  387. rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
  388. rdev->pm.requested_clock_mode_index = 0;
  389. rdev->pm.dynpm_can_upclock = false;
  390. break;
  391. case DYNPM_ACTION_NONE:
  392. default:
  393. DRM_ERROR("Requested mode for not defined action\n");
  394. return;
  395. }
  396. } else {
  397. /* XXX select a power state based on AC/DC, single/dualhead, etc. */
  398. /* for now just select the first power state and switch between clock modes */
  399. /* power state array is low to high, default is first (0) */
  400. if (rdev->pm.active_crtc_count > 1) {
  401. rdev->pm.requested_power_state_index = -1;
  402. /* start at 1 as we don't want the default mode */
  403. for (i = 1; i < rdev->pm.num_power_states; i++) {
  404. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  405. continue;
  406. else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
  407. (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
  408. rdev->pm.requested_power_state_index = i;
  409. break;
  410. }
  411. }
  412. /* if nothing selected, grab the default state. */
  413. if (rdev->pm.requested_power_state_index == -1)
  414. rdev->pm.requested_power_state_index = 0;
  415. } else
  416. rdev->pm.requested_power_state_index = 1;
  417. switch (rdev->pm.dynpm_planned_action) {
  418. case DYNPM_ACTION_MINIMUM:
  419. rdev->pm.requested_clock_mode_index = 0;
  420. rdev->pm.dynpm_can_downclock = false;
  421. break;
  422. case DYNPM_ACTION_DOWNCLOCK:
  423. if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
  424. if (rdev->pm.current_clock_mode_index == 0) {
  425. rdev->pm.requested_clock_mode_index = 0;
  426. rdev->pm.dynpm_can_downclock = false;
  427. } else
  428. rdev->pm.requested_clock_mode_index =
  429. rdev->pm.current_clock_mode_index - 1;
  430. } else {
  431. rdev->pm.requested_clock_mode_index = 0;
  432. rdev->pm.dynpm_can_downclock = false;
  433. }
  434. /* don't use the power state if crtcs are active and no display flag is set */
  435. if ((rdev->pm.active_crtc_count > 0) &&
  436. (rdev->pm.power_state[rdev->pm.requested_power_state_index].
  437. clock_info[rdev->pm.requested_clock_mode_index].flags &
  438. RADEON_PM_MODE_NO_DISPLAY)) {
  439. rdev->pm.requested_clock_mode_index++;
  440. }
  441. break;
  442. case DYNPM_ACTION_UPCLOCK:
  443. if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
  444. if (rdev->pm.current_clock_mode_index ==
  445. (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
  446. rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
  447. rdev->pm.dynpm_can_upclock = false;
  448. } else
  449. rdev->pm.requested_clock_mode_index =
  450. rdev->pm.current_clock_mode_index + 1;
  451. } else {
  452. rdev->pm.requested_clock_mode_index =
  453. rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
  454. rdev->pm.dynpm_can_upclock = false;
  455. }
  456. break;
  457. case DYNPM_ACTION_DEFAULT:
  458. rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
  459. rdev->pm.requested_clock_mode_index = 0;
  460. rdev->pm.dynpm_can_upclock = false;
  461. break;
  462. case DYNPM_ACTION_NONE:
  463. default:
  464. DRM_ERROR("Requested mode for not defined action\n");
  465. return;
  466. }
  467. }
  468. DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
  469. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  470. clock_info[rdev->pm.requested_clock_mode_index].sclk,
  471. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  472. clock_info[rdev->pm.requested_clock_mode_index].mclk,
  473. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  474. pcie_lanes);
  475. }
  476. void rs780_pm_init_profile(struct radeon_device *rdev)
  477. {
  478. if (rdev->pm.num_power_states == 2) {
  479. /* default */
  480. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  481. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  482. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  483. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  484. /* low sh */
  485. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
  486. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
  487. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  488. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  489. /* mid sh */
  490. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
  491. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
  492. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  493. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  494. /* high sh */
  495. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
  496. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
  497. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  498. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  499. /* low mh */
  500. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
  501. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
  502. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  503. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  504. /* mid mh */
  505. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
  506. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
  507. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  508. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  509. /* high mh */
  510. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
  511. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
  512. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  513. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  514. } else if (rdev->pm.num_power_states == 3) {
  515. /* default */
  516. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  517. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  518. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  519. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  520. /* low sh */
  521. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
  522. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
  523. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  524. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  525. /* mid sh */
  526. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
  527. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
  528. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  529. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  530. /* high sh */
  531. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
  532. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
  533. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  534. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  535. /* low mh */
  536. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
  537. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
  538. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  539. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  540. /* mid mh */
  541. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
  542. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
  543. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  544. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  545. /* high mh */
  546. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
  547. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
  548. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  549. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  550. } else {
  551. /* default */
  552. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  553. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  554. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  555. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  556. /* low sh */
  557. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
  558. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
  559. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  560. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  561. /* mid sh */
  562. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
  563. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
  564. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  565. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  566. /* high sh */
  567. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
  568. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
  569. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  570. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  571. /* low mh */
  572. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
  573. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
  574. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  575. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  576. /* mid mh */
  577. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
  578. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
  579. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  580. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  581. /* high mh */
  582. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
  583. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
  584. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  585. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  586. }
  587. }
  588. void r600_pm_init_profile(struct radeon_device *rdev)
  589. {
  590. int idx;
  591. if (rdev->family == CHIP_R600) {
  592. /* XXX */
  593. /* default */
  594. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  595. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  596. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  597. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  598. /* low sh */
  599. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  600. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  601. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  602. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  603. /* mid sh */
  604. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  605. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  606. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  607. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  608. /* high sh */
  609. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  610. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  611. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  612. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  613. /* low mh */
  614. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  615. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  616. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  617. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  618. /* mid mh */
  619. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  620. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  621. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  622. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  623. /* high mh */
  624. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  625. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  626. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  627. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  628. } else {
  629. if (rdev->pm.num_power_states < 4) {
  630. /* default */
  631. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  632. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  633. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  634. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  635. /* low sh */
  636. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
  637. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
  638. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  639. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  640. /* mid sh */
  641. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
  642. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
  643. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  644. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  645. /* high sh */
  646. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
  647. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
  648. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  649. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  650. /* low mh */
  651. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
  652. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
  653. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  654. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  655. /* low mh */
  656. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
  657. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
  658. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  659. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  660. /* high mh */
  661. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
  662. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
  663. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  664. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  665. } else {
  666. /* default */
  667. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  668. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  669. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  670. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  671. /* low sh */
  672. if (rdev->flags & RADEON_IS_MOBILITY)
  673. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  674. else
  675. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  676. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  677. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  678. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  679. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  680. /* mid sh */
  681. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  682. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  683. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  684. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  685. /* high sh */
  686. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  687. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  688. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  689. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  690. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  691. /* low mh */
  692. if (rdev->flags & RADEON_IS_MOBILITY)
  693. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
  694. else
  695. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
  696. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  697. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  698. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  699. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  700. /* mid mh */
  701. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  702. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  703. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  704. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  705. /* high mh */
  706. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
  707. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  708. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  709. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  710. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  711. }
  712. }
  713. }
  714. void r600_pm_misc(struct radeon_device *rdev)
  715. {
  716. int req_ps_idx = rdev->pm.requested_power_state_index;
  717. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  718. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  719. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  720. if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
  721. /* 0xff01 is a flag rather then an actual voltage */
  722. if (voltage->voltage == 0xff01)
  723. return;
  724. if (voltage->voltage != rdev->pm.current_vddc) {
  725. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  726. rdev->pm.current_vddc = voltage->voltage;
  727. DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
  728. }
  729. }
  730. }
  731. bool r600_gui_idle(struct radeon_device *rdev)
  732. {
  733. if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
  734. return false;
  735. else
  736. return true;
  737. }
  738. /* hpd for digital panel detect/disconnect */
  739. bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  740. {
  741. bool connected = false;
  742. if (ASIC_IS_DCE3(rdev)) {
  743. switch (hpd) {
  744. case RADEON_HPD_1:
  745. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  746. connected = true;
  747. break;
  748. case RADEON_HPD_2:
  749. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  750. connected = true;
  751. break;
  752. case RADEON_HPD_3:
  753. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  754. connected = true;
  755. break;
  756. case RADEON_HPD_4:
  757. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  758. connected = true;
  759. break;
  760. /* DCE 3.2 */
  761. case RADEON_HPD_5:
  762. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  763. connected = true;
  764. break;
  765. case RADEON_HPD_6:
  766. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  767. connected = true;
  768. break;
  769. default:
  770. break;
  771. }
  772. } else {
  773. switch (hpd) {
  774. case RADEON_HPD_1:
  775. if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  776. connected = true;
  777. break;
  778. case RADEON_HPD_2:
  779. if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  780. connected = true;
  781. break;
  782. case RADEON_HPD_3:
  783. if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  784. connected = true;
  785. break;
  786. default:
  787. break;
  788. }
  789. }
  790. return connected;
  791. }
  792. void r600_hpd_set_polarity(struct radeon_device *rdev,
  793. enum radeon_hpd_id hpd)
  794. {
  795. u32 tmp;
  796. bool connected = r600_hpd_sense(rdev, hpd);
  797. if (ASIC_IS_DCE3(rdev)) {
  798. switch (hpd) {
  799. case RADEON_HPD_1:
  800. tmp = RREG32(DC_HPD1_INT_CONTROL);
  801. if (connected)
  802. tmp &= ~DC_HPDx_INT_POLARITY;
  803. else
  804. tmp |= DC_HPDx_INT_POLARITY;
  805. WREG32(DC_HPD1_INT_CONTROL, tmp);
  806. break;
  807. case RADEON_HPD_2:
  808. tmp = RREG32(DC_HPD2_INT_CONTROL);
  809. if (connected)
  810. tmp &= ~DC_HPDx_INT_POLARITY;
  811. else
  812. tmp |= DC_HPDx_INT_POLARITY;
  813. WREG32(DC_HPD2_INT_CONTROL, tmp);
  814. break;
  815. case RADEON_HPD_3:
  816. tmp = RREG32(DC_HPD3_INT_CONTROL);
  817. if (connected)
  818. tmp &= ~DC_HPDx_INT_POLARITY;
  819. else
  820. tmp |= DC_HPDx_INT_POLARITY;
  821. WREG32(DC_HPD3_INT_CONTROL, tmp);
  822. break;
  823. case RADEON_HPD_4:
  824. tmp = RREG32(DC_HPD4_INT_CONTROL);
  825. if (connected)
  826. tmp &= ~DC_HPDx_INT_POLARITY;
  827. else
  828. tmp |= DC_HPDx_INT_POLARITY;
  829. WREG32(DC_HPD4_INT_CONTROL, tmp);
  830. break;
  831. case RADEON_HPD_5:
  832. tmp = RREG32(DC_HPD5_INT_CONTROL);
  833. if (connected)
  834. tmp &= ~DC_HPDx_INT_POLARITY;
  835. else
  836. tmp |= DC_HPDx_INT_POLARITY;
  837. WREG32(DC_HPD5_INT_CONTROL, tmp);
  838. break;
  839. /* DCE 3.2 */
  840. case RADEON_HPD_6:
  841. tmp = RREG32(DC_HPD6_INT_CONTROL);
  842. if (connected)
  843. tmp &= ~DC_HPDx_INT_POLARITY;
  844. else
  845. tmp |= DC_HPDx_INT_POLARITY;
  846. WREG32(DC_HPD6_INT_CONTROL, tmp);
  847. break;
  848. default:
  849. break;
  850. }
  851. } else {
  852. switch (hpd) {
  853. case RADEON_HPD_1:
  854. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  855. if (connected)
  856. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  857. else
  858. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  859. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  860. break;
  861. case RADEON_HPD_2:
  862. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  863. if (connected)
  864. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  865. else
  866. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  867. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  868. break;
  869. case RADEON_HPD_3:
  870. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  871. if (connected)
  872. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  873. else
  874. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  875. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  876. break;
  877. default:
  878. break;
  879. }
  880. }
  881. }
  882. void r600_hpd_init(struct radeon_device *rdev)
  883. {
  884. struct drm_device *dev = rdev->ddev;
  885. struct drm_connector *connector;
  886. unsigned enable = 0;
  887. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  888. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  889. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  890. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  891. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  892. * aux dp channel on imac and help (but not completely fix)
  893. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  894. */
  895. continue;
  896. }
  897. if (ASIC_IS_DCE3(rdev)) {
  898. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
  899. if (ASIC_IS_DCE32(rdev))
  900. tmp |= DC_HPDx_EN;
  901. switch (radeon_connector->hpd.hpd) {
  902. case RADEON_HPD_1:
  903. WREG32(DC_HPD1_CONTROL, tmp);
  904. break;
  905. case RADEON_HPD_2:
  906. WREG32(DC_HPD2_CONTROL, tmp);
  907. break;
  908. case RADEON_HPD_3:
  909. WREG32(DC_HPD3_CONTROL, tmp);
  910. break;
  911. case RADEON_HPD_4:
  912. WREG32(DC_HPD4_CONTROL, tmp);
  913. break;
  914. /* DCE 3.2 */
  915. case RADEON_HPD_5:
  916. WREG32(DC_HPD5_CONTROL, tmp);
  917. break;
  918. case RADEON_HPD_6:
  919. WREG32(DC_HPD6_CONTROL, tmp);
  920. break;
  921. default:
  922. break;
  923. }
  924. } else {
  925. switch (radeon_connector->hpd.hpd) {
  926. case RADEON_HPD_1:
  927. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  928. break;
  929. case RADEON_HPD_2:
  930. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  931. break;
  932. case RADEON_HPD_3:
  933. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  934. break;
  935. default:
  936. break;
  937. }
  938. }
  939. enable |= 1 << radeon_connector->hpd.hpd;
  940. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  941. }
  942. radeon_irq_kms_enable_hpd(rdev, enable);
  943. }
  944. void r600_hpd_fini(struct radeon_device *rdev)
  945. {
  946. struct drm_device *dev = rdev->ddev;
  947. struct drm_connector *connector;
  948. unsigned disable = 0;
  949. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  950. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  951. if (ASIC_IS_DCE3(rdev)) {
  952. switch (radeon_connector->hpd.hpd) {
  953. case RADEON_HPD_1:
  954. WREG32(DC_HPD1_CONTROL, 0);
  955. break;
  956. case RADEON_HPD_2:
  957. WREG32(DC_HPD2_CONTROL, 0);
  958. break;
  959. case RADEON_HPD_3:
  960. WREG32(DC_HPD3_CONTROL, 0);
  961. break;
  962. case RADEON_HPD_4:
  963. WREG32(DC_HPD4_CONTROL, 0);
  964. break;
  965. /* DCE 3.2 */
  966. case RADEON_HPD_5:
  967. WREG32(DC_HPD5_CONTROL, 0);
  968. break;
  969. case RADEON_HPD_6:
  970. WREG32(DC_HPD6_CONTROL, 0);
  971. break;
  972. default:
  973. break;
  974. }
  975. } else {
  976. switch (radeon_connector->hpd.hpd) {
  977. case RADEON_HPD_1:
  978. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
  979. break;
  980. case RADEON_HPD_2:
  981. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
  982. break;
  983. case RADEON_HPD_3:
  984. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
  985. break;
  986. default:
  987. break;
  988. }
  989. }
  990. disable |= 1 << radeon_connector->hpd.hpd;
  991. }
  992. radeon_irq_kms_disable_hpd(rdev, disable);
  993. }
  994. /*
  995. * R600 PCIE GART
  996. */
  997. void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
  998. {
  999. unsigned i;
  1000. u32 tmp;
  1001. /* flush hdp cache so updates hit vram */
  1002. if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
  1003. !(rdev->flags & RADEON_IS_AGP)) {
  1004. void __iomem *ptr = (void *)rdev->gart.ptr;
  1005. u32 tmp;
  1006. /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
  1007. * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
  1008. * This seems to cause problems on some AGP cards. Just use the old
  1009. * method for them.
  1010. */
  1011. WREG32(HDP_DEBUG1, 0);
  1012. tmp = readl((void __iomem *)ptr);
  1013. } else
  1014. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  1015. WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
  1016. WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
  1017. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  1018. for (i = 0; i < rdev->usec_timeout; i++) {
  1019. /* read MC_STATUS */
  1020. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  1021. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  1022. if (tmp == 2) {
  1023. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  1024. return;
  1025. }
  1026. if (tmp) {
  1027. return;
  1028. }
  1029. udelay(1);
  1030. }
  1031. }
  1032. int r600_pcie_gart_init(struct radeon_device *rdev)
  1033. {
  1034. int r;
  1035. if (rdev->gart.robj) {
  1036. WARN(1, "R600 PCIE GART already initialized\n");
  1037. return 0;
  1038. }
  1039. /* Initialize common gart structure */
  1040. r = radeon_gart_init(rdev);
  1041. if (r)
  1042. return r;
  1043. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  1044. return radeon_gart_table_vram_alloc(rdev);
  1045. }
  1046. static int r600_pcie_gart_enable(struct radeon_device *rdev)
  1047. {
  1048. u32 tmp;
  1049. int r, i;
  1050. if (rdev->gart.robj == NULL) {
  1051. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  1052. return -EINVAL;
  1053. }
  1054. r = radeon_gart_table_vram_pin(rdev);
  1055. if (r)
  1056. return r;
  1057. /* Setup L2 cache */
  1058. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  1059. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1060. EFFECTIVE_L2_QUEUE_SIZE(7));
  1061. WREG32(VM_L2_CNTL2, 0);
  1062. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  1063. /* Setup TLB control */
  1064. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  1065. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1066. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  1067. ENABLE_WAIT_L2_QUERY;
  1068. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  1069. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  1070. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  1071. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  1072. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  1073. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  1074. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  1075. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  1076. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  1077. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  1078. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  1079. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  1080. WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL, tmp);
  1081. WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL, tmp);
  1082. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  1083. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  1084. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  1085. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  1086. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  1087. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  1088. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  1089. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  1090. (u32)(rdev->dummy_page.addr >> 12));
  1091. for (i = 1; i < 7; i++)
  1092. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  1093. r600_pcie_gart_tlb_flush(rdev);
  1094. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  1095. (unsigned)(rdev->mc.gtt_size >> 20),
  1096. (unsigned long long)rdev->gart.table_addr);
  1097. rdev->gart.ready = true;
  1098. return 0;
  1099. }
  1100. static void r600_pcie_gart_disable(struct radeon_device *rdev)
  1101. {
  1102. u32 tmp;
  1103. int i;
  1104. /* Disable all tables */
  1105. for (i = 0; i < 7; i++)
  1106. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  1107. /* Disable L2 cache */
  1108. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  1109. EFFECTIVE_L2_QUEUE_SIZE(7));
  1110. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  1111. /* Setup L1 TLB control */
  1112. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  1113. ENABLE_WAIT_L2_QUERY;
  1114. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  1115. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  1116. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  1117. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  1118. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  1119. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  1120. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  1121. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  1122. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
  1123. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
  1124. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  1125. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  1126. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
  1127. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  1128. WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL, tmp);
  1129. WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL, tmp);
  1130. radeon_gart_table_vram_unpin(rdev);
  1131. }
  1132. static void r600_pcie_gart_fini(struct radeon_device *rdev)
  1133. {
  1134. radeon_gart_fini(rdev);
  1135. r600_pcie_gart_disable(rdev);
  1136. radeon_gart_table_vram_free(rdev);
  1137. }
  1138. static void r600_agp_enable(struct radeon_device *rdev)
  1139. {
  1140. u32 tmp;
  1141. int i;
  1142. /* Setup L2 cache */
  1143. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  1144. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1145. EFFECTIVE_L2_QUEUE_SIZE(7));
  1146. WREG32(VM_L2_CNTL2, 0);
  1147. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  1148. /* Setup TLB control */
  1149. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  1150. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1151. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  1152. ENABLE_WAIT_L2_QUERY;
  1153. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  1154. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  1155. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  1156. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  1157. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  1158. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  1159. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  1160. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  1161. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  1162. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  1163. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  1164. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  1165. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  1166. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  1167. for (i = 0; i < 7; i++)
  1168. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  1169. }
  1170. int r600_mc_wait_for_idle(struct radeon_device *rdev)
  1171. {
  1172. unsigned i;
  1173. u32 tmp;
  1174. for (i = 0; i < rdev->usec_timeout; i++) {
  1175. /* read MC_STATUS */
  1176. tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
  1177. if (!tmp)
  1178. return 0;
  1179. udelay(1);
  1180. }
  1181. return -1;
  1182. }
  1183. uint32_t rs780_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  1184. {
  1185. unsigned long flags;
  1186. uint32_t r;
  1187. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  1188. WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg));
  1189. r = RREG32(R_0028FC_MC_DATA);
  1190. WREG32(R_0028F8_MC_INDEX, ~C_0028F8_MC_IND_ADDR);
  1191. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  1192. return r;
  1193. }
  1194. void rs780_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1195. {
  1196. unsigned long flags;
  1197. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  1198. WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg) |
  1199. S_0028F8_MC_IND_WR_EN(1));
  1200. WREG32(R_0028FC_MC_DATA, v);
  1201. WREG32(R_0028F8_MC_INDEX, 0x7F);
  1202. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  1203. }
  1204. static void r600_mc_program(struct radeon_device *rdev)
  1205. {
  1206. struct rv515_mc_save save;
  1207. u32 tmp;
  1208. int i, j;
  1209. /* Initialize HDP */
  1210. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1211. WREG32((0x2c14 + j), 0x00000000);
  1212. WREG32((0x2c18 + j), 0x00000000);
  1213. WREG32((0x2c1c + j), 0x00000000);
  1214. WREG32((0x2c20 + j), 0x00000000);
  1215. WREG32((0x2c24 + j), 0x00000000);
  1216. }
  1217. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  1218. rv515_mc_stop(rdev, &save);
  1219. if (r600_mc_wait_for_idle(rdev)) {
  1220. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1221. }
  1222. /* Lockout access through VGA aperture (doesn't exist before R600) */
  1223. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  1224. /* Update configuration */
  1225. if (rdev->flags & RADEON_IS_AGP) {
  1226. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  1227. /* VRAM before AGP */
  1228. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1229. rdev->mc.vram_start >> 12);
  1230. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1231. rdev->mc.gtt_end >> 12);
  1232. } else {
  1233. /* VRAM after AGP */
  1234. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1235. rdev->mc.gtt_start >> 12);
  1236. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1237. rdev->mc.vram_end >> 12);
  1238. }
  1239. } else {
  1240. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
  1241. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
  1242. }
  1243. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  1244. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  1245. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  1246. WREG32(MC_VM_FB_LOCATION, tmp);
  1247. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  1248. WREG32(HDP_NONSURFACE_INFO, (2 << 7));
  1249. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  1250. if (rdev->flags & RADEON_IS_AGP) {
  1251. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
  1252. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
  1253. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  1254. } else {
  1255. WREG32(MC_VM_AGP_BASE, 0);
  1256. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  1257. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  1258. }
  1259. if (r600_mc_wait_for_idle(rdev)) {
  1260. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1261. }
  1262. rv515_mc_resume(rdev, &save);
  1263. /* we need to own VRAM, so turn off the VGA renderer here
  1264. * to stop it overwriting our objects */
  1265. rv515_vga_render_disable(rdev);
  1266. }
  1267. /**
  1268. * r600_vram_gtt_location - try to find VRAM & GTT location
  1269. * @rdev: radeon device structure holding all necessary informations
  1270. * @mc: memory controller structure holding memory informations
  1271. *
  1272. * Function will place try to place VRAM at same place as in CPU (PCI)
  1273. * address space as some GPU seems to have issue when we reprogram at
  1274. * different address space.
  1275. *
  1276. * If there is not enough space to fit the unvisible VRAM after the
  1277. * aperture then we limit the VRAM size to the aperture.
  1278. *
  1279. * If we are using AGP then place VRAM adjacent to AGP aperture are we need
  1280. * them to be in one from GPU point of view so that we can program GPU to
  1281. * catch access outside them (weird GPU policy see ??).
  1282. *
  1283. * This function will never fails, worst case are limiting VRAM or GTT.
  1284. *
  1285. * Note: GTT start, end, size should be initialized before calling this
  1286. * function on AGP platform.
  1287. */
  1288. static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  1289. {
  1290. u64 size_bf, size_af;
  1291. if (mc->mc_vram_size > 0xE0000000) {
  1292. /* leave room for at least 512M GTT */
  1293. dev_warn(rdev->dev, "limiting VRAM\n");
  1294. mc->real_vram_size = 0xE0000000;
  1295. mc->mc_vram_size = 0xE0000000;
  1296. }
  1297. if (rdev->flags & RADEON_IS_AGP) {
  1298. size_bf = mc->gtt_start;
  1299. size_af = mc->mc_mask - mc->gtt_end;
  1300. if (size_bf > size_af) {
  1301. if (mc->mc_vram_size > size_bf) {
  1302. dev_warn(rdev->dev, "limiting VRAM\n");
  1303. mc->real_vram_size = size_bf;
  1304. mc->mc_vram_size = size_bf;
  1305. }
  1306. mc->vram_start = mc->gtt_start - mc->mc_vram_size;
  1307. } else {
  1308. if (mc->mc_vram_size > size_af) {
  1309. dev_warn(rdev->dev, "limiting VRAM\n");
  1310. mc->real_vram_size = size_af;
  1311. mc->mc_vram_size = size_af;
  1312. }
  1313. mc->vram_start = mc->gtt_end + 1;
  1314. }
  1315. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  1316. dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
  1317. mc->mc_vram_size >> 20, mc->vram_start,
  1318. mc->vram_end, mc->real_vram_size >> 20);
  1319. } else {
  1320. u64 base = 0;
  1321. if (rdev->flags & RADEON_IS_IGP) {
  1322. base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
  1323. base <<= 24;
  1324. }
  1325. radeon_vram_location(rdev, &rdev->mc, base);
  1326. rdev->mc.gtt_base_align = 0;
  1327. radeon_gtt_location(rdev, mc);
  1328. }
  1329. }
  1330. static int r600_mc_init(struct radeon_device *rdev)
  1331. {
  1332. u32 tmp;
  1333. int chansize, numchan;
  1334. uint32_t h_addr, l_addr;
  1335. unsigned long long k8_addr;
  1336. /* Get VRAM informations */
  1337. rdev->mc.vram_is_ddr = true;
  1338. tmp = RREG32(RAMCFG);
  1339. if (tmp & CHANSIZE_OVERRIDE) {
  1340. chansize = 16;
  1341. } else if (tmp & CHANSIZE_MASK) {
  1342. chansize = 64;
  1343. } else {
  1344. chansize = 32;
  1345. }
  1346. tmp = RREG32(CHMAP);
  1347. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1348. case 0:
  1349. default:
  1350. numchan = 1;
  1351. break;
  1352. case 1:
  1353. numchan = 2;
  1354. break;
  1355. case 2:
  1356. numchan = 4;
  1357. break;
  1358. case 3:
  1359. numchan = 8;
  1360. break;
  1361. }
  1362. rdev->mc.vram_width = numchan * chansize;
  1363. /* Could aper size report 0 ? */
  1364. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  1365. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  1366. /* Setup GPU memory space */
  1367. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  1368. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  1369. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  1370. r600_vram_gtt_location(rdev, &rdev->mc);
  1371. if (rdev->flags & RADEON_IS_IGP) {
  1372. rs690_pm_info(rdev);
  1373. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  1374. if (rdev->family == CHIP_RS780 || rdev->family == CHIP_RS880) {
  1375. /* Use K8 direct mapping for fast fb access. */
  1376. rdev->fastfb_working = false;
  1377. h_addr = G_000012_K8_ADDR_EXT(RREG32_MC(R_000012_MC_MISC_UMA_CNTL));
  1378. l_addr = RREG32_MC(R_000011_K8_FB_LOCATION);
  1379. k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
  1380. #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
  1381. if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
  1382. #endif
  1383. {
  1384. /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
  1385. * memory is present.
  1386. */
  1387. if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
  1388. DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
  1389. (unsigned long long)rdev->mc.aper_base, k8_addr);
  1390. rdev->mc.aper_base = (resource_size_t)k8_addr;
  1391. rdev->fastfb_working = true;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. radeon_update_bandwidth_info(rdev);
  1397. return 0;
  1398. }
  1399. int r600_vram_scratch_init(struct radeon_device *rdev)
  1400. {
  1401. int r;
  1402. if (rdev->vram_scratch.robj == NULL) {
  1403. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
  1404. PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
  1405. 0, NULL, NULL, &rdev->vram_scratch.robj);
  1406. if (r) {
  1407. return r;
  1408. }
  1409. }
  1410. r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
  1411. if (unlikely(r != 0))
  1412. return r;
  1413. r = radeon_bo_pin(rdev->vram_scratch.robj,
  1414. RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
  1415. if (r) {
  1416. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1417. return r;
  1418. }
  1419. r = radeon_bo_kmap(rdev->vram_scratch.robj,
  1420. (void **)&rdev->vram_scratch.ptr);
  1421. if (r)
  1422. radeon_bo_unpin(rdev->vram_scratch.robj);
  1423. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1424. return r;
  1425. }
  1426. void r600_vram_scratch_fini(struct radeon_device *rdev)
  1427. {
  1428. int r;
  1429. if (rdev->vram_scratch.robj == NULL) {
  1430. return;
  1431. }
  1432. r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
  1433. if (likely(r == 0)) {
  1434. radeon_bo_kunmap(rdev->vram_scratch.robj);
  1435. radeon_bo_unpin(rdev->vram_scratch.robj);
  1436. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1437. }
  1438. radeon_bo_unref(&rdev->vram_scratch.robj);
  1439. }
  1440. void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung)
  1441. {
  1442. u32 tmp = RREG32(R600_BIOS_3_SCRATCH);
  1443. if (hung)
  1444. tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1445. else
  1446. tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1447. WREG32(R600_BIOS_3_SCRATCH, tmp);
  1448. }
  1449. static void r600_print_gpu_status_regs(struct radeon_device *rdev)
  1450. {
  1451. dev_info(rdev->dev, " R_008010_GRBM_STATUS = 0x%08X\n",
  1452. RREG32(R_008010_GRBM_STATUS));
  1453. dev_info(rdev->dev, " R_008014_GRBM_STATUS2 = 0x%08X\n",
  1454. RREG32(R_008014_GRBM_STATUS2));
  1455. dev_info(rdev->dev, " R_000E50_SRBM_STATUS = 0x%08X\n",
  1456. RREG32(R_000E50_SRBM_STATUS));
  1457. dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
  1458. RREG32(CP_STALLED_STAT1));
  1459. dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
  1460. RREG32(CP_STALLED_STAT2));
  1461. dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
  1462. RREG32(CP_BUSY_STAT));
  1463. dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
  1464. RREG32(CP_STAT));
  1465. dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
  1466. RREG32(DMA_STATUS_REG));
  1467. }
  1468. static bool r600_is_display_hung(struct radeon_device *rdev)
  1469. {
  1470. u32 crtc_hung = 0;
  1471. u32 crtc_status[2];
  1472. u32 i, j, tmp;
  1473. for (i = 0; i < rdev->num_crtc; i++) {
  1474. if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[i]) & AVIVO_CRTC_EN) {
  1475. crtc_status[i] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  1476. crtc_hung |= (1 << i);
  1477. }
  1478. }
  1479. for (j = 0; j < 10; j++) {
  1480. for (i = 0; i < rdev->num_crtc; i++) {
  1481. if (crtc_hung & (1 << i)) {
  1482. tmp = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  1483. if (tmp != crtc_status[i])
  1484. crtc_hung &= ~(1 << i);
  1485. }
  1486. }
  1487. if (crtc_hung == 0)
  1488. return false;
  1489. udelay(100);
  1490. }
  1491. return true;
  1492. }
  1493. u32 r600_gpu_check_soft_reset(struct radeon_device *rdev)
  1494. {
  1495. u32 reset_mask = 0;
  1496. u32 tmp;
  1497. /* GRBM_STATUS */
  1498. tmp = RREG32(R_008010_GRBM_STATUS);
  1499. if (rdev->family >= CHIP_RV770) {
  1500. if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
  1501. G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
  1502. G_008010_TA_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
  1503. G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
  1504. G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
  1505. reset_mask |= RADEON_RESET_GFX;
  1506. } else {
  1507. if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
  1508. G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
  1509. G_008010_TA03_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
  1510. G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
  1511. G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
  1512. reset_mask |= RADEON_RESET_GFX;
  1513. }
  1514. if (G_008010_CF_RQ_PENDING(tmp) | G_008010_PF_RQ_PENDING(tmp) |
  1515. G_008010_CP_BUSY(tmp) | G_008010_CP_COHERENCY_BUSY(tmp))
  1516. reset_mask |= RADEON_RESET_CP;
  1517. if (G_008010_GRBM_EE_BUSY(tmp))
  1518. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  1519. /* DMA_STATUS_REG */
  1520. tmp = RREG32(DMA_STATUS_REG);
  1521. if (!(tmp & DMA_IDLE))
  1522. reset_mask |= RADEON_RESET_DMA;
  1523. /* SRBM_STATUS */
  1524. tmp = RREG32(R_000E50_SRBM_STATUS);
  1525. if (G_000E50_RLC_RQ_PENDING(tmp) | G_000E50_RLC_BUSY(tmp))
  1526. reset_mask |= RADEON_RESET_RLC;
  1527. if (G_000E50_IH_BUSY(tmp))
  1528. reset_mask |= RADEON_RESET_IH;
  1529. if (G_000E50_SEM_BUSY(tmp))
  1530. reset_mask |= RADEON_RESET_SEM;
  1531. if (G_000E50_GRBM_RQ_PENDING(tmp))
  1532. reset_mask |= RADEON_RESET_GRBM;
  1533. if (G_000E50_VMC_BUSY(tmp))
  1534. reset_mask |= RADEON_RESET_VMC;
  1535. if (G_000E50_MCB_BUSY(tmp) | G_000E50_MCDZ_BUSY(tmp) |
  1536. G_000E50_MCDY_BUSY(tmp) | G_000E50_MCDX_BUSY(tmp) |
  1537. G_000E50_MCDW_BUSY(tmp))
  1538. reset_mask |= RADEON_RESET_MC;
  1539. if (r600_is_display_hung(rdev))
  1540. reset_mask |= RADEON_RESET_DISPLAY;
  1541. /* Skip MC reset as it's mostly likely not hung, just busy */
  1542. if (reset_mask & RADEON_RESET_MC) {
  1543. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  1544. reset_mask &= ~RADEON_RESET_MC;
  1545. }
  1546. return reset_mask;
  1547. }
  1548. static void r600_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  1549. {
  1550. struct rv515_mc_save save;
  1551. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  1552. u32 tmp;
  1553. if (reset_mask == 0)
  1554. return;
  1555. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  1556. r600_print_gpu_status_regs(rdev);
  1557. /* Disable CP parsing/prefetching */
  1558. if (rdev->family >= CHIP_RV770)
  1559. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
  1560. else
  1561. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1562. /* disable the RLC */
  1563. WREG32(RLC_CNTL, 0);
  1564. if (reset_mask & RADEON_RESET_DMA) {
  1565. /* Disable DMA */
  1566. tmp = RREG32(DMA_RB_CNTL);
  1567. tmp &= ~DMA_RB_ENABLE;
  1568. WREG32(DMA_RB_CNTL, tmp);
  1569. }
  1570. mdelay(50);
  1571. rv515_mc_stop(rdev, &save);
  1572. if (r600_mc_wait_for_idle(rdev)) {
  1573. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1574. }
  1575. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  1576. if (rdev->family >= CHIP_RV770)
  1577. grbm_soft_reset |= S_008020_SOFT_RESET_DB(1) |
  1578. S_008020_SOFT_RESET_CB(1) |
  1579. S_008020_SOFT_RESET_PA(1) |
  1580. S_008020_SOFT_RESET_SC(1) |
  1581. S_008020_SOFT_RESET_SPI(1) |
  1582. S_008020_SOFT_RESET_SX(1) |
  1583. S_008020_SOFT_RESET_SH(1) |
  1584. S_008020_SOFT_RESET_TC(1) |
  1585. S_008020_SOFT_RESET_TA(1) |
  1586. S_008020_SOFT_RESET_VC(1) |
  1587. S_008020_SOFT_RESET_VGT(1);
  1588. else
  1589. grbm_soft_reset |= S_008020_SOFT_RESET_CR(1) |
  1590. S_008020_SOFT_RESET_DB(1) |
  1591. S_008020_SOFT_RESET_CB(1) |
  1592. S_008020_SOFT_RESET_PA(1) |
  1593. S_008020_SOFT_RESET_SC(1) |
  1594. S_008020_SOFT_RESET_SMX(1) |
  1595. S_008020_SOFT_RESET_SPI(1) |
  1596. S_008020_SOFT_RESET_SX(1) |
  1597. S_008020_SOFT_RESET_SH(1) |
  1598. S_008020_SOFT_RESET_TC(1) |
  1599. S_008020_SOFT_RESET_TA(1) |
  1600. S_008020_SOFT_RESET_VC(1) |
  1601. S_008020_SOFT_RESET_VGT(1);
  1602. }
  1603. if (reset_mask & RADEON_RESET_CP) {
  1604. grbm_soft_reset |= S_008020_SOFT_RESET_CP(1) |
  1605. S_008020_SOFT_RESET_VGT(1);
  1606. srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
  1607. }
  1608. if (reset_mask & RADEON_RESET_DMA) {
  1609. if (rdev->family >= CHIP_RV770)
  1610. srbm_soft_reset |= RV770_SOFT_RESET_DMA;
  1611. else
  1612. srbm_soft_reset |= SOFT_RESET_DMA;
  1613. }
  1614. if (reset_mask & RADEON_RESET_RLC)
  1615. srbm_soft_reset |= S_000E60_SOFT_RESET_RLC(1);
  1616. if (reset_mask & RADEON_RESET_SEM)
  1617. srbm_soft_reset |= S_000E60_SOFT_RESET_SEM(1);
  1618. if (reset_mask & RADEON_RESET_IH)
  1619. srbm_soft_reset |= S_000E60_SOFT_RESET_IH(1);
  1620. if (reset_mask & RADEON_RESET_GRBM)
  1621. srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
  1622. if (!(rdev->flags & RADEON_IS_IGP)) {
  1623. if (reset_mask & RADEON_RESET_MC)
  1624. srbm_soft_reset |= S_000E60_SOFT_RESET_MC(1);
  1625. }
  1626. if (reset_mask & RADEON_RESET_VMC)
  1627. srbm_soft_reset |= S_000E60_SOFT_RESET_VMC(1);
  1628. if (grbm_soft_reset) {
  1629. tmp = RREG32(R_008020_GRBM_SOFT_RESET);
  1630. tmp |= grbm_soft_reset;
  1631. dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  1632. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  1633. tmp = RREG32(R_008020_GRBM_SOFT_RESET);
  1634. udelay(50);
  1635. tmp &= ~grbm_soft_reset;
  1636. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  1637. tmp = RREG32(R_008020_GRBM_SOFT_RESET);
  1638. }
  1639. if (srbm_soft_reset) {
  1640. tmp = RREG32(SRBM_SOFT_RESET);
  1641. tmp |= srbm_soft_reset;
  1642. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  1643. WREG32(SRBM_SOFT_RESET, tmp);
  1644. tmp = RREG32(SRBM_SOFT_RESET);
  1645. udelay(50);
  1646. tmp &= ~srbm_soft_reset;
  1647. WREG32(SRBM_SOFT_RESET, tmp);
  1648. tmp = RREG32(SRBM_SOFT_RESET);
  1649. }
  1650. /* Wait a little for things to settle down */
  1651. mdelay(1);
  1652. rv515_mc_resume(rdev, &save);
  1653. udelay(50);
  1654. r600_print_gpu_status_regs(rdev);
  1655. }
  1656. static void r600_gpu_pci_config_reset(struct radeon_device *rdev)
  1657. {
  1658. struct rv515_mc_save save;
  1659. u32 tmp, i;
  1660. dev_info(rdev->dev, "GPU pci config reset\n");
  1661. /* disable dpm? */
  1662. /* Disable CP parsing/prefetching */
  1663. if (rdev->family >= CHIP_RV770)
  1664. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
  1665. else
  1666. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1667. /* disable the RLC */
  1668. WREG32(RLC_CNTL, 0);
  1669. /* Disable DMA */
  1670. tmp = RREG32(DMA_RB_CNTL);
  1671. tmp &= ~DMA_RB_ENABLE;
  1672. WREG32(DMA_RB_CNTL, tmp);
  1673. mdelay(50);
  1674. /* set mclk/sclk to bypass */
  1675. if (rdev->family >= CHIP_RV770)
  1676. rv770_set_clk_bypass_mode(rdev);
  1677. /* disable BM */
  1678. pci_clear_master(rdev->pdev);
  1679. /* disable mem access */
  1680. rv515_mc_stop(rdev, &save);
  1681. if (r600_mc_wait_for_idle(rdev)) {
  1682. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1683. }
  1684. /* BIF reset workaround. Not sure if this is needed on 6xx */
  1685. tmp = RREG32(BUS_CNTL);
  1686. tmp |= VGA_COHE_SPEC_TIMER_DIS;
  1687. WREG32(BUS_CNTL, tmp);
  1688. tmp = RREG32(BIF_SCRATCH0);
  1689. /* reset */
  1690. radeon_pci_config_reset(rdev);
  1691. mdelay(1);
  1692. /* BIF reset workaround. Not sure if this is needed on 6xx */
  1693. tmp = SOFT_RESET_BIF;
  1694. WREG32(SRBM_SOFT_RESET, tmp);
  1695. mdelay(1);
  1696. WREG32(SRBM_SOFT_RESET, 0);
  1697. /* wait for asic to come out of reset */
  1698. for (i = 0; i < rdev->usec_timeout; i++) {
  1699. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  1700. break;
  1701. udelay(1);
  1702. }
  1703. }
  1704. int r600_asic_reset(struct radeon_device *rdev)
  1705. {
  1706. u32 reset_mask;
  1707. reset_mask = r600_gpu_check_soft_reset(rdev);
  1708. if (reset_mask)
  1709. r600_set_bios_scratch_engine_hung(rdev, true);
  1710. /* try soft reset */
  1711. r600_gpu_soft_reset(rdev, reset_mask);
  1712. reset_mask = r600_gpu_check_soft_reset(rdev);
  1713. /* try pci config reset */
  1714. if (reset_mask && radeon_hard_reset)
  1715. r600_gpu_pci_config_reset(rdev);
  1716. reset_mask = r600_gpu_check_soft_reset(rdev);
  1717. if (!reset_mask)
  1718. r600_set_bios_scratch_engine_hung(rdev, false);
  1719. return 0;
  1720. }
  1721. /**
  1722. * r600_gfx_is_lockup - Check if the GFX engine is locked up
  1723. *
  1724. * @rdev: radeon_device pointer
  1725. * @ring: radeon_ring structure holding ring information
  1726. *
  1727. * Check if the GFX engine is locked up.
  1728. * Returns true if the engine appears to be locked up, false if not.
  1729. */
  1730. bool r600_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  1731. {
  1732. u32 reset_mask = r600_gpu_check_soft_reset(rdev);
  1733. if (!(reset_mask & (RADEON_RESET_GFX |
  1734. RADEON_RESET_COMPUTE |
  1735. RADEON_RESET_CP))) {
  1736. radeon_ring_lockup_update(rdev, ring);
  1737. return false;
  1738. }
  1739. return radeon_ring_test_lockup(rdev, ring);
  1740. }
  1741. u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  1742. u32 tiling_pipe_num,
  1743. u32 max_rb_num,
  1744. u32 total_max_rb_num,
  1745. u32 disabled_rb_mask)
  1746. {
  1747. u32 rendering_pipe_num, rb_num_width, req_rb_num;
  1748. u32 pipe_rb_ratio, pipe_rb_remain, tmp;
  1749. u32 data = 0, mask = 1 << (max_rb_num - 1);
  1750. unsigned i, j;
  1751. /* mask out the RBs that don't exist on that asic */
  1752. tmp = disabled_rb_mask | ((0xff << max_rb_num) & 0xff);
  1753. /* make sure at least one RB is available */
  1754. if ((tmp & 0xff) != 0xff)
  1755. disabled_rb_mask = tmp;
  1756. rendering_pipe_num = 1 << tiling_pipe_num;
  1757. req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
  1758. BUG_ON(rendering_pipe_num < req_rb_num);
  1759. pipe_rb_ratio = rendering_pipe_num / req_rb_num;
  1760. pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
  1761. if (rdev->family <= CHIP_RV740) {
  1762. /* r6xx/r7xx */
  1763. rb_num_width = 2;
  1764. } else {
  1765. /* eg+ */
  1766. rb_num_width = 4;
  1767. }
  1768. for (i = 0; i < max_rb_num; i++) {
  1769. if (!(mask & disabled_rb_mask)) {
  1770. for (j = 0; j < pipe_rb_ratio; j++) {
  1771. data <<= rb_num_width;
  1772. data |= max_rb_num - i - 1;
  1773. }
  1774. if (pipe_rb_remain) {
  1775. data <<= rb_num_width;
  1776. data |= max_rb_num - i - 1;
  1777. pipe_rb_remain--;
  1778. }
  1779. }
  1780. mask >>= 1;
  1781. }
  1782. return data;
  1783. }
  1784. int r600_count_pipe_bits(uint32_t val)
  1785. {
  1786. return hweight32(val);
  1787. }
  1788. static void r600_gpu_init(struct radeon_device *rdev)
  1789. {
  1790. u32 tiling_config;
  1791. u32 ramcfg;
  1792. u32 cc_gc_shader_pipe_config;
  1793. u32 tmp;
  1794. int i, j;
  1795. u32 sq_config;
  1796. u32 sq_gpr_resource_mgmt_1 = 0;
  1797. u32 sq_gpr_resource_mgmt_2 = 0;
  1798. u32 sq_thread_resource_mgmt = 0;
  1799. u32 sq_stack_resource_mgmt_1 = 0;
  1800. u32 sq_stack_resource_mgmt_2 = 0;
  1801. u32 disabled_rb_mask;
  1802. rdev->config.r600.tiling_group_size = 256;
  1803. switch (rdev->family) {
  1804. case CHIP_R600:
  1805. rdev->config.r600.max_pipes = 4;
  1806. rdev->config.r600.max_tile_pipes = 8;
  1807. rdev->config.r600.max_simds = 4;
  1808. rdev->config.r600.max_backends = 4;
  1809. rdev->config.r600.max_gprs = 256;
  1810. rdev->config.r600.max_threads = 192;
  1811. rdev->config.r600.max_stack_entries = 256;
  1812. rdev->config.r600.max_hw_contexts = 8;
  1813. rdev->config.r600.max_gs_threads = 16;
  1814. rdev->config.r600.sx_max_export_size = 128;
  1815. rdev->config.r600.sx_max_export_pos_size = 16;
  1816. rdev->config.r600.sx_max_export_smx_size = 128;
  1817. rdev->config.r600.sq_num_cf_insts = 2;
  1818. break;
  1819. case CHIP_RV630:
  1820. case CHIP_RV635:
  1821. rdev->config.r600.max_pipes = 2;
  1822. rdev->config.r600.max_tile_pipes = 2;
  1823. rdev->config.r600.max_simds = 3;
  1824. rdev->config.r600.max_backends = 1;
  1825. rdev->config.r600.max_gprs = 128;
  1826. rdev->config.r600.max_threads = 192;
  1827. rdev->config.r600.max_stack_entries = 128;
  1828. rdev->config.r600.max_hw_contexts = 8;
  1829. rdev->config.r600.max_gs_threads = 4;
  1830. rdev->config.r600.sx_max_export_size = 128;
  1831. rdev->config.r600.sx_max_export_pos_size = 16;
  1832. rdev->config.r600.sx_max_export_smx_size = 128;
  1833. rdev->config.r600.sq_num_cf_insts = 2;
  1834. break;
  1835. case CHIP_RV610:
  1836. case CHIP_RV620:
  1837. case CHIP_RS780:
  1838. case CHIP_RS880:
  1839. rdev->config.r600.max_pipes = 1;
  1840. rdev->config.r600.max_tile_pipes = 1;
  1841. rdev->config.r600.max_simds = 2;
  1842. rdev->config.r600.max_backends = 1;
  1843. rdev->config.r600.max_gprs = 128;
  1844. rdev->config.r600.max_threads = 192;
  1845. rdev->config.r600.max_stack_entries = 128;
  1846. rdev->config.r600.max_hw_contexts = 4;
  1847. rdev->config.r600.max_gs_threads = 4;
  1848. rdev->config.r600.sx_max_export_size = 128;
  1849. rdev->config.r600.sx_max_export_pos_size = 16;
  1850. rdev->config.r600.sx_max_export_smx_size = 128;
  1851. rdev->config.r600.sq_num_cf_insts = 1;
  1852. break;
  1853. case CHIP_RV670:
  1854. rdev->config.r600.max_pipes = 4;
  1855. rdev->config.r600.max_tile_pipes = 4;
  1856. rdev->config.r600.max_simds = 4;
  1857. rdev->config.r600.max_backends = 4;
  1858. rdev->config.r600.max_gprs = 192;
  1859. rdev->config.r600.max_threads = 192;
  1860. rdev->config.r600.max_stack_entries = 256;
  1861. rdev->config.r600.max_hw_contexts = 8;
  1862. rdev->config.r600.max_gs_threads = 16;
  1863. rdev->config.r600.sx_max_export_size = 128;
  1864. rdev->config.r600.sx_max_export_pos_size = 16;
  1865. rdev->config.r600.sx_max_export_smx_size = 128;
  1866. rdev->config.r600.sq_num_cf_insts = 2;
  1867. break;
  1868. default:
  1869. break;
  1870. }
  1871. /* Initialize HDP */
  1872. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1873. WREG32((0x2c14 + j), 0x00000000);
  1874. WREG32((0x2c18 + j), 0x00000000);
  1875. WREG32((0x2c1c + j), 0x00000000);
  1876. WREG32((0x2c20 + j), 0x00000000);
  1877. WREG32((0x2c24 + j), 0x00000000);
  1878. }
  1879. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  1880. /* Setup tiling */
  1881. tiling_config = 0;
  1882. ramcfg = RREG32(RAMCFG);
  1883. switch (rdev->config.r600.max_tile_pipes) {
  1884. case 1:
  1885. tiling_config |= PIPE_TILING(0);
  1886. break;
  1887. case 2:
  1888. tiling_config |= PIPE_TILING(1);
  1889. break;
  1890. case 4:
  1891. tiling_config |= PIPE_TILING(2);
  1892. break;
  1893. case 8:
  1894. tiling_config |= PIPE_TILING(3);
  1895. break;
  1896. default:
  1897. break;
  1898. }
  1899. rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
  1900. rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1901. tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1902. tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
  1903. tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  1904. if (tmp > 3) {
  1905. tiling_config |= ROW_TILING(3);
  1906. tiling_config |= SAMPLE_SPLIT(3);
  1907. } else {
  1908. tiling_config |= ROW_TILING(tmp);
  1909. tiling_config |= SAMPLE_SPLIT(tmp);
  1910. }
  1911. tiling_config |= BANK_SWAPS(1);
  1912. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
  1913. tmp = rdev->config.r600.max_simds -
  1914. r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
  1915. rdev->config.r600.active_simds = tmp;
  1916. disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
  1917. tmp = 0;
  1918. for (i = 0; i < rdev->config.r600.max_backends; i++)
  1919. tmp |= (1 << i);
  1920. /* if all the backends are disabled, fix it up here */
  1921. if ((disabled_rb_mask & tmp) == tmp) {
  1922. for (i = 0; i < rdev->config.r600.max_backends; i++)
  1923. disabled_rb_mask &= ~(1 << i);
  1924. }
  1925. tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
  1926. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
  1927. R6XX_MAX_BACKENDS, disabled_rb_mask);
  1928. tiling_config |= tmp << 16;
  1929. rdev->config.r600.backend_map = tmp;
  1930. rdev->config.r600.tile_config = tiling_config;
  1931. WREG32(GB_TILING_CONFIG, tiling_config);
  1932. WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
  1933. WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
  1934. WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff);
  1935. tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
  1936. WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
  1937. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
  1938. /* Setup some CP states */
  1939. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
  1940. WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
  1941. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
  1942. SYNC_WALKER | SYNC_ALIGNER));
  1943. /* Setup various GPU states */
  1944. if (rdev->family == CHIP_RV670)
  1945. WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
  1946. tmp = RREG32(SX_DEBUG_1);
  1947. tmp |= SMX_EVENT_RELEASE;
  1948. if ((rdev->family > CHIP_R600))
  1949. tmp |= ENABLE_NEW_SMX_ADDRESS;
  1950. WREG32(SX_DEBUG_1, tmp);
  1951. if (((rdev->family) == CHIP_R600) ||
  1952. ((rdev->family) == CHIP_RV630) ||
  1953. ((rdev->family) == CHIP_RV610) ||
  1954. ((rdev->family) == CHIP_RV620) ||
  1955. ((rdev->family) == CHIP_RS780) ||
  1956. ((rdev->family) == CHIP_RS880)) {
  1957. WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
  1958. } else {
  1959. WREG32(DB_DEBUG, 0);
  1960. }
  1961. WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
  1962. DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
  1963. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1964. WREG32(VGT_NUM_INSTANCES, 0);
  1965. WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
  1966. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
  1967. tmp = RREG32(SQ_MS_FIFO_SIZES);
  1968. if (((rdev->family) == CHIP_RV610) ||
  1969. ((rdev->family) == CHIP_RV620) ||
  1970. ((rdev->family) == CHIP_RS780) ||
  1971. ((rdev->family) == CHIP_RS880)) {
  1972. tmp = (CACHE_FIFO_SIZE(0xa) |
  1973. FETCH_FIFO_HIWATER(0xa) |
  1974. DONE_FIFO_HIWATER(0xe0) |
  1975. ALU_UPDATE_FIFO_HIWATER(0x8));
  1976. } else if (((rdev->family) == CHIP_R600) ||
  1977. ((rdev->family) == CHIP_RV630)) {
  1978. tmp &= ~DONE_FIFO_HIWATER(0xff);
  1979. tmp |= DONE_FIFO_HIWATER(0x4);
  1980. }
  1981. WREG32(SQ_MS_FIFO_SIZES, tmp);
  1982. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1983. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1984. */
  1985. sq_config = RREG32(SQ_CONFIG);
  1986. sq_config &= ~(PS_PRIO(3) |
  1987. VS_PRIO(3) |
  1988. GS_PRIO(3) |
  1989. ES_PRIO(3));
  1990. sq_config |= (DX9_CONSTS |
  1991. VC_ENABLE |
  1992. PS_PRIO(0) |
  1993. VS_PRIO(1) |
  1994. GS_PRIO(2) |
  1995. ES_PRIO(3));
  1996. if ((rdev->family) == CHIP_R600) {
  1997. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
  1998. NUM_VS_GPRS(124) |
  1999. NUM_CLAUSE_TEMP_GPRS(4));
  2000. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
  2001. NUM_ES_GPRS(0));
  2002. sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
  2003. NUM_VS_THREADS(48) |
  2004. NUM_GS_THREADS(4) |
  2005. NUM_ES_THREADS(4));
  2006. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
  2007. NUM_VS_STACK_ENTRIES(128));
  2008. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
  2009. NUM_ES_STACK_ENTRIES(0));
  2010. } else if (((rdev->family) == CHIP_RV610) ||
  2011. ((rdev->family) == CHIP_RV620) ||
  2012. ((rdev->family) == CHIP_RS780) ||
  2013. ((rdev->family) == CHIP_RS880)) {
  2014. /* no vertex cache */
  2015. sq_config &= ~VC_ENABLE;
  2016. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  2017. NUM_VS_GPRS(44) |
  2018. NUM_CLAUSE_TEMP_GPRS(2));
  2019. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  2020. NUM_ES_GPRS(17));
  2021. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  2022. NUM_VS_THREADS(78) |
  2023. NUM_GS_THREADS(4) |
  2024. NUM_ES_THREADS(31));
  2025. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  2026. NUM_VS_STACK_ENTRIES(40));
  2027. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  2028. NUM_ES_STACK_ENTRIES(16));
  2029. } else if (((rdev->family) == CHIP_RV630) ||
  2030. ((rdev->family) == CHIP_RV635)) {
  2031. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  2032. NUM_VS_GPRS(44) |
  2033. NUM_CLAUSE_TEMP_GPRS(2));
  2034. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
  2035. NUM_ES_GPRS(18));
  2036. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  2037. NUM_VS_THREADS(78) |
  2038. NUM_GS_THREADS(4) |
  2039. NUM_ES_THREADS(31));
  2040. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  2041. NUM_VS_STACK_ENTRIES(40));
  2042. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  2043. NUM_ES_STACK_ENTRIES(16));
  2044. } else if ((rdev->family) == CHIP_RV670) {
  2045. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  2046. NUM_VS_GPRS(44) |
  2047. NUM_CLAUSE_TEMP_GPRS(2));
  2048. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  2049. NUM_ES_GPRS(17));
  2050. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  2051. NUM_VS_THREADS(78) |
  2052. NUM_GS_THREADS(4) |
  2053. NUM_ES_THREADS(31));
  2054. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
  2055. NUM_VS_STACK_ENTRIES(64));
  2056. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
  2057. NUM_ES_STACK_ENTRIES(64));
  2058. }
  2059. WREG32(SQ_CONFIG, sq_config);
  2060. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  2061. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  2062. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  2063. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  2064. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  2065. if (((rdev->family) == CHIP_RV610) ||
  2066. ((rdev->family) == CHIP_RV620) ||
  2067. ((rdev->family) == CHIP_RS780) ||
  2068. ((rdev->family) == CHIP_RS880)) {
  2069. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
  2070. } else {
  2071. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
  2072. }
  2073. /* More default values. 2D/3D driver should adjust as needed */
  2074. WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
  2075. S1_X(0x4) | S1_Y(0xc)));
  2076. WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
  2077. S1_X(0x2) | S1_Y(0x2) |
  2078. S2_X(0xa) | S2_Y(0x6) |
  2079. S3_X(0x6) | S3_Y(0xa)));
  2080. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
  2081. S1_X(0x4) | S1_Y(0xc) |
  2082. S2_X(0x1) | S2_Y(0x6) |
  2083. S3_X(0xa) | S3_Y(0xe)));
  2084. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
  2085. S5_X(0x0) | S5_Y(0x0) |
  2086. S6_X(0xb) | S6_Y(0x4) |
  2087. S7_X(0x7) | S7_Y(0x8)));
  2088. WREG32(VGT_STRMOUT_EN, 0);
  2089. tmp = rdev->config.r600.max_pipes * 16;
  2090. switch (rdev->family) {
  2091. case CHIP_RV610:
  2092. case CHIP_RV620:
  2093. case CHIP_RS780:
  2094. case CHIP_RS880:
  2095. tmp += 32;
  2096. break;
  2097. case CHIP_RV670:
  2098. tmp += 128;
  2099. break;
  2100. default:
  2101. break;
  2102. }
  2103. if (tmp > 256) {
  2104. tmp = 256;
  2105. }
  2106. WREG32(VGT_ES_PER_GS, 128);
  2107. WREG32(VGT_GS_PER_ES, tmp);
  2108. WREG32(VGT_GS_PER_VS, 2);
  2109. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2110. /* more default values. 2D/3D driver should adjust as needed */
  2111. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2112. WREG32(VGT_STRMOUT_EN, 0);
  2113. WREG32(SX_MISC, 0);
  2114. WREG32(PA_SC_MODE_CNTL, 0);
  2115. WREG32(PA_SC_AA_CONFIG, 0);
  2116. WREG32(PA_SC_LINE_STIPPLE, 0);
  2117. WREG32(SPI_INPUT_Z, 0);
  2118. WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
  2119. WREG32(CB_COLOR7_FRAG, 0);
  2120. /* Clear render buffer base addresses */
  2121. WREG32(CB_COLOR0_BASE, 0);
  2122. WREG32(CB_COLOR1_BASE, 0);
  2123. WREG32(CB_COLOR2_BASE, 0);
  2124. WREG32(CB_COLOR3_BASE, 0);
  2125. WREG32(CB_COLOR4_BASE, 0);
  2126. WREG32(CB_COLOR5_BASE, 0);
  2127. WREG32(CB_COLOR6_BASE, 0);
  2128. WREG32(CB_COLOR7_BASE, 0);
  2129. WREG32(CB_COLOR7_FRAG, 0);
  2130. switch (rdev->family) {
  2131. case CHIP_RV610:
  2132. case CHIP_RV620:
  2133. case CHIP_RS780:
  2134. case CHIP_RS880:
  2135. tmp = TC_L2_SIZE(8);
  2136. break;
  2137. case CHIP_RV630:
  2138. case CHIP_RV635:
  2139. tmp = TC_L2_SIZE(4);
  2140. break;
  2141. case CHIP_R600:
  2142. tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
  2143. break;
  2144. default:
  2145. tmp = TC_L2_SIZE(0);
  2146. break;
  2147. }
  2148. WREG32(TC_CNTL, tmp);
  2149. tmp = RREG32(HDP_HOST_PATH_CNTL);
  2150. WREG32(HDP_HOST_PATH_CNTL, tmp);
  2151. tmp = RREG32(ARB_POP);
  2152. tmp |= ENABLE_TC128;
  2153. WREG32(ARB_POP, tmp);
  2154. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  2155. WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
  2156. NUM_CLIP_SEQ(3)));
  2157. WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
  2158. WREG32(VC_ENHANCE, 0);
  2159. }
  2160. /*
  2161. * Indirect registers accessor
  2162. */
  2163. u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
  2164. {
  2165. unsigned long flags;
  2166. u32 r;
  2167. spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
  2168. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  2169. (void)RREG32(PCIE_PORT_INDEX);
  2170. r = RREG32(PCIE_PORT_DATA);
  2171. spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
  2172. return r;
  2173. }
  2174. void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2175. {
  2176. unsigned long flags;
  2177. spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
  2178. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  2179. (void)RREG32(PCIE_PORT_INDEX);
  2180. WREG32(PCIE_PORT_DATA, (v));
  2181. (void)RREG32(PCIE_PORT_DATA);
  2182. spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
  2183. }
  2184. /*
  2185. * CP & Ring
  2186. */
  2187. void r600_cp_stop(struct radeon_device *rdev)
  2188. {
  2189. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  2190. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  2191. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  2192. WREG32(SCRATCH_UMSK, 0);
  2193. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2194. }
  2195. int r600_init_microcode(struct radeon_device *rdev)
  2196. {
  2197. const char *chip_name;
  2198. const char *rlc_chip_name;
  2199. const char *smc_chip_name = "RV770";
  2200. size_t pfp_req_size, me_req_size, rlc_req_size, smc_req_size = 0;
  2201. char fw_name[30];
  2202. int err;
  2203. DRM_DEBUG("\n");
  2204. switch (rdev->family) {
  2205. case CHIP_R600:
  2206. chip_name = "R600";
  2207. rlc_chip_name = "R600";
  2208. break;
  2209. case CHIP_RV610:
  2210. chip_name = "RV610";
  2211. rlc_chip_name = "R600";
  2212. break;
  2213. case CHIP_RV630:
  2214. chip_name = "RV630";
  2215. rlc_chip_name = "R600";
  2216. break;
  2217. case CHIP_RV620:
  2218. chip_name = "RV620";
  2219. rlc_chip_name = "R600";
  2220. break;
  2221. case CHIP_RV635:
  2222. chip_name = "RV635";
  2223. rlc_chip_name = "R600";
  2224. break;
  2225. case CHIP_RV670:
  2226. chip_name = "RV670";
  2227. rlc_chip_name = "R600";
  2228. break;
  2229. case CHIP_RS780:
  2230. case CHIP_RS880:
  2231. chip_name = "RS780";
  2232. rlc_chip_name = "R600";
  2233. break;
  2234. case CHIP_RV770:
  2235. chip_name = "RV770";
  2236. rlc_chip_name = "R700";
  2237. smc_chip_name = "RV770";
  2238. smc_req_size = ALIGN(RV770_SMC_UCODE_SIZE, 4);
  2239. break;
  2240. case CHIP_RV730:
  2241. chip_name = "RV730";
  2242. rlc_chip_name = "R700";
  2243. smc_chip_name = "RV730";
  2244. smc_req_size = ALIGN(RV730_SMC_UCODE_SIZE, 4);
  2245. break;
  2246. case CHIP_RV710:
  2247. chip_name = "RV710";
  2248. rlc_chip_name = "R700";
  2249. smc_chip_name = "RV710";
  2250. smc_req_size = ALIGN(RV710_SMC_UCODE_SIZE, 4);
  2251. break;
  2252. case CHIP_RV740:
  2253. chip_name = "RV730";
  2254. rlc_chip_name = "R700";
  2255. smc_chip_name = "RV740";
  2256. smc_req_size = ALIGN(RV740_SMC_UCODE_SIZE, 4);
  2257. break;
  2258. case CHIP_CEDAR:
  2259. chip_name = "CEDAR";
  2260. rlc_chip_name = "CEDAR";
  2261. smc_chip_name = "CEDAR";
  2262. smc_req_size = ALIGN(CEDAR_SMC_UCODE_SIZE, 4);
  2263. break;
  2264. case CHIP_REDWOOD:
  2265. chip_name = "REDWOOD";
  2266. rlc_chip_name = "REDWOOD";
  2267. smc_chip_name = "REDWOOD";
  2268. smc_req_size = ALIGN(REDWOOD_SMC_UCODE_SIZE, 4);
  2269. break;
  2270. case CHIP_JUNIPER:
  2271. chip_name = "JUNIPER";
  2272. rlc_chip_name = "JUNIPER";
  2273. smc_chip_name = "JUNIPER";
  2274. smc_req_size = ALIGN(JUNIPER_SMC_UCODE_SIZE, 4);
  2275. break;
  2276. case CHIP_CYPRESS:
  2277. case CHIP_HEMLOCK:
  2278. chip_name = "CYPRESS";
  2279. rlc_chip_name = "CYPRESS";
  2280. smc_chip_name = "CYPRESS";
  2281. smc_req_size = ALIGN(CYPRESS_SMC_UCODE_SIZE, 4);
  2282. break;
  2283. case CHIP_PALM:
  2284. chip_name = "PALM";
  2285. rlc_chip_name = "SUMO";
  2286. break;
  2287. case CHIP_SUMO:
  2288. chip_name = "SUMO";
  2289. rlc_chip_name = "SUMO";
  2290. break;
  2291. case CHIP_SUMO2:
  2292. chip_name = "SUMO2";
  2293. rlc_chip_name = "SUMO";
  2294. break;
  2295. default: BUG();
  2296. }
  2297. if (rdev->family >= CHIP_CEDAR) {
  2298. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  2299. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  2300. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  2301. } else if (rdev->family >= CHIP_RV770) {
  2302. pfp_req_size = R700_PFP_UCODE_SIZE * 4;
  2303. me_req_size = R700_PM4_UCODE_SIZE * 4;
  2304. rlc_req_size = R700_RLC_UCODE_SIZE * 4;
  2305. } else {
  2306. pfp_req_size = R600_PFP_UCODE_SIZE * 4;
  2307. me_req_size = R600_PM4_UCODE_SIZE * 12;
  2308. rlc_req_size = R600_RLC_UCODE_SIZE * 4;
  2309. }
  2310. DRM_INFO("Loading %s Microcode\n", chip_name);
  2311. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  2312. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  2313. if (err)
  2314. goto out;
  2315. if (rdev->pfp_fw->size != pfp_req_size) {
  2316. printk(KERN_ERR
  2317. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  2318. rdev->pfp_fw->size, fw_name);
  2319. err = -EINVAL;
  2320. goto out;
  2321. }
  2322. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  2323. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  2324. if (err)
  2325. goto out;
  2326. if (rdev->me_fw->size != me_req_size) {
  2327. printk(KERN_ERR
  2328. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  2329. rdev->me_fw->size, fw_name);
  2330. err = -EINVAL;
  2331. }
  2332. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  2333. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  2334. if (err)
  2335. goto out;
  2336. if (rdev->rlc_fw->size != rlc_req_size) {
  2337. printk(KERN_ERR
  2338. "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
  2339. rdev->rlc_fw->size, fw_name);
  2340. err = -EINVAL;
  2341. }
  2342. if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_HEMLOCK)) {
  2343. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", smc_chip_name);
  2344. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  2345. if (err) {
  2346. printk(KERN_ERR
  2347. "smc: error loading firmware \"%s\"\n",
  2348. fw_name);
  2349. release_firmware(rdev->smc_fw);
  2350. rdev->smc_fw = NULL;
  2351. err = 0;
  2352. } else if (rdev->smc_fw->size != smc_req_size) {
  2353. printk(KERN_ERR
  2354. "smc: Bogus length %zu in firmware \"%s\"\n",
  2355. rdev->smc_fw->size, fw_name);
  2356. err = -EINVAL;
  2357. }
  2358. }
  2359. out:
  2360. if (err) {
  2361. if (err != -EINVAL)
  2362. printk(KERN_ERR
  2363. "r600_cp: Failed to load firmware \"%s\"\n",
  2364. fw_name);
  2365. release_firmware(rdev->pfp_fw);
  2366. rdev->pfp_fw = NULL;
  2367. release_firmware(rdev->me_fw);
  2368. rdev->me_fw = NULL;
  2369. release_firmware(rdev->rlc_fw);
  2370. rdev->rlc_fw = NULL;
  2371. release_firmware(rdev->smc_fw);
  2372. rdev->smc_fw = NULL;
  2373. }
  2374. return err;
  2375. }
  2376. u32 r600_gfx_get_rptr(struct radeon_device *rdev,
  2377. struct radeon_ring *ring)
  2378. {
  2379. u32 rptr;
  2380. if (rdev->wb.enabled)
  2381. rptr = rdev->wb.wb[ring->rptr_offs/4];
  2382. else
  2383. rptr = RREG32(R600_CP_RB_RPTR);
  2384. return rptr;
  2385. }
  2386. u32 r600_gfx_get_wptr(struct radeon_device *rdev,
  2387. struct radeon_ring *ring)
  2388. {
  2389. u32 wptr;
  2390. wptr = RREG32(R600_CP_RB_WPTR);
  2391. return wptr;
  2392. }
  2393. void r600_gfx_set_wptr(struct radeon_device *rdev,
  2394. struct radeon_ring *ring)
  2395. {
  2396. WREG32(R600_CP_RB_WPTR, ring->wptr);
  2397. (void)RREG32(R600_CP_RB_WPTR);
  2398. }
  2399. static int r600_cp_load_microcode(struct radeon_device *rdev)
  2400. {
  2401. const __be32 *fw_data;
  2402. int i;
  2403. if (!rdev->me_fw || !rdev->pfp_fw)
  2404. return -EINVAL;
  2405. r600_cp_stop(rdev);
  2406. WREG32(CP_RB_CNTL,
  2407. #ifdef __BIG_ENDIAN
  2408. BUF_SWAP_32BIT |
  2409. #endif
  2410. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  2411. /* Reset cp */
  2412. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  2413. RREG32(GRBM_SOFT_RESET);
  2414. mdelay(15);
  2415. WREG32(GRBM_SOFT_RESET, 0);
  2416. WREG32(CP_ME_RAM_WADDR, 0);
  2417. fw_data = (const __be32 *)rdev->me_fw->data;
  2418. WREG32(CP_ME_RAM_WADDR, 0);
  2419. for (i = 0; i < R600_PM4_UCODE_SIZE * 3; i++)
  2420. WREG32(CP_ME_RAM_DATA,
  2421. be32_to_cpup(fw_data++));
  2422. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2423. WREG32(CP_PFP_UCODE_ADDR, 0);
  2424. for (i = 0; i < R600_PFP_UCODE_SIZE; i++)
  2425. WREG32(CP_PFP_UCODE_DATA,
  2426. be32_to_cpup(fw_data++));
  2427. WREG32(CP_PFP_UCODE_ADDR, 0);
  2428. WREG32(CP_ME_RAM_WADDR, 0);
  2429. WREG32(CP_ME_RAM_RADDR, 0);
  2430. return 0;
  2431. }
  2432. int r600_cp_start(struct radeon_device *rdev)
  2433. {
  2434. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2435. int r;
  2436. uint32_t cp_me;
  2437. r = radeon_ring_lock(rdev, ring, 7);
  2438. if (r) {
  2439. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2440. return r;
  2441. }
  2442. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2443. radeon_ring_write(ring, 0x1);
  2444. if (rdev->family >= CHIP_RV770) {
  2445. radeon_ring_write(ring, 0x0);
  2446. radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
  2447. } else {
  2448. radeon_ring_write(ring, 0x3);
  2449. radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
  2450. }
  2451. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2452. radeon_ring_write(ring, 0);
  2453. radeon_ring_write(ring, 0);
  2454. radeon_ring_unlock_commit(rdev, ring, false);
  2455. cp_me = 0xff;
  2456. WREG32(R_0086D8_CP_ME_CNTL, cp_me);
  2457. return 0;
  2458. }
  2459. int r600_cp_resume(struct radeon_device *rdev)
  2460. {
  2461. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2462. u32 tmp;
  2463. u32 rb_bufsz;
  2464. int r;
  2465. /* Reset cp */
  2466. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  2467. RREG32(GRBM_SOFT_RESET);
  2468. mdelay(15);
  2469. WREG32(GRBM_SOFT_RESET, 0);
  2470. /* Set ring buffer size */
  2471. rb_bufsz = order_base_2(ring->ring_size / 8);
  2472. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2473. #ifdef __BIG_ENDIAN
  2474. tmp |= BUF_SWAP_32BIT;
  2475. #endif
  2476. WREG32(CP_RB_CNTL, tmp);
  2477. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2478. /* Set the write pointer delay */
  2479. WREG32(CP_RB_WPTR_DELAY, 0);
  2480. /* Initialize the ring buffer's read and write pointers */
  2481. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2482. WREG32(CP_RB_RPTR_WR, 0);
  2483. ring->wptr = 0;
  2484. WREG32(CP_RB_WPTR, ring->wptr);
  2485. /* set the wb address whether it's enabled or not */
  2486. WREG32(CP_RB_RPTR_ADDR,
  2487. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2488. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2489. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2490. if (rdev->wb.enabled)
  2491. WREG32(SCRATCH_UMSK, 0xff);
  2492. else {
  2493. tmp |= RB_NO_UPDATE;
  2494. WREG32(SCRATCH_UMSK, 0);
  2495. }
  2496. mdelay(1);
  2497. WREG32(CP_RB_CNTL, tmp);
  2498. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2499. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2500. r600_cp_start(rdev);
  2501. ring->ready = true;
  2502. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2503. if (r) {
  2504. ring->ready = false;
  2505. return r;
  2506. }
  2507. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  2508. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  2509. return 0;
  2510. }
  2511. void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
  2512. {
  2513. u32 rb_bufsz;
  2514. int r;
  2515. /* Align ring size */
  2516. rb_bufsz = order_base_2(ring_size / 8);
  2517. ring_size = (1 << (rb_bufsz + 1)) * 4;
  2518. ring->ring_size = ring_size;
  2519. ring->align_mask = 16 - 1;
  2520. if (radeon_ring_supports_scratch_reg(rdev, ring)) {
  2521. r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
  2522. if (r) {
  2523. DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
  2524. ring->rptr_save_reg = 0;
  2525. }
  2526. }
  2527. }
  2528. void r600_cp_fini(struct radeon_device *rdev)
  2529. {
  2530. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2531. r600_cp_stop(rdev);
  2532. radeon_ring_fini(rdev, ring);
  2533. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2534. }
  2535. /*
  2536. * GPU scratch registers helpers function.
  2537. */
  2538. void r600_scratch_init(struct radeon_device *rdev)
  2539. {
  2540. int i;
  2541. rdev->scratch.num_reg = 7;
  2542. rdev->scratch.reg_base = SCRATCH_REG0;
  2543. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2544. rdev->scratch.free[i] = true;
  2545. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2546. }
  2547. }
  2548. int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
  2549. {
  2550. uint32_t scratch;
  2551. uint32_t tmp = 0;
  2552. unsigned i;
  2553. int r;
  2554. r = radeon_scratch_get(rdev, &scratch);
  2555. if (r) {
  2556. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  2557. return r;
  2558. }
  2559. WREG32(scratch, 0xCAFEDEAD);
  2560. r = radeon_ring_lock(rdev, ring, 3);
  2561. if (r) {
  2562. DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
  2563. radeon_scratch_free(rdev, scratch);
  2564. return r;
  2565. }
  2566. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2567. radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  2568. radeon_ring_write(ring, 0xDEADBEEF);
  2569. radeon_ring_unlock_commit(rdev, ring, false);
  2570. for (i = 0; i < rdev->usec_timeout; i++) {
  2571. tmp = RREG32(scratch);
  2572. if (tmp == 0xDEADBEEF)
  2573. break;
  2574. DRM_UDELAY(1);
  2575. }
  2576. if (i < rdev->usec_timeout) {
  2577. DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
  2578. } else {
  2579. DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  2580. ring->idx, scratch, tmp);
  2581. r = -EINVAL;
  2582. }
  2583. radeon_scratch_free(rdev, scratch);
  2584. return r;
  2585. }
  2586. /*
  2587. * CP fences/semaphores
  2588. */
  2589. void r600_fence_ring_emit(struct radeon_device *rdev,
  2590. struct radeon_fence *fence)
  2591. {
  2592. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2593. u32 cp_coher_cntl = PACKET3_TC_ACTION_ENA | PACKET3_VC_ACTION_ENA |
  2594. PACKET3_SH_ACTION_ENA;
  2595. if (rdev->family >= CHIP_RV770)
  2596. cp_coher_cntl |= PACKET3_FULL_CACHE_ENA;
  2597. if (rdev->wb.use_event) {
  2598. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2599. /* flush read cache over gart */
  2600. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2601. radeon_ring_write(ring, cp_coher_cntl);
  2602. radeon_ring_write(ring, 0xFFFFFFFF);
  2603. radeon_ring_write(ring, 0);
  2604. radeon_ring_write(ring, 10); /* poll interval */
  2605. /* EVENT_WRITE_EOP - flush caches, send int */
  2606. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2607. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
  2608. radeon_ring_write(ring, lower_32_bits(addr));
  2609. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2610. radeon_ring_write(ring, fence->seq);
  2611. radeon_ring_write(ring, 0);
  2612. } else {
  2613. /* flush read cache over gart */
  2614. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2615. radeon_ring_write(ring, cp_coher_cntl);
  2616. radeon_ring_write(ring, 0xFFFFFFFF);
  2617. radeon_ring_write(ring, 0);
  2618. radeon_ring_write(ring, 10); /* poll interval */
  2619. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  2620. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
  2621. /* wait for 3D idle clean */
  2622. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2623. radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2624. radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
  2625. /* Emit fence sequence & fire IRQ */
  2626. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2627. radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  2628. radeon_ring_write(ring, fence->seq);
  2629. /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
  2630. radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
  2631. radeon_ring_write(ring, RB_INT_STAT);
  2632. }
  2633. }
  2634. /**
  2635. * r600_semaphore_ring_emit - emit a semaphore on the CP ring
  2636. *
  2637. * @rdev: radeon_device pointer
  2638. * @ring: radeon ring buffer object
  2639. * @semaphore: radeon semaphore object
  2640. * @emit_wait: Is this a sempahore wait?
  2641. *
  2642. * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
  2643. * from running ahead of semaphore waits.
  2644. */
  2645. bool r600_semaphore_ring_emit(struct radeon_device *rdev,
  2646. struct radeon_ring *ring,
  2647. struct radeon_semaphore *semaphore,
  2648. bool emit_wait)
  2649. {
  2650. uint64_t addr = semaphore->gpu_addr;
  2651. unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
  2652. if (rdev->family < CHIP_CAYMAN)
  2653. sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
  2654. radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
  2655. radeon_ring_write(ring, lower_32_bits(addr));
  2656. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
  2657. /* PFP_SYNC_ME packet only exists on 7xx+, only enable it on eg+ */
  2658. if (emit_wait && (rdev->family >= CHIP_CEDAR)) {
  2659. /* Prevent the PFP from running ahead of the semaphore wait */
  2660. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  2661. radeon_ring_write(ring, 0x0);
  2662. }
  2663. return true;
  2664. }
  2665. /**
  2666. * r600_copy_cpdma - copy pages using the CP DMA engine
  2667. *
  2668. * @rdev: radeon_device pointer
  2669. * @src_offset: src GPU address
  2670. * @dst_offset: dst GPU address
  2671. * @num_gpu_pages: number of GPU pages to xfer
  2672. * @fence: radeon fence object
  2673. *
  2674. * Copy GPU paging using the CP DMA engine (r6xx+).
  2675. * Used by the radeon ttm implementation to move pages if
  2676. * registered as the asic copy callback.
  2677. */
  2678. struct radeon_fence *r600_copy_cpdma(struct radeon_device *rdev,
  2679. uint64_t src_offset, uint64_t dst_offset,
  2680. unsigned num_gpu_pages,
  2681. struct reservation_object *resv)
  2682. {
  2683. struct radeon_fence *fence;
  2684. struct radeon_sync sync;
  2685. int ring_index = rdev->asic->copy.blit_ring_index;
  2686. struct radeon_ring *ring = &rdev->ring[ring_index];
  2687. u32 size_in_bytes, cur_size_in_bytes, tmp;
  2688. int i, num_loops;
  2689. int r = 0;
  2690. radeon_sync_create(&sync);
  2691. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  2692. num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
  2693. r = radeon_ring_lock(rdev, ring, num_loops * 6 + 24);
  2694. if (r) {
  2695. DRM_ERROR("radeon: moving bo (%d).\n", r);
  2696. radeon_sync_free(rdev, &sync, NULL);
  2697. return ERR_PTR(r);
  2698. }
  2699. radeon_sync_resv(rdev, &sync, resv, false);
  2700. radeon_sync_rings(rdev, &sync, ring->idx);
  2701. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2702. radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2703. radeon_ring_write(ring, WAIT_3D_IDLE_bit);
  2704. for (i = 0; i < num_loops; i++) {
  2705. cur_size_in_bytes = size_in_bytes;
  2706. if (cur_size_in_bytes > 0x1fffff)
  2707. cur_size_in_bytes = 0x1fffff;
  2708. size_in_bytes -= cur_size_in_bytes;
  2709. tmp = upper_32_bits(src_offset) & 0xff;
  2710. if (size_in_bytes == 0)
  2711. tmp |= PACKET3_CP_DMA_CP_SYNC;
  2712. radeon_ring_write(ring, PACKET3(PACKET3_CP_DMA, 4));
  2713. radeon_ring_write(ring, lower_32_bits(src_offset));
  2714. radeon_ring_write(ring, tmp);
  2715. radeon_ring_write(ring, lower_32_bits(dst_offset));
  2716. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  2717. radeon_ring_write(ring, cur_size_in_bytes);
  2718. src_offset += cur_size_in_bytes;
  2719. dst_offset += cur_size_in_bytes;
  2720. }
  2721. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2722. radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2723. radeon_ring_write(ring, WAIT_CP_DMA_IDLE_bit);
  2724. r = radeon_fence_emit(rdev, &fence, ring->idx);
  2725. if (r) {
  2726. radeon_ring_unlock_undo(rdev, ring);
  2727. radeon_sync_free(rdev, &sync, NULL);
  2728. return ERR_PTR(r);
  2729. }
  2730. radeon_ring_unlock_commit(rdev, ring, false);
  2731. radeon_sync_free(rdev, &sync, fence);
  2732. return fence;
  2733. }
  2734. int r600_set_surface_reg(struct radeon_device *rdev, int reg,
  2735. uint32_t tiling_flags, uint32_t pitch,
  2736. uint32_t offset, uint32_t obj_size)
  2737. {
  2738. /* FIXME: implement */
  2739. return 0;
  2740. }
  2741. void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
  2742. {
  2743. /* FIXME: implement */
  2744. }
  2745. static int r600_startup(struct radeon_device *rdev)
  2746. {
  2747. struct radeon_ring *ring;
  2748. int r;
  2749. /* enable pcie gen2 link */
  2750. r600_pcie_gen2_enable(rdev);
  2751. /* scratch needs to be initialized before MC */
  2752. r = r600_vram_scratch_init(rdev);
  2753. if (r)
  2754. return r;
  2755. r600_mc_program(rdev);
  2756. if (rdev->flags & RADEON_IS_AGP) {
  2757. r600_agp_enable(rdev);
  2758. } else {
  2759. r = r600_pcie_gart_enable(rdev);
  2760. if (r)
  2761. return r;
  2762. }
  2763. r600_gpu_init(rdev);
  2764. /* allocate wb buffer */
  2765. r = radeon_wb_init(rdev);
  2766. if (r)
  2767. return r;
  2768. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2769. if (r) {
  2770. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  2771. return r;
  2772. }
  2773. if (rdev->has_uvd) {
  2774. r = uvd_v1_0_resume(rdev);
  2775. if (!r) {
  2776. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
  2777. if (r) {
  2778. dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
  2779. }
  2780. }
  2781. if (r)
  2782. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  2783. }
  2784. /* Enable IRQ */
  2785. if (!rdev->irq.installed) {
  2786. r = radeon_irq_kms_init(rdev);
  2787. if (r)
  2788. return r;
  2789. }
  2790. r = r600_irq_init(rdev);
  2791. if (r) {
  2792. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  2793. radeon_irq_kms_fini(rdev);
  2794. return r;
  2795. }
  2796. r600_irq_set(rdev);
  2797. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2798. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  2799. RADEON_CP_PACKET2);
  2800. if (r)
  2801. return r;
  2802. r = r600_cp_load_microcode(rdev);
  2803. if (r)
  2804. return r;
  2805. r = r600_cp_resume(rdev);
  2806. if (r)
  2807. return r;
  2808. if (rdev->has_uvd) {
  2809. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  2810. if (ring->ring_size) {
  2811. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  2812. RADEON_CP_PACKET2);
  2813. if (!r)
  2814. r = uvd_v1_0_init(rdev);
  2815. if (r)
  2816. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  2817. }
  2818. }
  2819. r = radeon_ib_pool_init(rdev);
  2820. if (r) {
  2821. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  2822. return r;
  2823. }
  2824. r = radeon_audio_init(rdev);
  2825. if (r) {
  2826. DRM_ERROR("radeon: audio init failed\n");
  2827. return r;
  2828. }
  2829. return 0;
  2830. }
  2831. void r600_vga_set_state(struct radeon_device *rdev, bool state)
  2832. {
  2833. uint32_t temp;
  2834. temp = RREG32(CONFIG_CNTL);
  2835. if (state == false) {
  2836. temp &= ~(1<<0);
  2837. temp |= (1<<1);
  2838. } else {
  2839. temp &= ~(1<<1);
  2840. }
  2841. WREG32(CONFIG_CNTL, temp);
  2842. }
  2843. int r600_resume(struct radeon_device *rdev)
  2844. {
  2845. int r;
  2846. /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
  2847. * posting will perform necessary task to bring back GPU into good
  2848. * shape.
  2849. */
  2850. /* post card */
  2851. atom_asic_init(rdev->mode_info.atom_context);
  2852. if (rdev->pm.pm_method == PM_METHOD_DPM)
  2853. radeon_pm_resume(rdev);
  2854. rdev->accel_working = true;
  2855. r = r600_startup(rdev);
  2856. if (r) {
  2857. DRM_ERROR("r600 startup failed on resume\n");
  2858. rdev->accel_working = false;
  2859. return r;
  2860. }
  2861. return r;
  2862. }
  2863. int r600_suspend(struct radeon_device *rdev)
  2864. {
  2865. radeon_pm_suspend(rdev);
  2866. radeon_audio_fini(rdev);
  2867. r600_cp_stop(rdev);
  2868. if (rdev->has_uvd) {
  2869. uvd_v1_0_fini(rdev);
  2870. radeon_uvd_suspend(rdev);
  2871. }
  2872. r600_irq_suspend(rdev);
  2873. radeon_wb_disable(rdev);
  2874. r600_pcie_gart_disable(rdev);
  2875. return 0;
  2876. }
  2877. /* Plan is to move initialization in that function and use
  2878. * helper function so that radeon_device_init pretty much
  2879. * do nothing more than calling asic specific function. This
  2880. * should also allow to remove a bunch of callback function
  2881. * like vram_info.
  2882. */
  2883. int r600_init(struct radeon_device *rdev)
  2884. {
  2885. int r;
  2886. if (r600_debugfs_mc_info_init(rdev)) {
  2887. DRM_ERROR("Failed to register debugfs file for mc !\n");
  2888. }
  2889. /* Read BIOS */
  2890. if (!radeon_get_bios(rdev)) {
  2891. if (ASIC_IS_AVIVO(rdev))
  2892. return -EINVAL;
  2893. }
  2894. /* Must be an ATOMBIOS */
  2895. if (!rdev->is_atom_bios) {
  2896. dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
  2897. return -EINVAL;
  2898. }
  2899. r = radeon_atombios_init(rdev);
  2900. if (r)
  2901. return r;
  2902. /* Post card if necessary */
  2903. if (!radeon_card_posted(rdev)) {
  2904. if (!rdev->bios) {
  2905. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  2906. return -EINVAL;
  2907. }
  2908. DRM_INFO("GPU not posted. posting now...\n");
  2909. atom_asic_init(rdev->mode_info.atom_context);
  2910. }
  2911. /* Initialize scratch registers */
  2912. r600_scratch_init(rdev);
  2913. /* Initialize surface registers */
  2914. radeon_surface_init(rdev);
  2915. /* Initialize clocks */
  2916. radeon_get_clock_info(rdev->ddev);
  2917. /* Fence driver */
  2918. r = radeon_fence_driver_init(rdev);
  2919. if (r)
  2920. return r;
  2921. if (rdev->flags & RADEON_IS_AGP) {
  2922. r = radeon_agp_init(rdev);
  2923. if (r)
  2924. radeon_agp_disable(rdev);
  2925. }
  2926. r = r600_mc_init(rdev);
  2927. if (r)
  2928. return r;
  2929. /* Memory manager */
  2930. r = radeon_bo_init(rdev);
  2931. if (r)
  2932. return r;
  2933. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  2934. r = r600_init_microcode(rdev);
  2935. if (r) {
  2936. DRM_ERROR("Failed to load firmware!\n");
  2937. return r;
  2938. }
  2939. }
  2940. /* Initialize power management */
  2941. radeon_pm_init(rdev);
  2942. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  2943. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  2944. if (rdev->has_uvd) {
  2945. r = radeon_uvd_init(rdev);
  2946. if (!r) {
  2947. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  2948. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
  2949. }
  2950. }
  2951. rdev->ih.ring_obj = NULL;
  2952. r600_ih_ring_init(rdev, 64 * 1024);
  2953. r = r600_pcie_gart_init(rdev);
  2954. if (r)
  2955. return r;
  2956. rdev->accel_working = true;
  2957. r = r600_startup(rdev);
  2958. if (r) {
  2959. dev_err(rdev->dev, "disabling GPU acceleration\n");
  2960. r600_cp_fini(rdev);
  2961. r600_irq_fini(rdev);
  2962. radeon_wb_fini(rdev);
  2963. radeon_ib_pool_fini(rdev);
  2964. radeon_irq_kms_fini(rdev);
  2965. r600_pcie_gart_fini(rdev);
  2966. rdev->accel_working = false;
  2967. }
  2968. return 0;
  2969. }
  2970. void r600_fini(struct radeon_device *rdev)
  2971. {
  2972. radeon_pm_fini(rdev);
  2973. radeon_audio_fini(rdev);
  2974. r600_cp_fini(rdev);
  2975. r600_irq_fini(rdev);
  2976. if (rdev->has_uvd) {
  2977. uvd_v1_0_fini(rdev);
  2978. radeon_uvd_fini(rdev);
  2979. }
  2980. radeon_wb_fini(rdev);
  2981. radeon_ib_pool_fini(rdev);
  2982. radeon_irq_kms_fini(rdev);
  2983. r600_pcie_gart_fini(rdev);
  2984. r600_vram_scratch_fini(rdev);
  2985. radeon_agp_fini(rdev);
  2986. radeon_gem_fini(rdev);
  2987. radeon_fence_driver_fini(rdev);
  2988. radeon_bo_fini(rdev);
  2989. radeon_atombios_fini(rdev);
  2990. kfree(rdev->bios);
  2991. rdev->bios = NULL;
  2992. }
  2993. /*
  2994. * CS stuff
  2995. */
  2996. void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2997. {
  2998. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2999. u32 next_rptr;
  3000. if (ring->rptr_save_reg) {
  3001. next_rptr = ring->wptr + 3 + 4;
  3002. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  3003. radeon_ring_write(ring, ((ring->rptr_save_reg -
  3004. PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  3005. radeon_ring_write(ring, next_rptr);
  3006. } else if (rdev->wb.enabled) {
  3007. next_rptr = ring->wptr + 5 + 4;
  3008. radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
  3009. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3010. radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
  3011. radeon_ring_write(ring, next_rptr);
  3012. radeon_ring_write(ring, 0);
  3013. }
  3014. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  3015. radeon_ring_write(ring,
  3016. #ifdef __BIG_ENDIAN
  3017. (2 << 0) |
  3018. #endif
  3019. (ib->gpu_addr & 0xFFFFFFFC));
  3020. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  3021. radeon_ring_write(ring, ib->length_dw);
  3022. }
  3023. int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
  3024. {
  3025. struct radeon_ib ib;
  3026. uint32_t scratch;
  3027. uint32_t tmp = 0;
  3028. unsigned i;
  3029. int r;
  3030. r = radeon_scratch_get(rdev, &scratch);
  3031. if (r) {
  3032. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  3033. return r;
  3034. }
  3035. WREG32(scratch, 0xCAFEDEAD);
  3036. r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
  3037. if (r) {
  3038. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  3039. goto free_scratch;
  3040. }
  3041. ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
  3042. ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  3043. ib.ptr[2] = 0xDEADBEEF;
  3044. ib.length_dw = 3;
  3045. r = radeon_ib_schedule(rdev, &ib, NULL, false);
  3046. if (r) {
  3047. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  3048. goto free_ib;
  3049. }
  3050. r = radeon_fence_wait(ib.fence, false);
  3051. if (r) {
  3052. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  3053. goto free_ib;
  3054. }
  3055. for (i = 0; i < rdev->usec_timeout; i++) {
  3056. tmp = RREG32(scratch);
  3057. if (tmp == 0xDEADBEEF)
  3058. break;
  3059. DRM_UDELAY(1);
  3060. }
  3061. if (i < rdev->usec_timeout) {
  3062. DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
  3063. } else {
  3064. DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
  3065. scratch, tmp);
  3066. r = -EINVAL;
  3067. }
  3068. free_ib:
  3069. radeon_ib_free(rdev, &ib);
  3070. free_scratch:
  3071. radeon_scratch_free(rdev, scratch);
  3072. return r;
  3073. }
  3074. /*
  3075. * Interrupts
  3076. *
  3077. * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
  3078. * the same as the CP ring buffer, but in reverse. Rather than the CPU
  3079. * writing to the ring and the GPU consuming, the GPU writes to the ring
  3080. * and host consumes. As the host irq handler processes interrupts, it
  3081. * increments the rptr. When the rptr catches up with the wptr, all the
  3082. * current interrupts have been processed.
  3083. */
  3084. void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
  3085. {
  3086. u32 rb_bufsz;
  3087. /* Align ring size */
  3088. rb_bufsz = order_base_2(ring_size / 4);
  3089. ring_size = (1 << rb_bufsz) * 4;
  3090. rdev->ih.ring_size = ring_size;
  3091. rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
  3092. rdev->ih.rptr = 0;
  3093. }
  3094. int r600_ih_ring_alloc(struct radeon_device *rdev)
  3095. {
  3096. int r;
  3097. /* Allocate ring buffer */
  3098. if (rdev->ih.ring_obj == NULL) {
  3099. r = radeon_bo_create(rdev, rdev->ih.ring_size,
  3100. PAGE_SIZE, true,
  3101. RADEON_GEM_DOMAIN_GTT, 0,
  3102. NULL, NULL, &rdev->ih.ring_obj);
  3103. if (r) {
  3104. DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
  3105. return r;
  3106. }
  3107. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  3108. if (unlikely(r != 0))
  3109. return r;
  3110. r = radeon_bo_pin(rdev->ih.ring_obj,
  3111. RADEON_GEM_DOMAIN_GTT,
  3112. &rdev->ih.gpu_addr);
  3113. if (r) {
  3114. radeon_bo_unreserve(rdev->ih.ring_obj);
  3115. DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
  3116. return r;
  3117. }
  3118. r = radeon_bo_kmap(rdev->ih.ring_obj,
  3119. (void **)&rdev->ih.ring);
  3120. radeon_bo_unreserve(rdev->ih.ring_obj);
  3121. if (r) {
  3122. DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
  3123. return r;
  3124. }
  3125. }
  3126. return 0;
  3127. }
  3128. void r600_ih_ring_fini(struct radeon_device *rdev)
  3129. {
  3130. int r;
  3131. if (rdev->ih.ring_obj) {
  3132. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  3133. if (likely(r == 0)) {
  3134. radeon_bo_kunmap(rdev->ih.ring_obj);
  3135. radeon_bo_unpin(rdev->ih.ring_obj);
  3136. radeon_bo_unreserve(rdev->ih.ring_obj);
  3137. }
  3138. radeon_bo_unref(&rdev->ih.ring_obj);
  3139. rdev->ih.ring = NULL;
  3140. rdev->ih.ring_obj = NULL;
  3141. }
  3142. }
  3143. void r600_rlc_stop(struct radeon_device *rdev)
  3144. {
  3145. if ((rdev->family >= CHIP_RV770) &&
  3146. (rdev->family <= CHIP_RV740)) {
  3147. /* r7xx asics need to soft reset RLC before halting */
  3148. WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
  3149. RREG32(SRBM_SOFT_RESET);
  3150. mdelay(15);
  3151. WREG32(SRBM_SOFT_RESET, 0);
  3152. RREG32(SRBM_SOFT_RESET);
  3153. }
  3154. WREG32(RLC_CNTL, 0);
  3155. }
  3156. static void r600_rlc_start(struct radeon_device *rdev)
  3157. {
  3158. WREG32(RLC_CNTL, RLC_ENABLE);
  3159. }
  3160. static int r600_rlc_resume(struct radeon_device *rdev)
  3161. {
  3162. u32 i;
  3163. const __be32 *fw_data;
  3164. if (!rdev->rlc_fw)
  3165. return -EINVAL;
  3166. r600_rlc_stop(rdev);
  3167. WREG32(RLC_HB_CNTL, 0);
  3168. WREG32(RLC_HB_BASE, 0);
  3169. WREG32(RLC_HB_RPTR, 0);
  3170. WREG32(RLC_HB_WPTR, 0);
  3171. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  3172. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  3173. WREG32(RLC_MC_CNTL, 0);
  3174. WREG32(RLC_UCODE_CNTL, 0);
  3175. fw_data = (const __be32 *)rdev->rlc_fw->data;
  3176. if (rdev->family >= CHIP_RV770) {
  3177. for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
  3178. WREG32(RLC_UCODE_ADDR, i);
  3179. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3180. }
  3181. } else {
  3182. for (i = 0; i < R600_RLC_UCODE_SIZE; i++) {
  3183. WREG32(RLC_UCODE_ADDR, i);
  3184. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3185. }
  3186. }
  3187. WREG32(RLC_UCODE_ADDR, 0);
  3188. r600_rlc_start(rdev);
  3189. return 0;
  3190. }
  3191. static void r600_enable_interrupts(struct radeon_device *rdev)
  3192. {
  3193. u32 ih_cntl = RREG32(IH_CNTL);
  3194. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3195. ih_cntl |= ENABLE_INTR;
  3196. ih_rb_cntl |= IH_RB_ENABLE;
  3197. WREG32(IH_CNTL, ih_cntl);
  3198. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3199. rdev->ih.enabled = true;
  3200. }
  3201. void r600_disable_interrupts(struct radeon_device *rdev)
  3202. {
  3203. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3204. u32 ih_cntl = RREG32(IH_CNTL);
  3205. ih_rb_cntl &= ~IH_RB_ENABLE;
  3206. ih_cntl &= ~ENABLE_INTR;
  3207. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3208. WREG32(IH_CNTL, ih_cntl);
  3209. /* set rptr, wptr to 0 */
  3210. WREG32(IH_RB_RPTR, 0);
  3211. WREG32(IH_RB_WPTR, 0);
  3212. rdev->ih.enabled = false;
  3213. rdev->ih.rptr = 0;
  3214. }
  3215. static void r600_disable_interrupt_state(struct radeon_device *rdev)
  3216. {
  3217. u32 tmp;
  3218. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3219. tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  3220. WREG32(DMA_CNTL, tmp);
  3221. WREG32(GRBM_INT_CNTL, 0);
  3222. WREG32(DxMODE_INT_MASK, 0);
  3223. WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
  3224. WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
  3225. if (ASIC_IS_DCE3(rdev)) {
  3226. WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
  3227. WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
  3228. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3229. WREG32(DC_HPD1_INT_CONTROL, tmp);
  3230. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3231. WREG32(DC_HPD2_INT_CONTROL, tmp);
  3232. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3233. WREG32(DC_HPD3_INT_CONTROL, tmp);
  3234. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3235. WREG32(DC_HPD4_INT_CONTROL, tmp);
  3236. if (ASIC_IS_DCE32(rdev)) {
  3237. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3238. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3239. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3240. WREG32(DC_HPD6_INT_CONTROL, tmp);
  3241. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3242. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
  3243. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3244. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
  3245. } else {
  3246. tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3247. WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
  3248. tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3249. WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
  3250. }
  3251. } else {
  3252. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  3253. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  3254. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  3255. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  3256. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  3257. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  3258. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  3259. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  3260. tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3261. WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
  3262. tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3263. WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
  3264. }
  3265. }
  3266. int r600_irq_init(struct radeon_device *rdev)
  3267. {
  3268. int ret = 0;
  3269. int rb_bufsz;
  3270. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  3271. /* allocate ring */
  3272. ret = r600_ih_ring_alloc(rdev);
  3273. if (ret)
  3274. return ret;
  3275. /* disable irqs */
  3276. r600_disable_interrupts(rdev);
  3277. /* init rlc */
  3278. if (rdev->family >= CHIP_CEDAR)
  3279. ret = evergreen_rlc_resume(rdev);
  3280. else
  3281. ret = r600_rlc_resume(rdev);
  3282. if (ret) {
  3283. r600_ih_ring_fini(rdev);
  3284. return ret;
  3285. }
  3286. /* setup interrupt control */
  3287. /* set dummy read address to ring address */
  3288. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  3289. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  3290. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  3291. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  3292. */
  3293. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  3294. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  3295. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  3296. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  3297. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  3298. rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
  3299. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  3300. IH_WPTR_OVERFLOW_CLEAR |
  3301. (rb_bufsz << 1));
  3302. if (rdev->wb.enabled)
  3303. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  3304. /* set the writeback address whether it's enabled or not */
  3305. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  3306. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  3307. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3308. /* set rptr, wptr to 0 */
  3309. WREG32(IH_RB_RPTR, 0);
  3310. WREG32(IH_RB_WPTR, 0);
  3311. /* Default settings for IH_CNTL (disabled at first) */
  3312. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
  3313. /* RPTR_REARM only works if msi's are enabled */
  3314. if (rdev->msi_enabled)
  3315. ih_cntl |= RPTR_REARM;
  3316. WREG32(IH_CNTL, ih_cntl);
  3317. /* force the active interrupt state to all disabled */
  3318. if (rdev->family >= CHIP_CEDAR)
  3319. evergreen_disable_interrupt_state(rdev);
  3320. else
  3321. r600_disable_interrupt_state(rdev);
  3322. /* at this point everything should be setup correctly to enable master */
  3323. pci_set_master(rdev->pdev);
  3324. /* enable irqs */
  3325. r600_enable_interrupts(rdev);
  3326. return ret;
  3327. }
  3328. void r600_irq_suspend(struct radeon_device *rdev)
  3329. {
  3330. r600_irq_disable(rdev);
  3331. r600_rlc_stop(rdev);
  3332. }
  3333. void r600_irq_fini(struct radeon_device *rdev)
  3334. {
  3335. r600_irq_suspend(rdev);
  3336. r600_ih_ring_fini(rdev);
  3337. }
  3338. int r600_irq_set(struct radeon_device *rdev)
  3339. {
  3340. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  3341. u32 mode_int = 0;
  3342. u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  3343. u32 grbm_int_cntl = 0;
  3344. u32 hdmi0, hdmi1;
  3345. u32 dma_cntl;
  3346. u32 thermal_int = 0;
  3347. if (!rdev->irq.installed) {
  3348. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  3349. return -EINVAL;
  3350. }
  3351. /* don't enable anything if the ih is disabled */
  3352. if (!rdev->ih.enabled) {
  3353. r600_disable_interrupts(rdev);
  3354. /* force the active interrupt state to all disabled */
  3355. r600_disable_interrupt_state(rdev);
  3356. return 0;
  3357. }
  3358. if (ASIC_IS_DCE3(rdev)) {
  3359. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3360. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3361. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3362. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3363. if (ASIC_IS_DCE32(rdev)) {
  3364. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3365. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3366. hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3367. hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  3368. } else {
  3369. hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3370. hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3371. }
  3372. } else {
  3373. hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3374. hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3375. hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  3376. hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3377. hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
  3378. }
  3379. dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  3380. if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
  3381. thermal_int = RREG32(CG_THERMAL_INT) &
  3382. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  3383. } else if (rdev->family >= CHIP_RV770) {
  3384. thermal_int = RREG32(RV770_CG_THERMAL_INT) &
  3385. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  3386. }
  3387. if (rdev->irq.dpm_thermal) {
  3388. DRM_DEBUG("dpm thermal\n");
  3389. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  3390. }
  3391. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  3392. DRM_DEBUG("r600_irq_set: sw int\n");
  3393. cp_int_cntl |= RB_INT_ENABLE;
  3394. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  3395. }
  3396. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  3397. DRM_DEBUG("r600_irq_set: sw int dma\n");
  3398. dma_cntl |= TRAP_ENABLE;
  3399. }
  3400. if (rdev->irq.crtc_vblank_int[0] ||
  3401. atomic_read(&rdev->irq.pflip[0])) {
  3402. DRM_DEBUG("r600_irq_set: vblank 0\n");
  3403. mode_int |= D1MODE_VBLANK_INT_MASK;
  3404. }
  3405. if (rdev->irq.crtc_vblank_int[1] ||
  3406. atomic_read(&rdev->irq.pflip[1])) {
  3407. DRM_DEBUG("r600_irq_set: vblank 1\n");
  3408. mode_int |= D2MODE_VBLANK_INT_MASK;
  3409. }
  3410. if (rdev->irq.hpd[0]) {
  3411. DRM_DEBUG("r600_irq_set: hpd 1\n");
  3412. hpd1 |= DC_HPDx_INT_EN;
  3413. }
  3414. if (rdev->irq.hpd[1]) {
  3415. DRM_DEBUG("r600_irq_set: hpd 2\n");
  3416. hpd2 |= DC_HPDx_INT_EN;
  3417. }
  3418. if (rdev->irq.hpd[2]) {
  3419. DRM_DEBUG("r600_irq_set: hpd 3\n");
  3420. hpd3 |= DC_HPDx_INT_EN;
  3421. }
  3422. if (rdev->irq.hpd[3]) {
  3423. DRM_DEBUG("r600_irq_set: hpd 4\n");
  3424. hpd4 |= DC_HPDx_INT_EN;
  3425. }
  3426. if (rdev->irq.hpd[4]) {
  3427. DRM_DEBUG("r600_irq_set: hpd 5\n");
  3428. hpd5 |= DC_HPDx_INT_EN;
  3429. }
  3430. if (rdev->irq.hpd[5]) {
  3431. DRM_DEBUG("r600_irq_set: hpd 6\n");
  3432. hpd6 |= DC_HPDx_INT_EN;
  3433. }
  3434. if (rdev->irq.afmt[0]) {
  3435. DRM_DEBUG("r600_irq_set: hdmi 0\n");
  3436. hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
  3437. }
  3438. if (rdev->irq.afmt[1]) {
  3439. DRM_DEBUG("r600_irq_set: hdmi 0\n");
  3440. hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
  3441. }
  3442. WREG32(CP_INT_CNTL, cp_int_cntl);
  3443. WREG32(DMA_CNTL, dma_cntl);
  3444. WREG32(DxMODE_INT_MASK, mode_int);
  3445. WREG32(D1GRPH_INTERRUPT_CONTROL, DxGRPH_PFLIP_INT_MASK);
  3446. WREG32(D2GRPH_INTERRUPT_CONTROL, DxGRPH_PFLIP_INT_MASK);
  3447. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  3448. if (ASIC_IS_DCE3(rdev)) {
  3449. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  3450. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  3451. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  3452. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  3453. if (ASIC_IS_DCE32(rdev)) {
  3454. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  3455. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  3456. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
  3457. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
  3458. } else {
  3459. WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
  3460. WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
  3461. }
  3462. } else {
  3463. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
  3464. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
  3465. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
  3466. WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
  3467. WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
  3468. }
  3469. if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
  3470. WREG32(CG_THERMAL_INT, thermal_int);
  3471. } else if (rdev->family >= CHIP_RV770) {
  3472. WREG32(RV770_CG_THERMAL_INT, thermal_int);
  3473. }
  3474. /* posting read */
  3475. RREG32(R_000E50_SRBM_STATUS);
  3476. return 0;
  3477. }
  3478. static void r600_irq_ack(struct radeon_device *rdev)
  3479. {
  3480. u32 tmp;
  3481. if (ASIC_IS_DCE3(rdev)) {
  3482. rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
  3483. rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
  3484. rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
  3485. if (ASIC_IS_DCE32(rdev)) {
  3486. rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
  3487. rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
  3488. } else {
  3489. rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
  3490. rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
  3491. }
  3492. } else {
  3493. rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  3494. rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  3495. rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
  3496. rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
  3497. rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
  3498. }
  3499. rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
  3500. rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
  3501. if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
  3502. WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
  3503. if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
  3504. WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
  3505. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
  3506. WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  3507. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
  3508. WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  3509. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
  3510. WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  3511. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
  3512. WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  3513. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
  3514. if (ASIC_IS_DCE3(rdev)) {
  3515. tmp = RREG32(DC_HPD1_INT_CONTROL);
  3516. tmp |= DC_HPDx_INT_ACK;
  3517. WREG32(DC_HPD1_INT_CONTROL, tmp);
  3518. } else {
  3519. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  3520. tmp |= DC_HPDx_INT_ACK;
  3521. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  3522. }
  3523. }
  3524. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
  3525. if (ASIC_IS_DCE3(rdev)) {
  3526. tmp = RREG32(DC_HPD2_INT_CONTROL);
  3527. tmp |= DC_HPDx_INT_ACK;
  3528. WREG32(DC_HPD2_INT_CONTROL, tmp);
  3529. } else {
  3530. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  3531. tmp |= DC_HPDx_INT_ACK;
  3532. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  3533. }
  3534. }
  3535. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
  3536. if (ASIC_IS_DCE3(rdev)) {
  3537. tmp = RREG32(DC_HPD3_INT_CONTROL);
  3538. tmp |= DC_HPDx_INT_ACK;
  3539. WREG32(DC_HPD3_INT_CONTROL, tmp);
  3540. } else {
  3541. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  3542. tmp |= DC_HPDx_INT_ACK;
  3543. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  3544. }
  3545. }
  3546. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
  3547. tmp = RREG32(DC_HPD4_INT_CONTROL);
  3548. tmp |= DC_HPDx_INT_ACK;
  3549. WREG32(DC_HPD4_INT_CONTROL, tmp);
  3550. }
  3551. if (ASIC_IS_DCE32(rdev)) {
  3552. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
  3553. tmp = RREG32(DC_HPD5_INT_CONTROL);
  3554. tmp |= DC_HPDx_INT_ACK;
  3555. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3556. }
  3557. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
  3558. tmp = RREG32(DC_HPD6_INT_CONTROL);
  3559. tmp |= DC_HPDx_INT_ACK;
  3560. WREG32(DC_HPD6_INT_CONTROL, tmp);
  3561. }
  3562. if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
  3563. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
  3564. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  3565. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
  3566. }
  3567. if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
  3568. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
  3569. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  3570. WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
  3571. }
  3572. } else {
  3573. if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
  3574. tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
  3575. tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
  3576. WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
  3577. }
  3578. if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
  3579. if (ASIC_IS_DCE3(rdev)) {
  3580. tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
  3581. tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
  3582. WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
  3583. } else {
  3584. tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
  3585. tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
  3586. WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
  3587. }
  3588. }
  3589. }
  3590. }
  3591. void r600_irq_disable(struct radeon_device *rdev)
  3592. {
  3593. r600_disable_interrupts(rdev);
  3594. /* Wait and acknowledge irq */
  3595. mdelay(1);
  3596. r600_irq_ack(rdev);
  3597. r600_disable_interrupt_state(rdev);
  3598. }
  3599. static u32 r600_get_ih_wptr(struct radeon_device *rdev)
  3600. {
  3601. u32 wptr, tmp;
  3602. if (rdev->wb.enabled)
  3603. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  3604. else
  3605. wptr = RREG32(IH_RB_WPTR);
  3606. if (wptr & RB_OVERFLOW) {
  3607. wptr &= ~RB_OVERFLOW;
  3608. /* When a ring buffer overflow happen start parsing interrupt
  3609. * from the last not overwritten vector (wptr + 16). Hopefully
  3610. * this should allow us to catchup.
  3611. */
  3612. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
  3613. wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
  3614. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  3615. tmp = RREG32(IH_RB_CNTL);
  3616. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  3617. WREG32(IH_RB_CNTL, tmp);
  3618. }
  3619. return (wptr & rdev->ih.ptr_mask);
  3620. }
  3621. /* r600 IV Ring
  3622. * Each IV ring entry is 128 bits:
  3623. * [7:0] - interrupt source id
  3624. * [31:8] - reserved
  3625. * [59:32] - interrupt source data
  3626. * [127:60] - reserved
  3627. *
  3628. * The basic interrupt vector entries
  3629. * are decoded as follows:
  3630. * src_id src_data description
  3631. * 1 0 D1 Vblank
  3632. * 1 1 D1 Vline
  3633. * 5 0 D2 Vblank
  3634. * 5 1 D2 Vline
  3635. * 19 0 FP Hot plug detection A
  3636. * 19 1 FP Hot plug detection B
  3637. * 19 2 DAC A auto-detection
  3638. * 19 3 DAC B auto-detection
  3639. * 21 4 HDMI block A
  3640. * 21 5 HDMI block B
  3641. * 176 - CP_INT RB
  3642. * 177 - CP_INT IB1
  3643. * 178 - CP_INT IB2
  3644. * 181 - EOP Interrupt
  3645. * 233 - GUI Idle
  3646. *
  3647. * Note, these are based on r600 and may need to be
  3648. * adjusted or added to on newer asics
  3649. */
  3650. int r600_irq_process(struct radeon_device *rdev)
  3651. {
  3652. u32 wptr;
  3653. u32 rptr;
  3654. u32 src_id, src_data;
  3655. u32 ring_index;
  3656. bool queue_hotplug = false;
  3657. bool queue_hdmi = false;
  3658. bool queue_thermal = false;
  3659. if (!rdev->ih.enabled || rdev->shutdown)
  3660. return IRQ_NONE;
  3661. /* No MSIs, need a dummy read to flush PCI DMAs */
  3662. if (!rdev->msi_enabled)
  3663. RREG32(IH_RB_WPTR);
  3664. wptr = r600_get_ih_wptr(rdev);
  3665. restart_ih:
  3666. /* is somebody else already processing irqs? */
  3667. if (atomic_xchg(&rdev->ih.lock, 1))
  3668. return IRQ_NONE;
  3669. rptr = rdev->ih.rptr;
  3670. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  3671. /* Order reading of wptr vs. reading of IH ring data */
  3672. rmb();
  3673. /* display interrupts */
  3674. r600_irq_ack(rdev);
  3675. while (rptr != wptr) {
  3676. /* wptr/rptr are in bytes! */
  3677. ring_index = rptr / 4;
  3678. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  3679. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  3680. switch (src_id) {
  3681. case 1: /* D1 vblank/vline */
  3682. switch (src_data) {
  3683. case 0: /* D1 vblank */
  3684. if (!(rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT))
  3685. DRM_DEBUG("IH: D1 vblank - IH event w/o asserted irq bit?\n");
  3686. if (rdev->irq.crtc_vblank_int[0]) {
  3687. drm_handle_vblank(rdev->ddev, 0);
  3688. rdev->pm.vblank_sync = true;
  3689. wake_up(&rdev->irq.vblank_queue);
  3690. }
  3691. if (atomic_read(&rdev->irq.pflip[0]))
  3692. radeon_crtc_handle_vblank(rdev, 0);
  3693. rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  3694. DRM_DEBUG("IH: D1 vblank\n");
  3695. break;
  3696. case 1: /* D1 vline */
  3697. if (!(rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT))
  3698. DRM_DEBUG("IH: D1 vline - IH event w/o asserted irq bit?\n");
  3699. rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  3700. DRM_DEBUG("IH: D1 vline\n");
  3701. break;
  3702. default:
  3703. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3704. break;
  3705. }
  3706. break;
  3707. case 5: /* D2 vblank/vline */
  3708. switch (src_data) {
  3709. case 0: /* D2 vblank */
  3710. if (!(rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT))
  3711. DRM_DEBUG("IH: D2 vblank - IH event w/o asserted irq bit?\n");
  3712. if (rdev->irq.crtc_vblank_int[1]) {
  3713. drm_handle_vblank(rdev->ddev, 1);
  3714. rdev->pm.vblank_sync = true;
  3715. wake_up(&rdev->irq.vblank_queue);
  3716. }
  3717. if (atomic_read(&rdev->irq.pflip[1]))
  3718. radeon_crtc_handle_vblank(rdev, 1);
  3719. rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
  3720. DRM_DEBUG("IH: D2 vblank\n");
  3721. break;
  3722. case 1: /* D1 vline */
  3723. if (!(rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT))
  3724. DRM_DEBUG("IH: D2 vline - IH event w/o asserted irq bit?\n");
  3725. rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
  3726. DRM_DEBUG("IH: D2 vline\n");
  3727. break;
  3728. default:
  3729. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3730. break;
  3731. }
  3732. break;
  3733. case 9: /* D1 pflip */
  3734. DRM_DEBUG("IH: D1 flip\n");
  3735. if (radeon_use_pflipirq > 0)
  3736. radeon_crtc_handle_flip(rdev, 0);
  3737. break;
  3738. case 11: /* D2 pflip */
  3739. DRM_DEBUG("IH: D2 flip\n");
  3740. if (radeon_use_pflipirq > 0)
  3741. radeon_crtc_handle_flip(rdev, 1);
  3742. break;
  3743. case 19: /* HPD/DAC hotplug */
  3744. switch (src_data) {
  3745. case 0:
  3746. if (!(rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT))
  3747. DRM_DEBUG("IH: HPD1 - IH event w/o asserted irq bit?\n");
  3748. rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
  3749. queue_hotplug = true;
  3750. DRM_DEBUG("IH: HPD1\n");
  3751. break;
  3752. case 1:
  3753. if (!(rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT))
  3754. DRM_DEBUG("IH: HPD2 - IH event w/o asserted irq bit?\n");
  3755. rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
  3756. queue_hotplug = true;
  3757. DRM_DEBUG("IH: HPD2\n");
  3758. break;
  3759. case 4:
  3760. if (!(rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT))
  3761. DRM_DEBUG("IH: HPD3 - IH event w/o asserted irq bit?\n");
  3762. rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
  3763. queue_hotplug = true;
  3764. DRM_DEBUG("IH: HPD3\n");
  3765. break;
  3766. case 5:
  3767. if (!(rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT))
  3768. DRM_DEBUG("IH: HPD4 - IH event w/o asserted irq bit?\n");
  3769. rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
  3770. queue_hotplug = true;
  3771. DRM_DEBUG("IH: HPD4\n");
  3772. break;
  3773. case 10:
  3774. if (!(rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT))
  3775. DRM_DEBUG("IH: HPD5 - IH event w/o asserted irq bit?\n");
  3776. rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
  3777. queue_hotplug = true;
  3778. DRM_DEBUG("IH: HPD5\n");
  3779. break;
  3780. case 12:
  3781. if (!(rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT))
  3782. DRM_DEBUG("IH: HPD6 - IH event w/o asserted irq bit?\n");
  3783. rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
  3784. queue_hotplug = true;
  3785. DRM_DEBUG("IH: HPD6\n");
  3786. break;
  3787. default:
  3788. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3789. break;
  3790. }
  3791. break;
  3792. case 21: /* hdmi */
  3793. switch (src_data) {
  3794. case 4:
  3795. if (!(rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG))
  3796. DRM_DEBUG("IH: HDMI0 - IH event w/o asserted irq bit?\n");
  3797. rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
  3798. queue_hdmi = true;
  3799. DRM_DEBUG("IH: HDMI0\n");
  3800. break;
  3801. case 5:
  3802. if (!(rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG))
  3803. DRM_DEBUG("IH: HDMI1 - IH event w/o asserted irq bit?\n");
  3804. rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
  3805. queue_hdmi = true;
  3806. DRM_DEBUG("IH: HDMI1\n");
  3807. break;
  3808. default:
  3809. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  3810. break;
  3811. }
  3812. break;
  3813. case 124: /* UVD */
  3814. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  3815. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  3816. break;
  3817. case 176: /* CP_INT in ring buffer */
  3818. case 177: /* CP_INT in IB1 */
  3819. case 178: /* CP_INT in IB2 */
  3820. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  3821. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  3822. break;
  3823. case 181: /* CP EOP event */
  3824. DRM_DEBUG("IH: CP EOP\n");
  3825. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  3826. break;
  3827. case 224: /* DMA trap event */
  3828. DRM_DEBUG("IH: DMA trap\n");
  3829. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  3830. break;
  3831. case 230: /* thermal low to high */
  3832. DRM_DEBUG("IH: thermal low to high\n");
  3833. rdev->pm.dpm.thermal.high_to_low = false;
  3834. queue_thermal = true;
  3835. break;
  3836. case 231: /* thermal high to low */
  3837. DRM_DEBUG("IH: thermal high to low\n");
  3838. rdev->pm.dpm.thermal.high_to_low = true;
  3839. queue_thermal = true;
  3840. break;
  3841. case 233: /* GUI IDLE */
  3842. DRM_DEBUG("IH: GUI idle\n");
  3843. break;
  3844. default:
  3845. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3846. break;
  3847. }
  3848. /* wptr/rptr are in bytes! */
  3849. rptr += 16;
  3850. rptr &= rdev->ih.ptr_mask;
  3851. WREG32(IH_RB_RPTR, rptr);
  3852. }
  3853. if (queue_hotplug)
  3854. schedule_delayed_work(&rdev->hotplug_work, 0);
  3855. if (queue_hdmi)
  3856. schedule_work(&rdev->audio_work);
  3857. if (queue_thermal && rdev->pm.dpm_enabled)
  3858. schedule_work(&rdev->pm.dpm.thermal.work);
  3859. rdev->ih.rptr = rptr;
  3860. atomic_set(&rdev->ih.lock, 0);
  3861. /* make sure wptr hasn't changed while processing */
  3862. wptr = r600_get_ih_wptr(rdev);
  3863. if (wptr != rptr)
  3864. goto restart_ih;
  3865. return IRQ_HANDLED;
  3866. }
  3867. /*
  3868. * Debugfs info
  3869. */
  3870. #if defined(CONFIG_DEBUG_FS)
  3871. static int r600_debugfs_mc_info(struct seq_file *m, void *data)
  3872. {
  3873. struct drm_info_node *node = (struct drm_info_node *) m->private;
  3874. struct drm_device *dev = node->minor->dev;
  3875. struct radeon_device *rdev = dev->dev_private;
  3876. DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
  3877. DREG32_SYS(m, rdev, VM_L2_STATUS);
  3878. return 0;
  3879. }
  3880. static struct drm_info_list r600_mc_info_list[] = {
  3881. {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
  3882. };
  3883. #endif
  3884. int r600_debugfs_mc_info_init(struct radeon_device *rdev)
  3885. {
  3886. #if defined(CONFIG_DEBUG_FS)
  3887. return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
  3888. #else
  3889. return 0;
  3890. #endif
  3891. }
  3892. /**
  3893. * r600_mmio_hdp_flush - flush Host Data Path cache via MMIO
  3894. * rdev: radeon device structure
  3895. *
  3896. * Some R6XX/R7XX don't seem to take into account HDP flushes performed
  3897. * through the ring buffer. This leads to corruption in rendering, see
  3898. * http://bugzilla.kernel.org/show_bug.cgi?id=15186 . To avoid this, we
  3899. * directly perform the HDP flush by writing the register through MMIO.
  3900. */
  3901. void r600_mmio_hdp_flush(struct radeon_device *rdev)
  3902. {
  3903. /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
  3904. * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
  3905. * This seems to cause problems on some AGP cards. Just use the old
  3906. * method for them.
  3907. */
  3908. if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
  3909. rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
  3910. void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
  3911. u32 tmp;
  3912. WREG32(HDP_DEBUG1, 0);
  3913. tmp = readl((void __iomem *)ptr);
  3914. } else
  3915. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3916. }
  3917. void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
  3918. {
  3919. u32 link_width_cntl, mask;
  3920. if (rdev->flags & RADEON_IS_IGP)
  3921. return;
  3922. if (!(rdev->flags & RADEON_IS_PCIE))
  3923. return;
  3924. /* x2 cards have a special sequence */
  3925. if (ASIC_IS_X2(rdev))
  3926. return;
  3927. radeon_gui_idle(rdev);
  3928. switch (lanes) {
  3929. case 0:
  3930. mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
  3931. break;
  3932. case 1:
  3933. mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
  3934. break;
  3935. case 2:
  3936. mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
  3937. break;
  3938. case 4:
  3939. mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
  3940. break;
  3941. case 8:
  3942. mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
  3943. break;
  3944. case 12:
  3945. /* not actually supported */
  3946. mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
  3947. break;
  3948. case 16:
  3949. mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
  3950. break;
  3951. default:
  3952. DRM_ERROR("invalid pcie lane request: %d\n", lanes);
  3953. return;
  3954. }
  3955. link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  3956. link_width_cntl &= ~RADEON_PCIE_LC_LINK_WIDTH_MASK;
  3957. link_width_cntl |= mask << RADEON_PCIE_LC_LINK_WIDTH_SHIFT;
  3958. link_width_cntl |= (RADEON_PCIE_LC_RECONFIG_NOW |
  3959. R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
  3960. WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3961. }
  3962. int r600_get_pcie_lanes(struct radeon_device *rdev)
  3963. {
  3964. u32 link_width_cntl;
  3965. if (rdev->flags & RADEON_IS_IGP)
  3966. return 0;
  3967. if (!(rdev->flags & RADEON_IS_PCIE))
  3968. return 0;
  3969. /* x2 cards have a special sequence */
  3970. if (ASIC_IS_X2(rdev))
  3971. return 0;
  3972. radeon_gui_idle(rdev);
  3973. link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  3974. switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
  3975. case RADEON_PCIE_LC_LINK_WIDTH_X1:
  3976. return 1;
  3977. case RADEON_PCIE_LC_LINK_WIDTH_X2:
  3978. return 2;
  3979. case RADEON_PCIE_LC_LINK_WIDTH_X4:
  3980. return 4;
  3981. case RADEON_PCIE_LC_LINK_WIDTH_X8:
  3982. return 8;
  3983. case RADEON_PCIE_LC_LINK_WIDTH_X12:
  3984. /* not actually supported */
  3985. return 12;
  3986. case RADEON_PCIE_LC_LINK_WIDTH_X0:
  3987. case RADEON_PCIE_LC_LINK_WIDTH_X16:
  3988. default:
  3989. return 16;
  3990. }
  3991. }
  3992. static void r600_pcie_gen2_enable(struct radeon_device *rdev)
  3993. {
  3994. u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
  3995. u16 link_cntl2;
  3996. if (radeon_pcie_gen2 == 0)
  3997. return;
  3998. if (rdev->flags & RADEON_IS_IGP)
  3999. return;
  4000. if (!(rdev->flags & RADEON_IS_PCIE))
  4001. return;
  4002. /* x2 cards have a special sequence */
  4003. if (ASIC_IS_X2(rdev))
  4004. return;
  4005. /* only RV6xx+ chips are supported */
  4006. if (rdev->family <= CHIP_R600)
  4007. return;
  4008. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  4009. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  4010. return;
  4011. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  4012. if (speed_cntl & LC_CURRENT_DATA_RATE) {
  4013. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  4014. return;
  4015. }
  4016. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  4017. /* 55 nm r6xx asics */
  4018. if ((rdev->family == CHIP_RV670) ||
  4019. (rdev->family == CHIP_RV620) ||
  4020. (rdev->family == CHIP_RV635)) {
  4021. /* advertise upconfig capability */
  4022. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  4023. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  4024. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  4025. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  4026. if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
  4027. lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
  4028. link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
  4029. LC_RECONFIG_ARC_MISSING_ESCAPE);
  4030. link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
  4031. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  4032. } else {
  4033. link_width_cntl |= LC_UPCONFIGURE_DIS;
  4034. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  4035. }
  4036. }
  4037. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  4038. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  4039. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  4040. /* 55 nm r6xx asics */
  4041. if ((rdev->family == CHIP_RV670) ||
  4042. (rdev->family == CHIP_RV620) ||
  4043. (rdev->family == CHIP_RV635)) {
  4044. WREG32(MM_CFGREGS_CNTL, 0x8);
  4045. link_cntl2 = RREG32(0x4088);
  4046. WREG32(MM_CFGREGS_CNTL, 0);
  4047. /* not supported yet */
  4048. if (link_cntl2 & SELECTABLE_DEEMPHASIS)
  4049. return;
  4050. }
  4051. speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
  4052. speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
  4053. speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
  4054. speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
  4055. speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
  4056. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  4057. tmp = RREG32(0x541c);
  4058. WREG32(0x541c, tmp | 0x8);
  4059. WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
  4060. link_cntl2 = RREG16(0x4088);
  4061. link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
  4062. link_cntl2 |= 0x2;
  4063. WREG16(0x4088, link_cntl2);
  4064. WREG32(MM_CFGREGS_CNTL, 0);
  4065. if ((rdev->family == CHIP_RV670) ||
  4066. (rdev->family == CHIP_RV620) ||
  4067. (rdev->family == CHIP_RV635)) {
  4068. training_cntl = RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL);
  4069. training_cntl &= ~LC_POINT_7_PLUS_EN;
  4070. WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL, training_cntl);
  4071. } else {
  4072. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  4073. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  4074. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  4075. }
  4076. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  4077. speed_cntl |= LC_GEN2_EN_STRAP;
  4078. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  4079. } else {
  4080. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  4081. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  4082. if (1)
  4083. link_width_cntl |= LC_UPCONFIGURE_DIS;
  4084. else
  4085. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  4086. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  4087. }
  4088. }
  4089. /**
  4090. * r600_get_gpu_clock_counter - return GPU clock counter snapshot
  4091. *
  4092. * @rdev: radeon_device pointer
  4093. *
  4094. * Fetches a GPU clock counter snapshot (R6xx-cayman).
  4095. * Returns the 64 bit clock counter snapshot.
  4096. */
  4097. uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev)
  4098. {
  4099. uint64_t clock;
  4100. mutex_lock(&rdev->gpu_clock_mutex);
  4101. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  4102. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  4103. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  4104. mutex_unlock(&rdev->gpu_clock_mutex);
  4105. return clock;
  4106. }