Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 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 | |
| 35 | #define EVERGREEN_PFP_UCODE_SIZE 1120 |
| 36 | #define EVERGREEN_PM4_UCODE_SIZE 1376 |
| 37 | #define EVERGREEN_RLC_UCODE_SIZE 768 |
| 38 | #define BTC_MC_UCODE_SIZE 6024 |
| 39 | |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 40 | #define CAYMAN_PFP_UCODE_SIZE 2176 |
| 41 | #define CAYMAN_PM4_UCODE_SIZE 2176 |
| 42 | #define CAYMAN_RLC_UCODE_SIZE 1024 |
| 43 | #define CAYMAN_MC_UCODE_SIZE 6037 |
| 44 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 45 | /* Firmware Names */ |
| 46 | MODULE_FIRMWARE("radeon/BARTS_pfp.bin"); |
| 47 | MODULE_FIRMWARE("radeon/BARTS_me.bin"); |
| 48 | MODULE_FIRMWARE("radeon/BARTS_mc.bin"); |
| 49 | MODULE_FIRMWARE("radeon/BTC_rlc.bin"); |
| 50 | MODULE_FIRMWARE("radeon/TURKS_pfp.bin"); |
| 51 | MODULE_FIRMWARE("radeon/TURKS_me.bin"); |
| 52 | MODULE_FIRMWARE("radeon/TURKS_mc.bin"); |
| 53 | MODULE_FIRMWARE("radeon/CAICOS_pfp.bin"); |
| 54 | MODULE_FIRMWARE("radeon/CAICOS_me.bin"); |
| 55 | MODULE_FIRMWARE("radeon/CAICOS_mc.bin"); |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 56 | MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin"); |
| 57 | MODULE_FIRMWARE("radeon/CAYMAN_me.bin"); |
| 58 | MODULE_FIRMWARE("radeon/CAYMAN_mc.bin"); |
| 59 | MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin"); |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 60 | |
| 61 | #define BTC_IO_MC_REGS_SIZE 29 |
| 62 | |
| 63 | static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 64 | {0x00000077, 0xff010100}, |
| 65 | {0x00000078, 0x00000000}, |
| 66 | {0x00000079, 0x00001434}, |
| 67 | {0x0000007a, 0xcc08ec08}, |
| 68 | {0x0000007b, 0x00040000}, |
| 69 | {0x0000007c, 0x000080c0}, |
| 70 | {0x0000007d, 0x09000000}, |
| 71 | {0x0000007e, 0x00210404}, |
| 72 | {0x00000081, 0x08a8e800}, |
| 73 | {0x00000082, 0x00030444}, |
| 74 | {0x00000083, 0x00000000}, |
| 75 | {0x00000085, 0x00000001}, |
| 76 | {0x00000086, 0x00000002}, |
| 77 | {0x00000087, 0x48490000}, |
| 78 | {0x00000088, 0x20244647}, |
| 79 | {0x00000089, 0x00000005}, |
| 80 | {0x0000008b, 0x66030000}, |
| 81 | {0x0000008c, 0x00006603}, |
| 82 | {0x0000008d, 0x00000100}, |
| 83 | {0x0000008f, 0x00001c0a}, |
| 84 | {0x00000090, 0xff000001}, |
| 85 | {0x00000094, 0x00101101}, |
| 86 | {0x00000095, 0x00000fff}, |
| 87 | {0x00000096, 0x00116fff}, |
| 88 | {0x00000097, 0x60010000}, |
| 89 | {0x00000098, 0x10010000}, |
| 90 | {0x00000099, 0x00006000}, |
| 91 | {0x0000009a, 0x00001000}, |
| 92 | {0x0000009f, 0x00946a00} |
| 93 | }; |
| 94 | |
| 95 | static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 96 | {0x00000077, 0xff010100}, |
| 97 | {0x00000078, 0x00000000}, |
| 98 | {0x00000079, 0x00001434}, |
| 99 | {0x0000007a, 0xcc08ec08}, |
| 100 | {0x0000007b, 0x00040000}, |
| 101 | {0x0000007c, 0x000080c0}, |
| 102 | {0x0000007d, 0x09000000}, |
| 103 | {0x0000007e, 0x00210404}, |
| 104 | {0x00000081, 0x08a8e800}, |
| 105 | {0x00000082, 0x00030444}, |
| 106 | {0x00000083, 0x00000000}, |
| 107 | {0x00000085, 0x00000001}, |
| 108 | {0x00000086, 0x00000002}, |
| 109 | {0x00000087, 0x48490000}, |
| 110 | {0x00000088, 0x20244647}, |
| 111 | {0x00000089, 0x00000005}, |
| 112 | {0x0000008b, 0x66030000}, |
| 113 | {0x0000008c, 0x00006603}, |
| 114 | {0x0000008d, 0x00000100}, |
| 115 | {0x0000008f, 0x00001c0a}, |
| 116 | {0x00000090, 0xff000001}, |
| 117 | {0x00000094, 0x00101101}, |
| 118 | {0x00000095, 0x00000fff}, |
| 119 | {0x00000096, 0x00116fff}, |
| 120 | {0x00000097, 0x60010000}, |
| 121 | {0x00000098, 0x10010000}, |
| 122 | {0x00000099, 0x00006000}, |
| 123 | {0x0000009a, 0x00001000}, |
| 124 | {0x0000009f, 0x00936a00} |
| 125 | }; |
| 126 | |
| 127 | static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 128 | {0x00000077, 0xff010100}, |
| 129 | {0x00000078, 0x00000000}, |
| 130 | {0x00000079, 0x00001434}, |
| 131 | {0x0000007a, 0xcc08ec08}, |
| 132 | {0x0000007b, 0x00040000}, |
| 133 | {0x0000007c, 0x000080c0}, |
| 134 | {0x0000007d, 0x09000000}, |
| 135 | {0x0000007e, 0x00210404}, |
| 136 | {0x00000081, 0x08a8e800}, |
| 137 | {0x00000082, 0x00030444}, |
| 138 | {0x00000083, 0x00000000}, |
| 139 | {0x00000085, 0x00000001}, |
| 140 | {0x00000086, 0x00000002}, |
| 141 | {0x00000087, 0x48490000}, |
| 142 | {0x00000088, 0x20244647}, |
| 143 | {0x00000089, 0x00000005}, |
| 144 | {0x0000008b, 0x66030000}, |
| 145 | {0x0000008c, 0x00006603}, |
| 146 | {0x0000008d, 0x00000100}, |
| 147 | {0x0000008f, 0x00001c0a}, |
| 148 | {0x00000090, 0xff000001}, |
| 149 | {0x00000094, 0x00101101}, |
| 150 | {0x00000095, 0x00000fff}, |
| 151 | {0x00000096, 0x00116fff}, |
| 152 | {0x00000097, 0x60010000}, |
| 153 | {0x00000098, 0x10010000}, |
| 154 | {0x00000099, 0x00006000}, |
| 155 | {0x0000009a, 0x00001000}, |
| 156 | {0x0000009f, 0x00916a00} |
| 157 | }; |
| 158 | |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 159 | static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 160 | {0x00000077, 0xff010100}, |
| 161 | {0x00000078, 0x00000000}, |
| 162 | {0x00000079, 0x00001434}, |
| 163 | {0x0000007a, 0xcc08ec08}, |
| 164 | {0x0000007b, 0x00040000}, |
| 165 | {0x0000007c, 0x000080c0}, |
| 166 | {0x0000007d, 0x09000000}, |
| 167 | {0x0000007e, 0x00210404}, |
| 168 | {0x00000081, 0x08a8e800}, |
| 169 | {0x00000082, 0x00030444}, |
| 170 | {0x00000083, 0x00000000}, |
| 171 | {0x00000085, 0x00000001}, |
| 172 | {0x00000086, 0x00000002}, |
| 173 | {0x00000087, 0x48490000}, |
| 174 | {0x00000088, 0x20244647}, |
| 175 | {0x00000089, 0x00000005}, |
| 176 | {0x0000008b, 0x66030000}, |
| 177 | {0x0000008c, 0x00006603}, |
| 178 | {0x0000008d, 0x00000100}, |
| 179 | {0x0000008f, 0x00001c0a}, |
| 180 | {0x00000090, 0xff000001}, |
| 181 | {0x00000094, 0x00101101}, |
| 182 | {0x00000095, 0x00000fff}, |
| 183 | {0x00000096, 0x00116fff}, |
| 184 | {0x00000097, 0x60010000}, |
| 185 | {0x00000098, 0x10010000}, |
| 186 | {0x00000099, 0x00006000}, |
| 187 | {0x0000009a, 0x00001000}, |
| 188 | {0x0000009f, 0x00976b00} |
| 189 | }; |
| 190 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 191 | int btc_mc_load_microcode(struct radeon_device *rdev) |
| 192 | { |
| 193 | const __be32 *fw_data; |
| 194 | u32 mem_type, running, blackout = 0; |
| 195 | u32 *io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 196 | int i, ucode_size, regs_size; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 197 | |
| 198 | if (!rdev->mc_fw) |
| 199 | return -EINVAL; |
| 200 | |
| 201 | switch (rdev->family) { |
| 202 | case CHIP_BARTS: |
| 203 | io_mc_regs = (u32 *)&barts_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 204 | ucode_size = BTC_MC_UCODE_SIZE; |
| 205 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 206 | break; |
| 207 | case CHIP_TURKS: |
| 208 | io_mc_regs = (u32 *)&turks_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 209 | ucode_size = BTC_MC_UCODE_SIZE; |
| 210 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 211 | break; |
| 212 | case CHIP_CAICOS: |
| 213 | default: |
| 214 | io_mc_regs = (u32 *)&caicos_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 215 | ucode_size = BTC_MC_UCODE_SIZE; |
| 216 | regs_size = BTC_IO_MC_REGS_SIZE; |
| 217 | break; |
| 218 | case CHIP_CAYMAN: |
| 219 | io_mc_regs = (u32 *)&cayman_io_mc_regs; |
| 220 | ucode_size = CAYMAN_MC_UCODE_SIZE; |
| 221 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | |
| 225 | mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT; |
| 226 | running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK; |
| 227 | |
| 228 | if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) { |
| 229 | if (running) { |
| 230 | blackout = RREG32(MC_SHARED_BLACKOUT_CNTL); |
| 231 | WREG32(MC_SHARED_BLACKOUT_CNTL, 1); |
| 232 | } |
| 233 | |
| 234 | /* reset the engine and set to writable */ |
| 235 | WREG32(MC_SEQ_SUP_CNTL, 0x00000008); |
| 236 | WREG32(MC_SEQ_SUP_CNTL, 0x00000010); |
| 237 | |
| 238 | /* load mc io regs */ |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 239 | for (i = 0; i < regs_size; i++) { |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 240 | WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]); |
| 241 | WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]); |
| 242 | } |
| 243 | /* load the MC ucode */ |
| 244 | fw_data = (const __be32 *)rdev->mc_fw->data; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 245 | for (i = 0; i < ucode_size; i++) |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 246 | WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++)); |
| 247 | |
| 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 | |
| 253 | /* wait for training to complete */ |
| 254 | while (!(RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)) |
| 255 | udelay(10); |
| 256 | |
| 257 | if (running) |
| 258 | WREG32(MC_SHARED_BLACKOUT_CNTL, blackout); |
| 259 | } |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int ni_init_microcode(struct radeon_device *rdev) |
| 265 | { |
| 266 | struct platform_device *pdev; |
| 267 | const char *chip_name; |
| 268 | const char *rlc_chip_name; |
| 269 | size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size; |
| 270 | char fw_name[30]; |
| 271 | int err; |
| 272 | |
| 273 | DRM_DEBUG("\n"); |
| 274 | |
| 275 | pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); |
| 276 | err = IS_ERR(pdev); |
| 277 | if (err) { |
| 278 | printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); |
| 279 | return -EINVAL; |
| 280 | } |
| 281 | |
| 282 | switch (rdev->family) { |
| 283 | case CHIP_BARTS: |
| 284 | chip_name = "BARTS"; |
| 285 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 286 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 287 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 288 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 289 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 290 | break; |
| 291 | case CHIP_TURKS: |
| 292 | chip_name = "TURKS"; |
| 293 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 294 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 295 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 296 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 297 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 298 | break; |
| 299 | case CHIP_CAICOS: |
| 300 | chip_name = "CAICOS"; |
| 301 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 302 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 303 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 304 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 305 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
| 306 | break; |
| 307 | case CHIP_CAYMAN: |
| 308 | chip_name = "CAYMAN"; |
| 309 | rlc_chip_name = "CAYMAN"; |
| 310 | pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4; |
| 311 | me_req_size = CAYMAN_PM4_UCODE_SIZE * 4; |
| 312 | rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4; |
| 313 | mc_req_size = CAYMAN_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 314 | break; |
| 315 | default: BUG(); |
| 316 | } |
| 317 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 318 | DRM_INFO("Loading %s Microcode\n", chip_name); |
| 319 | |
| 320 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name); |
| 321 | err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev); |
| 322 | if (err) |
| 323 | goto out; |
| 324 | if (rdev->pfp_fw->size != pfp_req_size) { |
| 325 | printk(KERN_ERR |
| 326 | "ni_cp: Bogus length %zu in firmware \"%s\"\n", |
| 327 | rdev->pfp_fw->size, fw_name); |
| 328 | err = -EINVAL; |
| 329 | goto out; |
| 330 | } |
| 331 | |
| 332 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name); |
| 333 | err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); |
| 334 | if (err) |
| 335 | goto out; |
| 336 | if (rdev->me_fw->size != me_req_size) { |
| 337 | printk(KERN_ERR |
| 338 | "ni_cp: Bogus length %zu in firmware \"%s\"\n", |
| 339 | rdev->me_fw->size, fw_name); |
| 340 | err = -EINVAL; |
| 341 | } |
| 342 | |
| 343 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name); |
| 344 | err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev); |
| 345 | if (err) |
| 346 | goto out; |
| 347 | if (rdev->rlc_fw->size != rlc_req_size) { |
| 348 | printk(KERN_ERR |
| 349 | "ni_rlc: Bogus length %zu in firmware \"%s\"\n", |
| 350 | rdev->rlc_fw->size, fw_name); |
| 351 | err = -EINVAL; |
| 352 | } |
| 353 | |
| 354 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name); |
| 355 | err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev); |
| 356 | if (err) |
| 357 | goto out; |
| 358 | if (rdev->mc_fw->size != mc_req_size) { |
| 359 | printk(KERN_ERR |
| 360 | "ni_mc: Bogus length %zu in firmware \"%s\"\n", |
| 361 | rdev->mc_fw->size, fw_name); |
| 362 | err = -EINVAL; |
| 363 | } |
| 364 | out: |
| 365 | platform_device_unregister(pdev); |
| 366 | |
| 367 | if (err) { |
| 368 | if (err != -EINVAL) |
| 369 | printk(KERN_ERR |
| 370 | "ni_cp: Failed to load firmware \"%s\"\n", |
| 371 | fw_name); |
| 372 | release_firmware(rdev->pfp_fw); |
| 373 | rdev->pfp_fw = NULL; |
| 374 | release_firmware(rdev->me_fw); |
| 375 | rdev->me_fw = NULL; |
| 376 | release_firmware(rdev->rlc_fw); |
| 377 | rdev->rlc_fw = NULL; |
| 378 | release_firmware(rdev->mc_fw); |
| 379 | rdev->mc_fw = NULL; |
| 380 | } |
| 381 | return err; |
| 382 | } |
| 383 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 384 | /* |
| 385 | * Core functions |
| 386 | */ |
| 387 | static u32 cayman_get_tile_pipe_to_backend_map(struct radeon_device *rdev, |
| 388 | u32 num_tile_pipes, |
| 389 | u32 num_backends_per_asic, |
| 390 | u32 *backend_disable_mask_per_asic, |
| 391 | u32 num_shader_engines) |
| 392 | { |
| 393 | u32 backend_map = 0; |
| 394 | u32 enabled_backends_mask = 0; |
| 395 | u32 enabled_backends_count = 0; |
| 396 | u32 num_backends_per_se; |
| 397 | u32 cur_pipe; |
| 398 | u32 swizzle_pipe[CAYMAN_MAX_PIPES]; |
| 399 | u32 cur_backend = 0; |
| 400 | u32 i; |
| 401 | bool force_no_swizzle; |
| 402 | |
| 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 | |
| 417 | /* make sure we have the same number of backends per se */ |
| 418 | num_backends_per_asic = ALIGN(num_backends_per_asic, num_shader_engines); |
| 419 | /* set up the number of backends per se */ |
| 420 | num_backends_per_se = num_backends_per_asic / num_shader_engines; |
| 421 | if (num_backends_per_se > rdev->config.cayman.max_backends_per_se) { |
| 422 | num_backends_per_se = rdev->config.cayman.max_backends_per_se; |
| 423 | num_backends_per_asic = num_backends_per_se * num_shader_engines; |
| 424 | } |
| 425 | |
| 426 | /* create enable mask and count for enabled backends */ |
| 427 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 428 | if (((*backend_disable_mask_per_asic >> i) & 1) == 0) { |
| 429 | enabled_backends_mask |= (1 << i); |
| 430 | ++enabled_backends_count; |
| 431 | } |
| 432 | if (enabled_backends_count == num_backends_per_asic) |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | /* force the backends mask to match the current number of backends */ |
| 437 | if (enabled_backends_count != num_backends_per_asic) { |
| 438 | u32 this_backend_enabled; |
| 439 | u32 shader_engine; |
| 440 | u32 backend_per_se; |
| 441 | |
| 442 | enabled_backends_mask = 0; |
| 443 | enabled_backends_count = 0; |
| 444 | *backend_disable_mask_per_asic = CAYMAN_MAX_BACKENDS_MASK; |
| 445 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 446 | /* calc the current se */ |
| 447 | shader_engine = i / rdev->config.cayman.max_backends_per_se; |
| 448 | /* calc the backend per se */ |
| 449 | backend_per_se = i % rdev->config.cayman.max_backends_per_se; |
| 450 | /* default to not enabled */ |
| 451 | this_backend_enabled = 0; |
| 452 | if ((shader_engine < num_shader_engines) && |
| 453 | (backend_per_se < num_backends_per_se)) |
| 454 | this_backend_enabled = 1; |
| 455 | if (this_backend_enabled) { |
| 456 | enabled_backends_mask |= (1 << i); |
| 457 | *backend_disable_mask_per_asic &= ~(1 << i); |
| 458 | ++enabled_backends_count; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | |
| 464 | memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * CAYMAN_MAX_PIPES); |
| 465 | switch (rdev->family) { |
| 466 | case CHIP_CAYMAN: |
| 467 | force_no_swizzle = true; |
| 468 | break; |
| 469 | default: |
| 470 | force_no_swizzle = false; |
| 471 | break; |
| 472 | } |
| 473 | if (force_no_swizzle) { |
| 474 | bool last_backend_enabled = false; |
| 475 | |
| 476 | force_no_swizzle = false; |
| 477 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 478 | if (((enabled_backends_mask >> i) & 1) == 1) { |
| 479 | if (last_backend_enabled) |
| 480 | force_no_swizzle = true; |
| 481 | last_backend_enabled = true; |
| 482 | } else |
| 483 | last_backend_enabled = false; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | switch (num_tile_pipes) { |
| 488 | case 1: |
| 489 | case 3: |
| 490 | case 5: |
| 491 | case 7: |
| 492 | DRM_ERROR("odd number of pipes!\n"); |
| 493 | break; |
| 494 | case 2: |
| 495 | swizzle_pipe[0] = 0; |
| 496 | swizzle_pipe[1] = 1; |
| 497 | break; |
| 498 | case 4: |
| 499 | if (force_no_swizzle) { |
| 500 | swizzle_pipe[0] = 0; |
| 501 | swizzle_pipe[1] = 1; |
| 502 | swizzle_pipe[2] = 2; |
| 503 | swizzle_pipe[3] = 3; |
| 504 | } else { |
| 505 | swizzle_pipe[0] = 0; |
| 506 | swizzle_pipe[1] = 2; |
| 507 | swizzle_pipe[2] = 1; |
| 508 | swizzle_pipe[3] = 3; |
| 509 | } |
| 510 | break; |
| 511 | case 6: |
| 512 | if (force_no_swizzle) { |
| 513 | swizzle_pipe[0] = 0; |
| 514 | swizzle_pipe[1] = 1; |
| 515 | swizzle_pipe[2] = 2; |
| 516 | swizzle_pipe[3] = 3; |
| 517 | swizzle_pipe[4] = 4; |
| 518 | swizzle_pipe[5] = 5; |
| 519 | } else { |
| 520 | swizzle_pipe[0] = 0; |
| 521 | swizzle_pipe[1] = 2; |
| 522 | swizzle_pipe[2] = 4; |
| 523 | swizzle_pipe[3] = 1; |
| 524 | swizzle_pipe[4] = 3; |
| 525 | swizzle_pipe[5] = 5; |
| 526 | } |
| 527 | break; |
| 528 | case 8: |
| 529 | if (force_no_swizzle) { |
| 530 | swizzle_pipe[0] = 0; |
| 531 | swizzle_pipe[1] = 1; |
| 532 | swizzle_pipe[2] = 2; |
| 533 | swizzle_pipe[3] = 3; |
| 534 | swizzle_pipe[4] = 4; |
| 535 | swizzle_pipe[5] = 5; |
| 536 | swizzle_pipe[6] = 6; |
| 537 | swizzle_pipe[7] = 7; |
| 538 | } else { |
| 539 | swizzle_pipe[0] = 0; |
| 540 | swizzle_pipe[1] = 2; |
| 541 | swizzle_pipe[2] = 4; |
| 542 | swizzle_pipe[3] = 6; |
| 543 | swizzle_pipe[4] = 1; |
| 544 | swizzle_pipe[5] = 3; |
| 545 | swizzle_pipe[6] = 5; |
| 546 | swizzle_pipe[7] = 7; |
| 547 | } |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) { |
| 552 | while (((1 << cur_backend) & enabled_backends_mask) == 0) |
| 553 | cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS; |
| 554 | |
| 555 | backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4))); |
| 556 | |
| 557 | cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS; |
| 558 | } |
| 559 | |
| 560 | return backend_map; |
| 561 | } |
| 562 | |
| 563 | static void cayman_program_channel_remap(struct radeon_device *rdev) |
| 564 | { |
| 565 | u32 tcp_chan_steer_lo, tcp_chan_steer_hi, mc_shared_chremap, tmp; |
| 566 | |
| 567 | tmp = RREG32(MC_SHARED_CHMAP); |
| 568 | switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { |
| 569 | case 0: |
| 570 | case 1: |
| 571 | case 2: |
| 572 | case 3: |
| 573 | default: |
| 574 | /* default mapping */ |
| 575 | mc_shared_chremap = 0x00fac688; |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | switch (rdev->family) { |
| 580 | case CHIP_CAYMAN: |
| 581 | default: |
| 582 | //tcp_chan_steer_lo = 0x54763210 |
| 583 | tcp_chan_steer_lo = 0x76543210; |
| 584 | tcp_chan_steer_hi = 0x0000ba98; |
| 585 | break; |
| 586 | } |
| 587 | |
| 588 | WREG32(TCP_CHAN_STEER_LO, tcp_chan_steer_lo); |
| 589 | WREG32(TCP_CHAN_STEER_HI, tcp_chan_steer_hi); |
| 590 | WREG32(MC_SHARED_CHREMAP, mc_shared_chremap); |
| 591 | } |
| 592 | |
| 593 | static u32 cayman_get_disable_mask_per_asic(struct radeon_device *rdev, |
| 594 | u32 disable_mask_per_se, |
| 595 | u32 max_disable_mask_per_se, |
| 596 | u32 num_shader_engines) |
| 597 | { |
| 598 | u32 disable_field_width_per_se = r600_count_pipe_bits(disable_mask_per_se); |
| 599 | u32 disable_mask_per_asic = disable_mask_per_se & max_disable_mask_per_se; |
| 600 | |
| 601 | if (num_shader_engines == 1) |
| 602 | return disable_mask_per_asic; |
| 603 | else if (num_shader_engines == 2) |
| 604 | return disable_mask_per_asic | (disable_mask_per_asic << disable_field_width_per_se); |
| 605 | else |
| 606 | return 0xffffffff; |
| 607 | } |
| 608 | |
| 609 | static void cayman_gpu_init(struct radeon_device *rdev) |
| 610 | { |
| 611 | u32 cc_rb_backend_disable = 0; |
| 612 | u32 cc_gc_shader_pipe_config; |
| 613 | u32 gb_addr_config = 0; |
| 614 | u32 mc_shared_chmap, mc_arb_ramcfg; |
| 615 | u32 gb_backend_map; |
| 616 | u32 cgts_tcc_disable; |
| 617 | u32 sx_debug_1; |
| 618 | u32 smx_dc_ctl0; |
| 619 | u32 gc_user_shader_pipe_config; |
| 620 | u32 gc_user_rb_backend_disable; |
| 621 | u32 cgts_user_tcc_disable; |
| 622 | u32 cgts_sm_ctrl_reg; |
| 623 | u32 hdp_host_path_cntl; |
| 624 | u32 tmp; |
| 625 | int i, j; |
| 626 | |
| 627 | switch (rdev->family) { |
| 628 | case CHIP_CAYMAN: |
| 629 | default: |
| 630 | rdev->config.cayman.max_shader_engines = 2; |
| 631 | rdev->config.cayman.max_pipes_per_simd = 4; |
| 632 | rdev->config.cayman.max_tile_pipes = 8; |
| 633 | rdev->config.cayman.max_simds_per_se = 12; |
| 634 | rdev->config.cayman.max_backends_per_se = 4; |
| 635 | rdev->config.cayman.max_texture_channel_caches = 8; |
| 636 | rdev->config.cayman.max_gprs = 256; |
| 637 | rdev->config.cayman.max_threads = 256; |
| 638 | rdev->config.cayman.max_gs_threads = 32; |
| 639 | rdev->config.cayman.max_stack_entries = 512; |
| 640 | rdev->config.cayman.sx_num_of_sets = 8; |
| 641 | rdev->config.cayman.sx_max_export_size = 256; |
| 642 | rdev->config.cayman.sx_max_export_pos_size = 64; |
| 643 | rdev->config.cayman.sx_max_export_smx_size = 192; |
| 644 | rdev->config.cayman.max_hw_contexts = 8; |
| 645 | rdev->config.cayman.sq_num_cf_insts = 2; |
| 646 | |
| 647 | rdev->config.cayman.sc_prim_fifo_size = 0x100; |
| 648 | rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30; |
| 649 | rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130; |
| 650 | break; |
| 651 | } |
| 652 | |
| 653 | /* Initialize HDP */ |
| 654 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 655 | WREG32((0x2c14 + j), 0x00000000); |
| 656 | WREG32((0x2c18 + j), 0x00000000); |
| 657 | WREG32((0x2c1c + j), 0x00000000); |
| 658 | WREG32((0x2c20 + j), 0x00000000); |
| 659 | WREG32((0x2c24 + j), 0x00000000); |
| 660 | } |
| 661 | |
| 662 | WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff)); |
| 663 | |
| 664 | mc_shared_chmap = RREG32(MC_SHARED_CHMAP); |
| 665 | mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); |
| 666 | |
| 667 | cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE); |
| 668 | cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG); |
| 669 | cgts_tcc_disable = RREG32(CGTS_TCC_DISABLE); |
| 670 | gc_user_rb_backend_disable = RREG32(GC_USER_RB_BACKEND_DISABLE); |
| 671 | gc_user_shader_pipe_config = RREG32(GC_USER_SHADER_PIPE_CONFIG); |
| 672 | cgts_user_tcc_disable = RREG32(CGTS_USER_TCC_DISABLE); |
| 673 | |
| 674 | rdev->config.cayman.num_shader_engines = rdev->config.cayman.max_shader_engines; |
| 675 | tmp = ((~gc_user_shader_pipe_config) & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT; |
| 676 | rdev->config.cayman.num_shader_pipes_per_simd = r600_count_pipe_bits(tmp); |
| 677 | rdev->config.cayman.num_tile_pipes = rdev->config.cayman.max_tile_pipes; |
| 678 | tmp = ((~gc_user_shader_pipe_config) & INACTIVE_SIMDS_MASK) >> INACTIVE_SIMDS_SHIFT; |
| 679 | rdev->config.cayman.num_simds_per_se = r600_count_pipe_bits(tmp); |
| 680 | tmp = ((~gc_user_rb_backend_disable) & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT; |
| 681 | rdev->config.cayman.num_backends_per_se = r600_count_pipe_bits(tmp); |
| 682 | tmp = (gc_user_rb_backend_disable & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT; |
| 683 | rdev->config.cayman.backend_disable_mask_per_asic = |
| 684 | cayman_get_disable_mask_per_asic(rdev, tmp, CAYMAN_MAX_BACKENDS_PER_SE_MASK, |
| 685 | rdev->config.cayman.num_shader_engines); |
| 686 | rdev->config.cayman.backend_map = |
| 687 | cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes, |
| 688 | rdev->config.cayman.num_backends_per_se * |
| 689 | rdev->config.cayman.num_shader_engines, |
| 690 | &rdev->config.cayman.backend_disable_mask_per_asic, |
| 691 | rdev->config.cayman.num_shader_engines); |
| 692 | tmp = ((~cgts_user_tcc_disable) & TCC_DISABLE_MASK) >> TCC_DISABLE_SHIFT; |
| 693 | rdev->config.cayman.num_texture_channel_caches = r600_count_pipe_bits(tmp); |
| 694 | tmp = (mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT; |
| 695 | rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256; |
| 696 | if (rdev->config.cayman.mem_max_burst_length_bytes > 512) |
| 697 | rdev->config.cayman.mem_max_burst_length_bytes = 512; |
| 698 | tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT; |
| 699 | rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024; |
| 700 | if (rdev->config.cayman.mem_row_size_in_kb > 4) |
| 701 | rdev->config.cayman.mem_row_size_in_kb = 4; |
| 702 | /* XXX use MC settings? */ |
| 703 | rdev->config.cayman.shader_engine_tile_size = 32; |
| 704 | rdev->config.cayman.num_gpus = 1; |
| 705 | rdev->config.cayman.multi_gpu_tile_size = 64; |
| 706 | |
| 707 | //gb_addr_config = 0x02011003 |
| 708 | #if 0 |
| 709 | gb_addr_config = RREG32(GB_ADDR_CONFIG); |
| 710 | #else |
| 711 | gb_addr_config = 0; |
| 712 | switch (rdev->config.cayman.num_tile_pipes) { |
| 713 | case 1: |
| 714 | default: |
| 715 | gb_addr_config |= NUM_PIPES(0); |
| 716 | break; |
| 717 | case 2: |
| 718 | gb_addr_config |= NUM_PIPES(1); |
| 719 | break; |
| 720 | case 4: |
| 721 | gb_addr_config |= NUM_PIPES(2); |
| 722 | break; |
| 723 | case 8: |
| 724 | gb_addr_config |= NUM_PIPES(3); |
| 725 | break; |
| 726 | } |
| 727 | |
| 728 | tmp = (rdev->config.cayman.mem_max_burst_length_bytes / 256) - 1; |
| 729 | gb_addr_config |= PIPE_INTERLEAVE_SIZE(tmp); |
| 730 | gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.cayman.num_shader_engines - 1); |
| 731 | tmp = (rdev->config.cayman.shader_engine_tile_size / 16) - 1; |
| 732 | gb_addr_config |= SHADER_ENGINE_TILE_SIZE(tmp); |
| 733 | switch (rdev->config.cayman.num_gpus) { |
| 734 | case 1: |
| 735 | default: |
| 736 | gb_addr_config |= NUM_GPUS(0); |
| 737 | break; |
| 738 | case 2: |
| 739 | gb_addr_config |= NUM_GPUS(1); |
| 740 | break; |
| 741 | case 4: |
| 742 | gb_addr_config |= NUM_GPUS(2); |
| 743 | break; |
| 744 | } |
| 745 | switch (rdev->config.cayman.multi_gpu_tile_size) { |
| 746 | case 16: |
| 747 | gb_addr_config |= MULTI_GPU_TILE_SIZE(0); |
| 748 | break; |
| 749 | case 32: |
| 750 | default: |
| 751 | gb_addr_config |= MULTI_GPU_TILE_SIZE(1); |
| 752 | break; |
| 753 | case 64: |
| 754 | gb_addr_config |= MULTI_GPU_TILE_SIZE(2); |
| 755 | break; |
| 756 | case 128: |
| 757 | gb_addr_config |= MULTI_GPU_TILE_SIZE(3); |
| 758 | break; |
| 759 | } |
| 760 | switch (rdev->config.cayman.mem_row_size_in_kb) { |
| 761 | case 1: |
| 762 | default: |
| 763 | gb_addr_config |= ROW_SIZE(0); |
| 764 | break; |
| 765 | case 2: |
| 766 | gb_addr_config |= ROW_SIZE(1); |
| 767 | break; |
| 768 | case 4: |
| 769 | gb_addr_config |= ROW_SIZE(2); |
| 770 | break; |
| 771 | } |
| 772 | #endif |
| 773 | |
| 774 | tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT; |
| 775 | rdev->config.cayman.num_tile_pipes = (1 << tmp); |
| 776 | tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT; |
| 777 | rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256; |
| 778 | tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT; |
| 779 | rdev->config.cayman.num_shader_engines = tmp + 1; |
| 780 | tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT; |
| 781 | rdev->config.cayman.num_gpus = tmp + 1; |
| 782 | tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT; |
| 783 | rdev->config.cayman.multi_gpu_tile_size = 1 << tmp; |
| 784 | tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT; |
| 785 | rdev->config.cayman.mem_row_size_in_kb = 1 << tmp; |
| 786 | |
| 787 | //gb_backend_map = 0x76541032; |
| 788 | #if 0 |
| 789 | gb_backend_map = RREG32(GB_BACKEND_MAP); |
| 790 | #else |
| 791 | gb_backend_map = |
| 792 | cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes, |
| 793 | rdev->config.cayman.num_backends_per_se * |
| 794 | rdev->config.cayman.num_shader_engines, |
| 795 | &rdev->config.cayman.backend_disable_mask_per_asic, |
| 796 | rdev->config.cayman.num_shader_engines); |
| 797 | #endif |
| 798 | /* setup tiling info dword. gb_addr_config is not adequate since it does |
| 799 | * not have bank info, so create a custom tiling dword. |
| 800 | * bits 3:0 num_pipes |
| 801 | * bits 7:4 num_banks |
| 802 | * bits 11:8 group_size |
| 803 | * bits 15:12 row_size |
| 804 | */ |
| 805 | rdev->config.cayman.tile_config = 0; |
| 806 | switch (rdev->config.cayman.num_tile_pipes) { |
| 807 | case 1: |
| 808 | default: |
| 809 | rdev->config.cayman.tile_config |= (0 << 0); |
| 810 | break; |
| 811 | case 2: |
| 812 | rdev->config.cayman.tile_config |= (1 << 0); |
| 813 | break; |
| 814 | case 4: |
| 815 | rdev->config.cayman.tile_config |= (2 << 0); |
| 816 | break; |
| 817 | case 8: |
| 818 | rdev->config.cayman.tile_config |= (3 << 0); |
| 819 | break; |
| 820 | } |
| 821 | rdev->config.cayman.tile_config |= |
| 822 | ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4; |
| 823 | rdev->config.cayman.tile_config |= |
| 824 | (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT; |
| 825 | rdev->config.cayman.tile_config |= |
| 826 | ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12; |
| 827 | |
| 828 | WREG32(GB_BACKEND_MAP, gb_backend_map); |
| 829 | WREG32(GB_ADDR_CONFIG, gb_addr_config); |
| 830 | WREG32(DMIF_ADDR_CONFIG, gb_addr_config); |
| 831 | WREG32(HDP_ADDR_CONFIG, gb_addr_config); |
| 832 | |
| 833 | cayman_program_channel_remap(rdev); |
| 834 | |
| 835 | /* primary versions */ |
| 836 | WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 837 | WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 838 | WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config); |
| 839 | |
| 840 | WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable); |
| 841 | WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable); |
| 842 | |
| 843 | /* user versions */ |
| 844 | WREG32(GC_USER_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 845 | WREG32(GC_USER_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 846 | WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config); |
| 847 | |
| 848 | WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable); |
| 849 | WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable); |
| 850 | |
| 851 | /* reprogram the shader complex */ |
| 852 | cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG); |
| 853 | for (i = 0; i < 16; i++) |
| 854 | WREG32(CGTS_SM_CTRL_REG, OVERRIDE); |
| 855 | WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg); |
| 856 | |
| 857 | /* set HW defaults for 3D engine */ |
| 858 | WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60)); |
| 859 | |
| 860 | sx_debug_1 = RREG32(SX_DEBUG_1); |
| 861 | sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS; |
| 862 | WREG32(SX_DEBUG_1, sx_debug_1); |
| 863 | |
| 864 | smx_dc_ctl0 = RREG32(SMX_DC_CTL0); |
| 865 | smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff); |
| 866 | smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets); |
| 867 | WREG32(SMX_DC_CTL0, smx_dc_ctl0); |
| 868 | |
| 869 | WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE); |
| 870 | |
| 871 | /* need to be explicitly zero-ed */ |
| 872 | WREG32(VGT_OFFCHIP_LDS_BASE, 0); |
| 873 | WREG32(SQ_LSTMP_RING_BASE, 0); |
| 874 | WREG32(SQ_HSTMP_RING_BASE, 0); |
| 875 | WREG32(SQ_ESTMP_RING_BASE, 0); |
| 876 | WREG32(SQ_GSTMP_RING_BASE, 0); |
| 877 | WREG32(SQ_VSTMP_RING_BASE, 0); |
| 878 | WREG32(SQ_PSTMP_RING_BASE, 0); |
| 879 | |
| 880 | WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO); |
| 881 | |
| 882 | WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) | |
| 883 | POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) | |
| 884 | SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1))); |
| 885 | |
| 886 | WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) | |
| 887 | SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) | |
| 888 | SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size))); |
| 889 | |
| 890 | |
| 891 | WREG32(VGT_NUM_INSTANCES, 1); |
| 892 | |
| 893 | WREG32(CP_PERFMON_CNTL, 0); |
| 894 | |
| 895 | WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) | |
| 896 | FETCH_FIFO_HIWATER(0x4) | |
| 897 | DONE_FIFO_HIWATER(0xe0) | |
| 898 | ALU_UPDATE_FIFO_HIWATER(0x8))); |
| 899 | |
| 900 | WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4)); |
| 901 | WREG32(SQ_CONFIG, (VC_ENABLE | |
| 902 | EXPORT_SRC_C | |
| 903 | GFX_PRIO(0) | |
| 904 | CS1_PRIO(0) | |
| 905 | CS2_PRIO(1))); |
| 906 | WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE); |
| 907 | |
| 908 | WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) | |
| 909 | FORCE_EOV_MAX_REZ_CNT(255))); |
| 910 | |
| 911 | WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) | |
| 912 | AUTO_INVLD_EN(ES_AND_GS_AUTO)); |
| 913 | |
| 914 | WREG32(VGT_GS_VERTEX_REUSE, 16); |
| 915 | WREG32(PA_SC_LINE_STIPPLE_STATE, 0); |
| 916 | |
| 917 | WREG32(CB_PERF_CTR0_SEL_0, 0); |
| 918 | WREG32(CB_PERF_CTR0_SEL_1, 0); |
| 919 | WREG32(CB_PERF_CTR1_SEL_0, 0); |
| 920 | WREG32(CB_PERF_CTR1_SEL_1, 0); |
| 921 | WREG32(CB_PERF_CTR2_SEL_0, 0); |
| 922 | WREG32(CB_PERF_CTR2_SEL_1, 0); |
| 923 | WREG32(CB_PERF_CTR3_SEL_0, 0); |
| 924 | WREG32(CB_PERF_CTR3_SEL_1, 0); |
| 925 | |
| 926 | hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL); |
| 927 | WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl); |
| 928 | |
| 929 | WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3)); |
| 930 | |
| 931 | udelay(50); |
| 932 | } |
| 933 | |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame^] | 934 | /* |
| 935 | * GART |
| 936 | */ |
| 937 | void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev) |
| 938 | { |
| 939 | /* flush hdp cache */ |
| 940 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 941 | |
| 942 | /* bits 0-7 are the VM contexts0-7 */ |
| 943 | WREG32(VM_INVALIDATE_REQUEST, 1); |
| 944 | } |
| 945 | |
| 946 | int cayman_pcie_gart_enable(struct radeon_device *rdev) |
| 947 | { |
| 948 | int r; |
| 949 | |
| 950 | if (rdev->gart.table.vram.robj == NULL) { |
| 951 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 952 | return -EINVAL; |
| 953 | } |
| 954 | r = radeon_gart_table_vram_pin(rdev); |
| 955 | if (r) |
| 956 | return r; |
| 957 | radeon_gart_restore(rdev); |
| 958 | /* Setup TLB control */ |
| 959 | WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB | |
| 960 | ENABLE_L1_FRAGMENT_PROCESSING | |
| 961 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 962 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU); |
| 963 | /* Setup L2 cache */ |
| 964 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | |
| 965 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 966 | ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE | |
| 967 | EFFECTIVE_L2_QUEUE_SIZE(7) | |
| 968 | CONTEXT1_IDENTITY_ACCESS_MODE(1)); |
| 969 | WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE); |
| 970 | WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY | |
| 971 | L2_CACHE_BIGK_FRAGMENT_SIZE(6)); |
| 972 | /* setup context0 */ |
| 973 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); |
| 974 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); |
| 975 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); |
| 976 | WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, |
| 977 | (u32)(rdev->dummy_page.addr >> 12)); |
| 978 | WREG32(VM_CONTEXT0_CNTL2, 0); |
| 979 | WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 980 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
| 981 | /* disable context1-7 */ |
| 982 | WREG32(VM_CONTEXT1_CNTL2, 0); |
| 983 | WREG32(VM_CONTEXT1_CNTL, 0); |
| 984 | |
| 985 | cayman_pcie_gart_tlb_flush(rdev); |
| 986 | rdev->gart.ready = true; |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | void cayman_pcie_gart_disable(struct radeon_device *rdev) |
| 991 | { |
| 992 | int r; |
| 993 | |
| 994 | /* Disable all tables */ |
| 995 | WREG32(VM_CONTEXT0_CNTL, 0); |
| 996 | WREG32(VM_CONTEXT1_CNTL, 0); |
| 997 | /* Setup TLB control */ |
| 998 | WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING | |
| 999 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 1000 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU); |
| 1001 | /* Setup L2 cache */ |
| 1002 | WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1003 | ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE | |
| 1004 | EFFECTIVE_L2_QUEUE_SIZE(7) | |
| 1005 | CONTEXT1_IDENTITY_ACCESS_MODE(1)); |
| 1006 | WREG32(VM_L2_CNTL2, 0); |
| 1007 | WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY | |
| 1008 | L2_CACHE_BIGK_FRAGMENT_SIZE(6)); |
| 1009 | if (rdev->gart.table.vram.robj) { |
| 1010 | r = radeon_bo_reserve(rdev->gart.table.vram.robj, false); |
| 1011 | if (likely(r == 0)) { |
| 1012 | radeon_bo_kunmap(rdev->gart.table.vram.robj); |
| 1013 | radeon_bo_unpin(rdev->gart.table.vram.robj); |
| 1014 | radeon_bo_unreserve(rdev->gart.table.vram.robj); |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | void cayman_pcie_gart_fini(struct radeon_device *rdev) |
| 1020 | { |
| 1021 | cayman_pcie_gart_disable(rdev); |
| 1022 | radeon_gart_table_vram_free(rdev); |
| 1023 | radeon_gart_fini(rdev); |
| 1024 | } |
| 1025 | |