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> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 28 | #include "drmP.h" |
| 29 | #include "radeon.h" |
| 30 | #include "radeon_asic.h" |
| 31 | #include "radeon_drm.h" |
| 32 | #include "nid.h" |
| 33 | #include "atom.h" |
| 34 | #include "ni_reg.h" |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 35 | #include "cayman_blit_shaders.h" |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 36 | |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 37 | extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save); |
| 38 | extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save); |
| 39 | extern int evergreen_mc_wait_for_idle(struct radeon_device *rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 40 | extern void evergreen_mc_program(struct radeon_device *rdev); |
| 41 | extern void evergreen_irq_suspend(struct radeon_device *rdev); |
| 42 | extern int evergreen_mc_init(struct radeon_device *rdev); |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 43 | extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev); |
Ilija Hadzic | b07759b | 2011-09-20 10:22:58 -0400 | [diff] [blame] | 44 | extern void evergreen_pcie_gen2_enable(struct radeon_device *rdev); |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 45 | extern void si_rlc_fini(struct radeon_device *rdev); |
| 46 | extern int si_rlc_init(struct radeon_device *rdev); |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 47 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 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 |
| 52 | |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 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 |
| 57 | |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 58 | #define ARUBA_RLC_UCODE_SIZE 1536 |
| 59 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 60 | /* Firmware Names */ |
| 61 | MODULE_FIRMWARE("radeon/BARTS_pfp.bin"); |
| 62 | MODULE_FIRMWARE("radeon/BARTS_me.bin"); |
| 63 | MODULE_FIRMWARE("radeon/BARTS_mc.bin"); |
| 64 | MODULE_FIRMWARE("radeon/BTC_rlc.bin"); |
| 65 | MODULE_FIRMWARE("radeon/TURKS_pfp.bin"); |
| 66 | MODULE_FIRMWARE("radeon/TURKS_me.bin"); |
| 67 | MODULE_FIRMWARE("radeon/TURKS_mc.bin"); |
| 68 | MODULE_FIRMWARE("radeon/CAICOS_pfp.bin"); |
| 69 | MODULE_FIRMWARE("radeon/CAICOS_me.bin"); |
| 70 | MODULE_FIRMWARE("radeon/CAICOS_mc.bin"); |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 71 | MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin"); |
| 72 | MODULE_FIRMWARE("radeon/CAYMAN_me.bin"); |
| 73 | MODULE_FIRMWARE("radeon/CAYMAN_mc.bin"); |
| 74 | MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin"); |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 75 | MODULE_FIRMWARE("radeon/ARUBA_pfp.bin"); |
| 76 | MODULE_FIRMWARE("radeon/ARUBA_me.bin"); |
| 77 | MODULE_FIRMWARE("radeon/ARUBA_rlc.bin"); |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 78 | |
| 79 | #define BTC_IO_MC_REGS_SIZE 29 |
| 80 | |
| 81 | static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 82 | {0x00000077, 0xff010100}, |
| 83 | {0x00000078, 0x00000000}, |
| 84 | {0x00000079, 0x00001434}, |
| 85 | {0x0000007a, 0xcc08ec08}, |
| 86 | {0x0000007b, 0x00040000}, |
| 87 | {0x0000007c, 0x000080c0}, |
| 88 | {0x0000007d, 0x09000000}, |
| 89 | {0x0000007e, 0x00210404}, |
| 90 | {0x00000081, 0x08a8e800}, |
| 91 | {0x00000082, 0x00030444}, |
| 92 | {0x00000083, 0x00000000}, |
| 93 | {0x00000085, 0x00000001}, |
| 94 | {0x00000086, 0x00000002}, |
| 95 | {0x00000087, 0x48490000}, |
| 96 | {0x00000088, 0x20244647}, |
| 97 | {0x00000089, 0x00000005}, |
| 98 | {0x0000008b, 0x66030000}, |
| 99 | {0x0000008c, 0x00006603}, |
| 100 | {0x0000008d, 0x00000100}, |
| 101 | {0x0000008f, 0x00001c0a}, |
| 102 | {0x00000090, 0xff000001}, |
| 103 | {0x00000094, 0x00101101}, |
| 104 | {0x00000095, 0x00000fff}, |
| 105 | {0x00000096, 0x00116fff}, |
| 106 | {0x00000097, 0x60010000}, |
| 107 | {0x00000098, 0x10010000}, |
| 108 | {0x00000099, 0x00006000}, |
| 109 | {0x0000009a, 0x00001000}, |
| 110 | {0x0000009f, 0x00946a00} |
| 111 | }; |
| 112 | |
| 113 | static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 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} |
| 143 | }; |
| 144 | |
| 145 | static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 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} |
| 175 | }; |
| 176 | |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 177 | static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = { |
| 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} |
| 207 | }; |
| 208 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 209 | int ni_mc_load_microcode(struct radeon_device *rdev) |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 210 | { |
| 211 | const __be32 *fw_data; |
| 212 | u32 mem_type, running, blackout = 0; |
| 213 | u32 *io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 214 | int i, ucode_size, regs_size; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 215 | |
| 216 | if (!rdev->mc_fw) |
| 217 | return -EINVAL; |
| 218 | |
| 219 | switch (rdev->family) { |
| 220 | case CHIP_BARTS: |
| 221 | io_mc_regs = (u32 *)&barts_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 222 | ucode_size = BTC_MC_UCODE_SIZE; |
| 223 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 224 | break; |
| 225 | case CHIP_TURKS: |
| 226 | io_mc_regs = (u32 *)&turks_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 227 | ucode_size = BTC_MC_UCODE_SIZE; |
| 228 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 229 | break; |
| 230 | case CHIP_CAICOS: |
| 231 | default: |
| 232 | io_mc_regs = (u32 *)&caicos_io_mc_regs; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 233 | ucode_size = BTC_MC_UCODE_SIZE; |
| 234 | regs_size = BTC_IO_MC_REGS_SIZE; |
| 235 | break; |
| 236 | case CHIP_CAYMAN: |
| 237 | io_mc_regs = (u32 *)&cayman_io_mc_regs; |
| 238 | ucode_size = CAYMAN_MC_UCODE_SIZE; |
| 239 | regs_size = BTC_IO_MC_REGS_SIZE; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 240 | break; |
| 241 | } |
| 242 | |
| 243 | mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT; |
| 244 | running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK; |
| 245 | |
| 246 | if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) { |
| 247 | if (running) { |
| 248 | blackout = RREG32(MC_SHARED_BLACKOUT_CNTL); |
| 249 | WREG32(MC_SHARED_BLACKOUT_CNTL, 1); |
| 250 | } |
| 251 | |
| 252 | /* reset the engine and set to writable */ |
| 253 | WREG32(MC_SEQ_SUP_CNTL, 0x00000008); |
| 254 | WREG32(MC_SEQ_SUP_CNTL, 0x00000010); |
| 255 | |
| 256 | /* load mc io regs */ |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 257 | for (i = 0; i < regs_size; i++) { |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 258 | WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]); |
| 259 | WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]); |
| 260 | } |
| 261 | /* load the MC ucode */ |
| 262 | fw_data = (const __be32 *)rdev->mc_fw->data; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 263 | for (i = 0; i < ucode_size; i++) |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 264 | WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++)); |
| 265 | |
| 266 | /* put the engine back into the active state */ |
| 267 | WREG32(MC_SEQ_SUP_CNTL, 0x00000008); |
| 268 | WREG32(MC_SEQ_SUP_CNTL, 0x00000004); |
| 269 | WREG32(MC_SEQ_SUP_CNTL, 0x00000001); |
| 270 | |
| 271 | /* wait for training to complete */ |
Alex Deucher | 0e2c978 | 2011-11-02 18:08:25 -0400 | [diff] [blame] | 272 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 273 | if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD) |
| 274 | break; |
| 275 | udelay(1); |
| 276 | } |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 277 | |
| 278 | if (running) |
| 279 | WREG32(MC_SHARED_BLACKOUT_CNTL, blackout); |
| 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | int ni_init_microcode(struct radeon_device *rdev) |
| 286 | { |
| 287 | struct platform_device *pdev; |
| 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; |
| 291 | char fw_name[30]; |
| 292 | int err; |
| 293 | |
| 294 | DRM_DEBUG("\n"); |
| 295 | |
| 296 | pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); |
| 297 | err = IS_ERR(pdev); |
| 298 | if (err) { |
| 299 | printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
| 303 | switch (rdev->family) { |
| 304 | case CHIP_BARTS: |
| 305 | chip_name = "BARTS"; |
| 306 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 307 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 308 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 309 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 310 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 311 | break; |
| 312 | case CHIP_TURKS: |
| 313 | chip_name = "TURKS"; |
| 314 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 315 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 316 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 317 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 318 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 319 | break; |
| 320 | case CHIP_CAICOS: |
| 321 | chip_name = "CAICOS"; |
| 322 | rlc_chip_name = "BTC"; |
Alex Deucher | 9b8253c | 2011-03-02 20:07:28 -0500 | [diff] [blame] | 323 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 324 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
| 325 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
| 326 | mc_req_size = BTC_MC_UCODE_SIZE * 4; |
| 327 | break; |
| 328 | case CHIP_CAYMAN: |
| 329 | chip_name = "CAYMAN"; |
| 330 | rlc_chip_name = "CAYMAN"; |
| 331 | pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4; |
| 332 | me_req_size = CAYMAN_PM4_UCODE_SIZE * 4; |
| 333 | rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4; |
| 334 | mc_req_size = CAYMAN_MC_UCODE_SIZE * 4; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 335 | break; |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 336 | case CHIP_ARUBA: |
| 337 | chip_name = "ARUBA"; |
| 338 | rlc_chip_name = "ARUBA"; |
| 339 | /* pfp/me same size as CAYMAN */ |
| 340 | pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4; |
| 341 | me_req_size = CAYMAN_PM4_UCODE_SIZE * 4; |
| 342 | rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4; |
| 343 | mc_req_size = 0; |
| 344 | break; |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 345 | default: BUG(); |
| 346 | } |
| 347 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 348 | DRM_INFO("Loading %s Microcode\n", chip_name); |
| 349 | |
| 350 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name); |
| 351 | err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev); |
| 352 | if (err) |
| 353 | goto out; |
| 354 | if (rdev->pfp_fw->size != pfp_req_size) { |
| 355 | printk(KERN_ERR |
| 356 | "ni_cp: Bogus length %zu in firmware \"%s\"\n", |
| 357 | rdev->pfp_fw->size, fw_name); |
| 358 | err = -EINVAL; |
| 359 | goto out; |
| 360 | } |
| 361 | |
| 362 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name); |
| 363 | err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); |
| 364 | if (err) |
| 365 | goto out; |
| 366 | if (rdev->me_fw->size != me_req_size) { |
| 367 | printk(KERN_ERR |
| 368 | "ni_cp: Bogus length %zu in firmware \"%s\"\n", |
| 369 | rdev->me_fw->size, fw_name); |
| 370 | err = -EINVAL; |
| 371 | } |
| 372 | |
| 373 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name); |
| 374 | err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev); |
| 375 | if (err) |
| 376 | goto out; |
| 377 | if (rdev->rlc_fw->size != rlc_req_size) { |
| 378 | printk(KERN_ERR |
| 379 | "ni_rlc: Bogus length %zu in firmware \"%s\"\n", |
| 380 | rdev->rlc_fw->size, fw_name); |
| 381 | err = -EINVAL; |
| 382 | } |
| 383 | |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 384 | /* no MC ucode on TN */ |
| 385 | if (!(rdev->flags & RADEON_IS_IGP)) { |
| 386 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name); |
| 387 | err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev); |
| 388 | if (err) |
| 389 | goto out; |
| 390 | if (rdev->mc_fw->size != mc_req_size) { |
| 391 | printk(KERN_ERR |
| 392 | "ni_mc: Bogus length %zu in firmware \"%s\"\n", |
| 393 | rdev->mc_fw->size, fw_name); |
| 394 | err = -EINVAL; |
| 395 | } |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 396 | } |
| 397 | out: |
| 398 | platform_device_unregister(pdev); |
| 399 | |
| 400 | if (err) { |
| 401 | if (err != -EINVAL) |
| 402 | printk(KERN_ERR |
| 403 | "ni_cp: Failed to load firmware \"%s\"\n", |
| 404 | fw_name); |
| 405 | release_firmware(rdev->pfp_fw); |
| 406 | rdev->pfp_fw = NULL; |
| 407 | release_firmware(rdev->me_fw); |
| 408 | rdev->me_fw = NULL; |
| 409 | release_firmware(rdev->rlc_fw); |
| 410 | rdev->rlc_fw = NULL; |
| 411 | release_firmware(rdev->mc_fw); |
| 412 | rdev->mc_fw = NULL; |
| 413 | } |
| 414 | return err; |
| 415 | } |
| 416 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 417 | /* |
| 418 | * Core functions |
| 419 | */ |
| 420 | static u32 cayman_get_tile_pipe_to_backend_map(struct radeon_device *rdev, |
| 421 | u32 num_tile_pipes, |
| 422 | u32 num_backends_per_asic, |
| 423 | u32 *backend_disable_mask_per_asic, |
| 424 | u32 num_shader_engines) |
| 425 | { |
| 426 | u32 backend_map = 0; |
| 427 | u32 enabled_backends_mask = 0; |
| 428 | u32 enabled_backends_count = 0; |
| 429 | u32 num_backends_per_se; |
| 430 | u32 cur_pipe; |
| 431 | u32 swizzle_pipe[CAYMAN_MAX_PIPES]; |
| 432 | u32 cur_backend = 0; |
| 433 | u32 i; |
| 434 | bool force_no_swizzle; |
| 435 | |
| 436 | /* force legal values */ |
| 437 | if (num_tile_pipes < 1) |
| 438 | num_tile_pipes = 1; |
| 439 | if (num_tile_pipes > rdev->config.cayman.max_tile_pipes) |
| 440 | num_tile_pipes = rdev->config.cayman.max_tile_pipes; |
| 441 | if (num_shader_engines < 1) |
| 442 | num_shader_engines = 1; |
| 443 | if (num_shader_engines > rdev->config.cayman.max_shader_engines) |
| 444 | num_shader_engines = rdev->config.cayman.max_shader_engines; |
Dave Airlie | c289cff | 2011-05-19 14:14:40 +1000 | [diff] [blame] | 445 | if (num_backends_per_asic < num_shader_engines) |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 446 | num_backends_per_asic = num_shader_engines; |
| 447 | if (num_backends_per_asic > (rdev->config.cayman.max_backends_per_se * num_shader_engines)) |
| 448 | num_backends_per_asic = rdev->config.cayman.max_backends_per_se * num_shader_engines; |
| 449 | |
| 450 | /* make sure we have the same number of backends per se */ |
| 451 | num_backends_per_asic = ALIGN(num_backends_per_asic, num_shader_engines); |
| 452 | /* set up the number of backends per se */ |
| 453 | num_backends_per_se = num_backends_per_asic / num_shader_engines; |
| 454 | if (num_backends_per_se > rdev->config.cayman.max_backends_per_se) { |
| 455 | num_backends_per_se = rdev->config.cayman.max_backends_per_se; |
| 456 | num_backends_per_asic = num_backends_per_se * num_shader_engines; |
| 457 | } |
| 458 | |
| 459 | /* create enable mask and count for enabled backends */ |
| 460 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 461 | if (((*backend_disable_mask_per_asic >> i) & 1) == 0) { |
| 462 | enabled_backends_mask |= (1 << i); |
| 463 | ++enabled_backends_count; |
| 464 | } |
| 465 | if (enabled_backends_count == num_backends_per_asic) |
| 466 | break; |
| 467 | } |
| 468 | |
| 469 | /* force the backends mask to match the current number of backends */ |
| 470 | if (enabled_backends_count != num_backends_per_asic) { |
| 471 | u32 this_backend_enabled; |
| 472 | u32 shader_engine; |
| 473 | u32 backend_per_se; |
| 474 | |
| 475 | enabled_backends_mask = 0; |
| 476 | enabled_backends_count = 0; |
| 477 | *backend_disable_mask_per_asic = CAYMAN_MAX_BACKENDS_MASK; |
| 478 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 479 | /* calc the current se */ |
| 480 | shader_engine = i / rdev->config.cayman.max_backends_per_se; |
| 481 | /* calc the backend per se */ |
| 482 | backend_per_se = i % rdev->config.cayman.max_backends_per_se; |
| 483 | /* default to not enabled */ |
| 484 | this_backend_enabled = 0; |
| 485 | if ((shader_engine < num_shader_engines) && |
| 486 | (backend_per_se < num_backends_per_se)) |
| 487 | this_backend_enabled = 1; |
| 488 | if (this_backend_enabled) { |
| 489 | enabled_backends_mask |= (1 << i); |
| 490 | *backend_disable_mask_per_asic &= ~(1 << i); |
| 491 | ++enabled_backends_count; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | |
| 497 | memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * CAYMAN_MAX_PIPES); |
| 498 | switch (rdev->family) { |
| 499 | case CHIP_CAYMAN: |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 500 | case CHIP_ARUBA: |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 501 | force_no_swizzle = true; |
| 502 | break; |
| 503 | default: |
| 504 | force_no_swizzle = false; |
| 505 | break; |
| 506 | } |
| 507 | if (force_no_swizzle) { |
| 508 | bool last_backend_enabled = false; |
| 509 | |
| 510 | force_no_swizzle = false; |
| 511 | for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) { |
| 512 | if (((enabled_backends_mask >> i) & 1) == 1) { |
| 513 | if (last_backend_enabled) |
| 514 | force_no_swizzle = true; |
| 515 | last_backend_enabled = true; |
| 516 | } else |
| 517 | last_backend_enabled = false; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | switch (num_tile_pipes) { |
| 522 | case 1: |
| 523 | case 3: |
| 524 | case 5: |
| 525 | case 7: |
| 526 | DRM_ERROR("odd number of pipes!\n"); |
| 527 | break; |
| 528 | case 2: |
| 529 | swizzle_pipe[0] = 0; |
| 530 | swizzle_pipe[1] = 1; |
| 531 | break; |
| 532 | case 4: |
| 533 | if (force_no_swizzle) { |
| 534 | swizzle_pipe[0] = 0; |
| 535 | swizzle_pipe[1] = 1; |
| 536 | swizzle_pipe[2] = 2; |
| 537 | swizzle_pipe[3] = 3; |
| 538 | } else { |
| 539 | swizzle_pipe[0] = 0; |
| 540 | swizzle_pipe[1] = 2; |
| 541 | swizzle_pipe[2] = 1; |
| 542 | swizzle_pipe[3] = 3; |
| 543 | } |
| 544 | break; |
| 545 | case 6: |
| 546 | if (force_no_swizzle) { |
| 547 | swizzle_pipe[0] = 0; |
| 548 | swizzle_pipe[1] = 1; |
| 549 | swizzle_pipe[2] = 2; |
| 550 | swizzle_pipe[3] = 3; |
| 551 | swizzle_pipe[4] = 4; |
| 552 | swizzle_pipe[5] = 5; |
| 553 | } else { |
| 554 | swizzle_pipe[0] = 0; |
| 555 | swizzle_pipe[1] = 2; |
| 556 | swizzle_pipe[2] = 4; |
| 557 | swizzle_pipe[3] = 1; |
| 558 | swizzle_pipe[4] = 3; |
| 559 | swizzle_pipe[5] = 5; |
| 560 | } |
| 561 | break; |
| 562 | case 8: |
| 563 | if (force_no_swizzle) { |
| 564 | swizzle_pipe[0] = 0; |
| 565 | swizzle_pipe[1] = 1; |
| 566 | swizzle_pipe[2] = 2; |
| 567 | swizzle_pipe[3] = 3; |
| 568 | swizzle_pipe[4] = 4; |
| 569 | swizzle_pipe[5] = 5; |
| 570 | swizzle_pipe[6] = 6; |
| 571 | swizzle_pipe[7] = 7; |
| 572 | } else { |
| 573 | swizzle_pipe[0] = 0; |
| 574 | swizzle_pipe[1] = 2; |
| 575 | swizzle_pipe[2] = 4; |
| 576 | swizzle_pipe[3] = 6; |
| 577 | swizzle_pipe[4] = 1; |
| 578 | swizzle_pipe[5] = 3; |
| 579 | swizzle_pipe[6] = 5; |
| 580 | swizzle_pipe[7] = 7; |
| 581 | } |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) { |
| 586 | while (((1 << cur_backend) & enabled_backends_mask) == 0) |
| 587 | cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS; |
| 588 | |
| 589 | backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4))); |
| 590 | |
| 591 | cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS; |
| 592 | } |
| 593 | |
| 594 | return backend_map; |
| 595 | } |
| 596 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 597 | static u32 cayman_get_disable_mask_per_asic(struct radeon_device *rdev, |
| 598 | u32 disable_mask_per_se, |
| 599 | u32 max_disable_mask_per_se, |
| 600 | u32 num_shader_engines) |
| 601 | { |
| 602 | u32 disable_field_width_per_se = r600_count_pipe_bits(disable_mask_per_se); |
| 603 | u32 disable_mask_per_asic = disable_mask_per_se & max_disable_mask_per_se; |
| 604 | |
| 605 | if (num_shader_engines == 1) |
| 606 | return disable_mask_per_asic; |
| 607 | else if (num_shader_engines == 2) |
| 608 | return disable_mask_per_asic | (disable_mask_per_asic << disable_field_width_per_se); |
| 609 | else |
| 610 | return 0xffffffff; |
| 611 | } |
| 612 | |
| 613 | static void cayman_gpu_init(struct radeon_device *rdev) |
| 614 | { |
| 615 | u32 cc_rb_backend_disable = 0; |
| 616 | u32 cc_gc_shader_pipe_config; |
| 617 | u32 gb_addr_config = 0; |
| 618 | u32 mc_shared_chmap, mc_arb_ramcfg; |
| 619 | u32 gb_backend_map; |
| 620 | u32 cgts_tcc_disable; |
| 621 | u32 sx_debug_1; |
| 622 | u32 smx_dc_ctl0; |
| 623 | u32 gc_user_shader_pipe_config; |
| 624 | u32 gc_user_rb_backend_disable; |
| 625 | u32 cgts_user_tcc_disable; |
| 626 | u32 cgts_sm_ctrl_reg; |
| 627 | u32 hdp_host_path_cntl; |
| 628 | u32 tmp; |
| 629 | int i, j; |
| 630 | |
| 631 | switch (rdev->family) { |
| 632 | case CHIP_CAYMAN: |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 633 | rdev->config.cayman.max_shader_engines = 2; |
| 634 | rdev->config.cayman.max_pipes_per_simd = 4; |
| 635 | rdev->config.cayman.max_tile_pipes = 8; |
| 636 | rdev->config.cayman.max_simds_per_se = 12; |
| 637 | rdev->config.cayman.max_backends_per_se = 4; |
| 638 | rdev->config.cayman.max_texture_channel_caches = 8; |
| 639 | rdev->config.cayman.max_gprs = 256; |
| 640 | rdev->config.cayman.max_threads = 256; |
| 641 | rdev->config.cayman.max_gs_threads = 32; |
| 642 | rdev->config.cayman.max_stack_entries = 512; |
| 643 | rdev->config.cayman.sx_num_of_sets = 8; |
| 644 | rdev->config.cayman.sx_max_export_size = 256; |
| 645 | rdev->config.cayman.sx_max_export_pos_size = 64; |
| 646 | rdev->config.cayman.sx_max_export_smx_size = 192; |
| 647 | rdev->config.cayman.max_hw_contexts = 8; |
| 648 | rdev->config.cayman.sq_num_cf_insts = 2; |
| 649 | |
| 650 | rdev->config.cayman.sc_prim_fifo_size = 0x100; |
| 651 | rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30; |
| 652 | rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130; |
| 653 | break; |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 654 | case CHIP_ARUBA: |
| 655 | default: |
| 656 | rdev->config.cayman.max_shader_engines = 1; |
| 657 | rdev->config.cayman.max_pipes_per_simd = 4; |
| 658 | rdev->config.cayman.max_tile_pipes = 2; |
| 659 | if ((rdev->pdev->device == 0x9900) || |
Alex Deucher | d16ba20 | 2012-06-05 09:50:28 -0400 | [diff] [blame] | 660 | (rdev->pdev->device == 0x9901) || |
| 661 | (rdev->pdev->device == 0x9905) || |
| 662 | (rdev->pdev->device == 0x9906) || |
| 663 | (rdev->pdev->device == 0x9907) || |
| 664 | (rdev->pdev->device == 0x9908) || |
| 665 | (rdev->pdev->device == 0x9909) || |
| 666 | (rdev->pdev->device == 0x9910) || |
| 667 | (rdev->pdev->device == 0x9917)) { |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 668 | rdev->config.cayman.max_simds_per_se = 6; |
| 669 | rdev->config.cayman.max_backends_per_se = 2; |
| 670 | } else if ((rdev->pdev->device == 0x9903) || |
Alex Deucher | d16ba20 | 2012-06-05 09:50:28 -0400 | [diff] [blame] | 671 | (rdev->pdev->device == 0x9904) || |
| 672 | (rdev->pdev->device == 0x990A) || |
| 673 | (rdev->pdev->device == 0x9913) || |
| 674 | (rdev->pdev->device == 0x9918)) { |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 675 | rdev->config.cayman.max_simds_per_se = 4; |
| 676 | rdev->config.cayman.max_backends_per_se = 2; |
Alex Deucher | d16ba20 | 2012-06-05 09:50:28 -0400 | [diff] [blame] | 677 | } else if ((rdev->pdev->device == 0x9919) || |
| 678 | (rdev->pdev->device == 0x9990) || |
| 679 | (rdev->pdev->device == 0x9991) || |
| 680 | (rdev->pdev->device == 0x9994) || |
| 681 | (rdev->pdev->device == 0x99A0)) { |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 682 | rdev->config.cayman.max_simds_per_se = 3; |
| 683 | rdev->config.cayman.max_backends_per_se = 1; |
| 684 | } else { |
| 685 | rdev->config.cayman.max_simds_per_se = 2; |
| 686 | rdev->config.cayman.max_backends_per_se = 1; |
| 687 | } |
| 688 | rdev->config.cayman.max_texture_channel_caches = 2; |
| 689 | rdev->config.cayman.max_gprs = 256; |
| 690 | rdev->config.cayman.max_threads = 256; |
| 691 | rdev->config.cayman.max_gs_threads = 32; |
| 692 | rdev->config.cayman.max_stack_entries = 512; |
| 693 | rdev->config.cayman.sx_num_of_sets = 8; |
| 694 | rdev->config.cayman.sx_max_export_size = 256; |
| 695 | rdev->config.cayman.sx_max_export_pos_size = 64; |
| 696 | rdev->config.cayman.sx_max_export_smx_size = 192; |
| 697 | rdev->config.cayman.max_hw_contexts = 8; |
| 698 | rdev->config.cayman.sq_num_cf_insts = 2; |
| 699 | |
| 700 | rdev->config.cayman.sc_prim_fifo_size = 0x40; |
| 701 | rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30; |
| 702 | rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130; |
| 703 | break; |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /* Initialize HDP */ |
| 707 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 708 | WREG32((0x2c14 + j), 0x00000000); |
| 709 | WREG32((0x2c18 + j), 0x00000000); |
| 710 | WREG32((0x2c1c + j), 0x00000000); |
| 711 | WREG32((0x2c20 + j), 0x00000000); |
| 712 | WREG32((0x2c24 + j), 0x00000000); |
| 713 | } |
| 714 | |
| 715 | WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff)); |
| 716 | |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 717 | evergreen_fix_pci_max_read_req_size(rdev); |
| 718 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 719 | mc_shared_chmap = RREG32(MC_SHARED_CHMAP); |
| 720 | mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); |
| 721 | |
| 722 | cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE); |
| 723 | cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG); |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 724 | cgts_tcc_disable = 0xffff0000; |
| 725 | for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++) |
| 726 | cgts_tcc_disable &= ~(1 << (16 + i)); |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 727 | gc_user_rb_backend_disable = RREG32(GC_USER_RB_BACKEND_DISABLE); |
| 728 | gc_user_shader_pipe_config = RREG32(GC_USER_SHADER_PIPE_CONFIG); |
| 729 | cgts_user_tcc_disable = RREG32(CGTS_USER_TCC_DISABLE); |
| 730 | |
| 731 | rdev->config.cayman.num_shader_engines = rdev->config.cayman.max_shader_engines; |
| 732 | tmp = ((~gc_user_shader_pipe_config) & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT; |
| 733 | rdev->config.cayman.num_shader_pipes_per_simd = r600_count_pipe_bits(tmp); |
| 734 | rdev->config.cayman.num_tile_pipes = rdev->config.cayman.max_tile_pipes; |
| 735 | tmp = ((~gc_user_shader_pipe_config) & INACTIVE_SIMDS_MASK) >> INACTIVE_SIMDS_SHIFT; |
| 736 | rdev->config.cayman.num_simds_per_se = r600_count_pipe_bits(tmp); |
| 737 | tmp = ((~gc_user_rb_backend_disable) & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT; |
| 738 | rdev->config.cayman.num_backends_per_se = r600_count_pipe_bits(tmp); |
| 739 | tmp = (gc_user_rb_backend_disable & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT; |
| 740 | rdev->config.cayman.backend_disable_mask_per_asic = |
| 741 | cayman_get_disable_mask_per_asic(rdev, tmp, CAYMAN_MAX_BACKENDS_PER_SE_MASK, |
| 742 | rdev->config.cayman.num_shader_engines); |
| 743 | rdev->config.cayman.backend_map = |
| 744 | cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes, |
| 745 | rdev->config.cayman.num_backends_per_se * |
| 746 | rdev->config.cayman.num_shader_engines, |
| 747 | &rdev->config.cayman.backend_disable_mask_per_asic, |
| 748 | rdev->config.cayman.num_shader_engines); |
| 749 | tmp = ((~cgts_user_tcc_disable) & TCC_DISABLE_MASK) >> TCC_DISABLE_SHIFT; |
| 750 | rdev->config.cayman.num_texture_channel_caches = r600_count_pipe_bits(tmp); |
| 751 | tmp = (mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT; |
| 752 | rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256; |
| 753 | if (rdev->config.cayman.mem_max_burst_length_bytes > 512) |
| 754 | rdev->config.cayman.mem_max_burst_length_bytes = 512; |
| 755 | tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT; |
| 756 | rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024; |
| 757 | if (rdev->config.cayman.mem_row_size_in_kb > 4) |
| 758 | rdev->config.cayman.mem_row_size_in_kb = 4; |
| 759 | /* XXX use MC settings? */ |
| 760 | rdev->config.cayman.shader_engine_tile_size = 32; |
| 761 | rdev->config.cayman.num_gpus = 1; |
| 762 | rdev->config.cayman.multi_gpu_tile_size = 64; |
| 763 | |
| 764 | //gb_addr_config = 0x02011003 |
| 765 | #if 0 |
| 766 | gb_addr_config = RREG32(GB_ADDR_CONFIG); |
| 767 | #else |
| 768 | gb_addr_config = 0; |
| 769 | switch (rdev->config.cayman.num_tile_pipes) { |
| 770 | case 1: |
| 771 | default: |
| 772 | gb_addr_config |= NUM_PIPES(0); |
| 773 | break; |
| 774 | case 2: |
| 775 | gb_addr_config |= NUM_PIPES(1); |
| 776 | break; |
| 777 | case 4: |
| 778 | gb_addr_config |= NUM_PIPES(2); |
| 779 | break; |
| 780 | case 8: |
| 781 | gb_addr_config |= NUM_PIPES(3); |
| 782 | break; |
| 783 | } |
| 784 | |
| 785 | tmp = (rdev->config.cayman.mem_max_burst_length_bytes / 256) - 1; |
| 786 | gb_addr_config |= PIPE_INTERLEAVE_SIZE(tmp); |
| 787 | gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.cayman.num_shader_engines - 1); |
| 788 | tmp = (rdev->config.cayman.shader_engine_tile_size / 16) - 1; |
| 789 | gb_addr_config |= SHADER_ENGINE_TILE_SIZE(tmp); |
| 790 | switch (rdev->config.cayman.num_gpus) { |
| 791 | case 1: |
| 792 | default: |
| 793 | gb_addr_config |= NUM_GPUS(0); |
| 794 | break; |
| 795 | case 2: |
| 796 | gb_addr_config |= NUM_GPUS(1); |
| 797 | break; |
| 798 | case 4: |
| 799 | gb_addr_config |= NUM_GPUS(2); |
| 800 | break; |
| 801 | } |
| 802 | switch (rdev->config.cayman.multi_gpu_tile_size) { |
| 803 | case 16: |
| 804 | gb_addr_config |= MULTI_GPU_TILE_SIZE(0); |
| 805 | break; |
| 806 | case 32: |
| 807 | default: |
| 808 | gb_addr_config |= MULTI_GPU_TILE_SIZE(1); |
| 809 | break; |
| 810 | case 64: |
| 811 | gb_addr_config |= MULTI_GPU_TILE_SIZE(2); |
| 812 | break; |
| 813 | case 128: |
| 814 | gb_addr_config |= MULTI_GPU_TILE_SIZE(3); |
| 815 | break; |
| 816 | } |
| 817 | switch (rdev->config.cayman.mem_row_size_in_kb) { |
| 818 | case 1: |
| 819 | default: |
| 820 | gb_addr_config |= ROW_SIZE(0); |
| 821 | break; |
| 822 | case 2: |
| 823 | gb_addr_config |= ROW_SIZE(1); |
| 824 | break; |
| 825 | case 4: |
| 826 | gb_addr_config |= ROW_SIZE(2); |
| 827 | break; |
| 828 | } |
| 829 | #endif |
| 830 | |
| 831 | tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT; |
| 832 | rdev->config.cayman.num_tile_pipes = (1 << tmp); |
| 833 | tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT; |
| 834 | rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256; |
| 835 | tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT; |
| 836 | rdev->config.cayman.num_shader_engines = tmp + 1; |
| 837 | tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT; |
| 838 | rdev->config.cayman.num_gpus = tmp + 1; |
| 839 | tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT; |
| 840 | rdev->config.cayman.multi_gpu_tile_size = 1 << tmp; |
| 841 | tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT; |
| 842 | rdev->config.cayman.mem_row_size_in_kb = 1 << tmp; |
| 843 | |
| 844 | //gb_backend_map = 0x76541032; |
| 845 | #if 0 |
| 846 | gb_backend_map = RREG32(GB_BACKEND_MAP); |
| 847 | #else |
| 848 | gb_backend_map = |
| 849 | cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes, |
| 850 | rdev->config.cayman.num_backends_per_se * |
| 851 | rdev->config.cayman.num_shader_engines, |
| 852 | &rdev->config.cayman.backend_disable_mask_per_asic, |
| 853 | rdev->config.cayman.num_shader_engines); |
| 854 | #endif |
| 855 | /* setup tiling info dword. gb_addr_config is not adequate since it does |
| 856 | * not have bank info, so create a custom tiling dword. |
| 857 | * bits 3:0 num_pipes |
| 858 | * bits 7:4 num_banks |
| 859 | * bits 11:8 group_size |
| 860 | * bits 15:12 row_size |
| 861 | */ |
| 862 | rdev->config.cayman.tile_config = 0; |
| 863 | switch (rdev->config.cayman.num_tile_pipes) { |
| 864 | case 1: |
| 865 | default: |
| 866 | rdev->config.cayman.tile_config |= (0 << 0); |
| 867 | break; |
| 868 | case 2: |
| 869 | rdev->config.cayman.tile_config |= (1 << 0); |
| 870 | break; |
| 871 | case 4: |
| 872 | rdev->config.cayman.tile_config |= (2 << 0); |
| 873 | break; |
| 874 | case 8: |
| 875 | rdev->config.cayman.tile_config |= (3 << 0); |
| 876 | break; |
| 877 | } |
Alex Deucher | 7b76e47 | 2012-03-20 17:18:36 -0400 | [diff] [blame] | 878 | |
| 879 | /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */ |
| 880 | if (rdev->flags & RADEON_IS_IGP) |
Alex Deucher | 772605e | 2012-05-24 22:55:15 -0400 | [diff] [blame] | 881 | rdev->config.cayman.tile_config |= 1 << 4; |
Alex Deucher | d8d09be | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 882 | else { |
Alex Deucher | e3d7a0f | 2012-07-31 11:05:11 -0400 | [diff] [blame^] | 883 | switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) { |
| 884 | case 0: /* four banks */ |
Alex Deucher | d8d09be | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 885 | rdev->config.cayman.tile_config |= 0 << 4; |
Alex Deucher | e3d7a0f | 2012-07-31 11:05:11 -0400 | [diff] [blame^] | 886 | break; |
| 887 | case 1: /* eight banks */ |
| 888 | rdev->config.cayman.tile_config |= 1 << 4; |
| 889 | break; |
| 890 | case 2: /* sixteen banks */ |
| 891 | default: |
| 892 | rdev->config.cayman.tile_config |= 2 << 4; |
| 893 | break; |
| 894 | } |
Alex Deucher | d8d09be | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 895 | } |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 896 | rdev->config.cayman.tile_config |= |
Dave Airlie | cde5083 | 2011-05-19 14:14:41 +1000 | [diff] [blame] | 897 | ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8; |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 898 | rdev->config.cayman.tile_config |= |
| 899 | ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12; |
| 900 | |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 901 | rdev->config.cayman.backend_map = gb_backend_map; |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 902 | WREG32(GB_BACKEND_MAP, gb_backend_map); |
| 903 | WREG32(GB_ADDR_CONFIG, gb_addr_config); |
| 904 | WREG32(DMIF_ADDR_CONFIG, gb_addr_config); |
| 905 | WREG32(HDP_ADDR_CONFIG, gb_addr_config); |
| 906 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 907 | /* primary versions */ |
| 908 | WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 909 | WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 910 | WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config); |
| 911 | |
| 912 | WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable); |
| 913 | WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable); |
| 914 | |
| 915 | /* user versions */ |
| 916 | WREG32(GC_USER_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 917 | WREG32(GC_USER_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable); |
| 918 | WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config); |
| 919 | |
| 920 | WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable); |
| 921 | WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable); |
| 922 | |
| 923 | /* reprogram the shader complex */ |
| 924 | cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG); |
| 925 | for (i = 0; i < 16; i++) |
| 926 | WREG32(CGTS_SM_CTRL_REG, OVERRIDE); |
| 927 | WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg); |
| 928 | |
| 929 | /* set HW defaults for 3D engine */ |
| 930 | WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60)); |
| 931 | |
| 932 | sx_debug_1 = RREG32(SX_DEBUG_1); |
| 933 | sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS; |
| 934 | WREG32(SX_DEBUG_1, sx_debug_1); |
| 935 | |
| 936 | smx_dc_ctl0 = RREG32(SMX_DC_CTL0); |
| 937 | smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff); |
Dave Airlie | 285e042 | 2011-05-09 14:54:33 +1000 | [diff] [blame] | 938 | smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets); |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 939 | WREG32(SMX_DC_CTL0, smx_dc_ctl0); |
| 940 | |
| 941 | WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE); |
| 942 | |
| 943 | /* need to be explicitly zero-ed */ |
| 944 | WREG32(VGT_OFFCHIP_LDS_BASE, 0); |
| 945 | WREG32(SQ_LSTMP_RING_BASE, 0); |
| 946 | WREG32(SQ_HSTMP_RING_BASE, 0); |
| 947 | WREG32(SQ_ESTMP_RING_BASE, 0); |
| 948 | WREG32(SQ_GSTMP_RING_BASE, 0); |
| 949 | WREG32(SQ_VSTMP_RING_BASE, 0); |
| 950 | WREG32(SQ_PSTMP_RING_BASE, 0); |
| 951 | |
| 952 | WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO); |
| 953 | |
Dave Airlie | 285e042 | 2011-05-09 14:54:33 +1000 | [diff] [blame] | 954 | WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) | |
| 955 | POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) | |
| 956 | SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1))); |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 957 | |
Dave Airlie | 285e042 | 2011-05-09 14:54:33 +1000 | [diff] [blame] | 958 | WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) | |
| 959 | SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) | |
| 960 | SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size))); |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 961 | |
| 962 | |
| 963 | WREG32(VGT_NUM_INSTANCES, 1); |
| 964 | |
| 965 | WREG32(CP_PERFMON_CNTL, 0); |
| 966 | |
Dave Airlie | 285e042 | 2011-05-09 14:54:33 +1000 | [diff] [blame] | 967 | WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 968 | FETCH_FIFO_HIWATER(0x4) | |
| 969 | DONE_FIFO_HIWATER(0xe0) | |
| 970 | ALU_UPDATE_FIFO_HIWATER(0x8))); |
| 971 | |
| 972 | WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4)); |
| 973 | WREG32(SQ_CONFIG, (VC_ENABLE | |
| 974 | EXPORT_SRC_C | |
| 975 | GFX_PRIO(0) | |
| 976 | CS1_PRIO(0) | |
| 977 | CS2_PRIO(1))); |
| 978 | WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE); |
| 979 | |
| 980 | WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) | |
| 981 | FORCE_EOV_MAX_REZ_CNT(255))); |
| 982 | |
| 983 | WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) | |
| 984 | AUTO_INVLD_EN(ES_AND_GS_AUTO)); |
| 985 | |
| 986 | WREG32(VGT_GS_VERTEX_REUSE, 16); |
| 987 | WREG32(PA_SC_LINE_STIPPLE_STATE, 0); |
| 988 | |
| 989 | WREG32(CB_PERF_CTR0_SEL_0, 0); |
| 990 | WREG32(CB_PERF_CTR0_SEL_1, 0); |
| 991 | WREG32(CB_PERF_CTR1_SEL_0, 0); |
| 992 | WREG32(CB_PERF_CTR1_SEL_1, 0); |
| 993 | WREG32(CB_PERF_CTR2_SEL_0, 0); |
| 994 | WREG32(CB_PERF_CTR2_SEL_1, 0); |
| 995 | WREG32(CB_PERF_CTR3_SEL_0, 0); |
| 996 | WREG32(CB_PERF_CTR3_SEL_1, 0); |
| 997 | |
Dave Airlie | 0b65f83 | 2011-05-19 14:14:42 +1000 | [diff] [blame] | 998 | tmp = RREG32(HDP_MISC_CNTL); |
| 999 | tmp |= HDP_FLUSH_INVALIDATE_CACHE; |
| 1000 | WREG32(HDP_MISC_CNTL, tmp); |
| 1001 | |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 1002 | hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL); |
| 1003 | WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl); |
| 1004 | |
| 1005 | WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3)); |
| 1006 | |
| 1007 | udelay(50); |
| 1008 | } |
| 1009 | |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1010 | /* |
| 1011 | * GART |
| 1012 | */ |
| 1013 | void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev) |
| 1014 | { |
| 1015 | /* flush hdp cache */ |
| 1016 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 1017 | |
| 1018 | /* bits 0-7 are the VM contexts0-7 */ |
| 1019 | WREG32(VM_INVALIDATE_REQUEST, 1); |
| 1020 | } |
| 1021 | |
| 1022 | int cayman_pcie_gart_enable(struct radeon_device *rdev) |
| 1023 | { |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1024 | int i, r; |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1025 | |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 1026 | if (rdev->gart.robj == NULL) { |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1027 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 1028 | return -EINVAL; |
| 1029 | } |
| 1030 | r = radeon_gart_table_vram_pin(rdev); |
| 1031 | if (r) |
| 1032 | return r; |
| 1033 | radeon_gart_restore(rdev); |
| 1034 | /* Setup TLB control */ |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1035 | WREG32(MC_VM_MX_L1_TLB_CNTL, |
| 1036 | (0xA << 7) | |
| 1037 | ENABLE_L1_TLB | |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1038 | ENABLE_L1_FRAGMENT_PROCESSING | |
| 1039 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1040 | ENABLE_ADVANCED_DRIVER_MODEL | |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1041 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU); |
| 1042 | /* Setup L2 cache */ |
| 1043 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | |
| 1044 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1045 | ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE | |
| 1046 | EFFECTIVE_L2_QUEUE_SIZE(7) | |
| 1047 | CONTEXT1_IDENTITY_ACCESS_MODE(1)); |
| 1048 | WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE); |
| 1049 | WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY | |
| 1050 | L2_CACHE_BIGK_FRAGMENT_SIZE(6)); |
| 1051 | /* setup context0 */ |
| 1052 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); |
| 1053 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); |
| 1054 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); |
| 1055 | WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, |
| 1056 | (u32)(rdev->dummy_page.addr >> 12)); |
| 1057 | WREG32(VM_CONTEXT0_CNTL2, 0); |
| 1058 | WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 1059 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1060 | |
| 1061 | WREG32(0x15D4, 0); |
| 1062 | WREG32(0x15D8, 0); |
| 1063 | WREG32(0x15DC, 0); |
| 1064 | |
| 1065 | /* empty context1-7 */ |
| 1066 | for (i = 1; i < 8; i++) { |
| 1067 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0); |
| 1068 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), 0); |
| 1069 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), |
| 1070 | rdev->gart.table_addr >> 12); |
| 1071 | } |
| 1072 | |
| 1073 | /* enable context1-7 */ |
| 1074 | WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR, |
| 1075 | (u32)(rdev->dummy_page.addr >> 12)); |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1076 | WREG32(VM_CONTEXT1_CNTL2, 0); |
| 1077 | WREG32(VM_CONTEXT1_CNTL, 0); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1078 | WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 1079 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1080 | |
| 1081 | cayman_pcie_gart_tlb_flush(rdev); |
Tormod Volden | fcf4de5 | 2011-08-31 21:54:07 +0000 | [diff] [blame] | 1082 | DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n", |
| 1083 | (unsigned)(rdev->mc.gtt_size >> 20), |
| 1084 | (unsigned long long)rdev->gart.table_addr); |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1085 | rdev->gart.ready = true; |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | void cayman_pcie_gart_disable(struct radeon_device *rdev) |
| 1090 | { |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1091 | /* Disable all tables */ |
| 1092 | WREG32(VM_CONTEXT0_CNTL, 0); |
| 1093 | WREG32(VM_CONTEXT1_CNTL, 0); |
| 1094 | /* Setup TLB control */ |
| 1095 | WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING | |
| 1096 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 1097 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU); |
| 1098 | /* Setup L2 cache */ |
| 1099 | WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1100 | ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE | |
| 1101 | EFFECTIVE_L2_QUEUE_SIZE(7) | |
| 1102 | CONTEXT1_IDENTITY_ACCESS_MODE(1)); |
| 1103 | WREG32(VM_L2_CNTL2, 0); |
| 1104 | WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY | |
| 1105 | L2_CACHE_BIGK_FRAGMENT_SIZE(6)); |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 1106 | radeon_gart_table_vram_unpin(rdev); |
Alex Deucher | fa8198e | 2011-03-02 20:07:30 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | void cayman_pcie_gart_fini(struct radeon_device *rdev) |
| 1110 | { |
| 1111 | cayman_pcie_gart_disable(rdev); |
| 1112 | radeon_gart_table_vram_free(rdev); |
| 1113 | radeon_gart_fini(rdev); |
| 1114 | } |
| 1115 | |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 1116 | void cayman_cp_int_cntl_setup(struct radeon_device *rdev, |
| 1117 | int ring, u32 cp_int_cntl) |
| 1118 | { |
| 1119 | u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3; |
| 1120 | |
| 1121 | WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3)); |
| 1122 | WREG32(CP_INT_CNTL, cp_int_cntl); |
| 1123 | } |
| 1124 | |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1125 | /* |
| 1126 | * CP. |
| 1127 | */ |
Alex Deucher | b40e7e1 | 2011-11-17 14:57:50 -0500 | [diff] [blame] | 1128 | void cayman_fence_ring_emit(struct radeon_device *rdev, |
| 1129 | struct radeon_fence *fence) |
| 1130 | { |
| 1131 | struct radeon_ring *ring = &rdev->ring[fence->ring]; |
| 1132 | u64 addr = rdev->fence_drv[fence->ring].gpu_addr; |
| 1133 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1134 | /* flush read cache over gart for this vmid */ |
| 1135 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 1136 | radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2); |
| 1137 | radeon_ring_write(ring, 0); |
Alex Deucher | b40e7e1 | 2011-11-17 14:57:50 -0500 | [diff] [blame] | 1138 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3)); |
| 1139 | radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA); |
| 1140 | radeon_ring_write(ring, 0xFFFFFFFF); |
| 1141 | radeon_ring_write(ring, 0); |
| 1142 | radeon_ring_write(ring, 10); /* poll interval */ |
| 1143 | /* EVENT_WRITE_EOP - flush caches, send int */ |
| 1144 | radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4)); |
| 1145 | radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5)); |
| 1146 | radeon_ring_write(ring, addr & 0xffffffff); |
| 1147 | radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2)); |
| 1148 | radeon_ring_write(ring, fence->seq); |
| 1149 | radeon_ring_write(ring, 0); |
| 1150 | } |
| 1151 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1152 | void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 1153 | { |
| 1154 | struct radeon_ring *ring = &rdev->ring[ib->fence->ring]; |
| 1155 | |
| 1156 | /* set to DX10/11 mode */ |
| 1157 | radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0)); |
| 1158 | radeon_ring_write(ring, 1); |
| 1159 | radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2)); |
| 1160 | radeon_ring_write(ring, |
| 1161 | #ifdef __BIG_ENDIAN |
| 1162 | (2 << 0) | |
| 1163 | #endif |
| 1164 | (ib->gpu_addr & 0xFFFFFFFC)); |
| 1165 | radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF); |
| 1166 | radeon_ring_write(ring, ib->length_dw | (ib->vm_id << 24)); |
| 1167 | |
| 1168 | /* flush read cache over gart for this vmid */ |
| 1169 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 1170 | radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2); |
| 1171 | radeon_ring_write(ring, ib->vm_id); |
| 1172 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3)); |
| 1173 | radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA); |
| 1174 | radeon_ring_write(ring, 0xFFFFFFFF); |
| 1175 | radeon_ring_write(ring, 0); |
| 1176 | radeon_ring_write(ring, 10); /* poll interval */ |
| 1177 | } |
| 1178 | |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1179 | static void cayman_cp_enable(struct radeon_device *rdev, bool enable) |
| 1180 | { |
| 1181 | if (enable) |
| 1182 | WREG32(CP_ME_CNTL, 0); |
| 1183 | else { |
Dave Airlie | 38f1cff | 2011-03-16 11:34:41 +1000 | [diff] [blame] | 1184 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1185 | WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT)); |
| 1186 | WREG32(SCRATCH_UMSK, 0); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | static int cayman_cp_load_microcode(struct radeon_device *rdev) |
| 1191 | { |
| 1192 | const __be32 *fw_data; |
| 1193 | int i; |
| 1194 | |
| 1195 | if (!rdev->me_fw || !rdev->pfp_fw) |
| 1196 | return -EINVAL; |
| 1197 | |
| 1198 | cayman_cp_enable(rdev, false); |
| 1199 | |
| 1200 | fw_data = (const __be32 *)rdev->pfp_fw->data; |
| 1201 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1202 | for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++) |
| 1203 | WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 1204 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1205 | |
| 1206 | fw_data = (const __be32 *)rdev->me_fw->data; |
| 1207 | WREG32(CP_ME_RAM_WADDR, 0); |
| 1208 | for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++) |
| 1209 | WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++)); |
| 1210 | |
| 1211 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1212 | WREG32(CP_ME_RAM_WADDR, 0); |
| 1213 | WREG32(CP_ME_RAM_RADDR, 0); |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | static int cayman_cp_start(struct radeon_device *rdev) |
| 1218 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1219 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1220 | int r, i; |
| 1221 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1222 | r = radeon_ring_lock(rdev, ring, 7); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1223 | if (r) { |
| 1224 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 1225 | return r; |
| 1226 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1227 | radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5)); |
| 1228 | radeon_ring_write(ring, 0x1); |
| 1229 | radeon_ring_write(ring, 0x0); |
| 1230 | radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1); |
| 1231 | radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1)); |
| 1232 | radeon_ring_write(ring, 0); |
| 1233 | radeon_ring_write(ring, 0); |
| 1234 | radeon_ring_unlock_commit(rdev, ring); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1235 | |
| 1236 | cayman_cp_enable(rdev, true); |
| 1237 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1238 | r = radeon_ring_lock(rdev, ring, cayman_default_size + 19); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1239 | if (r) { |
| 1240 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 1241 | return r; |
| 1242 | } |
| 1243 | |
| 1244 | /* setup clear context state */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1245 | radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0)); |
| 1246 | radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1247 | |
| 1248 | for (i = 0; i < cayman_default_size; i++) |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1249 | radeon_ring_write(ring, cayman_default_state[i]); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1250 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1251 | radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0)); |
| 1252 | radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1253 | |
| 1254 | /* set clear context state */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1255 | radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0)); |
| 1256 | radeon_ring_write(ring, 0); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1257 | |
| 1258 | /* SQ_VTX_BASE_VTX_LOC */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1259 | radeon_ring_write(ring, 0xc0026f00); |
| 1260 | radeon_ring_write(ring, 0x00000000); |
| 1261 | radeon_ring_write(ring, 0x00000000); |
| 1262 | radeon_ring_write(ring, 0x00000000); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1263 | |
| 1264 | /* Clear consts */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1265 | radeon_ring_write(ring, 0xc0036f00); |
| 1266 | radeon_ring_write(ring, 0x00000bc4); |
| 1267 | radeon_ring_write(ring, 0xffffffff); |
| 1268 | radeon_ring_write(ring, 0xffffffff); |
| 1269 | radeon_ring_write(ring, 0xffffffff); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1270 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1271 | radeon_ring_write(ring, 0xc0026900); |
| 1272 | radeon_ring_write(ring, 0x00000316); |
| 1273 | radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */ |
| 1274 | radeon_ring_write(ring, 0x00000010); /* */ |
Alex Deucher | 9b91d18 | 2011-03-02 20:07:39 -0500 | [diff] [blame] | 1275 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1276 | radeon_ring_unlock_commit(rdev, ring); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1277 | |
| 1278 | /* XXX init other rings */ |
| 1279 | |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1283 | static void cayman_cp_fini(struct radeon_device *rdev) |
| 1284 | { |
| 1285 | cayman_cp_enable(rdev, false); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1286 | radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1287 | } |
| 1288 | |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1289 | int cayman_cp_resume(struct radeon_device *rdev) |
| 1290 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1291 | struct radeon_ring *ring; |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1292 | u32 tmp; |
| 1293 | u32 rb_bufsz; |
| 1294 | int r; |
| 1295 | |
| 1296 | /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */ |
| 1297 | WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP | |
| 1298 | SOFT_RESET_PA | |
| 1299 | SOFT_RESET_SH | |
| 1300 | SOFT_RESET_VGT | |
Jerome Glisse | a49a50d | 2011-08-24 20:00:17 +0000 | [diff] [blame] | 1301 | SOFT_RESET_SPI | |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1302 | SOFT_RESET_SX)); |
| 1303 | RREG32(GRBM_SOFT_RESET); |
| 1304 | mdelay(15); |
| 1305 | WREG32(GRBM_SOFT_RESET, 0); |
| 1306 | RREG32(GRBM_SOFT_RESET); |
| 1307 | |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 1308 | WREG32(CP_SEM_WAIT_TIMER, 0x0); |
Alex Deucher | 11ef3f1 | 2012-01-20 14:47:43 -0500 | [diff] [blame] | 1309 | WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1310 | |
| 1311 | /* Set the write pointer delay */ |
| 1312 | WREG32(CP_RB_WPTR_DELAY, 0); |
| 1313 | |
| 1314 | WREG32(CP_DEBUG, (1 << 27)); |
| 1315 | |
| 1316 | /* ring 0 - compute and gfx */ |
| 1317 | /* Set ring buffer size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1318 | ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
| 1319 | rb_bufsz = drm_order(ring->ring_size / 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1320 | tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz; |
| 1321 | #ifdef __BIG_ENDIAN |
| 1322 | tmp |= BUF_SWAP_32BIT; |
| 1323 | #endif |
| 1324 | WREG32(CP_RB0_CNTL, tmp); |
| 1325 | |
| 1326 | /* Initialize the ring buffer's read and write pointers */ |
| 1327 | WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1328 | ring->wptr = 0; |
| 1329 | WREG32(CP_RB0_WPTR, ring->wptr); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1330 | |
| 1331 | /* set the wb address wether it's enabled or not */ |
| 1332 | WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC); |
| 1333 | WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF); |
| 1334 | WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF); |
| 1335 | |
| 1336 | if (rdev->wb.enabled) |
| 1337 | WREG32(SCRATCH_UMSK, 0xff); |
| 1338 | else { |
| 1339 | tmp |= RB_NO_UPDATE; |
| 1340 | WREG32(SCRATCH_UMSK, 0); |
| 1341 | } |
| 1342 | |
| 1343 | mdelay(1); |
| 1344 | WREG32(CP_RB0_CNTL, tmp); |
| 1345 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1346 | WREG32(CP_RB0_BASE, ring->gpu_addr >> 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1347 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1348 | ring->rptr = RREG32(CP_RB0_RPTR); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1349 | |
| 1350 | /* ring1 - compute only */ |
| 1351 | /* Set ring buffer size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1352 | ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]; |
| 1353 | rb_bufsz = drm_order(ring->ring_size / 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1354 | tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz; |
| 1355 | #ifdef __BIG_ENDIAN |
| 1356 | tmp |= BUF_SWAP_32BIT; |
| 1357 | #endif |
| 1358 | WREG32(CP_RB1_CNTL, tmp); |
| 1359 | |
| 1360 | /* Initialize the ring buffer's read and write pointers */ |
| 1361 | WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1362 | ring->wptr = 0; |
| 1363 | WREG32(CP_RB1_WPTR, ring->wptr); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1364 | |
| 1365 | /* set the wb address wether it's enabled or not */ |
| 1366 | WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC); |
| 1367 | WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF); |
| 1368 | |
| 1369 | mdelay(1); |
| 1370 | WREG32(CP_RB1_CNTL, tmp); |
| 1371 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1372 | WREG32(CP_RB1_BASE, ring->gpu_addr >> 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1373 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1374 | ring->rptr = RREG32(CP_RB1_RPTR); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1375 | |
| 1376 | /* ring2 - compute only */ |
| 1377 | /* Set ring buffer size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1378 | ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]; |
| 1379 | rb_bufsz = drm_order(ring->ring_size / 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1380 | tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz; |
| 1381 | #ifdef __BIG_ENDIAN |
| 1382 | tmp |= BUF_SWAP_32BIT; |
| 1383 | #endif |
| 1384 | WREG32(CP_RB2_CNTL, tmp); |
| 1385 | |
| 1386 | /* Initialize the ring buffer's read and write pointers */ |
| 1387 | WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1388 | ring->wptr = 0; |
| 1389 | WREG32(CP_RB2_WPTR, ring->wptr); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1390 | |
| 1391 | /* set the wb address wether it's enabled or not */ |
| 1392 | WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC); |
| 1393 | WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF); |
| 1394 | |
| 1395 | mdelay(1); |
| 1396 | WREG32(CP_RB2_CNTL, tmp); |
| 1397 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1398 | WREG32(CP_RB2_BASE, ring->gpu_addr >> 8); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1399 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1400 | ring->rptr = RREG32(CP_RB2_RPTR); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1401 | |
| 1402 | /* start the rings */ |
| 1403 | cayman_cp_start(rdev); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1404 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true; |
| 1405 | rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false; |
| 1406 | rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false; |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1407 | /* this only test cp0 */ |
Alex Deucher | f712812 | 2012-02-23 17:53:45 -0500 | [diff] [blame] | 1408 | r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1409 | if (r) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1410 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; |
| 1411 | rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false; |
| 1412 | rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false; |
Alex Deucher | 0c88a02 | 2011-03-02 20:07:31 -0500 | [diff] [blame] | 1413 | return r; |
| 1414 | } |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1419 | bool cayman_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring) |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1420 | { |
| 1421 | u32 srbm_status; |
| 1422 | u32 grbm_status; |
| 1423 | u32 grbm_status_se0, grbm_status_se1; |
| 1424 | struct r100_gpu_lockup *lockup = &rdev->config.cayman.lockup; |
| 1425 | int r; |
| 1426 | |
| 1427 | srbm_status = RREG32(SRBM_STATUS); |
| 1428 | grbm_status = RREG32(GRBM_STATUS); |
| 1429 | grbm_status_se0 = RREG32(GRBM_STATUS_SE0); |
| 1430 | grbm_status_se1 = RREG32(GRBM_STATUS_SE1); |
| 1431 | if (!(grbm_status & GUI_ACTIVE)) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1432 | r100_gpu_lockup_update(lockup, ring); |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1433 | return false; |
| 1434 | } |
| 1435 | /* force CP activities */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1436 | r = radeon_ring_lock(rdev, ring, 2); |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1437 | if (!r) { |
| 1438 | /* PACKET2 NOP */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1439 | radeon_ring_write(ring, 0x80000000); |
| 1440 | radeon_ring_write(ring, 0x80000000); |
| 1441 | radeon_ring_unlock_commit(rdev, ring); |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1442 | } |
| 1443 | /* XXX deal with CP0,1,2 */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1444 | ring->rptr = RREG32(ring->rptr_reg); |
| 1445 | return r100_gpu_cp_is_lockup(rdev, lockup, ring); |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static int cayman_gpu_soft_reset(struct radeon_device *rdev) |
| 1449 | { |
| 1450 | struct evergreen_mc_save save; |
| 1451 | u32 grbm_reset = 0; |
| 1452 | |
| 1453 | if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE)) |
| 1454 | return 0; |
| 1455 | |
| 1456 | dev_info(rdev->dev, "GPU softreset \n"); |
| 1457 | dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n", |
| 1458 | RREG32(GRBM_STATUS)); |
| 1459 | dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n", |
| 1460 | RREG32(GRBM_STATUS_SE0)); |
| 1461 | dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n", |
| 1462 | RREG32(GRBM_STATUS_SE1)); |
| 1463 | dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n", |
| 1464 | RREG32(SRBM_STATUS)); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1465 | dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n", |
| 1466 | RREG32(0x14F8)); |
| 1467 | dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n", |
| 1468 | RREG32(0x14D8)); |
| 1469 | dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n", |
| 1470 | RREG32(0x14FC)); |
| 1471 | dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n", |
| 1472 | RREG32(0x14DC)); |
| 1473 | |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1474 | evergreen_mc_stop(rdev, &save); |
| 1475 | if (evergreen_mc_wait_for_idle(rdev)) { |
| 1476 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
| 1477 | } |
| 1478 | /* Disable CP parsing/prefetching */ |
| 1479 | WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT); |
| 1480 | |
| 1481 | /* reset all the gfx blocks */ |
| 1482 | grbm_reset = (SOFT_RESET_CP | |
| 1483 | SOFT_RESET_CB | |
| 1484 | SOFT_RESET_DB | |
| 1485 | SOFT_RESET_GDS | |
| 1486 | SOFT_RESET_PA | |
| 1487 | SOFT_RESET_SC | |
| 1488 | SOFT_RESET_SPI | |
| 1489 | SOFT_RESET_SH | |
| 1490 | SOFT_RESET_SX | |
| 1491 | SOFT_RESET_TC | |
| 1492 | SOFT_RESET_TA | |
| 1493 | SOFT_RESET_VGT | |
| 1494 | SOFT_RESET_IA); |
| 1495 | |
| 1496 | dev_info(rdev->dev, " GRBM_SOFT_RESET=0x%08X\n", grbm_reset); |
| 1497 | WREG32(GRBM_SOFT_RESET, grbm_reset); |
| 1498 | (void)RREG32(GRBM_SOFT_RESET); |
| 1499 | udelay(50); |
| 1500 | WREG32(GRBM_SOFT_RESET, 0); |
| 1501 | (void)RREG32(GRBM_SOFT_RESET); |
| 1502 | /* Wait a little for things to settle down */ |
| 1503 | udelay(50); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1504 | |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1505 | dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n", |
| 1506 | RREG32(GRBM_STATUS)); |
| 1507 | dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n", |
| 1508 | RREG32(GRBM_STATUS_SE0)); |
| 1509 | dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n", |
| 1510 | RREG32(GRBM_STATUS_SE1)); |
| 1511 | dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n", |
| 1512 | RREG32(SRBM_STATUS)); |
| 1513 | evergreen_mc_resume(rdev, &save); |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | int cayman_asic_reset(struct radeon_device *rdev) |
| 1518 | { |
| 1519 | return cayman_gpu_soft_reset(rdev); |
| 1520 | } |
| 1521 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1522 | static int cayman_startup(struct radeon_device *rdev) |
| 1523 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1524 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1525 | int r; |
| 1526 | |
Ilija Hadzic | b07759b | 2011-09-20 10:22:58 -0400 | [diff] [blame] | 1527 | /* enable pcie gen2 link */ |
| 1528 | evergreen_pcie_gen2_enable(rdev); |
| 1529 | |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1530 | if (rdev->flags & RADEON_IS_IGP) { |
| 1531 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) { |
| 1532 | r = ni_init_microcode(rdev); |
| 1533 | if (r) { |
| 1534 | DRM_ERROR("Failed to load firmware!\n"); |
| 1535 | return r; |
| 1536 | } |
| 1537 | } |
| 1538 | } else { |
| 1539 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) { |
| 1540 | r = ni_init_microcode(rdev); |
| 1541 | if (r) { |
| 1542 | DRM_ERROR("Failed to load firmware!\n"); |
| 1543 | return r; |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | r = ni_mc_load_microcode(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1548 | if (r) { |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1549 | DRM_ERROR("Failed to load MC firmware!\n"); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1550 | return r; |
| 1551 | } |
| 1552 | } |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1553 | |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1554 | r = r600_vram_scratch_init(rdev); |
| 1555 | if (r) |
| 1556 | return r; |
| 1557 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1558 | evergreen_mc_program(rdev); |
| 1559 | r = cayman_pcie_gart_enable(rdev); |
| 1560 | if (r) |
| 1561 | return r; |
| 1562 | cayman_gpu_init(rdev); |
| 1563 | |
Alex Deucher | cb92d45 | 2011-05-25 16:39:00 -0400 | [diff] [blame] | 1564 | r = evergreen_blit_init(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1565 | if (r) { |
Ilija Hadzic | fb3d9e9 | 2011-10-12 23:29:41 -0400 | [diff] [blame] | 1566 | r600_blit_fini(rdev); |
Alex Deucher | 27cd776 | 2012-02-23 17:53:42 -0500 | [diff] [blame] | 1567 | rdev->asic->copy.copy = NULL; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1568 | dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r); |
| 1569 | } |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1570 | |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1571 | /* allocate rlc buffers */ |
| 1572 | if (rdev->flags & RADEON_IS_IGP) { |
| 1573 | r = si_rlc_init(rdev); |
| 1574 | if (r) { |
| 1575 | DRM_ERROR("Failed to init rlc BOs!\n"); |
| 1576 | return r; |
| 1577 | } |
| 1578 | } |
| 1579 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1580 | /* allocate wb buffer */ |
| 1581 | r = radeon_wb_init(rdev); |
| 1582 | if (r) |
| 1583 | return r; |
| 1584 | |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 1585 | r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); |
| 1586 | if (r) { |
| 1587 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 1588 | return r; |
| 1589 | } |
| 1590 | |
| 1591 | r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX); |
| 1592 | if (r) { |
| 1593 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 1594 | return r; |
| 1595 | } |
| 1596 | |
| 1597 | r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX); |
| 1598 | if (r) { |
| 1599 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 1600 | return r; |
| 1601 | } |
| 1602 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1603 | /* Enable IRQ */ |
| 1604 | r = r600_irq_init(rdev); |
| 1605 | if (r) { |
| 1606 | DRM_ERROR("radeon: IH init failed (%d).\n", r); |
| 1607 | radeon_irq_kms_fini(rdev); |
| 1608 | return r; |
| 1609 | } |
| 1610 | evergreen_irq_set(rdev); |
| 1611 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1612 | r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET, |
Alex Deucher | 78c5560 | 2011-11-17 14:25:56 -0500 | [diff] [blame] | 1613 | CP_RB0_RPTR, CP_RB0_WPTR, |
| 1614 | 0, 0xfffff, RADEON_CP_PACKET2); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1615 | if (r) |
| 1616 | return r; |
| 1617 | r = cayman_cp_load_microcode(rdev); |
| 1618 | if (r) |
| 1619 | return r; |
| 1620 | r = cayman_cp_resume(rdev); |
| 1621 | if (r) |
| 1622 | return r; |
| 1623 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1624 | r = radeon_ib_pool_start(rdev); |
| 1625 | if (r) |
| 1626 | return r; |
| 1627 | |
Alex Deucher | f712812 | 2012-02-23 17:53:45 -0500 | [diff] [blame] | 1628 | r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1629 | if (r) { |
| 1630 | DRM_ERROR("radeon: failed testing IB (%d).\n", r); |
| 1631 | rdev->accel_working = false; |
| 1632 | return r; |
| 1633 | } |
| 1634 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1635 | r = radeon_vm_manager_start(rdev); |
| 1636 | if (r) |
| 1637 | return r; |
| 1638 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | int cayman_resume(struct radeon_device *rdev) |
| 1643 | { |
| 1644 | int r; |
| 1645 | |
| 1646 | /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw, |
| 1647 | * posting will perform necessary task to bring back GPU into good |
| 1648 | * shape. |
| 1649 | */ |
| 1650 | /* post card */ |
| 1651 | atom_asic_init(rdev->mode_info.atom_context); |
| 1652 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1653 | rdev->accel_working = true; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1654 | r = cayman_startup(rdev); |
| 1655 | if (r) { |
| 1656 | DRM_ERROR("cayman startup failed on resume\n"); |
Jerome Glisse | 6b7746e | 2012-02-20 17:57:20 -0500 | [diff] [blame] | 1657 | rdev->accel_working = false; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1658 | return r; |
| 1659 | } |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1660 | return r; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | int cayman_suspend(struct radeon_device *rdev) |
| 1664 | { |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1665 | /* FIXME: we should wait for ring to be empty */ |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1666 | radeon_ib_pool_suspend(rdev); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1667 | radeon_vm_manager_suspend(rdev); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1668 | r600_blit_suspend(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1669 | cayman_cp_enable(rdev, false); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1670 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1671 | evergreen_irq_suspend(rdev); |
| 1672 | radeon_wb_disable(rdev); |
| 1673 | cayman_pcie_gart_disable(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1674 | return 0; |
| 1675 | } |
| 1676 | |
| 1677 | /* Plan is to move initialization in that function and use |
| 1678 | * helper function so that radeon_device_init pretty much |
| 1679 | * do nothing more than calling asic specific function. This |
| 1680 | * should also allow to remove a bunch of callback function |
| 1681 | * like vram_info. |
| 1682 | */ |
| 1683 | int cayman_init(struct radeon_device *rdev) |
| 1684 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1685 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1686 | int r; |
| 1687 | |
| 1688 | /* This don't do much */ |
| 1689 | r = radeon_gem_init(rdev); |
| 1690 | if (r) |
| 1691 | return r; |
| 1692 | /* Read BIOS */ |
| 1693 | if (!radeon_get_bios(rdev)) { |
| 1694 | if (ASIC_IS_AVIVO(rdev)) |
| 1695 | return -EINVAL; |
| 1696 | } |
| 1697 | /* Must be an ATOMBIOS */ |
| 1698 | if (!rdev->is_atom_bios) { |
| 1699 | dev_err(rdev->dev, "Expecting atombios for cayman GPU\n"); |
| 1700 | return -EINVAL; |
| 1701 | } |
| 1702 | r = radeon_atombios_init(rdev); |
| 1703 | if (r) |
| 1704 | return r; |
| 1705 | |
| 1706 | /* Post card if necessary */ |
| 1707 | if (!radeon_card_posted(rdev)) { |
| 1708 | if (!rdev->bios) { |
| 1709 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 1710 | return -EINVAL; |
| 1711 | } |
| 1712 | DRM_INFO("GPU not posted. posting now...\n"); |
| 1713 | atom_asic_init(rdev->mode_info.atom_context); |
| 1714 | } |
| 1715 | /* Initialize scratch registers */ |
| 1716 | r600_scratch_init(rdev); |
| 1717 | /* Initialize surface registers */ |
| 1718 | radeon_surface_init(rdev); |
| 1719 | /* Initialize clocks */ |
| 1720 | radeon_get_clock_info(rdev->ddev); |
| 1721 | /* Fence driver */ |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 1722 | r = radeon_fence_driver_init(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1723 | if (r) |
| 1724 | return r; |
| 1725 | /* initialize memory controller */ |
| 1726 | r = evergreen_mc_init(rdev); |
| 1727 | if (r) |
| 1728 | return r; |
| 1729 | /* Memory manager */ |
| 1730 | r = radeon_bo_init(rdev); |
| 1731 | if (r) |
| 1732 | return r; |
| 1733 | |
| 1734 | r = radeon_irq_kms_init(rdev); |
| 1735 | if (r) |
| 1736 | return r; |
| 1737 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1738 | ring->ring_obj = NULL; |
| 1739 | r600_ring_init(rdev, ring, 1024 * 1024); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1740 | |
| 1741 | rdev->ih.ring_obj = NULL; |
| 1742 | r600_ih_ring_init(rdev, 64 * 1024); |
| 1743 | |
| 1744 | r = r600_pcie_gart_init(rdev); |
| 1745 | if (r) |
| 1746 | return r; |
| 1747 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1748 | r = radeon_ib_pool_init(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1749 | rdev->accel_working = true; |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1750 | if (r) { |
| 1751 | dev_err(rdev->dev, "IB initialization failed (%d).\n", r); |
| 1752 | rdev->accel_working = false; |
| 1753 | } |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1754 | r = radeon_vm_manager_init(rdev); |
| 1755 | if (r) { |
| 1756 | dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r); |
| 1757 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1758 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1759 | r = cayman_startup(rdev); |
| 1760 | if (r) { |
| 1761 | dev_err(rdev->dev, "disabling GPU acceleration\n"); |
| 1762 | cayman_cp_fini(rdev); |
| 1763 | r600_irq_fini(rdev); |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1764 | if (rdev->flags & RADEON_IS_IGP) |
| 1765 | si_rlc_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1766 | radeon_wb_fini(rdev); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1767 | r100_ib_fini(rdev); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1768 | radeon_vm_manager_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1769 | radeon_irq_kms_fini(rdev); |
| 1770 | cayman_pcie_gart_fini(rdev); |
| 1771 | rdev->accel_working = false; |
| 1772 | } |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1773 | |
| 1774 | /* Don't start up if the MC ucode is missing. |
| 1775 | * The default clocks and voltages before the MC ucode |
| 1776 | * is loaded are not suffient for advanced operations. |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1777 | * |
| 1778 | * We can skip this check for TN, because there is no MC |
| 1779 | * ucode. |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1780 | */ |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1781 | if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) { |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1782 | DRM_ERROR("radeon: MC ucode required for NI+.\n"); |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
| 1789 | void cayman_fini(struct radeon_device *rdev) |
| 1790 | { |
Ilija Hadzic | fb3d9e9 | 2011-10-12 23:29:41 -0400 | [diff] [blame] | 1791 | r600_blit_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1792 | cayman_cp_fini(rdev); |
| 1793 | r600_irq_fini(rdev); |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 1794 | if (rdev->flags & RADEON_IS_IGP) |
| 1795 | si_rlc_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1796 | radeon_wb_fini(rdev); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1797 | radeon_vm_manager_fini(rdev); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1798 | r100_ib_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1799 | radeon_irq_kms_fini(rdev); |
| 1800 | cayman_pcie_gart_fini(rdev); |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1801 | r600_vram_scratch_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1802 | radeon_gem_fini(rdev); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 1803 | radeon_semaphore_driver_fini(rdev); |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1804 | radeon_fence_driver_fini(rdev); |
| 1805 | radeon_bo_fini(rdev); |
| 1806 | radeon_atombios_fini(rdev); |
| 1807 | kfree(rdev->bios); |
| 1808 | rdev->bios = NULL; |
| 1809 | } |
| 1810 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1811 | /* |
| 1812 | * vm |
| 1813 | */ |
| 1814 | int cayman_vm_init(struct radeon_device *rdev) |
| 1815 | { |
| 1816 | /* number of VMs */ |
| 1817 | rdev->vm_manager.nvm = 8; |
| 1818 | /* base offset of vram pages */ |
Alex Deucher | e71270f | 2012-03-20 17:18:38 -0400 | [diff] [blame] | 1819 | if (rdev->flags & RADEON_IS_IGP) { |
| 1820 | u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET); |
| 1821 | tmp <<= 22; |
| 1822 | rdev->vm_manager.vram_base_offset = tmp; |
| 1823 | } else |
| 1824 | rdev->vm_manager.vram_base_offset = 0; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 1825 | return 0; |
| 1826 | } |
| 1827 | |
| 1828 | void cayman_vm_fini(struct radeon_device *rdev) |
| 1829 | { |
| 1830 | } |
| 1831 | |
| 1832 | int cayman_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm, int id) |
| 1833 | { |
| 1834 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (id << 2), 0); |
| 1835 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (id << 2), vm->last_pfn); |
| 1836 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (id << 2), vm->pt_gpu_addr >> 12); |
| 1837 | /* flush hdp cache */ |
| 1838 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 1839 | /* bits 0-7 are the VM contexts0-7 */ |
| 1840 | WREG32(VM_INVALIDATE_REQUEST, 1 << id); |
| 1841 | return 0; |
| 1842 | } |
| 1843 | |
| 1844 | void cayman_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm) |
| 1845 | { |
| 1846 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (vm->id << 2), 0); |
| 1847 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (vm->id << 2), 0); |
| 1848 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0); |
| 1849 | /* flush hdp cache */ |
| 1850 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 1851 | /* bits 0-7 are the VM contexts0-7 */ |
| 1852 | WREG32(VM_INVALIDATE_REQUEST, 1 << vm->id); |
| 1853 | } |
| 1854 | |
| 1855 | void cayman_vm_tlb_flush(struct radeon_device *rdev, struct radeon_vm *vm) |
| 1856 | { |
| 1857 | if (vm->id == -1) |
| 1858 | return; |
| 1859 | |
| 1860 | /* flush hdp cache */ |
| 1861 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 1862 | /* bits 0-7 are the VM contexts0-7 */ |
| 1863 | WREG32(VM_INVALIDATE_REQUEST, 1 << vm->id); |
| 1864 | } |
| 1865 | |
| 1866 | #define R600_PTE_VALID (1 << 0) |
| 1867 | #define R600_PTE_SYSTEM (1 << 1) |
| 1868 | #define R600_PTE_SNOOPED (1 << 2) |
| 1869 | #define R600_PTE_READABLE (1 << 5) |
| 1870 | #define R600_PTE_WRITEABLE (1 << 6) |
| 1871 | |
| 1872 | uint32_t cayman_vm_page_flags(struct radeon_device *rdev, |
| 1873 | struct radeon_vm *vm, |
| 1874 | uint32_t flags) |
| 1875 | { |
| 1876 | uint32_t r600_flags = 0; |
| 1877 | |
| 1878 | r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_PTE_VALID : 0; |
| 1879 | r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0; |
| 1880 | r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0; |
| 1881 | if (flags & RADEON_VM_PAGE_SYSTEM) { |
| 1882 | r600_flags |= R600_PTE_SYSTEM; |
| 1883 | r600_flags |= (flags & RADEON_VM_PAGE_SNOOPED) ? R600_PTE_SNOOPED : 0; |
| 1884 | } |
| 1885 | return r600_flags; |
| 1886 | } |
| 1887 | |
| 1888 | void cayman_vm_set_page(struct radeon_device *rdev, struct radeon_vm *vm, |
| 1889 | unsigned pfn, uint64_t addr, uint32_t flags) |
| 1890 | { |
| 1891 | void __iomem *ptr = (void *)vm->pt; |
| 1892 | |
| 1893 | addr = addr & 0xFFFFFFFFFFFFF000ULL; |
| 1894 | addr |= flags; |
| 1895 | writeq(addr, ptr + (pfn * 8)); |
| 1896 | } |