rv770.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/firmware.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <drm/drmP.h>
  32. #include "radeon.h"
  33. #include "radeon_asic.h"
  34. #include <drm/radeon_drm.h>
  35. #include "rv770d.h"
  36. #include "atom.h"
  37. #include "avivod.h"
  38. #define R700_PFP_UCODE_SIZE 848
  39. #define R700_PM4_UCODE_SIZE 1360
  40. static void rv770_gpu_init(struct radeon_device *rdev);
  41. void rv770_fini(struct radeon_device *rdev);
  42. static void rv770_pcie_gen2_enable(struct radeon_device *rdev);
  43. int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk);
  44. int rv770_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  45. {
  46. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  47. int r;
  48. /* RV740 uses evergreen uvd clk programming */
  49. if (rdev->family == CHIP_RV740)
  50. return evergreen_set_uvd_clocks(rdev, vclk, dclk);
  51. /* bypass vclk and dclk with bclk */
  52. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  53. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  54. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  55. if (!vclk || !dclk) {
  56. /* keep the Bypass mode, put PLL to sleep */
  57. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  58. return 0;
  59. }
  60. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 50000, 160000,
  61. 43663, 0x03FFFFFE, 1, 30, ~0,
  62. &fb_div, &vclk_div, &dclk_div);
  63. if (r)
  64. return r;
  65. fb_div |= 1;
  66. vclk_div -= 1;
  67. dclk_div -= 1;
  68. /* set UPLL_FB_DIV to 0x50000 */
  69. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(0x50000), ~UPLL_FB_DIV_MASK);
  70. /* deassert UPLL_RESET and UPLL_SLEEP */
  71. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~(UPLL_RESET_MASK | UPLL_SLEEP_MASK));
  72. /* assert BYPASS EN and FB_DIV[0] <- ??? why? */
  73. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  74. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(1), ~UPLL_FB_DIV(1));
  75. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  76. if (r)
  77. return r;
  78. /* assert PLL_RESET */
  79. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  80. /* set the required FB_DIV, REF_DIV, Post divder values */
  81. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_REF_DIV(1), ~UPLL_REF_DIV_MASK);
  82. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  83. UPLL_SW_HILEN(vclk_div >> 1) |
  84. UPLL_SW_LOLEN((vclk_div >> 1) + (vclk_div & 1)) |
  85. UPLL_SW_HILEN2(dclk_div >> 1) |
  86. UPLL_SW_LOLEN2((dclk_div >> 1) + (dclk_div & 1)),
  87. ~UPLL_SW_MASK);
  88. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div),
  89. ~UPLL_FB_DIV_MASK);
  90. /* give the PLL some time to settle */
  91. mdelay(15);
  92. /* deassert PLL_RESET */
  93. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  94. mdelay(15);
  95. /* deassert BYPASS EN and FB_DIV[0] <- ??? why? */
  96. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  97. WREG32_P(CG_UPLL_FUNC_CNTL_3, 0, ~UPLL_FB_DIV(1));
  98. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  99. if (r)
  100. return r;
  101. /* switch VCLK and DCLK selection */
  102. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  103. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  104. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  105. mdelay(100);
  106. return 0;
  107. }
  108. static const u32 r7xx_golden_registers[] =
  109. {
  110. 0x8d00, 0xffffffff, 0x0e0e0074,
  111. 0x8d04, 0xffffffff, 0x013a2b34,
  112. 0x9508, 0xffffffff, 0x00000002,
  113. 0x8b20, 0xffffffff, 0,
  114. 0x88c4, 0xffffffff, 0x000000c2,
  115. 0x28350, 0xffffffff, 0,
  116. 0x9058, 0xffffffff, 0x0fffc40f,
  117. 0x240c, 0xffffffff, 0x00000380,
  118. 0x733c, 0xffffffff, 0x00000002,
  119. 0x2650, 0x00040000, 0,
  120. 0x20bc, 0x00040000, 0,
  121. 0x7300, 0xffffffff, 0x001000f0
  122. };
  123. static const u32 r7xx_golden_dyn_gpr_registers[] =
  124. {
  125. 0x8db0, 0xffffffff, 0x98989898,
  126. 0x8db4, 0xffffffff, 0x98989898,
  127. 0x8db8, 0xffffffff, 0x98989898,
  128. 0x8dbc, 0xffffffff, 0x98989898,
  129. 0x8dc0, 0xffffffff, 0x98989898,
  130. 0x8dc4, 0xffffffff, 0x98989898,
  131. 0x8dc8, 0xffffffff, 0x98989898,
  132. 0x8dcc, 0xffffffff, 0x98989898,
  133. 0x88c4, 0xffffffff, 0x00000082
  134. };
  135. static const u32 rv770_golden_registers[] =
  136. {
  137. 0x562c, 0xffffffff, 0,
  138. 0x3f90, 0xffffffff, 0,
  139. 0x9148, 0xffffffff, 0,
  140. 0x3f94, 0xffffffff, 0,
  141. 0x914c, 0xffffffff, 0,
  142. 0x9698, 0x18000000, 0x18000000
  143. };
  144. static const u32 rv770ce_golden_registers[] =
  145. {
  146. 0x562c, 0xffffffff, 0,
  147. 0x3f90, 0xffffffff, 0x00cc0000,
  148. 0x9148, 0xffffffff, 0x00cc0000,
  149. 0x3f94, 0xffffffff, 0x00cc0000,
  150. 0x914c, 0xffffffff, 0x00cc0000,
  151. 0x9b7c, 0xffffffff, 0x00fa0000,
  152. 0x3f8c, 0xffffffff, 0x00fa0000,
  153. 0x9698, 0x18000000, 0x18000000
  154. };
  155. static const u32 rv770_mgcg_init[] =
  156. {
  157. 0x8bcc, 0xffffffff, 0x130300f9,
  158. 0x5448, 0xffffffff, 0x100,
  159. 0x55e4, 0xffffffff, 0x100,
  160. 0x160c, 0xffffffff, 0x100,
  161. 0x5644, 0xffffffff, 0x100,
  162. 0xc164, 0xffffffff, 0x100,
  163. 0x8a18, 0xffffffff, 0x100,
  164. 0x897c, 0xffffffff, 0x8000100,
  165. 0x8b28, 0xffffffff, 0x3c000100,
  166. 0x9144, 0xffffffff, 0x100,
  167. 0x9a1c, 0xffffffff, 0x10000,
  168. 0x9a50, 0xffffffff, 0x100,
  169. 0x9a1c, 0xffffffff, 0x10001,
  170. 0x9a50, 0xffffffff, 0x100,
  171. 0x9a1c, 0xffffffff, 0x10002,
  172. 0x9a50, 0xffffffff, 0x100,
  173. 0x9a1c, 0xffffffff, 0x10003,
  174. 0x9a50, 0xffffffff, 0x100,
  175. 0x9a1c, 0xffffffff, 0x0,
  176. 0x9870, 0xffffffff, 0x100,
  177. 0x8d58, 0xffffffff, 0x100,
  178. 0x9500, 0xffffffff, 0x0,
  179. 0x9510, 0xffffffff, 0x100,
  180. 0x9500, 0xffffffff, 0x1,
  181. 0x9510, 0xffffffff, 0x100,
  182. 0x9500, 0xffffffff, 0x2,
  183. 0x9510, 0xffffffff, 0x100,
  184. 0x9500, 0xffffffff, 0x3,
  185. 0x9510, 0xffffffff, 0x100,
  186. 0x9500, 0xffffffff, 0x4,
  187. 0x9510, 0xffffffff, 0x100,
  188. 0x9500, 0xffffffff, 0x5,
  189. 0x9510, 0xffffffff, 0x100,
  190. 0x9500, 0xffffffff, 0x6,
  191. 0x9510, 0xffffffff, 0x100,
  192. 0x9500, 0xffffffff, 0x7,
  193. 0x9510, 0xffffffff, 0x100,
  194. 0x9500, 0xffffffff, 0x8,
  195. 0x9510, 0xffffffff, 0x100,
  196. 0x9500, 0xffffffff, 0x9,
  197. 0x9510, 0xffffffff, 0x100,
  198. 0x9500, 0xffffffff, 0x8000,
  199. 0x9490, 0xffffffff, 0x0,
  200. 0x949c, 0xffffffff, 0x100,
  201. 0x9490, 0xffffffff, 0x1,
  202. 0x949c, 0xffffffff, 0x100,
  203. 0x9490, 0xffffffff, 0x2,
  204. 0x949c, 0xffffffff, 0x100,
  205. 0x9490, 0xffffffff, 0x3,
  206. 0x949c, 0xffffffff, 0x100,
  207. 0x9490, 0xffffffff, 0x4,
  208. 0x949c, 0xffffffff, 0x100,
  209. 0x9490, 0xffffffff, 0x5,
  210. 0x949c, 0xffffffff, 0x100,
  211. 0x9490, 0xffffffff, 0x6,
  212. 0x949c, 0xffffffff, 0x100,
  213. 0x9490, 0xffffffff, 0x7,
  214. 0x949c, 0xffffffff, 0x100,
  215. 0x9490, 0xffffffff, 0x8,
  216. 0x949c, 0xffffffff, 0x100,
  217. 0x9490, 0xffffffff, 0x9,
  218. 0x949c, 0xffffffff, 0x100,
  219. 0x9490, 0xffffffff, 0x8000,
  220. 0x9604, 0xffffffff, 0x0,
  221. 0x9654, 0xffffffff, 0x100,
  222. 0x9604, 0xffffffff, 0x1,
  223. 0x9654, 0xffffffff, 0x100,
  224. 0x9604, 0xffffffff, 0x2,
  225. 0x9654, 0xffffffff, 0x100,
  226. 0x9604, 0xffffffff, 0x3,
  227. 0x9654, 0xffffffff, 0x100,
  228. 0x9604, 0xffffffff, 0x4,
  229. 0x9654, 0xffffffff, 0x100,
  230. 0x9604, 0xffffffff, 0x5,
  231. 0x9654, 0xffffffff, 0x100,
  232. 0x9604, 0xffffffff, 0x6,
  233. 0x9654, 0xffffffff, 0x100,
  234. 0x9604, 0xffffffff, 0x7,
  235. 0x9654, 0xffffffff, 0x100,
  236. 0x9604, 0xffffffff, 0x8,
  237. 0x9654, 0xffffffff, 0x100,
  238. 0x9604, 0xffffffff, 0x9,
  239. 0x9654, 0xffffffff, 0x100,
  240. 0x9604, 0xffffffff, 0x80000000,
  241. 0x9030, 0xffffffff, 0x100,
  242. 0x9034, 0xffffffff, 0x100,
  243. 0x9038, 0xffffffff, 0x100,
  244. 0x903c, 0xffffffff, 0x100,
  245. 0x9040, 0xffffffff, 0x100,
  246. 0xa200, 0xffffffff, 0x100,
  247. 0xa204, 0xffffffff, 0x100,
  248. 0xa208, 0xffffffff, 0x100,
  249. 0xa20c, 0xffffffff, 0x100,
  250. 0x971c, 0xffffffff, 0x100,
  251. 0x915c, 0xffffffff, 0x00020001,
  252. 0x9160, 0xffffffff, 0x00040003,
  253. 0x916c, 0xffffffff, 0x00060005,
  254. 0x9170, 0xffffffff, 0x00080007,
  255. 0x9174, 0xffffffff, 0x000a0009,
  256. 0x9178, 0xffffffff, 0x000c000b,
  257. 0x917c, 0xffffffff, 0x000e000d,
  258. 0x9180, 0xffffffff, 0x0010000f,
  259. 0x918c, 0xffffffff, 0x00120011,
  260. 0x9190, 0xffffffff, 0x00140013,
  261. 0x9194, 0xffffffff, 0x00020001,
  262. 0x9198, 0xffffffff, 0x00040003,
  263. 0x919c, 0xffffffff, 0x00060005,
  264. 0x91a8, 0xffffffff, 0x00080007,
  265. 0x91ac, 0xffffffff, 0x000a0009,
  266. 0x91b0, 0xffffffff, 0x000c000b,
  267. 0x91b4, 0xffffffff, 0x000e000d,
  268. 0x91b8, 0xffffffff, 0x0010000f,
  269. 0x91c4, 0xffffffff, 0x00120011,
  270. 0x91c8, 0xffffffff, 0x00140013,
  271. 0x91cc, 0xffffffff, 0x00020001,
  272. 0x91d0, 0xffffffff, 0x00040003,
  273. 0x91d4, 0xffffffff, 0x00060005,
  274. 0x91e0, 0xffffffff, 0x00080007,
  275. 0x91e4, 0xffffffff, 0x000a0009,
  276. 0x91e8, 0xffffffff, 0x000c000b,
  277. 0x91ec, 0xffffffff, 0x00020001,
  278. 0x91f0, 0xffffffff, 0x00040003,
  279. 0x91f4, 0xffffffff, 0x00060005,
  280. 0x9200, 0xffffffff, 0x00080007,
  281. 0x9204, 0xffffffff, 0x000a0009,
  282. 0x9208, 0xffffffff, 0x000c000b,
  283. 0x920c, 0xffffffff, 0x000e000d,
  284. 0x9210, 0xffffffff, 0x0010000f,
  285. 0x921c, 0xffffffff, 0x00120011,
  286. 0x9220, 0xffffffff, 0x00140013,
  287. 0x9224, 0xffffffff, 0x00020001,
  288. 0x9228, 0xffffffff, 0x00040003,
  289. 0x922c, 0xffffffff, 0x00060005,
  290. 0x9238, 0xffffffff, 0x00080007,
  291. 0x923c, 0xffffffff, 0x000a0009,
  292. 0x9240, 0xffffffff, 0x000c000b,
  293. 0x9244, 0xffffffff, 0x000e000d,
  294. 0x9248, 0xffffffff, 0x0010000f,
  295. 0x9254, 0xffffffff, 0x00120011,
  296. 0x9258, 0xffffffff, 0x00140013,
  297. 0x925c, 0xffffffff, 0x00020001,
  298. 0x9260, 0xffffffff, 0x00040003,
  299. 0x9264, 0xffffffff, 0x00060005,
  300. 0x9270, 0xffffffff, 0x00080007,
  301. 0x9274, 0xffffffff, 0x000a0009,
  302. 0x9278, 0xffffffff, 0x000c000b,
  303. 0x927c, 0xffffffff, 0x000e000d,
  304. 0x9280, 0xffffffff, 0x0010000f,
  305. 0x928c, 0xffffffff, 0x00120011,
  306. 0x9290, 0xffffffff, 0x00140013,
  307. 0x9294, 0xffffffff, 0x00020001,
  308. 0x929c, 0xffffffff, 0x00040003,
  309. 0x92a0, 0xffffffff, 0x00060005,
  310. 0x92a4, 0xffffffff, 0x00080007
  311. };
  312. static const u32 rv710_golden_registers[] =
  313. {
  314. 0x3f90, 0x00ff0000, 0x00fc0000,
  315. 0x9148, 0x00ff0000, 0x00fc0000,
  316. 0x3f94, 0x00ff0000, 0x00fc0000,
  317. 0x914c, 0x00ff0000, 0x00fc0000,
  318. 0xb4c, 0x00000020, 0x00000020,
  319. 0xa180, 0xffffffff, 0x00003f3f
  320. };
  321. static const u32 rv710_mgcg_init[] =
  322. {
  323. 0x8bcc, 0xffffffff, 0x13030040,
  324. 0x5448, 0xffffffff, 0x100,
  325. 0x55e4, 0xffffffff, 0x100,
  326. 0x160c, 0xffffffff, 0x100,
  327. 0x5644, 0xffffffff, 0x100,
  328. 0xc164, 0xffffffff, 0x100,
  329. 0x8a18, 0xffffffff, 0x100,
  330. 0x897c, 0xffffffff, 0x8000100,
  331. 0x8b28, 0xffffffff, 0x3c000100,
  332. 0x9144, 0xffffffff, 0x100,
  333. 0x9a1c, 0xffffffff, 0x10000,
  334. 0x9a50, 0xffffffff, 0x100,
  335. 0x9a1c, 0xffffffff, 0x0,
  336. 0x9870, 0xffffffff, 0x100,
  337. 0x8d58, 0xffffffff, 0x100,
  338. 0x9500, 0xffffffff, 0x0,
  339. 0x9510, 0xffffffff, 0x100,
  340. 0x9500, 0xffffffff, 0x1,
  341. 0x9510, 0xffffffff, 0x100,
  342. 0x9500, 0xffffffff, 0x8000,
  343. 0x9490, 0xffffffff, 0x0,
  344. 0x949c, 0xffffffff, 0x100,
  345. 0x9490, 0xffffffff, 0x1,
  346. 0x949c, 0xffffffff, 0x100,
  347. 0x9490, 0xffffffff, 0x8000,
  348. 0x9604, 0xffffffff, 0x0,
  349. 0x9654, 0xffffffff, 0x100,
  350. 0x9604, 0xffffffff, 0x1,
  351. 0x9654, 0xffffffff, 0x100,
  352. 0x9604, 0xffffffff, 0x80000000,
  353. 0x9030, 0xffffffff, 0x100,
  354. 0x9034, 0xffffffff, 0x100,
  355. 0x9038, 0xffffffff, 0x100,
  356. 0x903c, 0xffffffff, 0x100,
  357. 0x9040, 0xffffffff, 0x100,
  358. 0xa200, 0xffffffff, 0x100,
  359. 0xa204, 0xffffffff, 0x100,
  360. 0xa208, 0xffffffff, 0x100,
  361. 0xa20c, 0xffffffff, 0x100,
  362. 0x971c, 0xffffffff, 0x100,
  363. 0x915c, 0xffffffff, 0x00020001,
  364. 0x9174, 0xffffffff, 0x00000003,
  365. 0x9178, 0xffffffff, 0x00050001,
  366. 0x917c, 0xffffffff, 0x00030002,
  367. 0x918c, 0xffffffff, 0x00000004,
  368. 0x9190, 0xffffffff, 0x00070006,
  369. 0x9194, 0xffffffff, 0x00050001,
  370. 0x9198, 0xffffffff, 0x00030002,
  371. 0x91a8, 0xffffffff, 0x00000004,
  372. 0x91ac, 0xffffffff, 0x00070006,
  373. 0x91e8, 0xffffffff, 0x00000001,
  374. 0x9294, 0xffffffff, 0x00000001,
  375. 0x929c, 0xffffffff, 0x00000002,
  376. 0x92a0, 0xffffffff, 0x00040003,
  377. 0x9150, 0xffffffff, 0x4d940000
  378. };
  379. static const u32 rv730_golden_registers[] =
  380. {
  381. 0x3f90, 0x00ff0000, 0x00f00000,
  382. 0x9148, 0x00ff0000, 0x00f00000,
  383. 0x3f94, 0x00ff0000, 0x00f00000,
  384. 0x914c, 0x00ff0000, 0x00f00000,
  385. 0x900c, 0xffffffff, 0x003b033f,
  386. 0xb4c, 0x00000020, 0x00000020,
  387. 0xa180, 0xffffffff, 0x00003f3f
  388. };
  389. static const u32 rv730_mgcg_init[] =
  390. {
  391. 0x8bcc, 0xffffffff, 0x130300f9,
  392. 0x5448, 0xffffffff, 0x100,
  393. 0x55e4, 0xffffffff, 0x100,
  394. 0x160c, 0xffffffff, 0x100,
  395. 0x5644, 0xffffffff, 0x100,
  396. 0xc164, 0xffffffff, 0x100,
  397. 0x8a18, 0xffffffff, 0x100,
  398. 0x897c, 0xffffffff, 0x8000100,
  399. 0x8b28, 0xffffffff, 0x3c000100,
  400. 0x9144, 0xffffffff, 0x100,
  401. 0x9a1c, 0xffffffff, 0x10000,
  402. 0x9a50, 0xffffffff, 0x100,
  403. 0x9a1c, 0xffffffff, 0x10001,
  404. 0x9a50, 0xffffffff, 0x100,
  405. 0x9a1c, 0xffffffff, 0x0,
  406. 0x9870, 0xffffffff, 0x100,
  407. 0x8d58, 0xffffffff, 0x100,
  408. 0x9500, 0xffffffff, 0x0,
  409. 0x9510, 0xffffffff, 0x100,
  410. 0x9500, 0xffffffff, 0x1,
  411. 0x9510, 0xffffffff, 0x100,
  412. 0x9500, 0xffffffff, 0x2,
  413. 0x9510, 0xffffffff, 0x100,
  414. 0x9500, 0xffffffff, 0x3,
  415. 0x9510, 0xffffffff, 0x100,
  416. 0x9500, 0xffffffff, 0x4,
  417. 0x9510, 0xffffffff, 0x100,
  418. 0x9500, 0xffffffff, 0x5,
  419. 0x9510, 0xffffffff, 0x100,
  420. 0x9500, 0xffffffff, 0x6,
  421. 0x9510, 0xffffffff, 0x100,
  422. 0x9500, 0xffffffff, 0x7,
  423. 0x9510, 0xffffffff, 0x100,
  424. 0x9500, 0xffffffff, 0x8000,
  425. 0x9490, 0xffffffff, 0x0,
  426. 0x949c, 0xffffffff, 0x100,
  427. 0x9490, 0xffffffff, 0x1,
  428. 0x949c, 0xffffffff, 0x100,
  429. 0x9490, 0xffffffff, 0x2,
  430. 0x949c, 0xffffffff, 0x100,
  431. 0x9490, 0xffffffff, 0x3,
  432. 0x949c, 0xffffffff, 0x100,
  433. 0x9490, 0xffffffff, 0x4,
  434. 0x949c, 0xffffffff, 0x100,
  435. 0x9490, 0xffffffff, 0x5,
  436. 0x949c, 0xffffffff, 0x100,
  437. 0x9490, 0xffffffff, 0x6,
  438. 0x949c, 0xffffffff, 0x100,
  439. 0x9490, 0xffffffff, 0x7,
  440. 0x949c, 0xffffffff, 0x100,
  441. 0x9490, 0xffffffff, 0x8000,
  442. 0x9604, 0xffffffff, 0x0,
  443. 0x9654, 0xffffffff, 0x100,
  444. 0x9604, 0xffffffff, 0x1,
  445. 0x9654, 0xffffffff, 0x100,
  446. 0x9604, 0xffffffff, 0x2,
  447. 0x9654, 0xffffffff, 0x100,
  448. 0x9604, 0xffffffff, 0x3,
  449. 0x9654, 0xffffffff, 0x100,
  450. 0x9604, 0xffffffff, 0x4,
  451. 0x9654, 0xffffffff, 0x100,
  452. 0x9604, 0xffffffff, 0x5,
  453. 0x9654, 0xffffffff, 0x100,
  454. 0x9604, 0xffffffff, 0x6,
  455. 0x9654, 0xffffffff, 0x100,
  456. 0x9604, 0xffffffff, 0x7,
  457. 0x9654, 0xffffffff, 0x100,
  458. 0x9604, 0xffffffff, 0x80000000,
  459. 0x9030, 0xffffffff, 0x100,
  460. 0x9034, 0xffffffff, 0x100,
  461. 0x9038, 0xffffffff, 0x100,
  462. 0x903c, 0xffffffff, 0x100,
  463. 0x9040, 0xffffffff, 0x100,
  464. 0xa200, 0xffffffff, 0x100,
  465. 0xa204, 0xffffffff, 0x100,
  466. 0xa208, 0xffffffff, 0x100,
  467. 0xa20c, 0xffffffff, 0x100,
  468. 0x971c, 0xffffffff, 0x100,
  469. 0x915c, 0xffffffff, 0x00020001,
  470. 0x916c, 0xffffffff, 0x00040003,
  471. 0x9170, 0xffffffff, 0x00000005,
  472. 0x9178, 0xffffffff, 0x00050001,
  473. 0x917c, 0xffffffff, 0x00030002,
  474. 0x918c, 0xffffffff, 0x00000004,
  475. 0x9190, 0xffffffff, 0x00070006,
  476. 0x9194, 0xffffffff, 0x00050001,
  477. 0x9198, 0xffffffff, 0x00030002,
  478. 0x91a8, 0xffffffff, 0x00000004,
  479. 0x91ac, 0xffffffff, 0x00070006,
  480. 0x91b0, 0xffffffff, 0x00050001,
  481. 0x91b4, 0xffffffff, 0x00030002,
  482. 0x91c4, 0xffffffff, 0x00000004,
  483. 0x91c8, 0xffffffff, 0x00070006,
  484. 0x91cc, 0xffffffff, 0x00050001,
  485. 0x91d0, 0xffffffff, 0x00030002,
  486. 0x91e0, 0xffffffff, 0x00000004,
  487. 0x91e4, 0xffffffff, 0x00070006,
  488. 0x91e8, 0xffffffff, 0x00000001,
  489. 0x91ec, 0xffffffff, 0x00050001,
  490. 0x91f0, 0xffffffff, 0x00030002,
  491. 0x9200, 0xffffffff, 0x00000004,
  492. 0x9204, 0xffffffff, 0x00070006,
  493. 0x9208, 0xffffffff, 0x00050001,
  494. 0x920c, 0xffffffff, 0x00030002,
  495. 0x921c, 0xffffffff, 0x00000004,
  496. 0x9220, 0xffffffff, 0x00070006,
  497. 0x9224, 0xffffffff, 0x00050001,
  498. 0x9228, 0xffffffff, 0x00030002,
  499. 0x9238, 0xffffffff, 0x00000004,
  500. 0x923c, 0xffffffff, 0x00070006,
  501. 0x9240, 0xffffffff, 0x00050001,
  502. 0x9244, 0xffffffff, 0x00030002,
  503. 0x9254, 0xffffffff, 0x00000004,
  504. 0x9258, 0xffffffff, 0x00070006,
  505. 0x9294, 0xffffffff, 0x00000001,
  506. 0x929c, 0xffffffff, 0x00000002,
  507. 0x92a0, 0xffffffff, 0x00040003,
  508. 0x92a4, 0xffffffff, 0x00000005
  509. };
  510. static const u32 rv740_golden_registers[] =
  511. {
  512. 0x88c4, 0xffffffff, 0x00000082,
  513. 0x28a50, 0xfffffffc, 0x00000004,
  514. 0x2650, 0x00040000, 0,
  515. 0x20bc, 0x00040000, 0,
  516. 0x733c, 0xffffffff, 0x00000002,
  517. 0x7300, 0xffffffff, 0x001000f0,
  518. 0x3f90, 0x00ff0000, 0,
  519. 0x9148, 0x00ff0000, 0,
  520. 0x3f94, 0x00ff0000, 0,
  521. 0x914c, 0x00ff0000, 0,
  522. 0x240c, 0xffffffff, 0x00000380,
  523. 0x8a14, 0x00000007, 0x00000007,
  524. 0x8b24, 0xffffffff, 0x00ff0fff,
  525. 0x28a4c, 0xffffffff, 0x00004000,
  526. 0xa180, 0xffffffff, 0x00003f3f,
  527. 0x8d00, 0xffffffff, 0x0e0e003a,
  528. 0x8d04, 0xffffffff, 0x013a0e2a,
  529. 0x8c00, 0xffffffff, 0xe400000f,
  530. 0x8db0, 0xffffffff, 0x98989898,
  531. 0x8db4, 0xffffffff, 0x98989898,
  532. 0x8db8, 0xffffffff, 0x98989898,
  533. 0x8dbc, 0xffffffff, 0x98989898,
  534. 0x8dc0, 0xffffffff, 0x98989898,
  535. 0x8dc4, 0xffffffff, 0x98989898,
  536. 0x8dc8, 0xffffffff, 0x98989898,
  537. 0x8dcc, 0xffffffff, 0x98989898,
  538. 0x9058, 0xffffffff, 0x0fffc40f,
  539. 0x900c, 0xffffffff, 0x003b033f,
  540. 0x28350, 0xffffffff, 0,
  541. 0x8cf0, 0x1fffffff, 0x08e00420,
  542. 0x9508, 0xffffffff, 0x00000002,
  543. 0x88c4, 0xffffffff, 0x000000c2,
  544. 0x9698, 0x18000000, 0x18000000
  545. };
  546. static const u32 rv740_mgcg_init[] =
  547. {
  548. 0x8bcc, 0xffffffff, 0x13030100,
  549. 0x5448, 0xffffffff, 0x100,
  550. 0x55e4, 0xffffffff, 0x100,
  551. 0x160c, 0xffffffff, 0x100,
  552. 0x5644, 0xffffffff, 0x100,
  553. 0xc164, 0xffffffff, 0x100,
  554. 0x8a18, 0xffffffff, 0x100,
  555. 0x897c, 0xffffffff, 0x100,
  556. 0x8b28, 0xffffffff, 0x100,
  557. 0x9144, 0xffffffff, 0x100,
  558. 0x9a1c, 0xffffffff, 0x10000,
  559. 0x9a50, 0xffffffff, 0x100,
  560. 0x9a1c, 0xffffffff, 0x10001,
  561. 0x9a50, 0xffffffff, 0x100,
  562. 0x9a1c, 0xffffffff, 0x10002,
  563. 0x9a50, 0xffffffff, 0x100,
  564. 0x9a1c, 0xffffffff, 0x10003,
  565. 0x9a50, 0xffffffff, 0x100,
  566. 0x9a1c, 0xffffffff, 0x0,
  567. 0x9870, 0xffffffff, 0x100,
  568. 0x8d58, 0xffffffff, 0x100,
  569. 0x9500, 0xffffffff, 0x0,
  570. 0x9510, 0xffffffff, 0x100,
  571. 0x9500, 0xffffffff, 0x1,
  572. 0x9510, 0xffffffff, 0x100,
  573. 0x9500, 0xffffffff, 0x2,
  574. 0x9510, 0xffffffff, 0x100,
  575. 0x9500, 0xffffffff, 0x3,
  576. 0x9510, 0xffffffff, 0x100,
  577. 0x9500, 0xffffffff, 0x4,
  578. 0x9510, 0xffffffff, 0x100,
  579. 0x9500, 0xffffffff, 0x5,
  580. 0x9510, 0xffffffff, 0x100,
  581. 0x9500, 0xffffffff, 0x6,
  582. 0x9510, 0xffffffff, 0x100,
  583. 0x9500, 0xffffffff, 0x7,
  584. 0x9510, 0xffffffff, 0x100,
  585. 0x9500, 0xffffffff, 0x8000,
  586. 0x9490, 0xffffffff, 0x0,
  587. 0x949c, 0xffffffff, 0x100,
  588. 0x9490, 0xffffffff, 0x1,
  589. 0x949c, 0xffffffff, 0x100,
  590. 0x9490, 0xffffffff, 0x2,
  591. 0x949c, 0xffffffff, 0x100,
  592. 0x9490, 0xffffffff, 0x3,
  593. 0x949c, 0xffffffff, 0x100,
  594. 0x9490, 0xffffffff, 0x4,
  595. 0x949c, 0xffffffff, 0x100,
  596. 0x9490, 0xffffffff, 0x5,
  597. 0x949c, 0xffffffff, 0x100,
  598. 0x9490, 0xffffffff, 0x6,
  599. 0x949c, 0xffffffff, 0x100,
  600. 0x9490, 0xffffffff, 0x7,
  601. 0x949c, 0xffffffff, 0x100,
  602. 0x9490, 0xffffffff, 0x8000,
  603. 0x9604, 0xffffffff, 0x0,
  604. 0x9654, 0xffffffff, 0x100,
  605. 0x9604, 0xffffffff, 0x1,
  606. 0x9654, 0xffffffff, 0x100,
  607. 0x9604, 0xffffffff, 0x2,
  608. 0x9654, 0xffffffff, 0x100,
  609. 0x9604, 0xffffffff, 0x3,
  610. 0x9654, 0xffffffff, 0x100,
  611. 0x9604, 0xffffffff, 0x4,
  612. 0x9654, 0xffffffff, 0x100,
  613. 0x9604, 0xffffffff, 0x5,
  614. 0x9654, 0xffffffff, 0x100,
  615. 0x9604, 0xffffffff, 0x6,
  616. 0x9654, 0xffffffff, 0x100,
  617. 0x9604, 0xffffffff, 0x7,
  618. 0x9654, 0xffffffff, 0x100,
  619. 0x9604, 0xffffffff, 0x80000000,
  620. 0x9030, 0xffffffff, 0x100,
  621. 0x9034, 0xffffffff, 0x100,
  622. 0x9038, 0xffffffff, 0x100,
  623. 0x903c, 0xffffffff, 0x100,
  624. 0x9040, 0xffffffff, 0x100,
  625. 0xa200, 0xffffffff, 0x100,
  626. 0xa204, 0xffffffff, 0x100,
  627. 0xa208, 0xffffffff, 0x100,
  628. 0xa20c, 0xffffffff, 0x100,
  629. 0x971c, 0xffffffff, 0x100,
  630. 0x915c, 0xffffffff, 0x00020001,
  631. 0x9160, 0xffffffff, 0x00040003,
  632. 0x916c, 0xffffffff, 0x00060005,
  633. 0x9170, 0xffffffff, 0x00080007,
  634. 0x9174, 0xffffffff, 0x000a0009,
  635. 0x9178, 0xffffffff, 0x000c000b,
  636. 0x917c, 0xffffffff, 0x000e000d,
  637. 0x9180, 0xffffffff, 0x0010000f,
  638. 0x918c, 0xffffffff, 0x00120011,
  639. 0x9190, 0xffffffff, 0x00140013,
  640. 0x9194, 0xffffffff, 0x00020001,
  641. 0x9198, 0xffffffff, 0x00040003,
  642. 0x919c, 0xffffffff, 0x00060005,
  643. 0x91a8, 0xffffffff, 0x00080007,
  644. 0x91ac, 0xffffffff, 0x000a0009,
  645. 0x91b0, 0xffffffff, 0x000c000b,
  646. 0x91b4, 0xffffffff, 0x000e000d,
  647. 0x91b8, 0xffffffff, 0x0010000f,
  648. 0x91c4, 0xffffffff, 0x00120011,
  649. 0x91c8, 0xffffffff, 0x00140013,
  650. 0x91cc, 0xffffffff, 0x00020001,
  651. 0x91d0, 0xffffffff, 0x00040003,
  652. 0x91d4, 0xffffffff, 0x00060005,
  653. 0x91e0, 0xffffffff, 0x00080007,
  654. 0x91e4, 0xffffffff, 0x000a0009,
  655. 0x91e8, 0xffffffff, 0x000c000b,
  656. 0x91ec, 0xffffffff, 0x00020001,
  657. 0x91f0, 0xffffffff, 0x00040003,
  658. 0x91f4, 0xffffffff, 0x00060005,
  659. 0x9200, 0xffffffff, 0x00080007,
  660. 0x9204, 0xffffffff, 0x000a0009,
  661. 0x9208, 0xffffffff, 0x000c000b,
  662. 0x920c, 0xffffffff, 0x000e000d,
  663. 0x9210, 0xffffffff, 0x0010000f,
  664. 0x921c, 0xffffffff, 0x00120011,
  665. 0x9220, 0xffffffff, 0x00140013,
  666. 0x9224, 0xffffffff, 0x00020001,
  667. 0x9228, 0xffffffff, 0x00040003,
  668. 0x922c, 0xffffffff, 0x00060005,
  669. 0x9238, 0xffffffff, 0x00080007,
  670. 0x923c, 0xffffffff, 0x000a0009,
  671. 0x9240, 0xffffffff, 0x000c000b,
  672. 0x9244, 0xffffffff, 0x000e000d,
  673. 0x9248, 0xffffffff, 0x0010000f,
  674. 0x9254, 0xffffffff, 0x00120011,
  675. 0x9258, 0xffffffff, 0x00140013,
  676. 0x9294, 0xffffffff, 0x00020001,
  677. 0x929c, 0xffffffff, 0x00040003,
  678. 0x92a0, 0xffffffff, 0x00060005,
  679. 0x92a4, 0xffffffff, 0x00080007
  680. };
  681. static void rv770_init_golden_registers(struct radeon_device *rdev)
  682. {
  683. switch (rdev->family) {
  684. case CHIP_RV770:
  685. radeon_program_register_sequence(rdev,
  686. r7xx_golden_registers,
  687. (const u32)ARRAY_SIZE(r7xx_golden_registers));
  688. radeon_program_register_sequence(rdev,
  689. r7xx_golden_dyn_gpr_registers,
  690. (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
  691. if (rdev->pdev->device == 0x994e)
  692. radeon_program_register_sequence(rdev,
  693. rv770ce_golden_registers,
  694. (const u32)ARRAY_SIZE(rv770ce_golden_registers));
  695. else
  696. radeon_program_register_sequence(rdev,
  697. rv770_golden_registers,
  698. (const u32)ARRAY_SIZE(rv770_golden_registers));
  699. radeon_program_register_sequence(rdev,
  700. rv770_mgcg_init,
  701. (const u32)ARRAY_SIZE(rv770_mgcg_init));
  702. break;
  703. case CHIP_RV730:
  704. radeon_program_register_sequence(rdev,
  705. r7xx_golden_registers,
  706. (const u32)ARRAY_SIZE(r7xx_golden_registers));
  707. radeon_program_register_sequence(rdev,
  708. r7xx_golden_dyn_gpr_registers,
  709. (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
  710. radeon_program_register_sequence(rdev,
  711. rv730_golden_registers,
  712. (const u32)ARRAY_SIZE(rv770_golden_registers));
  713. radeon_program_register_sequence(rdev,
  714. rv730_mgcg_init,
  715. (const u32)ARRAY_SIZE(rv770_mgcg_init));
  716. break;
  717. case CHIP_RV710:
  718. radeon_program_register_sequence(rdev,
  719. r7xx_golden_registers,
  720. (const u32)ARRAY_SIZE(r7xx_golden_registers));
  721. radeon_program_register_sequence(rdev,
  722. r7xx_golden_dyn_gpr_registers,
  723. (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
  724. radeon_program_register_sequence(rdev,
  725. rv710_golden_registers,
  726. (const u32)ARRAY_SIZE(rv770_golden_registers));
  727. radeon_program_register_sequence(rdev,
  728. rv710_mgcg_init,
  729. (const u32)ARRAY_SIZE(rv770_mgcg_init));
  730. break;
  731. case CHIP_RV740:
  732. radeon_program_register_sequence(rdev,
  733. rv740_golden_registers,
  734. (const u32)ARRAY_SIZE(rv770_golden_registers));
  735. radeon_program_register_sequence(rdev,
  736. rv740_mgcg_init,
  737. (const u32)ARRAY_SIZE(rv770_mgcg_init));
  738. break;
  739. default:
  740. break;
  741. }
  742. }
  743. #define PCIE_BUS_CLK 10000
  744. #define TCLK (PCIE_BUS_CLK / 10)
  745. /**
  746. * rv770_get_xclk - get the xclk
  747. *
  748. * @rdev: radeon_device pointer
  749. *
  750. * Returns the reference clock used by the gfx engine
  751. * (r7xx-cayman).
  752. */
  753. u32 rv770_get_xclk(struct radeon_device *rdev)
  754. {
  755. u32 reference_clock = rdev->clock.spll.reference_freq;
  756. u32 tmp = RREG32(CG_CLKPIN_CNTL);
  757. if (tmp & MUX_TCLK_TO_XCLK)
  758. return TCLK;
  759. if (tmp & XTALIN_DIVIDE)
  760. return reference_clock / 4;
  761. return reference_clock;
  762. }
  763. int rv770_uvd_resume(struct radeon_device *rdev)
  764. {
  765. uint64_t addr;
  766. uint32_t chip_id, size;
  767. int r;
  768. r = radeon_uvd_resume(rdev);
  769. if (r)
  770. return r;
  771. /* programm the VCPU memory controller bits 0-27 */
  772. addr = rdev->uvd.gpu_addr >> 3;
  773. size = RADEON_GPU_PAGE_ALIGN(rdev->uvd.fw_size + 4) >> 3;
  774. WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
  775. WREG32(UVD_VCPU_CACHE_SIZE0, size);
  776. addr += size;
  777. size = RADEON_UVD_STACK_SIZE >> 3;
  778. WREG32(UVD_VCPU_CACHE_OFFSET1, addr);
  779. WREG32(UVD_VCPU_CACHE_SIZE1, size);
  780. addr += size;
  781. size = RADEON_UVD_HEAP_SIZE >> 3;
  782. WREG32(UVD_VCPU_CACHE_OFFSET2, addr);
  783. WREG32(UVD_VCPU_CACHE_SIZE2, size);
  784. /* bits 28-31 */
  785. addr = (rdev->uvd.gpu_addr >> 28) & 0xF;
  786. WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
  787. /* bits 32-39 */
  788. addr = (rdev->uvd.gpu_addr >> 32) & 0xFF;
  789. WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
  790. /* tell firmware which hardware it is running on */
  791. switch (rdev->family) {
  792. default:
  793. return -EINVAL;
  794. case CHIP_RV710:
  795. chip_id = 0x01000005;
  796. break;
  797. case CHIP_RV730:
  798. chip_id = 0x01000006;
  799. break;
  800. case CHIP_RV740:
  801. chip_id = 0x01000007;
  802. break;
  803. case CHIP_CYPRESS:
  804. case CHIP_HEMLOCK:
  805. chip_id = 0x01000008;
  806. break;
  807. case CHIP_JUNIPER:
  808. chip_id = 0x01000009;
  809. break;
  810. case CHIP_REDWOOD:
  811. chip_id = 0x0100000a;
  812. break;
  813. case CHIP_CEDAR:
  814. chip_id = 0x0100000b;
  815. break;
  816. case CHIP_SUMO:
  817. case CHIP_SUMO2:
  818. chip_id = 0x0100000c;
  819. break;
  820. case CHIP_PALM:
  821. chip_id = 0x0100000e;
  822. break;
  823. case CHIP_CAYMAN:
  824. chip_id = 0x0100000f;
  825. break;
  826. case CHIP_BARTS:
  827. chip_id = 0x01000010;
  828. break;
  829. case CHIP_TURKS:
  830. chip_id = 0x01000011;
  831. break;
  832. case CHIP_CAICOS:
  833. chip_id = 0x01000012;
  834. break;
  835. case CHIP_TAHITI:
  836. chip_id = 0x01000014;
  837. break;
  838. case CHIP_VERDE:
  839. chip_id = 0x01000015;
  840. break;
  841. case CHIP_PITCAIRN:
  842. chip_id = 0x01000016;
  843. break;
  844. case CHIP_ARUBA:
  845. chip_id = 0x01000017;
  846. break;
  847. }
  848. WREG32(UVD_VCPU_CHIP_ID, chip_id);
  849. return 0;
  850. }
  851. u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
  852. {
  853. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  854. u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
  855. int i;
  856. /* Lock the graphics update lock */
  857. tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
  858. WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  859. /* update the scanout addresses */
  860. if (radeon_crtc->crtc_id) {
  861. WREG32(D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
  862. WREG32(D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
  863. } else {
  864. WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
  865. WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
  866. }
  867. WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  868. (u32)crtc_base);
  869. WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  870. (u32)crtc_base);
  871. /* Wait for update_pending to go high. */
  872. for (i = 0; i < rdev->usec_timeout; i++) {
  873. if (RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)
  874. break;
  875. udelay(1);
  876. }
  877. DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
  878. /* Unlock the lock, so double-buffering can take place inside vblank */
  879. tmp &= ~AVIVO_D1GRPH_UPDATE_LOCK;
  880. WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  881. /* Return current update_pending status: */
  882. return RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING;
  883. }
  884. /* get temperature in millidegrees */
  885. int rv770_get_temp(struct radeon_device *rdev)
  886. {
  887. u32 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  888. ASIC_T_SHIFT;
  889. int actual_temp;
  890. if (temp & 0x400)
  891. actual_temp = -256;
  892. else if (temp & 0x200)
  893. actual_temp = 255;
  894. else if (temp & 0x100) {
  895. actual_temp = temp & 0x1ff;
  896. actual_temp |= ~0x1ff;
  897. } else
  898. actual_temp = temp & 0xff;
  899. return (actual_temp * 1000) / 2;
  900. }
  901. void rv770_pm_misc(struct radeon_device *rdev)
  902. {
  903. int req_ps_idx = rdev->pm.requested_power_state_index;
  904. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  905. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  906. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  907. if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
  908. /* 0xff01 is a flag rather then an actual voltage */
  909. if (voltage->voltage == 0xff01)
  910. return;
  911. if (voltage->voltage != rdev->pm.current_vddc) {
  912. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  913. rdev->pm.current_vddc = voltage->voltage;
  914. DRM_DEBUG("Setting: v: %d\n", voltage->voltage);
  915. }
  916. }
  917. }
  918. /*
  919. * GART
  920. */
  921. static int rv770_pcie_gart_enable(struct radeon_device *rdev)
  922. {
  923. u32 tmp;
  924. int r, i;
  925. if (rdev->gart.robj == NULL) {
  926. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  927. return -EINVAL;
  928. }
  929. r = radeon_gart_table_vram_pin(rdev);
  930. if (r)
  931. return r;
  932. radeon_gart_restore(rdev);
  933. /* Setup L2 cache */
  934. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  935. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  936. EFFECTIVE_L2_QUEUE_SIZE(7));
  937. WREG32(VM_L2_CNTL2, 0);
  938. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  939. /* Setup TLB control */
  940. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  941. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  942. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  943. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  944. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  945. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  946. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  947. if (rdev->family == CHIP_RV740)
  948. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  949. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  950. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  951. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  952. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  953. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  954. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  955. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  956. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  957. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  958. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  959. (u32)(rdev->dummy_page.addr >> 12));
  960. for (i = 1; i < 7; i++)
  961. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  962. r600_pcie_gart_tlb_flush(rdev);
  963. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  964. (unsigned)(rdev->mc.gtt_size >> 20),
  965. (unsigned long long)rdev->gart.table_addr);
  966. rdev->gart.ready = true;
  967. return 0;
  968. }
  969. static void rv770_pcie_gart_disable(struct radeon_device *rdev)
  970. {
  971. u32 tmp;
  972. int i;
  973. /* Disable all tables */
  974. for (i = 0; i < 7; i++)
  975. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  976. /* Setup L2 cache */
  977. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  978. EFFECTIVE_L2_QUEUE_SIZE(7));
  979. WREG32(VM_L2_CNTL2, 0);
  980. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  981. /* Setup TLB control */
  982. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  983. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  984. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  985. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  986. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  987. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  988. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  989. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  990. radeon_gart_table_vram_unpin(rdev);
  991. }
  992. static void rv770_pcie_gart_fini(struct radeon_device *rdev)
  993. {
  994. radeon_gart_fini(rdev);
  995. rv770_pcie_gart_disable(rdev);
  996. radeon_gart_table_vram_free(rdev);
  997. }
  998. static void rv770_agp_enable(struct radeon_device *rdev)
  999. {
  1000. u32 tmp;
  1001. int i;
  1002. /* Setup L2 cache */
  1003. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  1004. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1005. EFFECTIVE_L2_QUEUE_SIZE(7));
  1006. WREG32(VM_L2_CNTL2, 0);
  1007. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  1008. /* Setup TLB control */
  1009. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  1010. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1011. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  1012. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  1013. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  1014. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  1015. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  1016. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  1017. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  1018. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  1019. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  1020. for (i = 0; i < 7; i++)
  1021. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  1022. }
  1023. static void rv770_mc_program(struct radeon_device *rdev)
  1024. {
  1025. struct rv515_mc_save save;
  1026. u32 tmp;
  1027. int i, j;
  1028. /* Initialize HDP */
  1029. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1030. WREG32((0x2c14 + j), 0x00000000);
  1031. WREG32((0x2c18 + j), 0x00000000);
  1032. WREG32((0x2c1c + j), 0x00000000);
  1033. WREG32((0x2c20 + j), 0x00000000);
  1034. WREG32((0x2c24 + j), 0x00000000);
  1035. }
  1036. /* r7xx hw bug. Read from HDP_DEBUG1 rather
  1037. * than writing to HDP_REG_COHERENCY_FLUSH_CNTL
  1038. */
  1039. tmp = RREG32(HDP_DEBUG1);
  1040. rv515_mc_stop(rdev, &save);
  1041. if (r600_mc_wait_for_idle(rdev)) {
  1042. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1043. }
  1044. /* Lockout access through VGA aperture*/
  1045. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  1046. /* Update configuration */
  1047. if (rdev->flags & RADEON_IS_AGP) {
  1048. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  1049. /* VRAM before AGP */
  1050. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1051. rdev->mc.vram_start >> 12);
  1052. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1053. rdev->mc.gtt_end >> 12);
  1054. } else {
  1055. /* VRAM after AGP */
  1056. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1057. rdev->mc.gtt_start >> 12);
  1058. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1059. rdev->mc.vram_end >> 12);
  1060. }
  1061. } else {
  1062. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  1063. rdev->mc.vram_start >> 12);
  1064. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  1065. rdev->mc.vram_end >> 12);
  1066. }
  1067. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  1068. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  1069. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  1070. WREG32(MC_VM_FB_LOCATION, tmp);
  1071. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  1072. WREG32(HDP_NONSURFACE_INFO, (2 << 7));
  1073. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  1074. if (rdev->flags & RADEON_IS_AGP) {
  1075. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  1076. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  1077. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  1078. } else {
  1079. WREG32(MC_VM_AGP_BASE, 0);
  1080. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  1081. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  1082. }
  1083. if (r600_mc_wait_for_idle(rdev)) {
  1084. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1085. }
  1086. rv515_mc_resume(rdev, &save);
  1087. /* we need to own VRAM, so turn off the VGA renderer here
  1088. * to stop it overwriting our objects */
  1089. rv515_vga_render_disable(rdev);
  1090. }
  1091. /*
  1092. * CP.
  1093. */
  1094. void r700_cp_stop(struct radeon_device *rdev)
  1095. {
  1096. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  1097. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
  1098. WREG32(SCRATCH_UMSK, 0);
  1099. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  1100. }
  1101. static int rv770_cp_load_microcode(struct radeon_device *rdev)
  1102. {
  1103. const __be32 *fw_data;
  1104. int i;
  1105. if (!rdev->me_fw || !rdev->pfp_fw)
  1106. return -EINVAL;
  1107. r700_cp_stop(rdev);
  1108. WREG32(CP_RB_CNTL,
  1109. #ifdef __BIG_ENDIAN
  1110. BUF_SWAP_32BIT |
  1111. #endif
  1112. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  1113. /* Reset cp */
  1114. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1115. RREG32(GRBM_SOFT_RESET);
  1116. mdelay(15);
  1117. WREG32(GRBM_SOFT_RESET, 0);
  1118. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1119. WREG32(CP_PFP_UCODE_ADDR, 0);
  1120. for (i = 0; i < R700_PFP_UCODE_SIZE; i++)
  1121. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  1122. WREG32(CP_PFP_UCODE_ADDR, 0);
  1123. fw_data = (const __be32 *)rdev->me_fw->data;
  1124. WREG32(CP_ME_RAM_WADDR, 0);
  1125. for (i = 0; i < R700_PM4_UCODE_SIZE; i++)
  1126. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  1127. WREG32(CP_PFP_UCODE_ADDR, 0);
  1128. WREG32(CP_ME_RAM_WADDR, 0);
  1129. WREG32(CP_ME_RAM_RADDR, 0);
  1130. return 0;
  1131. }
  1132. void r700_cp_fini(struct radeon_device *rdev)
  1133. {
  1134. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1135. r700_cp_stop(rdev);
  1136. radeon_ring_fini(rdev, ring);
  1137. radeon_scratch_free(rdev, ring->rptr_save_reg);
  1138. }
  1139. /*
  1140. * Core functions
  1141. */
  1142. static void rv770_gpu_init(struct radeon_device *rdev)
  1143. {
  1144. int i, j, num_qd_pipes;
  1145. u32 ta_aux_cntl;
  1146. u32 sx_debug_1;
  1147. u32 smx_dc_ctl0;
  1148. u32 db_debug3;
  1149. u32 num_gs_verts_per_thread;
  1150. u32 vgt_gs_per_es;
  1151. u32 gs_prim_buffer_depth = 0;
  1152. u32 sq_ms_fifo_sizes;
  1153. u32 sq_config;
  1154. u32 sq_thread_resource_mgmt;
  1155. u32 hdp_host_path_cntl;
  1156. u32 sq_dyn_gpr_size_simd_ab_0;
  1157. u32 gb_tiling_config = 0;
  1158. u32 cc_rb_backend_disable = 0;
  1159. u32 cc_gc_shader_pipe_config = 0;
  1160. u32 mc_arb_ramcfg;
  1161. u32 db_debug4, tmp;
  1162. u32 inactive_pipes, shader_pipe_config;
  1163. u32 disabled_rb_mask;
  1164. unsigned active_number;
  1165. /* setup chip specs */
  1166. rdev->config.rv770.tiling_group_size = 256;
  1167. switch (rdev->family) {
  1168. case CHIP_RV770:
  1169. rdev->config.rv770.max_pipes = 4;
  1170. rdev->config.rv770.max_tile_pipes = 8;
  1171. rdev->config.rv770.max_simds = 10;
  1172. rdev->config.rv770.max_backends = 4;
  1173. rdev->config.rv770.max_gprs = 256;
  1174. rdev->config.rv770.max_threads = 248;
  1175. rdev->config.rv770.max_stack_entries = 512;
  1176. rdev->config.rv770.max_hw_contexts = 8;
  1177. rdev->config.rv770.max_gs_threads = 16 * 2;
  1178. rdev->config.rv770.sx_max_export_size = 128;
  1179. rdev->config.rv770.sx_max_export_pos_size = 16;
  1180. rdev->config.rv770.sx_max_export_smx_size = 112;
  1181. rdev->config.rv770.sq_num_cf_insts = 2;
  1182. rdev->config.rv770.sx_num_of_sets = 7;
  1183. rdev->config.rv770.sc_prim_fifo_size = 0xF9;
  1184. rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
  1185. rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
  1186. break;
  1187. case CHIP_RV730:
  1188. rdev->config.rv770.max_pipes = 2;
  1189. rdev->config.rv770.max_tile_pipes = 4;
  1190. rdev->config.rv770.max_simds = 8;
  1191. rdev->config.rv770.max_backends = 2;
  1192. rdev->config.rv770.max_gprs = 128;
  1193. rdev->config.rv770.max_threads = 248;
  1194. rdev->config.rv770.max_stack_entries = 256;
  1195. rdev->config.rv770.max_hw_contexts = 8;
  1196. rdev->config.rv770.max_gs_threads = 16 * 2;
  1197. rdev->config.rv770.sx_max_export_size = 256;
  1198. rdev->config.rv770.sx_max_export_pos_size = 32;
  1199. rdev->config.rv770.sx_max_export_smx_size = 224;
  1200. rdev->config.rv770.sq_num_cf_insts = 2;
  1201. rdev->config.rv770.sx_num_of_sets = 7;
  1202. rdev->config.rv770.sc_prim_fifo_size = 0xf9;
  1203. rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
  1204. rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
  1205. if (rdev->config.rv770.sx_max_export_pos_size > 16) {
  1206. rdev->config.rv770.sx_max_export_pos_size -= 16;
  1207. rdev->config.rv770.sx_max_export_smx_size += 16;
  1208. }
  1209. break;
  1210. case CHIP_RV710:
  1211. rdev->config.rv770.max_pipes = 2;
  1212. rdev->config.rv770.max_tile_pipes = 2;
  1213. rdev->config.rv770.max_simds = 2;
  1214. rdev->config.rv770.max_backends = 1;
  1215. rdev->config.rv770.max_gprs = 256;
  1216. rdev->config.rv770.max_threads = 192;
  1217. rdev->config.rv770.max_stack_entries = 256;
  1218. rdev->config.rv770.max_hw_contexts = 4;
  1219. rdev->config.rv770.max_gs_threads = 8 * 2;
  1220. rdev->config.rv770.sx_max_export_size = 128;
  1221. rdev->config.rv770.sx_max_export_pos_size = 16;
  1222. rdev->config.rv770.sx_max_export_smx_size = 112;
  1223. rdev->config.rv770.sq_num_cf_insts = 1;
  1224. rdev->config.rv770.sx_num_of_sets = 7;
  1225. rdev->config.rv770.sc_prim_fifo_size = 0x40;
  1226. rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
  1227. rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
  1228. break;
  1229. case CHIP_RV740:
  1230. rdev->config.rv770.max_pipes = 4;
  1231. rdev->config.rv770.max_tile_pipes = 4;
  1232. rdev->config.rv770.max_simds = 8;
  1233. rdev->config.rv770.max_backends = 4;
  1234. rdev->config.rv770.max_gprs = 256;
  1235. rdev->config.rv770.max_threads = 248;
  1236. rdev->config.rv770.max_stack_entries = 512;
  1237. rdev->config.rv770.max_hw_contexts = 8;
  1238. rdev->config.rv770.max_gs_threads = 16 * 2;
  1239. rdev->config.rv770.sx_max_export_size = 256;
  1240. rdev->config.rv770.sx_max_export_pos_size = 32;
  1241. rdev->config.rv770.sx_max_export_smx_size = 224;
  1242. rdev->config.rv770.sq_num_cf_insts = 2;
  1243. rdev->config.rv770.sx_num_of_sets = 7;
  1244. rdev->config.rv770.sc_prim_fifo_size = 0x100;
  1245. rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
  1246. rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
  1247. if (rdev->config.rv770.sx_max_export_pos_size > 16) {
  1248. rdev->config.rv770.sx_max_export_pos_size -= 16;
  1249. rdev->config.rv770.sx_max_export_smx_size += 16;
  1250. }
  1251. break;
  1252. default:
  1253. break;
  1254. }
  1255. /* Initialize HDP */
  1256. j = 0;
  1257. for (i = 0; i < 32; i++) {
  1258. WREG32((0x2c14 + j), 0x00000000);
  1259. WREG32((0x2c18 + j), 0x00000000);
  1260. WREG32((0x2c1c + j), 0x00000000);
  1261. WREG32((0x2c20 + j), 0x00000000);
  1262. WREG32((0x2c24 + j), 0x00000000);
  1263. j += 0x18;
  1264. }
  1265. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  1266. /* setup tiling, simd, pipe config */
  1267. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  1268. shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG);
  1269. inactive_pipes = (shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT;
  1270. for (i = 0, tmp = 1, active_number = 0; i < R7XX_MAX_PIPES; i++) {
  1271. if (!(inactive_pipes & tmp)) {
  1272. active_number++;
  1273. }
  1274. tmp <<= 1;
  1275. }
  1276. if (active_number == 1) {
  1277. WREG32(SPI_CONFIG_CNTL, DISABLE_INTERP_1);
  1278. } else {
  1279. WREG32(SPI_CONFIG_CNTL, 0);
  1280. }
  1281. cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  1282. tmp = R7XX_MAX_BACKENDS - r600_count_pipe_bits(cc_rb_backend_disable >> 16);
  1283. if (tmp < rdev->config.rv770.max_backends) {
  1284. rdev->config.rv770.max_backends = tmp;
  1285. }
  1286. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  1287. tmp = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R7XX_MAX_PIPES_MASK);
  1288. if (tmp < rdev->config.rv770.max_pipes) {
  1289. rdev->config.rv770.max_pipes = tmp;
  1290. }
  1291. tmp = R7XX_MAX_SIMDS - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R7XX_MAX_SIMDS_MASK);
  1292. if (tmp < rdev->config.rv770.max_simds) {
  1293. rdev->config.rv770.max_simds = tmp;
  1294. }
  1295. switch (rdev->config.rv770.max_tile_pipes) {
  1296. case 1:
  1297. default:
  1298. gb_tiling_config = PIPE_TILING(0);
  1299. break;
  1300. case 2:
  1301. gb_tiling_config = PIPE_TILING(1);
  1302. break;
  1303. case 4:
  1304. gb_tiling_config = PIPE_TILING(2);
  1305. break;
  1306. case 8:
  1307. gb_tiling_config = PIPE_TILING(3);
  1308. break;
  1309. }
  1310. rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes;
  1311. disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R7XX_MAX_BACKENDS_MASK;
  1312. tmp = (gb_tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
  1313. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.rv770.max_backends,
  1314. R7XX_MAX_BACKENDS, disabled_rb_mask);
  1315. gb_tiling_config |= tmp << 16;
  1316. rdev->config.rv770.backend_map = tmp;
  1317. if (rdev->family == CHIP_RV770)
  1318. gb_tiling_config |= BANK_TILING(1);
  1319. else {
  1320. if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
  1321. gb_tiling_config |= BANK_TILING(1);
  1322. else
  1323. gb_tiling_config |= BANK_TILING(0);
  1324. }
  1325. rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3);
  1326. gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
  1327. if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) {
  1328. gb_tiling_config |= ROW_TILING(3);
  1329. gb_tiling_config |= SAMPLE_SPLIT(3);
  1330. } else {
  1331. gb_tiling_config |=
  1332. ROW_TILING(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
  1333. gb_tiling_config |=
  1334. SAMPLE_SPLIT(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
  1335. }
  1336. gb_tiling_config |= BANK_SWAPS(1);
  1337. rdev->config.rv770.tile_config = gb_tiling_config;
  1338. WREG32(GB_TILING_CONFIG, gb_tiling_config);
  1339. WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1340. WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1341. WREG32(DMA_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1342. WREG32(DMA_TILING_CONFIG2, (gb_tiling_config & 0xffff));
  1343. if (rdev->family == CHIP_RV730) {
  1344. WREG32(UVD_UDEC_DB_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1345. WREG32(UVD_UDEC_DBW_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1346. WREG32(UVD_UDEC_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1347. }
  1348. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  1349. WREG32(CGTS_TCC_DISABLE, 0);
  1350. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  1351. WREG32(CGTS_USER_TCC_DISABLE, 0);
  1352. num_qd_pipes = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
  1353. WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK);
  1354. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK);
  1355. /* set HW defaults for 3D engine */
  1356. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  1357. ROQ_IB2_START(0x2b)));
  1358. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  1359. ta_aux_cntl = RREG32(TA_CNTL_AUX);
  1360. WREG32(TA_CNTL_AUX, ta_aux_cntl | DISABLE_CUBE_ANISO);
  1361. sx_debug_1 = RREG32(SX_DEBUG_1);
  1362. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  1363. WREG32(SX_DEBUG_1, sx_debug_1);
  1364. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  1365. smx_dc_ctl0 &= ~CACHE_DEPTH(0x1ff);
  1366. smx_dc_ctl0 |= CACHE_DEPTH((rdev->config.rv770.sx_num_of_sets * 64) - 1);
  1367. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  1368. if (rdev->family != CHIP_RV740)
  1369. WREG32(SMX_EVENT_CTL, (ES_FLUSH_CTL(4) |
  1370. GS_FLUSH_CTL(4) |
  1371. ACK_FLUSH_CTL(3) |
  1372. SYNC_FLUSH_CTL));
  1373. if (rdev->family != CHIP_RV770)
  1374. WREG32(SMX_SAR_CTL0, 0x00003f3f);
  1375. db_debug3 = RREG32(DB_DEBUG3);
  1376. db_debug3 &= ~DB_CLK_OFF_DELAY(0x1f);
  1377. switch (rdev->family) {
  1378. case CHIP_RV770:
  1379. case CHIP_RV740:
  1380. db_debug3 |= DB_CLK_OFF_DELAY(0x1f);
  1381. break;
  1382. case CHIP_RV710:
  1383. case CHIP_RV730:
  1384. default:
  1385. db_debug3 |= DB_CLK_OFF_DELAY(2);
  1386. break;
  1387. }
  1388. WREG32(DB_DEBUG3, db_debug3);
  1389. if (rdev->family != CHIP_RV770) {
  1390. db_debug4 = RREG32(DB_DEBUG4);
  1391. db_debug4 |= DISABLE_TILE_COVERED_FOR_PS_ITER;
  1392. WREG32(DB_DEBUG4, db_debug4);
  1393. }
  1394. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.rv770.sx_max_export_size / 4) - 1) |
  1395. POSITION_BUFFER_SIZE((rdev->config.rv770.sx_max_export_pos_size / 4) - 1) |
  1396. SMX_BUFFER_SIZE((rdev->config.rv770.sx_max_export_smx_size / 4) - 1)));
  1397. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.rv770.sc_prim_fifo_size) |
  1398. SC_HIZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_hiz_tile_fifo_size) |
  1399. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_earlyz_tile_fifo_fize)));
  1400. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1401. WREG32(VGT_NUM_INSTANCES, 1);
  1402. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  1403. WREG32(CP_PERFMON_CNTL, 0);
  1404. sq_ms_fifo_sizes = (CACHE_FIFO_SIZE(16 * rdev->config.rv770.sq_num_cf_insts) |
  1405. DONE_FIFO_HIWATER(0xe0) |
  1406. ALU_UPDATE_FIFO_HIWATER(0x8));
  1407. switch (rdev->family) {
  1408. case CHIP_RV770:
  1409. case CHIP_RV730:
  1410. case CHIP_RV710:
  1411. sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x1);
  1412. break;
  1413. case CHIP_RV740:
  1414. default:
  1415. sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x4);
  1416. break;
  1417. }
  1418. WREG32(SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
  1419. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1420. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1421. */
  1422. sq_config = RREG32(SQ_CONFIG);
  1423. sq_config &= ~(PS_PRIO(3) |
  1424. VS_PRIO(3) |
  1425. GS_PRIO(3) |
  1426. ES_PRIO(3));
  1427. sq_config |= (DX9_CONSTS |
  1428. VC_ENABLE |
  1429. EXPORT_SRC_C |
  1430. PS_PRIO(0) |
  1431. VS_PRIO(1) |
  1432. GS_PRIO(2) |
  1433. ES_PRIO(3));
  1434. if (rdev->family == CHIP_RV710)
  1435. /* no vertex cache */
  1436. sq_config &= ~VC_ENABLE;
  1437. WREG32(SQ_CONFIG, sq_config);
  1438. WREG32(SQ_GPR_RESOURCE_MGMT_1, (NUM_PS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
  1439. NUM_VS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
  1440. NUM_CLAUSE_TEMP_GPRS(((rdev->config.rv770.max_gprs * 24)/64)/2)));
  1441. WREG32(SQ_GPR_RESOURCE_MGMT_2, (NUM_GS_GPRS((rdev->config.rv770.max_gprs * 7)/64) |
  1442. NUM_ES_GPRS((rdev->config.rv770.max_gprs * 7)/64)));
  1443. sq_thread_resource_mgmt = (NUM_PS_THREADS((rdev->config.rv770.max_threads * 4)/8) |
  1444. NUM_VS_THREADS((rdev->config.rv770.max_threads * 2)/8) |
  1445. NUM_ES_THREADS((rdev->config.rv770.max_threads * 1)/8));
  1446. if (((rdev->config.rv770.max_threads * 1) / 8) > rdev->config.rv770.max_gs_threads)
  1447. sq_thread_resource_mgmt |= NUM_GS_THREADS(rdev->config.rv770.max_gs_threads);
  1448. else
  1449. sq_thread_resource_mgmt |= NUM_GS_THREADS((rdev->config.rv770.max_gs_threads * 1)/8);
  1450. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  1451. WREG32(SQ_STACK_RESOURCE_MGMT_1, (NUM_PS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
  1452. NUM_VS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
  1453. WREG32(SQ_STACK_RESOURCE_MGMT_2, (NUM_GS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
  1454. NUM_ES_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
  1455. sq_dyn_gpr_size_simd_ab_0 = (SIMDA_RING0((rdev->config.rv770.max_gprs * 38)/64) |
  1456. SIMDA_RING1((rdev->config.rv770.max_gprs * 38)/64) |
  1457. SIMDB_RING0((rdev->config.rv770.max_gprs * 38)/64) |
  1458. SIMDB_RING1((rdev->config.rv770.max_gprs * 38)/64));
  1459. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0);
  1460. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0);
  1461. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0);
  1462. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0);
  1463. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0);
  1464. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0);
  1465. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0);
  1466. WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0);
  1467. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  1468. FORCE_EOV_MAX_REZ_CNT(255)));
  1469. if (rdev->family == CHIP_RV710)
  1470. WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(TC_ONLY) |
  1471. AUTO_INVLD_EN(ES_AND_GS_AUTO)));
  1472. else
  1473. WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(VC_AND_TC) |
  1474. AUTO_INVLD_EN(ES_AND_GS_AUTO)));
  1475. switch (rdev->family) {
  1476. case CHIP_RV770:
  1477. case CHIP_RV730:
  1478. case CHIP_RV740:
  1479. gs_prim_buffer_depth = 384;
  1480. break;
  1481. case CHIP_RV710:
  1482. gs_prim_buffer_depth = 128;
  1483. break;
  1484. default:
  1485. break;
  1486. }
  1487. num_gs_verts_per_thread = rdev->config.rv770.max_pipes * 16;
  1488. vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
  1489. /* Max value for this is 256 */
  1490. if (vgt_gs_per_es > 256)
  1491. vgt_gs_per_es = 256;
  1492. WREG32(VGT_ES_PER_GS, 128);
  1493. WREG32(VGT_GS_PER_ES, vgt_gs_per_es);
  1494. WREG32(VGT_GS_PER_VS, 2);
  1495. /* more default values. 2D/3D driver should adjust as needed */
  1496. WREG32(VGT_GS_VERTEX_REUSE, 16);
  1497. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  1498. WREG32(VGT_STRMOUT_EN, 0);
  1499. WREG32(SX_MISC, 0);
  1500. WREG32(PA_SC_MODE_CNTL, 0);
  1501. WREG32(PA_SC_EDGERULE, 0xaaaaaaaa);
  1502. WREG32(PA_SC_AA_CONFIG, 0);
  1503. WREG32(PA_SC_CLIPRECT_RULE, 0xffff);
  1504. WREG32(PA_SC_LINE_STIPPLE, 0);
  1505. WREG32(SPI_INPUT_Z, 0);
  1506. WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
  1507. WREG32(CB_COLOR7_FRAG, 0);
  1508. /* clear render buffer base addresses */
  1509. WREG32(CB_COLOR0_BASE, 0);
  1510. WREG32(CB_COLOR1_BASE, 0);
  1511. WREG32(CB_COLOR2_BASE, 0);
  1512. WREG32(CB_COLOR3_BASE, 0);
  1513. WREG32(CB_COLOR4_BASE, 0);
  1514. WREG32(CB_COLOR5_BASE, 0);
  1515. WREG32(CB_COLOR6_BASE, 0);
  1516. WREG32(CB_COLOR7_BASE, 0);
  1517. WREG32(TCP_CNTL, 0);
  1518. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  1519. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  1520. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1521. WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
  1522. NUM_CLIP_SEQ(3)));
  1523. WREG32(VC_ENHANCE, 0);
  1524. }
  1525. void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  1526. {
  1527. u64 size_bf, size_af;
  1528. if (mc->mc_vram_size > 0xE0000000) {
  1529. /* leave room for at least 512M GTT */
  1530. dev_warn(rdev->dev, "limiting VRAM\n");
  1531. mc->real_vram_size = 0xE0000000;
  1532. mc->mc_vram_size = 0xE0000000;
  1533. }
  1534. if (rdev->flags & RADEON_IS_AGP) {
  1535. size_bf = mc->gtt_start;
  1536. size_af = mc->mc_mask - mc->gtt_end;
  1537. if (size_bf > size_af) {
  1538. if (mc->mc_vram_size > size_bf) {
  1539. dev_warn(rdev->dev, "limiting VRAM\n");
  1540. mc->real_vram_size = size_bf;
  1541. mc->mc_vram_size = size_bf;
  1542. }
  1543. mc->vram_start = mc->gtt_start - mc->mc_vram_size;
  1544. } else {
  1545. if (mc->mc_vram_size > size_af) {
  1546. dev_warn(rdev->dev, "limiting VRAM\n");
  1547. mc->real_vram_size = size_af;
  1548. mc->mc_vram_size = size_af;
  1549. }
  1550. mc->vram_start = mc->gtt_end + 1;
  1551. }
  1552. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  1553. dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
  1554. mc->mc_vram_size >> 20, mc->vram_start,
  1555. mc->vram_end, mc->real_vram_size >> 20);
  1556. } else {
  1557. radeon_vram_location(rdev, &rdev->mc, 0);
  1558. rdev->mc.gtt_base_align = 0;
  1559. radeon_gtt_location(rdev, mc);
  1560. }
  1561. }
  1562. static int rv770_mc_init(struct radeon_device *rdev)
  1563. {
  1564. u32 tmp;
  1565. int chansize, numchan;
  1566. /* Get VRAM informations */
  1567. rdev->mc.vram_is_ddr = true;
  1568. tmp = RREG32(MC_ARB_RAMCFG);
  1569. if (tmp & CHANSIZE_OVERRIDE) {
  1570. chansize = 16;
  1571. } else if (tmp & CHANSIZE_MASK) {
  1572. chansize = 64;
  1573. } else {
  1574. chansize = 32;
  1575. }
  1576. tmp = RREG32(MC_SHARED_CHMAP);
  1577. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1578. case 0:
  1579. default:
  1580. numchan = 1;
  1581. break;
  1582. case 1:
  1583. numchan = 2;
  1584. break;
  1585. case 2:
  1586. numchan = 4;
  1587. break;
  1588. case 3:
  1589. numchan = 8;
  1590. break;
  1591. }
  1592. rdev->mc.vram_width = numchan * chansize;
  1593. /* Could aper size report 0 ? */
  1594. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  1595. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  1596. /* Setup GPU memory space */
  1597. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  1598. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  1599. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  1600. r700_vram_gtt_location(rdev, &rdev->mc);
  1601. radeon_update_bandwidth_info(rdev);
  1602. return 0;
  1603. }
  1604. /**
  1605. * rv770_copy_dma - copy pages using the DMA engine
  1606. *
  1607. * @rdev: radeon_device pointer
  1608. * @src_offset: src GPU address
  1609. * @dst_offset: dst GPU address
  1610. * @num_gpu_pages: number of GPU pages to xfer
  1611. * @fence: radeon fence object
  1612. *
  1613. * Copy GPU paging using the DMA engine (r7xx).
  1614. * Used by the radeon ttm implementation to move pages if
  1615. * registered as the asic copy callback.
  1616. */
  1617. int rv770_copy_dma(struct radeon_device *rdev,
  1618. uint64_t src_offset, uint64_t dst_offset,
  1619. unsigned num_gpu_pages,
  1620. struct radeon_fence **fence)
  1621. {
  1622. struct radeon_semaphore *sem = NULL;
  1623. int ring_index = rdev->asic->copy.dma_ring_index;
  1624. struct radeon_ring *ring = &rdev->ring[ring_index];
  1625. u32 size_in_dw, cur_size_in_dw;
  1626. int i, num_loops;
  1627. int r = 0;
  1628. r = radeon_semaphore_create(rdev, &sem);
  1629. if (r) {
  1630. DRM_ERROR("radeon: moving bo (%d).\n", r);
  1631. return r;
  1632. }
  1633. size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
  1634. num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF);
  1635. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8);
  1636. if (r) {
  1637. DRM_ERROR("radeon: moving bo (%d).\n", r);
  1638. radeon_semaphore_free(rdev, &sem, NULL);
  1639. return r;
  1640. }
  1641. if (radeon_fence_need_sync(*fence, ring->idx)) {
  1642. radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
  1643. ring->idx);
  1644. radeon_fence_note_sync(*fence, ring->idx);
  1645. } else {
  1646. radeon_semaphore_free(rdev, &sem, NULL);
  1647. }
  1648. for (i = 0; i < num_loops; i++) {
  1649. cur_size_in_dw = size_in_dw;
  1650. if (cur_size_in_dw > 0xFFFF)
  1651. cur_size_in_dw = 0xFFFF;
  1652. size_in_dw -= cur_size_in_dw;
  1653. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
  1654. radeon_ring_write(ring, dst_offset & 0xfffffffc);
  1655. radeon_ring_write(ring, src_offset & 0xfffffffc);
  1656. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  1657. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  1658. src_offset += cur_size_in_dw * 4;
  1659. dst_offset += cur_size_in_dw * 4;
  1660. }
  1661. r = radeon_fence_emit(rdev, fence, ring->idx);
  1662. if (r) {
  1663. radeon_ring_unlock_undo(rdev, ring);
  1664. return r;
  1665. }
  1666. radeon_ring_unlock_commit(rdev, ring);
  1667. radeon_semaphore_free(rdev, &sem, *fence);
  1668. return r;
  1669. }
  1670. static int rv770_startup(struct radeon_device *rdev)
  1671. {
  1672. struct radeon_ring *ring;
  1673. int r;
  1674. /* enable pcie gen2 link */
  1675. rv770_pcie_gen2_enable(rdev);
  1676. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  1677. r = r600_init_microcode(rdev);
  1678. if (r) {
  1679. DRM_ERROR("Failed to load firmware!\n");
  1680. return r;
  1681. }
  1682. }
  1683. r = r600_vram_scratch_init(rdev);
  1684. if (r)
  1685. return r;
  1686. rv770_mc_program(rdev);
  1687. if (rdev->flags & RADEON_IS_AGP) {
  1688. rv770_agp_enable(rdev);
  1689. } else {
  1690. r = rv770_pcie_gart_enable(rdev);
  1691. if (r)
  1692. return r;
  1693. }
  1694. rv770_gpu_init(rdev);
  1695. r = r600_blit_init(rdev);
  1696. if (r) {
  1697. r600_blit_fini(rdev);
  1698. rdev->asic->copy.copy = NULL;
  1699. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  1700. }
  1701. /* allocate wb buffer */
  1702. r = radeon_wb_init(rdev);
  1703. if (r)
  1704. return r;
  1705. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  1706. if (r) {
  1707. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1708. return r;
  1709. }
  1710. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  1711. if (r) {
  1712. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  1713. return r;
  1714. }
  1715. r = rv770_uvd_resume(rdev);
  1716. if (!r) {
  1717. r = radeon_fence_driver_start_ring(rdev,
  1718. R600_RING_TYPE_UVD_INDEX);
  1719. if (r)
  1720. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  1721. }
  1722. if (r)
  1723. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  1724. /* Enable IRQ */
  1725. if (!rdev->irq.installed) {
  1726. r = radeon_irq_kms_init(rdev);
  1727. if (r)
  1728. return r;
  1729. }
  1730. r = r600_irq_init(rdev);
  1731. if (r) {
  1732. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  1733. radeon_irq_kms_fini(rdev);
  1734. return r;
  1735. }
  1736. r600_irq_set(rdev);
  1737. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1738. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  1739. R600_CP_RB_RPTR, R600_CP_RB_WPTR,
  1740. 0, 0xfffff, RADEON_CP_PACKET2);
  1741. if (r)
  1742. return r;
  1743. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  1744. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  1745. DMA_RB_RPTR, DMA_RB_WPTR,
  1746. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
  1747. if (r)
  1748. return r;
  1749. r = rv770_cp_load_microcode(rdev);
  1750. if (r)
  1751. return r;
  1752. r = r600_cp_resume(rdev);
  1753. if (r)
  1754. return r;
  1755. r = r600_dma_resume(rdev);
  1756. if (r)
  1757. return r;
  1758. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  1759. if (ring->ring_size) {
  1760. r = radeon_ring_init(rdev, ring, ring->ring_size,
  1761. R600_WB_UVD_RPTR_OFFSET,
  1762. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  1763. 0, 0xfffff, RADEON_CP_PACKET2);
  1764. if (!r)
  1765. r = r600_uvd_init(rdev);
  1766. if (r)
  1767. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  1768. }
  1769. r = radeon_ib_pool_init(rdev);
  1770. if (r) {
  1771. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  1772. return r;
  1773. }
  1774. r = r600_audio_init(rdev);
  1775. if (r) {
  1776. DRM_ERROR("radeon: audio init failed\n");
  1777. return r;
  1778. }
  1779. return 0;
  1780. }
  1781. int rv770_resume(struct radeon_device *rdev)
  1782. {
  1783. int r;
  1784. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  1785. * posting will perform necessary task to bring back GPU into good
  1786. * shape.
  1787. */
  1788. /* post card */
  1789. atom_asic_init(rdev->mode_info.atom_context);
  1790. /* init golden registers */
  1791. rv770_init_golden_registers(rdev);
  1792. rdev->accel_working = true;
  1793. r = rv770_startup(rdev);
  1794. if (r) {
  1795. DRM_ERROR("r600 startup failed on resume\n");
  1796. rdev->accel_working = false;
  1797. return r;
  1798. }
  1799. return r;
  1800. }
  1801. int rv770_suspend(struct radeon_device *rdev)
  1802. {
  1803. r600_audio_fini(rdev);
  1804. radeon_uvd_suspend(rdev);
  1805. r700_cp_stop(rdev);
  1806. r600_dma_stop(rdev);
  1807. r600_irq_suspend(rdev);
  1808. radeon_wb_disable(rdev);
  1809. rv770_pcie_gart_disable(rdev);
  1810. return 0;
  1811. }
  1812. /* Plan is to move initialization in that function and use
  1813. * helper function so that radeon_device_init pretty much
  1814. * do nothing more than calling asic specific function. This
  1815. * should also allow to remove a bunch of callback function
  1816. * like vram_info.
  1817. */
  1818. int rv770_init(struct radeon_device *rdev)
  1819. {
  1820. int r;
  1821. /* Read BIOS */
  1822. if (!radeon_get_bios(rdev)) {
  1823. if (ASIC_IS_AVIVO(rdev))
  1824. return -EINVAL;
  1825. }
  1826. /* Must be an ATOMBIOS */
  1827. if (!rdev->is_atom_bios) {
  1828. dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
  1829. return -EINVAL;
  1830. }
  1831. r = radeon_atombios_init(rdev);
  1832. if (r)
  1833. return r;
  1834. /* Post card if necessary */
  1835. if (!radeon_card_posted(rdev)) {
  1836. if (!rdev->bios) {
  1837. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  1838. return -EINVAL;
  1839. }
  1840. DRM_INFO("GPU not posted. posting now...\n");
  1841. atom_asic_init(rdev->mode_info.atom_context);
  1842. }
  1843. /* init golden registers */
  1844. rv770_init_golden_registers(rdev);
  1845. /* Initialize scratch registers */
  1846. r600_scratch_init(rdev);
  1847. /* Initialize surface registers */
  1848. radeon_surface_init(rdev);
  1849. /* Initialize clocks */
  1850. radeon_get_clock_info(rdev->ddev);
  1851. /* Fence driver */
  1852. r = radeon_fence_driver_init(rdev);
  1853. if (r)
  1854. return r;
  1855. /* initialize AGP */
  1856. if (rdev->flags & RADEON_IS_AGP) {
  1857. r = radeon_agp_init(rdev);
  1858. if (r)
  1859. radeon_agp_disable(rdev);
  1860. }
  1861. r = rv770_mc_init(rdev);
  1862. if (r)
  1863. return r;
  1864. /* Memory manager */
  1865. r = radeon_bo_init(rdev);
  1866. if (r)
  1867. return r;
  1868. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  1869. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  1870. rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
  1871. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
  1872. r = radeon_uvd_init(rdev);
  1873. if (!r) {
  1874. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  1875. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX],
  1876. 4096);
  1877. }
  1878. rdev->ih.ring_obj = NULL;
  1879. r600_ih_ring_init(rdev, 64 * 1024);
  1880. r = r600_pcie_gart_init(rdev);
  1881. if (r)
  1882. return r;
  1883. rdev->accel_working = true;
  1884. r = rv770_startup(rdev);
  1885. if (r) {
  1886. dev_err(rdev->dev, "disabling GPU acceleration\n");
  1887. r700_cp_fini(rdev);
  1888. r600_dma_fini(rdev);
  1889. r600_irq_fini(rdev);
  1890. radeon_wb_fini(rdev);
  1891. radeon_ib_pool_fini(rdev);
  1892. radeon_irq_kms_fini(rdev);
  1893. rv770_pcie_gart_fini(rdev);
  1894. rdev->accel_working = false;
  1895. }
  1896. return 0;
  1897. }
  1898. void rv770_fini(struct radeon_device *rdev)
  1899. {
  1900. r600_blit_fini(rdev);
  1901. r700_cp_fini(rdev);
  1902. r600_dma_fini(rdev);
  1903. r600_irq_fini(rdev);
  1904. radeon_wb_fini(rdev);
  1905. radeon_ib_pool_fini(rdev);
  1906. radeon_irq_kms_fini(rdev);
  1907. rv770_pcie_gart_fini(rdev);
  1908. radeon_uvd_fini(rdev);
  1909. r600_vram_scratch_fini(rdev);
  1910. radeon_gem_fini(rdev);
  1911. radeon_fence_driver_fini(rdev);
  1912. radeon_agp_fini(rdev);
  1913. radeon_bo_fini(rdev);
  1914. radeon_atombios_fini(rdev);
  1915. kfree(rdev->bios);
  1916. rdev->bios = NULL;
  1917. }
  1918. static void rv770_pcie_gen2_enable(struct radeon_device *rdev)
  1919. {
  1920. u32 link_width_cntl, lanes, speed_cntl, tmp;
  1921. u16 link_cntl2;
  1922. if (radeon_pcie_gen2 == 0)
  1923. return;
  1924. if (rdev->flags & RADEON_IS_IGP)
  1925. return;
  1926. if (!(rdev->flags & RADEON_IS_PCIE))
  1927. return;
  1928. /* x2 cards have a special sequence */
  1929. if (ASIC_IS_X2(rdev))
  1930. return;
  1931. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  1932. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  1933. return;
  1934. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  1935. /* advertise upconfig capability */
  1936. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  1937. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  1938. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  1939. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  1940. if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
  1941. lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
  1942. link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
  1943. LC_RECONFIG_ARC_MISSING_ESCAPE);
  1944. link_width_cntl |= lanes | LC_RECONFIG_NOW |
  1945. LC_RENEGOTIATE_EN | LC_UPCONFIGURE_SUPPORT;
  1946. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  1947. } else {
  1948. link_width_cntl |= LC_UPCONFIGURE_DIS;
  1949. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  1950. }
  1951. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1952. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  1953. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  1954. tmp = RREG32(0x541c);
  1955. WREG32(0x541c, tmp | 0x8);
  1956. WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
  1957. link_cntl2 = RREG16(0x4088);
  1958. link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
  1959. link_cntl2 |= 0x2;
  1960. WREG16(0x4088, link_cntl2);
  1961. WREG32(MM_CFGREGS_CNTL, 0);
  1962. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1963. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  1964. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  1965. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1966. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  1967. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  1968. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1969. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  1970. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  1971. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1972. speed_cntl |= LC_GEN2_EN_STRAP;
  1973. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  1974. } else {
  1975. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  1976. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  1977. if (1)
  1978. link_width_cntl |= LC_UPCONFIGURE_DIS;
  1979. else
  1980. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  1981. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  1982. }
  1983. }