18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2011 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Authors: Alex Deucher
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <linux/firmware.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include "radeon.h"
288c2ecf20Sopenharmony_ci#include "rv770d.h"
298c2ecf20Sopenharmony_ci#include "rv770_dpm.h"
308c2ecf20Sopenharmony_ci#include "rv770_smc.h"
318c2ecf20Sopenharmony_ci#include "atom.h"
328c2ecf20Sopenharmony_ci#include "radeon_ucode.h"
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define FIRST_SMC_INT_VECT_REG 0xFFD8
358c2ecf20Sopenharmony_ci#define FIRST_INT_VECT_S19     0xFFC0
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic const u8 rv770_smc_int_vectors[] =
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
408c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
418c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
428c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
438c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
448c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
458c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
468c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
478c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
488c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
498c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
508c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
518c2ecf20Sopenharmony_ci	0x08, 0x10, 0x0C, 0xD7,
528c2ecf20Sopenharmony_ci	0x08, 0x2B, 0x08, 0x10,
538c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51,
548c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic const u8 rv730_smc_int_vectors[] =
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
608c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
618c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
628c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
638c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
648c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
658c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
668c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
678c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
688c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
698c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
708c2ecf20Sopenharmony_ci	0x08, 0x15, 0x08, 0x15,
718c2ecf20Sopenharmony_ci	0x08, 0x15, 0x0C, 0xBB,
728c2ecf20Sopenharmony_ci	0x08, 0x30, 0x08, 0x15,
738c2ecf20Sopenharmony_ci	0x03, 0x56, 0x03, 0x56,
748c2ecf20Sopenharmony_ci	0x03, 0x56, 0x03, 0x56
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic const u8 rv710_smc_int_vectors[] =
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
808c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
818c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
828c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
838c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
848c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
858c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
868c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
878c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
888c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
898c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
908c2ecf20Sopenharmony_ci	0x08, 0x04, 0x08, 0x04,
918c2ecf20Sopenharmony_ci	0x08, 0x04, 0x0C, 0xCB,
928c2ecf20Sopenharmony_ci	0x08, 0x1F, 0x08, 0x04,
938c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51,
948c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic const u8 rv740_smc_int_vectors[] =
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1008c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1018c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1028c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1038c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1048c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1058c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1068c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1078c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1088c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1098c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1108c2ecf20Sopenharmony_ci	0x08, 0x10, 0x08, 0x10,
1118c2ecf20Sopenharmony_ci	0x08, 0x10, 0x0C, 0xD7,
1128c2ecf20Sopenharmony_ci	0x08, 0x2B, 0x08, 0x10,
1138c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51,
1148c2ecf20Sopenharmony_ci	0x03, 0x51, 0x03, 0x51
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic const u8 cedar_smc_int_vectors[] =
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1208c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1218c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1228c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1238c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1248c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1258c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1268c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1278c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1288c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1298c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1308c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1318c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x11, 0x8B,
1328c2ecf20Sopenharmony_ci	0x0B, 0x20, 0x0B, 0x05,
1338c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6,
1348c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic const u8 redwood_smc_int_vectors[] =
1388c2ecf20Sopenharmony_ci{
1398c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1408c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1418c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1428c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1438c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1448c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1458c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1468c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1478c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1488c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1498c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1508c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1518c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x11, 0x8B,
1528c2ecf20Sopenharmony_ci	0x0B, 0x20, 0x0B, 0x05,
1538c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6,
1548c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic const u8 juniper_smc_int_vectors[] =
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1608c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1618c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1628c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1638c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1648c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1658c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1668c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1678c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1688c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1698c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1708c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1718c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x11, 0x8B,
1728c2ecf20Sopenharmony_ci	0x0B, 0x20, 0x0B, 0x05,
1738c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6,
1748c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistatic const u8 cypress_smc_int_vectors[] =
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1808c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1818c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1828c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1838c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1848c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1858c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1868c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1878c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1888c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1898c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1908c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x0B, 0x05,
1918c2ecf20Sopenharmony_ci	0x0B, 0x05, 0x11, 0x8B,
1928c2ecf20Sopenharmony_ci	0x0B, 0x20, 0x0B, 0x05,
1938c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6,
1948c2ecf20Sopenharmony_ci	0x04, 0xF6, 0x04, 0xF6
1958c2ecf20Sopenharmony_ci};
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistatic const u8 barts_smc_int_vectors[] =
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2008c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2018c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2028c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2038c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2048c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2058c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2068c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2078c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2088c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2098c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2108c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2118c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x12, 0xAA,
2128c2ecf20Sopenharmony_ci	0x0C, 0x2F, 0x15, 0xF6,
2138c2ecf20Sopenharmony_ci	0x15, 0xF6, 0x05, 0x0A,
2148c2ecf20Sopenharmony_ci	0x05, 0x0A, 0x05, 0x0A
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic const u8 turks_smc_int_vectors[] =
2188c2ecf20Sopenharmony_ci{
2198c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2208c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2218c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2228c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2238c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2248c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2258c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2268c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2278c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2288c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2298c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2308c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2318c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x12, 0xAA,
2328c2ecf20Sopenharmony_ci	0x0C, 0x2F, 0x15, 0xF6,
2338c2ecf20Sopenharmony_ci	0x15, 0xF6, 0x05, 0x0A,
2348c2ecf20Sopenharmony_ci	0x05, 0x0A, 0x05, 0x0A
2358c2ecf20Sopenharmony_ci};
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistatic const u8 caicos_smc_int_vectors[] =
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2408c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2418c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2428c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2438c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2448c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2458c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2468c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2478c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2488c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2498c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2508c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x0C, 0x14,
2518c2ecf20Sopenharmony_ci	0x0C, 0x14, 0x12, 0xAA,
2528c2ecf20Sopenharmony_ci	0x0C, 0x2F, 0x15, 0xF6,
2538c2ecf20Sopenharmony_ci	0x15, 0xF6, 0x05, 0x0A,
2548c2ecf20Sopenharmony_ci	0x05, 0x0A, 0x05, 0x0A
2558c2ecf20Sopenharmony_ci};
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistatic const u8 cayman_smc_int_vectors[] =
2588c2ecf20Sopenharmony_ci{
2598c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2608c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2618c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2628c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2638c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2648c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2658c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2668c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2678c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2688c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2698c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2708c2ecf20Sopenharmony_ci	0x12, 0x05, 0x12, 0x05,
2718c2ecf20Sopenharmony_ci	0x12, 0x05, 0x18, 0xEA,
2728c2ecf20Sopenharmony_ci	0x12, 0x20, 0x1C, 0x34,
2738c2ecf20Sopenharmony_ci	0x1C, 0x34, 0x08, 0x72,
2748c2ecf20Sopenharmony_ci	0x08, 0x72, 0x08, 0x72
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistatic int rv770_set_smc_sram_address(struct radeon_device *rdev,
2788c2ecf20Sopenharmony_ci				      u16 smc_address, u16 limit)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	u32 addr;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	if (smc_address & 3)
2838c2ecf20Sopenharmony_ci		return -EINVAL;
2848c2ecf20Sopenharmony_ci	if ((smc_address + 3) > limit)
2858c2ecf20Sopenharmony_ci		return -EINVAL;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	addr = smc_address;
2888c2ecf20Sopenharmony_ci	addr |= SMC_SRAM_AUTO_INC_DIS;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	WREG32(SMC_SRAM_ADDR, addr);
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	return 0;
2938c2ecf20Sopenharmony_ci}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ciint rv770_copy_bytes_to_smc(struct radeon_device *rdev,
2968c2ecf20Sopenharmony_ci			    u16 smc_start_address, const u8 *src,
2978c2ecf20Sopenharmony_ci			    u16 byte_count, u16 limit)
2988c2ecf20Sopenharmony_ci{
2998c2ecf20Sopenharmony_ci	unsigned long flags;
3008c2ecf20Sopenharmony_ci	u32 data, original_data, extra_shift;
3018c2ecf20Sopenharmony_ci	u16 addr;
3028c2ecf20Sopenharmony_ci	int ret = 0;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	if (smc_start_address & 3)
3058c2ecf20Sopenharmony_ci		return -EINVAL;
3068c2ecf20Sopenharmony_ci	if ((smc_start_address + byte_count) > limit)
3078c2ecf20Sopenharmony_ci		return -EINVAL;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	addr = smc_start_address;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->smc_idx_lock, flags);
3128c2ecf20Sopenharmony_ci	while (byte_count >= 4) {
3138c2ecf20Sopenharmony_ci		/* SMC address space is BE */
3148c2ecf20Sopenharmony_ci		data = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci		ret = rv770_set_smc_sram_address(rdev, addr, limit);
3178c2ecf20Sopenharmony_ci		if (ret)
3188c2ecf20Sopenharmony_ci			goto done;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci		WREG32(SMC_SRAM_DATA, data);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci		src += 4;
3238c2ecf20Sopenharmony_ci		byte_count -= 4;
3248c2ecf20Sopenharmony_ci		addr += 4;
3258c2ecf20Sopenharmony_ci	}
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	/* RMW for final bytes */
3288c2ecf20Sopenharmony_ci	if (byte_count > 0) {
3298c2ecf20Sopenharmony_ci		data = 0;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci		ret = rv770_set_smc_sram_address(rdev, addr, limit);
3328c2ecf20Sopenharmony_ci		if (ret)
3338c2ecf20Sopenharmony_ci			goto done;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci		original_data = RREG32(SMC_SRAM_DATA);
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci		extra_shift = 8 * (4 - byte_count);
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci		while (byte_count > 0) {
3408c2ecf20Sopenharmony_ci			/* SMC address space is BE */
3418c2ecf20Sopenharmony_ci			data = (data << 8) + *src++;
3428c2ecf20Sopenharmony_ci			byte_count--;
3438c2ecf20Sopenharmony_ci		}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci		data <<= extra_shift;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci		data |= (original_data & ~((~0UL) << extra_shift));
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci		ret = rv770_set_smc_sram_address(rdev, addr, limit);
3508c2ecf20Sopenharmony_ci		if (ret)
3518c2ecf20Sopenharmony_ci			goto done;
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci		WREG32(SMC_SRAM_DATA, data);
3548c2ecf20Sopenharmony_ci	}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cidone:
3578c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	return ret;
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistatic int rv770_program_interrupt_vectors(struct radeon_device *rdev,
3638c2ecf20Sopenharmony_ci					   u32 smc_first_vector, const u8 *src,
3648c2ecf20Sopenharmony_ci					   u32 byte_count)
3658c2ecf20Sopenharmony_ci{
3668c2ecf20Sopenharmony_ci	u32 tmp, i;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	if (byte_count % 4)
3698c2ecf20Sopenharmony_ci		return -EINVAL;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	if (smc_first_vector < FIRST_SMC_INT_VECT_REG) {
3728c2ecf20Sopenharmony_ci		tmp = FIRST_SMC_INT_VECT_REG - smc_first_vector;
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci		if (tmp > byte_count)
3758c2ecf20Sopenharmony_ci			return 0;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci		byte_count -= tmp;
3788c2ecf20Sopenharmony_ci		src += tmp;
3798c2ecf20Sopenharmony_ci		smc_first_vector = FIRST_SMC_INT_VECT_REG;
3808c2ecf20Sopenharmony_ci	}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	for (i = 0; i < byte_count; i += 4) {
3838c2ecf20Sopenharmony_ci		/* SMC address space is BE */
3848c2ecf20Sopenharmony_ci		tmp = (src[i] << 24) | (src[i + 1] << 16) | (src[i + 2] << 8) | src[i + 3];
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci		WREG32(SMC_ISR_FFD8_FFDB + i, tmp);
3878c2ecf20Sopenharmony_ci	}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	return 0;
3908c2ecf20Sopenharmony_ci}
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_civoid rv770_start_smc(struct radeon_device *rdev)
3938c2ecf20Sopenharmony_ci{
3948c2ecf20Sopenharmony_ci	WREG32_P(SMC_IO, SMC_RST_N, ~SMC_RST_N);
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_civoid rv770_reset_smc(struct radeon_device *rdev)
3988c2ecf20Sopenharmony_ci{
3998c2ecf20Sopenharmony_ci	WREG32_P(SMC_IO, 0, ~SMC_RST_N);
4008c2ecf20Sopenharmony_ci}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_civoid rv770_stop_smc_clock(struct radeon_device *rdev)
4038c2ecf20Sopenharmony_ci{
4048c2ecf20Sopenharmony_ci	WREG32_P(SMC_IO, 0, ~SMC_CLK_EN);
4058c2ecf20Sopenharmony_ci}
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_civoid rv770_start_smc_clock(struct radeon_device *rdev)
4088c2ecf20Sopenharmony_ci{
4098c2ecf20Sopenharmony_ci	WREG32_P(SMC_IO, SMC_CLK_EN, ~SMC_CLK_EN);
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cibool rv770_is_smc_running(struct radeon_device *rdev)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	u32 tmp;
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	tmp = RREG32(SMC_IO);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	if ((tmp & SMC_RST_N) && (tmp & SMC_CLK_EN))
4198c2ecf20Sopenharmony_ci		return true;
4208c2ecf20Sopenharmony_ci	else
4218c2ecf20Sopenharmony_ci		return false;
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ciPPSMC_Result rv770_send_msg_to_smc(struct radeon_device *rdev, PPSMC_Msg msg)
4258c2ecf20Sopenharmony_ci{
4268c2ecf20Sopenharmony_ci	u32 tmp;
4278c2ecf20Sopenharmony_ci	int i;
4288c2ecf20Sopenharmony_ci	PPSMC_Result result;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	if (!rv770_is_smc_running(rdev))
4318c2ecf20Sopenharmony_ci		return PPSMC_Result_Failed;
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	WREG32_P(SMC_MSG, HOST_SMC_MSG(msg), ~HOST_SMC_MSG_MASK);
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->usec_timeout; i++) {
4368c2ecf20Sopenharmony_ci		tmp = RREG32(SMC_MSG) & HOST_SMC_RESP_MASK;
4378c2ecf20Sopenharmony_ci		tmp >>= HOST_SMC_RESP_SHIFT;
4388c2ecf20Sopenharmony_ci		if (tmp != 0)
4398c2ecf20Sopenharmony_ci			break;
4408c2ecf20Sopenharmony_ci		udelay(1);
4418c2ecf20Sopenharmony_ci	}
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	tmp = RREG32(SMC_MSG) & HOST_SMC_RESP_MASK;
4448c2ecf20Sopenharmony_ci	tmp >>= HOST_SMC_RESP_SHIFT;
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	result = (PPSMC_Result)tmp;
4478c2ecf20Sopenharmony_ci	return result;
4488c2ecf20Sopenharmony_ci}
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ciPPSMC_Result rv770_wait_for_smc_inactive(struct radeon_device *rdev)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci	int i;
4538c2ecf20Sopenharmony_ci	PPSMC_Result result = PPSMC_Result_OK;
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	if (!rv770_is_smc_running(rdev))
4568c2ecf20Sopenharmony_ci		return result;
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->usec_timeout; i++) {
4598c2ecf20Sopenharmony_ci		if (RREG32(SMC_IO) & SMC_STOP_MODE)
4608c2ecf20Sopenharmony_ci			break;
4618c2ecf20Sopenharmony_ci		udelay(1);
4628c2ecf20Sopenharmony_ci	}
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	return result;
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic void rv770_clear_smc_sram(struct radeon_device *rdev, u16 limit)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	unsigned long flags;
4708c2ecf20Sopenharmony_ci	u16 i;
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->smc_idx_lock, flags);
4738c2ecf20Sopenharmony_ci	for (i = 0;  i < limit; i += 4) {
4748c2ecf20Sopenharmony_ci		rv770_set_smc_sram_address(rdev, i, limit);
4758c2ecf20Sopenharmony_ci		WREG32(SMC_SRAM_DATA, 0);
4768c2ecf20Sopenharmony_ci	}
4778c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
4788c2ecf20Sopenharmony_ci}
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ciint rv770_load_smc_ucode(struct radeon_device *rdev,
4818c2ecf20Sopenharmony_ci			 u16 limit)
4828c2ecf20Sopenharmony_ci{
4838c2ecf20Sopenharmony_ci	int ret;
4848c2ecf20Sopenharmony_ci	const u8 *int_vect;
4858c2ecf20Sopenharmony_ci	u16 int_vect_start_address;
4868c2ecf20Sopenharmony_ci	u16 int_vect_size;
4878c2ecf20Sopenharmony_ci	const u8 *ucode_data;
4888c2ecf20Sopenharmony_ci	u16 ucode_start_address;
4898c2ecf20Sopenharmony_ci	u16 ucode_size;
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	if (!rdev->smc_fw)
4928c2ecf20Sopenharmony_ci		return -EINVAL;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	rv770_clear_smc_sram(rdev, limit);
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	switch (rdev->family) {
4978c2ecf20Sopenharmony_ci	case CHIP_RV770:
4988c2ecf20Sopenharmony_ci		ucode_start_address = RV770_SMC_UCODE_START;
4998c2ecf20Sopenharmony_ci		ucode_size = RV770_SMC_UCODE_SIZE;
5008c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&rv770_smc_int_vectors;
5018c2ecf20Sopenharmony_ci		int_vect_start_address = RV770_SMC_INT_VECTOR_START;
5028c2ecf20Sopenharmony_ci		int_vect_size = RV770_SMC_INT_VECTOR_SIZE;
5038c2ecf20Sopenharmony_ci		break;
5048c2ecf20Sopenharmony_ci	case CHIP_RV730:
5058c2ecf20Sopenharmony_ci		ucode_start_address = RV730_SMC_UCODE_START;
5068c2ecf20Sopenharmony_ci		ucode_size = RV730_SMC_UCODE_SIZE;
5078c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&rv730_smc_int_vectors;
5088c2ecf20Sopenharmony_ci		int_vect_start_address = RV730_SMC_INT_VECTOR_START;
5098c2ecf20Sopenharmony_ci		int_vect_size = RV730_SMC_INT_VECTOR_SIZE;
5108c2ecf20Sopenharmony_ci		break;
5118c2ecf20Sopenharmony_ci	case CHIP_RV710:
5128c2ecf20Sopenharmony_ci		ucode_start_address = RV710_SMC_UCODE_START;
5138c2ecf20Sopenharmony_ci		ucode_size = RV710_SMC_UCODE_SIZE;
5148c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&rv710_smc_int_vectors;
5158c2ecf20Sopenharmony_ci		int_vect_start_address = RV710_SMC_INT_VECTOR_START;
5168c2ecf20Sopenharmony_ci		int_vect_size = RV710_SMC_INT_VECTOR_SIZE;
5178c2ecf20Sopenharmony_ci		break;
5188c2ecf20Sopenharmony_ci	case CHIP_RV740:
5198c2ecf20Sopenharmony_ci		ucode_start_address = RV740_SMC_UCODE_START;
5208c2ecf20Sopenharmony_ci		ucode_size = RV740_SMC_UCODE_SIZE;
5218c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&rv740_smc_int_vectors;
5228c2ecf20Sopenharmony_ci		int_vect_start_address = RV740_SMC_INT_VECTOR_START;
5238c2ecf20Sopenharmony_ci		int_vect_size = RV740_SMC_INT_VECTOR_SIZE;
5248c2ecf20Sopenharmony_ci		break;
5258c2ecf20Sopenharmony_ci	case CHIP_CEDAR:
5268c2ecf20Sopenharmony_ci		ucode_start_address = CEDAR_SMC_UCODE_START;
5278c2ecf20Sopenharmony_ci		ucode_size = CEDAR_SMC_UCODE_SIZE;
5288c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&cedar_smc_int_vectors;
5298c2ecf20Sopenharmony_ci		int_vect_start_address = CEDAR_SMC_INT_VECTOR_START;
5308c2ecf20Sopenharmony_ci		int_vect_size = CEDAR_SMC_INT_VECTOR_SIZE;
5318c2ecf20Sopenharmony_ci		break;
5328c2ecf20Sopenharmony_ci	case CHIP_REDWOOD:
5338c2ecf20Sopenharmony_ci		ucode_start_address = REDWOOD_SMC_UCODE_START;
5348c2ecf20Sopenharmony_ci		ucode_size = REDWOOD_SMC_UCODE_SIZE;
5358c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&redwood_smc_int_vectors;
5368c2ecf20Sopenharmony_ci		int_vect_start_address = REDWOOD_SMC_INT_VECTOR_START;
5378c2ecf20Sopenharmony_ci		int_vect_size = REDWOOD_SMC_INT_VECTOR_SIZE;
5388c2ecf20Sopenharmony_ci		break;
5398c2ecf20Sopenharmony_ci	case CHIP_JUNIPER:
5408c2ecf20Sopenharmony_ci		ucode_start_address = JUNIPER_SMC_UCODE_START;
5418c2ecf20Sopenharmony_ci		ucode_size = JUNIPER_SMC_UCODE_SIZE;
5428c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&juniper_smc_int_vectors;
5438c2ecf20Sopenharmony_ci		int_vect_start_address = JUNIPER_SMC_INT_VECTOR_START;
5448c2ecf20Sopenharmony_ci		int_vect_size = JUNIPER_SMC_INT_VECTOR_SIZE;
5458c2ecf20Sopenharmony_ci		break;
5468c2ecf20Sopenharmony_ci	case CHIP_CYPRESS:
5478c2ecf20Sopenharmony_ci	case CHIP_HEMLOCK:
5488c2ecf20Sopenharmony_ci		ucode_start_address = CYPRESS_SMC_UCODE_START;
5498c2ecf20Sopenharmony_ci		ucode_size = CYPRESS_SMC_UCODE_SIZE;
5508c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&cypress_smc_int_vectors;
5518c2ecf20Sopenharmony_ci		int_vect_start_address = CYPRESS_SMC_INT_VECTOR_START;
5528c2ecf20Sopenharmony_ci		int_vect_size = CYPRESS_SMC_INT_VECTOR_SIZE;
5538c2ecf20Sopenharmony_ci		break;
5548c2ecf20Sopenharmony_ci	case CHIP_BARTS:
5558c2ecf20Sopenharmony_ci		ucode_start_address = BARTS_SMC_UCODE_START;
5568c2ecf20Sopenharmony_ci		ucode_size = BARTS_SMC_UCODE_SIZE;
5578c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&barts_smc_int_vectors;
5588c2ecf20Sopenharmony_ci		int_vect_start_address = BARTS_SMC_INT_VECTOR_START;
5598c2ecf20Sopenharmony_ci		int_vect_size = BARTS_SMC_INT_VECTOR_SIZE;
5608c2ecf20Sopenharmony_ci		break;
5618c2ecf20Sopenharmony_ci	case CHIP_TURKS:
5628c2ecf20Sopenharmony_ci		ucode_start_address = TURKS_SMC_UCODE_START;
5638c2ecf20Sopenharmony_ci		ucode_size = TURKS_SMC_UCODE_SIZE;
5648c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&turks_smc_int_vectors;
5658c2ecf20Sopenharmony_ci		int_vect_start_address = TURKS_SMC_INT_VECTOR_START;
5668c2ecf20Sopenharmony_ci		int_vect_size = TURKS_SMC_INT_VECTOR_SIZE;
5678c2ecf20Sopenharmony_ci		break;
5688c2ecf20Sopenharmony_ci	case CHIP_CAICOS:
5698c2ecf20Sopenharmony_ci		ucode_start_address = CAICOS_SMC_UCODE_START;
5708c2ecf20Sopenharmony_ci		ucode_size = CAICOS_SMC_UCODE_SIZE;
5718c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&caicos_smc_int_vectors;
5728c2ecf20Sopenharmony_ci		int_vect_start_address = CAICOS_SMC_INT_VECTOR_START;
5738c2ecf20Sopenharmony_ci		int_vect_size = CAICOS_SMC_INT_VECTOR_SIZE;
5748c2ecf20Sopenharmony_ci		break;
5758c2ecf20Sopenharmony_ci	case CHIP_CAYMAN:
5768c2ecf20Sopenharmony_ci		ucode_start_address = CAYMAN_SMC_UCODE_START;
5778c2ecf20Sopenharmony_ci		ucode_size = CAYMAN_SMC_UCODE_SIZE;
5788c2ecf20Sopenharmony_ci		int_vect = (const u8 *)&cayman_smc_int_vectors;
5798c2ecf20Sopenharmony_ci		int_vect_start_address = CAYMAN_SMC_INT_VECTOR_START;
5808c2ecf20Sopenharmony_ci		int_vect_size = CAYMAN_SMC_INT_VECTOR_SIZE;
5818c2ecf20Sopenharmony_ci		break;
5828c2ecf20Sopenharmony_ci	default:
5838c2ecf20Sopenharmony_ci		DRM_ERROR("unknown asic in smc ucode loader\n");
5848c2ecf20Sopenharmony_ci		BUG();
5858c2ecf20Sopenharmony_ci	}
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	/* load the ucode */
5888c2ecf20Sopenharmony_ci	ucode_data = (const u8 *)rdev->smc_fw->data;
5898c2ecf20Sopenharmony_ci	ret = rv770_copy_bytes_to_smc(rdev, ucode_start_address,
5908c2ecf20Sopenharmony_ci				      ucode_data, ucode_size, limit);
5918c2ecf20Sopenharmony_ci	if (ret)
5928c2ecf20Sopenharmony_ci		return ret;
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	/* set up the int vectors */
5958c2ecf20Sopenharmony_ci	ret = rv770_program_interrupt_vectors(rdev, int_vect_start_address,
5968c2ecf20Sopenharmony_ci					      int_vect, int_vect_size);
5978c2ecf20Sopenharmony_ci	if (ret)
5988c2ecf20Sopenharmony_ci		return ret;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	return 0;
6018c2ecf20Sopenharmony_ci}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ciint rv770_read_smc_sram_dword(struct radeon_device *rdev,
6048c2ecf20Sopenharmony_ci			      u16 smc_address, u32 *value, u16 limit)
6058c2ecf20Sopenharmony_ci{
6068c2ecf20Sopenharmony_ci	unsigned long flags;
6078c2ecf20Sopenharmony_ci	int ret;
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->smc_idx_lock, flags);
6108c2ecf20Sopenharmony_ci	ret = rv770_set_smc_sram_address(rdev, smc_address, limit);
6118c2ecf20Sopenharmony_ci	if (ret == 0)
6128c2ecf20Sopenharmony_ci		*value = RREG32(SMC_SRAM_DATA);
6138c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci	return ret;
6168c2ecf20Sopenharmony_ci}
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ciint rv770_write_smc_sram_dword(struct radeon_device *rdev,
6198c2ecf20Sopenharmony_ci			       u16 smc_address, u32 value, u16 limit)
6208c2ecf20Sopenharmony_ci{
6218c2ecf20Sopenharmony_ci	unsigned long flags;
6228c2ecf20Sopenharmony_ci	int ret;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->smc_idx_lock, flags);
6258c2ecf20Sopenharmony_ci	ret = rv770_set_smc_sram_address(rdev, smc_address, limit);
6268c2ecf20Sopenharmony_ci	if (ret == 0)
6278c2ecf20Sopenharmony_ci		WREG32(SMC_SRAM_DATA, value);
6288c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci	return ret;
6318c2ecf20Sopenharmony_ci}
632