rv770_smc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright 2011 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 "drmP.h"
  26. #include "radeon.h"
  27. #include "rv770d.h"
  28. #include "rv770_dpm.h"
  29. #include "rv770_smc.h"
  30. #include "atom.h"
  31. #include "radeon_ucode.h"
  32. #define FIRST_SMC_INT_VECT_REG 0xFFD8
  33. #define FIRST_INT_VECT_S19 0xFFC0
  34. static const u8 rv770_smc_int_vectors[] =
  35. {
  36. 0x08, 0x10, 0x08, 0x10,
  37. 0x08, 0x10, 0x08, 0x10,
  38. 0x08, 0x10, 0x08, 0x10,
  39. 0x08, 0x10, 0x08, 0x10,
  40. 0x08, 0x10, 0x08, 0x10,
  41. 0x08, 0x10, 0x08, 0x10,
  42. 0x08, 0x10, 0x08, 0x10,
  43. 0x08, 0x10, 0x08, 0x10,
  44. 0x08, 0x10, 0x08, 0x10,
  45. 0x08, 0x10, 0x08, 0x10,
  46. 0x08, 0x10, 0x08, 0x10,
  47. 0x08, 0x10, 0x08, 0x10,
  48. 0x08, 0x10, 0x0C, 0xD7,
  49. 0x08, 0x2B, 0x08, 0x10,
  50. 0x03, 0x51, 0x03, 0x51,
  51. 0x03, 0x51, 0x03, 0x51
  52. };
  53. static const u8 rv730_smc_int_vectors[] =
  54. {
  55. 0x08, 0x15, 0x08, 0x15,
  56. 0x08, 0x15, 0x08, 0x15,
  57. 0x08, 0x15, 0x08, 0x15,
  58. 0x08, 0x15, 0x08, 0x15,
  59. 0x08, 0x15, 0x08, 0x15,
  60. 0x08, 0x15, 0x08, 0x15,
  61. 0x08, 0x15, 0x08, 0x15,
  62. 0x08, 0x15, 0x08, 0x15,
  63. 0x08, 0x15, 0x08, 0x15,
  64. 0x08, 0x15, 0x08, 0x15,
  65. 0x08, 0x15, 0x08, 0x15,
  66. 0x08, 0x15, 0x08, 0x15,
  67. 0x08, 0x15, 0x0C, 0xBB,
  68. 0x08, 0x30, 0x08, 0x15,
  69. 0x03, 0x56, 0x03, 0x56,
  70. 0x03, 0x56, 0x03, 0x56
  71. };
  72. static const u8 rv710_smc_int_vectors[] =
  73. {
  74. 0x08, 0x04, 0x08, 0x04,
  75. 0x08, 0x04, 0x08, 0x04,
  76. 0x08, 0x04, 0x08, 0x04,
  77. 0x08, 0x04, 0x08, 0x04,
  78. 0x08, 0x04, 0x08, 0x04,
  79. 0x08, 0x04, 0x08, 0x04,
  80. 0x08, 0x04, 0x08, 0x04,
  81. 0x08, 0x04, 0x08, 0x04,
  82. 0x08, 0x04, 0x08, 0x04,
  83. 0x08, 0x04, 0x08, 0x04,
  84. 0x08, 0x04, 0x08, 0x04,
  85. 0x08, 0x04, 0x08, 0x04,
  86. 0x08, 0x04, 0x0C, 0xCB,
  87. 0x08, 0x1F, 0x08, 0x04,
  88. 0x03, 0x51, 0x03, 0x51,
  89. 0x03, 0x51, 0x03, 0x51
  90. };
  91. static const u8 rv740_smc_int_vectors[] =
  92. {
  93. 0x08, 0x10, 0x08, 0x10,
  94. 0x08, 0x10, 0x08, 0x10,
  95. 0x08, 0x10, 0x08, 0x10,
  96. 0x08, 0x10, 0x08, 0x10,
  97. 0x08, 0x10, 0x08, 0x10,
  98. 0x08, 0x10, 0x08, 0x10,
  99. 0x08, 0x10, 0x08, 0x10,
  100. 0x08, 0x10, 0x08, 0x10,
  101. 0x08, 0x10, 0x08, 0x10,
  102. 0x08, 0x10, 0x08, 0x10,
  103. 0x08, 0x10, 0x08, 0x10,
  104. 0x08, 0x10, 0x08, 0x10,
  105. 0x08, 0x10, 0x0C, 0xD7,
  106. 0x08, 0x2B, 0x08, 0x10,
  107. 0x03, 0x51, 0x03, 0x51,
  108. 0x03, 0x51, 0x03, 0x51
  109. };
  110. static const u8 cedar_smc_int_vectors[] =
  111. {
  112. 0x0B, 0x05, 0x0B, 0x05,
  113. 0x0B, 0x05, 0x0B, 0x05,
  114. 0x0B, 0x05, 0x0B, 0x05,
  115. 0x0B, 0x05, 0x0B, 0x05,
  116. 0x0B, 0x05, 0x0B, 0x05,
  117. 0x0B, 0x05, 0x0B, 0x05,
  118. 0x0B, 0x05, 0x0B, 0x05,
  119. 0x0B, 0x05, 0x0B, 0x05,
  120. 0x0B, 0x05, 0x0B, 0x05,
  121. 0x0B, 0x05, 0x0B, 0x05,
  122. 0x0B, 0x05, 0x0B, 0x05,
  123. 0x0B, 0x05, 0x0B, 0x05,
  124. 0x0B, 0x05, 0x11, 0x8B,
  125. 0x0B, 0x20, 0x0B, 0x05,
  126. 0x04, 0xF6, 0x04, 0xF6,
  127. 0x04, 0xF6, 0x04, 0xF6
  128. };
  129. static const u8 redwood_smc_int_vectors[] =
  130. {
  131. 0x0B, 0x05, 0x0B, 0x05,
  132. 0x0B, 0x05, 0x0B, 0x05,
  133. 0x0B, 0x05, 0x0B, 0x05,
  134. 0x0B, 0x05, 0x0B, 0x05,
  135. 0x0B, 0x05, 0x0B, 0x05,
  136. 0x0B, 0x05, 0x0B, 0x05,
  137. 0x0B, 0x05, 0x0B, 0x05,
  138. 0x0B, 0x05, 0x0B, 0x05,
  139. 0x0B, 0x05, 0x0B, 0x05,
  140. 0x0B, 0x05, 0x0B, 0x05,
  141. 0x0B, 0x05, 0x0B, 0x05,
  142. 0x0B, 0x05, 0x0B, 0x05,
  143. 0x0B, 0x05, 0x11, 0x8B,
  144. 0x0B, 0x20, 0x0B, 0x05,
  145. 0x04, 0xF6, 0x04, 0xF6,
  146. 0x04, 0xF6, 0x04, 0xF6
  147. };
  148. static const u8 juniper_smc_int_vectors[] =
  149. {
  150. 0x0B, 0x05, 0x0B, 0x05,
  151. 0x0B, 0x05, 0x0B, 0x05,
  152. 0x0B, 0x05, 0x0B, 0x05,
  153. 0x0B, 0x05, 0x0B, 0x05,
  154. 0x0B, 0x05, 0x0B, 0x05,
  155. 0x0B, 0x05, 0x0B, 0x05,
  156. 0x0B, 0x05, 0x0B, 0x05,
  157. 0x0B, 0x05, 0x0B, 0x05,
  158. 0x0B, 0x05, 0x0B, 0x05,
  159. 0x0B, 0x05, 0x0B, 0x05,
  160. 0x0B, 0x05, 0x0B, 0x05,
  161. 0x0B, 0x05, 0x0B, 0x05,
  162. 0x0B, 0x05, 0x11, 0x8B,
  163. 0x0B, 0x20, 0x0B, 0x05,
  164. 0x04, 0xF6, 0x04, 0xF6,
  165. 0x04, 0xF6, 0x04, 0xF6
  166. };
  167. static const u8 cypress_smc_int_vectors[] =
  168. {
  169. 0x0B, 0x05, 0x0B, 0x05,
  170. 0x0B, 0x05, 0x0B, 0x05,
  171. 0x0B, 0x05, 0x0B, 0x05,
  172. 0x0B, 0x05, 0x0B, 0x05,
  173. 0x0B, 0x05, 0x0B, 0x05,
  174. 0x0B, 0x05, 0x0B, 0x05,
  175. 0x0B, 0x05, 0x0B, 0x05,
  176. 0x0B, 0x05, 0x0B, 0x05,
  177. 0x0B, 0x05, 0x0B, 0x05,
  178. 0x0B, 0x05, 0x0B, 0x05,
  179. 0x0B, 0x05, 0x0B, 0x05,
  180. 0x0B, 0x05, 0x0B, 0x05,
  181. 0x0B, 0x05, 0x11, 0x8B,
  182. 0x0B, 0x20, 0x0B, 0x05,
  183. 0x04, 0xF6, 0x04, 0xF6,
  184. 0x04, 0xF6, 0x04, 0xF6
  185. };
  186. static const u8 barts_smc_int_vectors[] =
  187. {
  188. 0x0C, 0x14, 0x0C, 0x14,
  189. 0x0C, 0x14, 0x0C, 0x14,
  190. 0x0C, 0x14, 0x0C, 0x14,
  191. 0x0C, 0x14, 0x0C, 0x14,
  192. 0x0C, 0x14, 0x0C, 0x14,
  193. 0x0C, 0x14, 0x0C, 0x14,
  194. 0x0C, 0x14, 0x0C, 0x14,
  195. 0x0C, 0x14, 0x0C, 0x14,
  196. 0x0C, 0x14, 0x0C, 0x14,
  197. 0x0C, 0x14, 0x0C, 0x14,
  198. 0x0C, 0x14, 0x0C, 0x14,
  199. 0x0C, 0x14, 0x0C, 0x14,
  200. 0x0C, 0x14, 0x12, 0xAA,
  201. 0x0C, 0x2F, 0x15, 0xF6,
  202. 0x15, 0xF6, 0x05, 0x0A,
  203. 0x05, 0x0A, 0x05, 0x0A
  204. };
  205. static const u8 turks_smc_int_vectors[] =
  206. {
  207. 0x0C, 0x14, 0x0C, 0x14,
  208. 0x0C, 0x14, 0x0C, 0x14,
  209. 0x0C, 0x14, 0x0C, 0x14,
  210. 0x0C, 0x14, 0x0C, 0x14,
  211. 0x0C, 0x14, 0x0C, 0x14,
  212. 0x0C, 0x14, 0x0C, 0x14,
  213. 0x0C, 0x14, 0x0C, 0x14,
  214. 0x0C, 0x14, 0x0C, 0x14,
  215. 0x0C, 0x14, 0x0C, 0x14,
  216. 0x0C, 0x14, 0x0C, 0x14,
  217. 0x0C, 0x14, 0x0C, 0x14,
  218. 0x0C, 0x14, 0x0C, 0x14,
  219. 0x0C, 0x14, 0x12, 0xAA,
  220. 0x0C, 0x2F, 0x15, 0xF6,
  221. 0x15, 0xF6, 0x05, 0x0A,
  222. 0x05, 0x0A, 0x05, 0x0A
  223. };
  224. static const u8 caicos_smc_int_vectors[] =
  225. {
  226. 0x0C, 0x14, 0x0C, 0x14,
  227. 0x0C, 0x14, 0x0C, 0x14,
  228. 0x0C, 0x14, 0x0C, 0x14,
  229. 0x0C, 0x14, 0x0C, 0x14,
  230. 0x0C, 0x14, 0x0C, 0x14,
  231. 0x0C, 0x14, 0x0C, 0x14,
  232. 0x0C, 0x14, 0x0C, 0x14,
  233. 0x0C, 0x14, 0x0C, 0x14,
  234. 0x0C, 0x14, 0x0C, 0x14,
  235. 0x0C, 0x14, 0x0C, 0x14,
  236. 0x0C, 0x14, 0x0C, 0x14,
  237. 0x0C, 0x14, 0x0C, 0x14,
  238. 0x0C, 0x14, 0x12, 0xAA,
  239. 0x0C, 0x2F, 0x15, 0xF6,
  240. 0x15, 0xF6, 0x05, 0x0A,
  241. 0x05, 0x0A, 0x05, 0x0A
  242. };
  243. static const u8 cayman_smc_int_vectors[] =
  244. {
  245. 0x12, 0x05, 0x12, 0x05,
  246. 0x12, 0x05, 0x12, 0x05,
  247. 0x12, 0x05, 0x12, 0x05,
  248. 0x12, 0x05, 0x12, 0x05,
  249. 0x12, 0x05, 0x12, 0x05,
  250. 0x12, 0x05, 0x12, 0x05,
  251. 0x12, 0x05, 0x12, 0x05,
  252. 0x12, 0x05, 0x12, 0x05,
  253. 0x12, 0x05, 0x12, 0x05,
  254. 0x12, 0x05, 0x12, 0x05,
  255. 0x12, 0x05, 0x12, 0x05,
  256. 0x12, 0x05, 0x12, 0x05,
  257. 0x12, 0x05, 0x18, 0xEA,
  258. 0x12, 0x20, 0x1C, 0x34,
  259. 0x1C, 0x34, 0x08, 0x72,
  260. 0x08, 0x72, 0x08, 0x72
  261. };
  262. static int rv770_set_smc_sram_address(struct radeon_device *rdev,
  263. u16 smc_address, u16 limit)
  264. {
  265. u32 addr;
  266. if (smc_address & 3)
  267. return -EINVAL;
  268. if ((smc_address + 3) > limit)
  269. return -EINVAL;
  270. addr = smc_address;
  271. addr |= SMC_SRAM_AUTO_INC_DIS;
  272. WREG32(SMC_SRAM_ADDR, addr);
  273. return 0;
  274. }
  275. int rv770_copy_bytes_to_smc(struct radeon_device *rdev,
  276. u16 smc_start_address, const u8 *src,
  277. u16 byte_count, u16 limit)
  278. {
  279. unsigned long flags;
  280. u32 data, original_data, extra_shift;
  281. u16 addr;
  282. int ret = 0;
  283. if (smc_start_address & 3)
  284. return -EINVAL;
  285. if ((smc_start_address + byte_count) > limit)
  286. return -EINVAL;
  287. addr = smc_start_address;
  288. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  289. while (byte_count >= 4) {
  290. /* SMC address space is BE */
  291. data = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
  292. ret = rv770_set_smc_sram_address(rdev, addr, limit);
  293. if (ret)
  294. goto done;
  295. WREG32(SMC_SRAM_DATA, data);
  296. src += 4;
  297. byte_count -= 4;
  298. addr += 4;
  299. }
  300. /* RMW for final bytes */
  301. if (byte_count > 0) {
  302. data = 0;
  303. ret = rv770_set_smc_sram_address(rdev, addr, limit);
  304. if (ret)
  305. goto done;
  306. original_data = RREG32(SMC_SRAM_DATA);
  307. extra_shift = 8 * (4 - byte_count);
  308. while (byte_count > 0) {
  309. /* SMC address space is BE */
  310. data = (data << 8) + *src++;
  311. byte_count--;
  312. }
  313. data <<= extra_shift;
  314. data |= (original_data & ~((~0UL) << extra_shift));
  315. ret = rv770_set_smc_sram_address(rdev, addr, limit);
  316. if (ret)
  317. goto done;
  318. WREG32(SMC_SRAM_DATA, data);
  319. }
  320. done:
  321. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  322. return ret;
  323. }
  324. static int rv770_program_interrupt_vectors(struct radeon_device *rdev,
  325. u32 smc_first_vector, const u8 *src,
  326. u32 byte_count)
  327. {
  328. u32 tmp, i;
  329. if (byte_count % 4)
  330. return -EINVAL;
  331. if (smc_first_vector < FIRST_SMC_INT_VECT_REG) {
  332. tmp = FIRST_SMC_INT_VECT_REG - smc_first_vector;
  333. if (tmp > byte_count)
  334. return 0;
  335. byte_count -= tmp;
  336. src += tmp;
  337. smc_first_vector = FIRST_SMC_INT_VECT_REG;
  338. }
  339. for (i = 0; i < byte_count; i += 4) {
  340. /* SMC address space is BE */
  341. tmp = (src[i] << 24) | (src[i + 1] << 16) | (src[i + 2] << 8) | src[i + 3];
  342. WREG32(SMC_ISR_FFD8_FFDB + i, tmp);
  343. }
  344. return 0;
  345. }
  346. void rv770_start_smc(struct radeon_device *rdev)
  347. {
  348. WREG32_P(SMC_IO, SMC_RST_N, ~SMC_RST_N);
  349. }
  350. void rv770_reset_smc(struct radeon_device *rdev)
  351. {
  352. WREG32_P(SMC_IO, 0, ~SMC_RST_N);
  353. }
  354. void rv770_stop_smc_clock(struct radeon_device *rdev)
  355. {
  356. WREG32_P(SMC_IO, 0, ~SMC_CLK_EN);
  357. }
  358. void rv770_start_smc_clock(struct radeon_device *rdev)
  359. {
  360. WREG32_P(SMC_IO, SMC_CLK_EN, ~SMC_CLK_EN);
  361. }
  362. bool rv770_is_smc_running(struct radeon_device *rdev)
  363. {
  364. u32 tmp;
  365. tmp = RREG32(SMC_IO);
  366. if ((tmp & SMC_RST_N) && (tmp & SMC_CLK_EN))
  367. return true;
  368. else
  369. return false;
  370. }
  371. PPSMC_Result rv770_send_msg_to_smc(struct radeon_device *rdev, PPSMC_Msg msg)
  372. {
  373. u32 tmp;
  374. int i;
  375. PPSMC_Result result;
  376. if (!rv770_is_smc_running(rdev))
  377. return PPSMC_Result_Failed;
  378. WREG32_P(SMC_MSG, HOST_SMC_MSG(msg), ~HOST_SMC_MSG_MASK);
  379. for (i = 0; i < rdev->usec_timeout; i++) {
  380. tmp = RREG32(SMC_MSG) & HOST_SMC_RESP_MASK;
  381. tmp >>= HOST_SMC_RESP_SHIFT;
  382. if (tmp != 0)
  383. break;
  384. udelay(1);
  385. }
  386. tmp = RREG32(SMC_MSG) & HOST_SMC_RESP_MASK;
  387. tmp >>= HOST_SMC_RESP_SHIFT;
  388. result = (PPSMC_Result)tmp;
  389. return result;
  390. }
  391. PPSMC_Result rv770_wait_for_smc_inactive(struct radeon_device *rdev)
  392. {
  393. int i;
  394. PPSMC_Result result = PPSMC_Result_OK;
  395. if (!rv770_is_smc_running(rdev))
  396. return result;
  397. for (i = 0; i < rdev->usec_timeout; i++) {
  398. if (RREG32(SMC_IO) & SMC_STOP_MODE)
  399. break;
  400. udelay(1);
  401. }
  402. return result;
  403. }
  404. static void rv770_clear_smc_sram(struct radeon_device *rdev, u16 limit)
  405. {
  406. unsigned long flags;
  407. u16 i;
  408. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  409. for (i = 0; i < limit; i += 4) {
  410. rv770_set_smc_sram_address(rdev, i, limit);
  411. WREG32(SMC_SRAM_DATA, 0);
  412. }
  413. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  414. }
  415. int rv770_load_smc_ucode(struct radeon_device *rdev,
  416. u16 limit)
  417. {
  418. int ret;
  419. const u8 *int_vect;
  420. u16 int_vect_start_address;
  421. u16 int_vect_size;
  422. const u8 *ucode_data;
  423. u16 ucode_start_address;
  424. u16 ucode_size;
  425. if (!rdev->smc_fw)
  426. return -EINVAL;
  427. rv770_clear_smc_sram(rdev, limit);
  428. switch (rdev->family) {
  429. case CHIP_RV770:
  430. ucode_start_address = RV770_SMC_UCODE_START;
  431. ucode_size = RV770_SMC_UCODE_SIZE;
  432. int_vect = (const u8 *)&rv770_smc_int_vectors;
  433. int_vect_start_address = RV770_SMC_INT_VECTOR_START;
  434. int_vect_size = RV770_SMC_INT_VECTOR_SIZE;
  435. break;
  436. case CHIP_RV730:
  437. ucode_start_address = RV730_SMC_UCODE_START;
  438. ucode_size = RV730_SMC_UCODE_SIZE;
  439. int_vect = (const u8 *)&rv730_smc_int_vectors;
  440. int_vect_start_address = RV730_SMC_INT_VECTOR_START;
  441. int_vect_size = RV730_SMC_INT_VECTOR_SIZE;
  442. break;
  443. case CHIP_RV710:
  444. ucode_start_address = RV710_SMC_UCODE_START;
  445. ucode_size = RV710_SMC_UCODE_SIZE;
  446. int_vect = (const u8 *)&rv710_smc_int_vectors;
  447. int_vect_start_address = RV710_SMC_INT_VECTOR_START;
  448. int_vect_size = RV710_SMC_INT_VECTOR_SIZE;
  449. break;
  450. case CHIP_RV740:
  451. ucode_start_address = RV740_SMC_UCODE_START;
  452. ucode_size = RV740_SMC_UCODE_SIZE;
  453. int_vect = (const u8 *)&rv740_smc_int_vectors;
  454. int_vect_start_address = RV740_SMC_INT_VECTOR_START;
  455. int_vect_size = RV740_SMC_INT_VECTOR_SIZE;
  456. break;
  457. case CHIP_CEDAR:
  458. ucode_start_address = CEDAR_SMC_UCODE_START;
  459. ucode_size = CEDAR_SMC_UCODE_SIZE;
  460. int_vect = (const u8 *)&cedar_smc_int_vectors;
  461. int_vect_start_address = CEDAR_SMC_INT_VECTOR_START;
  462. int_vect_size = CEDAR_SMC_INT_VECTOR_SIZE;
  463. break;
  464. case CHIP_REDWOOD:
  465. ucode_start_address = REDWOOD_SMC_UCODE_START;
  466. ucode_size = REDWOOD_SMC_UCODE_SIZE;
  467. int_vect = (const u8 *)&redwood_smc_int_vectors;
  468. int_vect_start_address = REDWOOD_SMC_INT_VECTOR_START;
  469. int_vect_size = REDWOOD_SMC_INT_VECTOR_SIZE;
  470. break;
  471. case CHIP_JUNIPER:
  472. ucode_start_address = JUNIPER_SMC_UCODE_START;
  473. ucode_size = JUNIPER_SMC_UCODE_SIZE;
  474. int_vect = (const u8 *)&juniper_smc_int_vectors;
  475. int_vect_start_address = JUNIPER_SMC_INT_VECTOR_START;
  476. int_vect_size = JUNIPER_SMC_INT_VECTOR_SIZE;
  477. break;
  478. case CHIP_CYPRESS:
  479. case CHIP_HEMLOCK:
  480. ucode_start_address = CYPRESS_SMC_UCODE_START;
  481. ucode_size = CYPRESS_SMC_UCODE_SIZE;
  482. int_vect = (const u8 *)&cypress_smc_int_vectors;
  483. int_vect_start_address = CYPRESS_SMC_INT_VECTOR_START;
  484. int_vect_size = CYPRESS_SMC_INT_VECTOR_SIZE;
  485. break;
  486. case CHIP_BARTS:
  487. ucode_start_address = BARTS_SMC_UCODE_START;
  488. ucode_size = BARTS_SMC_UCODE_SIZE;
  489. int_vect = (const u8 *)&barts_smc_int_vectors;
  490. int_vect_start_address = BARTS_SMC_INT_VECTOR_START;
  491. int_vect_size = BARTS_SMC_INT_VECTOR_SIZE;
  492. break;
  493. case CHIP_TURKS:
  494. ucode_start_address = TURKS_SMC_UCODE_START;
  495. ucode_size = TURKS_SMC_UCODE_SIZE;
  496. int_vect = (const u8 *)&turks_smc_int_vectors;
  497. int_vect_start_address = TURKS_SMC_INT_VECTOR_START;
  498. int_vect_size = TURKS_SMC_INT_VECTOR_SIZE;
  499. break;
  500. case CHIP_CAICOS:
  501. ucode_start_address = CAICOS_SMC_UCODE_START;
  502. ucode_size = CAICOS_SMC_UCODE_SIZE;
  503. int_vect = (const u8 *)&caicos_smc_int_vectors;
  504. int_vect_start_address = CAICOS_SMC_INT_VECTOR_START;
  505. int_vect_size = CAICOS_SMC_INT_VECTOR_SIZE;
  506. break;
  507. case CHIP_CAYMAN:
  508. ucode_start_address = CAYMAN_SMC_UCODE_START;
  509. ucode_size = CAYMAN_SMC_UCODE_SIZE;
  510. int_vect = (const u8 *)&cayman_smc_int_vectors;
  511. int_vect_start_address = CAYMAN_SMC_INT_VECTOR_START;
  512. int_vect_size = CAYMAN_SMC_INT_VECTOR_SIZE;
  513. break;
  514. default:
  515. DRM_ERROR("unknown asic in smc ucode loader\n");
  516. BUG();
  517. }
  518. /* load the ucode */
  519. ucode_data = (const u8 *)rdev->smc_fw->data;
  520. ret = rv770_copy_bytes_to_smc(rdev, ucode_start_address,
  521. ucode_data, ucode_size, limit);
  522. if (ret)
  523. return ret;
  524. /* set up the int vectors */
  525. ret = rv770_program_interrupt_vectors(rdev, int_vect_start_address,
  526. int_vect, int_vect_size);
  527. if (ret)
  528. return ret;
  529. return 0;
  530. }
  531. int rv770_read_smc_sram_dword(struct radeon_device *rdev,
  532. u16 smc_address, u32 *value, u16 limit)
  533. {
  534. unsigned long flags;
  535. int ret;
  536. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  537. ret = rv770_set_smc_sram_address(rdev, smc_address, limit);
  538. if (ret == 0)
  539. *value = RREG32(SMC_SRAM_DATA);
  540. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  541. return ret;
  542. }
  543. int rv770_write_smc_sram_dword(struct radeon_device *rdev,
  544. u16 smc_address, u32 value, u16 limit)
  545. {
  546. unsigned long flags;
  547. int ret;
  548. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  549. ret = rv770_set_smc_sram_address(rdev, smc_address, limit);
  550. if (ret == 0)
  551. WREG32(SMC_SRAM_DATA, value);
  552. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  553. return ret;
  554. }