r600.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807
  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/platform_device.h>
  32. #include <linux/module.h>
  33. #include "drmP.h"
  34. #include "radeon_drm.h"
  35. #include "radeon.h"
  36. #include "radeon_asic.h"
  37. #include "radeon_mode.h"
  38. #include "r600d.h"
  39. #include "atom.h"
  40. #include "avivod.h"
  41. #define PFP_UCODE_SIZE 576
  42. #define PM4_UCODE_SIZE 1792
  43. #define RLC_UCODE_SIZE 768
  44. #define R700_PFP_UCODE_SIZE 848
  45. #define R700_PM4_UCODE_SIZE 1360
  46. #define R700_RLC_UCODE_SIZE 1024
  47. #define EVERGREEN_PFP_UCODE_SIZE 1120
  48. #define EVERGREEN_PM4_UCODE_SIZE 1376
  49. #define EVERGREEN_RLC_UCODE_SIZE 768
  50. #define CAYMAN_RLC_UCODE_SIZE 1024
  51. #define ARUBA_RLC_UCODE_SIZE 1536
  52. /* Firmware Names */
  53. MODULE_FIRMWARE("radeon/R600_pfp.bin");
  54. MODULE_FIRMWARE("radeon/R600_me.bin");
  55. MODULE_FIRMWARE("radeon/RV610_pfp.bin");
  56. MODULE_FIRMWARE("radeon/RV610_me.bin");
  57. MODULE_FIRMWARE("radeon/RV630_pfp.bin");
  58. MODULE_FIRMWARE("radeon/RV630_me.bin");
  59. MODULE_FIRMWARE("radeon/RV620_pfp.bin");
  60. MODULE_FIRMWARE("radeon/RV620_me.bin");
  61. MODULE_FIRMWARE("radeon/RV635_pfp.bin");
  62. MODULE_FIRMWARE("radeon/RV635_me.bin");
  63. MODULE_FIRMWARE("radeon/RV670_pfp.bin");
  64. MODULE_FIRMWARE("radeon/RV670_me.bin");
  65. MODULE_FIRMWARE("radeon/RS780_pfp.bin");
  66. MODULE_FIRMWARE("radeon/RS780_me.bin");
  67. MODULE_FIRMWARE("radeon/RV770_pfp.bin");
  68. MODULE_FIRMWARE("radeon/RV770_me.bin");
  69. MODULE_FIRMWARE("radeon/RV730_pfp.bin");
  70. MODULE_FIRMWARE("radeon/RV730_me.bin");
  71. MODULE_FIRMWARE("radeon/RV710_pfp.bin");
  72. MODULE_FIRMWARE("radeon/RV710_me.bin");
  73. MODULE_FIRMWARE("radeon/R600_rlc.bin");
  74. MODULE_FIRMWARE("radeon/R700_rlc.bin");
  75. MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
  76. MODULE_FIRMWARE("radeon/CEDAR_me.bin");
  77. MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
  78. MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
  79. MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
  80. MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
  81. MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
  82. MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
  83. MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
  84. MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
  85. MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
  86. MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
  87. MODULE_FIRMWARE("radeon/PALM_pfp.bin");
  88. MODULE_FIRMWARE("radeon/PALM_me.bin");
  89. MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
  90. MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
  91. MODULE_FIRMWARE("radeon/SUMO_me.bin");
  92. MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
  93. MODULE_FIRMWARE("radeon/SUMO2_me.bin");
  94. int r600_debugfs_mc_info_init(struct radeon_device *rdev);
  95. /* r600,rv610,rv630,rv620,rv635,rv670 */
  96. int r600_mc_wait_for_idle(struct radeon_device *rdev);
  97. void r600_gpu_init(struct radeon_device *rdev);
  98. void r600_fini(struct radeon_device *rdev);
  99. void r600_irq_disable(struct radeon_device *rdev);
  100. static void r600_pcie_gen2_enable(struct radeon_device *rdev);
  101. /* get temperature in millidegrees */
  102. int rv6xx_get_temp(struct radeon_device *rdev)
  103. {
  104. u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
  105. ASIC_T_SHIFT;
  106. int actual_temp = temp & 0xff;
  107. if (temp & 0x100)
  108. actual_temp -= 256;
  109. return actual_temp * 1000;
  110. }
  111. void r600_pm_get_dynpm_state(struct radeon_device *rdev)
  112. {
  113. int i;
  114. rdev->pm.dynpm_can_upclock = true;
  115. rdev->pm.dynpm_can_downclock = true;
  116. /* power state array is low to high, default is first */
  117. if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
  118. int min_power_state_index = 0;
  119. if (rdev->pm.num_power_states > 2)
  120. min_power_state_index = 1;
  121. switch (rdev->pm.dynpm_planned_action) {
  122. case DYNPM_ACTION_MINIMUM:
  123. rdev->pm.requested_power_state_index = min_power_state_index;
  124. rdev->pm.requested_clock_mode_index = 0;
  125. rdev->pm.dynpm_can_downclock = false;
  126. break;
  127. case DYNPM_ACTION_DOWNCLOCK:
  128. if (rdev->pm.current_power_state_index == min_power_state_index) {
  129. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  130. rdev->pm.dynpm_can_downclock = false;
  131. } else {
  132. if (rdev->pm.active_crtc_count > 1) {
  133. for (i = 0; i < rdev->pm.num_power_states; i++) {
  134. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  135. continue;
  136. else if (i >= rdev->pm.current_power_state_index) {
  137. rdev->pm.requested_power_state_index =
  138. rdev->pm.current_power_state_index;
  139. break;
  140. } else {
  141. rdev->pm.requested_power_state_index = i;
  142. break;
  143. }
  144. }
  145. } else {
  146. if (rdev->pm.current_power_state_index == 0)
  147. rdev->pm.requested_power_state_index =
  148. rdev->pm.num_power_states - 1;
  149. else
  150. rdev->pm.requested_power_state_index =
  151. rdev->pm.current_power_state_index - 1;
  152. }
  153. }
  154. rdev->pm.requested_clock_mode_index = 0;
  155. /* don't use the power state if crtcs are active and no display flag is set */
  156. if ((rdev->pm.active_crtc_count > 0) &&
  157. (rdev->pm.power_state[rdev->pm.requested_power_state_index].
  158. clock_info[rdev->pm.requested_clock_mode_index].flags &
  159. RADEON_PM_MODE_NO_DISPLAY)) {
  160. rdev->pm.requested_power_state_index++;
  161. }
  162. break;
  163. case DYNPM_ACTION_UPCLOCK:
  164. if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
  165. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  166. rdev->pm.dynpm_can_upclock = false;
  167. } else {
  168. if (rdev->pm.active_crtc_count > 1) {
  169. for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
  170. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  171. continue;
  172. else if (i <= rdev->pm.current_power_state_index) {
  173. rdev->pm.requested_power_state_index =
  174. rdev->pm.current_power_state_index;
  175. break;
  176. } else {
  177. rdev->pm.requested_power_state_index = i;
  178. break;
  179. }
  180. }
  181. } else
  182. rdev->pm.requested_power_state_index =
  183. rdev->pm.current_power_state_index + 1;
  184. }
  185. rdev->pm.requested_clock_mode_index = 0;
  186. break;
  187. case DYNPM_ACTION_DEFAULT:
  188. rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
  189. rdev->pm.requested_clock_mode_index = 0;
  190. rdev->pm.dynpm_can_upclock = false;
  191. break;
  192. case DYNPM_ACTION_NONE:
  193. default:
  194. DRM_ERROR("Requested mode for not defined action\n");
  195. return;
  196. }
  197. } else {
  198. /* XXX select a power state based on AC/DC, single/dualhead, etc. */
  199. /* for now just select the first power state and switch between clock modes */
  200. /* power state array is low to high, default is first (0) */
  201. if (rdev->pm.active_crtc_count > 1) {
  202. rdev->pm.requested_power_state_index = -1;
  203. /* start at 1 as we don't want the default mode */
  204. for (i = 1; i < rdev->pm.num_power_states; i++) {
  205. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  206. continue;
  207. else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
  208. (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
  209. rdev->pm.requested_power_state_index = i;
  210. break;
  211. }
  212. }
  213. /* if nothing selected, grab the default state. */
  214. if (rdev->pm.requested_power_state_index == -1)
  215. rdev->pm.requested_power_state_index = 0;
  216. } else
  217. rdev->pm.requested_power_state_index = 1;
  218. switch (rdev->pm.dynpm_planned_action) {
  219. case DYNPM_ACTION_MINIMUM:
  220. rdev->pm.requested_clock_mode_index = 0;
  221. rdev->pm.dynpm_can_downclock = false;
  222. break;
  223. case DYNPM_ACTION_DOWNCLOCK:
  224. if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
  225. if (rdev->pm.current_clock_mode_index == 0) {
  226. rdev->pm.requested_clock_mode_index = 0;
  227. rdev->pm.dynpm_can_downclock = false;
  228. } else
  229. rdev->pm.requested_clock_mode_index =
  230. rdev->pm.current_clock_mode_index - 1;
  231. } else {
  232. rdev->pm.requested_clock_mode_index = 0;
  233. rdev->pm.dynpm_can_downclock = false;
  234. }
  235. /* don't use the power state if crtcs are active and no display flag is set */
  236. if ((rdev->pm.active_crtc_count > 0) &&
  237. (rdev->pm.power_state[rdev->pm.requested_power_state_index].
  238. clock_info[rdev->pm.requested_clock_mode_index].flags &
  239. RADEON_PM_MODE_NO_DISPLAY)) {
  240. rdev->pm.requested_clock_mode_index++;
  241. }
  242. break;
  243. case DYNPM_ACTION_UPCLOCK:
  244. if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
  245. if (rdev->pm.current_clock_mode_index ==
  246. (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
  247. rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
  248. rdev->pm.dynpm_can_upclock = false;
  249. } else
  250. rdev->pm.requested_clock_mode_index =
  251. rdev->pm.current_clock_mode_index + 1;
  252. } else {
  253. rdev->pm.requested_clock_mode_index =
  254. rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
  255. rdev->pm.dynpm_can_upclock = false;
  256. }
  257. break;
  258. case DYNPM_ACTION_DEFAULT:
  259. rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
  260. rdev->pm.requested_clock_mode_index = 0;
  261. rdev->pm.dynpm_can_upclock = false;
  262. break;
  263. case DYNPM_ACTION_NONE:
  264. default:
  265. DRM_ERROR("Requested mode for not defined action\n");
  266. return;
  267. }
  268. }
  269. DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
  270. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  271. clock_info[rdev->pm.requested_clock_mode_index].sclk,
  272. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  273. clock_info[rdev->pm.requested_clock_mode_index].mclk,
  274. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  275. pcie_lanes);
  276. }
  277. void rs780_pm_init_profile(struct radeon_device *rdev)
  278. {
  279. if (rdev->pm.num_power_states == 2) {
  280. /* default */
  281. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  282. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  283. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  284. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  285. /* low sh */
  286. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
  287. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
  288. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  289. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  290. /* mid sh */
  291. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
  292. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
  293. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  294. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  295. /* high sh */
  296. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
  297. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
  298. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  299. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  300. /* low mh */
  301. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
  302. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
  303. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  304. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  305. /* mid mh */
  306. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
  307. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
  308. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  309. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  310. /* high mh */
  311. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
  312. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
  313. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  314. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  315. } else if (rdev->pm.num_power_states == 3) {
  316. /* default */
  317. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  318. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  319. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  320. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  321. /* low sh */
  322. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
  323. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
  324. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  325. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  326. /* mid sh */
  327. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
  328. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
  329. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  330. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  331. /* high sh */
  332. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
  333. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
  334. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  335. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  336. /* low mh */
  337. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
  338. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
  339. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  340. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  341. /* mid mh */
  342. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
  343. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
  344. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  345. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  346. /* high mh */
  347. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
  348. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
  349. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  350. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  351. } else {
  352. /* default */
  353. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  354. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  355. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  356. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  357. /* low sh */
  358. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
  359. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
  360. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  361. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  362. /* mid sh */
  363. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
  364. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
  365. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  366. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  367. /* high sh */
  368. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
  369. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
  370. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  371. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  372. /* low mh */
  373. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
  374. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
  375. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  376. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  377. /* mid mh */
  378. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
  379. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
  380. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  381. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  382. /* high mh */
  383. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
  384. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
  385. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  386. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  387. }
  388. }
  389. void r600_pm_init_profile(struct radeon_device *rdev)
  390. {
  391. int idx;
  392. if (rdev->family == CHIP_R600) {
  393. /* XXX */
  394. /* default */
  395. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  396. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  397. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  398. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  399. /* low sh */
  400. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  401. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  402. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  403. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  404. /* mid sh */
  405. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  406. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  407. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  408. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  409. /* high sh */
  410. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  411. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  412. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  413. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  414. /* low mh */
  415. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  416. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  417. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  418. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  419. /* mid mh */
  420. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  421. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  422. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  423. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  424. /* high mh */
  425. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  426. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  427. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  428. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  429. } else {
  430. if (rdev->pm.num_power_states < 4) {
  431. /* default */
  432. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  433. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  434. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  435. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  436. /* low sh */
  437. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
  438. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
  439. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  440. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  441. /* mid sh */
  442. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
  443. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
  444. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  445. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  446. /* high sh */
  447. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
  448. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
  449. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  450. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  451. /* low mh */
  452. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
  453. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
  454. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  455. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  456. /* low mh */
  457. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
  458. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
  459. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  460. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  461. /* high mh */
  462. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
  463. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
  464. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  465. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  466. } else {
  467. /* default */
  468. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  469. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  470. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  471. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  472. /* low sh */
  473. if (rdev->flags & RADEON_IS_MOBILITY)
  474. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  475. else
  476. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  477. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  478. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  479. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  480. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  481. /* mid sh */
  482. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  483. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  484. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  485. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  486. /* high sh */
  487. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  488. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  489. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  490. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  491. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  492. /* low mh */
  493. if (rdev->flags & RADEON_IS_MOBILITY)
  494. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
  495. else
  496. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
  497. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  498. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  499. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  500. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  501. /* mid mh */
  502. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  503. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  504. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  505. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  506. /* high mh */
  507. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
  508. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  509. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  510. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  511. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  512. }
  513. }
  514. }
  515. void r600_pm_misc(struct radeon_device *rdev)
  516. {
  517. int req_ps_idx = rdev->pm.requested_power_state_index;
  518. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  519. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  520. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  521. if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
  522. /* 0xff01 is a flag rather then an actual voltage */
  523. if (voltage->voltage == 0xff01)
  524. return;
  525. if (voltage->voltage != rdev->pm.current_vddc) {
  526. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  527. rdev->pm.current_vddc = voltage->voltage;
  528. DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
  529. }
  530. }
  531. }
  532. bool r600_gui_idle(struct radeon_device *rdev)
  533. {
  534. if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
  535. return false;
  536. else
  537. return true;
  538. }
  539. /* hpd for digital panel detect/disconnect */
  540. bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  541. {
  542. bool connected = false;
  543. if (ASIC_IS_DCE3(rdev)) {
  544. switch (hpd) {
  545. case RADEON_HPD_1:
  546. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  547. connected = true;
  548. break;
  549. case RADEON_HPD_2:
  550. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  551. connected = true;
  552. break;
  553. case RADEON_HPD_3:
  554. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  555. connected = true;
  556. break;
  557. case RADEON_HPD_4:
  558. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  559. connected = true;
  560. break;
  561. /* DCE 3.2 */
  562. case RADEON_HPD_5:
  563. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  564. connected = true;
  565. break;
  566. case RADEON_HPD_6:
  567. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  568. connected = true;
  569. break;
  570. default:
  571. break;
  572. }
  573. } else {
  574. switch (hpd) {
  575. case RADEON_HPD_1:
  576. if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  577. connected = true;
  578. break;
  579. case RADEON_HPD_2:
  580. if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  581. connected = true;
  582. break;
  583. case RADEON_HPD_3:
  584. if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  585. connected = true;
  586. break;
  587. default:
  588. break;
  589. }
  590. }
  591. return connected;
  592. }
  593. void r600_hpd_set_polarity(struct radeon_device *rdev,
  594. enum radeon_hpd_id hpd)
  595. {
  596. u32 tmp;
  597. bool connected = r600_hpd_sense(rdev, hpd);
  598. if (ASIC_IS_DCE3(rdev)) {
  599. switch (hpd) {
  600. case RADEON_HPD_1:
  601. tmp = RREG32(DC_HPD1_INT_CONTROL);
  602. if (connected)
  603. tmp &= ~DC_HPDx_INT_POLARITY;
  604. else
  605. tmp |= DC_HPDx_INT_POLARITY;
  606. WREG32(DC_HPD1_INT_CONTROL, tmp);
  607. break;
  608. case RADEON_HPD_2:
  609. tmp = RREG32(DC_HPD2_INT_CONTROL);
  610. if (connected)
  611. tmp &= ~DC_HPDx_INT_POLARITY;
  612. else
  613. tmp |= DC_HPDx_INT_POLARITY;
  614. WREG32(DC_HPD2_INT_CONTROL, tmp);
  615. break;
  616. case RADEON_HPD_3:
  617. tmp = RREG32(DC_HPD3_INT_CONTROL);
  618. if (connected)
  619. tmp &= ~DC_HPDx_INT_POLARITY;
  620. else
  621. tmp |= DC_HPDx_INT_POLARITY;
  622. WREG32(DC_HPD3_INT_CONTROL, tmp);
  623. break;
  624. case RADEON_HPD_4:
  625. tmp = RREG32(DC_HPD4_INT_CONTROL);
  626. if (connected)
  627. tmp &= ~DC_HPDx_INT_POLARITY;
  628. else
  629. tmp |= DC_HPDx_INT_POLARITY;
  630. WREG32(DC_HPD4_INT_CONTROL, tmp);
  631. break;
  632. case RADEON_HPD_5:
  633. tmp = RREG32(DC_HPD5_INT_CONTROL);
  634. if (connected)
  635. tmp &= ~DC_HPDx_INT_POLARITY;
  636. else
  637. tmp |= DC_HPDx_INT_POLARITY;
  638. WREG32(DC_HPD5_INT_CONTROL, tmp);
  639. break;
  640. /* DCE 3.2 */
  641. case RADEON_HPD_6:
  642. tmp = RREG32(DC_HPD6_INT_CONTROL);
  643. if (connected)
  644. tmp &= ~DC_HPDx_INT_POLARITY;
  645. else
  646. tmp |= DC_HPDx_INT_POLARITY;
  647. WREG32(DC_HPD6_INT_CONTROL, tmp);
  648. break;
  649. default:
  650. break;
  651. }
  652. } else {
  653. switch (hpd) {
  654. case RADEON_HPD_1:
  655. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  656. if (connected)
  657. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  658. else
  659. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  660. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  661. break;
  662. case RADEON_HPD_2:
  663. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  664. if (connected)
  665. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  666. else
  667. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  668. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  669. break;
  670. case RADEON_HPD_3:
  671. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  672. if (connected)
  673. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  674. else
  675. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  676. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  677. break;
  678. default:
  679. break;
  680. }
  681. }
  682. }
  683. void r600_hpd_init(struct radeon_device *rdev)
  684. {
  685. struct drm_device *dev = rdev->ddev;
  686. struct drm_connector *connector;
  687. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  688. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  689. if (ASIC_IS_DCE3(rdev)) {
  690. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
  691. if (ASIC_IS_DCE32(rdev))
  692. tmp |= DC_HPDx_EN;
  693. switch (radeon_connector->hpd.hpd) {
  694. case RADEON_HPD_1:
  695. WREG32(DC_HPD1_CONTROL, tmp);
  696. rdev->irq.hpd[0] = true;
  697. break;
  698. case RADEON_HPD_2:
  699. WREG32(DC_HPD2_CONTROL, tmp);
  700. rdev->irq.hpd[1] = true;
  701. break;
  702. case RADEON_HPD_3:
  703. WREG32(DC_HPD3_CONTROL, tmp);
  704. rdev->irq.hpd[2] = true;
  705. break;
  706. case RADEON_HPD_4:
  707. WREG32(DC_HPD4_CONTROL, tmp);
  708. rdev->irq.hpd[3] = true;
  709. break;
  710. /* DCE 3.2 */
  711. case RADEON_HPD_5:
  712. WREG32(DC_HPD5_CONTROL, tmp);
  713. rdev->irq.hpd[4] = true;
  714. break;
  715. case RADEON_HPD_6:
  716. WREG32(DC_HPD6_CONTROL, tmp);
  717. rdev->irq.hpd[5] = true;
  718. break;
  719. default:
  720. break;
  721. }
  722. } else {
  723. switch (radeon_connector->hpd.hpd) {
  724. case RADEON_HPD_1:
  725. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  726. rdev->irq.hpd[0] = true;
  727. break;
  728. case RADEON_HPD_2:
  729. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  730. rdev->irq.hpd[1] = true;
  731. break;
  732. case RADEON_HPD_3:
  733. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  734. rdev->irq.hpd[2] = true;
  735. break;
  736. default:
  737. break;
  738. }
  739. }
  740. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  741. }
  742. if (rdev->irq.installed)
  743. r600_irq_set(rdev);
  744. }
  745. void r600_hpd_fini(struct radeon_device *rdev)
  746. {
  747. struct drm_device *dev = rdev->ddev;
  748. struct drm_connector *connector;
  749. if (ASIC_IS_DCE3(rdev)) {
  750. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  751. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  752. switch (radeon_connector->hpd.hpd) {
  753. case RADEON_HPD_1:
  754. WREG32(DC_HPD1_CONTROL, 0);
  755. rdev->irq.hpd[0] = false;
  756. break;
  757. case RADEON_HPD_2:
  758. WREG32(DC_HPD2_CONTROL, 0);
  759. rdev->irq.hpd[1] = false;
  760. break;
  761. case RADEON_HPD_3:
  762. WREG32(DC_HPD3_CONTROL, 0);
  763. rdev->irq.hpd[2] = false;
  764. break;
  765. case RADEON_HPD_4:
  766. WREG32(DC_HPD4_CONTROL, 0);
  767. rdev->irq.hpd[3] = false;
  768. break;
  769. /* DCE 3.2 */
  770. case RADEON_HPD_5:
  771. WREG32(DC_HPD5_CONTROL, 0);
  772. rdev->irq.hpd[4] = false;
  773. break;
  774. case RADEON_HPD_6:
  775. WREG32(DC_HPD6_CONTROL, 0);
  776. rdev->irq.hpd[5] = false;
  777. break;
  778. default:
  779. break;
  780. }
  781. }
  782. } else {
  783. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  784. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  785. switch (radeon_connector->hpd.hpd) {
  786. case RADEON_HPD_1:
  787. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
  788. rdev->irq.hpd[0] = false;
  789. break;
  790. case RADEON_HPD_2:
  791. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
  792. rdev->irq.hpd[1] = false;
  793. break;
  794. case RADEON_HPD_3:
  795. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
  796. rdev->irq.hpd[2] = false;
  797. break;
  798. default:
  799. break;
  800. }
  801. }
  802. }
  803. }
  804. /*
  805. * R600 PCIE GART
  806. */
  807. void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
  808. {
  809. unsigned i;
  810. u32 tmp;
  811. /* flush hdp cache so updates hit vram */
  812. if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
  813. !(rdev->flags & RADEON_IS_AGP)) {
  814. void __iomem *ptr = (void *)rdev->gart.ptr;
  815. u32 tmp;
  816. /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
  817. * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
  818. * This seems to cause problems on some AGP cards. Just use the old
  819. * method for them.
  820. */
  821. WREG32(HDP_DEBUG1, 0);
  822. tmp = readl((void __iomem *)ptr);
  823. } else
  824. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  825. WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
  826. WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
  827. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  828. for (i = 0; i < rdev->usec_timeout; i++) {
  829. /* read MC_STATUS */
  830. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  831. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  832. if (tmp == 2) {
  833. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  834. return;
  835. }
  836. if (tmp) {
  837. return;
  838. }
  839. udelay(1);
  840. }
  841. }
  842. int r600_pcie_gart_init(struct radeon_device *rdev)
  843. {
  844. int r;
  845. if (rdev->gart.robj) {
  846. WARN(1, "R600 PCIE GART already initialized\n");
  847. return 0;
  848. }
  849. /* Initialize common gart structure */
  850. r = radeon_gart_init(rdev);
  851. if (r)
  852. return r;
  853. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  854. return radeon_gart_table_vram_alloc(rdev);
  855. }
  856. int r600_pcie_gart_enable(struct radeon_device *rdev)
  857. {
  858. u32 tmp;
  859. int r, i;
  860. if (rdev->gart.robj == NULL) {
  861. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  862. return -EINVAL;
  863. }
  864. r = radeon_gart_table_vram_pin(rdev);
  865. if (r)
  866. return r;
  867. radeon_gart_restore(rdev);
  868. /* Setup L2 cache */
  869. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  870. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  871. EFFECTIVE_L2_QUEUE_SIZE(7));
  872. WREG32(VM_L2_CNTL2, 0);
  873. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  874. /* Setup TLB control */
  875. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  876. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  877. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  878. ENABLE_WAIT_L2_QUERY;
  879. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  880. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  881. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  882. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  883. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  884. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  885. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  886. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  887. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  888. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  889. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  890. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  891. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  892. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  893. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  894. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  895. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  896. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  897. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  898. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  899. (u32)(rdev->dummy_page.addr >> 12));
  900. for (i = 1; i < 7; i++)
  901. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  902. r600_pcie_gart_tlb_flush(rdev);
  903. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  904. (unsigned)(rdev->mc.gtt_size >> 20),
  905. (unsigned long long)rdev->gart.table_addr);
  906. rdev->gart.ready = true;
  907. return 0;
  908. }
  909. void r600_pcie_gart_disable(struct radeon_device *rdev)
  910. {
  911. u32 tmp;
  912. int i;
  913. /* Disable all tables */
  914. for (i = 0; i < 7; i++)
  915. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  916. /* Disable L2 cache */
  917. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  918. EFFECTIVE_L2_QUEUE_SIZE(7));
  919. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  920. /* Setup L1 TLB control */
  921. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  922. ENABLE_WAIT_L2_QUERY;
  923. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  924. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  925. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  926. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  927. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  928. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  929. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  930. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  931. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
  932. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
  933. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  934. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  935. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
  936. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  937. radeon_gart_table_vram_unpin(rdev);
  938. }
  939. void r600_pcie_gart_fini(struct radeon_device *rdev)
  940. {
  941. radeon_gart_fini(rdev);
  942. r600_pcie_gart_disable(rdev);
  943. radeon_gart_table_vram_free(rdev);
  944. }
  945. void r600_agp_enable(struct radeon_device *rdev)
  946. {
  947. u32 tmp;
  948. int i;
  949. /* Setup L2 cache */
  950. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  951. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  952. EFFECTIVE_L2_QUEUE_SIZE(7));
  953. WREG32(VM_L2_CNTL2, 0);
  954. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  955. /* Setup TLB control */
  956. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  957. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  958. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  959. ENABLE_WAIT_L2_QUERY;
  960. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  961. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  962. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  963. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  964. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  965. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  966. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  967. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  968. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  969. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  970. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  971. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  972. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  973. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  974. for (i = 0; i < 7; i++)
  975. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  976. }
  977. int r600_mc_wait_for_idle(struct radeon_device *rdev)
  978. {
  979. unsigned i;
  980. u32 tmp;
  981. for (i = 0; i < rdev->usec_timeout; i++) {
  982. /* read MC_STATUS */
  983. tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
  984. if (!tmp)
  985. return 0;
  986. udelay(1);
  987. }
  988. return -1;
  989. }
  990. static void r600_mc_program(struct radeon_device *rdev)
  991. {
  992. struct rv515_mc_save save;
  993. u32 tmp;
  994. int i, j;
  995. /* Initialize HDP */
  996. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  997. WREG32((0x2c14 + j), 0x00000000);
  998. WREG32((0x2c18 + j), 0x00000000);
  999. WREG32((0x2c1c + j), 0x00000000);
  1000. WREG32((0x2c20 + j), 0x00000000);
  1001. WREG32((0x2c24 + j), 0x00000000);
  1002. }
  1003. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  1004. rv515_mc_stop(rdev, &save);
  1005. if (r600_mc_wait_for_idle(rdev)) {
  1006. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1007. }
  1008. /* Lockout access through VGA aperture (doesn't exist before R600) */
  1009. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  1010. /* Update configuration */
  1011. if (rdev->flags & RADEON_IS_AGP) {
  1012. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  1013. /* VRAM before AGP */
  1014. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1015. rdev->mc.vram_start >> 12);
  1016. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1017. rdev->mc.gtt_end >> 12);
  1018. } else {
  1019. /* VRAM after AGP */
  1020. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1021. rdev->mc.gtt_start >> 12);
  1022. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1023. rdev->mc.vram_end >> 12);
  1024. }
  1025. } else {
  1026. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
  1027. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
  1028. }
  1029. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  1030. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  1031. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  1032. WREG32(MC_VM_FB_LOCATION, tmp);
  1033. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  1034. WREG32(HDP_NONSURFACE_INFO, (2 << 7));
  1035. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  1036. if (rdev->flags & RADEON_IS_AGP) {
  1037. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
  1038. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
  1039. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  1040. } else {
  1041. WREG32(MC_VM_AGP_BASE, 0);
  1042. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  1043. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  1044. }
  1045. if (r600_mc_wait_for_idle(rdev)) {
  1046. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1047. }
  1048. rv515_mc_resume(rdev, &save);
  1049. /* we need to own VRAM, so turn off the VGA renderer here
  1050. * to stop it overwriting our objects */
  1051. rv515_vga_render_disable(rdev);
  1052. }
  1053. /**
  1054. * r600_vram_gtt_location - try to find VRAM & GTT location
  1055. * @rdev: radeon device structure holding all necessary informations
  1056. * @mc: memory controller structure holding memory informations
  1057. *
  1058. * Function will place try to place VRAM at same place as in CPU (PCI)
  1059. * address space as some GPU seems to have issue when we reprogram at
  1060. * different address space.
  1061. *
  1062. * If there is not enough space to fit the unvisible VRAM after the
  1063. * aperture then we limit the VRAM size to the aperture.
  1064. *
  1065. * If we are using AGP then place VRAM adjacent to AGP aperture are we need
  1066. * them to be in one from GPU point of view so that we can program GPU to
  1067. * catch access outside them (weird GPU policy see ??).
  1068. *
  1069. * This function will never fails, worst case are limiting VRAM or GTT.
  1070. *
  1071. * Note: GTT start, end, size should be initialized before calling this
  1072. * function on AGP platform.
  1073. */
  1074. static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  1075. {
  1076. u64 size_bf, size_af;
  1077. if (mc->mc_vram_size > 0xE0000000) {
  1078. /* leave room for at least 512M GTT */
  1079. dev_warn(rdev->dev, "limiting VRAM\n");
  1080. mc->real_vram_size = 0xE0000000;
  1081. mc->mc_vram_size = 0xE0000000;
  1082. }
  1083. if (rdev->flags & RADEON_IS_AGP) {
  1084. size_bf = mc->gtt_start;
  1085. size_af = 0xFFFFFFFF - mc->gtt_end;
  1086. if (size_bf > size_af) {
  1087. if (mc->mc_vram_size > size_bf) {
  1088. dev_warn(rdev->dev, "limiting VRAM\n");
  1089. mc->real_vram_size = size_bf;
  1090. mc->mc_vram_size = size_bf;
  1091. }
  1092. mc->vram_start = mc->gtt_start - mc->mc_vram_size;
  1093. } else {
  1094. if (mc->mc_vram_size > size_af) {
  1095. dev_warn(rdev->dev, "limiting VRAM\n");
  1096. mc->real_vram_size = size_af;
  1097. mc->mc_vram_size = size_af;
  1098. }
  1099. mc->vram_start = mc->gtt_end + 1;
  1100. }
  1101. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  1102. dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
  1103. mc->mc_vram_size >> 20, mc->vram_start,
  1104. mc->vram_end, mc->real_vram_size >> 20);
  1105. } else {
  1106. u64 base = 0;
  1107. if (rdev->flags & RADEON_IS_IGP) {
  1108. base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
  1109. base <<= 24;
  1110. }
  1111. radeon_vram_location(rdev, &rdev->mc, base);
  1112. rdev->mc.gtt_base_align = 0;
  1113. radeon_gtt_location(rdev, mc);
  1114. }
  1115. }
  1116. int r600_mc_init(struct radeon_device *rdev)
  1117. {
  1118. u32 tmp;
  1119. int chansize, numchan;
  1120. /* Get VRAM informations */
  1121. rdev->mc.vram_is_ddr = true;
  1122. tmp = RREG32(RAMCFG);
  1123. if (tmp & CHANSIZE_OVERRIDE) {
  1124. chansize = 16;
  1125. } else if (tmp & CHANSIZE_MASK) {
  1126. chansize = 64;
  1127. } else {
  1128. chansize = 32;
  1129. }
  1130. tmp = RREG32(CHMAP);
  1131. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1132. case 0:
  1133. default:
  1134. numchan = 1;
  1135. break;
  1136. case 1:
  1137. numchan = 2;
  1138. break;
  1139. case 2:
  1140. numchan = 4;
  1141. break;
  1142. case 3:
  1143. numchan = 8;
  1144. break;
  1145. }
  1146. rdev->mc.vram_width = numchan * chansize;
  1147. /* Could aper size report 0 ? */
  1148. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  1149. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  1150. /* Setup GPU memory space */
  1151. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  1152. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  1153. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  1154. r600_vram_gtt_location(rdev, &rdev->mc);
  1155. if (rdev->flags & RADEON_IS_IGP) {
  1156. rs690_pm_info(rdev);
  1157. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  1158. }
  1159. radeon_update_bandwidth_info(rdev);
  1160. return 0;
  1161. }
  1162. int r600_vram_scratch_init(struct radeon_device *rdev)
  1163. {
  1164. int r;
  1165. if (rdev->vram_scratch.robj == NULL) {
  1166. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
  1167. PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
  1168. &rdev->vram_scratch.robj);
  1169. if (r) {
  1170. return r;
  1171. }
  1172. }
  1173. r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
  1174. if (unlikely(r != 0))
  1175. return r;
  1176. r = radeon_bo_pin(rdev->vram_scratch.robj,
  1177. RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
  1178. if (r) {
  1179. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1180. return r;
  1181. }
  1182. r = radeon_bo_kmap(rdev->vram_scratch.robj,
  1183. (void **)&rdev->vram_scratch.ptr);
  1184. if (r)
  1185. radeon_bo_unpin(rdev->vram_scratch.robj);
  1186. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1187. return r;
  1188. }
  1189. void r600_vram_scratch_fini(struct radeon_device *rdev)
  1190. {
  1191. int r;
  1192. if (rdev->vram_scratch.robj == NULL) {
  1193. return;
  1194. }
  1195. r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
  1196. if (likely(r == 0)) {
  1197. radeon_bo_kunmap(rdev->vram_scratch.robj);
  1198. radeon_bo_unpin(rdev->vram_scratch.robj);
  1199. radeon_bo_unreserve(rdev->vram_scratch.robj);
  1200. }
  1201. radeon_bo_unref(&rdev->vram_scratch.robj);
  1202. }
  1203. /* We doesn't check that the GPU really needs a reset we simply do the
  1204. * reset, it's up to the caller to determine if the GPU needs one. We
  1205. * might add an helper function to check that.
  1206. */
  1207. int r600_gpu_soft_reset(struct radeon_device *rdev)
  1208. {
  1209. struct rv515_mc_save save;
  1210. u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
  1211. S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
  1212. S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
  1213. S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
  1214. S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
  1215. S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
  1216. S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
  1217. S_008010_GUI_ACTIVE(1);
  1218. u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
  1219. S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
  1220. S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
  1221. S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
  1222. S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
  1223. S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
  1224. S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
  1225. S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
  1226. u32 tmp;
  1227. if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
  1228. return 0;
  1229. dev_info(rdev->dev, "GPU softreset \n");
  1230. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  1231. RREG32(R_008010_GRBM_STATUS));
  1232. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  1233. RREG32(R_008014_GRBM_STATUS2));
  1234. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  1235. RREG32(R_000E50_SRBM_STATUS));
  1236. rv515_mc_stop(rdev, &save);
  1237. if (r600_mc_wait_for_idle(rdev)) {
  1238. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1239. }
  1240. /* Disable CP parsing/prefetching */
  1241. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1242. /* Check if any of the rendering block is busy and reset it */
  1243. if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
  1244. (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
  1245. tmp = S_008020_SOFT_RESET_CR(1) |
  1246. S_008020_SOFT_RESET_DB(1) |
  1247. S_008020_SOFT_RESET_CB(1) |
  1248. S_008020_SOFT_RESET_PA(1) |
  1249. S_008020_SOFT_RESET_SC(1) |
  1250. S_008020_SOFT_RESET_SMX(1) |
  1251. S_008020_SOFT_RESET_SPI(1) |
  1252. S_008020_SOFT_RESET_SX(1) |
  1253. S_008020_SOFT_RESET_SH(1) |
  1254. S_008020_SOFT_RESET_TC(1) |
  1255. S_008020_SOFT_RESET_TA(1) |
  1256. S_008020_SOFT_RESET_VC(1) |
  1257. S_008020_SOFT_RESET_VGT(1);
  1258. dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  1259. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  1260. RREG32(R_008020_GRBM_SOFT_RESET);
  1261. mdelay(15);
  1262. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  1263. }
  1264. /* Reset CP (we always reset CP) */
  1265. tmp = S_008020_SOFT_RESET_CP(1);
  1266. dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  1267. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  1268. RREG32(R_008020_GRBM_SOFT_RESET);
  1269. mdelay(15);
  1270. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  1271. /* Wait a little for things to settle down */
  1272. mdelay(1);
  1273. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  1274. RREG32(R_008010_GRBM_STATUS));
  1275. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  1276. RREG32(R_008014_GRBM_STATUS2));
  1277. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  1278. RREG32(R_000E50_SRBM_STATUS));
  1279. rv515_mc_resume(rdev, &save);
  1280. return 0;
  1281. }
  1282. bool r600_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  1283. {
  1284. u32 srbm_status;
  1285. u32 grbm_status;
  1286. u32 grbm_status2;
  1287. struct r100_gpu_lockup *lockup;
  1288. int r;
  1289. if (rdev->family >= CHIP_RV770)
  1290. lockup = &rdev->config.rv770.lockup;
  1291. else
  1292. lockup = &rdev->config.r600.lockup;
  1293. srbm_status = RREG32(R_000E50_SRBM_STATUS);
  1294. grbm_status = RREG32(R_008010_GRBM_STATUS);
  1295. grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
  1296. if (!G_008010_GUI_ACTIVE(grbm_status)) {
  1297. r100_gpu_lockup_update(lockup, ring);
  1298. return false;
  1299. }
  1300. /* force CP activities */
  1301. r = radeon_ring_lock(rdev, ring, 2);
  1302. if (!r) {
  1303. /* PACKET2 NOP */
  1304. radeon_ring_write(ring, 0x80000000);
  1305. radeon_ring_write(ring, 0x80000000);
  1306. radeon_ring_unlock_commit(rdev, ring);
  1307. }
  1308. ring->rptr = RREG32(ring->rptr_reg);
  1309. return r100_gpu_cp_is_lockup(rdev, lockup, ring);
  1310. }
  1311. int r600_asic_reset(struct radeon_device *rdev)
  1312. {
  1313. return r600_gpu_soft_reset(rdev);
  1314. }
  1315. static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
  1316. u32 num_backends,
  1317. u32 backend_disable_mask)
  1318. {
  1319. u32 backend_map = 0;
  1320. u32 enabled_backends_mask;
  1321. u32 enabled_backends_count;
  1322. u32 cur_pipe;
  1323. u32 swizzle_pipe[R6XX_MAX_PIPES];
  1324. u32 cur_backend;
  1325. u32 i;
  1326. if (num_tile_pipes > R6XX_MAX_PIPES)
  1327. num_tile_pipes = R6XX_MAX_PIPES;
  1328. if (num_tile_pipes < 1)
  1329. num_tile_pipes = 1;
  1330. if (num_backends > R6XX_MAX_BACKENDS)
  1331. num_backends = R6XX_MAX_BACKENDS;
  1332. if (num_backends < 1)
  1333. num_backends = 1;
  1334. enabled_backends_mask = 0;
  1335. enabled_backends_count = 0;
  1336. for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
  1337. if (((backend_disable_mask >> i) & 1) == 0) {
  1338. enabled_backends_mask |= (1 << i);
  1339. ++enabled_backends_count;
  1340. }
  1341. if (enabled_backends_count == num_backends)
  1342. break;
  1343. }
  1344. if (enabled_backends_count == 0) {
  1345. enabled_backends_mask = 1;
  1346. enabled_backends_count = 1;
  1347. }
  1348. if (enabled_backends_count != num_backends)
  1349. num_backends = enabled_backends_count;
  1350. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
  1351. switch (num_tile_pipes) {
  1352. case 1:
  1353. swizzle_pipe[0] = 0;
  1354. break;
  1355. case 2:
  1356. swizzle_pipe[0] = 0;
  1357. swizzle_pipe[1] = 1;
  1358. break;
  1359. case 3:
  1360. swizzle_pipe[0] = 0;
  1361. swizzle_pipe[1] = 1;
  1362. swizzle_pipe[2] = 2;
  1363. break;
  1364. case 4:
  1365. swizzle_pipe[0] = 0;
  1366. swizzle_pipe[1] = 1;
  1367. swizzle_pipe[2] = 2;
  1368. swizzle_pipe[3] = 3;
  1369. break;
  1370. case 5:
  1371. swizzle_pipe[0] = 0;
  1372. swizzle_pipe[1] = 1;
  1373. swizzle_pipe[2] = 2;
  1374. swizzle_pipe[3] = 3;
  1375. swizzle_pipe[4] = 4;
  1376. break;
  1377. case 6:
  1378. swizzle_pipe[0] = 0;
  1379. swizzle_pipe[1] = 2;
  1380. swizzle_pipe[2] = 4;
  1381. swizzle_pipe[3] = 5;
  1382. swizzle_pipe[4] = 1;
  1383. swizzle_pipe[5] = 3;
  1384. break;
  1385. case 7:
  1386. swizzle_pipe[0] = 0;
  1387. swizzle_pipe[1] = 2;
  1388. swizzle_pipe[2] = 4;
  1389. swizzle_pipe[3] = 6;
  1390. swizzle_pipe[4] = 1;
  1391. swizzle_pipe[5] = 3;
  1392. swizzle_pipe[6] = 5;
  1393. break;
  1394. case 8:
  1395. swizzle_pipe[0] = 0;
  1396. swizzle_pipe[1] = 2;
  1397. swizzle_pipe[2] = 4;
  1398. swizzle_pipe[3] = 6;
  1399. swizzle_pipe[4] = 1;
  1400. swizzle_pipe[5] = 3;
  1401. swizzle_pipe[6] = 5;
  1402. swizzle_pipe[7] = 7;
  1403. break;
  1404. }
  1405. cur_backend = 0;
  1406. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  1407. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  1408. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  1409. backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
  1410. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  1411. }
  1412. return backend_map;
  1413. }
  1414. int r600_count_pipe_bits(uint32_t val)
  1415. {
  1416. int i, ret = 0;
  1417. for (i = 0; i < 32; i++) {
  1418. ret += val & 1;
  1419. val >>= 1;
  1420. }
  1421. return ret;
  1422. }
  1423. void r600_gpu_init(struct radeon_device *rdev)
  1424. {
  1425. u32 tiling_config;
  1426. u32 ramcfg;
  1427. u32 backend_map;
  1428. u32 cc_rb_backend_disable;
  1429. u32 cc_gc_shader_pipe_config;
  1430. u32 tmp;
  1431. int i, j;
  1432. u32 sq_config;
  1433. u32 sq_gpr_resource_mgmt_1 = 0;
  1434. u32 sq_gpr_resource_mgmt_2 = 0;
  1435. u32 sq_thread_resource_mgmt = 0;
  1436. u32 sq_stack_resource_mgmt_1 = 0;
  1437. u32 sq_stack_resource_mgmt_2 = 0;
  1438. /* FIXME: implement */
  1439. switch (rdev->family) {
  1440. case CHIP_R600:
  1441. rdev->config.r600.max_pipes = 4;
  1442. rdev->config.r600.max_tile_pipes = 8;
  1443. rdev->config.r600.max_simds = 4;
  1444. rdev->config.r600.max_backends = 4;
  1445. rdev->config.r600.max_gprs = 256;
  1446. rdev->config.r600.max_threads = 192;
  1447. rdev->config.r600.max_stack_entries = 256;
  1448. rdev->config.r600.max_hw_contexts = 8;
  1449. rdev->config.r600.max_gs_threads = 16;
  1450. rdev->config.r600.sx_max_export_size = 128;
  1451. rdev->config.r600.sx_max_export_pos_size = 16;
  1452. rdev->config.r600.sx_max_export_smx_size = 128;
  1453. rdev->config.r600.sq_num_cf_insts = 2;
  1454. break;
  1455. case CHIP_RV630:
  1456. case CHIP_RV635:
  1457. rdev->config.r600.max_pipes = 2;
  1458. rdev->config.r600.max_tile_pipes = 2;
  1459. rdev->config.r600.max_simds = 3;
  1460. rdev->config.r600.max_backends = 1;
  1461. rdev->config.r600.max_gprs = 128;
  1462. rdev->config.r600.max_threads = 192;
  1463. rdev->config.r600.max_stack_entries = 128;
  1464. rdev->config.r600.max_hw_contexts = 8;
  1465. rdev->config.r600.max_gs_threads = 4;
  1466. rdev->config.r600.sx_max_export_size = 128;
  1467. rdev->config.r600.sx_max_export_pos_size = 16;
  1468. rdev->config.r600.sx_max_export_smx_size = 128;
  1469. rdev->config.r600.sq_num_cf_insts = 2;
  1470. break;
  1471. case CHIP_RV610:
  1472. case CHIP_RV620:
  1473. case CHIP_RS780:
  1474. case CHIP_RS880:
  1475. rdev->config.r600.max_pipes = 1;
  1476. rdev->config.r600.max_tile_pipes = 1;
  1477. rdev->config.r600.max_simds = 2;
  1478. rdev->config.r600.max_backends = 1;
  1479. rdev->config.r600.max_gprs = 128;
  1480. rdev->config.r600.max_threads = 192;
  1481. rdev->config.r600.max_stack_entries = 128;
  1482. rdev->config.r600.max_hw_contexts = 4;
  1483. rdev->config.r600.max_gs_threads = 4;
  1484. rdev->config.r600.sx_max_export_size = 128;
  1485. rdev->config.r600.sx_max_export_pos_size = 16;
  1486. rdev->config.r600.sx_max_export_smx_size = 128;
  1487. rdev->config.r600.sq_num_cf_insts = 1;
  1488. break;
  1489. case CHIP_RV670:
  1490. rdev->config.r600.max_pipes = 4;
  1491. rdev->config.r600.max_tile_pipes = 4;
  1492. rdev->config.r600.max_simds = 4;
  1493. rdev->config.r600.max_backends = 4;
  1494. rdev->config.r600.max_gprs = 192;
  1495. rdev->config.r600.max_threads = 192;
  1496. rdev->config.r600.max_stack_entries = 256;
  1497. rdev->config.r600.max_hw_contexts = 8;
  1498. rdev->config.r600.max_gs_threads = 16;
  1499. rdev->config.r600.sx_max_export_size = 128;
  1500. rdev->config.r600.sx_max_export_pos_size = 16;
  1501. rdev->config.r600.sx_max_export_smx_size = 128;
  1502. rdev->config.r600.sq_num_cf_insts = 2;
  1503. break;
  1504. default:
  1505. break;
  1506. }
  1507. /* Initialize HDP */
  1508. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1509. WREG32((0x2c14 + j), 0x00000000);
  1510. WREG32((0x2c18 + j), 0x00000000);
  1511. WREG32((0x2c1c + j), 0x00000000);
  1512. WREG32((0x2c20 + j), 0x00000000);
  1513. WREG32((0x2c24 + j), 0x00000000);
  1514. }
  1515. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  1516. /* Setup tiling */
  1517. tiling_config = 0;
  1518. ramcfg = RREG32(RAMCFG);
  1519. switch (rdev->config.r600.max_tile_pipes) {
  1520. case 1:
  1521. tiling_config |= PIPE_TILING(0);
  1522. break;
  1523. case 2:
  1524. tiling_config |= PIPE_TILING(1);
  1525. break;
  1526. case 4:
  1527. tiling_config |= PIPE_TILING(2);
  1528. break;
  1529. case 8:
  1530. tiling_config |= PIPE_TILING(3);
  1531. break;
  1532. default:
  1533. break;
  1534. }
  1535. rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
  1536. rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1537. tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1538. tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
  1539. if ((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
  1540. rdev->config.r600.tiling_group_size = 512;
  1541. else
  1542. rdev->config.r600.tiling_group_size = 256;
  1543. tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  1544. if (tmp > 3) {
  1545. tiling_config |= ROW_TILING(3);
  1546. tiling_config |= SAMPLE_SPLIT(3);
  1547. } else {
  1548. tiling_config |= ROW_TILING(tmp);
  1549. tiling_config |= SAMPLE_SPLIT(tmp);
  1550. }
  1551. tiling_config |= BANK_SWAPS(1);
  1552. cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  1553. cc_rb_backend_disable |=
  1554. BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
  1555. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  1556. cc_gc_shader_pipe_config |=
  1557. INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
  1558. cc_gc_shader_pipe_config |=
  1559. INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
  1560. backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
  1561. (R6XX_MAX_BACKENDS -
  1562. r600_count_pipe_bits((cc_rb_backend_disable &
  1563. R6XX_MAX_BACKENDS_MASK) >> 16)),
  1564. (cc_rb_backend_disable >> 16));
  1565. rdev->config.r600.tile_config = tiling_config;
  1566. rdev->config.r600.backend_map = backend_map;
  1567. tiling_config |= BACKEND_MAP(backend_map);
  1568. WREG32(GB_TILING_CONFIG, tiling_config);
  1569. WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
  1570. WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
  1571. /* Setup pipes */
  1572. WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  1573. WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1574. WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1575. tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
  1576. WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
  1577. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
  1578. /* Setup some CP states */
  1579. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
  1580. WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
  1581. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
  1582. SYNC_WALKER | SYNC_ALIGNER));
  1583. /* Setup various GPU states */
  1584. if (rdev->family == CHIP_RV670)
  1585. WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
  1586. tmp = RREG32(SX_DEBUG_1);
  1587. tmp |= SMX_EVENT_RELEASE;
  1588. if ((rdev->family > CHIP_R600))
  1589. tmp |= ENABLE_NEW_SMX_ADDRESS;
  1590. WREG32(SX_DEBUG_1, tmp);
  1591. if (((rdev->family) == CHIP_R600) ||
  1592. ((rdev->family) == CHIP_RV630) ||
  1593. ((rdev->family) == CHIP_RV610) ||
  1594. ((rdev->family) == CHIP_RV620) ||
  1595. ((rdev->family) == CHIP_RS780) ||
  1596. ((rdev->family) == CHIP_RS880)) {
  1597. WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
  1598. } else {
  1599. WREG32(DB_DEBUG, 0);
  1600. }
  1601. WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
  1602. DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
  1603. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1604. WREG32(VGT_NUM_INSTANCES, 0);
  1605. WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
  1606. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
  1607. tmp = RREG32(SQ_MS_FIFO_SIZES);
  1608. if (((rdev->family) == CHIP_RV610) ||
  1609. ((rdev->family) == CHIP_RV620) ||
  1610. ((rdev->family) == CHIP_RS780) ||
  1611. ((rdev->family) == CHIP_RS880)) {
  1612. tmp = (CACHE_FIFO_SIZE(0xa) |
  1613. FETCH_FIFO_HIWATER(0xa) |
  1614. DONE_FIFO_HIWATER(0xe0) |
  1615. ALU_UPDATE_FIFO_HIWATER(0x8));
  1616. } else if (((rdev->family) == CHIP_R600) ||
  1617. ((rdev->family) == CHIP_RV630)) {
  1618. tmp &= ~DONE_FIFO_HIWATER(0xff);
  1619. tmp |= DONE_FIFO_HIWATER(0x4);
  1620. }
  1621. WREG32(SQ_MS_FIFO_SIZES, tmp);
  1622. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1623. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1624. */
  1625. sq_config = RREG32(SQ_CONFIG);
  1626. sq_config &= ~(PS_PRIO(3) |
  1627. VS_PRIO(3) |
  1628. GS_PRIO(3) |
  1629. ES_PRIO(3));
  1630. sq_config |= (DX9_CONSTS |
  1631. VC_ENABLE |
  1632. PS_PRIO(0) |
  1633. VS_PRIO(1) |
  1634. GS_PRIO(2) |
  1635. ES_PRIO(3));
  1636. if ((rdev->family) == CHIP_R600) {
  1637. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
  1638. NUM_VS_GPRS(124) |
  1639. NUM_CLAUSE_TEMP_GPRS(4));
  1640. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
  1641. NUM_ES_GPRS(0));
  1642. sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
  1643. NUM_VS_THREADS(48) |
  1644. NUM_GS_THREADS(4) |
  1645. NUM_ES_THREADS(4));
  1646. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
  1647. NUM_VS_STACK_ENTRIES(128));
  1648. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
  1649. NUM_ES_STACK_ENTRIES(0));
  1650. } else if (((rdev->family) == CHIP_RV610) ||
  1651. ((rdev->family) == CHIP_RV620) ||
  1652. ((rdev->family) == CHIP_RS780) ||
  1653. ((rdev->family) == CHIP_RS880)) {
  1654. /* no vertex cache */
  1655. sq_config &= ~VC_ENABLE;
  1656. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1657. NUM_VS_GPRS(44) |
  1658. NUM_CLAUSE_TEMP_GPRS(2));
  1659. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1660. NUM_ES_GPRS(17));
  1661. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1662. NUM_VS_THREADS(78) |
  1663. NUM_GS_THREADS(4) |
  1664. NUM_ES_THREADS(31));
  1665. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1666. NUM_VS_STACK_ENTRIES(40));
  1667. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1668. NUM_ES_STACK_ENTRIES(16));
  1669. } else if (((rdev->family) == CHIP_RV630) ||
  1670. ((rdev->family) == CHIP_RV635)) {
  1671. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1672. NUM_VS_GPRS(44) |
  1673. NUM_CLAUSE_TEMP_GPRS(2));
  1674. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
  1675. NUM_ES_GPRS(18));
  1676. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1677. NUM_VS_THREADS(78) |
  1678. NUM_GS_THREADS(4) |
  1679. NUM_ES_THREADS(31));
  1680. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1681. NUM_VS_STACK_ENTRIES(40));
  1682. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1683. NUM_ES_STACK_ENTRIES(16));
  1684. } else if ((rdev->family) == CHIP_RV670) {
  1685. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1686. NUM_VS_GPRS(44) |
  1687. NUM_CLAUSE_TEMP_GPRS(2));
  1688. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1689. NUM_ES_GPRS(17));
  1690. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1691. NUM_VS_THREADS(78) |
  1692. NUM_GS_THREADS(4) |
  1693. NUM_ES_THREADS(31));
  1694. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
  1695. NUM_VS_STACK_ENTRIES(64));
  1696. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
  1697. NUM_ES_STACK_ENTRIES(64));
  1698. }
  1699. WREG32(SQ_CONFIG, sq_config);
  1700. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  1701. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  1702. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  1703. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  1704. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  1705. if (((rdev->family) == CHIP_RV610) ||
  1706. ((rdev->family) == CHIP_RV620) ||
  1707. ((rdev->family) == CHIP_RS780) ||
  1708. ((rdev->family) == CHIP_RS880)) {
  1709. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
  1710. } else {
  1711. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
  1712. }
  1713. /* More default values. 2D/3D driver should adjust as needed */
  1714. WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
  1715. S1_X(0x4) | S1_Y(0xc)));
  1716. WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
  1717. S1_X(0x2) | S1_Y(0x2) |
  1718. S2_X(0xa) | S2_Y(0x6) |
  1719. S3_X(0x6) | S3_Y(0xa)));
  1720. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
  1721. S1_X(0x4) | S1_Y(0xc) |
  1722. S2_X(0x1) | S2_Y(0x6) |
  1723. S3_X(0xa) | S3_Y(0xe)));
  1724. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
  1725. S5_X(0x0) | S5_Y(0x0) |
  1726. S6_X(0xb) | S6_Y(0x4) |
  1727. S7_X(0x7) | S7_Y(0x8)));
  1728. WREG32(VGT_STRMOUT_EN, 0);
  1729. tmp = rdev->config.r600.max_pipes * 16;
  1730. switch (rdev->family) {
  1731. case CHIP_RV610:
  1732. case CHIP_RV620:
  1733. case CHIP_RS780:
  1734. case CHIP_RS880:
  1735. tmp += 32;
  1736. break;
  1737. case CHIP_RV670:
  1738. tmp += 128;
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. if (tmp > 256) {
  1744. tmp = 256;
  1745. }
  1746. WREG32(VGT_ES_PER_GS, 128);
  1747. WREG32(VGT_GS_PER_ES, tmp);
  1748. WREG32(VGT_GS_PER_VS, 2);
  1749. WREG32(VGT_GS_VERTEX_REUSE, 16);
  1750. /* more default values. 2D/3D driver should adjust as needed */
  1751. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  1752. WREG32(VGT_STRMOUT_EN, 0);
  1753. WREG32(SX_MISC, 0);
  1754. WREG32(PA_SC_MODE_CNTL, 0);
  1755. WREG32(PA_SC_AA_CONFIG, 0);
  1756. WREG32(PA_SC_LINE_STIPPLE, 0);
  1757. WREG32(SPI_INPUT_Z, 0);
  1758. WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
  1759. WREG32(CB_COLOR7_FRAG, 0);
  1760. /* Clear render buffer base addresses */
  1761. WREG32(CB_COLOR0_BASE, 0);
  1762. WREG32(CB_COLOR1_BASE, 0);
  1763. WREG32(CB_COLOR2_BASE, 0);
  1764. WREG32(CB_COLOR3_BASE, 0);
  1765. WREG32(CB_COLOR4_BASE, 0);
  1766. WREG32(CB_COLOR5_BASE, 0);
  1767. WREG32(CB_COLOR6_BASE, 0);
  1768. WREG32(CB_COLOR7_BASE, 0);
  1769. WREG32(CB_COLOR7_FRAG, 0);
  1770. switch (rdev->family) {
  1771. case CHIP_RV610:
  1772. case CHIP_RV620:
  1773. case CHIP_RS780:
  1774. case CHIP_RS880:
  1775. tmp = TC_L2_SIZE(8);
  1776. break;
  1777. case CHIP_RV630:
  1778. case CHIP_RV635:
  1779. tmp = TC_L2_SIZE(4);
  1780. break;
  1781. case CHIP_R600:
  1782. tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
  1783. break;
  1784. default:
  1785. tmp = TC_L2_SIZE(0);
  1786. break;
  1787. }
  1788. WREG32(TC_CNTL, tmp);
  1789. tmp = RREG32(HDP_HOST_PATH_CNTL);
  1790. WREG32(HDP_HOST_PATH_CNTL, tmp);
  1791. tmp = RREG32(ARB_POP);
  1792. tmp |= ENABLE_TC128;
  1793. WREG32(ARB_POP, tmp);
  1794. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1795. WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
  1796. NUM_CLIP_SEQ(3)));
  1797. WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
  1798. WREG32(VC_ENHANCE, 0);
  1799. }
  1800. /*
  1801. * Indirect registers accessor
  1802. */
  1803. u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
  1804. {
  1805. u32 r;
  1806. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1807. (void)RREG32(PCIE_PORT_INDEX);
  1808. r = RREG32(PCIE_PORT_DATA);
  1809. return r;
  1810. }
  1811. void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1812. {
  1813. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1814. (void)RREG32(PCIE_PORT_INDEX);
  1815. WREG32(PCIE_PORT_DATA, (v));
  1816. (void)RREG32(PCIE_PORT_DATA);
  1817. }
  1818. /*
  1819. * CP & Ring
  1820. */
  1821. void r600_cp_stop(struct radeon_device *rdev)
  1822. {
  1823. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  1824. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1825. WREG32(SCRATCH_UMSK, 0);
  1826. }
  1827. int r600_init_microcode(struct radeon_device *rdev)
  1828. {
  1829. struct platform_device *pdev;
  1830. const char *chip_name;
  1831. const char *rlc_chip_name;
  1832. size_t pfp_req_size, me_req_size, rlc_req_size;
  1833. char fw_name[30];
  1834. int err;
  1835. DRM_DEBUG("\n");
  1836. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1837. err = IS_ERR(pdev);
  1838. if (err) {
  1839. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1840. return -EINVAL;
  1841. }
  1842. switch (rdev->family) {
  1843. case CHIP_R600:
  1844. chip_name = "R600";
  1845. rlc_chip_name = "R600";
  1846. break;
  1847. case CHIP_RV610:
  1848. chip_name = "RV610";
  1849. rlc_chip_name = "R600";
  1850. break;
  1851. case CHIP_RV630:
  1852. chip_name = "RV630";
  1853. rlc_chip_name = "R600";
  1854. break;
  1855. case CHIP_RV620:
  1856. chip_name = "RV620";
  1857. rlc_chip_name = "R600";
  1858. break;
  1859. case CHIP_RV635:
  1860. chip_name = "RV635";
  1861. rlc_chip_name = "R600";
  1862. break;
  1863. case CHIP_RV670:
  1864. chip_name = "RV670";
  1865. rlc_chip_name = "R600";
  1866. break;
  1867. case CHIP_RS780:
  1868. case CHIP_RS880:
  1869. chip_name = "RS780";
  1870. rlc_chip_name = "R600";
  1871. break;
  1872. case CHIP_RV770:
  1873. chip_name = "RV770";
  1874. rlc_chip_name = "R700";
  1875. break;
  1876. case CHIP_RV730:
  1877. case CHIP_RV740:
  1878. chip_name = "RV730";
  1879. rlc_chip_name = "R700";
  1880. break;
  1881. case CHIP_RV710:
  1882. chip_name = "RV710";
  1883. rlc_chip_name = "R700";
  1884. break;
  1885. case CHIP_CEDAR:
  1886. chip_name = "CEDAR";
  1887. rlc_chip_name = "CEDAR";
  1888. break;
  1889. case CHIP_REDWOOD:
  1890. chip_name = "REDWOOD";
  1891. rlc_chip_name = "REDWOOD";
  1892. break;
  1893. case CHIP_JUNIPER:
  1894. chip_name = "JUNIPER";
  1895. rlc_chip_name = "JUNIPER";
  1896. break;
  1897. case CHIP_CYPRESS:
  1898. case CHIP_HEMLOCK:
  1899. chip_name = "CYPRESS";
  1900. rlc_chip_name = "CYPRESS";
  1901. break;
  1902. case CHIP_PALM:
  1903. chip_name = "PALM";
  1904. rlc_chip_name = "SUMO";
  1905. break;
  1906. case CHIP_SUMO:
  1907. chip_name = "SUMO";
  1908. rlc_chip_name = "SUMO";
  1909. break;
  1910. case CHIP_SUMO2:
  1911. chip_name = "SUMO2";
  1912. rlc_chip_name = "SUMO";
  1913. break;
  1914. default: BUG();
  1915. }
  1916. if (rdev->family >= CHIP_CEDAR) {
  1917. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  1918. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  1919. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  1920. } else if (rdev->family >= CHIP_RV770) {
  1921. pfp_req_size = R700_PFP_UCODE_SIZE * 4;
  1922. me_req_size = R700_PM4_UCODE_SIZE * 4;
  1923. rlc_req_size = R700_RLC_UCODE_SIZE * 4;
  1924. } else {
  1925. pfp_req_size = PFP_UCODE_SIZE * 4;
  1926. me_req_size = PM4_UCODE_SIZE * 12;
  1927. rlc_req_size = RLC_UCODE_SIZE * 4;
  1928. }
  1929. DRM_INFO("Loading %s Microcode\n", chip_name);
  1930. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1931. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1932. if (err)
  1933. goto out;
  1934. if (rdev->pfp_fw->size != pfp_req_size) {
  1935. printk(KERN_ERR
  1936. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1937. rdev->pfp_fw->size, fw_name);
  1938. err = -EINVAL;
  1939. goto out;
  1940. }
  1941. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1942. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1943. if (err)
  1944. goto out;
  1945. if (rdev->me_fw->size != me_req_size) {
  1946. printk(KERN_ERR
  1947. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1948. rdev->me_fw->size, fw_name);
  1949. err = -EINVAL;
  1950. }
  1951. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1952. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1953. if (err)
  1954. goto out;
  1955. if (rdev->rlc_fw->size != rlc_req_size) {
  1956. printk(KERN_ERR
  1957. "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
  1958. rdev->rlc_fw->size, fw_name);
  1959. err = -EINVAL;
  1960. }
  1961. out:
  1962. platform_device_unregister(pdev);
  1963. if (err) {
  1964. if (err != -EINVAL)
  1965. printk(KERN_ERR
  1966. "r600_cp: Failed to load firmware \"%s\"\n",
  1967. fw_name);
  1968. release_firmware(rdev->pfp_fw);
  1969. rdev->pfp_fw = NULL;
  1970. release_firmware(rdev->me_fw);
  1971. rdev->me_fw = NULL;
  1972. release_firmware(rdev->rlc_fw);
  1973. rdev->rlc_fw = NULL;
  1974. }
  1975. return err;
  1976. }
  1977. static int r600_cp_load_microcode(struct radeon_device *rdev)
  1978. {
  1979. const __be32 *fw_data;
  1980. int i;
  1981. if (!rdev->me_fw || !rdev->pfp_fw)
  1982. return -EINVAL;
  1983. r600_cp_stop(rdev);
  1984. WREG32(CP_RB_CNTL,
  1985. #ifdef __BIG_ENDIAN
  1986. BUF_SWAP_32BIT |
  1987. #endif
  1988. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  1989. /* Reset cp */
  1990. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1991. RREG32(GRBM_SOFT_RESET);
  1992. mdelay(15);
  1993. WREG32(GRBM_SOFT_RESET, 0);
  1994. WREG32(CP_ME_RAM_WADDR, 0);
  1995. fw_data = (const __be32 *)rdev->me_fw->data;
  1996. WREG32(CP_ME_RAM_WADDR, 0);
  1997. for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
  1998. WREG32(CP_ME_RAM_DATA,
  1999. be32_to_cpup(fw_data++));
  2000. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2001. WREG32(CP_PFP_UCODE_ADDR, 0);
  2002. for (i = 0; i < PFP_UCODE_SIZE; i++)
  2003. WREG32(CP_PFP_UCODE_DATA,
  2004. be32_to_cpup(fw_data++));
  2005. WREG32(CP_PFP_UCODE_ADDR, 0);
  2006. WREG32(CP_ME_RAM_WADDR, 0);
  2007. WREG32(CP_ME_RAM_RADDR, 0);
  2008. return 0;
  2009. }
  2010. int r600_cp_start(struct radeon_device *rdev)
  2011. {
  2012. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2013. int r;
  2014. uint32_t cp_me;
  2015. r = radeon_ring_lock(rdev, ring, 7);
  2016. if (r) {
  2017. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2018. return r;
  2019. }
  2020. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2021. radeon_ring_write(ring, 0x1);
  2022. if (rdev->family >= CHIP_RV770) {
  2023. radeon_ring_write(ring, 0x0);
  2024. radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
  2025. } else {
  2026. radeon_ring_write(ring, 0x3);
  2027. radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
  2028. }
  2029. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2030. radeon_ring_write(ring, 0);
  2031. radeon_ring_write(ring, 0);
  2032. radeon_ring_unlock_commit(rdev, ring);
  2033. cp_me = 0xff;
  2034. WREG32(R_0086D8_CP_ME_CNTL, cp_me);
  2035. return 0;
  2036. }
  2037. int r600_cp_resume(struct radeon_device *rdev)
  2038. {
  2039. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2040. u32 tmp;
  2041. u32 rb_bufsz;
  2042. int r;
  2043. /* Reset cp */
  2044. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  2045. RREG32(GRBM_SOFT_RESET);
  2046. mdelay(15);
  2047. WREG32(GRBM_SOFT_RESET, 0);
  2048. /* Set ring buffer size */
  2049. rb_bufsz = drm_order(ring->ring_size / 8);
  2050. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2051. #ifdef __BIG_ENDIAN
  2052. tmp |= BUF_SWAP_32BIT;
  2053. #endif
  2054. WREG32(CP_RB_CNTL, tmp);
  2055. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2056. /* Set the write pointer delay */
  2057. WREG32(CP_RB_WPTR_DELAY, 0);
  2058. /* Initialize the ring buffer's read and write pointers */
  2059. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2060. WREG32(CP_RB_RPTR_WR, 0);
  2061. ring->wptr = 0;
  2062. WREG32(CP_RB_WPTR, ring->wptr);
  2063. /* set the wb address whether it's enabled or not */
  2064. WREG32(CP_RB_RPTR_ADDR,
  2065. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2066. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2067. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2068. if (rdev->wb.enabled)
  2069. WREG32(SCRATCH_UMSK, 0xff);
  2070. else {
  2071. tmp |= RB_NO_UPDATE;
  2072. WREG32(SCRATCH_UMSK, 0);
  2073. }
  2074. mdelay(1);
  2075. WREG32(CP_RB_CNTL, tmp);
  2076. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2077. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2078. ring->rptr = RREG32(CP_RB_RPTR);
  2079. r600_cp_start(rdev);
  2080. ring->ready = true;
  2081. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2082. if (r) {
  2083. ring->ready = false;
  2084. return r;
  2085. }
  2086. return 0;
  2087. }
  2088. void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
  2089. {
  2090. u32 rb_bufsz;
  2091. /* Align ring size */
  2092. rb_bufsz = drm_order(ring_size / 8);
  2093. ring_size = (1 << (rb_bufsz + 1)) * 4;
  2094. ring->ring_size = ring_size;
  2095. ring->align_mask = 16 - 1;
  2096. }
  2097. void r600_cp_fini(struct radeon_device *rdev)
  2098. {
  2099. r600_cp_stop(rdev);
  2100. radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2101. }
  2102. /*
  2103. * GPU scratch registers helpers function.
  2104. */
  2105. void r600_scratch_init(struct radeon_device *rdev)
  2106. {
  2107. int i;
  2108. rdev->scratch.num_reg = 7;
  2109. rdev->scratch.reg_base = SCRATCH_REG0;
  2110. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2111. rdev->scratch.free[i] = true;
  2112. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2113. }
  2114. }
  2115. int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
  2116. {
  2117. uint32_t scratch;
  2118. uint32_t tmp = 0;
  2119. unsigned i, ridx = radeon_ring_index(rdev, ring);
  2120. int r;
  2121. r = radeon_scratch_get(rdev, &scratch);
  2122. if (r) {
  2123. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  2124. return r;
  2125. }
  2126. WREG32(scratch, 0xCAFEDEAD);
  2127. r = radeon_ring_lock(rdev, ring, 3);
  2128. if (r) {
  2129. DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ridx, r);
  2130. radeon_scratch_free(rdev, scratch);
  2131. return r;
  2132. }
  2133. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2134. radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  2135. radeon_ring_write(ring, 0xDEADBEEF);
  2136. radeon_ring_unlock_commit(rdev, ring);
  2137. for (i = 0; i < rdev->usec_timeout; i++) {
  2138. tmp = RREG32(scratch);
  2139. if (tmp == 0xDEADBEEF)
  2140. break;
  2141. DRM_UDELAY(1);
  2142. }
  2143. if (i < rdev->usec_timeout) {
  2144. DRM_INFO("ring test on %d succeeded in %d usecs\n", ridx, i);
  2145. } else {
  2146. DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  2147. ridx, scratch, tmp);
  2148. r = -EINVAL;
  2149. }
  2150. radeon_scratch_free(rdev, scratch);
  2151. return r;
  2152. }
  2153. void r600_fence_ring_emit(struct radeon_device *rdev,
  2154. struct radeon_fence *fence)
  2155. {
  2156. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2157. u32 cp_coher_cntl = PACKET3_TC_ACTION_ENA | PACKET3_VC_ACTION_ENA |
  2158. PACKET3_SH_ACTION_ENA;
  2159. if (rdev->family >= CHIP_RV770)
  2160. cp_coher_cntl |= PACKET3_FULL_CACHE_ENA;
  2161. if (rdev->wb.use_event) {
  2162. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2163. /* flush read cache over gart */
  2164. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2165. radeon_ring_write(ring, cp_coher_cntl);
  2166. radeon_ring_write(ring, 0xFFFFFFFF);
  2167. radeon_ring_write(ring, 0);
  2168. radeon_ring_write(ring, 10); /* poll interval */
  2169. /* EVENT_WRITE_EOP - flush caches, send int */
  2170. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2171. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
  2172. radeon_ring_write(ring, addr & 0xffffffff);
  2173. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2174. radeon_ring_write(ring, fence->seq);
  2175. radeon_ring_write(ring, 0);
  2176. } else {
  2177. /* flush read cache over gart */
  2178. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2179. radeon_ring_write(ring, cp_coher_cntl);
  2180. radeon_ring_write(ring, 0xFFFFFFFF);
  2181. radeon_ring_write(ring, 0);
  2182. radeon_ring_write(ring, 10); /* poll interval */
  2183. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  2184. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
  2185. /* wait for 3D idle clean */
  2186. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2187. radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2188. radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
  2189. /* Emit fence sequence & fire IRQ */
  2190. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2191. radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  2192. radeon_ring_write(ring, fence->seq);
  2193. /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
  2194. radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
  2195. radeon_ring_write(ring, RB_INT_STAT);
  2196. }
  2197. }
  2198. void r600_semaphore_ring_emit(struct radeon_device *rdev,
  2199. struct radeon_ring *ring,
  2200. struct radeon_semaphore *semaphore,
  2201. bool emit_wait)
  2202. {
  2203. uint64_t addr = semaphore->gpu_addr;
  2204. unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
  2205. if (rdev->family < CHIP_CAYMAN)
  2206. sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
  2207. radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
  2208. radeon_ring_write(ring, addr & 0xffffffff);
  2209. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
  2210. }
  2211. int r600_copy_blit(struct radeon_device *rdev,
  2212. uint64_t src_offset,
  2213. uint64_t dst_offset,
  2214. unsigned num_gpu_pages,
  2215. struct radeon_fence *fence)
  2216. {
  2217. int r;
  2218. mutex_lock(&rdev->r600_blit.mutex);
  2219. rdev->r600_blit.vb_ib = NULL;
  2220. r = r600_blit_prepare_copy(rdev, num_gpu_pages);
  2221. if (r) {
  2222. if (rdev->r600_blit.vb_ib)
  2223. radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
  2224. mutex_unlock(&rdev->r600_blit.mutex);
  2225. return r;
  2226. }
  2227. r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages);
  2228. r600_blit_done_copy(rdev, fence);
  2229. mutex_unlock(&rdev->r600_blit.mutex);
  2230. return 0;
  2231. }
  2232. void r600_blit_suspend(struct radeon_device *rdev)
  2233. {
  2234. int r;
  2235. /* unpin shaders bo */
  2236. if (rdev->r600_blit.shader_obj) {
  2237. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  2238. if (!r) {
  2239. radeon_bo_unpin(rdev->r600_blit.shader_obj);
  2240. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  2241. }
  2242. }
  2243. }
  2244. int r600_set_surface_reg(struct radeon_device *rdev, int reg,
  2245. uint32_t tiling_flags, uint32_t pitch,
  2246. uint32_t offset, uint32_t obj_size)
  2247. {
  2248. /* FIXME: implement */
  2249. return 0;
  2250. }
  2251. void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
  2252. {
  2253. /* FIXME: implement */
  2254. }
  2255. int r600_startup(struct radeon_device *rdev)
  2256. {
  2257. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2258. int r;
  2259. /* enable pcie gen2 link */
  2260. r600_pcie_gen2_enable(rdev);
  2261. r600_mc_program(rdev);
  2262. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  2263. r = r600_init_microcode(rdev);
  2264. if (r) {
  2265. DRM_ERROR("Failed to load firmware!\n");
  2266. return r;
  2267. }
  2268. }
  2269. r = r600_vram_scratch_init(rdev);
  2270. if (r)
  2271. return r;
  2272. if (rdev->flags & RADEON_IS_AGP) {
  2273. r600_agp_enable(rdev);
  2274. } else {
  2275. r = r600_pcie_gart_enable(rdev);
  2276. if (r)
  2277. return r;
  2278. }
  2279. r600_gpu_init(rdev);
  2280. r = r600_blit_init(rdev);
  2281. if (r) {
  2282. r600_blit_fini(rdev);
  2283. rdev->asic->copy.copy = NULL;
  2284. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  2285. }
  2286. /* allocate wb buffer */
  2287. r = radeon_wb_init(rdev);
  2288. if (r)
  2289. return r;
  2290. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2291. if (r) {
  2292. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  2293. return r;
  2294. }
  2295. /* Enable IRQ */
  2296. if (!rdev->irq.installed) {
  2297. r = radeon_irq_kms_init(rdev);
  2298. if (r)
  2299. return r;
  2300. }
  2301. r = r600_irq_init(rdev);
  2302. if (r) {
  2303. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  2304. radeon_irq_kms_fini(rdev);
  2305. return r;
  2306. }
  2307. r600_irq_set(rdev);
  2308. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  2309. R600_CP_RB_RPTR, R600_CP_RB_WPTR,
  2310. 0, 0xfffff, RADEON_CP_PACKET2);
  2311. if (r)
  2312. return r;
  2313. r = r600_cp_load_microcode(rdev);
  2314. if (r)
  2315. return r;
  2316. r = r600_cp_resume(rdev);
  2317. if (r)
  2318. return r;
  2319. r = radeon_ib_pool_start(rdev);
  2320. if (r)
  2321. return r;
  2322. r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2323. if (r) {
  2324. DRM_ERROR("radeon: failed testing IB (%d).\n", r);
  2325. rdev->accel_working = false;
  2326. return r;
  2327. }
  2328. return 0;
  2329. }
  2330. void r600_vga_set_state(struct radeon_device *rdev, bool state)
  2331. {
  2332. uint32_t temp;
  2333. temp = RREG32(CONFIG_CNTL);
  2334. if (state == false) {
  2335. temp &= ~(1<<0);
  2336. temp |= (1<<1);
  2337. } else {
  2338. temp &= ~(1<<1);
  2339. }
  2340. WREG32(CONFIG_CNTL, temp);
  2341. }
  2342. int r600_resume(struct radeon_device *rdev)
  2343. {
  2344. int r;
  2345. /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
  2346. * posting will perform necessary task to bring back GPU into good
  2347. * shape.
  2348. */
  2349. /* post card */
  2350. atom_asic_init(rdev->mode_info.atom_context);
  2351. rdev->accel_working = true;
  2352. r = r600_startup(rdev);
  2353. if (r) {
  2354. DRM_ERROR("r600 startup failed on resume\n");
  2355. rdev->accel_working = false;
  2356. return r;
  2357. }
  2358. r = r600_audio_init(rdev);
  2359. if (r) {
  2360. DRM_ERROR("radeon: audio resume failed\n");
  2361. return r;
  2362. }
  2363. return r;
  2364. }
  2365. int r600_suspend(struct radeon_device *rdev)
  2366. {
  2367. r600_audio_fini(rdev);
  2368. radeon_ib_pool_suspend(rdev);
  2369. r600_blit_suspend(rdev);
  2370. /* FIXME: we should wait for ring to be empty */
  2371. r600_cp_stop(rdev);
  2372. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2373. r600_irq_suspend(rdev);
  2374. radeon_wb_disable(rdev);
  2375. r600_pcie_gart_disable(rdev);
  2376. return 0;
  2377. }
  2378. /* Plan is to move initialization in that function and use
  2379. * helper function so that radeon_device_init pretty much
  2380. * do nothing more than calling asic specific function. This
  2381. * should also allow to remove a bunch of callback function
  2382. * like vram_info.
  2383. */
  2384. int r600_init(struct radeon_device *rdev)
  2385. {
  2386. int r;
  2387. if (r600_debugfs_mc_info_init(rdev)) {
  2388. DRM_ERROR("Failed to register debugfs file for mc !\n");
  2389. }
  2390. /* This don't do much */
  2391. r = radeon_gem_init(rdev);
  2392. if (r)
  2393. return r;
  2394. /* Read BIOS */
  2395. if (!radeon_get_bios(rdev)) {
  2396. if (ASIC_IS_AVIVO(rdev))
  2397. return -EINVAL;
  2398. }
  2399. /* Must be an ATOMBIOS */
  2400. if (!rdev->is_atom_bios) {
  2401. dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
  2402. return -EINVAL;
  2403. }
  2404. r = radeon_atombios_init(rdev);
  2405. if (r)
  2406. return r;
  2407. /* Post card if necessary */
  2408. if (!radeon_card_posted(rdev)) {
  2409. if (!rdev->bios) {
  2410. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  2411. return -EINVAL;
  2412. }
  2413. DRM_INFO("GPU not posted. posting now...\n");
  2414. atom_asic_init(rdev->mode_info.atom_context);
  2415. }
  2416. /* Initialize scratch registers */
  2417. r600_scratch_init(rdev);
  2418. /* Initialize surface registers */
  2419. radeon_surface_init(rdev);
  2420. /* Initialize clocks */
  2421. radeon_get_clock_info(rdev->ddev);
  2422. /* Fence driver */
  2423. r = radeon_fence_driver_init(rdev);
  2424. if (r)
  2425. return r;
  2426. if (rdev->flags & RADEON_IS_AGP) {
  2427. r = radeon_agp_init(rdev);
  2428. if (r)
  2429. radeon_agp_disable(rdev);
  2430. }
  2431. r = r600_mc_init(rdev);
  2432. if (r)
  2433. return r;
  2434. /* Memory manager */
  2435. r = radeon_bo_init(rdev);
  2436. if (r)
  2437. return r;
  2438. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  2439. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  2440. rdev->ih.ring_obj = NULL;
  2441. r600_ih_ring_init(rdev, 64 * 1024);
  2442. r = r600_pcie_gart_init(rdev);
  2443. if (r)
  2444. return r;
  2445. r = radeon_ib_pool_init(rdev);
  2446. rdev->accel_working = true;
  2447. if (r) {
  2448. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  2449. rdev->accel_working = false;
  2450. }
  2451. r = r600_startup(rdev);
  2452. if (r) {
  2453. dev_err(rdev->dev, "disabling GPU acceleration\n");
  2454. r600_cp_fini(rdev);
  2455. r600_irq_fini(rdev);
  2456. radeon_wb_fini(rdev);
  2457. r100_ib_fini(rdev);
  2458. radeon_irq_kms_fini(rdev);
  2459. r600_pcie_gart_fini(rdev);
  2460. rdev->accel_working = false;
  2461. }
  2462. r = r600_audio_init(rdev);
  2463. if (r)
  2464. return r; /* TODO error handling */
  2465. return 0;
  2466. }
  2467. void r600_fini(struct radeon_device *rdev)
  2468. {
  2469. r600_audio_fini(rdev);
  2470. r600_blit_fini(rdev);
  2471. r600_cp_fini(rdev);
  2472. r600_irq_fini(rdev);
  2473. radeon_wb_fini(rdev);
  2474. r100_ib_fini(rdev);
  2475. radeon_irq_kms_fini(rdev);
  2476. r600_pcie_gart_fini(rdev);
  2477. r600_vram_scratch_fini(rdev);
  2478. radeon_agp_fini(rdev);
  2479. radeon_gem_fini(rdev);
  2480. radeon_semaphore_driver_fini(rdev);
  2481. radeon_fence_driver_fini(rdev);
  2482. radeon_bo_fini(rdev);
  2483. radeon_atombios_fini(rdev);
  2484. kfree(rdev->bios);
  2485. rdev->bios = NULL;
  2486. }
  2487. /*
  2488. * CS stuff
  2489. */
  2490. void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2491. {
  2492. struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
  2493. /* FIXME: implement */
  2494. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2495. radeon_ring_write(ring,
  2496. #ifdef __BIG_ENDIAN
  2497. (2 << 0) |
  2498. #endif
  2499. (ib->gpu_addr & 0xFFFFFFFC));
  2500. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  2501. radeon_ring_write(ring, ib->length_dw);
  2502. }
  2503. int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
  2504. {
  2505. struct radeon_ib *ib;
  2506. uint32_t scratch;
  2507. uint32_t tmp = 0;
  2508. unsigned i;
  2509. int r;
  2510. int ring_index = radeon_ring_index(rdev, ring);
  2511. r = radeon_scratch_get(rdev, &scratch);
  2512. if (r) {
  2513. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  2514. return r;
  2515. }
  2516. WREG32(scratch, 0xCAFEDEAD);
  2517. r = radeon_ib_get(rdev, ring_index, &ib, 256);
  2518. if (r) {
  2519. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  2520. return r;
  2521. }
  2522. ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
  2523. ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2524. ib->ptr[2] = 0xDEADBEEF;
  2525. ib->length_dw = 3;
  2526. r = radeon_ib_schedule(rdev, ib);
  2527. if (r) {
  2528. radeon_scratch_free(rdev, scratch);
  2529. radeon_ib_free(rdev, &ib);
  2530. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  2531. return r;
  2532. }
  2533. r = radeon_fence_wait(ib->fence, false);
  2534. if (r) {
  2535. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  2536. return r;
  2537. }
  2538. for (i = 0; i < rdev->usec_timeout; i++) {
  2539. tmp = RREG32(scratch);
  2540. if (tmp == 0xDEADBEEF)
  2541. break;
  2542. DRM_UDELAY(1);
  2543. }
  2544. if (i < rdev->usec_timeout) {
  2545. DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib->fence->ring, i);
  2546. } else {
  2547. DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
  2548. scratch, tmp);
  2549. r = -EINVAL;
  2550. }
  2551. radeon_scratch_free(rdev, scratch);
  2552. radeon_ib_free(rdev, &ib);
  2553. return r;
  2554. }
  2555. /*
  2556. * Interrupts
  2557. *
  2558. * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
  2559. * the same as the CP ring buffer, but in reverse. Rather than the CPU
  2560. * writing to the ring and the GPU consuming, the GPU writes to the ring
  2561. * and host consumes. As the host irq handler processes interrupts, it
  2562. * increments the rptr. When the rptr catches up with the wptr, all the
  2563. * current interrupts have been processed.
  2564. */
  2565. void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
  2566. {
  2567. u32 rb_bufsz;
  2568. /* Align ring size */
  2569. rb_bufsz = drm_order(ring_size / 4);
  2570. ring_size = (1 << rb_bufsz) * 4;
  2571. rdev->ih.ring_size = ring_size;
  2572. rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
  2573. rdev->ih.rptr = 0;
  2574. }
  2575. int r600_ih_ring_alloc(struct radeon_device *rdev)
  2576. {
  2577. int r;
  2578. /* Allocate ring buffer */
  2579. if (rdev->ih.ring_obj == NULL) {
  2580. r = radeon_bo_create(rdev, rdev->ih.ring_size,
  2581. PAGE_SIZE, true,
  2582. RADEON_GEM_DOMAIN_GTT,
  2583. &rdev->ih.ring_obj);
  2584. if (r) {
  2585. DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
  2586. return r;
  2587. }
  2588. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2589. if (unlikely(r != 0))
  2590. return r;
  2591. r = radeon_bo_pin(rdev->ih.ring_obj,
  2592. RADEON_GEM_DOMAIN_GTT,
  2593. &rdev->ih.gpu_addr);
  2594. if (r) {
  2595. radeon_bo_unreserve(rdev->ih.ring_obj);
  2596. DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
  2597. return r;
  2598. }
  2599. r = radeon_bo_kmap(rdev->ih.ring_obj,
  2600. (void **)&rdev->ih.ring);
  2601. radeon_bo_unreserve(rdev->ih.ring_obj);
  2602. if (r) {
  2603. DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
  2604. return r;
  2605. }
  2606. }
  2607. return 0;
  2608. }
  2609. void r600_ih_ring_fini(struct radeon_device *rdev)
  2610. {
  2611. int r;
  2612. if (rdev->ih.ring_obj) {
  2613. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2614. if (likely(r == 0)) {
  2615. radeon_bo_kunmap(rdev->ih.ring_obj);
  2616. radeon_bo_unpin(rdev->ih.ring_obj);
  2617. radeon_bo_unreserve(rdev->ih.ring_obj);
  2618. }
  2619. radeon_bo_unref(&rdev->ih.ring_obj);
  2620. rdev->ih.ring = NULL;
  2621. rdev->ih.ring_obj = NULL;
  2622. }
  2623. }
  2624. void r600_rlc_stop(struct radeon_device *rdev)
  2625. {
  2626. if ((rdev->family >= CHIP_RV770) &&
  2627. (rdev->family <= CHIP_RV740)) {
  2628. /* r7xx asics need to soft reset RLC before halting */
  2629. WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
  2630. RREG32(SRBM_SOFT_RESET);
  2631. mdelay(15);
  2632. WREG32(SRBM_SOFT_RESET, 0);
  2633. RREG32(SRBM_SOFT_RESET);
  2634. }
  2635. WREG32(RLC_CNTL, 0);
  2636. }
  2637. static void r600_rlc_start(struct radeon_device *rdev)
  2638. {
  2639. WREG32(RLC_CNTL, RLC_ENABLE);
  2640. }
  2641. static int r600_rlc_init(struct radeon_device *rdev)
  2642. {
  2643. u32 i;
  2644. const __be32 *fw_data;
  2645. if (!rdev->rlc_fw)
  2646. return -EINVAL;
  2647. r600_rlc_stop(rdev);
  2648. WREG32(RLC_HB_CNTL, 0);
  2649. if (rdev->family == CHIP_ARUBA) {
  2650. WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  2651. WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  2652. }
  2653. if (rdev->family <= CHIP_CAYMAN) {
  2654. WREG32(RLC_HB_BASE, 0);
  2655. WREG32(RLC_HB_RPTR, 0);
  2656. WREG32(RLC_HB_WPTR, 0);
  2657. }
  2658. if (rdev->family <= CHIP_CAICOS) {
  2659. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  2660. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  2661. }
  2662. WREG32(RLC_MC_CNTL, 0);
  2663. WREG32(RLC_UCODE_CNTL, 0);
  2664. fw_data = (const __be32 *)rdev->rlc_fw->data;
  2665. if (rdev->family >= CHIP_ARUBA) {
  2666. for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
  2667. WREG32(RLC_UCODE_ADDR, i);
  2668. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2669. }
  2670. } else if (rdev->family >= CHIP_CAYMAN) {
  2671. for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
  2672. WREG32(RLC_UCODE_ADDR, i);
  2673. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2674. }
  2675. } else if (rdev->family >= CHIP_CEDAR) {
  2676. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  2677. WREG32(RLC_UCODE_ADDR, i);
  2678. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2679. }
  2680. } else if (rdev->family >= CHIP_RV770) {
  2681. for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
  2682. WREG32(RLC_UCODE_ADDR, i);
  2683. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2684. }
  2685. } else {
  2686. for (i = 0; i < RLC_UCODE_SIZE; i++) {
  2687. WREG32(RLC_UCODE_ADDR, i);
  2688. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2689. }
  2690. }
  2691. WREG32(RLC_UCODE_ADDR, 0);
  2692. r600_rlc_start(rdev);
  2693. return 0;
  2694. }
  2695. static void r600_enable_interrupts(struct radeon_device *rdev)
  2696. {
  2697. u32 ih_cntl = RREG32(IH_CNTL);
  2698. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2699. ih_cntl |= ENABLE_INTR;
  2700. ih_rb_cntl |= IH_RB_ENABLE;
  2701. WREG32(IH_CNTL, ih_cntl);
  2702. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2703. rdev->ih.enabled = true;
  2704. }
  2705. void r600_disable_interrupts(struct radeon_device *rdev)
  2706. {
  2707. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2708. u32 ih_cntl = RREG32(IH_CNTL);
  2709. ih_rb_cntl &= ~IH_RB_ENABLE;
  2710. ih_cntl &= ~ENABLE_INTR;
  2711. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2712. WREG32(IH_CNTL, ih_cntl);
  2713. /* set rptr, wptr to 0 */
  2714. WREG32(IH_RB_RPTR, 0);
  2715. WREG32(IH_RB_WPTR, 0);
  2716. rdev->ih.enabled = false;
  2717. rdev->ih.wptr = 0;
  2718. rdev->ih.rptr = 0;
  2719. }
  2720. static void r600_disable_interrupt_state(struct radeon_device *rdev)
  2721. {
  2722. u32 tmp;
  2723. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  2724. WREG32(GRBM_INT_CNTL, 0);
  2725. WREG32(DxMODE_INT_MASK, 0);
  2726. WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
  2727. WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
  2728. if (ASIC_IS_DCE3(rdev)) {
  2729. WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
  2730. WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
  2731. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2732. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2733. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2734. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2735. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2736. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2737. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2738. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2739. if (ASIC_IS_DCE32(rdev)) {
  2740. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2741. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2742. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2743. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2744. }
  2745. } else {
  2746. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  2747. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  2748. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2749. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2750. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2751. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2752. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2753. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2754. }
  2755. }
  2756. int r600_irq_init(struct radeon_device *rdev)
  2757. {
  2758. int ret = 0;
  2759. int rb_bufsz;
  2760. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  2761. /* allocate ring */
  2762. ret = r600_ih_ring_alloc(rdev);
  2763. if (ret)
  2764. return ret;
  2765. /* disable irqs */
  2766. r600_disable_interrupts(rdev);
  2767. /* init rlc */
  2768. ret = r600_rlc_init(rdev);
  2769. if (ret) {
  2770. r600_ih_ring_fini(rdev);
  2771. return ret;
  2772. }
  2773. /* setup interrupt control */
  2774. /* set dummy read address to ring address */
  2775. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  2776. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  2777. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  2778. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  2779. */
  2780. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  2781. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  2782. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  2783. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  2784. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  2785. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  2786. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  2787. IH_WPTR_OVERFLOW_CLEAR |
  2788. (rb_bufsz << 1));
  2789. if (rdev->wb.enabled)
  2790. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  2791. /* set the writeback address whether it's enabled or not */
  2792. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  2793. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  2794. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2795. /* set rptr, wptr to 0 */
  2796. WREG32(IH_RB_RPTR, 0);
  2797. WREG32(IH_RB_WPTR, 0);
  2798. /* Default settings for IH_CNTL (disabled at first) */
  2799. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
  2800. /* RPTR_REARM only works if msi's are enabled */
  2801. if (rdev->msi_enabled)
  2802. ih_cntl |= RPTR_REARM;
  2803. WREG32(IH_CNTL, ih_cntl);
  2804. /* force the active interrupt state to all disabled */
  2805. if (rdev->family >= CHIP_CEDAR)
  2806. evergreen_disable_interrupt_state(rdev);
  2807. else
  2808. r600_disable_interrupt_state(rdev);
  2809. /* enable irqs */
  2810. r600_enable_interrupts(rdev);
  2811. return ret;
  2812. }
  2813. void r600_irq_suspend(struct radeon_device *rdev)
  2814. {
  2815. r600_irq_disable(rdev);
  2816. r600_rlc_stop(rdev);
  2817. }
  2818. void r600_irq_fini(struct radeon_device *rdev)
  2819. {
  2820. r600_irq_suspend(rdev);
  2821. r600_ih_ring_fini(rdev);
  2822. }
  2823. int r600_irq_set(struct radeon_device *rdev)
  2824. {
  2825. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  2826. u32 mode_int = 0;
  2827. u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  2828. u32 grbm_int_cntl = 0;
  2829. u32 hdmi1, hdmi2;
  2830. u32 d1grph = 0, d2grph = 0;
  2831. if (!rdev->irq.installed) {
  2832. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  2833. return -EINVAL;
  2834. }
  2835. /* don't enable anything if the ih is disabled */
  2836. if (!rdev->ih.enabled) {
  2837. r600_disable_interrupts(rdev);
  2838. /* force the active interrupt state to all disabled */
  2839. r600_disable_interrupt_state(rdev);
  2840. return 0;
  2841. }
  2842. hdmi1 = RREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2843. if (ASIC_IS_DCE3(rdev)) {
  2844. hdmi2 = RREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2845. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2846. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2847. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2848. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2849. if (ASIC_IS_DCE32(rdev)) {
  2850. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2851. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2852. }
  2853. } else {
  2854. hdmi2 = RREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2855. hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2856. hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2857. hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2858. }
  2859. if (rdev->irq.sw_int[RADEON_RING_TYPE_GFX_INDEX]) {
  2860. DRM_DEBUG("r600_irq_set: sw int\n");
  2861. cp_int_cntl |= RB_INT_ENABLE;
  2862. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  2863. }
  2864. if (rdev->irq.crtc_vblank_int[0] ||
  2865. rdev->irq.pflip[0]) {
  2866. DRM_DEBUG("r600_irq_set: vblank 0\n");
  2867. mode_int |= D1MODE_VBLANK_INT_MASK;
  2868. }
  2869. if (rdev->irq.crtc_vblank_int[1] ||
  2870. rdev->irq.pflip[1]) {
  2871. DRM_DEBUG("r600_irq_set: vblank 1\n");
  2872. mode_int |= D2MODE_VBLANK_INT_MASK;
  2873. }
  2874. if (rdev->irq.hpd[0]) {
  2875. DRM_DEBUG("r600_irq_set: hpd 1\n");
  2876. hpd1 |= DC_HPDx_INT_EN;
  2877. }
  2878. if (rdev->irq.hpd[1]) {
  2879. DRM_DEBUG("r600_irq_set: hpd 2\n");
  2880. hpd2 |= DC_HPDx_INT_EN;
  2881. }
  2882. if (rdev->irq.hpd[2]) {
  2883. DRM_DEBUG("r600_irq_set: hpd 3\n");
  2884. hpd3 |= DC_HPDx_INT_EN;
  2885. }
  2886. if (rdev->irq.hpd[3]) {
  2887. DRM_DEBUG("r600_irq_set: hpd 4\n");
  2888. hpd4 |= DC_HPDx_INT_EN;
  2889. }
  2890. if (rdev->irq.hpd[4]) {
  2891. DRM_DEBUG("r600_irq_set: hpd 5\n");
  2892. hpd5 |= DC_HPDx_INT_EN;
  2893. }
  2894. if (rdev->irq.hpd[5]) {
  2895. DRM_DEBUG("r600_irq_set: hpd 6\n");
  2896. hpd6 |= DC_HPDx_INT_EN;
  2897. }
  2898. if (rdev->irq.hdmi[0]) {
  2899. DRM_DEBUG("r600_irq_set: hdmi 1\n");
  2900. hdmi1 |= R600_HDMI_INT_EN;
  2901. }
  2902. if (rdev->irq.hdmi[1]) {
  2903. DRM_DEBUG("r600_irq_set: hdmi 2\n");
  2904. hdmi2 |= R600_HDMI_INT_EN;
  2905. }
  2906. if (rdev->irq.gui_idle) {
  2907. DRM_DEBUG("gui idle\n");
  2908. grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
  2909. }
  2910. WREG32(CP_INT_CNTL, cp_int_cntl);
  2911. WREG32(DxMODE_INT_MASK, mode_int);
  2912. WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
  2913. WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
  2914. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  2915. WREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, hdmi1);
  2916. if (ASIC_IS_DCE3(rdev)) {
  2917. WREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, hdmi2);
  2918. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  2919. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  2920. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  2921. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  2922. if (ASIC_IS_DCE32(rdev)) {
  2923. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  2924. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  2925. }
  2926. } else {
  2927. WREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, hdmi2);
  2928. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
  2929. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
  2930. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
  2931. }
  2932. /* posting read */
  2933. RREG32(R_000E50_SRBM_STATUS);
  2934. return 0;
  2935. }
  2936. static void r600_irq_ack(struct radeon_device *rdev)
  2937. {
  2938. u32 tmp;
  2939. if (ASIC_IS_DCE3(rdev)) {
  2940. rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
  2941. rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
  2942. rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
  2943. } else {
  2944. rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  2945. rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  2946. rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
  2947. }
  2948. rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
  2949. rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
  2950. if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
  2951. WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
  2952. if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
  2953. WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
  2954. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
  2955. WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2956. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
  2957. WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2958. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
  2959. WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2960. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
  2961. WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2962. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
  2963. if (ASIC_IS_DCE3(rdev)) {
  2964. tmp = RREG32(DC_HPD1_INT_CONTROL);
  2965. tmp |= DC_HPDx_INT_ACK;
  2966. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2967. } else {
  2968. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  2969. tmp |= DC_HPDx_INT_ACK;
  2970. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2971. }
  2972. }
  2973. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
  2974. if (ASIC_IS_DCE3(rdev)) {
  2975. tmp = RREG32(DC_HPD2_INT_CONTROL);
  2976. tmp |= DC_HPDx_INT_ACK;
  2977. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2978. } else {
  2979. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  2980. tmp |= DC_HPDx_INT_ACK;
  2981. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2982. }
  2983. }
  2984. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
  2985. if (ASIC_IS_DCE3(rdev)) {
  2986. tmp = RREG32(DC_HPD3_INT_CONTROL);
  2987. tmp |= DC_HPDx_INT_ACK;
  2988. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2989. } else {
  2990. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  2991. tmp |= DC_HPDx_INT_ACK;
  2992. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2993. }
  2994. }
  2995. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
  2996. tmp = RREG32(DC_HPD4_INT_CONTROL);
  2997. tmp |= DC_HPDx_INT_ACK;
  2998. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2999. }
  3000. if (ASIC_IS_DCE32(rdev)) {
  3001. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
  3002. tmp = RREG32(DC_HPD5_INT_CONTROL);
  3003. tmp |= DC_HPDx_INT_ACK;
  3004. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3005. }
  3006. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
  3007. tmp = RREG32(DC_HPD5_INT_CONTROL);
  3008. tmp |= DC_HPDx_INT_ACK;
  3009. WREG32(DC_HPD6_INT_CONTROL, tmp);
  3010. }
  3011. }
  3012. if (RREG32(R600_HDMI_BLOCK1 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  3013. WREG32_P(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  3014. }
  3015. if (ASIC_IS_DCE3(rdev)) {
  3016. if (RREG32(R600_HDMI_BLOCK3 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  3017. WREG32_P(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  3018. }
  3019. } else {
  3020. if (RREG32(R600_HDMI_BLOCK2 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  3021. WREG32_P(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  3022. }
  3023. }
  3024. }
  3025. void r600_irq_disable(struct radeon_device *rdev)
  3026. {
  3027. r600_disable_interrupts(rdev);
  3028. /* Wait and acknowledge irq */
  3029. mdelay(1);
  3030. r600_irq_ack(rdev);
  3031. r600_disable_interrupt_state(rdev);
  3032. }
  3033. static u32 r600_get_ih_wptr(struct radeon_device *rdev)
  3034. {
  3035. u32 wptr, tmp;
  3036. if (rdev->wb.enabled)
  3037. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  3038. else
  3039. wptr = RREG32(IH_RB_WPTR);
  3040. if (wptr & RB_OVERFLOW) {
  3041. /* When a ring buffer overflow happen start parsing interrupt
  3042. * from the last not overwritten vector (wptr + 16). Hopefully
  3043. * this should allow us to catchup.
  3044. */
  3045. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  3046. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  3047. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  3048. tmp = RREG32(IH_RB_CNTL);
  3049. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  3050. WREG32(IH_RB_CNTL, tmp);
  3051. }
  3052. return (wptr & rdev->ih.ptr_mask);
  3053. }
  3054. /* r600 IV Ring
  3055. * Each IV ring entry is 128 bits:
  3056. * [7:0] - interrupt source id
  3057. * [31:8] - reserved
  3058. * [59:32] - interrupt source data
  3059. * [127:60] - reserved
  3060. *
  3061. * The basic interrupt vector entries
  3062. * are decoded as follows:
  3063. * src_id src_data description
  3064. * 1 0 D1 Vblank
  3065. * 1 1 D1 Vline
  3066. * 5 0 D2 Vblank
  3067. * 5 1 D2 Vline
  3068. * 19 0 FP Hot plug detection A
  3069. * 19 1 FP Hot plug detection B
  3070. * 19 2 DAC A auto-detection
  3071. * 19 3 DAC B auto-detection
  3072. * 21 4 HDMI block A
  3073. * 21 5 HDMI block B
  3074. * 176 - CP_INT RB
  3075. * 177 - CP_INT IB1
  3076. * 178 - CP_INT IB2
  3077. * 181 - EOP Interrupt
  3078. * 233 - GUI Idle
  3079. *
  3080. * Note, these are based on r600 and may need to be
  3081. * adjusted or added to on newer asics
  3082. */
  3083. int r600_irq_process(struct radeon_device *rdev)
  3084. {
  3085. u32 wptr;
  3086. u32 rptr;
  3087. u32 src_id, src_data;
  3088. u32 ring_index;
  3089. unsigned long flags;
  3090. bool queue_hotplug = false;
  3091. if (!rdev->ih.enabled || rdev->shutdown)
  3092. return IRQ_NONE;
  3093. /* No MSIs, need a dummy read to flush PCI DMAs */
  3094. if (!rdev->msi_enabled)
  3095. RREG32(IH_RB_WPTR);
  3096. wptr = r600_get_ih_wptr(rdev);
  3097. rptr = rdev->ih.rptr;
  3098. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  3099. spin_lock_irqsave(&rdev->ih.lock, flags);
  3100. if (rptr == wptr) {
  3101. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  3102. return IRQ_NONE;
  3103. }
  3104. restart_ih:
  3105. /* Order reading of wptr vs. reading of IH ring data */
  3106. rmb();
  3107. /* display interrupts */
  3108. r600_irq_ack(rdev);
  3109. rdev->ih.wptr = wptr;
  3110. while (rptr != wptr) {
  3111. /* wptr/rptr are in bytes! */
  3112. ring_index = rptr / 4;
  3113. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  3114. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  3115. switch (src_id) {
  3116. case 1: /* D1 vblank/vline */
  3117. switch (src_data) {
  3118. case 0: /* D1 vblank */
  3119. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
  3120. if (rdev->irq.crtc_vblank_int[0]) {
  3121. drm_handle_vblank(rdev->ddev, 0);
  3122. rdev->pm.vblank_sync = true;
  3123. wake_up(&rdev->irq.vblank_queue);
  3124. }
  3125. if (rdev->irq.pflip[0])
  3126. radeon_crtc_handle_flip(rdev, 0);
  3127. rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  3128. DRM_DEBUG("IH: D1 vblank\n");
  3129. }
  3130. break;
  3131. case 1: /* D1 vline */
  3132. if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
  3133. rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  3134. DRM_DEBUG("IH: D1 vline\n");
  3135. }
  3136. break;
  3137. default:
  3138. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3139. break;
  3140. }
  3141. break;
  3142. case 5: /* D2 vblank/vline */
  3143. switch (src_data) {
  3144. case 0: /* D2 vblank */
  3145. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
  3146. if (rdev->irq.crtc_vblank_int[1]) {
  3147. drm_handle_vblank(rdev->ddev, 1);
  3148. rdev->pm.vblank_sync = true;
  3149. wake_up(&rdev->irq.vblank_queue);
  3150. }
  3151. if (rdev->irq.pflip[1])
  3152. radeon_crtc_handle_flip(rdev, 1);
  3153. rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
  3154. DRM_DEBUG("IH: D2 vblank\n");
  3155. }
  3156. break;
  3157. case 1: /* D1 vline */
  3158. if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
  3159. rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
  3160. DRM_DEBUG("IH: D2 vline\n");
  3161. }
  3162. break;
  3163. default:
  3164. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3165. break;
  3166. }
  3167. break;
  3168. case 19: /* HPD/DAC hotplug */
  3169. switch (src_data) {
  3170. case 0:
  3171. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
  3172. rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
  3173. queue_hotplug = true;
  3174. DRM_DEBUG("IH: HPD1\n");
  3175. }
  3176. break;
  3177. case 1:
  3178. if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
  3179. rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
  3180. queue_hotplug = true;
  3181. DRM_DEBUG("IH: HPD2\n");
  3182. }
  3183. break;
  3184. case 4:
  3185. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
  3186. rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
  3187. queue_hotplug = true;
  3188. DRM_DEBUG("IH: HPD3\n");
  3189. }
  3190. break;
  3191. case 5:
  3192. if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
  3193. rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
  3194. queue_hotplug = true;
  3195. DRM_DEBUG("IH: HPD4\n");
  3196. }
  3197. break;
  3198. case 10:
  3199. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
  3200. rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
  3201. queue_hotplug = true;
  3202. DRM_DEBUG("IH: HPD5\n");
  3203. }
  3204. break;
  3205. case 12:
  3206. if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
  3207. rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
  3208. queue_hotplug = true;
  3209. DRM_DEBUG("IH: HPD6\n");
  3210. }
  3211. break;
  3212. default:
  3213. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3214. break;
  3215. }
  3216. break;
  3217. case 21: /* HDMI */
  3218. DRM_DEBUG("IH: HDMI: 0x%x\n", src_data);
  3219. r600_audio_schedule_polling(rdev);
  3220. break;
  3221. case 176: /* CP_INT in ring buffer */
  3222. case 177: /* CP_INT in IB1 */
  3223. case 178: /* CP_INT in IB2 */
  3224. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  3225. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  3226. break;
  3227. case 181: /* CP EOP event */
  3228. DRM_DEBUG("IH: CP EOP\n");
  3229. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  3230. break;
  3231. case 233: /* GUI IDLE */
  3232. DRM_DEBUG("IH: GUI idle\n");
  3233. rdev->pm.gui_idle = true;
  3234. wake_up(&rdev->irq.idle_queue);
  3235. break;
  3236. default:
  3237. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  3238. break;
  3239. }
  3240. /* wptr/rptr are in bytes! */
  3241. rptr += 16;
  3242. rptr &= rdev->ih.ptr_mask;
  3243. }
  3244. /* make sure wptr hasn't changed while processing */
  3245. wptr = r600_get_ih_wptr(rdev);
  3246. if (wptr != rdev->ih.wptr)
  3247. goto restart_ih;
  3248. if (queue_hotplug)
  3249. schedule_work(&rdev->hotplug_work);
  3250. rdev->ih.rptr = rptr;
  3251. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  3252. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  3253. return IRQ_HANDLED;
  3254. }
  3255. /*
  3256. * Debugfs info
  3257. */
  3258. #if defined(CONFIG_DEBUG_FS)
  3259. static int r600_debugfs_mc_info(struct seq_file *m, void *data)
  3260. {
  3261. struct drm_info_node *node = (struct drm_info_node *) m->private;
  3262. struct drm_device *dev = node->minor->dev;
  3263. struct radeon_device *rdev = dev->dev_private;
  3264. DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
  3265. DREG32_SYS(m, rdev, VM_L2_STATUS);
  3266. return 0;
  3267. }
  3268. static struct drm_info_list r600_mc_info_list[] = {
  3269. {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
  3270. };
  3271. #endif
  3272. int r600_debugfs_mc_info_init(struct radeon_device *rdev)
  3273. {
  3274. #if defined(CONFIG_DEBUG_FS)
  3275. return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
  3276. #else
  3277. return 0;
  3278. #endif
  3279. }
  3280. /**
  3281. * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
  3282. * rdev: radeon device structure
  3283. * bo: buffer object struct which userspace is waiting for idle
  3284. *
  3285. * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
  3286. * through ring buffer, this leads to corruption in rendering, see
  3287. * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
  3288. * directly perform HDP flush by writing register through MMIO.
  3289. */
  3290. void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
  3291. {
  3292. /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
  3293. * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
  3294. * This seems to cause problems on some AGP cards. Just use the old
  3295. * method for them.
  3296. */
  3297. if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
  3298. rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
  3299. void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
  3300. u32 tmp;
  3301. WREG32(HDP_DEBUG1, 0);
  3302. tmp = readl((void __iomem *)ptr);
  3303. } else
  3304. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3305. }
  3306. void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
  3307. {
  3308. u32 link_width_cntl, mask, target_reg;
  3309. if (rdev->flags & RADEON_IS_IGP)
  3310. return;
  3311. if (!(rdev->flags & RADEON_IS_PCIE))
  3312. return;
  3313. /* x2 cards have a special sequence */
  3314. if (ASIC_IS_X2(rdev))
  3315. return;
  3316. /* FIXME wait for idle */
  3317. switch (lanes) {
  3318. case 0:
  3319. mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
  3320. break;
  3321. case 1:
  3322. mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
  3323. break;
  3324. case 2:
  3325. mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
  3326. break;
  3327. case 4:
  3328. mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
  3329. break;
  3330. case 8:
  3331. mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
  3332. break;
  3333. case 12:
  3334. mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
  3335. break;
  3336. case 16:
  3337. default:
  3338. mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
  3339. break;
  3340. }
  3341. link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  3342. if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
  3343. (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
  3344. return;
  3345. if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS)
  3346. return;
  3347. link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
  3348. RADEON_PCIE_LC_RECONFIG_NOW |
  3349. R600_PCIE_LC_RENEGOTIATE_EN |
  3350. R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
  3351. link_width_cntl |= mask;
  3352. WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3353. /* some northbridges can renegotiate the link rather than requiring
  3354. * a complete re-config.
  3355. * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.)
  3356. */
  3357. if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT)
  3358. link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT;
  3359. else
  3360. link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE;
  3361. WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
  3362. RADEON_PCIE_LC_RECONFIG_NOW));
  3363. if (rdev->family >= CHIP_RV770)
  3364. target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX;
  3365. else
  3366. target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX;
  3367. /* wait for lane set to complete */
  3368. link_width_cntl = RREG32(target_reg);
  3369. while (link_width_cntl == 0xffffffff)
  3370. link_width_cntl = RREG32(target_reg);
  3371. }
  3372. int r600_get_pcie_lanes(struct radeon_device *rdev)
  3373. {
  3374. u32 link_width_cntl;
  3375. if (rdev->flags & RADEON_IS_IGP)
  3376. return 0;
  3377. if (!(rdev->flags & RADEON_IS_PCIE))
  3378. return 0;
  3379. /* x2 cards have a special sequence */
  3380. if (ASIC_IS_X2(rdev))
  3381. return 0;
  3382. /* FIXME wait for idle */
  3383. link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  3384. switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
  3385. case RADEON_PCIE_LC_LINK_WIDTH_X0:
  3386. return 0;
  3387. case RADEON_PCIE_LC_LINK_WIDTH_X1:
  3388. return 1;
  3389. case RADEON_PCIE_LC_LINK_WIDTH_X2:
  3390. return 2;
  3391. case RADEON_PCIE_LC_LINK_WIDTH_X4:
  3392. return 4;
  3393. case RADEON_PCIE_LC_LINK_WIDTH_X8:
  3394. return 8;
  3395. case RADEON_PCIE_LC_LINK_WIDTH_X16:
  3396. default:
  3397. return 16;
  3398. }
  3399. }
  3400. static void r600_pcie_gen2_enable(struct radeon_device *rdev)
  3401. {
  3402. u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
  3403. u16 link_cntl2;
  3404. if (radeon_pcie_gen2 == 0)
  3405. return;
  3406. if (rdev->flags & RADEON_IS_IGP)
  3407. return;
  3408. if (!(rdev->flags & RADEON_IS_PCIE))
  3409. return;
  3410. /* x2 cards have a special sequence */
  3411. if (ASIC_IS_X2(rdev))
  3412. return;
  3413. /* only RV6xx+ chips are supported */
  3414. if (rdev->family <= CHIP_R600)
  3415. return;
  3416. /* 55 nm r6xx asics */
  3417. if ((rdev->family == CHIP_RV670) ||
  3418. (rdev->family == CHIP_RV620) ||
  3419. (rdev->family == CHIP_RV635)) {
  3420. /* advertise upconfig capability */
  3421. link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
  3422. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  3423. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3424. link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
  3425. if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
  3426. lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
  3427. link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
  3428. LC_RECONFIG_ARC_MISSING_ESCAPE);
  3429. link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
  3430. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3431. } else {
  3432. link_width_cntl |= LC_UPCONFIGURE_DIS;
  3433. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3434. }
  3435. }
  3436. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3437. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  3438. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  3439. /* 55 nm r6xx asics */
  3440. if ((rdev->family == CHIP_RV670) ||
  3441. (rdev->family == CHIP_RV620) ||
  3442. (rdev->family == CHIP_RV635)) {
  3443. WREG32(MM_CFGREGS_CNTL, 0x8);
  3444. link_cntl2 = RREG32(0x4088);
  3445. WREG32(MM_CFGREGS_CNTL, 0);
  3446. /* not supported yet */
  3447. if (link_cntl2 & SELECTABLE_DEEMPHASIS)
  3448. return;
  3449. }
  3450. speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
  3451. speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
  3452. speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
  3453. speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
  3454. speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
  3455. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3456. tmp = RREG32(0x541c);
  3457. WREG32(0x541c, tmp | 0x8);
  3458. WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
  3459. link_cntl2 = RREG16(0x4088);
  3460. link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
  3461. link_cntl2 |= 0x2;
  3462. WREG16(0x4088, link_cntl2);
  3463. WREG32(MM_CFGREGS_CNTL, 0);
  3464. if ((rdev->family == CHIP_RV670) ||
  3465. (rdev->family == CHIP_RV620) ||
  3466. (rdev->family == CHIP_RV635)) {
  3467. training_cntl = RREG32_PCIE_P(PCIE_LC_TRAINING_CNTL);
  3468. training_cntl &= ~LC_POINT_7_PLUS_EN;
  3469. WREG32_PCIE_P(PCIE_LC_TRAINING_CNTL, training_cntl);
  3470. } else {
  3471. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3472. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  3473. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3474. }
  3475. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3476. speed_cntl |= LC_GEN2_EN_STRAP;
  3477. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3478. } else {
  3479. link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
  3480. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  3481. if (1)
  3482. link_width_cntl |= LC_UPCONFIGURE_DIS;
  3483. else
  3484. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  3485. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3486. }
  3487. }