evergreen.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include "drmP.h"
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include "radeon_drm.h"
  31. #include "evergreend.h"
  32. #include "atom.h"
  33. #include "avivod.h"
  34. #include "evergreen_reg.h"
  35. #include "evergreen_blit_shaders.h"
  36. #define EVERGREEN_PFP_UCODE_SIZE 1120
  37. #define EVERGREEN_PM4_UCODE_SIZE 1376
  38. static const u32 crtc_offsets[6] =
  39. {
  40. EVERGREEN_CRTC0_REGISTER_OFFSET,
  41. EVERGREEN_CRTC1_REGISTER_OFFSET,
  42. EVERGREEN_CRTC2_REGISTER_OFFSET,
  43. EVERGREEN_CRTC3_REGISTER_OFFSET,
  44. EVERGREEN_CRTC4_REGISTER_OFFSET,
  45. EVERGREEN_CRTC5_REGISTER_OFFSET
  46. };
  47. static void evergreen_gpu_init(struct radeon_device *rdev);
  48. void evergreen_fini(struct radeon_device *rdev);
  49. void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  50. extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  51. int ring, u32 cp_int_cntl);
  52. void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  53. unsigned *bankh, unsigned *mtaspect,
  54. unsigned *tile_split)
  55. {
  56. *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
  57. *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
  58. *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
  59. *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
  60. switch (*bankw) {
  61. default:
  62. case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
  63. case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
  64. case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
  65. case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
  66. }
  67. switch (*bankh) {
  68. default:
  69. case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
  70. case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
  71. case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
  72. case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
  73. }
  74. switch (*mtaspect) {
  75. default:
  76. case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
  77. case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
  78. case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
  79. case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
  80. }
  81. }
  82. void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
  83. {
  84. u16 ctl, v;
  85. int cap, err;
  86. cap = pci_pcie_cap(rdev->pdev);
  87. if (!cap)
  88. return;
  89. err = pci_read_config_word(rdev->pdev, cap + PCI_EXP_DEVCTL, &ctl);
  90. if (err)
  91. return;
  92. v = (ctl & PCI_EXP_DEVCTL_READRQ) >> 12;
  93. /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
  94. * to avoid hangs or perfomance issues
  95. */
  96. if ((v == 0) || (v == 6) || (v == 7)) {
  97. ctl &= ~PCI_EXP_DEVCTL_READRQ;
  98. ctl |= (2 << 12);
  99. pci_write_config_word(rdev->pdev, cap + PCI_EXP_DEVCTL, ctl);
  100. }
  101. }
  102. void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
  103. {
  104. int i;
  105. if (crtc >= rdev->num_crtc)
  106. return;
  107. if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN) {
  108. for (i = 0; i < rdev->usec_timeout; i++) {
  109. if (!(RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK))
  110. break;
  111. udelay(1);
  112. }
  113. for (i = 0; i < rdev->usec_timeout; i++) {
  114. if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
  115. break;
  116. udelay(1);
  117. }
  118. }
  119. }
  120. void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc)
  121. {
  122. /* enable the pflip int */
  123. radeon_irq_kms_pflip_irq_get(rdev, crtc);
  124. }
  125. void evergreen_post_page_flip(struct radeon_device *rdev, int crtc)
  126. {
  127. /* disable the pflip int */
  128. radeon_irq_kms_pflip_irq_put(rdev, crtc);
  129. }
  130. u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
  131. {
  132. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  133. u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
  134. int i;
  135. /* Lock the graphics update lock */
  136. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  137. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  138. /* update the scanout addresses */
  139. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  140. upper_32_bits(crtc_base));
  141. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  142. (u32)crtc_base);
  143. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  144. upper_32_bits(crtc_base));
  145. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  146. (u32)crtc_base);
  147. /* Wait for update_pending to go high. */
  148. for (i = 0; i < rdev->usec_timeout; i++) {
  149. if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
  150. break;
  151. udelay(1);
  152. }
  153. DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
  154. /* Unlock the lock, so double-buffering can take place inside vblank */
  155. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  156. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  157. /* Return current update_pending status: */
  158. return RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING;
  159. }
  160. /* get temperature in millidegrees */
  161. int evergreen_get_temp(struct radeon_device *rdev)
  162. {
  163. u32 temp, toffset;
  164. int actual_temp = 0;
  165. if (rdev->family == CHIP_JUNIPER) {
  166. toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
  167. TOFFSET_SHIFT;
  168. temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
  169. TS0_ADC_DOUT_SHIFT;
  170. if (toffset & 0x100)
  171. actual_temp = temp / 2 - (0x200 - toffset);
  172. else
  173. actual_temp = temp / 2 + toffset;
  174. actual_temp = actual_temp * 1000;
  175. } else {
  176. temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  177. ASIC_T_SHIFT;
  178. if (temp & 0x400)
  179. actual_temp = -256;
  180. else if (temp & 0x200)
  181. actual_temp = 255;
  182. else if (temp & 0x100) {
  183. actual_temp = temp & 0x1ff;
  184. actual_temp |= ~0x1ff;
  185. } else
  186. actual_temp = temp & 0xff;
  187. actual_temp = (actual_temp * 1000) / 2;
  188. }
  189. return actual_temp;
  190. }
  191. int sumo_get_temp(struct radeon_device *rdev)
  192. {
  193. u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
  194. int actual_temp = temp - 49;
  195. return actual_temp * 1000;
  196. }
  197. void sumo_pm_init_profile(struct radeon_device *rdev)
  198. {
  199. int idx;
  200. /* default */
  201. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  202. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  203. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  204. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  205. /* low,mid sh/mh */
  206. if (rdev->flags & RADEON_IS_MOBILITY)
  207. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  208. else
  209. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  210. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  211. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  212. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  213. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  214. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  215. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  216. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  217. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  218. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  219. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  220. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  221. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  222. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  223. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  224. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  225. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  226. /* high sh/mh */
  227. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  228. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  229. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  230. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  231. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
  232. rdev->pm.power_state[idx].num_clock_modes - 1;
  233. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  234. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  235. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  236. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
  237. rdev->pm.power_state[idx].num_clock_modes - 1;
  238. }
  239. void evergreen_pm_misc(struct radeon_device *rdev)
  240. {
  241. int req_ps_idx = rdev->pm.requested_power_state_index;
  242. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  243. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  244. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  245. if (voltage->type == VOLTAGE_SW) {
  246. /* 0xff01 is a flag rather then an actual voltage */
  247. if (voltage->voltage == 0xff01)
  248. return;
  249. if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
  250. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  251. rdev->pm.current_vddc = voltage->voltage;
  252. DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
  253. }
  254. /* 0xff01 is a flag rather then an actual voltage */
  255. if (voltage->vddci == 0xff01)
  256. return;
  257. if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
  258. radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
  259. rdev->pm.current_vddci = voltage->vddci;
  260. DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
  261. }
  262. }
  263. }
  264. void evergreen_pm_prepare(struct radeon_device *rdev)
  265. {
  266. struct drm_device *ddev = rdev->ddev;
  267. struct drm_crtc *crtc;
  268. struct radeon_crtc *radeon_crtc;
  269. u32 tmp;
  270. /* disable any active CRTCs */
  271. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  272. radeon_crtc = to_radeon_crtc(crtc);
  273. if (radeon_crtc->enabled) {
  274. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  275. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  276. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  277. }
  278. }
  279. }
  280. void evergreen_pm_finish(struct radeon_device *rdev)
  281. {
  282. struct drm_device *ddev = rdev->ddev;
  283. struct drm_crtc *crtc;
  284. struct radeon_crtc *radeon_crtc;
  285. u32 tmp;
  286. /* enable any active CRTCs */
  287. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  288. radeon_crtc = to_radeon_crtc(crtc);
  289. if (radeon_crtc->enabled) {
  290. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  291. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  292. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  293. }
  294. }
  295. }
  296. bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  297. {
  298. bool connected = false;
  299. switch (hpd) {
  300. case RADEON_HPD_1:
  301. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  302. connected = true;
  303. break;
  304. case RADEON_HPD_2:
  305. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  306. connected = true;
  307. break;
  308. case RADEON_HPD_3:
  309. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  310. connected = true;
  311. break;
  312. case RADEON_HPD_4:
  313. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  314. connected = true;
  315. break;
  316. case RADEON_HPD_5:
  317. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  318. connected = true;
  319. break;
  320. case RADEON_HPD_6:
  321. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  322. connected = true;
  323. break;
  324. default:
  325. break;
  326. }
  327. return connected;
  328. }
  329. void evergreen_hpd_set_polarity(struct radeon_device *rdev,
  330. enum radeon_hpd_id hpd)
  331. {
  332. u32 tmp;
  333. bool connected = evergreen_hpd_sense(rdev, hpd);
  334. switch (hpd) {
  335. case RADEON_HPD_1:
  336. tmp = RREG32(DC_HPD1_INT_CONTROL);
  337. if (connected)
  338. tmp &= ~DC_HPDx_INT_POLARITY;
  339. else
  340. tmp |= DC_HPDx_INT_POLARITY;
  341. WREG32(DC_HPD1_INT_CONTROL, tmp);
  342. break;
  343. case RADEON_HPD_2:
  344. tmp = RREG32(DC_HPD2_INT_CONTROL);
  345. if (connected)
  346. tmp &= ~DC_HPDx_INT_POLARITY;
  347. else
  348. tmp |= DC_HPDx_INT_POLARITY;
  349. WREG32(DC_HPD2_INT_CONTROL, tmp);
  350. break;
  351. case RADEON_HPD_3:
  352. tmp = RREG32(DC_HPD3_INT_CONTROL);
  353. if (connected)
  354. tmp &= ~DC_HPDx_INT_POLARITY;
  355. else
  356. tmp |= DC_HPDx_INT_POLARITY;
  357. WREG32(DC_HPD3_INT_CONTROL, tmp);
  358. break;
  359. case RADEON_HPD_4:
  360. tmp = RREG32(DC_HPD4_INT_CONTROL);
  361. if (connected)
  362. tmp &= ~DC_HPDx_INT_POLARITY;
  363. else
  364. tmp |= DC_HPDx_INT_POLARITY;
  365. WREG32(DC_HPD4_INT_CONTROL, tmp);
  366. break;
  367. case RADEON_HPD_5:
  368. tmp = RREG32(DC_HPD5_INT_CONTROL);
  369. if (connected)
  370. tmp &= ~DC_HPDx_INT_POLARITY;
  371. else
  372. tmp |= DC_HPDx_INT_POLARITY;
  373. WREG32(DC_HPD5_INT_CONTROL, tmp);
  374. break;
  375. case RADEON_HPD_6:
  376. tmp = RREG32(DC_HPD6_INT_CONTROL);
  377. if (connected)
  378. tmp &= ~DC_HPDx_INT_POLARITY;
  379. else
  380. tmp |= DC_HPDx_INT_POLARITY;
  381. WREG32(DC_HPD6_INT_CONTROL, tmp);
  382. break;
  383. default:
  384. break;
  385. }
  386. }
  387. void evergreen_hpd_init(struct radeon_device *rdev)
  388. {
  389. struct drm_device *dev = rdev->ddev;
  390. struct drm_connector *connector;
  391. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
  392. DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
  393. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  394. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  395. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  396. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  397. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  398. * aux dp channel on imac and help (but not completely fix)
  399. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  400. * also avoid interrupt storms during dpms.
  401. */
  402. continue;
  403. }
  404. switch (radeon_connector->hpd.hpd) {
  405. case RADEON_HPD_1:
  406. WREG32(DC_HPD1_CONTROL, tmp);
  407. rdev->irq.hpd[0] = true;
  408. break;
  409. case RADEON_HPD_2:
  410. WREG32(DC_HPD2_CONTROL, tmp);
  411. rdev->irq.hpd[1] = true;
  412. break;
  413. case RADEON_HPD_3:
  414. WREG32(DC_HPD3_CONTROL, tmp);
  415. rdev->irq.hpd[2] = true;
  416. break;
  417. case RADEON_HPD_4:
  418. WREG32(DC_HPD4_CONTROL, tmp);
  419. rdev->irq.hpd[3] = true;
  420. break;
  421. case RADEON_HPD_5:
  422. WREG32(DC_HPD5_CONTROL, tmp);
  423. rdev->irq.hpd[4] = true;
  424. break;
  425. case RADEON_HPD_6:
  426. WREG32(DC_HPD6_CONTROL, tmp);
  427. rdev->irq.hpd[5] = true;
  428. break;
  429. default:
  430. break;
  431. }
  432. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  433. }
  434. if (rdev->irq.installed)
  435. evergreen_irq_set(rdev);
  436. }
  437. void evergreen_hpd_fini(struct radeon_device *rdev)
  438. {
  439. struct drm_device *dev = rdev->ddev;
  440. struct drm_connector *connector;
  441. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  442. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  443. switch (radeon_connector->hpd.hpd) {
  444. case RADEON_HPD_1:
  445. WREG32(DC_HPD1_CONTROL, 0);
  446. rdev->irq.hpd[0] = false;
  447. break;
  448. case RADEON_HPD_2:
  449. WREG32(DC_HPD2_CONTROL, 0);
  450. rdev->irq.hpd[1] = false;
  451. break;
  452. case RADEON_HPD_3:
  453. WREG32(DC_HPD3_CONTROL, 0);
  454. rdev->irq.hpd[2] = false;
  455. break;
  456. case RADEON_HPD_4:
  457. WREG32(DC_HPD4_CONTROL, 0);
  458. rdev->irq.hpd[3] = false;
  459. break;
  460. case RADEON_HPD_5:
  461. WREG32(DC_HPD5_CONTROL, 0);
  462. rdev->irq.hpd[4] = false;
  463. break;
  464. case RADEON_HPD_6:
  465. WREG32(DC_HPD6_CONTROL, 0);
  466. rdev->irq.hpd[5] = false;
  467. break;
  468. default:
  469. break;
  470. }
  471. }
  472. }
  473. /* watermark setup */
  474. static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
  475. struct radeon_crtc *radeon_crtc,
  476. struct drm_display_mode *mode,
  477. struct drm_display_mode *other_mode)
  478. {
  479. u32 tmp, buffer_alloc, i;
  480. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  481. /*
  482. * Line Buffer Setup
  483. * There are 3 line buffers, each one shared by 2 display controllers.
  484. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  485. * the display controllers. The paritioning is done via one of four
  486. * preset allocations specified in bits 2:0:
  487. * first display controller
  488. * 0 - first half of lb (3840 * 2)
  489. * 1 - first 3/4 of lb (5760 * 2)
  490. * 2 - whole lb (7680 * 2), other crtc must be disabled
  491. * 3 - first 1/4 of lb (1920 * 2)
  492. * second display controller
  493. * 4 - second half of lb (3840 * 2)
  494. * 5 - second 3/4 of lb (5760 * 2)
  495. * 6 - whole lb (7680 * 2), other crtc must be disabled
  496. * 7 - last 1/4 of lb (1920 * 2)
  497. */
  498. /* this can get tricky if we have two large displays on a paired group
  499. * of crtcs. Ideally for multiple large displays we'd assign them to
  500. * non-linked crtcs for maximum line buffer allocation.
  501. */
  502. if (radeon_crtc->base.enabled && mode) {
  503. if (other_mode) {
  504. tmp = 0; /* 1/2 */
  505. buffer_alloc = 1;
  506. } else {
  507. tmp = 2; /* whole */
  508. buffer_alloc = 2;
  509. }
  510. } else {
  511. tmp = 0;
  512. buffer_alloc = 0;
  513. }
  514. /* second controller of the pair uses second half of the lb */
  515. if (radeon_crtc->crtc_id % 2)
  516. tmp += 4;
  517. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
  518. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  519. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  520. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  521. for (i = 0; i < rdev->usec_timeout; i++) {
  522. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  523. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  524. break;
  525. udelay(1);
  526. }
  527. }
  528. if (radeon_crtc->base.enabled && mode) {
  529. switch (tmp) {
  530. case 0:
  531. case 4:
  532. default:
  533. if (ASIC_IS_DCE5(rdev))
  534. return 4096 * 2;
  535. else
  536. return 3840 * 2;
  537. case 1:
  538. case 5:
  539. if (ASIC_IS_DCE5(rdev))
  540. return 6144 * 2;
  541. else
  542. return 5760 * 2;
  543. case 2:
  544. case 6:
  545. if (ASIC_IS_DCE5(rdev))
  546. return 8192 * 2;
  547. else
  548. return 7680 * 2;
  549. case 3:
  550. case 7:
  551. if (ASIC_IS_DCE5(rdev))
  552. return 2048 * 2;
  553. else
  554. return 1920 * 2;
  555. }
  556. }
  557. /* controller not enabled, so no lb used */
  558. return 0;
  559. }
  560. u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
  561. {
  562. u32 tmp = RREG32(MC_SHARED_CHMAP);
  563. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  564. case 0:
  565. default:
  566. return 1;
  567. case 1:
  568. return 2;
  569. case 2:
  570. return 4;
  571. case 3:
  572. return 8;
  573. }
  574. }
  575. struct evergreen_wm_params {
  576. u32 dram_channels; /* number of dram channels */
  577. u32 yclk; /* bandwidth per dram data pin in kHz */
  578. u32 sclk; /* engine clock in kHz */
  579. u32 disp_clk; /* display clock in kHz */
  580. u32 src_width; /* viewport width */
  581. u32 active_time; /* active display time in ns */
  582. u32 blank_time; /* blank time in ns */
  583. bool interlaced; /* mode is interlaced */
  584. fixed20_12 vsc; /* vertical scale ratio */
  585. u32 num_heads; /* number of active crtcs */
  586. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  587. u32 lb_size; /* line buffer allocated to pipe */
  588. u32 vtaps; /* vertical scaler taps */
  589. };
  590. static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
  591. {
  592. /* Calculate DRAM Bandwidth and the part allocated to display. */
  593. fixed20_12 dram_efficiency; /* 0.7 */
  594. fixed20_12 yclk, dram_channels, bandwidth;
  595. fixed20_12 a;
  596. a.full = dfixed_const(1000);
  597. yclk.full = dfixed_const(wm->yclk);
  598. yclk.full = dfixed_div(yclk, a);
  599. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  600. a.full = dfixed_const(10);
  601. dram_efficiency.full = dfixed_const(7);
  602. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  603. bandwidth.full = dfixed_mul(dram_channels, yclk);
  604. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  605. return dfixed_trunc(bandwidth);
  606. }
  607. static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  608. {
  609. /* Calculate DRAM Bandwidth and the part allocated to display. */
  610. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  611. fixed20_12 yclk, dram_channels, bandwidth;
  612. fixed20_12 a;
  613. a.full = dfixed_const(1000);
  614. yclk.full = dfixed_const(wm->yclk);
  615. yclk.full = dfixed_div(yclk, a);
  616. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  617. a.full = dfixed_const(10);
  618. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  619. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  620. bandwidth.full = dfixed_mul(dram_channels, yclk);
  621. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  622. return dfixed_trunc(bandwidth);
  623. }
  624. static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
  625. {
  626. /* Calculate the display Data return Bandwidth */
  627. fixed20_12 return_efficiency; /* 0.8 */
  628. fixed20_12 sclk, bandwidth;
  629. fixed20_12 a;
  630. a.full = dfixed_const(1000);
  631. sclk.full = dfixed_const(wm->sclk);
  632. sclk.full = dfixed_div(sclk, a);
  633. a.full = dfixed_const(10);
  634. return_efficiency.full = dfixed_const(8);
  635. return_efficiency.full = dfixed_div(return_efficiency, a);
  636. a.full = dfixed_const(32);
  637. bandwidth.full = dfixed_mul(a, sclk);
  638. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  639. return dfixed_trunc(bandwidth);
  640. }
  641. static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
  642. {
  643. /* Calculate the DMIF Request Bandwidth */
  644. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  645. fixed20_12 disp_clk, bandwidth;
  646. fixed20_12 a;
  647. a.full = dfixed_const(1000);
  648. disp_clk.full = dfixed_const(wm->disp_clk);
  649. disp_clk.full = dfixed_div(disp_clk, a);
  650. a.full = dfixed_const(10);
  651. disp_clk_request_efficiency.full = dfixed_const(8);
  652. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  653. a.full = dfixed_const(32);
  654. bandwidth.full = dfixed_mul(a, disp_clk);
  655. bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
  656. return dfixed_trunc(bandwidth);
  657. }
  658. static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
  659. {
  660. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  661. u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
  662. u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
  663. u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
  664. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  665. }
  666. static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
  667. {
  668. /* Calculate the display mode Average Bandwidth
  669. * DisplayMode should contain the source and destination dimensions,
  670. * timing, etc.
  671. */
  672. fixed20_12 bpp;
  673. fixed20_12 line_time;
  674. fixed20_12 src_width;
  675. fixed20_12 bandwidth;
  676. fixed20_12 a;
  677. a.full = dfixed_const(1000);
  678. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  679. line_time.full = dfixed_div(line_time, a);
  680. bpp.full = dfixed_const(wm->bytes_per_pixel);
  681. src_width.full = dfixed_const(wm->src_width);
  682. bandwidth.full = dfixed_mul(src_width, bpp);
  683. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  684. bandwidth.full = dfixed_div(bandwidth, line_time);
  685. return dfixed_trunc(bandwidth);
  686. }
  687. static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
  688. {
  689. /* First calcualte the latency in ns */
  690. u32 mc_latency = 2000; /* 2000 ns. */
  691. u32 available_bandwidth = evergreen_available_bandwidth(wm);
  692. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  693. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  694. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  695. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  696. (wm->num_heads * cursor_line_pair_return_time);
  697. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  698. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  699. fixed20_12 a, b, c;
  700. if (wm->num_heads == 0)
  701. return 0;
  702. a.full = dfixed_const(2);
  703. b.full = dfixed_const(1);
  704. if ((wm->vsc.full > a.full) ||
  705. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  706. (wm->vtaps >= 5) ||
  707. ((wm->vsc.full >= a.full) && wm->interlaced))
  708. max_src_lines_per_dst_line = 4;
  709. else
  710. max_src_lines_per_dst_line = 2;
  711. a.full = dfixed_const(available_bandwidth);
  712. b.full = dfixed_const(wm->num_heads);
  713. a.full = dfixed_div(a, b);
  714. b.full = dfixed_const(1000);
  715. c.full = dfixed_const(wm->disp_clk);
  716. b.full = dfixed_div(c, b);
  717. c.full = dfixed_const(wm->bytes_per_pixel);
  718. b.full = dfixed_mul(b, c);
  719. lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
  720. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  721. b.full = dfixed_const(1000);
  722. c.full = dfixed_const(lb_fill_bw);
  723. b.full = dfixed_div(c, b);
  724. a.full = dfixed_div(a, b);
  725. line_fill_time = dfixed_trunc(a);
  726. if (line_fill_time < wm->active_time)
  727. return latency;
  728. else
  729. return latency + (line_fill_time - wm->active_time);
  730. }
  731. static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  732. {
  733. if (evergreen_average_bandwidth(wm) <=
  734. (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
  735. return true;
  736. else
  737. return false;
  738. };
  739. static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
  740. {
  741. if (evergreen_average_bandwidth(wm) <=
  742. (evergreen_available_bandwidth(wm) / wm->num_heads))
  743. return true;
  744. else
  745. return false;
  746. };
  747. static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
  748. {
  749. u32 lb_partitions = wm->lb_size / wm->src_width;
  750. u32 line_time = wm->active_time + wm->blank_time;
  751. u32 latency_tolerant_lines;
  752. u32 latency_hiding;
  753. fixed20_12 a;
  754. a.full = dfixed_const(1);
  755. if (wm->vsc.full > a.full)
  756. latency_tolerant_lines = 1;
  757. else {
  758. if (lb_partitions <= (wm->vtaps + 1))
  759. latency_tolerant_lines = 1;
  760. else
  761. latency_tolerant_lines = 2;
  762. }
  763. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  764. if (evergreen_latency_watermark(wm) <= latency_hiding)
  765. return true;
  766. else
  767. return false;
  768. }
  769. static void evergreen_program_watermarks(struct radeon_device *rdev,
  770. struct radeon_crtc *radeon_crtc,
  771. u32 lb_size, u32 num_heads)
  772. {
  773. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  774. struct evergreen_wm_params wm;
  775. u32 pixel_period;
  776. u32 line_time = 0;
  777. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  778. u32 priority_a_mark = 0, priority_b_mark = 0;
  779. u32 priority_a_cnt = PRIORITY_OFF;
  780. u32 priority_b_cnt = PRIORITY_OFF;
  781. u32 pipe_offset = radeon_crtc->crtc_id * 16;
  782. u32 tmp, arb_control3;
  783. fixed20_12 a, b, c;
  784. if (radeon_crtc->base.enabled && num_heads && mode) {
  785. pixel_period = 1000000 / (u32)mode->clock;
  786. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  787. priority_a_cnt = 0;
  788. priority_b_cnt = 0;
  789. wm.yclk = rdev->pm.current_mclk * 10;
  790. wm.sclk = rdev->pm.current_sclk * 10;
  791. wm.disp_clk = mode->clock;
  792. wm.src_width = mode->crtc_hdisplay;
  793. wm.active_time = mode->crtc_hdisplay * pixel_period;
  794. wm.blank_time = line_time - wm.active_time;
  795. wm.interlaced = false;
  796. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  797. wm.interlaced = true;
  798. wm.vsc = radeon_crtc->vsc;
  799. wm.vtaps = 1;
  800. if (radeon_crtc->rmx_type != RMX_OFF)
  801. wm.vtaps = 2;
  802. wm.bytes_per_pixel = 4; /* XXX: get this from fb config */
  803. wm.lb_size = lb_size;
  804. wm.dram_channels = evergreen_get_number_of_dram_channels(rdev);
  805. wm.num_heads = num_heads;
  806. /* set for high clocks */
  807. latency_watermark_a = min(evergreen_latency_watermark(&wm), (u32)65535);
  808. /* set for low clocks */
  809. /* wm.yclk = low clk; wm.sclk = low clk */
  810. latency_watermark_b = min(evergreen_latency_watermark(&wm), (u32)65535);
  811. /* possibly force display priority to high */
  812. /* should really do this at mode validation time... */
  813. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
  814. !evergreen_average_bandwidth_vs_available_bandwidth(&wm) ||
  815. !evergreen_check_latency_hiding(&wm) ||
  816. (rdev->disp_priority == 2)) {
  817. DRM_DEBUG_KMS("force priority to high\n");
  818. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  819. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  820. }
  821. a.full = dfixed_const(1000);
  822. b.full = dfixed_const(mode->clock);
  823. b.full = dfixed_div(b, a);
  824. c.full = dfixed_const(latency_watermark_a);
  825. c.full = dfixed_mul(c, b);
  826. c.full = dfixed_mul(c, radeon_crtc->hsc);
  827. c.full = dfixed_div(c, a);
  828. a.full = dfixed_const(16);
  829. c.full = dfixed_div(c, a);
  830. priority_a_mark = dfixed_trunc(c);
  831. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  832. a.full = dfixed_const(1000);
  833. b.full = dfixed_const(mode->clock);
  834. b.full = dfixed_div(b, a);
  835. c.full = dfixed_const(latency_watermark_b);
  836. c.full = dfixed_mul(c, b);
  837. c.full = dfixed_mul(c, radeon_crtc->hsc);
  838. c.full = dfixed_div(c, a);
  839. a.full = dfixed_const(16);
  840. c.full = dfixed_div(c, a);
  841. priority_b_mark = dfixed_trunc(c);
  842. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  843. }
  844. /* select wm A */
  845. arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  846. tmp = arb_control3;
  847. tmp &= ~LATENCY_WATERMARK_MASK(3);
  848. tmp |= LATENCY_WATERMARK_MASK(1);
  849. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  850. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  851. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  852. LATENCY_HIGH_WATERMARK(line_time)));
  853. /* select wm B */
  854. tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  855. tmp &= ~LATENCY_WATERMARK_MASK(3);
  856. tmp |= LATENCY_WATERMARK_MASK(2);
  857. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  858. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  859. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  860. LATENCY_HIGH_WATERMARK(line_time)));
  861. /* restore original selection */
  862. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
  863. /* write the priority marks */
  864. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  865. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  866. }
  867. void evergreen_bandwidth_update(struct radeon_device *rdev)
  868. {
  869. struct drm_display_mode *mode0 = NULL;
  870. struct drm_display_mode *mode1 = NULL;
  871. u32 num_heads = 0, lb_size;
  872. int i;
  873. radeon_update_display_priority(rdev);
  874. for (i = 0; i < rdev->num_crtc; i++) {
  875. if (rdev->mode_info.crtcs[i]->base.enabled)
  876. num_heads++;
  877. }
  878. for (i = 0; i < rdev->num_crtc; i += 2) {
  879. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  880. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  881. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  882. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  883. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  884. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  885. }
  886. }
  887. int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
  888. {
  889. unsigned i;
  890. u32 tmp;
  891. for (i = 0; i < rdev->usec_timeout; i++) {
  892. /* read MC_STATUS */
  893. tmp = RREG32(SRBM_STATUS) & 0x1F00;
  894. if (!tmp)
  895. return 0;
  896. udelay(1);
  897. }
  898. return -1;
  899. }
  900. /*
  901. * GART
  902. */
  903. void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
  904. {
  905. unsigned i;
  906. u32 tmp;
  907. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  908. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  909. for (i = 0; i < rdev->usec_timeout; i++) {
  910. /* read MC_STATUS */
  911. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  912. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  913. if (tmp == 2) {
  914. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  915. return;
  916. }
  917. if (tmp) {
  918. return;
  919. }
  920. udelay(1);
  921. }
  922. }
  923. int evergreen_pcie_gart_enable(struct radeon_device *rdev)
  924. {
  925. u32 tmp;
  926. int r;
  927. if (rdev->gart.robj == NULL) {
  928. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  929. return -EINVAL;
  930. }
  931. r = radeon_gart_table_vram_pin(rdev);
  932. if (r)
  933. return r;
  934. radeon_gart_restore(rdev);
  935. /* Setup L2 cache */
  936. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  937. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  938. EFFECTIVE_L2_QUEUE_SIZE(7));
  939. WREG32(VM_L2_CNTL2, 0);
  940. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  941. /* Setup TLB control */
  942. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  943. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  944. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  945. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  946. if (rdev->flags & RADEON_IS_IGP) {
  947. WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
  948. WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
  949. WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
  950. } else {
  951. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  952. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  953. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  954. if ((rdev->family == CHIP_JUNIPER) ||
  955. (rdev->family == CHIP_CYPRESS) ||
  956. (rdev->family == CHIP_HEMLOCK) ||
  957. (rdev->family == CHIP_BARTS))
  958. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  959. }
  960. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  961. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  962. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  963. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  964. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  965. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  966. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  967. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  968. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  969. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  970. (u32)(rdev->dummy_page.addr >> 12));
  971. WREG32(VM_CONTEXT1_CNTL, 0);
  972. evergreen_pcie_gart_tlb_flush(rdev);
  973. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  974. (unsigned)(rdev->mc.gtt_size >> 20),
  975. (unsigned long long)rdev->gart.table_addr);
  976. rdev->gart.ready = true;
  977. return 0;
  978. }
  979. void evergreen_pcie_gart_disable(struct radeon_device *rdev)
  980. {
  981. u32 tmp;
  982. /* Disable all tables */
  983. WREG32(VM_CONTEXT0_CNTL, 0);
  984. WREG32(VM_CONTEXT1_CNTL, 0);
  985. /* Setup L2 cache */
  986. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  987. EFFECTIVE_L2_QUEUE_SIZE(7));
  988. WREG32(VM_L2_CNTL2, 0);
  989. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  990. /* Setup TLB control */
  991. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  992. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  993. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  994. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  995. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  996. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  997. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  998. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  999. radeon_gart_table_vram_unpin(rdev);
  1000. }
  1001. void evergreen_pcie_gart_fini(struct radeon_device *rdev)
  1002. {
  1003. evergreen_pcie_gart_disable(rdev);
  1004. radeon_gart_table_vram_free(rdev);
  1005. radeon_gart_fini(rdev);
  1006. }
  1007. void evergreen_agp_enable(struct radeon_device *rdev)
  1008. {
  1009. u32 tmp;
  1010. /* Setup L2 cache */
  1011. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  1012. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1013. EFFECTIVE_L2_QUEUE_SIZE(7));
  1014. WREG32(VM_L2_CNTL2, 0);
  1015. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  1016. /* Setup TLB control */
  1017. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  1018. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1019. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  1020. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  1021. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  1022. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  1023. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  1024. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  1025. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  1026. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  1027. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  1028. WREG32(VM_CONTEXT0_CNTL, 0);
  1029. WREG32(VM_CONTEXT1_CNTL, 0);
  1030. }
  1031. void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
  1032. {
  1033. u32 crtc_enabled, tmp, frame_count, blackout;
  1034. int i, j;
  1035. save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
  1036. save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
  1037. /* disable VGA render */
  1038. WREG32(VGA_RENDER_CONTROL, 0);
  1039. /* blank the display controllers */
  1040. for (i = 0; i < rdev->num_crtc; i++) {
  1041. crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
  1042. if (crtc_enabled) {
  1043. save->crtc_enabled[i] = true;
  1044. if (ASIC_IS_DCE6(rdev)) {
  1045. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  1046. if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
  1047. radeon_wait_for_vblank(rdev, i);
  1048. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  1049. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  1050. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  1051. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  1052. }
  1053. } else {
  1054. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  1055. if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
  1056. radeon_wait_for_vblank(rdev, i);
  1057. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  1058. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1059. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  1060. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  1061. }
  1062. }
  1063. /* wait for the next frame */
  1064. frame_count = radeon_get_vblank_counter(rdev, i);
  1065. for (j = 0; j < rdev->usec_timeout; j++) {
  1066. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  1067. break;
  1068. udelay(1);
  1069. }
  1070. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  1071. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  1072. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  1073. tmp &= ~EVERGREEN_CRTC_MASTER_EN;
  1074. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  1075. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  1076. save->crtc_enabled[i] = false;
  1077. /* ***** */
  1078. } else {
  1079. save->crtc_enabled[i] = false;
  1080. }
  1081. }
  1082. radeon_mc_wait_for_idle(rdev);
  1083. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1084. if ((blackout & BLACKOUT_MODE_MASK) != 1) {
  1085. /* Block CPU access */
  1086. WREG32(BIF_FB_EN, 0);
  1087. /* blackout the MC */
  1088. blackout &= ~BLACKOUT_MODE_MASK;
  1089. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1090. }
  1091. /* wait for the MC to settle */
  1092. udelay(100);
  1093. /* lock double buffered regs */
  1094. for (i = 0; i < rdev->num_crtc; i++) {
  1095. if (save->crtc_enabled[i]) {
  1096. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  1097. if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
  1098. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  1099. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  1100. }
  1101. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  1102. if (!(tmp & 1)) {
  1103. tmp |= 1;
  1104. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  1105. }
  1106. }
  1107. }
  1108. }
  1109. void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
  1110. {
  1111. u32 tmp, frame_count;
  1112. int i, j;
  1113. /* update crtc base addresses */
  1114. for (i = 0; i < rdev->num_crtc; i++) {
  1115. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  1116. upper_32_bits(rdev->mc.vram_start));
  1117. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  1118. upper_32_bits(rdev->mc.vram_start));
  1119. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  1120. (u32)rdev->mc.vram_start);
  1121. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  1122. (u32)rdev->mc.vram_start);
  1123. }
  1124. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
  1125. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
  1126. /* unlock regs and wait for update */
  1127. for (i = 0; i < rdev->num_crtc; i++) {
  1128. if (save->crtc_enabled[i]) {
  1129. tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
  1130. if ((tmp & 0x3) != 0) {
  1131. tmp &= ~0x3;
  1132. WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  1133. }
  1134. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  1135. if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
  1136. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  1137. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  1138. }
  1139. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  1140. if (tmp & 1) {
  1141. tmp &= ~1;
  1142. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  1143. }
  1144. for (j = 0; j < rdev->usec_timeout; j++) {
  1145. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  1146. if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
  1147. break;
  1148. udelay(1);
  1149. }
  1150. }
  1151. }
  1152. /* unblackout the MC */
  1153. tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1154. tmp &= ~BLACKOUT_MODE_MASK;
  1155. WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
  1156. /* allow CPU access */
  1157. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  1158. for (i = 0; i < rdev->num_crtc; i++) {
  1159. if (save->crtc_enabled[i]) {
  1160. if (ASIC_IS_DCE6(rdev)) {
  1161. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  1162. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  1163. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  1164. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  1165. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  1166. } else {
  1167. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  1168. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1169. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  1170. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  1171. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  1172. }
  1173. /* wait for the next frame */
  1174. frame_count = radeon_get_vblank_counter(rdev, i);
  1175. for (j = 0; j < rdev->usec_timeout; j++) {
  1176. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  1177. break;
  1178. udelay(1);
  1179. }
  1180. }
  1181. }
  1182. /* Unlock vga access */
  1183. WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
  1184. mdelay(1);
  1185. WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
  1186. }
  1187. void evergreen_mc_program(struct radeon_device *rdev)
  1188. {
  1189. struct evergreen_mc_save save;
  1190. u32 tmp;
  1191. int i, j;
  1192. /* Initialize HDP */
  1193. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1194. WREG32((0x2c14 + j), 0x00000000);
  1195. WREG32((0x2c18 + j), 0x00000000);
  1196. WREG32((0x2c1c + j), 0x00000000);
  1197. WREG32((0x2c20 + j), 0x00000000);
  1198. WREG32((0x2c24 + j), 0x00000000);
  1199. }
  1200. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  1201. evergreen_mc_stop(rdev, &save);
  1202. if (evergreen_mc_wait_for_idle(rdev)) {
  1203. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1204. }
  1205. /* Lockout access through VGA aperture*/
  1206. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  1207. /* Update configuration */
  1208. if (rdev->flags & RADEON_IS_AGP) {
  1209. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  1210. /* VRAM before AGP */
  1211. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1212. rdev->mc.vram_start >> 12);
  1213. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1214. rdev->mc.gtt_end >> 12);
  1215. } else {
  1216. /* VRAM after AGP */
  1217. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1218. rdev->mc.gtt_start >> 12);
  1219. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1220. rdev->mc.vram_end >> 12);
  1221. }
  1222. } else {
  1223. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1224. rdev->mc.vram_start >> 12);
  1225. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1226. rdev->mc.vram_end >> 12);
  1227. }
  1228. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  1229. /* llano/ontario only */
  1230. if ((rdev->family == CHIP_PALM) ||
  1231. (rdev->family == CHIP_SUMO) ||
  1232. (rdev->family == CHIP_SUMO2)) {
  1233. tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
  1234. tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
  1235. tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
  1236. WREG32(MC_FUS_VM_FB_OFFSET, tmp);
  1237. }
  1238. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  1239. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  1240. WREG32(MC_VM_FB_LOCATION, tmp);
  1241. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  1242. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  1243. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  1244. if (rdev->flags & RADEON_IS_AGP) {
  1245. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  1246. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  1247. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  1248. } else {
  1249. WREG32(MC_VM_AGP_BASE, 0);
  1250. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  1251. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  1252. }
  1253. if (evergreen_mc_wait_for_idle(rdev)) {
  1254. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1255. }
  1256. evergreen_mc_resume(rdev, &save);
  1257. /* we need to own VRAM, so turn off the VGA renderer here
  1258. * to stop it overwriting our objects */
  1259. rv515_vga_render_disable(rdev);
  1260. }
  1261. /*
  1262. * CP.
  1263. */
  1264. void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  1265. {
  1266. struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
  1267. /* set to DX10/11 mode */
  1268. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  1269. radeon_ring_write(ring, 1);
  1270. /* FIXME: implement */
  1271. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  1272. radeon_ring_write(ring,
  1273. #ifdef __BIG_ENDIAN
  1274. (2 << 0) |
  1275. #endif
  1276. (ib->gpu_addr & 0xFFFFFFFC));
  1277. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  1278. radeon_ring_write(ring, ib->length_dw);
  1279. }
  1280. static int evergreen_cp_load_microcode(struct radeon_device *rdev)
  1281. {
  1282. const __be32 *fw_data;
  1283. int i;
  1284. if (!rdev->me_fw || !rdev->pfp_fw)
  1285. return -EINVAL;
  1286. r700_cp_stop(rdev);
  1287. WREG32(CP_RB_CNTL,
  1288. #ifdef __BIG_ENDIAN
  1289. BUF_SWAP_32BIT |
  1290. #endif
  1291. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  1292. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1293. WREG32(CP_PFP_UCODE_ADDR, 0);
  1294. for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
  1295. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  1296. WREG32(CP_PFP_UCODE_ADDR, 0);
  1297. fw_data = (const __be32 *)rdev->me_fw->data;
  1298. WREG32(CP_ME_RAM_WADDR, 0);
  1299. for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
  1300. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  1301. WREG32(CP_PFP_UCODE_ADDR, 0);
  1302. WREG32(CP_ME_RAM_WADDR, 0);
  1303. WREG32(CP_ME_RAM_RADDR, 0);
  1304. return 0;
  1305. }
  1306. static int evergreen_cp_start(struct radeon_device *rdev)
  1307. {
  1308. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1309. int r, i;
  1310. uint32_t cp_me;
  1311. r = radeon_ring_lock(rdev, ring, 7);
  1312. if (r) {
  1313. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1314. return r;
  1315. }
  1316. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  1317. radeon_ring_write(ring, 0x1);
  1318. radeon_ring_write(ring, 0x0);
  1319. radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
  1320. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  1321. radeon_ring_write(ring, 0);
  1322. radeon_ring_write(ring, 0);
  1323. radeon_ring_unlock_commit(rdev, ring);
  1324. cp_me = 0xff;
  1325. WREG32(CP_ME_CNTL, cp_me);
  1326. r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
  1327. if (r) {
  1328. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1329. return r;
  1330. }
  1331. /* setup clear context state */
  1332. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1333. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  1334. for (i = 0; i < evergreen_default_size; i++)
  1335. radeon_ring_write(ring, evergreen_default_state[i]);
  1336. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1337. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  1338. /* set clear context state */
  1339. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  1340. radeon_ring_write(ring, 0);
  1341. /* SQ_VTX_BASE_VTX_LOC */
  1342. radeon_ring_write(ring, 0xc0026f00);
  1343. radeon_ring_write(ring, 0x00000000);
  1344. radeon_ring_write(ring, 0x00000000);
  1345. radeon_ring_write(ring, 0x00000000);
  1346. /* Clear consts */
  1347. radeon_ring_write(ring, 0xc0036f00);
  1348. radeon_ring_write(ring, 0x00000bc4);
  1349. radeon_ring_write(ring, 0xffffffff);
  1350. radeon_ring_write(ring, 0xffffffff);
  1351. radeon_ring_write(ring, 0xffffffff);
  1352. radeon_ring_write(ring, 0xc0026900);
  1353. radeon_ring_write(ring, 0x00000316);
  1354. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  1355. radeon_ring_write(ring, 0x00000010); /* */
  1356. radeon_ring_unlock_commit(rdev, ring);
  1357. return 0;
  1358. }
  1359. int evergreen_cp_resume(struct radeon_device *rdev)
  1360. {
  1361. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1362. u32 tmp;
  1363. u32 rb_bufsz;
  1364. int r;
  1365. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  1366. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  1367. SOFT_RESET_PA |
  1368. SOFT_RESET_SH |
  1369. SOFT_RESET_VGT |
  1370. SOFT_RESET_SPI |
  1371. SOFT_RESET_SX));
  1372. RREG32(GRBM_SOFT_RESET);
  1373. mdelay(15);
  1374. WREG32(GRBM_SOFT_RESET, 0);
  1375. RREG32(GRBM_SOFT_RESET);
  1376. /* Set ring buffer size */
  1377. rb_bufsz = drm_order(ring->ring_size / 8);
  1378. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1379. #ifdef __BIG_ENDIAN
  1380. tmp |= BUF_SWAP_32BIT;
  1381. #endif
  1382. WREG32(CP_RB_CNTL, tmp);
  1383. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  1384. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  1385. /* Set the write pointer delay */
  1386. WREG32(CP_RB_WPTR_DELAY, 0);
  1387. /* Initialize the ring buffer's read and write pointers */
  1388. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  1389. WREG32(CP_RB_RPTR_WR, 0);
  1390. ring->wptr = 0;
  1391. WREG32(CP_RB_WPTR, ring->wptr);
  1392. /* set the wb address wether it's enabled or not */
  1393. WREG32(CP_RB_RPTR_ADDR,
  1394. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  1395. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  1396. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  1397. if (rdev->wb.enabled)
  1398. WREG32(SCRATCH_UMSK, 0xff);
  1399. else {
  1400. tmp |= RB_NO_UPDATE;
  1401. WREG32(SCRATCH_UMSK, 0);
  1402. }
  1403. mdelay(1);
  1404. WREG32(CP_RB_CNTL, tmp);
  1405. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  1406. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  1407. ring->rptr = RREG32(CP_RB_RPTR);
  1408. evergreen_cp_start(rdev);
  1409. ring->ready = true;
  1410. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  1411. if (r) {
  1412. ring->ready = false;
  1413. return r;
  1414. }
  1415. return 0;
  1416. }
  1417. /*
  1418. * Core functions
  1419. */
  1420. static u32 evergreen_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
  1421. u32 num_tile_pipes,
  1422. u32 num_backends,
  1423. u32 backend_disable_mask)
  1424. {
  1425. u32 backend_map = 0;
  1426. u32 enabled_backends_mask = 0;
  1427. u32 enabled_backends_count = 0;
  1428. u32 cur_pipe;
  1429. u32 swizzle_pipe[EVERGREEN_MAX_PIPES];
  1430. u32 cur_backend = 0;
  1431. u32 i;
  1432. bool force_no_swizzle;
  1433. if (num_tile_pipes > EVERGREEN_MAX_PIPES)
  1434. num_tile_pipes = EVERGREEN_MAX_PIPES;
  1435. if (num_tile_pipes < 1)
  1436. num_tile_pipes = 1;
  1437. if (num_backends > EVERGREEN_MAX_BACKENDS)
  1438. num_backends = EVERGREEN_MAX_BACKENDS;
  1439. if (num_backends < 1)
  1440. num_backends = 1;
  1441. for (i = 0; i < EVERGREEN_MAX_BACKENDS; ++i) {
  1442. if (((backend_disable_mask >> i) & 1) == 0) {
  1443. enabled_backends_mask |= (1 << i);
  1444. ++enabled_backends_count;
  1445. }
  1446. if (enabled_backends_count == num_backends)
  1447. break;
  1448. }
  1449. if (enabled_backends_count == 0) {
  1450. enabled_backends_mask = 1;
  1451. enabled_backends_count = 1;
  1452. }
  1453. if (enabled_backends_count != num_backends)
  1454. num_backends = enabled_backends_count;
  1455. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * EVERGREEN_MAX_PIPES);
  1456. switch (rdev->family) {
  1457. case CHIP_CEDAR:
  1458. case CHIP_REDWOOD:
  1459. case CHIP_PALM:
  1460. case CHIP_SUMO:
  1461. case CHIP_SUMO2:
  1462. case CHIP_TURKS:
  1463. case CHIP_CAICOS:
  1464. force_no_swizzle = false;
  1465. break;
  1466. case CHIP_CYPRESS:
  1467. case CHIP_HEMLOCK:
  1468. case CHIP_JUNIPER:
  1469. case CHIP_BARTS:
  1470. default:
  1471. force_no_swizzle = true;
  1472. break;
  1473. }
  1474. if (force_no_swizzle) {
  1475. bool last_backend_enabled = false;
  1476. force_no_swizzle = false;
  1477. for (i = 0; i < EVERGREEN_MAX_BACKENDS; ++i) {
  1478. if (((enabled_backends_mask >> i) & 1) == 1) {
  1479. if (last_backend_enabled)
  1480. force_no_swizzle = true;
  1481. last_backend_enabled = true;
  1482. } else
  1483. last_backend_enabled = false;
  1484. }
  1485. }
  1486. switch (num_tile_pipes) {
  1487. case 1:
  1488. case 3:
  1489. case 5:
  1490. case 7:
  1491. DRM_ERROR("odd number of pipes!\n");
  1492. break;
  1493. case 2:
  1494. swizzle_pipe[0] = 0;
  1495. swizzle_pipe[1] = 1;
  1496. break;
  1497. case 4:
  1498. if (force_no_swizzle) {
  1499. swizzle_pipe[0] = 0;
  1500. swizzle_pipe[1] = 1;
  1501. swizzle_pipe[2] = 2;
  1502. swizzle_pipe[3] = 3;
  1503. } else {
  1504. swizzle_pipe[0] = 0;
  1505. swizzle_pipe[1] = 2;
  1506. swizzle_pipe[2] = 1;
  1507. swizzle_pipe[3] = 3;
  1508. }
  1509. break;
  1510. case 6:
  1511. if (force_no_swizzle) {
  1512. swizzle_pipe[0] = 0;
  1513. swizzle_pipe[1] = 1;
  1514. swizzle_pipe[2] = 2;
  1515. swizzle_pipe[3] = 3;
  1516. swizzle_pipe[4] = 4;
  1517. swizzle_pipe[5] = 5;
  1518. } else {
  1519. swizzle_pipe[0] = 0;
  1520. swizzle_pipe[1] = 2;
  1521. swizzle_pipe[2] = 4;
  1522. swizzle_pipe[3] = 1;
  1523. swizzle_pipe[4] = 3;
  1524. swizzle_pipe[5] = 5;
  1525. }
  1526. break;
  1527. case 8:
  1528. if (force_no_swizzle) {
  1529. swizzle_pipe[0] = 0;
  1530. swizzle_pipe[1] = 1;
  1531. swizzle_pipe[2] = 2;
  1532. swizzle_pipe[3] = 3;
  1533. swizzle_pipe[4] = 4;
  1534. swizzle_pipe[5] = 5;
  1535. swizzle_pipe[6] = 6;
  1536. swizzle_pipe[7] = 7;
  1537. } else {
  1538. swizzle_pipe[0] = 0;
  1539. swizzle_pipe[1] = 2;
  1540. swizzle_pipe[2] = 4;
  1541. swizzle_pipe[3] = 6;
  1542. swizzle_pipe[4] = 1;
  1543. swizzle_pipe[5] = 3;
  1544. swizzle_pipe[6] = 5;
  1545. swizzle_pipe[7] = 7;
  1546. }
  1547. break;
  1548. }
  1549. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  1550. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  1551. cur_backend = (cur_backend + 1) % EVERGREEN_MAX_BACKENDS;
  1552. backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4)));
  1553. cur_backend = (cur_backend + 1) % EVERGREEN_MAX_BACKENDS;
  1554. }
  1555. return backend_map;
  1556. }
  1557. static void evergreen_gpu_init(struct radeon_device *rdev)
  1558. {
  1559. u32 cc_rb_backend_disable = 0;
  1560. u32 cc_gc_shader_pipe_config;
  1561. u32 gb_addr_config = 0;
  1562. u32 mc_shared_chmap, mc_arb_ramcfg;
  1563. u32 gb_backend_map;
  1564. u32 grbm_gfx_index;
  1565. u32 sx_debug_1;
  1566. u32 smx_dc_ctl0;
  1567. u32 sq_config;
  1568. u32 sq_lds_resource_mgmt;
  1569. u32 sq_gpr_resource_mgmt_1;
  1570. u32 sq_gpr_resource_mgmt_2;
  1571. u32 sq_gpr_resource_mgmt_3;
  1572. u32 sq_thread_resource_mgmt;
  1573. u32 sq_thread_resource_mgmt_2;
  1574. u32 sq_stack_resource_mgmt_1;
  1575. u32 sq_stack_resource_mgmt_2;
  1576. u32 sq_stack_resource_mgmt_3;
  1577. u32 vgt_cache_invalidation;
  1578. u32 hdp_host_path_cntl, tmp;
  1579. int i, j, num_shader_engines, ps_thread_count;
  1580. switch (rdev->family) {
  1581. case CHIP_CYPRESS:
  1582. case CHIP_HEMLOCK:
  1583. rdev->config.evergreen.num_ses = 2;
  1584. rdev->config.evergreen.max_pipes = 4;
  1585. rdev->config.evergreen.max_tile_pipes = 8;
  1586. rdev->config.evergreen.max_simds = 10;
  1587. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  1588. rdev->config.evergreen.max_gprs = 256;
  1589. rdev->config.evergreen.max_threads = 248;
  1590. rdev->config.evergreen.max_gs_threads = 32;
  1591. rdev->config.evergreen.max_stack_entries = 512;
  1592. rdev->config.evergreen.sx_num_of_sets = 4;
  1593. rdev->config.evergreen.sx_max_export_size = 256;
  1594. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1595. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1596. rdev->config.evergreen.max_hw_contexts = 8;
  1597. rdev->config.evergreen.sq_num_cf_insts = 2;
  1598. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  1599. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1600. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1601. break;
  1602. case CHIP_JUNIPER:
  1603. rdev->config.evergreen.num_ses = 1;
  1604. rdev->config.evergreen.max_pipes = 4;
  1605. rdev->config.evergreen.max_tile_pipes = 4;
  1606. rdev->config.evergreen.max_simds = 10;
  1607. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  1608. rdev->config.evergreen.max_gprs = 256;
  1609. rdev->config.evergreen.max_threads = 248;
  1610. rdev->config.evergreen.max_gs_threads = 32;
  1611. rdev->config.evergreen.max_stack_entries = 512;
  1612. rdev->config.evergreen.sx_num_of_sets = 4;
  1613. rdev->config.evergreen.sx_max_export_size = 256;
  1614. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1615. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1616. rdev->config.evergreen.max_hw_contexts = 8;
  1617. rdev->config.evergreen.sq_num_cf_insts = 2;
  1618. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  1619. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1620. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1621. break;
  1622. case CHIP_REDWOOD:
  1623. rdev->config.evergreen.num_ses = 1;
  1624. rdev->config.evergreen.max_pipes = 4;
  1625. rdev->config.evergreen.max_tile_pipes = 4;
  1626. rdev->config.evergreen.max_simds = 5;
  1627. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  1628. rdev->config.evergreen.max_gprs = 256;
  1629. rdev->config.evergreen.max_threads = 248;
  1630. rdev->config.evergreen.max_gs_threads = 32;
  1631. rdev->config.evergreen.max_stack_entries = 256;
  1632. rdev->config.evergreen.sx_num_of_sets = 4;
  1633. rdev->config.evergreen.sx_max_export_size = 256;
  1634. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1635. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1636. rdev->config.evergreen.max_hw_contexts = 8;
  1637. rdev->config.evergreen.sq_num_cf_insts = 2;
  1638. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  1639. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1640. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1641. break;
  1642. case CHIP_CEDAR:
  1643. default:
  1644. rdev->config.evergreen.num_ses = 1;
  1645. rdev->config.evergreen.max_pipes = 2;
  1646. rdev->config.evergreen.max_tile_pipes = 2;
  1647. rdev->config.evergreen.max_simds = 2;
  1648. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  1649. rdev->config.evergreen.max_gprs = 256;
  1650. rdev->config.evergreen.max_threads = 192;
  1651. rdev->config.evergreen.max_gs_threads = 16;
  1652. rdev->config.evergreen.max_stack_entries = 256;
  1653. rdev->config.evergreen.sx_num_of_sets = 4;
  1654. rdev->config.evergreen.sx_max_export_size = 128;
  1655. rdev->config.evergreen.sx_max_export_pos_size = 32;
  1656. rdev->config.evergreen.sx_max_export_smx_size = 96;
  1657. rdev->config.evergreen.max_hw_contexts = 4;
  1658. rdev->config.evergreen.sq_num_cf_insts = 1;
  1659. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  1660. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1661. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1662. break;
  1663. case CHIP_PALM:
  1664. rdev->config.evergreen.num_ses = 1;
  1665. rdev->config.evergreen.max_pipes = 2;
  1666. rdev->config.evergreen.max_tile_pipes = 2;
  1667. rdev->config.evergreen.max_simds = 2;
  1668. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  1669. rdev->config.evergreen.max_gprs = 256;
  1670. rdev->config.evergreen.max_threads = 192;
  1671. rdev->config.evergreen.max_gs_threads = 16;
  1672. rdev->config.evergreen.max_stack_entries = 256;
  1673. rdev->config.evergreen.sx_num_of_sets = 4;
  1674. rdev->config.evergreen.sx_max_export_size = 128;
  1675. rdev->config.evergreen.sx_max_export_pos_size = 32;
  1676. rdev->config.evergreen.sx_max_export_smx_size = 96;
  1677. rdev->config.evergreen.max_hw_contexts = 4;
  1678. rdev->config.evergreen.sq_num_cf_insts = 1;
  1679. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  1680. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1681. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1682. break;
  1683. case CHIP_SUMO:
  1684. rdev->config.evergreen.num_ses = 1;
  1685. rdev->config.evergreen.max_pipes = 4;
  1686. rdev->config.evergreen.max_tile_pipes = 4;
  1687. if (rdev->pdev->device == 0x9648)
  1688. rdev->config.evergreen.max_simds = 3;
  1689. else if ((rdev->pdev->device == 0x9647) ||
  1690. (rdev->pdev->device == 0x964a))
  1691. rdev->config.evergreen.max_simds = 4;
  1692. else
  1693. rdev->config.evergreen.max_simds = 5;
  1694. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  1695. rdev->config.evergreen.max_gprs = 256;
  1696. rdev->config.evergreen.max_threads = 248;
  1697. rdev->config.evergreen.max_gs_threads = 32;
  1698. rdev->config.evergreen.max_stack_entries = 256;
  1699. rdev->config.evergreen.sx_num_of_sets = 4;
  1700. rdev->config.evergreen.sx_max_export_size = 256;
  1701. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1702. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1703. rdev->config.evergreen.max_hw_contexts = 8;
  1704. rdev->config.evergreen.sq_num_cf_insts = 2;
  1705. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  1706. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1707. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1708. break;
  1709. case CHIP_SUMO2:
  1710. rdev->config.evergreen.num_ses = 1;
  1711. rdev->config.evergreen.max_pipes = 4;
  1712. rdev->config.evergreen.max_tile_pipes = 4;
  1713. rdev->config.evergreen.max_simds = 2;
  1714. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  1715. rdev->config.evergreen.max_gprs = 256;
  1716. rdev->config.evergreen.max_threads = 248;
  1717. rdev->config.evergreen.max_gs_threads = 32;
  1718. rdev->config.evergreen.max_stack_entries = 512;
  1719. rdev->config.evergreen.sx_num_of_sets = 4;
  1720. rdev->config.evergreen.sx_max_export_size = 256;
  1721. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1722. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1723. rdev->config.evergreen.max_hw_contexts = 4;
  1724. rdev->config.evergreen.sq_num_cf_insts = 2;
  1725. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  1726. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1727. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1728. break;
  1729. case CHIP_BARTS:
  1730. rdev->config.evergreen.num_ses = 2;
  1731. rdev->config.evergreen.max_pipes = 4;
  1732. rdev->config.evergreen.max_tile_pipes = 8;
  1733. rdev->config.evergreen.max_simds = 7;
  1734. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  1735. rdev->config.evergreen.max_gprs = 256;
  1736. rdev->config.evergreen.max_threads = 248;
  1737. rdev->config.evergreen.max_gs_threads = 32;
  1738. rdev->config.evergreen.max_stack_entries = 512;
  1739. rdev->config.evergreen.sx_num_of_sets = 4;
  1740. rdev->config.evergreen.sx_max_export_size = 256;
  1741. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1742. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1743. rdev->config.evergreen.max_hw_contexts = 8;
  1744. rdev->config.evergreen.sq_num_cf_insts = 2;
  1745. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  1746. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1747. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1748. break;
  1749. case CHIP_TURKS:
  1750. rdev->config.evergreen.num_ses = 1;
  1751. rdev->config.evergreen.max_pipes = 4;
  1752. rdev->config.evergreen.max_tile_pipes = 4;
  1753. rdev->config.evergreen.max_simds = 6;
  1754. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  1755. rdev->config.evergreen.max_gprs = 256;
  1756. rdev->config.evergreen.max_threads = 248;
  1757. rdev->config.evergreen.max_gs_threads = 32;
  1758. rdev->config.evergreen.max_stack_entries = 256;
  1759. rdev->config.evergreen.sx_num_of_sets = 4;
  1760. rdev->config.evergreen.sx_max_export_size = 256;
  1761. rdev->config.evergreen.sx_max_export_pos_size = 64;
  1762. rdev->config.evergreen.sx_max_export_smx_size = 192;
  1763. rdev->config.evergreen.max_hw_contexts = 8;
  1764. rdev->config.evergreen.sq_num_cf_insts = 2;
  1765. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  1766. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1767. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1768. break;
  1769. case CHIP_CAICOS:
  1770. rdev->config.evergreen.num_ses = 1;
  1771. rdev->config.evergreen.max_pipes = 2;
  1772. rdev->config.evergreen.max_tile_pipes = 2;
  1773. rdev->config.evergreen.max_simds = 2;
  1774. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  1775. rdev->config.evergreen.max_gprs = 256;
  1776. rdev->config.evergreen.max_threads = 192;
  1777. rdev->config.evergreen.max_gs_threads = 16;
  1778. rdev->config.evergreen.max_stack_entries = 256;
  1779. rdev->config.evergreen.sx_num_of_sets = 4;
  1780. rdev->config.evergreen.sx_max_export_size = 128;
  1781. rdev->config.evergreen.sx_max_export_pos_size = 32;
  1782. rdev->config.evergreen.sx_max_export_smx_size = 96;
  1783. rdev->config.evergreen.max_hw_contexts = 4;
  1784. rdev->config.evergreen.sq_num_cf_insts = 1;
  1785. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  1786. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  1787. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  1788. break;
  1789. }
  1790. /* Initialize HDP */
  1791. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1792. WREG32((0x2c14 + j), 0x00000000);
  1793. WREG32((0x2c18 + j), 0x00000000);
  1794. WREG32((0x2c1c + j), 0x00000000);
  1795. WREG32((0x2c20 + j), 0x00000000);
  1796. WREG32((0x2c24 + j), 0x00000000);
  1797. }
  1798. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  1799. evergreen_fix_pci_max_read_req_size(rdev);
  1800. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & ~2;
  1801. cc_gc_shader_pipe_config |=
  1802. INACTIVE_QD_PIPES((EVERGREEN_MAX_PIPES_MASK << rdev->config.evergreen.max_pipes)
  1803. & EVERGREEN_MAX_PIPES_MASK);
  1804. cc_gc_shader_pipe_config |=
  1805. INACTIVE_SIMDS((EVERGREEN_MAX_SIMDS_MASK << rdev->config.evergreen.max_simds)
  1806. & EVERGREEN_MAX_SIMDS_MASK);
  1807. cc_rb_backend_disable =
  1808. BACKEND_DISABLE((EVERGREEN_MAX_BACKENDS_MASK << rdev->config.evergreen.max_backends)
  1809. & EVERGREEN_MAX_BACKENDS_MASK);
  1810. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  1811. if ((rdev->family == CHIP_PALM) ||
  1812. (rdev->family == CHIP_SUMO) ||
  1813. (rdev->family == CHIP_SUMO2))
  1814. mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
  1815. else
  1816. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  1817. switch (rdev->config.evergreen.max_tile_pipes) {
  1818. case 1:
  1819. default:
  1820. gb_addr_config |= NUM_PIPES(0);
  1821. break;
  1822. case 2:
  1823. gb_addr_config |= NUM_PIPES(1);
  1824. break;
  1825. case 4:
  1826. gb_addr_config |= NUM_PIPES(2);
  1827. break;
  1828. case 8:
  1829. gb_addr_config |= NUM_PIPES(3);
  1830. break;
  1831. }
  1832. gb_addr_config |= PIPE_INTERLEAVE_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
  1833. gb_addr_config |= BANK_INTERLEAVE_SIZE(0);
  1834. gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.evergreen.num_ses - 1);
  1835. gb_addr_config |= SHADER_ENGINE_TILE_SIZE(1);
  1836. gb_addr_config |= NUM_GPUS(0); /* Hemlock? */
  1837. gb_addr_config |= MULTI_GPU_TILE_SIZE(2);
  1838. if (((mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT) > 2)
  1839. gb_addr_config |= ROW_SIZE(2);
  1840. else
  1841. gb_addr_config |= ROW_SIZE((mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT);
  1842. if (rdev->ddev->pdev->device == 0x689e) {
  1843. u32 efuse_straps_4;
  1844. u32 efuse_straps_3;
  1845. u8 efuse_box_bit_131_124;
  1846. WREG32(RCU_IND_INDEX, 0x204);
  1847. efuse_straps_4 = RREG32(RCU_IND_DATA);
  1848. WREG32(RCU_IND_INDEX, 0x203);
  1849. efuse_straps_3 = RREG32(RCU_IND_DATA);
  1850. efuse_box_bit_131_124 = (u8)(((efuse_straps_4 & 0xf) << 4) | ((efuse_straps_3 & 0xf0000000) >> 28));
  1851. switch(efuse_box_bit_131_124) {
  1852. case 0x00:
  1853. gb_backend_map = 0x76543210;
  1854. break;
  1855. case 0x55:
  1856. gb_backend_map = 0x77553311;
  1857. break;
  1858. case 0x56:
  1859. gb_backend_map = 0x77553300;
  1860. break;
  1861. case 0x59:
  1862. gb_backend_map = 0x77552211;
  1863. break;
  1864. case 0x66:
  1865. gb_backend_map = 0x77443300;
  1866. break;
  1867. case 0x99:
  1868. gb_backend_map = 0x66552211;
  1869. break;
  1870. case 0x5a:
  1871. gb_backend_map = 0x77552200;
  1872. break;
  1873. case 0xaa:
  1874. gb_backend_map = 0x66442200;
  1875. break;
  1876. case 0x95:
  1877. gb_backend_map = 0x66553311;
  1878. break;
  1879. default:
  1880. DRM_ERROR("bad backend map, using default\n");
  1881. gb_backend_map =
  1882. evergreen_get_tile_pipe_to_backend_map(rdev,
  1883. rdev->config.evergreen.max_tile_pipes,
  1884. rdev->config.evergreen.max_backends,
  1885. ((EVERGREEN_MAX_BACKENDS_MASK <<
  1886. rdev->config.evergreen.max_backends) &
  1887. EVERGREEN_MAX_BACKENDS_MASK));
  1888. break;
  1889. }
  1890. } else if (rdev->ddev->pdev->device == 0x68b9) {
  1891. u32 efuse_straps_3;
  1892. u8 efuse_box_bit_127_124;
  1893. WREG32(RCU_IND_INDEX, 0x203);
  1894. efuse_straps_3 = RREG32(RCU_IND_DATA);
  1895. efuse_box_bit_127_124 = (u8)((efuse_straps_3 & 0xF0000000) >> 28);
  1896. switch(efuse_box_bit_127_124) {
  1897. case 0x0:
  1898. gb_backend_map = 0x00003210;
  1899. break;
  1900. case 0x5:
  1901. case 0x6:
  1902. case 0x9:
  1903. case 0xa:
  1904. gb_backend_map = 0x00003311;
  1905. break;
  1906. default:
  1907. DRM_ERROR("bad backend map, using default\n");
  1908. gb_backend_map =
  1909. evergreen_get_tile_pipe_to_backend_map(rdev,
  1910. rdev->config.evergreen.max_tile_pipes,
  1911. rdev->config.evergreen.max_backends,
  1912. ((EVERGREEN_MAX_BACKENDS_MASK <<
  1913. rdev->config.evergreen.max_backends) &
  1914. EVERGREEN_MAX_BACKENDS_MASK));
  1915. break;
  1916. }
  1917. } else {
  1918. switch (rdev->family) {
  1919. case CHIP_CYPRESS:
  1920. case CHIP_HEMLOCK:
  1921. case CHIP_BARTS:
  1922. gb_backend_map = 0x66442200;
  1923. break;
  1924. case CHIP_JUNIPER:
  1925. gb_backend_map = 0x00002200;
  1926. break;
  1927. default:
  1928. gb_backend_map =
  1929. evergreen_get_tile_pipe_to_backend_map(rdev,
  1930. rdev->config.evergreen.max_tile_pipes,
  1931. rdev->config.evergreen.max_backends,
  1932. ((EVERGREEN_MAX_BACKENDS_MASK <<
  1933. rdev->config.evergreen.max_backends) &
  1934. EVERGREEN_MAX_BACKENDS_MASK));
  1935. }
  1936. }
  1937. /* setup tiling info dword. gb_addr_config is not adequate since it does
  1938. * not have bank info, so create a custom tiling dword.
  1939. * bits 3:0 num_pipes
  1940. * bits 7:4 num_banks
  1941. * bits 11:8 group_size
  1942. * bits 15:12 row_size
  1943. */
  1944. rdev->config.evergreen.tile_config = 0;
  1945. switch (rdev->config.evergreen.max_tile_pipes) {
  1946. case 1:
  1947. default:
  1948. rdev->config.evergreen.tile_config |= (0 << 0);
  1949. break;
  1950. case 2:
  1951. rdev->config.evergreen.tile_config |= (1 << 0);
  1952. break;
  1953. case 4:
  1954. rdev->config.evergreen.tile_config |= (2 << 0);
  1955. break;
  1956. case 8:
  1957. rdev->config.evergreen.tile_config |= (3 << 0);
  1958. break;
  1959. }
  1960. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  1961. if (rdev->flags & RADEON_IS_IGP)
  1962. rdev->config.evergreen.tile_config |= 1 << 4;
  1963. else {
  1964. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  1965. case 0: /* four banks */
  1966. rdev->config.evergreen.tile_config |= 0 << 4;
  1967. break;
  1968. case 1: /* eight banks */
  1969. rdev->config.evergreen.tile_config |= 1 << 4;
  1970. break;
  1971. case 2: /* sixteen banks */
  1972. default:
  1973. rdev->config.evergreen.tile_config |= 2 << 4;
  1974. break;
  1975. }
  1976. }
  1977. rdev->config.evergreen.tile_config |=
  1978. ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT) << 8;
  1979. rdev->config.evergreen.tile_config |=
  1980. ((gb_addr_config & 0x30000000) >> 28) << 12;
  1981. rdev->config.evergreen.backend_map = gb_backend_map;
  1982. WREG32(GB_BACKEND_MAP, gb_backend_map);
  1983. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  1984. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  1985. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  1986. num_shader_engines = ((RREG32(GB_ADDR_CONFIG) & NUM_SHADER_ENGINES(3)) >> 12) + 1;
  1987. grbm_gfx_index = INSTANCE_BROADCAST_WRITES;
  1988. for (i = 0; i < rdev->config.evergreen.num_ses; i++) {
  1989. u32 rb = cc_rb_backend_disable | (0xf0 << 16);
  1990. u32 sp = cc_gc_shader_pipe_config;
  1991. u32 gfx = grbm_gfx_index | SE_INDEX(i);
  1992. if (i == num_shader_engines) {
  1993. rb |= BACKEND_DISABLE(EVERGREEN_MAX_BACKENDS_MASK);
  1994. sp |= INACTIVE_SIMDS(EVERGREEN_MAX_SIMDS_MASK);
  1995. }
  1996. WREG32(GRBM_GFX_INDEX, gfx);
  1997. WREG32(RLC_GFX_INDEX, gfx);
  1998. WREG32(CC_RB_BACKEND_DISABLE, rb);
  1999. WREG32(CC_SYS_RB_BACKEND_DISABLE, rb);
  2000. WREG32(GC_USER_RB_BACKEND_DISABLE, rb);
  2001. WREG32(CC_GC_SHADER_PIPE_CONFIG, sp);
  2002. }
  2003. grbm_gfx_index = INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2004. WREG32(GRBM_GFX_INDEX, grbm_gfx_index);
  2005. WREG32(RLC_GFX_INDEX, grbm_gfx_index);
  2006. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  2007. WREG32(CGTS_TCC_DISABLE, 0);
  2008. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  2009. WREG32(CGTS_USER_TCC_DISABLE, 0);
  2010. /* set HW defaults for 3D engine */
  2011. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2012. ROQ_IB2_START(0x2b)));
  2013. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  2014. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
  2015. SYNC_GRADIENT |
  2016. SYNC_WALKER |
  2017. SYNC_ALIGNER));
  2018. sx_debug_1 = RREG32(SX_DEBUG_1);
  2019. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  2020. WREG32(SX_DEBUG_1, sx_debug_1);
  2021. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  2022. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  2023. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
  2024. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  2025. if (rdev->family <= CHIP_SUMO2)
  2026. WREG32(SMX_SAR_CTL0, 0x00010000);
  2027. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
  2028. POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
  2029. SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
  2030. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
  2031. SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
  2032. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
  2033. WREG32(VGT_NUM_INSTANCES, 1);
  2034. WREG32(SPI_CONFIG_CNTL, 0);
  2035. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2036. WREG32(CP_PERFMON_CNTL, 0);
  2037. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
  2038. FETCH_FIFO_HIWATER(0x4) |
  2039. DONE_FIFO_HIWATER(0xe0) |
  2040. ALU_UPDATE_FIFO_HIWATER(0x8)));
  2041. sq_config = RREG32(SQ_CONFIG);
  2042. sq_config &= ~(PS_PRIO(3) |
  2043. VS_PRIO(3) |
  2044. GS_PRIO(3) |
  2045. ES_PRIO(3));
  2046. sq_config |= (VC_ENABLE |
  2047. EXPORT_SRC_C |
  2048. PS_PRIO(0) |
  2049. VS_PRIO(1) |
  2050. GS_PRIO(2) |
  2051. ES_PRIO(3));
  2052. switch (rdev->family) {
  2053. case CHIP_CEDAR:
  2054. case CHIP_PALM:
  2055. case CHIP_SUMO:
  2056. case CHIP_SUMO2:
  2057. case CHIP_CAICOS:
  2058. /* no vertex cache */
  2059. sq_config &= ~VC_ENABLE;
  2060. break;
  2061. default:
  2062. break;
  2063. }
  2064. sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
  2065. sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
  2066. sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
  2067. sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
  2068. sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  2069. sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  2070. sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  2071. sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  2072. switch (rdev->family) {
  2073. case CHIP_CEDAR:
  2074. case CHIP_PALM:
  2075. case CHIP_SUMO:
  2076. case CHIP_SUMO2:
  2077. ps_thread_count = 96;
  2078. break;
  2079. default:
  2080. ps_thread_count = 128;
  2081. break;
  2082. }
  2083. sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
  2084. sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  2085. sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  2086. sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  2087. sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  2088. sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  2089. sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2090. sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2091. sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2092. sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2093. sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2094. sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  2095. WREG32(SQ_CONFIG, sq_config);
  2096. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  2097. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  2098. WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
  2099. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  2100. WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
  2101. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  2102. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  2103. WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
  2104. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
  2105. WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
  2106. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2107. FORCE_EOV_MAX_REZ_CNT(255)));
  2108. switch (rdev->family) {
  2109. case CHIP_CEDAR:
  2110. case CHIP_PALM:
  2111. case CHIP_SUMO:
  2112. case CHIP_SUMO2:
  2113. case CHIP_CAICOS:
  2114. vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
  2115. break;
  2116. default:
  2117. vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
  2118. break;
  2119. }
  2120. vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
  2121. WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
  2122. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2123. WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
  2124. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2125. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
  2126. WREG32(VGT_OUT_DEALLOC_CNTL, 16);
  2127. WREG32(CB_PERF_CTR0_SEL_0, 0);
  2128. WREG32(CB_PERF_CTR0_SEL_1, 0);
  2129. WREG32(CB_PERF_CTR1_SEL_0, 0);
  2130. WREG32(CB_PERF_CTR1_SEL_1, 0);
  2131. WREG32(CB_PERF_CTR2_SEL_0, 0);
  2132. WREG32(CB_PERF_CTR2_SEL_1, 0);
  2133. WREG32(CB_PERF_CTR3_SEL_0, 0);
  2134. WREG32(CB_PERF_CTR3_SEL_1, 0);
  2135. /* clear render buffer base addresses */
  2136. WREG32(CB_COLOR0_BASE, 0);
  2137. WREG32(CB_COLOR1_BASE, 0);
  2138. WREG32(CB_COLOR2_BASE, 0);
  2139. WREG32(CB_COLOR3_BASE, 0);
  2140. WREG32(CB_COLOR4_BASE, 0);
  2141. WREG32(CB_COLOR5_BASE, 0);
  2142. WREG32(CB_COLOR6_BASE, 0);
  2143. WREG32(CB_COLOR7_BASE, 0);
  2144. WREG32(CB_COLOR8_BASE, 0);
  2145. WREG32(CB_COLOR9_BASE, 0);
  2146. WREG32(CB_COLOR10_BASE, 0);
  2147. WREG32(CB_COLOR11_BASE, 0);
  2148. /* set the shader const cache sizes to 0 */
  2149. for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
  2150. WREG32(i, 0);
  2151. for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
  2152. WREG32(i, 0);
  2153. tmp = RREG32(HDP_MISC_CNTL);
  2154. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2155. WREG32(HDP_MISC_CNTL, tmp);
  2156. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2157. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2158. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2159. udelay(50);
  2160. }
  2161. int evergreen_mc_init(struct radeon_device *rdev)
  2162. {
  2163. u32 tmp;
  2164. int chansize, numchan;
  2165. /* Get VRAM informations */
  2166. rdev->mc.vram_is_ddr = true;
  2167. if ((rdev->family == CHIP_PALM) ||
  2168. (rdev->family == CHIP_SUMO) ||
  2169. (rdev->family == CHIP_SUMO2))
  2170. tmp = RREG32(FUS_MC_ARB_RAMCFG);
  2171. else
  2172. tmp = RREG32(MC_ARB_RAMCFG);
  2173. if (tmp & CHANSIZE_OVERRIDE) {
  2174. chansize = 16;
  2175. } else if (tmp & CHANSIZE_MASK) {
  2176. chansize = 64;
  2177. } else {
  2178. chansize = 32;
  2179. }
  2180. tmp = RREG32(MC_SHARED_CHMAP);
  2181. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  2182. case 0:
  2183. default:
  2184. numchan = 1;
  2185. break;
  2186. case 1:
  2187. numchan = 2;
  2188. break;
  2189. case 2:
  2190. numchan = 4;
  2191. break;
  2192. case 3:
  2193. numchan = 8;
  2194. break;
  2195. }
  2196. rdev->mc.vram_width = numchan * chansize;
  2197. /* Could aper size report 0 ? */
  2198. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  2199. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  2200. /* Setup GPU memory space */
  2201. if ((rdev->family == CHIP_PALM) ||
  2202. (rdev->family == CHIP_SUMO) ||
  2203. (rdev->family == CHIP_SUMO2)) {
  2204. /* size in bytes on fusion */
  2205. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  2206. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  2207. } else {
  2208. /* size in MB on evergreen/cayman/tn */
  2209. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  2210. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  2211. }
  2212. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  2213. r700_vram_gtt_location(rdev, &rdev->mc);
  2214. radeon_update_bandwidth_info(rdev);
  2215. return 0;
  2216. }
  2217. bool evergreen_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  2218. {
  2219. u32 srbm_status;
  2220. u32 grbm_status;
  2221. u32 grbm_status_se0, grbm_status_se1;
  2222. struct r100_gpu_lockup *lockup = &rdev->config.evergreen.lockup;
  2223. int r;
  2224. srbm_status = RREG32(SRBM_STATUS);
  2225. grbm_status = RREG32(GRBM_STATUS);
  2226. grbm_status_se0 = RREG32(GRBM_STATUS_SE0);
  2227. grbm_status_se1 = RREG32(GRBM_STATUS_SE1);
  2228. if (!(grbm_status & GUI_ACTIVE)) {
  2229. r100_gpu_lockup_update(lockup, ring);
  2230. return false;
  2231. }
  2232. /* force CP activities */
  2233. r = radeon_ring_lock(rdev, ring, 2);
  2234. if (!r) {
  2235. /* PACKET2 NOP */
  2236. radeon_ring_write(ring, 0x80000000);
  2237. radeon_ring_write(ring, 0x80000000);
  2238. radeon_ring_unlock_commit(rdev, ring);
  2239. }
  2240. ring->rptr = RREG32(CP_RB_RPTR);
  2241. return r100_gpu_cp_is_lockup(rdev, lockup, ring);
  2242. }
  2243. static int evergreen_gpu_soft_reset(struct radeon_device *rdev)
  2244. {
  2245. struct evergreen_mc_save save;
  2246. u32 grbm_reset = 0;
  2247. if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
  2248. return 0;
  2249. dev_info(rdev->dev, "GPU softreset \n");
  2250. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  2251. RREG32(GRBM_STATUS));
  2252. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  2253. RREG32(GRBM_STATUS_SE0));
  2254. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  2255. RREG32(GRBM_STATUS_SE1));
  2256. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  2257. RREG32(SRBM_STATUS));
  2258. evergreen_mc_stop(rdev, &save);
  2259. if (evergreen_mc_wait_for_idle(rdev)) {
  2260. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2261. }
  2262. /* Disable CP parsing/prefetching */
  2263. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  2264. /* reset all the gfx blocks */
  2265. grbm_reset = (SOFT_RESET_CP |
  2266. SOFT_RESET_CB |
  2267. SOFT_RESET_DB |
  2268. SOFT_RESET_PA |
  2269. SOFT_RESET_SC |
  2270. SOFT_RESET_SPI |
  2271. SOFT_RESET_SH |
  2272. SOFT_RESET_SX |
  2273. SOFT_RESET_TC |
  2274. SOFT_RESET_TA |
  2275. SOFT_RESET_VC |
  2276. SOFT_RESET_VGT);
  2277. dev_info(rdev->dev, " GRBM_SOFT_RESET=0x%08X\n", grbm_reset);
  2278. WREG32(GRBM_SOFT_RESET, grbm_reset);
  2279. (void)RREG32(GRBM_SOFT_RESET);
  2280. udelay(50);
  2281. WREG32(GRBM_SOFT_RESET, 0);
  2282. (void)RREG32(GRBM_SOFT_RESET);
  2283. /* Wait a little for things to settle down */
  2284. udelay(50);
  2285. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  2286. RREG32(GRBM_STATUS));
  2287. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  2288. RREG32(GRBM_STATUS_SE0));
  2289. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  2290. RREG32(GRBM_STATUS_SE1));
  2291. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  2292. RREG32(SRBM_STATUS));
  2293. evergreen_mc_resume(rdev, &save);
  2294. return 0;
  2295. }
  2296. int evergreen_asic_reset(struct radeon_device *rdev)
  2297. {
  2298. return evergreen_gpu_soft_reset(rdev);
  2299. }
  2300. /* Interrupts */
  2301. u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
  2302. {
  2303. switch (crtc) {
  2304. case 0:
  2305. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC0_REGISTER_OFFSET);
  2306. case 1:
  2307. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC1_REGISTER_OFFSET);
  2308. case 2:
  2309. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC2_REGISTER_OFFSET);
  2310. case 3:
  2311. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC3_REGISTER_OFFSET);
  2312. case 4:
  2313. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC4_REGISTER_OFFSET);
  2314. case 5:
  2315. return RREG32(CRTC_STATUS_FRAME_COUNT + EVERGREEN_CRTC5_REGISTER_OFFSET);
  2316. default:
  2317. return 0;
  2318. }
  2319. }
  2320. void evergreen_disable_interrupt_state(struct radeon_device *rdev)
  2321. {
  2322. u32 tmp;
  2323. if (rdev->family >= CHIP_CAYMAN) {
  2324. cayman_cp_int_cntl_setup(rdev, 0,
  2325. CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  2326. cayman_cp_int_cntl_setup(rdev, 1, 0);
  2327. cayman_cp_int_cntl_setup(rdev, 2, 0);
  2328. } else
  2329. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  2330. WREG32(GRBM_INT_CNTL, 0);
  2331. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  2332. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  2333. if (rdev->num_crtc >= 4) {
  2334. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  2335. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  2336. }
  2337. if (rdev->num_crtc >= 6) {
  2338. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  2339. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  2340. }
  2341. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  2342. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  2343. if (rdev->num_crtc >= 4) {
  2344. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  2345. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  2346. }
  2347. if (rdev->num_crtc >= 6) {
  2348. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  2349. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  2350. }
  2351. /* only one DAC on DCE6 */
  2352. if (!ASIC_IS_DCE6(rdev))
  2353. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  2354. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  2355. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2356. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2357. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2358. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2359. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2360. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2361. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2362. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2363. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2364. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2365. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2366. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2367. }
  2368. int evergreen_irq_set(struct radeon_device *rdev)
  2369. {
  2370. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  2371. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  2372. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  2373. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  2374. u32 grbm_int_cntl = 0;
  2375. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  2376. if (!rdev->irq.installed) {
  2377. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  2378. return -EINVAL;
  2379. }
  2380. /* don't enable anything if the ih is disabled */
  2381. if (!rdev->ih.enabled) {
  2382. r600_disable_interrupts(rdev);
  2383. /* force the active interrupt state to all disabled */
  2384. evergreen_disable_interrupt_state(rdev);
  2385. return 0;
  2386. }
  2387. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2388. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2389. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2390. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2391. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2392. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2393. if (rdev->family >= CHIP_CAYMAN) {
  2394. /* enable CP interrupts on all rings */
  2395. if (rdev->irq.sw_int[RADEON_RING_TYPE_GFX_INDEX]) {
  2396. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  2397. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  2398. }
  2399. if (rdev->irq.sw_int[CAYMAN_RING_TYPE_CP1_INDEX]) {
  2400. DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
  2401. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  2402. }
  2403. if (rdev->irq.sw_int[CAYMAN_RING_TYPE_CP2_INDEX]) {
  2404. DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
  2405. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  2406. }
  2407. } else {
  2408. if (rdev->irq.sw_int[RADEON_RING_TYPE_GFX_INDEX]) {
  2409. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  2410. cp_int_cntl |= RB_INT_ENABLE;
  2411. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  2412. }
  2413. }
  2414. if (rdev->irq.crtc_vblank_int[0] ||
  2415. rdev->irq.pflip[0]) {
  2416. DRM_DEBUG("evergreen_irq_set: vblank 0\n");
  2417. crtc1 |= VBLANK_INT_MASK;
  2418. }
  2419. if (rdev->irq.crtc_vblank_int[1] ||
  2420. rdev->irq.pflip[1]) {
  2421. DRM_DEBUG("evergreen_irq_set: vblank 1\n");
  2422. crtc2 |= VBLANK_INT_MASK;
  2423. }
  2424. if (rdev->irq.crtc_vblank_int[2] ||
  2425. rdev->irq.pflip[2]) {
  2426. DRM_DEBUG("evergreen_irq_set: vblank 2\n");
  2427. crtc3 |= VBLANK_INT_MASK;
  2428. }
  2429. if (rdev->irq.crtc_vblank_int[3] ||
  2430. rdev->irq.pflip[3]) {
  2431. DRM_DEBUG("evergreen_irq_set: vblank 3\n");
  2432. crtc4 |= VBLANK_INT_MASK;
  2433. }
  2434. if (rdev->irq.crtc_vblank_int[4] ||
  2435. rdev->irq.pflip[4]) {
  2436. DRM_DEBUG("evergreen_irq_set: vblank 4\n");
  2437. crtc5 |= VBLANK_INT_MASK;
  2438. }
  2439. if (rdev->irq.crtc_vblank_int[5] ||
  2440. rdev->irq.pflip[5]) {
  2441. DRM_DEBUG("evergreen_irq_set: vblank 5\n");
  2442. crtc6 |= VBLANK_INT_MASK;
  2443. }
  2444. if (rdev->irq.hpd[0]) {
  2445. DRM_DEBUG("evergreen_irq_set: hpd 1\n");
  2446. hpd1 |= DC_HPDx_INT_EN;
  2447. }
  2448. if (rdev->irq.hpd[1]) {
  2449. DRM_DEBUG("evergreen_irq_set: hpd 2\n");
  2450. hpd2 |= DC_HPDx_INT_EN;
  2451. }
  2452. if (rdev->irq.hpd[2]) {
  2453. DRM_DEBUG("evergreen_irq_set: hpd 3\n");
  2454. hpd3 |= DC_HPDx_INT_EN;
  2455. }
  2456. if (rdev->irq.hpd[3]) {
  2457. DRM_DEBUG("evergreen_irq_set: hpd 4\n");
  2458. hpd4 |= DC_HPDx_INT_EN;
  2459. }
  2460. if (rdev->irq.hpd[4]) {
  2461. DRM_DEBUG("evergreen_irq_set: hpd 5\n");
  2462. hpd5 |= DC_HPDx_INT_EN;
  2463. }
  2464. if (rdev->irq.hpd[5]) {
  2465. DRM_DEBUG("evergreen_irq_set: hpd 6\n");
  2466. hpd6 |= DC_HPDx_INT_EN;
  2467. }
  2468. if (rdev->irq.gui_idle) {
  2469. DRM_DEBUG("gui idle\n");
  2470. grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
  2471. }
  2472. if (rdev->family >= CHIP_CAYMAN) {
  2473. cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
  2474. cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
  2475. cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
  2476. } else
  2477. WREG32(CP_INT_CNTL, cp_int_cntl);
  2478. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  2479. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  2480. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  2481. if (rdev->num_crtc >= 4) {
  2482. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  2483. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  2484. }
  2485. if (rdev->num_crtc >= 6) {
  2486. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  2487. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  2488. }
  2489. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  2490. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  2491. if (rdev->num_crtc >= 4) {
  2492. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  2493. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  2494. }
  2495. if (rdev->num_crtc >= 6) {
  2496. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  2497. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  2498. }
  2499. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  2500. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  2501. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  2502. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  2503. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  2504. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  2505. return 0;
  2506. }
  2507. static void evergreen_irq_ack(struct radeon_device *rdev)
  2508. {
  2509. u32 tmp;
  2510. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  2511. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  2512. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  2513. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  2514. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  2515. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  2516. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  2517. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  2518. if (rdev->num_crtc >= 4) {
  2519. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  2520. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  2521. }
  2522. if (rdev->num_crtc >= 6) {
  2523. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  2524. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  2525. }
  2526. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  2527. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2528. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  2529. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2530. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  2531. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  2532. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  2533. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  2534. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  2535. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  2536. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  2537. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  2538. if (rdev->num_crtc >= 4) {
  2539. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  2540. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2541. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  2542. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2543. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  2544. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  2545. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  2546. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  2547. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  2548. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  2549. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  2550. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  2551. }
  2552. if (rdev->num_crtc >= 6) {
  2553. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  2554. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2555. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  2556. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  2557. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  2558. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  2559. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  2560. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  2561. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  2562. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  2563. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  2564. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  2565. }
  2566. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  2567. tmp = RREG32(DC_HPD1_INT_CONTROL);
  2568. tmp |= DC_HPDx_INT_ACK;
  2569. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2570. }
  2571. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  2572. tmp = RREG32(DC_HPD2_INT_CONTROL);
  2573. tmp |= DC_HPDx_INT_ACK;
  2574. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2575. }
  2576. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  2577. tmp = RREG32(DC_HPD3_INT_CONTROL);
  2578. tmp |= DC_HPDx_INT_ACK;
  2579. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2580. }
  2581. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  2582. tmp = RREG32(DC_HPD4_INT_CONTROL);
  2583. tmp |= DC_HPDx_INT_ACK;
  2584. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2585. }
  2586. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  2587. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2588. tmp |= DC_HPDx_INT_ACK;
  2589. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2590. }
  2591. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  2592. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2593. tmp |= DC_HPDx_INT_ACK;
  2594. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2595. }
  2596. }
  2597. void evergreen_irq_disable(struct radeon_device *rdev)
  2598. {
  2599. r600_disable_interrupts(rdev);
  2600. /* Wait and acknowledge irq */
  2601. mdelay(1);
  2602. evergreen_irq_ack(rdev);
  2603. evergreen_disable_interrupt_state(rdev);
  2604. }
  2605. void evergreen_irq_suspend(struct radeon_device *rdev)
  2606. {
  2607. evergreen_irq_disable(rdev);
  2608. r600_rlc_stop(rdev);
  2609. }
  2610. static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
  2611. {
  2612. u32 wptr, tmp;
  2613. if (rdev->wb.enabled)
  2614. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  2615. else
  2616. wptr = RREG32(IH_RB_WPTR);
  2617. if (wptr & RB_OVERFLOW) {
  2618. /* When a ring buffer overflow happen start parsing interrupt
  2619. * from the last not overwritten vector (wptr + 16). Hopefully
  2620. * this should allow us to catchup.
  2621. */
  2622. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  2623. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  2624. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  2625. tmp = RREG32(IH_RB_CNTL);
  2626. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  2627. WREG32(IH_RB_CNTL, tmp);
  2628. }
  2629. return (wptr & rdev->ih.ptr_mask);
  2630. }
  2631. int evergreen_irq_process(struct radeon_device *rdev)
  2632. {
  2633. u32 wptr;
  2634. u32 rptr;
  2635. u32 src_id, src_data;
  2636. u32 ring_index;
  2637. unsigned long flags;
  2638. bool queue_hotplug = false;
  2639. if (!rdev->ih.enabled || rdev->shutdown)
  2640. return IRQ_NONE;
  2641. wptr = evergreen_get_ih_wptr(rdev);
  2642. rptr = rdev->ih.rptr;
  2643. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  2644. spin_lock_irqsave(&rdev->ih.lock, flags);
  2645. if (rptr == wptr) {
  2646. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2647. return IRQ_NONE;
  2648. }
  2649. restart_ih:
  2650. /* Order reading of wptr vs. reading of IH ring data */
  2651. rmb();
  2652. /* display interrupts */
  2653. evergreen_irq_ack(rdev);
  2654. rdev->ih.wptr = wptr;
  2655. while (rptr != wptr) {
  2656. /* wptr/rptr are in bytes! */
  2657. ring_index = rptr / 4;
  2658. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  2659. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  2660. switch (src_id) {
  2661. case 1: /* D1 vblank/vline */
  2662. switch (src_data) {
  2663. case 0: /* D1 vblank */
  2664. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  2665. if (rdev->irq.crtc_vblank_int[0]) {
  2666. drm_handle_vblank(rdev->ddev, 0);
  2667. rdev->pm.vblank_sync = true;
  2668. wake_up(&rdev->irq.vblank_queue);
  2669. }
  2670. if (rdev->irq.pflip[0])
  2671. radeon_crtc_handle_flip(rdev, 0);
  2672. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  2673. DRM_DEBUG("IH: D1 vblank\n");
  2674. }
  2675. break;
  2676. case 1: /* D1 vline */
  2677. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  2678. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  2679. DRM_DEBUG("IH: D1 vline\n");
  2680. }
  2681. break;
  2682. default:
  2683. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2684. break;
  2685. }
  2686. break;
  2687. case 2: /* D2 vblank/vline */
  2688. switch (src_data) {
  2689. case 0: /* D2 vblank */
  2690. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  2691. if (rdev->irq.crtc_vblank_int[1]) {
  2692. drm_handle_vblank(rdev->ddev, 1);
  2693. rdev->pm.vblank_sync = true;
  2694. wake_up(&rdev->irq.vblank_queue);
  2695. }
  2696. if (rdev->irq.pflip[1])
  2697. radeon_crtc_handle_flip(rdev, 1);
  2698. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  2699. DRM_DEBUG("IH: D2 vblank\n");
  2700. }
  2701. break;
  2702. case 1: /* D2 vline */
  2703. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  2704. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  2705. DRM_DEBUG("IH: D2 vline\n");
  2706. }
  2707. break;
  2708. default:
  2709. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2710. break;
  2711. }
  2712. break;
  2713. case 3: /* D3 vblank/vline */
  2714. switch (src_data) {
  2715. case 0: /* D3 vblank */
  2716. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  2717. if (rdev->irq.crtc_vblank_int[2]) {
  2718. drm_handle_vblank(rdev->ddev, 2);
  2719. rdev->pm.vblank_sync = true;
  2720. wake_up(&rdev->irq.vblank_queue);
  2721. }
  2722. if (rdev->irq.pflip[2])
  2723. radeon_crtc_handle_flip(rdev, 2);
  2724. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  2725. DRM_DEBUG("IH: D3 vblank\n");
  2726. }
  2727. break;
  2728. case 1: /* D3 vline */
  2729. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  2730. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  2731. DRM_DEBUG("IH: D3 vline\n");
  2732. }
  2733. break;
  2734. default:
  2735. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2736. break;
  2737. }
  2738. break;
  2739. case 4: /* D4 vblank/vline */
  2740. switch (src_data) {
  2741. case 0: /* D4 vblank */
  2742. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  2743. if (rdev->irq.crtc_vblank_int[3]) {
  2744. drm_handle_vblank(rdev->ddev, 3);
  2745. rdev->pm.vblank_sync = true;
  2746. wake_up(&rdev->irq.vblank_queue);
  2747. }
  2748. if (rdev->irq.pflip[3])
  2749. radeon_crtc_handle_flip(rdev, 3);
  2750. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  2751. DRM_DEBUG("IH: D4 vblank\n");
  2752. }
  2753. break;
  2754. case 1: /* D4 vline */
  2755. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  2756. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  2757. DRM_DEBUG("IH: D4 vline\n");
  2758. }
  2759. break;
  2760. default:
  2761. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2762. break;
  2763. }
  2764. break;
  2765. case 5: /* D5 vblank/vline */
  2766. switch (src_data) {
  2767. case 0: /* D5 vblank */
  2768. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  2769. if (rdev->irq.crtc_vblank_int[4]) {
  2770. drm_handle_vblank(rdev->ddev, 4);
  2771. rdev->pm.vblank_sync = true;
  2772. wake_up(&rdev->irq.vblank_queue);
  2773. }
  2774. if (rdev->irq.pflip[4])
  2775. radeon_crtc_handle_flip(rdev, 4);
  2776. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  2777. DRM_DEBUG("IH: D5 vblank\n");
  2778. }
  2779. break;
  2780. case 1: /* D5 vline */
  2781. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  2782. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  2783. DRM_DEBUG("IH: D5 vline\n");
  2784. }
  2785. break;
  2786. default:
  2787. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2788. break;
  2789. }
  2790. break;
  2791. case 6: /* D6 vblank/vline */
  2792. switch (src_data) {
  2793. case 0: /* D6 vblank */
  2794. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  2795. if (rdev->irq.crtc_vblank_int[5]) {
  2796. drm_handle_vblank(rdev->ddev, 5);
  2797. rdev->pm.vblank_sync = true;
  2798. wake_up(&rdev->irq.vblank_queue);
  2799. }
  2800. if (rdev->irq.pflip[5])
  2801. radeon_crtc_handle_flip(rdev, 5);
  2802. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  2803. DRM_DEBUG("IH: D6 vblank\n");
  2804. }
  2805. break;
  2806. case 1: /* D6 vline */
  2807. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  2808. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  2809. DRM_DEBUG("IH: D6 vline\n");
  2810. }
  2811. break;
  2812. default:
  2813. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2814. break;
  2815. }
  2816. break;
  2817. case 42: /* HPD hotplug */
  2818. switch (src_data) {
  2819. case 0:
  2820. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  2821. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  2822. queue_hotplug = true;
  2823. DRM_DEBUG("IH: HPD1\n");
  2824. }
  2825. break;
  2826. case 1:
  2827. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  2828. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  2829. queue_hotplug = true;
  2830. DRM_DEBUG("IH: HPD2\n");
  2831. }
  2832. break;
  2833. case 2:
  2834. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  2835. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  2836. queue_hotplug = true;
  2837. DRM_DEBUG("IH: HPD3\n");
  2838. }
  2839. break;
  2840. case 3:
  2841. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  2842. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  2843. queue_hotplug = true;
  2844. DRM_DEBUG("IH: HPD4\n");
  2845. }
  2846. break;
  2847. case 4:
  2848. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  2849. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  2850. queue_hotplug = true;
  2851. DRM_DEBUG("IH: HPD5\n");
  2852. }
  2853. break;
  2854. case 5:
  2855. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  2856. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  2857. queue_hotplug = true;
  2858. DRM_DEBUG("IH: HPD6\n");
  2859. }
  2860. break;
  2861. default:
  2862. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2863. break;
  2864. }
  2865. break;
  2866. case 176: /* CP_INT in ring buffer */
  2867. case 177: /* CP_INT in IB1 */
  2868. case 178: /* CP_INT in IB2 */
  2869. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  2870. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2871. break;
  2872. case 181: /* CP EOP event */
  2873. DRM_DEBUG("IH: CP EOP\n");
  2874. if (rdev->family >= CHIP_CAYMAN) {
  2875. switch (src_data) {
  2876. case 0:
  2877. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2878. break;
  2879. case 1:
  2880. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  2881. break;
  2882. case 2:
  2883. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  2884. break;
  2885. }
  2886. } else
  2887. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2888. break;
  2889. case 233: /* GUI IDLE */
  2890. DRM_DEBUG("IH: GUI idle\n");
  2891. rdev->pm.gui_idle = true;
  2892. wake_up(&rdev->irq.idle_queue);
  2893. break;
  2894. default:
  2895. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2896. break;
  2897. }
  2898. /* wptr/rptr are in bytes! */
  2899. rptr += 16;
  2900. rptr &= rdev->ih.ptr_mask;
  2901. }
  2902. /* make sure wptr hasn't changed while processing */
  2903. wptr = evergreen_get_ih_wptr(rdev);
  2904. if (wptr != rdev->ih.wptr)
  2905. goto restart_ih;
  2906. if (queue_hotplug)
  2907. schedule_work(&rdev->hotplug_work);
  2908. rdev->ih.rptr = rptr;
  2909. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  2910. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2911. return IRQ_HANDLED;
  2912. }
  2913. static int evergreen_startup(struct radeon_device *rdev)
  2914. {
  2915. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2916. int r;
  2917. /* enable pcie gen2 link */
  2918. evergreen_pcie_gen2_enable(rdev);
  2919. evergreen_mc_program(rdev);
  2920. if (ASIC_IS_DCE5(rdev)) {
  2921. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  2922. r = ni_init_microcode(rdev);
  2923. if (r) {
  2924. DRM_ERROR("Failed to load firmware!\n");
  2925. return r;
  2926. }
  2927. }
  2928. r = ni_mc_load_microcode(rdev);
  2929. if (r) {
  2930. DRM_ERROR("Failed to load MC firmware!\n");
  2931. return r;
  2932. }
  2933. } else {
  2934. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  2935. r = r600_init_microcode(rdev);
  2936. if (r) {
  2937. DRM_ERROR("Failed to load firmware!\n");
  2938. return r;
  2939. }
  2940. }
  2941. }
  2942. r = r600_vram_scratch_init(rdev);
  2943. if (r)
  2944. return r;
  2945. if (rdev->flags & RADEON_IS_AGP) {
  2946. evergreen_agp_enable(rdev);
  2947. } else {
  2948. r = evergreen_pcie_gart_enable(rdev);
  2949. if (r)
  2950. return r;
  2951. }
  2952. evergreen_gpu_init(rdev);
  2953. r = evergreen_blit_init(rdev);
  2954. if (r) {
  2955. r600_blit_fini(rdev);
  2956. rdev->asic->copy.copy = NULL;
  2957. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  2958. }
  2959. /* allocate wb buffer */
  2960. r = radeon_wb_init(rdev);
  2961. if (r)
  2962. return r;
  2963. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  2964. if (r) {
  2965. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  2966. return r;
  2967. }
  2968. /* Enable IRQ */
  2969. if (!rdev->irq.installed) {
  2970. r = radeon_irq_kms_init(rdev);
  2971. if (r)
  2972. return r;
  2973. }
  2974. r = r600_irq_init(rdev);
  2975. if (r) {
  2976. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  2977. radeon_irq_kms_fini(rdev);
  2978. return r;
  2979. }
  2980. evergreen_irq_set(rdev);
  2981. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  2982. R600_CP_RB_RPTR, R600_CP_RB_WPTR,
  2983. 0, 0xfffff, RADEON_CP_PACKET2);
  2984. if (r)
  2985. return r;
  2986. r = evergreen_cp_load_microcode(rdev);
  2987. if (r)
  2988. return r;
  2989. r = evergreen_cp_resume(rdev);
  2990. if (r)
  2991. return r;
  2992. r = radeon_ib_pool_start(rdev);
  2993. if (r)
  2994. return r;
  2995. r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2996. if (r) {
  2997. DRM_ERROR("radeon: failed testing IB (%d).\n", r);
  2998. rdev->accel_working = false;
  2999. return r;
  3000. }
  3001. r = r600_audio_init(rdev);
  3002. if (r) {
  3003. DRM_ERROR("radeon: audio init failed\n");
  3004. return r;
  3005. }
  3006. return 0;
  3007. }
  3008. int evergreen_resume(struct radeon_device *rdev)
  3009. {
  3010. int r;
  3011. /* reset the asic, the gfx blocks are often in a bad state
  3012. * after the driver is unloaded or after a resume
  3013. */
  3014. if (radeon_asic_reset(rdev))
  3015. dev_warn(rdev->dev, "GPU reset failed !\n");
  3016. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  3017. * posting will perform necessary task to bring back GPU into good
  3018. * shape.
  3019. */
  3020. /* post card */
  3021. atom_asic_init(rdev->mode_info.atom_context);
  3022. rdev->accel_working = true;
  3023. r = evergreen_startup(rdev);
  3024. if (r) {
  3025. DRM_ERROR("evergreen startup failed on resume\n");
  3026. rdev->accel_working = false;
  3027. return r;
  3028. }
  3029. return r;
  3030. }
  3031. int evergreen_suspend(struct radeon_device *rdev)
  3032. {
  3033. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  3034. r600_audio_fini(rdev);
  3035. /* FIXME: we should wait for ring to be empty */
  3036. radeon_ib_pool_suspend(rdev);
  3037. r600_blit_suspend(rdev);
  3038. r700_cp_stop(rdev);
  3039. ring->ready = false;
  3040. evergreen_irq_suspend(rdev);
  3041. radeon_wb_disable(rdev);
  3042. evergreen_pcie_gart_disable(rdev);
  3043. return 0;
  3044. }
  3045. /* Plan is to move initialization in that function and use
  3046. * helper function so that radeon_device_init pretty much
  3047. * do nothing more than calling asic specific function. This
  3048. * should also allow to remove a bunch of callback function
  3049. * like vram_info.
  3050. */
  3051. int evergreen_init(struct radeon_device *rdev)
  3052. {
  3053. int r;
  3054. /* This don't do much */
  3055. r = radeon_gem_init(rdev);
  3056. if (r)
  3057. return r;
  3058. /* Read BIOS */
  3059. if (!radeon_get_bios(rdev)) {
  3060. if (ASIC_IS_AVIVO(rdev))
  3061. return -EINVAL;
  3062. }
  3063. /* Must be an ATOMBIOS */
  3064. if (!rdev->is_atom_bios) {
  3065. dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
  3066. return -EINVAL;
  3067. }
  3068. r = radeon_atombios_init(rdev);
  3069. if (r)
  3070. return r;
  3071. /* reset the asic, the gfx blocks are often in a bad state
  3072. * after the driver is unloaded or after a resume
  3073. */
  3074. if (radeon_asic_reset(rdev))
  3075. dev_warn(rdev->dev, "GPU reset failed !\n");
  3076. /* Post card if necessary */
  3077. if (!radeon_card_posted(rdev)) {
  3078. if (!rdev->bios) {
  3079. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  3080. return -EINVAL;
  3081. }
  3082. DRM_INFO("GPU not posted. posting now...\n");
  3083. atom_asic_init(rdev->mode_info.atom_context);
  3084. }
  3085. /* Initialize scratch registers */
  3086. r600_scratch_init(rdev);
  3087. /* Initialize surface registers */
  3088. radeon_surface_init(rdev);
  3089. /* Initialize clocks */
  3090. radeon_get_clock_info(rdev->ddev);
  3091. /* Fence driver */
  3092. r = radeon_fence_driver_init(rdev);
  3093. if (r)
  3094. return r;
  3095. /* initialize AGP */
  3096. if (rdev->flags & RADEON_IS_AGP) {
  3097. r = radeon_agp_init(rdev);
  3098. if (r)
  3099. radeon_agp_disable(rdev);
  3100. }
  3101. /* initialize memory controller */
  3102. r = evergreen_mc_init(rdev);
  3103. if (r)
  3104. return r;
  3105. /* Memory manager */
  3106. r = radeon_bo_init(rdev);
  3107. if (r)
  3108. return r;
  3109. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  3110. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  3111. rdev->ih.ring_obj = NULL;
  3112. r600_ih_ring_init(rdev, 64 * 1024);
  3113. r = r600_pcie_gart_init(rdev);
  3114. if (r)
  3115. return r;
  3116. r = radeon_ib_pool_init(rdev);
  3117. rdev->accel_working = true;
  3118. if (r) {
  3119. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  3120. rdev->accel_working = false;
  3121. }
  3122. r = evergreen_startup(rdev);
  3123. if (r) {
  3124. dev_err(rdev->dev, "disabling GPU acceleration\n");
  3125. r700_cp_fini(rdev);
  3126. r600_irq_fini(rdev);
  3127. radeon_wb_fini(rdev);
  3128. r100_ib_fini(rdev);
  3129. radeon_irq_kms_fini(rdev);
  3130. evergreen_pcie_gart_fini(rdev);
  3131. rdev->accel_working = false;
  3132. }
  3133. /* Don't start up if the MC ucode is missing on BTC parts.
  3134. * The default clocks and voltages before the MC ucode
  3135. * is loaded are not suffient for advanced operations.
  3136. */
  3137. if (ASIC_IS_DCE5(rdev)) {
  3138. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  3139. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  3140. return -EINVAL;
  3141. }
  3142. }
  3143. /* posting read */
  3144. RREG32(SRBM_STATUS);
  3145. return 0;
  3146. }
  3147. void evergreen_fini(struct radeon_device *rdev)
  3148. {
  3149. r600_audio_fini(rdev);
  3150. r600_blit_fini(rdev);
  3151. r700_cp_fini(rdev);
  3152. r600_irq_fini(rdev);
  3153. radeon_wb_fini(rdev);
  3154. r100_ib_fini(rdev);
  3155. radeon_irq_kms_fini(rdev);
  3156. evergreen_pcie_gart_fini(rdev);
  3157. r600_vram_scratch_fini(rdev);
  3158. radeon_gem_fini(rdev);
  3159. radeon_semaphore_driver_fini(rdev);
  3160. radeon_fence_driver_fini(rdev);
  3161. radeon_agp_fini(rdev);
  3162. radeon_bo_fini(rdev);
  3163. radeon_atombios_fini(rdev);
  3164. kfree(rdev->bios);
  3165. rdev->bios = NULL;
  3166. }
  3167. void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
  3168. {
  3169. u32 link_width_cntl, speed_cntl;
  3170. if (radeon_pcie_gen2 == 0)
  3171. return;
  3172. if (rdev->flags & RADEON_IS_IGP)
  3173. return;
  3174. if (!(rdev->flags & RADEON_IS_PCIE))
  3175. return;
  3176. /* x2 cards have a special sequence */
  3177. if (ASIC_IS_X2(rdev))
  3178. return;
  3179. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3180. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  3181. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  3182. link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
  3183. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  3184. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3185. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3186. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  3187. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3188. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3189. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  3190. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3191. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3192. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  3193. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3194. speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
  3195. speed_cntl |= LC_GEN2_EN_STRAP;
  3196. WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
  3197. } else {
  3198. link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
  3199. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  3200. if (1)
  3201. link_width_cntl |= LC_UPCONFIGURE_DIS;
  3202. else
  3203. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  3204. WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  3205. }
  3206. }