rv770.c 58 KB

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