26 #include <linux/slab.h>
27 #include <linux/module.h>
48 #define EVERGREEN_PFP_UCODE_SIZE 1120
49 #define EVERGREEN_PM4_UCODE_SIZE 1376
50 #define EVERGREEN_RLC_UCODE_SIZE 768
51 #define BTC_MC_UCODE_SIZE 6024
53 #define CAYMAN_PFP_UCODE_SIZE 2176
54 #define CAYMAN_PM4_UCODE_SIZE 2176
55 #define CAYMAN_RLC_UCODE_SIZE 1024
56 #define CAYMAN_MC_UCODE_SIZE 6037
58 #define ARUBA_RLC_UCODE_SIZE 1536
79 #define BTC_IO_MC_REGS_SIZE 29
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, 0x00946a00}
114 {0x00000077, 0xff010100},
115 {0x00000078, 0x00000000},
116 {0x00000079, 0x00001434},
117 {0x0000007a, 0xcc08ec08},
118 {0x0000007b, 0x00040000},
119 {0x0000007c, 0x000080c0},
120 {0x0000007d, 0x09000000},
121 {0x0000007e, 0x00210404},
122 {0x00000081, 0x08a8e800},
123 {0x00000082, 0x00030444},
124 {0x00000083, 0x00000000},
125 {0x00000085, 0x00000001},
126 {0x00000086, 0x00000002},
127 {0x00000087, 0x48490000},
128 {0x00000088, 0x20244647},
129 {0x00000089, 0x00000005},
130 {0x0000008b, 0x66030000},
131 {0x0000008c, 0x00006603},
132 {0x0000008d, 0x00000100},
133 {0x0000008f, 0x00001c0a},
134 {0x00000090, 0xff000001},
135 {0x00000094, 0x00101101},
136 {0x00000095, 0x00000fff},
137 {0x00000096, 0x00116fff},
138 {0x00000097, 0x60010000},
139 {0x00000098, 0x10010000},
140 {0x00000099, 0x00006000},
141 {0x0000009a, 0x00001000},
142 {0x0000009f, 0x00936a00}
146 {0x00000077, 0xff010100},
147 {0x00000078, 0x00000000},
148 {0x00000079, 0x00001434},
149 {0x0000007a, 0xcc08ec08},
150 {0x0000007b, 0x00040000},
151 {0x0000007c, 0x000080c0},
152 {0x0000007d, 0x09000000},
153 {0x0000007e, 0x00210404},
154 {0x00000081, 0x08a8e800},
155 {0x00000082, 0x00030444},
156 {0x00000083, 0x00000000},
157 {0x00000085, 0x00000001},
158 {0x00000086, 0x00000002},
159 {0x00000087, 0x48490000},
160 {0x00000088, 0x20244647},
161 {0x00000089, 0x00000005},
162 {0x0000008b, 0x66030000},
163 {0x0000008c, 0x00006603},
164 {0x0000008d, 0x00000100},
165 {0x0000008f, 0x00001c0a},
166 {0x00000090, 0xff000001},
167 {0x00000094, 0x00101101},
168 {0x00000095, 0x00000fff},
169 {0x00000096, 0x00116fff},
170 {0x00000097, 0x60010000},
171 {0x00000098, 0x10010000},
172 {0x00000099, 0x00006000},
173 {0x0000009a, 0x00001000},
174 {0x0000009f, 0x00916a00}
178 {0x00000077, 0xff010100},
179 {0x00000078, 0x00000000},
180 {0x00000079, 0x00001434},
181 {0x0000007a, 0xcc08ec08},
182 {0x0000007b, 0x00040000},
183 {0x0000007c, 0x000080c0},
184 {0x0000007d, 0x09000000},
185 {0x0000007e, 0x00210404},
186 {0x00000081, 0x08a8e800},
187 {0x00000082, 0x00030444},
188 {0x00000083, 0x00000000},
189 {0x00000085, 0x00000001},
190 {0x00000086, 0x00000002},
191 {0x00000087, 0x48490000},
192 {0x00000088, 0x20244647},
193 {0x00000089, 0x00000005},
194 {0x0000008b, 0x66030000},
195 {0x0000008c, 0x00006603},
196 {0x0000008d, 0x00000100},
197 {0x0000008f, 0x00001c0a},
198 {0x00000090, 0xff000001},
199 {0x00000094, 0x00101101},
200 {0x00000095, 0x00000fff},
201 {0x00000096, 0x00116fff},
202 {0x00000097, 0x60010000},
203 {0x00000098, 0x10010000},
204 {0x00000099, 0x00006000},
205 {0x0000009a, 0x00001000},
206 {0x0000009f, 0x00976b00}
214 int i, ucode_size, regs_size;
221 io_mc_regs = (
u32 *)&barts_io_mc_regs;
226 io_mc_regs = (
u32 *)&turks_io_mc_regs;
232 io_mc_regs = (
u32 *)&caicos_io_mc_regs;
237 io_mc_regs = (
u32 *)&cayman_io_mc_regs;
257 for (i = 0; i < regs_size; i++) {
263 for (i = 0; i < ucode_size; i++)
288 const char *chip_name;
289 const char *rlc_chip_name;
290 size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
296 pdev = platform_device_register_simple(
"radeon_cp", 0,
NULL, 0);
306 rlc_chip_name =
"BTC";
314 rlc_chip_name =
"BTC";
321 chip_name =
"CAICOS";
322 rlc_chip_name =
"BTC";
329 chip_name =
"CAYMAN";
330 rlc_chip_name =
"CAYMAN";
338 rlc_chip_name =
"ARUBA";
348 DRM_INFO(
"Loading %s Microcode\n", chip_name);
350 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_pfp.bin", chip_name);
354 if (rdev->
pfp_fw->size != pfp_req_size) {
356 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
357 rdev->
pfp_fw->size, fw_name);
362 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_me.bin", chip_name);
366 if (rdev->
me_fw->size != me_req_size) {
368 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
369 rdev->
me_fw->size, fw_name);
373 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_rlc.bin", rlc_chip_name);
377 if (rdev->
rlc_fw->size != rlc_req_size) {
379 "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
380 rdev->
rlc_fw->size, fw_name);
386 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_mc.bin", chip_name);
390 if (rdev->
mc_fw->size != mc_req_size) {
392 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
393 rdev->
mc_fw->size, fw_name);
403 "ni_cp: Failed to load firmware \"%s\"\n",
422 u32 gb_addr_config = 0;
423 u32 mc_shared_chmap, mc_arb_ramcfg;
424 u32 cgts_tcc_disable;
427 u32 cgts_sm_ctrl_reg;
428 u32 hdp_host_path_cntl;
430 u32 disabled_rb_mask;
462 if ((rdev->
pdev->device == 0x9900) ||
463 (rdev->
pdev->device == 0x9901) ||
464 (rdev->
pdev->device == 0x9905) ||
465 (rdev->
pdev->device == 0x9906) ||
466 (rdev->
pdev->device == 0x9907) ||
467 (rdev->
pdev->device == 0x9908) ||
468 (rdev->
pdev->device == 0x9909) ||
469 (rdev->
pdev->device == 0x9910) ||
470 (rdev->
pdev->device == 0x9917)) {
473 }
else if ((rdev->
pdev->device == 0x9903) ||
474 (rdev->
pdev->device == 0x9904) ||
475 (rdev->
pdev->device == 0x990A) ||
476 (rdev->
pdev->device == 0x9913) ||
477 (rdev->
pdev->device == 0x9918)) {
480 }
else if ((rdev->
pdev->device == 0x9919) ||
481 (rdev->
pdev->device == 0x9990) ||
482 (rdev->
pdev->device == 0x9991) ||
483 (rdev->
pdev->device == 0x9994) ||
484 (rdev->
pdev->device == 0x99A0)) {
511 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
512 WREG32((0x2c14 + j), 0x00000000);
513 WREG32((0x2c18 + j), 0x00000000);
514 WREG32((0x2c1c + j), 0x00000000);
515 WREG32((0x2c20 + j), 0x00000000);
516 WREG32((0x2c24 + j), 0x00000000);
527 rdev->
config.
cayman.mem_row_size_in_kb = (4 * (1 << (8 +
tmp))) / 1024;
538 rdev->
config.
cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
596 for (i = (rdev->
config.
cayman.max_shader_engines - 1); i >= 0; i--) {
597 u32 rb_disable_bitmap;
603 tmp |= rb_disable_bitmap;
606 disabled_rb_mask =
tmp;
622 cgts_tcc_disable = 0xffff0000;
623 for (i = 0; i < rdev->
config.
cayman.max_texture_channel_caches; i++)
624 cgts_tcc_disable &= ~(1 << (16 + i));
632 for (i = 0; i < 16; i++)
729 static int cayman_pcie_gart_enable(
struct radeon_device *rdev)
734 dev_err(rdev->
dev,
"No VRAM object for PCIE GART.\n");
777 for (i = 1; i < 8; i++) {
781 rdev->
gart.table_addr >> 12);
793 DRM_INFO(
"PCIE GART of %uM enabled (table at 0x%016llX).\n",
794 (
unsigned)(rdev->
mc.gtt_size >> 20),
795 (
unsigned long long)rdev->
gart.table_addr);
796 rdev->
gart.ready =
true;
800 static void cayman_pcie_gart_disable(
struct radeon_device *rdev)
820 static void cayman_pcie_gart_fini(
struct radeon_device *rdev)
822 cayman_pcie_gart_disable(rdev);
887 (ib->
vm ? (ib->
vm->id << 24) : 0));
911 static int cayman_cp_load_microcode(
struct radeon_device *rdev)
919 cayman_cp_enable(rdev,
false);
945 DRM_ERROR(
"radeon: cp failed to lock ring (%d).\n", r);
957 cayman_cp_enable(rdev,
true);
961 DRM_ERROR(
"radeon: cp failed to lock ring (%d).\n", r);
1007 cayman_cp_enable(rdev,
false);
1014 static const int ridx[] = {
1019 static const unsigned cp_rb_cntl[] = {
1024 static const unsigned cp_rb_rptr_addr[] = {
1029 static const unsigned cp_rb_rptr_addr_hi[] = {
1034 static const unsigned cp_rb_base[] = {
1066 for (i = 0; i < 3; ++
i) {
1071 ring = &rdev->
ring[ridx[
i]];
1077 WREG32(cp_rb_cntl[i], rb_cntl);
1081 WREG32(cp_rb_rptr_addr[i], addr & 0xFFFFFFFC);
1086 for (i = 0; i < 3; ++
i) {
1087 ring = &rdev->
ring[ridx[
i]];
1091 for (i = 0; i < 3; ++
i) {
1093 ring = &rdev->
ring[ridx[
i]];
1105 cayman_cp_start(rdev);
1121 static int cayman_gpu_soft_reset(
struct radeon_device *rdev)
1138 dev_info(rdev->
dev,
" R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1140 dev_info(rdev->
dev,
" R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1142 dev_info(rdev->
dev,
" R_00867C_CP_BUSY_STAT = 0x%08X\n",
1144 dev_info(rdev->
dev,
" R_008680_CP_STAT = 0x%08X\n",
1146 dev_info(rdev->
dev,
" VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
1148 dev_info(rdev->
dev,
" VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
1150 dev_info(rdev->
dev,
" VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1152 dev_info(rdev->
dev,
" VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1157 dev_warn(rdev->
dev,
"Wait for MC idle timedout !\n");
1177 dev_info(rdev->
dev,
" GRBM_SOFT_RESET=0x%08X\n", grbm_reset);
1194 dev_info(rdev->
dev,
" R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1196 dev_info(rdev->
dev,
" R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1198 dev_info(rdev->
dev,
" R_00867C_CP_BUSY_STAT = 0x%08X\n",
1200 dev_info(rdev->
dev,
" R_008680_CP_STAT = 0x%08X\n",
1208 return cayman_gpu_soft_reset(rdev);
1223 DRM_ERROR(
"Failed to load firmware!\n");
1231 DRM_ERROR(
"Failed to load firmware!\n");
1238 DRM_ERROR(
"Failed to load MC firmware!\n");
1248 r = cayman_pcie_gart_enable(rdev);
1251 cayman_gpu_init(rdev);
1257 dev_warn(rdev->
dev,
"failed blitter (%d) falling back to memcpy\n", r);
1264 DRM_ERROR(
"Failed to init rlc BOs!\n");
1276 dev_err(rdev->
dev,
"failed initializing CP fences (%d).\n", r);
1282 dev_err(rdev->
dev,
"failed initializing CP fences (%d).\n", r);
1288 dev_err(rdev->
dev,
"failed initializing CP fences (%d).\n", r);
1295 DRM_ERROR(
"radeon: IH init failed (%d).\n", r);
1306 r = cayman_cp_load_microcode(rdev);
1309 r = cayman_cp_resume(rdev);
1315 dev_err(rdev->
dev,
"IB initialization failed (%d).\n", r);
1321 dev_err(rdev->
dev,
"vm manager initialization failed (%d).\n", r);
1344 r = cayman_startup(rdev);
1346 DRM_ERROR(
"cayman startup failed on resume\n");
1356 cayman_cp_enable(rdev,
false);
1360 cayman_pcie_gart_disable(rdev);
1382 dev_err(rdev->
dev,
"Expecting atombios for cayman GPU\n");
1392 dev_err(rdev->
dev,
"Card not posted and no BIOS - ignoring\n");
1395 DRM_INFO(
"GPU not posted. posting now...\n");
1424 rdev->
ih.ring_obj =
NULL;
1432 r = cayman_startup(rdev);
1434 dev_err(rdev->
dev,
"disabling GPU acceleration\n");
1435 cayman_cp_fini(rdev);
1443 cayman_pcie_gart_fini(rdev);
1455 DRM_ERROR(
"radeon: MC ucode required for NI+.\n");
1465 cayman_cp_fini(rdev);
1473 cayman_pcie_gart_fini(rdev);
1504 #define R600_ENTRY_VALID (1 << 0)
1505 #define R600_PTE_SYSTEM (1 << 1)
1506 #define R600_PTE_SNOOPED (1 << 2)
1507 #define R600_PTE_READABLE (1 << 5)
1508 #define R600_PTE_WRITEABLE (1 << 6)
1543 unsigned ndw = 1 + count * 2;
1550 for (; ndw > 1; ndw -= 2, --
count, pe += 8) {
1554 value &= 0xFFFFFFFFFFFFF000ULL;
1562 value |= r600_flags;