ni.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include <linux/module.h>
  28. #include "drmP.h"
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "radeon_drm.h"
  32. #include "nid.h"
  33. #include "atom.h"
  34. #include "ni_reg.h"
  35. #include "cayman_blit_shaders.h"
  36. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  37. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  38. extern int evergreen_mc_wait_for_idle(struct radeon_device *rdev);
  39. extern void evergreen_mc_program(struct radeon_device *rdev);
  40. extern void evergreen_irq_suspend(struct radeon_device *rdev);
  41. extern int evergreen_mc_init(struct radeon_device *rdev);
  42. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  43. extern void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  44. extern void si_rlc_fini(struct radeon_device *rdev);
  45. extern int si_rlc_init(struct radeon_device *rdev);
  46. #define EVERGREEN_PFP_UCODE_SIZE 1120
  47. #define EVERGREEN_PM4_UCODE_SIZE 1376
  48. #define EVERGREEN_RLC_UCODE_SIZE 768
  49. #define BTC_MC_UCODE_SIZE 6024
  50. #define CAYMAN_PFP_UCODE_SIZE 2176
  51. #define CAYMAN_PM4_UCODE_SIZE 2176
  52. #define CAYMAN_RLC_UCODE_SIZE 1024
  53. #define CAYMAN_MC_UCODE_SIZE 6037
  54. #define ARUBA_RLC_UCODE_SIZE 1536
  55. /* Firmware Names */
  56. MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
  57. MODULE_FIRMWARE("radeon/BARTS_me.bin");
  58. MODULE_FIRMWARE("radeon/BARTS_mc.bin");
  59. MODULE_FIRMWARE("radeon/BTC_rlc.bin");
  60. MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
  61. MODULE_FIRMWARE("radeon/TURKS_me.bin");
  62. MODULE_FIRMWARE("radeon/TURKS_mc.bin");
  63. MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
  64. MODULE_FIRMWARE("radeon/CAICOS_me.bin");
  65. MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
  66. MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin");
  67. MODULE_FIRMWARE("radeon/CAYMAN_me.bin");
  68. MODULE_FIRMWARE("radeon/CAYMAN_mc.bin");
  69. MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin");
  70. MODULE_FIRMWARE("radeon/ARUBA_pfp.bin");
  71. MODULE_FIRMWARE("radeon/ARUBA_me.bin");
  72. MODULE_FIRMWARE("radeon/ARUBA_rlc.bin");
  73. #define BTC_IO_MC_REGS_SIZE 29
  74. static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  75. {0x00000077, 0xff010100},
  76. {0x00000078, 0x00000000},
  77. {0x00000079, 0x00001434},
  78. {0x0000007a, 0xcc08ec08},
  79. {0x0000007b, 0x00040000},
  80. {0x0000007c, 0x000080c0},
  81. {0x0000007d, 0x09000000},
  82. {0x0000007e, 0x00210404},
  83. {0x00000081, 0x08a8e800},
  84. {0x00000082, 0x00030444},
  85. {0x00000083, 0x00000000},
  86. {0x00000085, 0x00000001},
  87. {0x00000086, 0x00000002},
  88. {0x00000087, 0x48490000},
  89. {0x00000088, 0x20244647},
  90. {0x00000089, 0x00000005},
  91. {0x0000008b, 0x66030000},
  92. {0x0000008c, 0x00006603},
  93. {0x0000008d, 0x00000100},
  94. {0x0000008f, 0x00001c0a},
  95. {0x00000090, 0xff000001},
  96. {0x00000094, 0x00101101},
  97. {0x00000095, 0x00000fff},
  98. {0x00000096, 0x00116fff},
  99. {0x00000097, 0x60010000},
  100. {0x00000098, 0x10010000},
  101. {0x00000099, 0x00006000},
  102. {0x0000009a, 0x00001000},
  103. {0x0000009f, 0x00946a00}
  104. };
  105. static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  106. {0x00000077, 0xff010100},
  107. {0x00000078, 0x00000000},
  108. {0x00000079, 0x00001434},
  109. {0x0000007a, 0xcc08ec08},
  110. {0x0000007b, 0x00040000},
  111. {0x0000007c, 0x000080c0},
  112. {0x0000007d, 0x09000000},
  113. {0x0000007e, 0x00210404},
  114. {0x00000081, 0x08a8e800},
  115. {0x00000082, 0x00030444},
  116. {0x00000083, 0x00000000},
  117. {0x00000085, 0x00000001},
  118. {0x00000086, 0x00000002},
  119. {0x00000087, 0x48490000},
  120. {0x00000088, 0x20244647},
  121. {0x00000089, 0x00000005},
  122. {0x0000008b, 0x66030000},
  123. {0x0000008c, 0x00006603},
  124. {0x0000008d, 0x00000100},
  125. {0x0000008f, 0x00001c0a},
  126. {0x00000090, 0xff000001},
  127. {0x00000094, 0x00101101},
  128. {0x00000095, 0x00000fff},
  129. {0x00000096, 0x00116fff},
  130. {0x00000097, 0x60010000},
  131. {0x00000098, 0x10010000},
  132. {0x00000099, 0x00006000},
  133. {0x0000009a, 0x00001000},
  134. {0x0000009f, 0x00936a00}
  135. };
  136. static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  137. {0x00000077, 0xff010100},
  138. {0x00000078, 0x00000000},
  139. {0x00000079, 0x00001434},
  140. {0x0000007a, 0xcc08ec08},
  141. {0x0000007b, 0x00040000},
  142. {0x0000007c, 0x000080c0},
  143. {0x0000007d, 0x09000000},
  144. {0x0000007e, 0x00210404},
  145. {0x00000081, 0x08a8e800},
  146. {0x00000082, 0x00030444},
  147. {0x00000083, 0x00000000},
  148. {0x00000085, 0x00000001},
  149. {0x00000086, 0x00000002},
  150. {0x00000087, 0x48490000},
  151. {0x00000088, 0x20244647},
  152. {0x00000089, 0x00000005},
  153. {0x0000008b, 0x66030000},
  154. {0x0000008c, 0x00006603},
  155. {0x0000008d, 0x00000100},
  156. {0x0000008f, 0x00001c0a},
  157. {0x00000090, 0xff000001},
  158. {0x00000094, 0x00101101},
  159. {0x00000095, 0x00000fff},
  160. {0x00000096, 0x00116fff},
  161. {0x00000097, 0x60010000},
  162. {0x00000098, 0x10010000},
  163. {0x00000099, 0x00006000},
  164. {0x0000009a, 0x00001000},
  165. {0x0000009f, 0x00916a00}
  166. };
  167. static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  168. {0x00000077, 0xff010100},
  169. {0x00000078, 0x00000000},
  170. {0x00000079, 0x00001434},
  171. {0x0000007a, 0xcc08ec08},
  172. {0x0000007b, 0x00040000},
  173. {0x0000007c, 0x000080c0},
  174. {0x0000007d, 0x09000000},
  175. {0x0000007e, 0x00210404},
  176. {0x00000081, 0x08a8e800},
  177. {0x00000082, 0x00030444},
  178. {0x00000083, 0x00000000},
  179. {0x00000085, 0x00000001},
  180. {0x00000086, 0x00000002},
  181. {0x00000087, 0x48490000},
  182. {0x00000088, 0x20244647},
  183. {0x00000089, 0x00000005},
  184. {0x0000008b, 0x66030000},
  185. {0x0000008c, 0x00006603},
  186. {0x0000008d, 0x00000100},
  187. {0x0000008f, 0x00001c0a},
  188. {0x00000090, 0xff000001},
  189. {0x00000094, 0x00101101},
  190. {0x00000095, 0x00000fff},
  191. {0x00000096, 0x00116fff},
  192. {0x00000097, 0x60010000},
  193. {0x00000098, 0x10010000},
  194. {0x00000099, 0x00006000},
  195. {0x0000009a, 0x00001000},
  196. {0x0000009f, 0x00976b00}
  197. };
  198. int ni_mc_load_microcode(struct radeon_device *rdev)
  199. {
  200. const __be32 *fw_data;
  201. u32 mem_type, running, blackout = 0;
  202. u32 *io_mc_regs;
  203. int i, ucode_size, regs_size;
  204. if (!rdev->mc_fw)
  205. return -EINVAL;
  206. switch (rdev->family) {
  207. case CHIP_BARTS:
  208. io_mc_regs = (u32 *)&barts_io_mc_regs;
  209. ucode_size = BTC_MC_UCODE_SIZE;
  210. regs_size = BTC_IO_MC_REGS_SIZE;
  211. break;
  212. case CHIP_TURKS:
  213. io_mc_regs = (u32 *)&turks_io_mc_regs;
  214. ucode_size = BTC_MC_UCODE_SIZE;
  215. regs_size = BTC_IO_MC_REGS_SIZE;
  216. break;
  217. case CHIP_CAICOS:
  218. default:
  219. io_mc_regs = (u32 *)&caicos_io_mc_regs;
  220. ucode_size = BTC_MC_UCODE_SIZE;
  221. regs_size = BTC_IO_MC_REGS_SIZE;
  222. break;
  223. case CHIP_CAYMAN:
  224. io_mc_regs = (u32 *)&cayman_io_mc_regs;
  225. ucode_size = CAYMAN_MC_UCODE_SIZE;
  226. regs_size = BTC_IO_MC_REGS_SIZE;
  227. break;
  228. }
  229. mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
  230. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  231. if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
  232. if (running) {
  233. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  234. WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
  235. }
  236. /* reset the engine and set to writable */
  237. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  238. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  239. /* load mc io regs */
  240. for (i = 0; i < regs_size; i++) {
  241. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  242. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  243. }
  244. /* load the MC ucode */
  245. fw_data = (const __be32 *)rdev->mc_fw->data;
  246. for (i = 0; i < ucode_size; i++)
  247. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  248. /* put the engine back into the active state */
  249. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  250. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  251. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  252. /* wait for training to complete */
  253. for (i = 0; i < rdev->usec_timeout; i++) {
  254. if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
  255. break;
  256. udelay(1);
  257. }
  258. if (running)
  259. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  260. }
  261. return 0;
  262. }
  263. int ni_init_microcode(struct radeon_device *rdev)
  264. {
  265. struct platform_device *pdev;
  266. const char *chip_name;
  267. const char *rlc_chip_name;
  268. size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
  269. char fw_name[30];
  270. int err;
  271. DRM_DEBUG("\n");
  272. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  273. err = IS_ERR(pdev);
  274. if (err) {
  275. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  276. return -EINVAL;
  277. }
  278. switch (rdev->family) {
  279. case CHIP_BARTS:
  280. chip_name = "BARTS";
  281. rlc_chip_name = "BTC";
  282. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  283. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  284. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  285. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  286. break;
  287. case CHIP_TURKS:
  288. chip_name = "TURKS";
  289. rlc_chip_name = "BTC";
  290. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  291. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  292. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  293. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  294. break;
  295. case CHIP_CAICOS:
  296. chip_name = "CAICOS";
  297. rlc_chip_name = "BTC";
  298. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  299. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  300. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  301. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  302. break;
  303. case CHIP_CAYMAN:
  304. chip_name = "CAYMAN";
  305. rlc_chip_name = "CAYMAN";
  306. pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
  307. me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
  308. rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4;
  309. mc_req_size = CAYMAN_MC_UCODE_SIZE * 4;
  310. break;
  311. case CHIP_ARUBA:
  312. chip_name = "ARUBA";
  313. rlc_chip_name = "ARUBA";
  314. /* pfp/me same size as CAYMAN */
  315. pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
  316. me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
  317. rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4;
  318. mc_req_size = 0;
  319. break;
  320. default: BUG();
  321. }
  322. DRM_INFO("Loading %s Microcode\n", chip_name);
  323. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  324. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  325. if (err)
  326. goto out;
  327. if (rdev->pfp_fw->size != pfp_req_size) {
  328. printk(KERN_ERR
  329. "ni_cp: Bogus length %zu in firmware \"%s\"\n",
  330. rdev->pfp_fw->size, fw_name);
  331. err = -EINVAL;
  332. goto out;
  333. }
  334. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  335. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  336. if (err)
  337. goto out;
  338. if (rdev->me_fw->size != me_req_size) {
  339. printk(KERN_ERR
  340. "ni_cp: Bogus length %zu in firmware \"%s\"\n",
  341. rdev->me_fw->size, fw_name);
  342. err = -EINVAL;
  343. }
  344. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  345. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  346. if (err)
  347. goto out;
  348. if (rdev->rlc_fw->size != rlc_req_size) {
  349. printk(KERN_ERR
  350. "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
  351. rdev->rlc_fw->size, fw_name);
  352. err = -EINVAL;
  353. }
  354. /* no MC ucode on TN */
  355. if (!(rdev->flags & RADEON_IS_IGP)) {
  356. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  357. err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
  358. if (err)
  359. goto out;
  360. if (rdev->mc_fw->size != mc_req_size) {
  361. printk(KERN_ERR
  362. "ni_mc: Bogus length %zu in firmware \"%s\"\n",
  363. rdev->mc_fw->size, fw_name);
  364. err = -EINVAL;
  365. }
  366. }
  367. out:
  368. platform_device_unregister(pdev);
  369. if (err) {
  370. if (err != -EINVAL)
  371. printk(KERN_ERR
  372. "ni_cp: Failed to load firmware \"%s\"\n",
  373. fw_name);
  374. release_firmware(rdev->pfp_fw);
  375. rdev->pfp_fw = NULL;
  376. release_firmware(rdev->me_fw);
  377. rdev->me_fw = NULL;
  378. release_firmware(rdev->rlc_fw);
  379. rdev->rlc_fw = NULL;
  380. release_firmware(rdev->mc_fw);
  381. rdev->mc_fw = NULL;
  382. }
  383. return err;
  384. }
  385. /*
  386. * Core functions
  387. */
  388. static u32 cayman_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
  389. u32 num_tile_pipes,
  390. u32 num_backends_per_asic,
  391. u32 *backend_disable_mask_per_asic,
  392. u32 num_shader_engines)
  393. {
  394. u32 backend_map = 0;
  395. u32 enabled_backends_mask = 0;
  396. u32 enabled_backends_count = 0;
  397. u32 num_backends_per_se;
  398. u32 cur_pipe;
  399. u32 swizzle_pipe[CAYMAN_MAX_PIPES];
  400. u32 cur_backend = 0;
  401. u32 i;
  402. bool force_no_swizzle;
  403. /* force legal values */
  404. if (num_tile_pipes < 1)
  405. num_tile_pipes = 1;
  406. if (num_tile_pipes > rdev->config.cayman.max_tile_pipes)
  407. num_tile_pipes = rdev->config.cayman.max_tile_pipes;
  408. if (num_shader_engines < 1)
  409. num_shader_engines = 1;
  410. if (num_shader_engines > rdev->config.cayman.max_shader_engines)
  411. num_shader_engines = rdev->config.cayman.max_shader_engines;
  412. if (num_backends_per_asic < num_shader_engines)
  413. num_backends_per_asic = num_shader_engines;
  414. if (num_backends_per_asic > (rdev->config.cayman.max_backends_per_se * num_shader_engines))
  415. num_backends_per_asic = rdev->config.cayman.max_backends_per_se * num_shader_engines;
  416. /* make sure we have the same number of backends per se */
  417. num_backends_per_asic = ALIGN(num_backends_per_asic, num_shader_engines);
  418. /* set up the number of backends per se */
  419. num_backends_per_se = num_backends_per_asic / num_shader_engines;
  420. if (num_backends_per_se > rdev->config.cayman.max_backends_per_se) {
  421. num_backends_per_se = rdev->config.cayman.max_backends_per_se;
  422. num_backends_per_asic = num_backends_per_se * num_shader_engines;
  423. }
  424. /* create enable mask and count for enabled backends */
  425. for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
  426. if (((*backend_disable_mask_per_asic >> i) & 1) == 0) {
  427. enabled_backends_mask |= (1 << i);
  428. ++enabled_backends_count;
  429. }
  430. if (enabled_backends_count == num_backends_per_asic)
  431. break;
  432. }
  433. /* force the backends mask to match the current number of backends */
  434. if (enabled_backends_count != num_backends_per_asic) {
  435. u32 this_backend_enabled;
  436. u32 shader_engine;
  437. u32 backend_per_se;
  438. enabled_backends_mask = 0;
  439. enabled_backends_count = 0;
  440. *backend_disable_mask_per_asic = CAYMAN_MAX_BACKENDS_MASK;
  441. for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
  442. /* calc the current se */
  443. shader_engine = i / rdev->config.cayman.max_backends_per_se;
  444. /* calc the backend per se */
  445. backend_per_se = i % rdev->config.cayman.max_backends_per_se;
  446. /* default to not enabled */
  447. this_backend_enabled = 0;
  448. if ((shader_engine < num_shader_engines) &&
  449. (backend_per_se < num_backends_per_se))
  450. this_backend_enabled = 1;
  451. if (this_backend_enabled) {
  452. enabled_backends_mask |= (1 << i);
  453. *backend_disable_mask_per_asic &= ~(1 << i);
  454. ++enabled_backends_count;
  455. }
  456. }
  457. }
  458. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * CAYMAN_MAX_PIPES);
  459. switch (rdev->family) {
  460. case CHIP_CAYMAN:
  461. case CHIP_ARUBA:
  462. force_no_swizzle = true;
  463. break;
  464. default:
  465. force_no_swizzle = false;
  466. break;
  467. }
  468. if (force_no_swizzle) {
  469. bool last_backend_enabled = false;
  470. force_no_swizzle = false;
  471. for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
  472. if (((enabled_backends_mask >> i) & 1) == 1) {
  473. if (last_backend_enabled)
  474. force_no_swizzle = true;
  475. last_backend_enabled = true;
  476. } else
  477. last_backend_enabled = false;
  478. }
  479. }
  480. switch (num_tile_pipes) {
  481. case 1:
  482. case 3:
  483. case 5:
  484. case 7:
  485. DRM_ERROR("odd number of pipes!\n");
  486. break;
  487. case 2:
  488. swizzle_pipe[0] = 0;
  489. swizzle_pipe[1] = 1;
  490. break;
  491. case 4:
  492. if (force_no_swizzle) {
  493. swizzle_pipe[0] = 0;
  494. swizzle_pipe[1] = 1;
  495. swizzle_pipe[2] = 2;
  496. swizzle_pipe[3] = 3;
  497. } else {
  498. swizzle_pipe[0] = 0;
  499. swizzle_pipe[1] = 2;
  500. swizzle_pipe[2] = 1;
  501. swizzle_pipe[3] = 3;
  502. }
  503. break;
  504. case 6:
  505. if (force_no_swizzle) {
  506. swizzle_pipe[0] = 0;
  507. swizzle_pipe[1] = 1;
  508. swizzle_pipe[2] = 2;
  509. swizzle_pipe[3] = 3;
  510. swizzle_pipe[4] = 4;
  511. swizzle_pipe[5] = 5;
  512. } else {
  513. swizzle_pipe[0] = 0;
  514. swizzle_pipe[1] = 2;
  515. swizzle_pipe[2] = 4;
  516. swizzle_pipe[3] = 1;
  517. swizzle_pipe[4] = 3;
  518. swizzle_pipe[5] = 5;
  519. }
  520. break;
  521. case 8:
  522. if (force_no_swizzle) {
  523. swizzle_pipe[0] = 0;
  524. swizzle_pipe[1] = 1;
  525. swizzle_pipe[2] = 2;
  526. swizzle_pipe[3] = 3;
  527. swizzle_pipe[4] = 4;
  528. swizzle_pipe[5] = 5;
  529. swizzle_pipe[6] = 6;
  530. swizzle_pipe[7] = 7;
  531. } else {
  532. swizzle_pipe[0] = 0;
  533. swizzle_pipe[1] = 2;
  534. swizzle_pipe[2] = 4;
  535. swizzle_pipe[3] = 6;
  536. swizzle_pipe[4] = 1;
  537. swizzle_pipe[5] = 3;
  538. swizzle_pipe[6] = 5;
  539. swizzle_pipe[7] = 7;
  540. }
  541. break;
  542. }
  543. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  544. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  545. cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS;
  546. backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4)));
  547. cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS;
  548. }
  549. return backend_map;
  550. }
  551. static u32 cayman_get_disable_mask_per_asic(struct radeon_device *rdev,
  552. u32 disable_mask_per_se,
  553. u32 max_disable_mask_per_se,
  554. u32 num_shader_engines)
  555. {
  556. u32 disable_field_width_per_se = r600_count_pipe_bits(disable_mask_per_se);
  557. u32 disable_mask_per_asic = disable_mask_per_se & max_disable_mask_per_se;
  558. if (num_shader_engines == 1)
  559. return disable_mask_per_asic;
  560. else if (num_shader_engines == 2)
  561. return disable_mask_per_asic | (disable_mask_per_asic << disable_field_width_per_se);
  562. else
  563. return 0xffffffff;
  564. }
  565. static void cayman_gpu_init(struct radeon_device *rdev)
  566. {
  567. u32 cc_rb_backend_disable = 0;
  568. u32 cc_gc_shader_pipe_config;
  569. u32 gb_addr_config = 0;
  570. u32 mc_shared_chmap, mc_arb_ramcfg;
  571. u32 gb_backend_map;
  572. u32 cgts_tcc_disable;
  573. u32 sx_debug_1;
  574. u32 smx_dc_ctl0;
  575. u32 gc_user_shader_pipe_config;
  576. u32 gc_user_rb_backend_disable;
  577. u32 cgts_user_tcc_disable;
  578. u32 cgts_sm_ctrl_reg;
  579. u32 hdp_host_path_cntl;
  580. u32 tmp;
  581. int i, j;
  582. switch (rdev->family) {
  583. case CHIP_CAYMAN:
  584. rdev->config.cayman.max_shader_engines = 2;
  585. rdev->config.cayman.max_pipes_per_simd = 4;
  586. rdev->config.cayman.max_tile_pipes = 8;
  587. rdev->config.cayman.max_simds_per_se = 12;
  588. rdev->config.cayman.max_backends_per_se = 4;
  589. rdev->config.cayman.max_texture_channel_caches = 8;
  590. rdev->config.cayman.max_gprs = 256;
  591. rdev->config.cayman.max_threads = 256;
  592. rdev->config.cayman.max_gs_threads = 32;
  593. rdev->config.cayman.max_stack_entries = 512;
  594. rdev->config.cayman.sx_num_of_sets = 8;
  595. rdev->config.cayman.sx_max_export_size = 256;
  596. rdev->config.cayman.sx_max_export_pos_size = 64;
  597. rdev->config.cayman.sx_max_export_smx_size = 192;
  598. rdev->config.cayman.max_hw_contexts = 8;
  599. rdev->config.cayman.sq_num_cf_insts = 2;
  600. rdev->config.cayman.sc_prim_fifo_size = 0x100;
  601. rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
  602. rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
  603. break;
  604. case CHIP_ARUBA:
  605. default:
  606. rdev->config.cayman.max_shader_engines = 1;
  607. rdev->config.cayman.max_pipes_per_simd = 4;
  608. rdev->config.cayman.max_tile_pipes = 2;
  609. if ((rdev->pdev->device == 0x9900) ||
  610. (rdev->pdev->device == 0x9901) ||
  611. (rdev->pdev->device == 0x9905) ||
  612. (rdev->pdev->device == 0x9906) ||
  613. (rdev->pdev->device == 0x9907) ||
  614. (rdev->pdev->device == 0x9908) ||
  615. (rdev->pdev->device == 0x9909) ||
  616. (rdev->pdev->device == 0x990B) ||
  617. (rdev->pdev->device == 0x990C) ||
  618. (rdev->pdev->device == 0x990F) ||
  619. (rdev->pdev->device == 0x9910) ||
  620. (rdev->pdev->device == 0x9917) ||
  621. (rdev->pdev->device == 0x9999) ||
  622. (rdev->pdev->device == 0x999C)) {
  623. rdev->config.cayman.max_simds_per_se = 6;
  624. rdev->config.cayman.max_backends_per_se = 2;
  625. rdev->config.cayman.max_hw_contexts = 8;
  626. rdev->config.cayman.sx_max_export_size = 256;
  627. rdev->config.cayman.sx_max_export_pos_size = 64;
  628. rdev->config.cayman.sx_max_export_smx_size = 192;
  629. } else if ((rdev->pdev->device == 0x9903) ||
  630. (rdev->pdev->device == 0x9904) ||
  631. (rdev->pdev->device == 0x990A) ||
  632. (rdev->pdev->device == 0x990D) ||
  633. (rdev->pdev->device == 0x990E) ||
  634. (rdev->pdev->device == 0x9913) ||
  635. (rdev->pdev->device == 0x9918) ||
  636. (rdev->pdev->device == 0x999D)) {
  637. rdev->config.cayman.max_simds_per_se = 4;
  638. rdev->config.cayman.max_backends_per_se = 2;
  639. rdev->config.cayman.max_hw_contexts = 8;
  640. rdev->config.cayman.sx_max_export_size = 256;
  641. rdev->config.cayman.sx_max_export_pos_size = 64;
  642. rdev->config.cayman.sx_max_export_smx_size = 192;
  643. } else if ((rdev->pdev->device == 0x9919) ||
  644. (rdev->pdev->device == 0x9990) ||
  645. (rdev->pdev->device == 0x9991) ||
  646. (rdev->pdev->device == 0x9994) ||
  647. (rdev->pdev->device == 0x9995) ||
  648. (rdev->pdev->device == 0x9996) ||
  649. (rdev->pdev->device == 0x999A) ||
  650. (rdev->pdev->device == 0x99A0)) {
  651. rdev->config.cayman.max_simds_per_se = 3;
  652. rdev->config.cayman.max_backends_per_se = 1;
  653. rdev->config.cayman.max_hw_contexts = 4;
  654. rdev->config.cayman.sx_max_export_size = 128;
  655. rdev->config.cayman.sx_max_export_pos_size = 32;
  656. rdev->config.cayman.sx_max_export_smx_size = 96;
  657. } else {
  658. rdev->config.cayman.max_simds_per_se = 2;
  659. rdev->config.cayman.max_backends_per_se = 1;
  660. rdev->config.cayman.max_hw_contexts = 4;
  661. rdev->config.cayman.sx_max_export_size = 128;
  662. rdev->config.cayman.sx_max_export_pos_size = 32;
  663. rdev->config.cayman.sx_max_export_smx_size = 96;
  664. }
  665. rdev->config.cayman.max_texture_channel_caches = 2;
  666. rdev->config.cayman.max_gprs = 256;
  667. rdev->config.cayman.max_threads = 256;
  668. rdev->config.cayman.max_gs_threads = 32;
  669. rdev->config.cayman.max_stack_entries = 512;
  670. rdev->config.cayman.sx_num_of_sets = 8;
  671. rdev->config.cayman.sq_num_cf_insts = 2;
  672. rdev->config.cayman.sc_prim_fifo_size = 0x40;
  673. rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
  674. rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
  675. break;
  676. }
  677. /* Initialize HDP */
  678. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  679. WREG32((0x2c14 + j), 0x00000000);
  680. WREG32((0x2c18 + j), 0x00000000);
  681. WREG32((0x2c1c + j), 0x00000000);
  682. WREG32((0x2c20 + j), 0x00000000);
  683. WREG32((0x2c24 + j), 0x00000000);
  684. }
  685. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  686. evergreen_fix_pci_max_read_req_size(rdev);
  687. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  688. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  689. cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE);
  690. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG);
  691. cgts_tcc_disable = 0xffff0000;
  692. for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
  693. cgts_tcc_disable &= ~(1 << (16 + i));
  694. gc_user_rb_backend_disable = RREG32(GC_USER_RB_BACKEND_DISABLE);
  695. gc_user_shader_pipe_config = RREG32(GC_USER_SHADER_PIPE_CONFIG);
  696. cgts_user_tcc_disable = RREG32(CGTS_USER_TCC_DISABLE);
  697. rdev->config.cayman.num_shader_engines = rdev->config.cayman.max_shader_engines;
  698. tmp = ((~gc_user_shader_pipe_config) & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT;
  699. rdev->config.cayman.num_shader_pipes_per_simd = r600_count_pipe_bits(tmp);
  700. rdev->config.cayman.num_tile_pipes = rdev->config.cayman.max_tile_pipes;
  701. tmp = ((~gc_user_shader_pipe_config) & INACTIVE_SIMDS_MASK) >> INACTIVE_SIMDS_SHIFT;
  702. rdev->config.cayman.num_simds_per_se = r600_count_pipe_bits(tmp);
  703. tmp = ((~gc_user_rb_backend_disable) & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT;
  704. rdev->config.cayman.num_backends_per_se = r600_count_pipe_bits(tmp);
  705. tmp = (gc_user_rb_backend_disable & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT;
  706. rdev->config.cayman.backend_disable_mask_per_asic =
  707. cayman_get_disable_mask_per_asic(rdev, tmp, CAYMAN_MAX_BACKENDS_PER_SE_MASK,
  708. rdev->config.cayman.num_shader_engines);
  709. rdev->config.cayman.backend_map =
  710. cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes,
  711. rdev->config.cayman.num_backends_per_se *
  712. rdev->config.cayman.num_shader_engines,
  713. &rdev->config.cayman.backend_disable_mask_per_asic,
  714. rdev->config.cayman.num_shader_engines);
  715. tmp = ((~cgts_user_tcc_disable) & TCC_DISABLE_MASK) >> TCC_DISABLE_SHIFT;
  716. rdev->config.cayman.num_texture_channel_caches = r600_count_pipe_bits(tmp);
  717. tmp = (mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT;
  718. rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
  719. if (rdev->config.cayman.mem_max_burst_length_bytes > 512)
  720. rdev->config.cayman.mem_max_burst_length_bytes = 512;
  721. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  722. rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  723. if (rdev->config.cayman.mem_row_size_in_kb > 4)
  724. rdev->config.cayman.mem_row_size_in_kb = 4;
  725. /* XXX use MC settings? */
  726. rdev->config.cayman.shader_engine_tile_size = 32;
  727. rdev->config.cayman.num_gpus = 1;
  728. rdev->config.cayman.multi_gpu_tile_size = 64;
  729. //gb_addr_config = 0x02011003
  730. #if 0
  731. gb_addr_config = RREG32(GB_ADDR_CONFIG);
  732. #else
  733. gb_addr_config = 0;
  734. switch (rdev->config.cayman.num_tile_pipes) {
  735. case 1:
  736. default:
  737. gb_addr_config |= NUM_PIPES(0);
  738. break;
  739. case 2:
  740. gb_addr_config |= NUM_PIPES(1);
  741. break;
  742. case 4:
  743. gb_addr_config |= NUM_PIPES(2);
  744. break;
  745. case 8:
  746. gb_addr_config |= NUM_PIPES(3);
  747. break;
  748. }
  749. tmp = (rdev->config.cayman.mem_max_burst_length_bytes / 256) - 1;
  750. gb_addr_config |= PIPE_INTERLEAVE_SIZE(tmp);
  751. gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.cayman.num_shader_engines - 1);
  752. tmp = (rdev->config.cayman.shader_engine_tile_size / 16) - 1;
  753. gb_addr_config |= SHADER_ENGINE_TILE_SIZE(tmp);
  754. switch (rdev->config.cayman.num_gpus) {
  755. case 1:
  756. default:
  757. gb_addr_config |= NUM_GPUS(0);
  758. break;
  759. case 2:
  760. gb_addr_config |= NUM_GPUS(1);
  761. break;
  762. case 4:
  763. gb_addr_config |= NUM_GPUS(2);
  764. break;
  765. }
  766. switch (rdev->config.cayman.multi_gpu_tile_size) {
  767. case 16:
  768. gb_addr_config |= MULTI_GPU_TILE_SIZE(0);
  769. break;
  770. case 32:
  771. default:
  772. gb_addr_config |= MULTI_GPU_TILE_SIZE(1);
  773. break;
  774. case 64:
  775. gb_addr_config |= MULTI_GPU_TILE_SIZE(2);
  776. break;
  777. case 128:
  778. gb_addr_config |= MULTI_GPU_TILE_SIZE(3);
  779. break;
  780. }
  781. switch (rdev->config.cayman.mem_row_size_in_kb) {
  782. case 1:
  783. default:
  784. gb_addr_config |= ROW_SIZE(0);
  785. break;
  786. case 2:
  787. gb_addr_config |= ROW_SIZE(1);
  788. break;
  789. case 4:
  790. gb_addr_config |= ROW_SIZE(2);
  791. break;
  792. }
  793. #endif
  794. tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
  795. rdev->config.cayman.num_tile_pipes = (1 << tmp);
  796. tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
  797. rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
  798. tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT;
  799. rdev->config.cayman.num_shader_engines = tmp + 1;
  800. tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT;
  801. rdev->config.cayman.num_gpus = tmp + 1;
  802. tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT;
  803. rdev->config.cayman.multi_gpu_tile_size = 1 << tmp;
  804. tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
  805. rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
  806. //gb_backend_map = 0x76541032;
  807. #if 0
  808. gb_backend_map = RREG32(GB_BACKEND_MAP);
  809. #else
  810. gb_backend_map =
  811. cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes,
  812. rdev->config.cayman.num_backends_per_se *
  813. rdev->config.cayman.num_shader_engines,
  814. &rdev->config.cayman.backend_disable_mask_per_asic,
  815. rdev->config.cayman.num_shader_engines);
  816. #endif
  817. /* setup tiling info dword. gb_addr_config is not adequate since it does
  818. * not have bank info, so create a custom tiling dword.
  819. * bits 3:0 num_pipes
  820. * bits 7:4 num_banks
  821. * bits 11:8 group_size
  822. * bits 15:12 row_size
  823. */
  824. rdev->config.cayman.tile_config = 0;
  825. switch (rdev->config.cayman.num_tile_pipes) {
  826. case 1:
  827. default:
  828. rdev->config.cayman.tile_config |= (0 << 0);
  829. break;
  830. case 2:
  831. rdev->config.cayman.tile_config |= (1 << 0);
  832. break;
  833. case 4:
  834. rdev->config.cayman.tile_config |= (2 << 0);
  835. break;
  836. case 8:
  837. rdev->config.cayman.tile_config |= (3 << 0);
  838. break;
  839. }
  840. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  841. if (rdev->flags & RADEON_IS_IGP)
  842. rdev->config.cayman.tile_config |= 1 << 4;
  843. else {
  844. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  845. case 0: /* four banks */
  846. rdev->config.cayman.tile_config |= 0 << 4;
  847. break;
  848. case 1: /* eight banks */
  849. rdev->config.cayman.tile_config |= 1 << 4;
  850. break;
  851. case 2: /* sixteen banks */
  852. default:
  853. rdev->config.cayman.tile_config |= 2 << 4;
  854. break;
  855. }
  856. }
  857. rdev->config.cayman.tile_config |=
  858. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  859. rdev->config.cayman.tile_config |=
  860. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  861. rdev->config.cayman.backend_map = gb_backend_map;
  862. WREG32(GB_BACKEND_MAP, gb_backend_map);
  863. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  864. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  865. if (ASIC_IS_DCE6(rdev))
  866. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  867. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  868. /* primary versions */
  869. WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  870. WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  871. WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  872. WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
  873. WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
  874. /* user versions */
  875. WREG32(GC_USER_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  876. WREG32(GC_USER_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  877. WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  878. WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
  879. WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
  880. /* reprogram the shader complex */
  881. cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG);
  882. for (i = 0; i < 16; i++)
  883. WREG32(CGTS_SM_CTRL_REG, OVERRIDE);
  884. WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
  885. /* set HW defaults for 3D engine */
  886. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  887. sx_debug_1 = RREG32(SX_DEBUG_1);
  888. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  889. WREG32(SX_DEBUG_1, sx_debug_1);
  890. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  891. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  892. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets);
  893. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  894. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE);
  895. /* need to be explicitly zero-ed */
  896. WREG32(VGT_OFFCHIP_LDS_BASE, 0);
  897. WREG32(SQ_LSTMP_RING_BASE, 0);
  898. WREG32(SQ_HSTMP_RING_BASE, 0);
  899. WREG32(SQ_ESTMP_RING_BASE, 0);
  900. WREG32(SQ_GSTMP_RING_BASE, 0);
  901. WREG32(SQ_VSTMP_RING_BASE, 0);
  902. WREG32(SQ_PSTMP_RING_BASE, 0);
  903. WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO);
  904. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) |
  905. POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) |
  906. SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1)));
  907. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) |
  908. SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) |
  909. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size)));
  910. WREG32(VGT_NUM_INSTANCES, 1);
  911. WREG32(CP_PERFMON_CNTL, 0);
  912. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) |
  913. FETCH_FIFO_HIWATER(0x4) |
  914. DONE_FIFO_HIWATER(0xe0) |
  915. ALU_UPDATE_FIFO_HIWATER(0x8)));
  916. WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4));
  917. WREG32(SQ_CONFIG, (VC_ENABLE |
  918. EXPORT_SRC_C |
  919. GFX_PRIO(0) |
  920. CS1_PRIO(0) |
  921. CS2_PRIO(1)));
  922. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE);
  923. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  924. FORCE_EOV_MAX_REZ_CNT(255)));
  925. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  926. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  927. WREG32(VGT_GS_VERTEX_REUSE, 16);
  928. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  929. WREG32(CB_PERF_CTR0_SEL_0, 0);
  930. WREG32(CB_PERF_CTR0_SEL_1, 0);
  931. WREG32(CB_PERF_CTR1_SEL_0, 0);
  932. WREG32(CB_PERF_CTR1_SEL_1, 0);
  933. WREG32(CB_PERF_CTR2_SEL_0, 0);
  934. WREG32(CB_PERF_CTR2_SEL_1, 0);
  935. WREG32(CB_PERF_CTR3_SEL_0, 0);
  936. WREG32(CB_PERF_CTR3_SEL_1, 0);
  937. tmp = RREG32(HDP_MISC_CNTL);
  938. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  939. WREG32(HDP_MISC_CNTL, tmp);
  940. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  941. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  942. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  943. udelay(50);
  944. }
  945. /*
  946. * GART
  947. */
  948. void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev)
  949. {
  950. /* flush hdp cache */
  951. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  952. /* bits 0-7 are the VM contexts0-7 */
  953. WREG32(VM_INVALIDATE_REQUEST, 1);
  954. }
  955. int cayman_pcie_gart_enable(struct radeon_device *rdev)
  956. {
  957. int i, r;
  958. if (rdev->gart.robj == NULL) {
  959. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  960. return -EINVAL;
  961. }
  962. r = radeon_gart_table_vram_pin(rdev);
  963. if (r)
  964. return r;
  965. radeon_gart_restore(rdev);
  966. /* Setup TLB control */
  967. WREG32(MC_VM_MX_L1_TLB_CNTL,
  968. (0xA << 7) |
  969. ENABLE_L1_TLB |
  970. ENABLE_L1_FRAGMENT_PROCESSING |
  971. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  972. ENABLE_ADVANCED_DRIVER_MODEL |
  973. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  974. /* Setup L2 cache */
  975. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  976. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  977. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  978. EFFECTIVE_L2_QUEUE_SIZE(7) |
  979. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  980. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  981. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  982. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  983. /* setup context0 */
  984. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  985. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  986. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  987. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  988. (u32)(rdev->dummy_page.addr >> 12));
  989. WREG32(VM_CONTEXT0_CNTL2, 0);
  990. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  991. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  992. WREG32(0x15D4, 0);
  993. WREG32(0x15D8, 0);
  994. WREG32(0x15DC, 0);
  995. /* empty context1-7 */
  996. for (i = 1; i < 8; i++) {
  997. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
  998. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), 0);
  999. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  1000. rdev->gart.table_addr >> 12);
  1001. }
  1002. /* enable context1-7 */
  1003. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  1004. (u32)(rdev->dummy_page.addr >> 12));
  1005. WREG32(VM_CONTEXT1_CNTL2, 0);
  1006. WREG32(VM_CONTEXT1_CNTL, 0);
  1007. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  1008. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  1009. cayman_pcie_gart_tlb_flush(rdev);
  1010. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  1011. (unsigned)(rdev->mc.gtt_size >> 20),
  1012. (unsigned long long)rdev->gart.table_addr);
  1013. rdev->gart.ready = true;
  1014. return 0;
  1015. }
  1016. void cayman_pcie_gart_disable(struct radeon_device *rdev)
  1017. {
  1018. /* Disable all tables */
  1019. WREG32(VM_CONTEXT0_CNTL, 0);
  1020. WREG32(VM_CONTEXT1_CNTL, 0);
  1021. /* Setup TLB control */
  1022. WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING |
  1023. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1024. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  1025. /* Setup L2 cache */
  1026. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1027. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  1028. EFFECTIVE_L2_QUEUE_SIZE(7) |
  1029. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  1030. WREG32(VM_L2_CNTL2, 0);
  1031. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  1032. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  1033. radeon_gart_table_vram_unpin(rdev);
  1034. }
  1035. void cayman_pcie_gart_fini(struct radeon_device *rdev)
  1036. {
  1037. cayman_pcie_gart_disable(rdev);
  1038. radeon_gart_table_vram_free(rdev);
  1039. radeon_gart_fini(rdev);
  1040. }
  1041. void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  1042. int ring, u32 cp_int_cntl)
  1043. {
  1044. u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3;
  1045. WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3));
  1046. WREG32(CP_INT_CNTL, cp_int_cntl);
  1047. }
  1048. /*
  1049. * CP.
  1050. */
  1051. void cayman_fence_ring_emit(struct radeon_device *rdev,
  1052. struct radeon_fence *fence)
  1053. {
  1054. struct radeon_ring *ring = &rdev->ring[fence->ring];
  1055. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  1056. /* flush read cache over gart for this vmid */
  1057. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1058. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  1059. radeon_ring_write(ring, 0);
  1060. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  1061. radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
  1062. radeon_ring_write(ring, 0xFFFFFFFF);
  1063. radeon_ring_write(ring, 0);
  1064. radeon_ring_write(ring, 10); /* poll interval */
  1065. /* EVENT_WRITE_EOP - flush caches, send int */
  1066. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  1067. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
  1068. radeon_ring_write(ring, addr & 0xffffffff);
  1069. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  1070. radeon_ring_write(ring, fence->seq);
  1071. radeon_ring_write(ring, 0);
  1072. }
  1073. void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  1074. {
  1075. struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
  1076. /* set to DX10/11 mode */
  1077. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  1078. radeon_ring_write(ring, 1);
  1079. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  1080. radeon_ring_write(ring,
  1081. #ifdef __BIG_ENDIAN
  1082. (2 << 0) |
  1083. #endif
  1084. (ib->gpu_addr & 0xFFFFFFFC));
  1085. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  1086. radeon_ring_write(ring, ib->length_dw | (ib->vm_id << 24));
  1087. /* flush read cache over gart for this vmid */
  1088. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1089. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  1090. radeon_ring_write(ring, ib->vm_id);
  1091. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  1092. radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
  1093. radeon_ring_write(ring, 0xFFFFFFFF);
  1094. radeon_ring_write(ring, 0);
  1095. radeon_ring_write(ring, 10); /* poll interval */
  1096. }
  1097. static void cayman_cp_enable(struct radeon_device *rdev, bool enable)
  1098. {
  1099. if (enable)
  1100. WREG32(CP_ME_CNTL, 0);
  1101. else {
  1102. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  1103. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
  1104. WREG32(SCRATCH_UMSK, 0);
  1105. }
  1106. }
  1107. static int cayman_cp_load_microcode(struct radeon_device *rdev)
  1108. {
  1109. const __be32 *fw_data;
  1110. int i;
  1111. if (!rdev->me_fw || !rdev->pfp_fw)
  1112. return -EINVAL;
  1113. cayman_cp_enable(rdev, false);
  1114. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1115. WREG32(CP_PFP_UCODE_ADDR, 0);
  1116. for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++)
  1117. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  1118. WREG32(CP_PFP_UCODE_ADDR, 0);
  1119. fw_data = (const __be32 *)rdev->me_fw->data;
  1120. WREG32(CP_ME_RAM_WADDR, 0);
  1121. for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++)
  1122. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  1123. WREG32(CP_PFP_UCODE_ADDR, 0);
  1124. WREG32(CP_ME_RAM_WADDR, 0);
  1125. WREG32(CP_ME_RAM_RADDR, 0);
  1126. return 0;
  1127. }
  1128. static int cayman_cp_start(struct radeon_device *rdev)
  1129. {
  1130. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1131. int r, i;
  1132. r = radeon_ring_lock(rdev, ring, 7);
  1133. if (r) {
  1134. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1135. return r;
  1136. }
  1137. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  1138. radeon_ring_write(ring, 0x1);
  1139. radeon_ring_write(ring, 0x0);
  1140. radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1);
  1141. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  1142. radeon_ring_write(ring, 0);
  1143. radeon_ring_write(ring, 0);
  1144. radeon_ring_unlock_commit(rdev, ring);
  1145. cayman_cp_enable(rdev, true);
  1146. r = radeon_ring_lock(rdev, ring, cayman_default_size + 19);
  1147. if (r) {
  1148. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1149. return r;
  1150. }
  1151. /* setup clear context state */
  1152. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1153. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  1154. for (i = 0; i < cayman_default_size; i++)
  1155. radeon_ring_write(ring, cayman_default_state[i]);
  1156. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1157. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  1158. /* set clear context state */
  1159. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  1160. radeon_ring_write(ring, 0);
  1161. /* SQ_VTX_BASE_VTX_LOC */
  1162. radeon_ring_write(ring, 0xc0026f00);
  1163. radeon_ring_write(ring, 0x00000000);
  1164. radeon_ring_write(ring, 0x00000000);
  1165. radeon_ring_write(ring, 0x00000000);
  1166. /* Clear consts */
  1167. radeon_ring_write(ring, 0xc0036f00);
  1168. radeon_ring_write(ring, 0x00000bc4);
  1169. radeon_ring_write(ring, 0xffffffff);
  1170. radeon_ring_write(ring, 0xffffffff);
  1171. radeon_ring_write(ring, 0xffffffff);
  1172. radeon_ring_write(ring, 0xc0026900);
  1173. radeon_ring_write(ring, 0x00000316);
  1174. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  1175. radeon_ring_write(ring, 0x00000010); /* */
  1176. radeon_ring_unlock_commit(rdev, ring);
  1177. /* XXX init other rings */
  1178. return 0;
  1179. }
  1180. static void cayman_cp_fini(struct radeon_device *rdev)
  1181. {
  1182. cayman_cp_enable(rdev, false);
  1183. radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  1184. }
  1185. int cayman_cp_resume(struct radeon_device *rdev)
  1186. {
  1187. struct radeon_ring *ring;
  1188. u32 tmp;
  1189. u32 rb_bufsz;
  1190. int r;
  1191. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  1192. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  1193. SOFT_RESET_PA |
  1194. SOFT_RESET_SH |
  1195. SOFT_RESET_VGT |
  1196. SOFT_RESET_SPI |
  1197. SOFT_RESET_SX));
  1198. RREG32(GRBM_SOFT_RESET);
  1199. mdelay(15);
  1200. WREG32(GRBM_SOFT_RESET, 0);
  1201. RREG32(GRBM_SOFT_RESET);
  1202. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  1203. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  1204. /* Set the write pointer delay */
  1205. WREG32(CP_RB_WPTR_DELAY, 0);
  1206. WREG32(CP_DEBUG, (1 << 27));
  1207. /* ring 0 - compute and gfx */
  1208. /* Set ring buffer size */
  1209. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1210. rb_bufsz = drm_order(ring->ring_size / 8);
  1211. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1212. #ifdef __BIG_ENDIAN
  1213. tmp |= BUF_SWAP_32BIT;
  1214. #endif
  1215. WREG32(CP_RB0_CNTL, tmp);
  1216. /* Initialize the ring buffer's read and write pointers */
  1217. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  1218. ring->wptr = 0;
  1219. WREG32(CP_RB0_WPTR, ring->wptr);
  1220. /* set the wb address wether it's enabled or not */
  1221. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  1222. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  1223. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  1224. if (rdev->wb.enabled)
  1225. WREG32(SCRATCH_UMSK, 0xff);
  1226. else {
  1227. tmp |= RB_NO_UPDATE;
  1228. WREG32(SCRATCH_UMSK, 0);
  1229. }
  1230. mdelay(1);
  1231. WREG32(CP_RB0_CNTL, tmp);
  1232. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  1233. ring->rptr = RREG32(CP_RB0_RPTR);
  1234. /* ring1 - compute only */
  1235. /* Set ring buffer size */
  1236. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  1237. rb_bufsz = drm_order(ring->ring_size / 8);
  1238. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1239. #ifdef __BIG_ENDIAN
  1240. tmp |= BUF_SWAP_32BIT;
  1241. #endif
  1242. WREG32(CP_RB1_CNTL, tmp);
  1243. /* Initialize the ring buffer's read and write pointers */
  1244. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  1245. ring->wptr = 0;
  1246. WREG32(CP_RB1_WPTR, ring->wptr);
  1247. /* set the wb address wether it's enabled or not */
  1248. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  1249. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  1250. mdelay(1);
  1251. WREG32(CP_RB1_CNTL, tmp);
  1252. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  1253. ring->rptr = RREG32(CP_RB1_RPTR);
  1254. /* ring2 - compute only */
  1255. /* Set ring buffer size */
  1256. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  1257. rb_bufsz = drm_order(ring->ring_size / 8);
  1258. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1259. #ifdef __BIG_ENDIAN
  1260. tmp |= BUF_SWAP_32BIT;
  1261. #endif
  1262. WREG32(CP_RB2_CNTL, tmp);
  1263. /* Initialize the ring buffer's read and write pointers */
  1264. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  1265. ring->wptr = 0;
  1266. WREG32(CP_RB2_WPTR, ring->wptr);
  1267. /* set the wb address wether it's enabled or not */
  1268. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  1269. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  1270. mdelay(1);
  1271. WREG32(CP_RB2_CNTL, tmp);
  1272. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  1273. ring->rptr = RREG32(CP_RB2_RPTR);
  1274. /* start the rings */
  1275. cayman_cp_start(rdev);
  1276. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  1277. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  1278. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  1279. /* this only test cp0 */
  1280. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  1281. if (r) {
  1282. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  1283. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  1284. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  1285. return r;
  1286. }
  1287. return 0;
  1288. }
  1289. bool cayman_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  1290. {
  1291. u32 srbm_status;
  1292. u32 grbm_status;
  1293. u32 grbm_status_se0, grbm_status_se1;
  1294. struct r100_gpu_lockup *lockup = &rdev->config.cayman.lockup;
  1295. int r;
  1296. srbm_status = RREG32(SRBM_STATUS);
  1297. grbm_status = RREG32(GRBM_STATUS);
  1298. grbm_status_se0 = RREG32(GRBM_STATUS_SE0);
  1299. grbm_status_se1 = RREG32(GRBM_STATUS_SE1);
  1300. if (!(grbm_status & GUI_ACTIVE)) {
  1301. r100_gpu_lockup_update(lockup, ring);
  1302. return false;
  1303. }
  1304. /* force CP activities */
  1305. r = radeon_ring_lock(rdev, ring, 2);
  1306. if (!r) {
  1307. /* PACKET2 NOP */
  1308. radeon_ring_write(ring, 0x80000000);
  1309. radeon_ring_write(ring, 0x80000000);
  1310. radeon_ring_unlock_commit(rdev, ring);
  1311. }
  1312. /* XXX deal with CP0,1,2 */
  1313. ring->rptr = RREG32(ring->rptr_reg);
  1314. return r100_gpu_cp_is_lockup(rdev, lockup, ring);
  1315. }
  1316. static int cayman_gpu_soft_reset(struct radeon_device *rdev)
  1317. {
  1318. struct evergreen_mc_save save;
  1319. u32 grbm_reset = 0;
  1320. if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
  1321. return 0;
  1322. dev_info(rdev->dev, "GPU softreset \n");
  1323. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  1324. RREG32(GRBM_STATUS));
  1325. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  1326. RREG32(GRBM_STATUS_SE0));
  1327. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  1328. RREG32(GRBM_STATUS_SE1));
  1329. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  1330. RREG32(SRBM_STATUS));
  1331. dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
  1332. RREG32(0x14F8));
  1333. dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
  1334. RREG32(0x14D8));
  1335. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  1336. RREG32(0x14FC));
  1337. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  1338. RREG32(0x14DC));
  1339. evergreen_mc_stop(rdev, &save);
  1340. if (evergreen_mc_wait_for_idle(rdev)) {
  1341. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1342. }
  1343. /* Disable CP parsing/prefetching */
  1344. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  1345. /* reset all the gfx blocks */
  1346. grbm_reset = (SOFT_RESET_CP |
  1347. SOFT_RESET_CB |
  1348. SOFT_RESET_DB |
  1349. SOFT_RESET_GDS |
  1350. SOFT_RESET_PA |
  1351. SOFT_RESET_SC |
  1352. SOFT_RESET_SPI |
  1353. SOFT_RESET_SH |
  1354. SOFT_RESET_SX |
  1355. SOFT_RESET_TC |
  1356. SOFT_RESET_TA |
  1357. SOFT_RESET_VGT |
  1358. SOFT_RESET_IA);
  1359. dev_info(rdev->dev, " GRBM_SOFT_RESET=0x%08X\n", grbm_reset);
  1360. WREG32(GRBM_SOFT_RESET, grbm_reset);
  1361. (void)RREG32(GRBM_SOFT_RESET);
  1362. udelay(50);
  1363. WREG32(GRBM_SOFT_RESET, 0);
  1364. (void)RREG32(GRBM_SOFT_RESET);
  1365. /* Wait a little for things to settle down */
  1366. udelay(50);
  1367. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  1368. RREG32(GRBM_STATUS));
  1369. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  1370. RREG32(GRBM_STATUS_SE0));
  1371. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  1372. RREG32(GRBM_STATUS_SE1));
  1373. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  1374. RREG32(SRBM_STATUS));
  1375. evergreen_mc_resume(rdev, &save);
  1376. return 0;
  1377. }
  1378. int cayman_asic_reset(struct radeon_device *rdev)
  1379. {
  1380. return cayman_gpu_soft_reset(rdev);
  1381. }
  1382. static int cayman_startup(struct radeon_device *rdev)
  1383. {
  1384. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1385. int r;
  1386. /* enable pcie gen2 link */
  1387. evergreen_pcie_gen2_enable(rdev);
  1388. evergreen_mc_program(rdev);
  1389. if (rdev->flags & RADEON_IS_IGP) {
  1390. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  1391. r = ni_init_microcode(rdev);
  1392. if (r) {
  1393. DRM_ERROR("Failed to load firmware!\n");
  1394. return r;
  1395. }
  1396. }
  1397. } else {
  1398. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  1399. r = ni_init_microcode(rdev);
  1400. if (r) {
  1401. DRM_ERROR("Failed to load firmware!\n");
  1402. return r;
  1403. }
  1404. }
  1405. r = ni_mc_load_microcode(rdev);
  1406. if (r) {
  1407. DRM_ERROR("Failed to load MC firmware!\n");
  1408. return r;
  1409. }
  1410. }
  1411. r = r600_vram_scratch_init(rdev);
  1412. if (r)
  1413. return r;
  1414. r = cayman_pcie_gart_enable(rdev);
  1415. if (r)
  1416. return r;
  1417. cayman_gpu_init(rdev);
  1418. r = evergreen_blit_init(rdev);
  1419. if (r) {
  1420. r600_blit_fini(rdev);
  1421. rdev->asic->copy.copy = NULL;
  1422. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  1423. }
  1424. /* allocate rlc buffers */
  1425. if (rdev->flags & RADEON_IS_IGP) {
  1426. r = si_rlc_init(rdev);
  1427. if (r) {
  1428. DRM_ERROR("Failed to init rlc BOs!\n");
  1429. return r;
  1430. }
  1431. }
  1432. /* allocate wb buffer */
  1433. r = radeon_wb_init(rdev);
  1434. if (r)
  1435. return r;
  1436. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  1437. if (r) {
  1438. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1439. return r;
  1440. }
  1441. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  1442. if (r) {
  1443. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1444. return r;
  1445. }
  1446. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  1447. if (r) {
  1448. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1449. return r;
  1450. }
  1451. /* Enable IRQ */
  1452. if (!rdev->irq.installed) {
  1453. r = radeon_irq_kms_init(rdev);
  1454. if (r)
  1455. return r;
  1456. }
  1457. r = r600_irq_init(rdev);
  1458. if (r) {
  1459. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  1460. radeon_irq_kms_fini(rdev);
  1461. return r;
  1462. }
  1463. evergreen_irq_set(rdev);
  1464. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  1465. CP_RB0_RPTR, CP_RB0_WPTR,
  1466. 0, 0xfffff, RADEON_CP_PACKET2);
  1467. if (r)
  1468. return r;
  1469. r = cayman_cp_load_microcode(rdev);
  1470. if (r)
  1471. return r;
  1472. r = cayman_cp_resume(rdev);
  1473. if (r)
  1474. return r;
  1475. r = radeon_ib_pool_start(rdev);
  1476. if (r)
  1477. return r;
  1478. r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  1479. if (r) {
  1480. DRM_ERROR("radeon: failed testing IB (%d).\n", r);
  1481. rdev->accel_working = false;
  1482. return r;
  1483. }
  1484. r = radeon_vm_manager_start(rdev);
  1485. if (r)
  1486. return r;
  1487. return 0;
  1488. }
  1489. int cayman_resume(struct radeon_device *rdev)
  1490. {
  1491. int r;
  1492. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  1493. * posting will perform necessary task to bring back GPU into good
  1494. * shape.
  1495. */
  1496. /* post card */
  1497. atom_asic_init(rdev->mode_info.atom_context);
  1498. rdev->accel_working = true;
  1499. r = cayman_startup(rdev);
  1500. if (r) {
  1501. DRM_ERROR("cayman startup failed on resume\n");
  1502. rdev->accel_working = false;
  1503. return r;
  1504. }
  1505. return r;
  1506. }
  1507. int cayman_suspend(struct radeon_device *rdev)
  1508. {
  1509. /* FIXME: we should wait for ring to be empty */
  1510. radeon_ib_pool_suspend(rdev);
  1511. radeon_vm_manager_suspend(rdev);
  1512. r600_blit_suspend(rdev);
  1513. cayman_cp_enable(rdev, false);
  1514. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  1515. evergreen_irq_suspend(rdev);
  1516. radeon_wb_disable(rdev);
  1517. cayman_pcie_gart_disable(rdev);
  1518. return 0;
  1519. }
  1520. /* Plan is to move initialization in that function and use
  1521. * helper function so that radeon_device_init pretty much
  1522. * do nothing more than calling asic specific function. This
  1523. * should also allow to remove a bunch of callback function
  1524. * like vram_info.
  1525. */
  1526. int cayman_init(struct radeon_device *rdev)
  1527. {
  1528. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1529. int r;
  1530. /* This don't do much */
  1531. r = radeon_gem_init(rdev);
  1532. if (r)
  1533. return r;
  1534. /* Read BIOS */
  1535. if (!radeon_get_bios(rdev)) {
  1536. if (ASIC_IS_AVIVO(rdev))
  1537. return -EINVAL;
  1538. }
  1539. /* Must be an ATOMBIOS */
  1540. if (!rdev->is_atom_bios) {
  1541. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  1542. return -EINVAL;
  1543. }
  1544. r = radeon_atombios_init(rdev);
  1545. if (r)
  1546. return r;
  1547. /* Post card if necessary */
  1548. if (!radeon_card_posted(rdev)) {
  1549. if (!rdev->bios) {
  1550. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  1551. return -EINVAL;
  1552. }
  1553. DRM_INFO("GPU not posted. posting now...\n");
  1554. atom_asic_init(rdev->mode_info.atom_context);
  1555. }
  1556. /* Initialize scratch registers */
  1557. r600_scratch_init(rdev);
  1558. /* Initialize surface registers */
  1559. radeon_surface_init(rdev);
  1560. /* Initialize clocks */
  1561. radeon_get_clock_info(rdev->ddev);
  1562. /* Fence driver */
  1563. r = radeon_fence_driver_init(rdev);
  1564. if (r)
  1565. return r;
  1566. /* initialize memory controller */
  1567. r = evergreen_mc_init(rdev);
  1568. if (r)
  1569. return r;
  1570. /* Memory manager */
  1571. r = radeon_bo_init(rdev);
  1572. if (r)
  1573. return r;
  1574. ring->ring_obj = NULL;
  1575. r600_ring_init(rdev, ring, 1024 * 1024);
  1576. rdev->ih.ring_obj = NULL;
  1577. r600_ih_ring_init(rdev, 64 * 1024);
  1578. r = r600_pcie_gart_init(rdev);
  1579. if (r)
  1580. return r;
  1581. r = radeon_ib_pool_init(rdev);
  1582. rdev->accel_working = true;
  1583. if (r) {
  1584. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  1585. rdev->accel_working = false;
  1586. }
  1587. r = radeon_vm_manager_init(rdev);
  1588. if (r) {
  1589. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  1590. }
  1591. r = cayman_startup(rdev);
  1592. if (r) {
  1593. dev_err(rdev->dev, "disabling GPU acceleration\n");
  1594. cayman_cp_fini(rdev);
  1595. r600_irq_fini(rdev);
  1596. if (rdev->flags & RADEON_IS_IGP)
  1597. si_rlc_fini(rdev);
  1598. radeon_wb_fini(rdev);
  1599. r100_ib_fini(rdev);
  1600. radeon_vm_manager_fini(rdev);
  1601. radeon_irq_kms_fini(rdev);
  1602. cayman_pcie_gart_fini(rdev);
  1603. rdev->accel_working = false;
  1604. }
  1605. /* Don't start up if the MC ucode is missing.
  1606. * The default clocks and voltages before the MC ucode
  1607. * is loaded are not suffient for advanced operations.
  1608. *
  1609. * We can skip this check for TN, because there is no MC
  1610. * ucode.
  1611. */
  1612. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  1613. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  1614. return -EINVAL;
  1615. }
  1616. return 0;
  1617. }
  1618. void cayman_fini(struct radeon_device *rdev)
  1619. {
  1620. r600_blit_fini(rdev);
  1621. cayman_cp_fini(rdev);
  1622. r600_irq_fini(rdev);
  1623. if (rdev->flags & RADEON_IS_IGP)
  1624. si_rlc_fini(rdev);
  1625. radeon_wb_fini(rdev);
  1626. radeon_vm_manager_fini(rdev);
  1627. r100_ib_fini(rdev);
  1628. radeon_irq_kms_fini(rdev);
  1629. cayman_pcie_gart_fini(rdev);
  1630. r600_vram_scratch_fini(rdev);
  1631. radeon_gem_fini(rdev);
  1632. radeon_semaphore_driver_fini(rdev);
  1633. radeon_fence_driver_fini(rdev);
  1634. radeon_bo_fini(rdev);
  1635. radeon_atombios_fini(rdev);
  1636. kfree(rdev->bios);
  1637. rdev->bios = NULL;
  1638. }
  1639. /*
  1640. * vm
  1641. */
  1642. int cayman_vm_init(struct radeon_device *rdev)
  1643. {
  1644. /* number of VMs */
  1645. rdev->vm_manager.nvm = 8;
  1646. /* base offset of vram pages */
  1647. if (rdev->flags & RADEON_IS_IGP) {
  1648. u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET);
  1649. tmp <<= 22;
  1650. rdev->vm_manager.vram_base_offset = tmp;
  1651. } else
  1652. rdev->vm_manager.vram_base_offset = 0;
  1653. return 0;
  1654. }
  1655. void cayman_vm_fini(struct radeon_device *rdev)
  1656. {
  1657. }
  1658. int cayman_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm, int id)
  1659. {
  1660. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (id << 2), 0);
  1661. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (id << 2), vm->last_pfn);
  1662. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (id << 2), vm->pt_gpu_addr >> 12);
  1663. /* flush hdp cache */
  1664. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  1665. /* bits 0-7 are the VM contexts0-7 */
  1666. WREG32(VM_INVALIDATE_REQUEST, 1 << id);
  1667. return 0;
  1668. }
  1669. void cayman_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm)
  1670. {
  1671. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (vm->id << 2), 0);
  1672. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (vm->id << 2), 0);
  1673. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0);
  1674. /* flush hdp cache */
  1675. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  1676. /* bits 0-7 are the VM contexts0-7 */
  1677. WREG32(VM_INVALIDATE_REQUEST, 1 << vm->id);
  1678. }
  1679. void cayman_vm_tlb_flush(struct radeon_device *rdev, struct radeon_vm *vm)
  1680. {
  1681. if (vm->id == -1)
  1682. return;
  1683. /* flush hdp cache */
  1684. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  1685. /* bits 0-7 are the VM contexts0-7 */
  1686. WREG32(VM_INVALIDATE_REQUEST, 1 << vm->id);
  1687. }
  1688. #define R600_PTE_VALID (1 << 0)
  1689. #define R600_PTE_SYSTEM (1 << 1)
  1690. #define R600_PTE_SNOOPED (1 << 2)
  1691. #define R600_PTE_READABLE (1 << 5)
  1692. #define R600_PTE_WRITEABLE (1 << 6)
  1693. uint32_t cayman_vm_page_flags(struct radeon_device *rdev,
  1694. struct radeon_vm *vm,
  1695. uint32_t flags)
  1696. {
  1697. uint32_t r600_flags = 0;
  1698. r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_PTE_VALID : 0;
  1699. r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0;
  1700. r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0;
  1701. if (flags & RADEON_VM_PAGE_SYSTEM) {
  1702. r600_flags |= R600_PTE_SYSTEM;
  1703. r600_flags |= (flags & RADEON_VM_PAGE_SNOOPED) ? R600_PTE_SNOOPED : 0;
  1704. }
  1705. return r600_flags;
  1706. }
  1707. void cayman_vm_set_page(struct radeon_device *rdev, struct radeon_vm *vm,
  1708. unsigned pfn, uint64_t addr, uint32_t flags)
  1709. {
  1710. void __iomem *ptr = (void *)vm->pt;
  1711. addr = addr & 0xFFFFFFFFFFFFF000ULL;
  1712. addr |= flags;
  1713. writeq(addr, ptr + (pfn * 8));
  1714. }