ni.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include "drmP.h"
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include "radeon_drm.h"
  31. #include "nid.h"
  32. #include "atom.h"
  33. #include "ni_reg.h"
  34. #define EVERGREEN_PFP_UCODE_SIZE 1120
  35. #define EVERGREEN_PM4_UCODE_SIZE 1376
  36. #define EVERGREEN_RLC_UCODE_SIZE 768
  37. #define BTC_MC_UCODE_SIZE 6024
  38. /* Firmware Names */
  39. MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
  40. MODULE_FIRMWARE("radeon/BARTS_me.bin");
  41. MODULE_FIRMWARE("radeon/BARTS_mc.bin");
  42. MODULE_FIRMWARE("radeon/BTC_rlc.bin");
  43. MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
  44. MODULE_FIRMWARE("radeon/TURKS_me.bin");
  45. MODULE_FIRMWARE("radeon/TURKS_mc.bin");
  46. MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
  47. MODULE_FIRMWARE("radeon/CAICOS_me.bin");
  48. MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
  49. #define BTC_IO_MC_REGS_SIZE 29
  50. static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  51. {0x00000077, 0xff010100},
  52. {0x00000078, 0x00000000},
  53. {0x00000079, 0x00001434},
  54. {0x0000007a, 0xcc08ec08},
  55. {0x0000007b, 0x00040000},
  56. {0x0000007c, 0x000080c0},
  57. {0x0000007d, 0x09000000},
  58. {0x0000007e, 0x00210404},
  59. {0x00000081, 0x08a8e800},
  60. {0x00000082, 0x00030444},
  61. {0x00000083, 0x00000000},
  62. {0x00000085, 0x00000001},
  63. {0x00000086, 0x00000002},
  64. {0x00000087, 0x48490000},
  65. {0x00000088, 0x20244647},
  66. {0x00000089, 0x00000005},
  67. {0x0000008b, 0x66030000},
  68. {0x0000008c, 0x00006603},
  69. {0x0000008d, 0x00000100},
  70. {0x0000008f, 0x00001c0a},
  71. {0x00000090, 0xff000001},
  72. {0x00000094, 0x00101101},
  73. {0x00000095, 0x00000fff},
  74. {0x00000096, 0x00116fff},
  75. {0x00000097, 0x60010000},
  76. {0x00000098, 0x10010000},
  77. {0x00000099, 0x00006000},
  78. {0x0000009a, 0x00001000},
  79. {0x0000009f, 0x00946a00}
  80. };
  81. static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  82. {0x00000077, 0xff010100},
  83. {0x00000078, 0x00000000},
  84. {0x00000079, 0x00001434},
  85. {0x0000007a, 0xcc08ec08},
  86. {0x0000007b, 0x00040000},
  87. {0x0000007c, 0x000080c0},
  88. {0x0000007d, 0x09000000},
  89. {0x0000007e, 0x00210404},
  90. {0x00000081, 0x08a8e800},
  91. {0x00000082, 0x00030444},
  92. {0x00000083, 0x00000000},
  93. {0x00000085, 0x00000001},
  94. {0x00000086, 0x00000002},
  95. {0x00000087, 0x48490000},
  96. {0x00000088, 0x20244647},
  97. {0x00000089, 0x00000005},
  98. {0x0000008b, 0x66030000},
  99. {0x0000008c, 0x00006603},
  100. {0x0000008d, 0x00000100},
  101. {0x0000008f, 0x00001c0a},
  102. {0x00000090, 0xff000001},
  103. {0x00000094, 0x00101101},
  104. {0x00000095, 0x00000fff},
  105. {0x00000096, 0x00116fff},
  106. {0x00000097, 0x60010000},
  107. {0x00000098, 0x10010000},
  108. {0x00000099, 0x00006000},
  109. {0x0000009a, 0x00001000},
  110. {0x0000009f, 0x00936a00}
  111. };
  112. static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  113. {0x00000077, 0xff010100},
  114. {0x00000078, 0x00000000},
  115. {0x00000079, 0x00001434},
  116. {0x0000007a, 0xcc08ec08},
  117. {0x0000007b, 0x00040000},
  118. {0x0000007c, 0x000080c0},
  119. {0x0000007d, 0x09000000},
  120. {0x0000007e, 0x00210404},
  121. {0x00000081, 0x08a8e800},
  122. {0x00000082, 0x00030444},
  123. {0x00000083, 0x00000000},
  124. {0x00000085, 0x00000001},
  125. {0x00000086, 0x00000002},
  126. {0x00000087, 0x48490000},
  127. {0x00000088, 0x20244647},
  128. {0x00000089, 0x00000005},
  129. {0x0000008b, 0x66030000},
  130. {0x0000008c, 0x00006603},
  131. {0x0000008d, 0x00000100},
  132. {0x0000008f, 0x00001c0a},
  133. {0x00000090, 0xff000001},
  134. {0x00000094, 0x00101101},
  135. {0x00000095, 0x00000fff},
  136. {0x00000096, 0x00116fff},
  137. {0x00000097, 0x60010000},
  138. {0x00000098, 0x10010000},
  139. {0x00000099, 0x00006000},
  140. {0x0000009a, 0x00001000},
  141. {0x0000009f, 0x00916a00}
  142. };
  143. int btc_mc_load_microcode(struct radeon_device *rdev)
  144. {
  145. const __be32 *fw_data;
  146. u32 mem_type, running, blackout = 0;
  147. u32 *io_mc_regs;
  148. int i;
  149. if (!rdev->mc_fw)
  150. return -EINVAL;
  151. switch (rdev->family) {
  152. case CHIP_BARTS:
  153. io_mc_regs = (u32 *)&barts_io_mc_regs;
  154. break;
  155. case CHIP_TURKS:
  156. io_mc_regs = (u32 *)&turks_io_mc_regs;
  157. break;
  158. case CHIP_CAICOS:
  159. default:
  160. io_mc_regs = (u32 *)&caicos_io_mc_regs;
  161. break;
  162. }
  163. mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
  164. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  165. if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
  166. if (running) {
  167. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  168. WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
  169. }
  170. /* reset the engine and set to writable */
  171. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  172. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  173. /* load mc io regs */
  174. for (i = 0; i < BTC_IO_MC_REGS_SIZE; i++) {
  175. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  176. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  177. }
  178. /* load the MC ucode */
  179. fw_data = (const __be32 *)rdev->mc_fw->data;
  180. for (i = 0; i < BTC_MC_UCODE_SIZE; i++)
  181. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  182. /* put the engine back into the active state */
  183. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  184. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  185. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  186. /* wait for training to complete */
  187. while (!(RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD))
  188. udelay(10);
  189. if (running)
  190. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  191. }
  192. return 0;
  193. }
  194. int ni_init_microcode(struct radeon_device *rdev)
  195. {
  196. struct platform_device *pdev;
  197. const char *chip_name;
  198. const char *rlc_chip_name;
  199. size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
  200. char fw_name[30];
  201. int err;
  202. DRM_DEBUG("\n");
  203. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  204. err = IS_ERR(pdev);
  205. if (err) {
  206. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  207. return -EINVAL;
  208. }
  209. switch (rdev->family) {
  210. case CHIP_BARTS:
  211. chip_name = "BARTS";
  212. rlc_chip_name = "BTC";
  213. break;
  214. case CHIP_TURKS:
  215. chip_name = "TURKS";
  216. rlc_chip_name = "BTC";
  217. break;
  218. case CHIP_CAICOS:
  219. chip_name = "CAICOS";
  220. rlc_chip_name = "BTC";
  221. break;
  222. default: BUG();
  223. }
  224. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  225. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  226. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  227. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  228. DRM_INFO("Loading %s Microcode\n", chip_name);
  229. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  230. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  231. if (err)
  232. goto out;
  233. if (rdev->pfp_fw->size != pfp_req_size) {
  234. printk(KERN_ERR
  235. "ni_cp: Bogus length %zu in firmware \"%s\"\n",
  236. rdev->pfp_fw->size, fw_name);
  237. err = -EINVAL;
  238. goto out;
  239. }
  240. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  241. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  242. if (err)
  243. goto out;
  244. if (rdev->me_fw->size != me_req_size) {
  245. printk(KERN_ERR
  246. "ni_cp: Bogus length %zu in firmware \"%s\"\n",
  247. rdev->me_fw->size, fw_name);
  248. err = -EINVAL;
  249. }
  250. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  251. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  252. if (err)
  253. goto out;
  254. if (rdev->rlc_fw->size != rlc_req_size) {
  255. printk(KERN_ERR
  256. "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
  257. rdev->rlc_fw->size, fw_name);
  258. err = -EINVAL;
  259. }
  260. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  261. err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
  262. if (err)
  263. goto out;
  264. if (rdev->mc_fw->size != mc_req_size) {
  265. printk(KERN_ERR
  266. "ni_mc: Bogus length %zu in firmware \"%s\"\n",
  267. rdev->mc_fw->size, fw_name);
  268. err = -EINVAL;
  269. }
  270. out:
  271. platform_device_unregister(pdev);
  272. if (err) {
  273. if (err != -EINVAL)
  274. printk(KERN_ERR
  275. "ni_cp: Failed to load firmware \"%s\"\n",
  276. fw_name);
  277. release_firmware(rdev->pfp_fw);
  278. rdev->pfp_fw = NULL;
  279. release_firmware(rdev->me_fw);
  280. rdev->me_fw = NULL;
  281. release_firmware(rdev->rlc_fw);
  282. rdev->rlc_fw = NULL;
  283. release_firmware(rdev->mc_fw);
  284. rdev->mc_fw = NULL;
  285. }
  286. return err;
  287. }