Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 28 | #include <linux/firmware.h> |
| 29 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <drm/drmP.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 32 | #include "radeon.h" |
Daniel Vetter | e699037 | 2010-03-11 21:19:17 +0000 | [diff] [blame] | 33 | #include "radeon_asic.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/radeon_drm.h> |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 35 | #include "rv770d.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 36 | #include "atom.h" |
Jerome Glisse | d39c3b8 | 2009-09-28 18:34:43 +0200 | [diff] [blame] | 37 | #include "avivod.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 38 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 39 | #define R700_PFP_UCODE_SIZE 848 |
| 40 | #define R700_PM4_UCODE_SIZE 1360 |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 41 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 42 | static void rv770_gpu_init(struct radeon_device *rdev); |
| 43 | void rv770_fini(struct radeon_device *rdev); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 44 | static void rv770_pcie_gen2_enable(struct radeon_device *rdev); |
Christian König | ef0e6e6 | 2013-04-08 12:41:35 +0200 | [diff] [blame] | 45 | int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk); |
| 46 | |
| 47 | static int rv770_uvd_calc_post_div(unsigned target_freq, |
| 48 | unsigned vco_freq, |
| 49 | unsigned *div) |
| 50 | { |
| 51 | /* Fclk = Fvco / PDIV */ |
| 52 | *div = vco_freq / target_freq; |
| 53 | |
| 54 | /* we alway need a frequency less than or equal the target */ |
| 55 | if ((vco_freq / *div) > target_freq) |
| 56 | *div += 1; |
| 57 | |
| 58 | /* out of range ? */ |
| 59 | if (*div > 30) |
| 60 | return -1; /* forget it */ |
| 61 | |
| 62 | *div -= 1; |
| 63 | return vco_freq / (*div + 1); |
| 64 | } |
| 65 | |
| 66 | static int rv770_uvd_send_upll_ctlreq(struct radeon_device *rdev) |
| 67 | { |
| 68 | unsigned i; |
| 69 | |
| 70 | /* assert UPLL_CTLREQ */ |
| 71 | WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_CTLREQ_MASK, ~UPLL_CTLREQ_MASK); |
| 72 | |
| 73 | /* wait for CTLACK and CTLACK2 to get asserted */ |
| 74 | for (i = 0; i < 100; ++i) { |
| 75 | uint32_t mask = UPLL_CTLACK_MASK | UPLL_CTLACK2_MASK; |
| 76 | if ((RREG32(CG_UPLL_FUNC_CNTL) & mask) == mask) |
| 77 | break; |
| 78 | mdelay(10); |
| 79 | } |
| 80 | if (i == 100) |
| 81 | return -ETIMEDOUT; |
| 82 | |
| 83 | /* deassert UPLL_CTLREQ */ |
| 84 | WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_CTLREQ_MASK); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int rv770_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk) |
| 90 | { |
| 91 | /* start off with something large */ |
| 92 | int optimal_diff_score = 0x7FFFFFF; |
| 93 | unsigned optimal_fb_div = 0, optimal_vclk_div = 0; |
| 94 | unsigned optimal_dclk_div = 0, optimal_vco_freq = 0; |
| 95 | unsigned vco_freq, vco_min = 50000, vco_max = 160000; |
| 96 | unsigned ref_freq = rdev->clock.spll.reference_freq; |
| 97 | int r; |
| 98 | |
| 99 | /* RV740 uses evergreen uvd clk programming */ |
| 100 | if (rdev->family == CHIP_RV740) |
| 101 | return evergreen_set_uvd_clocks(rdev, vclk, dclk); |
| 102 | |
| 103 | /* loop through vco from low to high */ |
| 104 | vco_min = max(max(vco_min, vclk), dclk); |
| 105 | for (vco_freq = vco_min; vco_freq <= vco_max; vco_freq += 500) { |
| 106 | uint64_t fb_div = (uint64_t)vco_freq * 43663; |
| 107 | int calc_clk, diff_score, diff_vclk, diff_dclk; |
| 108 | unsigned vclk_div, dclk_div; |
| 109 | |
| 110 | do_div(fb_div, ref_freq); |
| 111 | fb_div |= 1; |
| 112 | |
| 113 | /* fb div out of range ? */ |
| 114 | if (fb_div > 0x03FFFFFF) |
| 115 | break; /* it can oly get worse */ |
| 116 | |
| 117 | /* calc vclk with current vco freq. */ |
| 118 | calc_clk = rv770_uvd_calc_post_div(vclk, vco_freq, &vclk_div); |
| 119 | if (calc_clk == -1) |
| 120 | break; /* vco is too big, it has to stop. */ |
| 121 | diff_vclk = vclk - calc_clk; |
| 122 | |
| 123 | /* calc dclk with current vco freq. */ |
| 124 | calc_clk = rv770_uvd_calc_post_div(dclk, vco_freq, &dclk_div); |
| 125 | if (calc_clk == -1) |
| 126 | break; /* vco is too big, it has to stop. */ |
| 127 | diff_dclk = dclk - calc_clk; |
| 128 | |
| 129 | /* determine if this vco setting is better than current optimal settings */ |
| 130 | diff_score = abs(diff_vclk) + abs(diff_dclk); |
| 131 | if (diff_score < optimal_diff_score) { |
| 132 | optimal_fb_div = fb_div; |
| 133 | optimal_vclk_div = vclk_div; |
| 134 | optimal_dclk_div = dclk_div; |
| 135 | optimal_vco_freq = vco_freq; |
| 136 | optimal_diff_score = diff_score; |
| 137 | if (optimal_diff_score == 0) |
| 138 | break; /* it can't get better than this */ |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* bypass vclk and dclk with bclk */ |
| 143 | WREG32_P(CG_UPLL_FUNC_CNTL_2, |
| 144 | VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1), |
| 145 | ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK)); |
| 146 | |
| 147 | /* set UPLL_FB_DIV to 0x50000 */ |
| 148 | WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(0x50000), ~UPLL_FB_DIV_MASK); |
| 149 | |
| 150 | /* deassert UPLL_RESET */ |
| 151 | WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK); |
| 152 | |
| 153 | /* assert BYPASS EN and FB_DIV[0] <- ??? why? */ |
| 154 | WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK); |
| 155 | WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(1), ~UPLL_FB_DIV(1)); |
| 156 | |
| 157 | r = rv770_uvd_send_upll_ctlreq(rdev); |
| 158 | if (r) |
| 159 | return r; |
| 160 | |
| 161 | /* assert PLL_RESET */ |
| 162 | WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK); |
| 163 | |
| 164 | /* set the required FB_DIV, REF_DIV, Post divder values */ |
| 165 | WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_REF_DIV(1), ~UPLL_REF_DIV_MASK); |
| 166 | WREG32_P(CG_UPLL_FUNC_CNTL_2, |
| 167 | UPLL_SW_HILEN(optimal_vclk_div >> 1) | |
| 168 | UPLL_SW_LOLEN((optimal_vclk_div >> 1) + (optimal_vclk_div & 1)) | |
| 169 | UPLL_SW_HILEN2(optimal_dclk_div >> 1) | |
| 170 | UPLL_SW_LOLEN2((optimal_dclk_div >> 1) + (optimal_dclk_div & 1)), |
| 171 | ~UPLL_SW_MASK); |
| 172 | |
| 173 | WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(optimal_fb_div), |
| 174 | ~UPLL_FB_DIV_MASK); |
| 175 | |
| 176 | /* give the PLL some time to settle */ |
| 177 | mdelay(15); |
| 178 | |
| 179 | /* deassert PLL_RESET */ |
| 180 | WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK); |
| 181 | |
| 182 | mdelay(15); |
| 183 | |
| 184 | /* deassert BYPASS EN and FB_DIV[0] <- ??? why? */ |
| 185 | WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK); |
| 186 | WREG32_P(CG_UPLL_FUNC_CNTL_3, 0, ~UPLL_FB_DIV(1)); |
| 187 | |
| 188 | r = rv770_uvd_send_upll_ctlreq(rdev); |
| 189 | if (r) |
| 190 | return r; |
| 191 | |
| 192 | /* switch VCLK and DCLK selection */ |
| 193 | WREG32_P(CG_UPLL_FUNC_CNTL_2, |
| 194 | VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2), |
| 195 | ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK)); |
| 196 | |
| 197 | mdelay(100); |
| 198 | |
| 199 | return 0; |
| 200 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 201 | |
Alex Deucher | 454d2e2 | 2013-02-14 10:04:02 -0500 | [diff] [blame] | 202 | #define PCIE_BUS_CLK 10000 |
| 203 | #define TCLK (PCIE_BUS_CLK / 10) |
| 204 | |
| 205 | /** |
| 206 | * rv770_get_xclk - get the xclk |
| 207 | * |
| 208 | * @rdev: radeon_device pointer |
| 209 | * |
| 210 | * Returns the reference clock used by the gfx engine |
| 211 | * (r7xx-cayman). |
| 212 | */ |
| 213 | u32 rv770_get_xclk(struct radeon_device *rdev) |
| 214 | { |
| 215 | u32 reference_clock = rdev->clock.spll.reference_freq; |
| 216 | u32 tmp = RREG32(CG_CLKPIN_CNTL); |
| 217 | |
| 218 | if (tmp & MUX_TCLK_TO_XCLK) |
| 219 | return TCLK; |
| 220 | |
| 221 | if (tmp & XTALIN_DIVIDE) |
| 222 | return reference_clock / 4; |
| 223 | |
| 224 | return reference_clock; |
| 225 | } |
| 226 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 227 | int rv770_uvd_resume(struct radeon_device *rdev) |
| 228 | { |
| 229 | uint64_t addr; |
| 230 | uint32_t chip_id, size; |
| 231 | int r; |
| 232 | |
| 233 | r = radeon_uvd_resume(rdev); |
| 234 | if (r) |
| 235 | return r; |
| 236 | |
| 237 | /* programm the VCPU memory controller bits 0-27 */ |
| 238 | addr = rdev->uvd.gpu_addr >> 3; |
| 239 | size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) >> 3; |
| 240 | WREG32(UVD_VCPU_CACHE_OFFSET0, addr); |
| 241 | WREG32(UVD_VCPU_CACHE_SIZE0, size); |
| 242 | |
| 243 | addr += size; |
| 244 | size = RADEON_UVD_STACK_SIZE >> 3; |
| 245 | WREG32(UVD_VCPU_CACHE_OFFSET1, addr); |
| 246 | WREG32(UVD_VCPU_CACHE_SIZE1, size); |
| 247 | |
| 248 | addr += size; |
| 249 | size = RADEON_UVD_HEAP_SIZE >> 3; |
| 250 | WREG32(UVD_VCPU_CACHE_OFFSET2, addr); |
| 251 | WREG32(UVD_VCPU_CACHE_SIZE2, size); |
| 252 | |
| 253 | /* bits 28-31 */ |
| 254 | addr = (rdev->uvd.gpu_addr >> 28) & 0xF; |
| 255 | WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0)); |
| 256 | |
| 257 | /* bits 32-39 */ |
| 258 | addr = (rdev->uvd.gpu_addr >> 32) & 0xFF; |
| 259 | WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31)); |
| 260 | |
| 261 | /* tell firmware which hardware it is running on */ |
| 262 | switch (rdev->family) { |
| 263 | default: |
| 264 | return -EINVAL; |
| 265 | case CHIP_RV710: |
| 266 | chip_id = 0x01000005; |
| 267 | break; |
| 268 | case CHIP_RV730: |
| 269 | chip_id = 0x01000006; |
| 270 | break; |
| 271 | case CHIP_RV740: |
| 272 | chip_id = 0x01000007; |
| 273 | break; |
| 274 | case CHIP_CYPRESS: |
| 275 | case CHIP_HEMLOCK: |
| 276 | chip_id = 0x01000008; |
| 277 | break; |
| 278 | case CHIP_JUNIPER: |
| 279 | chip_id = 0x01000009; |
| 280 | break; |
| 281 | case CHIP_REDWOOD: |
| 282 | chip_id = 0x0100000a; |
| 283 | break; |
| 284 | case CHIP_CEDAR: |
| 285 | chip_id = 0x0100000b; |
| 286 | break; |
| 287 | case CHIP_SUMO: |
| 288 | chip_id = 0x0100000c; |
| 289 | break; |
| 290 | case CHIP_SUMO2: |
| 291 | chip_id = 0x0100000d; |
| 292 | break; |
| 293 | case CHIP_PALM: |
| 294 | chip_id = 0x0100000e; |
| 295 | break; |
| 296 | case CHIP_CAYMAN: |
| 297 | chip_id = 0x0100000f; |
| 298 | break; |
| 299 | case CHIP_BARTS: |
| 300 | chip_id = 0x01000010; |
| 301 | break; |
| 302 | case CHIP_TURKS: |
| 303 | chip_id = 0x01000011; |
| 304 | break; |
| 305 | case CHIP_CAICOS: |
| 306 | chip_id = 0x01000012; |
| 307 | break; |
| 308 | case CHIP_TAHITI: |
| 309 | chip_id = 0x01000014; |
| 310 | break; |
| 311 | case CHIP_VERDE: |
| 312 | chip_id = 0x01000015; |
| 313 | break; |
| 314 | case CHIP_PITCAIRN: |
| 315 | chip_id = 0x01000016; |
| 316 | break; |
| 317 | case CHIP_ARUBA: |
| 318 | chip_id = 0x01000017; |
| 319 | break; |
| 320 | } |
| 321 | WREG32(UVD_VCPU_CHIP_ID, chip_id); |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 326 | u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base) |
| 327 | { |
| 328 | struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; |
| 329 | u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset); |
Alex Deucher | f649647 | 2011-11-28 14:49:26 -0500 | [diff] [blame] | 330 | int i; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 331 | |
| 332 | /* Lock the graphics update lock */ |
| 333 | tmp |= AVIVO_D1GRPH_UPDATE_LOCK; |
| 334 | WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp); |
| 335 | |
| 336 | /* update the scanout addresses */ |
| 337 | if (radeon_crtc->crtc_id) { |
| 338 | WREG32(D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base)); |
| 339 | WREG32(D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base)); |
| 340 | } else { |
| 341 | WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base)); |
| 342 | WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base)); |
| 343 | } |
| 344 | WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 345 | (u32)crtc_base); |
| 346 | WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 347 | (u32)crtc_base); |
| 348 | |
| 349 | /* Wait for update_pending to go high. */ |
Alex Deucher | f649647 | 2011-11-28 14:49:26 -0500 | [diff] [blame] | 350 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 351 | if (RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING) |
| 352 | break; |
| 353 | udelay(1); |
| 354 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 355 | DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); |
| 356 | |
| 357 | /* Unlock the lock, so double-buffering can take place inside vblank */ |
| 358 | tmp &= ~AVIVO_D1GRPH_UPDATE_LOCK; |
| 359 | WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp); |
| 360 | |
| 361 | /* Return current update_pending status: */ |
| 362 | return RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING; |
| 363 | } |
| 364 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 365 | /* get temperature in millidegrees */ |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 366 | int rv770_get_temp(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 367 | { |
| 368 | u32 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >> |
| 369 | ASIC_T_SHIFT; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 370 | int actual_temp; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 371 | |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 372 | if (temp & 0x400) |
| 373 | actual_temp = -256; |
| 374 | else if (temp & 0x200) |
| 375 | actual_temp = 255; |
| 376 | else if (temp & 0x100) { |
| 377 | actual_temp = temp & 0x1ff; |
| 378 | actual_temp |= ~0x1ff; |
| 379 | } else |
| 380 | actual_temp = temp & 0xff; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 381 | |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 382 | return (actual_temp * 1000) / 2; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 385 | void rv770_pm_misc(struct radeon_device *rdev) |
| 386 | { |
Rafał Miłecki | a081a9d | 2010-06-07 18:20:25 -0400 | [diff] [blame] | 387 | int req_ps_idx = rdev->pm.requested_power_state_index; |
| 388 | int req_cm_idx = rdev->pm.requested_clock_mode_index; |
| 389 | struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx]; |
| 390 | struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage; |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 391 | |
| 392 | if ((voltage->type == VOLTAGE_SW) && voltage->voltage) { |
Alex Deucher | a377e18 | 2011-06-20 13:00:31 -0400 | [diff] [blame] | 393 | /* 0xff01 is a flag rather then an actual voltage */ |
| 394 | if (voltage->voltage == 0xff01) |
| 395 | return; |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 396 | if (voltage->voltage != rdev->pm.current_vddc) { |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 397 | radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 398 | rdev->pm.current_vddc = voltage->voltage; |
Rafał Miłecki | 0fcbe94 | 2010-06-07 18:25:21 -0400 | [diff] [blame] | 399 | DRM_DEBUG("Setting: v: %d\n", voltage->voltage); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 400 | } |
| 401 | } |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 402 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * GART |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 406 | */ |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 407 | static int rv770_pcie_gart_enable(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 408 | { |
| 409 | u32 tmp; |
| 410 | int r, i; |
| 411 | |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 412 | if (rdev->gart.robj == NULL) { |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 413 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 414 | return -EINVAL; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 415 | } |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 416 | r = radeon_gart_table_vram_pin(rdev); |
| 417 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 418 | return r; |
Dave Airlie | 8256856 | 2010-02-05 16:00:07 +1000 | [diff] [blame] | 419 | radeon_gart_restore(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 420 | /* Setup L2 cache */ |
| 421 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 422 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 423 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 424 | WREG32(VM_L2_CNTL2, 0); |
| 425 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 426 | /* Setup TLB control */ |
| 427 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 428 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 429 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | |
| 430 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
| 431 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 432 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 433 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
Alex Deucher | 0b8c30b | 2012-05-31 18:54:43 -0400 | [diff] [blame] | 434 | if (rdev->family == CHIP_RV740) |
| 435 | WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 436 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 437 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 438 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 439 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
| 440 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 441 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 442 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); |
| 443 | WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 444 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
| 445 | WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, |
| 446 | (u32)(rdev->dummy_page.addr >> 12)); |
| 447 | for (i = 1; i < 7; i++) |
| 448 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 449 | |
| 450 | r600_pcie_gart_tlb_flush(rdev); |
Tormod Volden | fcf4de5 | 2011-08-31 21:54:07 +0000 | [diff] [blame] | 451 | DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n", |
| 452 | (unsigned)(rdev->mc.gtt_size >> 20), |
| 453 | (unsigned long long)rdev->gart.table_addr); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 454 | rdev->gart.ready = true; |
| 455 | return 0; |
| 456 | } |
| 457 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 458 | static void rv770_pcie_gart_disable(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 459 | { |
| 460 | u32 tmp; |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 461 | int i; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 462 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 463 | /* Disable all tables */ |
| 464 | for (i = 0; i < 7; i++) |
| 465 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 466 | |
| 467 | /* Setup L2 cache */ |
| 468 | WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING | |
| 469 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 470 | WREG32(VM_L2_CNTL2, 0); |
| 471 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 472 | /* Setup TLB control */ |
| 473 | tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
| 474 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 475 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 476 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
| 477 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 478 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 479 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 480 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 481 | radeon_gart_table_vram_unpin(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 484 | static void rv770_pcie_gart_fini(struct radeon_device *rdev) |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 485 | { |
Jerome Glisse | f927456 | 2010-03-17 14:44:29 +0000 | [diff] [blame] | 486 | radeon_gart_fini(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 487 | rv770_pcie_gart_disable(rdev); |
| 488 | radeon_gart_table_vram_free(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 489 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 490 | |
| 491 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 492 | static void rv770_agp_enable(struct radeon_device *rdev) |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 493 | { |
| 494 | u32 tmp; |
| 495 | int i; |
| 496 | |
| 497 | /* Setup L2 cache */ |
| 498 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 499 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 500 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 501 | WREG32(VM_L2_CNTL2, 0); |
| 502 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 503 | /* Setup TLB control */ |
| 504 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 505 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 506 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | |
| 507 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
| 508 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 509 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 510 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
| 511 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 512 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 513 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 514 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
| 515 | for (i = 0; i < 7; i++) |
| 516 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 517 | } |
| 518 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 519 | static void rv770_mc_program(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 520 | { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 521 | struct rv515_mc_save save; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 522 | u32 tmp; |
| 523 | int i, j; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 524 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 525 | /* Initialize HDP */ |
| 526 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 527 | WREG32((0x2c14 + j), 0x00000000); |
| 528 | WREG32((0x2c18 + j), 0x00000000); |
| 529 | WREG32((0x2c1c + j), 0x00000000); |
| 530 | WREG32((0x2c20 + j), 0x00000000); |
| 531 | WREG32((0x2c24 + j), 0x00000000); |
| 532 | } |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 533 | /* r7xx hw bug. Read from HDP_DEBUG1 rather |
| 534 | * than writing to HDP_REG_COHERENCY_FLUSH_CNTL |
| 535 | */ |
| 536 | tmp = RREG32(HDP_DEBUG1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 537 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 538 | rv515_mc_stop(rdev, &save); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 539 | if (r600_mc_wait_for_idle(rdev)) { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 540 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 541 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 542 | /* Lockout access through VGA aperture*/ |
| 543 | WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 544 | /* Update configuration */ |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 545 | if (rdev->flags & RADEON_IS_AGP) { |
| 546 | if (rdev->mc.vram_start < rdev->mc.gtt_start) { |
| 547 | /* VRAM before AGP */ |
| 548 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 549 | rdev->mc.vram_start >> 12); |
| 550 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 551 | rdev->mc.gtt_end >> 12); |
| 552 | } else { |
| 553 | /* VRAM after AGP */ |
| 554 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 555 | rdev->mc.gtt_start >> 12); |
| 556 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 557 | rdev->mc.vram_end >> 12); |
| 558 | } |
| 559 | } else { |
| 560 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 561 | rdev->mc.vram_start >> 12); |
| 562 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 563 | rdev->mc.vram_end >> 12); |
| 564 | } |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 565 | WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 566 | tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 567 | tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); |
| 568 | WREG32(MC_VM_FB_LOCATION, tmp); |
| 569 | WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8)); |
| 570 | WREG32(HDP_NONSURFACE_INFO, (2 << 7)); |
Jerome Glisse | 46fcd2b | 2010-06-03 19:34:48 +0200 | [diff] [blame] | 571 | WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 572 | if (rdev->flags & RADEON_IS_AGP) { |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 573 | WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 574 | WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16); |
| 575 | WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22); |
| 576 | } else { |
| 577 | WREG32(MC_VM_AGP_BASE, 0); |
| 578 | WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF); |
| 579 | WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF); |
| 580 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 581 | if (r600_mc_wait_for_idle(rdev)) { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 582 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 583 | } |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 584 | rv515_mc_resume(rdev, &save); |
Dave Airlie | 698443d | 2009-09-18 14:16:38 +1000 | [diff] [blame] | 585 | /* we need to own VRAM, so turn off the VGA renderer here |
| 586 | * to stop it overwriting our objects */ |
Jerome Glisse | d39c3b8 | 2009-09-28 18:34:43 +0200 | [diff] [blame] | 587 | rv515_vga_render_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
| 591 | /* |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 592 | * CP. |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 593 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 594 | void r700_cp_stop(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 595 | { |
Dave Airlie | 5359533 | 2011-03-14 09:47:24 +1000 | [diff] [blame] | 596 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 597 | WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT)); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 598 | WREG32(SCRATCH_UMSK, 0); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 599 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 602 | static int rv770_cp_load_microcode(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 603 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 604 | const __be32 *fw_data; |
| 605 | int i; |
| 606 | |
| 607 | if (!rdev->me_fw || !rdev->pfp_fw) |
| 608 | return -EINVAL; |
| 609 | |
| 610 | r700_cp_stop(rdev); |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 611 | WREG32(CP_RB_CNTL, |
| 612 | #ifdef __BIG_ENDIAN |
| 613 | BUF_SWAP_32BIT | |
| 614 | #endif |
| 615 | RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 616 | |
| 617 | /* Reset cp */ |
| 618 | WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP); |
| 619 | RREG32(GRBM_SOFT_RESET); |
| 620 | mdelay(15); |
| 621 | WREG32(GRBM_SOFT_RESET, 0); |
| 622 | |
| 623 | fw_data = (const __be32 *)rdev->pfp_fw->data; |
| 624 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 625 | for (i = 0; i < R700_PFP_UCODE_SIZE; i++) |
| 626 | WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 627 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 628 | |
| 629 | fw_data = (const __be32 *)rdev->me_fw->data; |
| 630 | WREG32(CP_ME_RAM_WADDR, 0); |
| 631 | for (i = 0; i < R700_PM4_UCODE_SIZE; i++) |
| 632 | WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++)); |
| 633 | |
| 634 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 635 | WREG32(CP_ME_RAM_WADDR, 0); |
| 636 | WREG32(CP_ME_RAM_RADDR, 0); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 637 | return 0; |
| 638 | } |
| 639 | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 640 | void r700_cp_fini(struct radeon_device *rdev) |
| 641 | { |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 642 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 643 | r700_cp_stop(rdev); |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 644 | radeon_ring_fini(rdev, ring); |
| 645 | radeon_scratch_free(rdev, ring->rptr_save_reg); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 646 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 647 | |
| 648 | /* |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 649 | * Core functions |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 650 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 651 | static void rv770_gpu_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 652 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 653 | int i, j, num_qd_pipes; |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 654 | u32 ta_aux_cntl; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 655 | u32 sx_debug_1; |
| 656 | u32 smx_dc_ctl0; |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 657 | u32 db_debug3; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 658 | u32 num_gs_verts_per_thread; |
| 659 | u32 vgt_gs_per_es; |
| 660 | u32 gs_prim_buffer_depth = 0; |
| 661 | u32 sq_ms_fifo_sizes; |
| 662 | u32 sq_config; |
| 663 | u32 sq_thread_resource_mgmt; |
| 664 | u32 hdp_host_path_cntl; |
| 665 | u32 sq_dyn_gpr_size_simd_ab_0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 666 | u32 gb_tiling_config = 0; |
| 667 | u32 cc_rb_backend_disable = 0; |
| 668 | u32 cc_gc_shader_pipe_config = 0; |
| 669 | u32 mc_arb_ramcfg; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 670 | u32 db_debug4, tmp; |
| 671 | u32 inactive_pipes, shader_pipe_config; |
| 672 | u32 disabled_rb_mask; |
| 673 | unsigned active_number; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 674 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 675 | /* setup chip specs */ |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 676 | rdev->config.rv770.tiling_group_size = 256; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 677 | switch (rdev->family) { |
| 678 | case CHIP_RV770: |
| 679 | rdev->config.rv770.max_pipes = 4; |
| 680 | rdev->config.rv770.max_tile_pipes = 8; |
| 681 | rdev->config.rv770.max_simds = 10; |
| 682 | rdev->config.rv770.max_backends = 4; |
| 683 | rdev->config.rv770.max_gprs = 256; |
| 684 | rdev->config.rv770.max_threads = 248; |
| 685 | rdev->config.rv770.max_stack_entries = 512; |
| 686 | rdev->config.rv770.max_hw_contexts = 8; |
| 687 | rdev->config.rv770.max_gs_threads = 16 * 2; |
| 688 | rdev->config.rv770.sx_max_export_size = 128; |
| 689 | rdev->config.rv770.sx_max_export_pos_size = 16; |
| 690 | rdev->config.rv770.sx_max_export_smx_size = 112; |
| 691 | rdev->config.rv770.sq_num_cf_insts = 2; |
| 692 | |
| 693 | rdev->config.rv770.sx_num_of_sets = 7; |
| 694 | rdev->config.rv770.sc_prim_fifo_size = 0xF9; |
| 695 | rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30; |
| 696 | rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130; |
| 697 | break; |
| 698 | case CHIP_RV730: |
| 699 | rdev->config.rv770.max_pipes = 2; |
| 700 | rdev->config.rv770.max_tile_pipes = 4; |
| 701 | rdev->config.rv770.max_simds = 8; |
| 702 | rdev->config.rv770.max_backends = 2; |
| 703 | rdev->config.rv770.max_gprs = 128; |
| 704 | rdev->config.rv770.max_threads = 248; |
| 705 | rdev->config.rv770.max_stack_entries = 256; |
| 706 | rdev->config.rv770.max_hw_contexts = 8; |
| 707 | rdev->config.rv770.max_gs_threads = 16 * 2; |
| 708 | rdev->config.rv770.sx_max_export_size = 256; |
| 709 | rdev->config.rv770.sx_max_export_pos_size = 32; |
| 710 | rdev->config.rv770.sx_max_export_smx_size = 224; |
| 711 | rdev->config.rv770.sq_num_cf_insts = 2; |
| 712 | |
| 713 | rdev->config.rv770.sx_num_of_sets = 7; |
| 714 | rdev->config.rv770.sc_prim_fifo_size = 0xf9; |
| 715 | rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30; |
| 716 | rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130; |
| 717 | if (rdev->config.rv770.sx_max_export_pos_size > 16) { |
| 718 | rdev->config.rv770.sx_max_export_pos_size -= 16; |
| 719 | rdev->config.rv770.sx_max_export_smx_size += 16; |
| 720 | } |
| 721 | break; |
| 722 | case CHIP_RV710: |
| 723 | rdev->config.rv770.max_pipes = 2; |
| 724 | rdev->config.rv770.max_tile_pipes = 2; |
| 725 | rdev->config.rv770.max_simds = 2; |
| 726 | rdev->config.rv770.max_backends = 1; |
| 727 | rdev->config.rv770.max_gprs = 256; |
| 728 | rdev->config.rv770.max_threads = 192; |
| 729 | rdev->config.rv770.max_stack_entries = 256; |
| 730 | rdev->config.rv770.max_hw_contexts = 4; |
| 731 | rdev->config.rv770.max_gs_threads = 8 * 2; |
| 732 | rdev->config.rv770.sx_max_export_size = 128; |
| 733 | rdev->config.rv770.sx_max_export_pos_size = 16; |
| 734 | rdev->config.rv770.sx_max_export_smx_size = 112; |
| 735 | rdev->config.rv770.sq_num_cf_insts = 1; |
| 736 | |
| 737 | rdev->config.rv770.sx_num_of_sets = 7; |
| 738 | rdev->config.rv770.sc_prim_fifo_size = 0x40; |
| 739 | rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30; |
| 740 | rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130; |
| 741 | break; |
| 742 | case CHIP_RV740: |
| 743 | rdev->config.rv770.max_pipes = 4; |
| 744 | rdev->config.rv770.max_tile_pipes = 4; |
| 745 | rdev->config.rv770.max_simds = 8; |
| 746 | rdev->config.rv770.max_backends = 4; |
| 747 | rdev->config.rv770.max_gprs = 256; |
| 748 | rdev->config.rv770.max_threads = 248; |
| 749 | rdev->config.rv770.max_stack_entries = 512; |
| 750 | rdev->config.rv770.max_hw_contexts = 8; |
| 751 | rdev->config.rv770.max_gs_threads = 16 * 2; |
| 752 | rdev->config.rv770.sx_max_export_size = 256; |
| 753 | rdev->config.rv770.sx_max_export_pos_size = 32; |
| 754 | rdev->config.rv770.sx_max_export_smx_size = 224; |
| 755 | rdev->config.rv770.sq_num_cf_insts = 2; |
| 756 | |
| 757 | rdev->config.rv770.sx_num_of_sets = 7; |
| 758 | rdev->config.rv770.sc_prim_fifo_size = 0x100; |
| 759 | rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30; |
| 760 | rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130; |
| 761 | |
| 762 | if (rdev->config.rv770.sx_max_export_pos_size > 16) { |
| 763 | rdev->config.rv770.sx_max_export_pos_size -= 16; |
| 764 | rdev->config.rv770.sx_max_export_smx_size += 16; |
| 765 | } |
| 766 | break; |
| 767 | default: |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | /* Initialize HDP */ |
| 772 | j = 0; |
| 773 | for (i = 0; i < 32; i++) { |
| 774 | WREG32((0x2c14 + j), 0x00000000); |
| 775 | WREG32((0x2c18 + j), 0x00000000); |
| 776 | WREG32((0x2c1c + j), 0x00000000); |
| 777 | WREG32((0x2c20 + j), 0x00000000); |
| 778 | WREG32((0x2c24 + j), 0x00000000); |
| 779 | j += 0x18; |
| 780 | } |
| 781 | |
| 782 | WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff)); |
| 783 | |
| 784 | /* setup tiling, simd, pipe config */ |
| 785 | mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); |
| 786 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 787 | shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG); |
| 788 | inactive_pipes = (shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT; |
| 789 | for (i = 0, tmp = 1, active_number = 0; i < R7XX_MAX_PIPES; i++) { |
| 790 | if (!(inactive_pipes & tmp)) { |
| 791 | active_number++; |
| 792 | } |
| 793 | tmp <<= 1; |
| 794 | } |
| 795 | if (active_number == 1) { |
| 796 | WREG32(SPI_CONFIG_CNTL, DISABLE_INTERP_1); |
| 797 | } else { |
| 798 | WREG32(SPI_CONFIG_CNTL, 0); |
| 799 | } |
| 800 | |
| 801 | cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000; |
| 802 | tmp = R7XX_MAX_BACKENDS - r600_count_pipe_bits(cc_rb_backend_disable >> 16); |
| 803 | if (tmp < rdev->config.rv770.max_backends) { |
| 804 | rdev->config.rv770.max_backends = tmp; |
| 805 | } |
| 806 | |
| 807 | cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00; |
| 808 | tmp = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R7XX_MAX_PIPES_MASK); |
| 809 | if (tmp < rdev->config.rv770.max_pipes) { |
| 810 | rdev->config.rv770.max_pipes = tmp; |
| 811 | } |
| 812 | tmp = R7XX_MAX_SIMDS - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R7XX_MAX_SIMDS_MASK); |
| 813 | if (tmp < rdev->config.rv770.max_simds) { |
| 814 | rdev->config.rv770.max_simds = tmp; |
| 815 | } |
| 816 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 817 | switch (rdev->config.rv770.max_tile_pipes) { |
| 818 | case 1: |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 819 | default: |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 820 | gb_tiling_config = PIPE_TILING(0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 821 | break; |
| 822 | case 2: |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 823 | gb_tiling_config = PIPE_TILING(1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 824 | break; |
| 825 | case 4: |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 826 | gb_tiling_config = PIPE_TILING(2); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 827 | break; |
| 828 | case 8: |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 829 | gb_tiling_config = PIPE_TILING(3); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 830 | break; |
| 831 | } |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 832 | rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 833 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 834 | disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R7XX_MAX_BACKENDS_MASK; |
| 835 | tmp = (gb_tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT; |
| 836 | tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.rv770.max_backends, |
| 837 | R7XX_MAX_BACKENDS, disabled_rb_mask); |
| 838 | gb_tiling_config |= tmp << 16; |
| 839 | rdev->config.rv770.backend_map = tmp; |
| 840 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 841 | if (rdev->family == CHIP_RV770) |
| 842 | gb_tiling_config |= BANK_TILING(1); |
Alex Deucher | 29d6540 | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 843 | else { |
| 844 | if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) |
| 845 | gb_tiling_config |= BANK_TILING(1); |
| 846 | else |
| 847 | gb_tiling_config |= BANK_TILING(0); |
| 848 | } |
Jerome Glisse | 961fb59 | 2010-02-10 22:30:05 +0000 | [diff] [blame] | 849 | rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3); |
Alex Deucher | 881fe6c | 2010-10-18 23:54:56 -0400 | [diff] [blame] | 850 | gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT); |
Alex Deucher | e29649d | 2009-11-03 10:04:01 -0500 | [diff] [blame] | 851 | if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 852 | gb_tiling_config |= ROW_TILING(3); |
| 853 | gb_tiling_config |= SAMPLE_SPLIT(3); |
| 854 | } else { |
| 855 | gb_tiling_config |= |
| 856 | ROW_TILING(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT)); |
| 857 | gb_tiling_config |= |
| 858 | SAMPLE_SPLIT(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT)); |
| 859 | } |
| 860 | |
| 861 | gb_tiling_config |= BANK_SWAPS(1); |
Alex Deucher | e7aeeba | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 862 | rdev->config.rv770.tile_config = gb_tiling_config; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 863 | |
| 864 | WREG32(GB_TILING_CONFIG, gb_tiling_config); |
| 865 | WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
| 866 | WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 867 | WREG32(DMA_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
| 868 | WREG32(DMA_TILING_CONFIG2, (gb_tiling_config & 0xffff)); |
Christian König | 9a21059 | 2013-04-08 12:41:37 +0200 | [diff] [blame^] | 869 | if (rdev->family == CHIP_RV730) { |
| 870 | WREG32(UVD_UDEC_DB_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
| 871 | WREG32(UVD_UDEC_DBW_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
| 872 | WREG32(UVD_UDEC_TILING_CONFIG, (gb_tiling_config & 0xffff)); |
| 873 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 874 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 875 | WREG32(CGTS_SYS_TCC_DISABLE, 0); |
| 876 | WREG32(CGTS_TCC_DISABLE, 0); |
Alex Deucher | f867c60d | 2010-03-05 14:50:37 -0500 | [diff] [blame] | 877 | WREG32(CGTS_USER_SYS_TCC_DISABLE, 0); |
| 878 | WREG32(CGTS_USER_TCC_DISABLE, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 879 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 880 | |
| 881 | num_qd_pipes = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 882 | WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK); |
| 883 | WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK); |
| 884 | |
| 885 | /* set HW defaults for 3D engine */ |
| 886 | WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | |
Alex Deucher | e29649d | 2009-11-03 10:04:01 -0500 | [diff] [blame] | 887 | ROQ_IB2_START(0x2b))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 888 | |
| 889 | WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30)); |
| 890 | |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 891 | ta_aux_cntl = RREG32(TA_CNTL_AUX); |
| 892 | WREG32(TA_CNTL_AUX, ta_aux_cntl | DISABLE_CUBE_ANISO); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 893 | |
| 894 | sx_debug_1 = RREG32(SX_DEBUG_1); |
| 895 | sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS; |
| 896 | WREG32(SX_DEBUG_1, sx_debug_1); |
| 897 | |
| 898 | smx_dc_ctl0 = RREG32(SMX_DC_CTL0); |
| 899 | smx_dc_ctl0 &= ~CACHE_DEPTH(0x1ff); |
| 900 | smx_dc_ctl0 |= CACHE_DEPTH((rdev->config.rv770.sx_num_of_sets * 64) - 1); |
| 901 | WREG32(SMX_DC_CTL0, smx_dc_ctl0); |
| 902 | |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 903 | if (rdev->family != CHIP_RV740) |
| 904 | WREG32(SMX_EVENT_CTL, (ES_FLUSH_CTL(4) | |
| 905 | GS_FLUSH_CTL(4) | |
| 906 | ACK_FLUSH_CTL(3) | |
| 907 | SYNC_FLUSH_CTL)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 908 | |
Alex Deucher | b866d13 | 2012-06-14 22:06:36 +0200 | [diff] [blame] | 909 | if (rdev->family != CHIP_RV770) |
| 910 | WREG32(SMX_SAR_CTL0, 0x00003f3f); |
| 911 | |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 912 | db_debug3 = RREG32(DB_DEBUG3); |
| 913 | db_debug3 &= ~DB_CLK_OFF_DELAY(0x1f); |
| 914 | switch (rdev->family) { |
| 915 | case CHIP_RV770: |
| 916 | case CHIP_RV740: |
| 917 | db_debug3 |= DB_CLK_OFF_DELAY(0x1f); |
| 918 | break; |
| 919 | case CHIP_RV710: |
| 920 | case CHIP_RV730: |
| 921 | default: |
| 922 | db_debug3 |= DB_CLK_OFF_DELAY(2); |
| 923 | break; |
| 924 | } |
| 925 | WREG32(DB_DEBUG3, db_debug3); |
| 926 | |
| 927 | if (rdev->family != CHIP_RV770) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 928 | db_debug4 = RREG32(DB_DEBUG4); |
| 929 | db_debug4 |= DISABLE_TILE_COVERED_FOR_PS_ITER; |
| 930 | WREG32(DB_DEBUG4, db_debug4); |
| 931 | } |
| 932 | |
| 933 | WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.rv770.sx_max_export_size / 4) - 1) | |
Alex Deucher | e29649d | 2009-11-03 10:04:01 -0500 | [diff] [blame] | 934 | POSITION_BUFFER_SIZE((rdev->config.rv770.sx_max_export_pos_size / 4) - 1) | |
| 935 | SMX_BUFFER_SIZE((rdev->config.rv770.sx_max_export_smx_size / 4) - 1))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 936 | |
| 937 | WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.rv770.sc_prim_fifo_size) | |
Alex Deucher | e29649d | 2009-11-03 10:04:01 -0500 | [diff] [blame] | 938 | SC_HIZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_hiz_tile_fifo_size) | |
| 939 | SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_earlyz_tile_fifo_fize))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 940 | |
| 941 | WREG32(PA_SC_MULTI_CHIP_CNTL, 0); |
| 942 | |
| 943 | WREG32(VGT_NUM_INSTANCES, 1); |
| 944 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 945 | WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4)); |
| 946 | |
| 947 | WREG32(CP_PERFMON_CNTL, 0); |
| 948 | |
| 949 | sq_ms_fifo_sizes = (CACHE_FIFO_SIZE(16 * rdev->config.rv770.sq_num_cf_insts) | |
| 950 | DONE_FIFO_HIWATER(0xe0) | |
| 951 | ALU_UPDATE_FIFO_HIWATER(0x8)); |
| 952 | switch (rdev->family) { |
| 953 | case CHIP_RV770: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 954 | case CHIP_RV730: |
| 955 | case CHIP_RV710: |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 956 | sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x1); |
| 957 | break; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 958 | case CHIP_RV740: |
| 959 | default: |
| 960 | sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x4); |
| 961 | break; |
| 962 | } |
| 963 | WREG32(SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes); |
| 964 | |
| 965 | /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT |
| 966 | * should be adjusted as needed by the 2D/3D drivers. This just sets default values |
| 967 | */ |
| 968 | sq_config = RREG32(SQ_CONFIG); |
| 969 | sq_config &= ~(PS_PRIO(3) | |
| 970 | VS_PRIO(3) | |
| 971 | GS_PRIO(3) | |
| 972 | ES_PRIO(3)); |
| 973 | sq_config |= (DX9_CONSTS | |
| 974 | VC_ENABLE | |
| 975 | EXPORT_SRC_C | |
| 976 | PS_PRIO(0) | |
| 977 | VS_PRIO(1) | |
| 978 | GS_PRIO(2) | |
| 979 | ES_PRIO(3)); |
| 980 | if (rdev->family == CHIP_RV710) |
| 981 | /* no vertex cache */ |
| 982 | sq_config &= ~VC_ENABLE; |
| 983 | |
| 984 | WREG32(SQ_CONFIG, sq_config); |
| 985 | |
| 986 | WREG32(SQ_GPR_RESOURCE_MGMT_1, (NUM_PS_GPRS((rdev->config.rv770.max_gprs * 24)/64) | |
Dave Airlie | fe62e1a | 2009-09-21 14:06:30 +1000 | [diff] [blame] | 987 | NUM_VS_GPRS((rdev->config.rv770.max_gprs * 24)/64) | |
| 988 | NUM_CLAUSE_TEMP_GPRS(((rdev->config.rv770.max_gprs * 24)/64)/2))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 989 | |
| 990 | WREG32(SQ_GPR_RESOURCE_MGMT_2, (NUM_GS_GPRS((rdev->config.rv770.max_gprs * 7)/64) | |
Dave Airlie | fe62e1a | 2009-09-21 14:06:30 +1000 | [diff] [blame] | 991 | NUM_ES_GPRS((rdev->config.rv770.max_gprs * 7)/64))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 992 | |
| 993 | sq_thread_resource_mgmt = (NUM_PS_THREADS((rdev->config.rv770.max_threads * 4)/8) | |
| 994 | NUM_VS_THREADS((rdev->config.rv770.max_threads * 2)/8) | |
| 995 | NUM_ES_THREADS((rdev->config.rv770.max_threads * 1)/8)); |
| 996 | if (((rdev->config.rv770.max_threads * 1) / 8) > rdev->config.rv770.max_gs_threads) |
| 997 | sq_thread_resource_mgmt |= NUM_GS_THREADS(rdev->config.rv770.max_gs_threads); |
| 998 | else |
| 999 | sq_thread_resource_mgmt |= NUM_GS_THREADS((rdev->config.rv770.max_gs_threads * 1)/8); |
| 1000 | WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt); |
| 1001 | |
| 1002 | WREG32(SQ_STACK_RESOURCE_MGMT_1, (NUM_PS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) | |
| 1003 | NUM_VS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4))); |
| 1004 | |
| 1005 | WREG32(SQ_STACK_RESOURCE_MGMT_2, (NUM_GS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) | |
| 1006 | NUM_ES_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4))); |
| 1007 | |
| 1008 | sq_dyn_gpr_size_simd_ab_0 = (SIMDA_RING0((rdev->config.rv770.max_gprs * 38)/64) | |
| 1009 | SIMDA_RING1((rdev->config.rv770.max_gprs * 38)/64) | |
| 1010 | SIMDB_RING0((rdev->config.rv770.max_gprs * 38)/64) | |
| 1011 | SIMDB_RING1((rdev->config.rv770.max_gprs * 38)/64)); |
| 1012 | |
| 1013 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0); |
| 1014 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0); |
| 1015 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0); |
| 1016 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0); |
| 1017 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0); |
| 1018 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0); |
| 1019 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0); |
| 1020 | WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0); |
| 1021 | |
| 1022 | WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) | |
Dave Airlie | fe62e1a | 2009-09-21 14:06:30 +1000 | [diff] [blame] | 1023 | FORCE_EOV_MAX_REZ_CNT(255))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1024 | |
| 1025 | if (rdev->family == CHIP_RV710) |
| 1026 | WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(TC_ONLY) | |
Dave Airlie | fe62e1a | 2009-09-21 14:06:30 +1000 | [diff] [blame] | 1027 | AUTO_INVLD_EN(ES_AND_GS_AUTO))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1028 | else |
| 1029 | WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(VC_AND_TC) | |
Dave Airlie | fe62e1a | 2009-09-21 14:06:30 +1000 | [diff] [blame] | 1030 | AUTO_INVLD_EN(ES_AND_GS_AUTO))); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1031 | |
| 1032 | switch (rdev->family) { |
| 1033 | case CHIP_RV770: |
| 1034 | case CHIP_RV730: |
| 1035 | case CHIP_RV740: |
| 1036 | gs_prim_buffer_depth = 384; |
| 1037 | break; |
| 1038 | case CHIP_RV710: |
| 1039 | gs_prim_buffer_depth = 128; |
| 1040 | break; |
| 1041 | default: |
| 1042 | break; |
| 1043 | } |
| 1044 | |
| 1045 | num_gs_verts_per_thread = rdev->config.rv770.max_pipes * 16; |
| 1046 | vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread; |
| 1047 | /* Max value for this is 256 */ |
| 1048 | if (vgt_gs_per_es > 256) |
| 1049 | vgt_gs_per_es = 256; |
| 1050 | |
| 1051 | WREG32(VGT_ES_PER_GS, 128); |
| 1052 | WREG32(VGT_GS_PER_ES, vgt_gs_per_es); |
| 1053 | WREG32(VGT_GS_PER_VS, 2); |
| 1054 | |
| 1055 | /* more default values. 2D/3D driver should adjust as needed */ |
| 1056 | WREG32(VGT_GS_VERTEX_REUSE, 16); |
| 1057 | WREG32(PA_SC_LINE_STIPPLE_STATE, 0); |
| 1058 | WREG32(VGT_STRMOUT_EN, 0); |
| 1059 | WREG32(SX_MISC, 0); |
| 1060 | WREG32(PA_SC_MODE_CNTL, 0); |
| 1061 | WREG32(PA_SC_EDGERULE, 0xaaaaaaaa); |
| 1062 | WREG32(PA_SC_AA_CONFIG, 0); |
| 1063 | WREG32(PA_SC_CLIPRECT_RULE, 0xffff); |
| 1064 | WREG32(PA_SC_LINE_STIPPLE, 0); |
| 1065 | WREG32(SPI_INPUT_Z, 0); |
| 1066 | WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2)); |
| 1067 | WREG32(CB_COLOR7_FRAG, 0); |
| 1068 | |
| 1069 | /* clear render buffer base addresses */ |
| 1070 | WREG32(CB_COLOR0_BASE, 0); |
| 1071 | WREG32(CB_COLOR1_BASE, 0); |
| 1072 | WREG32(CB_COLOR2_BASE, 0); |
| 1073 | WREG32(CB_COLOR3_BASE, 0); |
| 1074 | WREG32(CB_COLOR4_BASE, 0); |
| 1075 | WREG32(CB_COLOR5_BASE, 0); |
| 1076 | WREG32(CB_COLOR6_BASE, 0); |
| 1077 | WREG32(CB_COLOR7_BASE, 0); |
| 1078 | |
| 1079 | WREG32(TCP_CNTL, 0); |
| 1080 | |
| 1081 | hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL); |
| 1082 | WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl); |
| 1083 | |
| 1084 | WREG32(PA_SC_MULTI_CHIP_CNTL, 0); |
| 1085 | |
| 1086 | WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA | |
| 1087 | NUM_CLIP_SEQ(3))); |
Alex Deucher | b866d13 | 2012-06-14 22:06:36 +0200 | [diff] [blame] | 1088 | WREG32(VC_ENHANCE, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1089 | } |
| 1090 | |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1091 | void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
| 1092 | { |
| 1093 | u64 size_bf, size_af; |
| 1094 | |
| 1095 | if (mc->mc_vram_size > 0xE0000000) { |
| 1096 | /* leave room for at least 512M GTT */ |
| 1097 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1098 | mc->real_vram_size = 0xE0000000; |
| 1099 | mc->mc_vram_size = 0xE0000000; |
| 1100 | } |
| 1101 | if (rdev->flags & RADEON_IS_AGP) { |
| 1102 | size_bf = mc->gtt_start; |
Alex Deucher | 9ed8b1f | 2013-04-08 11:13:01 -0400 | [diff] [blame] | 1103 | size_af = mc->mc_mask - mc->gtt_end; |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1104 | if (size_bf > size_af) { |
| 1105 | if (mc->mc_vram_size > size_bf) { |
| 1106 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1107 | mc->real_vram_size = size_bf; |
| 1108 | mc->mc_vram_size = size_bf; |
| 1109 | } |
| 1110 | mc->vram_start = mc->gtt_start - mc->mc_vram_size; |
| 1111 | } else { |
| 1112 | if (mc->mc_vram_size > size_af) { |
| 1113 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1114 | mc->real_vram_size = size_af; |
| 1115 | mc->mc_vram_size = size_af; |
| 1116 | } |
Jerome Glisse | dfc6ae5 | 2012-04-17 16:51:38 -0400 | [diff] [blame] | 1117 | mc->vram_start = mc->gtt_end + 1; |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1118 | } |
| 1119 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 1120 | dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", |
| 1121 | mc->mc_vram_size >> 20, mc->vram_start, |
| 1122 | mc->vram_end, mc->real_vram_size >> 20); |
| 1123 | } else { |
Alex Deucher | b4183e3 | 2010-12-15 11:04:10 -0500 | [diff] [blame] | 1124 | radeon_vram_location(rdev, &rdev->mc, 0); |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1125 | rdev->mc.gtt_base_align = 0; |
| 1126 | radeon_gtt_location(rdev, mc); |
| 1127 | } |
| 1128 | } |
| 1129 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1130 | static int rv770_mc_init(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1131 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1132 | u32 tmp; |
Alex Deucher | 5885b7a | 2009-10-19 17:23:33 -0400 | [diff] [blame] | 1133 | int chansize, numchan; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1134 | |
| 1135 | /* Get VRAM informations */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1136 | rdev->mc.vram_is_ddr = true; |
Alex Deucher | 5885b7a | 2009-10-19 17:23:33 -0400 | [diff] [blame] | 1137 | tmp = RREG32(MC_ARB_RAMCFG); |
| 1138 | if (tmp & CHANSIZE_OVERRIDE) { |
| 1139 | chansize = 16; |
| 1140 | } else if (tmp & CHANSIZE_MASK) { |
| 1141 | chansize = 64; |
| 1142 | } else { |
| 1143 | chansize = 32; |
| 1144 | } |
| 1145 | tmp = RREG32(MC_SHARED_CHMAP); |
| 1146 | switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { |
| 1147 | case 0: |
| 1148 | default: |
| 1149 | numchan = 1; |
| 1150 | break; |
| 1151 | case 1: |
| 1152 | numchan = 2; |
| 1153 | break; |
| 1154 | case 2: |
| 1155 | numchan = 4; |
| 1156 | break; |
| 1157 | case 3: |
| 1158 | numchan = 8; |
| 1159 | break; |
| 1160 | } |
| 1161 | rdev->mc.vram_width = numchan * chansize; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1162 | /* Could aper size report 0 ? */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 1163 | rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0); |
| 1164 | rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1165 | /* Setup GPU memory space */ |
| 1166 | rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE); |
| 1167 | rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE); |
Jerome Glisse | 51e5fcd | 2010-02-19 14:33:54 +0000 | [diff] [blame] | 1168 | rdev->mc.visible_vram_size = rdev->mc.aper_size; |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1169 | r700_vram_gtt_location(rdev, &rdev->mc); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 1170 | radeon_update_bandwidth_info(rdev); |
| 1171 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1172 | return 0; |
| 1173 | } |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1174 | |
Alex Deucher | 43fb778 | 2013-01-04 09:24:18 -0500 | [diff] [blame] | 1175 | /** |
| 1176 | * rv770_copy_dma - copy pages using the DMA engine |
| 1177 | * |
| 1178 | * @rdev: radeon_device pointer |
| 1179 | * @src_offset: src GPU address |
| 1180 | * @dst_offset: dst GPU address |
| 1181 | * @num_gpu_pages: number of GPU pages to xfer |
| 1182 | * @fence: radeon fence object |
| 1183 | * |
| 1184 | * Copy GPU paging using the DMA engine (r7xx). |
| 1185 | * Used by the radeon ttm implementation to move pages if |
| 1186 | * registered as the asic copy callback. |
| 1187 | */ |
| 1188 | int rv770_copy_dma(struct radeon_device *rdev, |
| 1189 | uint64_t src_offset, uint64_t dst_offset, |
| 1190 | unsigned num_gpu_pages, |
| 1191 | struct radeon_fence **fence) |
| 1192 | { |
| 1193 | struct radeon_semaphore *sem = NULL; |
| 1194 | int ring_index = rdev->asic->copy.dma_ring_index; |
| 1195 | struct radeon_ring *ring = &rdev->ring[ring_index]; |
| 1196 | u32 size_in_dw, cur_size_in_dw; |
| 1197 | int i, num_loops; |
| 1198 | int r = 0; |
| 1199 | |
| 1200 | r = radeon_semaphore_create(rdev, &sem); |
| 1201 | if (r) { |
| 1202 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 1203 | return r; |
| 1204 | } |
| 1205 | |
| 1206 | size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4; |
| 1207 | num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF); |
| 1208 | r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8); |
| 1209 | if (r) { |
| 1210 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 1211 | radeon_semaphore_free(rdev, &sem, NULL); |
| 1212 | return r; |
| 1213 | } |
| 1214 | |
| 1215 | if (radeon_fence_need_sync(*fence, ring->idx)) { |
| 1216 | radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring, |
| 1217 | ring->idx); |
| 1218 | radeon_fence_note_sync(*fence, ring->idx); |
| 1219 | } else { |
| 1220 | radeon_semaphore_free(rdev, &sem, NULL); |
| 1221 | } |
| 1222 | |
| 1223 | for (i = 0; i < num_loops; i++) { |
| 1224 | cur_size_in_dw = size_in_dw; |
| 1225 | if (cur_size_in_dw > 0xFFFF) |
| 1226 | cur_size_in_dw = 0xFFFF; |
| 1227 | size_in_dw -= cur_size_in_dw; |
| 1228 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw)); |
| 1229 | radeon_ring_write(ring, dst_offset & 0xfffffffc); |
| 1230 | radeon_ring_write(ring, src_offset & 0xfffffffc); |
| 1231 | radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff); |
| 1232 | radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff); |
| 1233 | src_offset += cur_size_in_dw * 4; |
| 1234 | dst_offset += cur_size_in_dw * 4; |
| 1235 | } |
| 1236 | |
| 1237 | r = radeon_fence_emit(rdev, fence, ring->idx); |
| 1238 | if (r) { |
| 1239 | radeon_ring_unlock_undo(rdev, ring); |
| 1240 | return r; |
| 1241 | } |
| 1242 | |
| 1243 | radeon_ring_unlock_commit(rdev, ring); |
| 1244 | radeon_semaphore_free(rdev, &sem, *fence); |
| 1245 | |
| 1246 | return r; |
| 1247 | } |
| 1248 | |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1249 | static int rv770_startup(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1250 | { |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1251 | struct radeon_ring *ring; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1252 | int r; |
| 1253 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 1254 | /* enable pcie gen2 link */ |
| 1255 | rv770_pcie_gen2_enable(rdev); |
| 1256 | |
Alex Deucher | 779720a | 2009-12-09 19:31:44 -0500 | [diff] [blame] | 1257 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) { |
| 1258 | r = r600_init_microcode(rdev); |
| 1259 | if (r) { |
| 1260 | DRM_ERROR("Failed to load firmware!\n"); |
| 1261 | return r; |
| 1262 | } |
| 1263 | } |
| 1264 | |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1265 | r = r600_vram_scratch_init(rdev); |
| 1266 | if (r) |
| 1267 | return r; |
| 1268 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1269 | rv770_mc_program(rdev); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1270 | if (rdev->flags & RADEON_IS_AGP) { |
| 1271 | rv770_agp_enable(rdev); |
| 1272 | } else { |
| 1273 | r = rv770_pcie_gart_enable(rdev); |
| 1274 | if (r) |
| 1275 | return r; |
| 1276 | } |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1277 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1278 | rv770_gpu_init(rdev); |
Jerome Glisse | c38c7b6 | 2010-02-04 17:27:27 +0100 | [diff] [blame] | 1279 | r = r600_blit_init(rdev); |
| 1280 | if (r) { |
| 1281 | r600_blit_fini(rdev); |
Alex Deucher | 27cd776 | 2012-02-23 17:53:42 -0500 | [diff] [blame] | 1282 | rdev->asic->copy.copy = NULL; |
Jerome Glisse | c38c7b6 | 2010-02-04 17:27:27 +0100 | [diff] [blame] | 1283 | dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r); |
| 1284 | } |
Alex Deucher | b70d6bb | 2010-08-06 21:36:58 -0400 | [diff] [blame] | 1285 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1286 | /* allocate wb buffer */ |
| 1287 | r = radeon_wb_init(rdev); |
| 1288 | if (r) |
| 1289 | return r; |
| 1290 | |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 1291 | r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); |
| 1292 | if (r) { |
| 1293 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 1294 | return r; |
| 1295 | } |
| 1296 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1297 | r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX); |
| 1298 | if (r) { |
| 1299 | dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r); |
| 1300 | return r; |
| 1301 | } |
| 1302 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 1303 | r = rv770_uvd_resume(rdev); |
| 1304 | if (!r) { |
| 1305 | r = radeon_fence_driver_start_ring(rdev, |
| 1306 | R600_RING_TYPE_UVD_INDEX); |
| 1307 | if (r) |
| 1308 | dev_err(rdev->dev, "UVD fences init error (%d).\n", r); |
| 1309 | } |
| 1310 | |
| 1311 | if (r) |
| 1312 | rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0; |
| 1313 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1314 | /* Enable IRQ */ |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1315 | r = r600_irq_init(rdev); |
| 1316 | if (r) { |
| 1317 | DRM_ERROR("radeon: IH init failed (%d).\n", r); |
| 1318 | radeon_irq_kms_fini(rdev); |
| 1319 | return r; |
| 1320 | } |
| 1321 | r600_irq_set(rdev); |
| 1322 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1323 | ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1324 | 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] | 1325 | R600_CP_RB_RPTR, R600_CP_RB_WPTR, |
| 1326 | 0, 0xfffff, RADEON_CP_PACKET2); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1327 | if (r) |
| 1328 | return r; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1329 | |
| 1330 | ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX]; |
| 1331 | r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET, |
| 1332 | DMA_RB_RPTR, DMA_RB_WPTR, |
| 1333 | 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0)); |
| 1334 | if (r) |
| 1335 | return r; |
| 1336 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1337 | r = rv770_cp_load_microcode(rdev); |
| 1338 | if (r) |
| 1339 | return r; |
| 1340 | r = r600_cp_resume(rdev); |
| 1341 | if (r) |
| 1342 | return r; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1343 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1344 | r = r600_dma_resume(rdev); |
| 1345 | if (r) |
| 1346 | return r; |
| 1347 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 1348 | ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX]; |
| 1349 | if (ring->ring_size) { |
| 1350 | r = radeon_ring_init(rdev, ring, ring->ring_size, |
| 1351 | R600_WB_UVD_RPTR_OFFSET, |
| 1352 | UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR, |
| 1353 | 0, 0xfffff, RADEON_CP_PACKET2); |
| 1354 | if (!r) |
| 1355 | r = r600_uvd_init(rdev); |
| 1356 | |
| 1357 | if (r) |
| 1358 | DRM_ERROR("radeon: failed initializing UVD (%d).\n", r); |
| 1359 | } |
| 1360 | |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 1361 | r = radeon_ib_pool_init(rdev); |
| 1362 | if (r) { |
| 1363 | dev_err(rdev->dev, "IB initialization failed (%d).\n", r); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1364 | return r; |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 1365 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1366 | |
Alex Deucher | d4e30ef | 2012-06-04 17:18:51 -0400 | [diff] [blame] | 1367 | r = r600_audio_init(rdev); |
| 1368 | if (r) { |
| 1369 | DRM_ERROR("radeon: audio init failed\n"); |
| 1370 | return r; |
| 1371 | } |
| 1372 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1373 | return 0; |
| 1374 | } |
| 1375 | |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1376 | int rv770_resume(struct radeon_device *rdev) |
| 1377 | { |
| 1378 | int r; |
| 1379 | |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1380 | /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw, |
| 1381 | * posting will perform necessary task to bring back GPU into good |
| 1382 | * shape. |
| 1383 | */ |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1384 | /* post card */ |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 1385 | atom_asic_init(rdev->mode_info.atom_context); |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1386 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 1387 | rdev->accel_working = true; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1388 | r = rv770_startup(rdev); |
| 1389 | if (r) { |
| 1390 | DRM_ERROR("r600 startup failed on resume\n"); |
Jerome Glisse | 6b7746e | 2012-02-20 17:57:20 -0500 | [diff] [blame] | 1391 | rdev->accel_working = false; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1392 | return r; |
| 1393 | } |
| 1394 | |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1395 | return r; |
| 1396 | |
| 1397 | } |
| 1398 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1399 | int rv770_suspend(struct radeon_device *rdev) |
| 1400 | { |
Rafał Miłecki | 8a8c6e7 | 2010-03-06 13:03:36 +0000 | [diff] [blame] | 1401 | r600_audio_fini(rdev); |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 1402 | radeon_uvd_suspend(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1403 | r700_cp_stop(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1404 | r600_dma_stop(rdev); |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 1405 | r600_irq_suspend(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1406 | radeon_wb_disable(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 1407 | rv770_pcie_gart_disable(rdev); |
Alex Deucher | 6ddddfe | 2011-10-14 10:51:22 -0400 | [diff] [blame] | 1408 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1409 | return 0; |
| 1410 | } |
| 1411 | |
| 1412 | /* Plan is to move initialization in that function and use |
| 1413 | * helper function so that radeon_device_init pretty much |
| 1414 | * do nothing more than calling asic specific function. This |
| 1415 | * should also allow to remove a bunch of callback function |
| 1416 | * like vram_info. |
| 1417 | */ |
| 1418 | int rv770_init(struct radeon_device *rdev) |
| 1419 | { |
| 1420 | int r; |
| 1421 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1422 | /* Read BIOS */ |
| 1423 | if (!radeon_get_bios(rdev)) { |
| 1424 | if (ASIC_IS_AVIVO(rdev)) |
| 1425 | return -EINVAL; |
| 1426 | } |
| 1427 | /* Must be an ATOMBIOS */ |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 1428 | if (!rdev->is_atom_bios) { |
| 1429 | dev_err(rdev->dev, "Expecting atombios for R600 GPU\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1430 | return -EINVAL; |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 1431 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1432 | r = radeon_atombios_init(rdev); |
| 1433 | if (r) |
| 1434 | return r; |
| 1435 | /* Post card if necessary */ |
Alex Deucher | fd909c3 | 2011-01-11 18:08:59 -0500 | [diff] [blame] | 1436 | if (!radeon_card_posted(rdev)) { |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 1437 | if (!rdev->bios) { |
| 1438 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 1439 | return -EINVAL; |
| 1440 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1441 | DRM_INFO("GPU not posted. posting now...\n"); |
| 1442 | atom_asic_init(rdev->mode_info.atom_context); |
| 1443 | } |
| 1444 | /* Initialize scratch registers */ |
| 1445 | r600_scratch_init(rdev); |
| 1446 | /* Initialize surface registers */ |
| 1447 | radeon_surface_init(rdev); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1448 | /* Initialize clocks */ |
Michel Dänzer | 5e6dde7 | 2009-09-17 09:42:28 +0200 | [diff] [blame] | 1449 | radeon_get_clock_info(rdev->ddev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1450 | /* Fence driver */ |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 1451 | r = radeon_fence_driver_init(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1452 | if (r) |
| 1453 | return r; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1454 | /* initialize AGP */ |
Jerome Glisse | 700a0cc | 2010-01-13 15:16:38 +0100 | [diff] [blame] | 1455 | if (rdev->flags & RADEON_IS_AGP) { |
| 1456 | r = radeon_agp_init(rdev); |
| 1457 | if (r) |
| 1458 | radeon_agp_disable(rdev); |
| 1459 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1460 | r = rv770_mc_init(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 1461 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1462 | return r; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1463 | /* Memory manager */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1464 | r = radeon_bo_init(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1465 | if (r) |
| 1466 | return r; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1467 | |
| 1468 | r = radeon_irq_kms_init(rdev); |
| 1469 | if (r) |
| 1470 | return r; |
| 1471 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1472 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL; |
| 1473 | r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1474 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1475 | rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL; |
| 1476 | r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024); |
| 1477 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 1478 | r = radeon_uvd_init(rdev); |
| 1479 | if (!r) { |
| 1480 | rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL; |
| 1481 | r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], |
| 1482 | 4096); |
| 1483 | } |
| 1484 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1485 | rdev->ih.ring_obj = NULL; |
| 1486 | r600_ih_ring_init(rdev, 64 * 1024); |
| 1487 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 1488 | r = r600_pcie_gart_init(rdev); |
| 1489 | if (r) |
| 1490 | return r; |
| 1491 | |
Alex Deucher | 779720a | 2009-12-09 19:31:44 -0500 | [diff] [blame] | 1492 | rdev->accel_working = true; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 1493 | r = rv770_startup(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1494 | if (r) { |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 1495 | dev_err(rdev->dev, "disabling GPU acceleration\n"); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1496 | r700_cp_fini(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1497 | r600_dma_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 1498 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1499 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 1500 | radeon_ib_pool_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 1501 | radeon_irq_kms_fini(rdev); |
Jerome Glisse | 75c8129 | 2009-10-01 18:02:14 +0200 | [diff] [blame] | 1502 | rv770_pcie_gart_fini(rdev); |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 1503 | rdev->accel_working = false; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1504 | } |
Rafał Miłecki | 8a8c6e7 | 2010-03-06 13:03:36 +0000 | [diff] [blame] | 1505 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1506 | return 0; |
| 1507 | } |
| 1508 | |
| 1509 | void rv770_fini(struct radeon_device *rdev) |
| 1510 | { |
| 1511 | r600_blit_fini(rdev); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1512 | r700_cp_fini(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1513 | r600_dma_fini(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1514 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1515 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 1516 | radeon_ib_pool_fini(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 1517 | radeon_irq_kms_fini(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 1518 | rv770_pcie_gart_fini(rdev); |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 1519 | radeon_uvd_fini(rdev); |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1520 | r600_vram_scratch_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1521 | radeon_gem_fini(rdev); |
| 1522 | radeon_fence_driver_fini(rdev); |
Jerome Glisse | d0269ed | 2010-01-07 16:08:32 +0100 | [diff] [blame] | 1523 | radeon_agp_fini(rdev); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1524 | radeon_bo_fini(rdev); |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 1525 | radeon_atombios_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1526 | kfree(rdev->bios); |
| 1527 | rdev->bios = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1528 | } |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 1529 | |
| 1530 | static void rv770_pcie_gen2_enable(struct radeon_device *rdev) |
| 1531 | { |
| 1532 | u32 link_width_cntl, lanes, speed_cntl, tmp; |
| 1533 | u16 link_cntl2; |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 1534 | u32 mask; |
| 1535 | int ret; |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 1536 | |
Alex Deucher | d42dd57 | 2011-01-12 20:05:11 -0500 | [diff] [blame] | 1537 | if (radeon_pcie_gen2 == 0) |
| 1538 | return; |
| 1539 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 1540 | if (rdev->flags & RADEON_IS_IGP) |
| 1541 | return; |
| 1542 | |
| 1543 | if (!(rdev->flags & RADEON_IS_PCIE)) |
| 1544 | return; |
| 1545 | |
| 1546 | /* x2 cards have a special sequence */ |
| 1547 | if (ASIC_IS_X2(rdev)) |
| 1548 | return; |
| 1549 | |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 1550 | ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask); |
| 1551 | if (ret != 0) |
| 1552 | return; |
| 1553 | |
| 1554 | if (!(mask & DRM_PCIE_SPEED_50)) |
| 1555 | return; |
| 1556 | |
| 1557 | DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n"); |
| 1558 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 1559 | /* advertise upconfig capability */ |
| 1560 | link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL); |
| 1561 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
| 1562 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 1563 | link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL); |
| 1564 | if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) { |
| 1565 | lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT; |
| 1566 | link_width_cntl &= ~(LC_LINK_WIDTH_MASK | |
| 1567 | LC_RECONFIG_ARC_MISSING_ESCAPE); |
| 1568 | link_width_cntl |= lanes | LC_RECONFIG_NOW | |
| 1569 | LC_RENEGOTIATE_EN | LC_UPCONFIGURE_SUPPORT; |
| 1570 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 1571 | } else { |
| 1572 | link_width_cntl |= LC_UPCONFIGURE_DIS; |
| 1573 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 1574 | } |
| 1575 | |
| 1576 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 1577 | if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) && |
| 1578 | (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) { |
| 1579 | |
| 1580 | tmp = RREG32(0x541c); |
| 1581 | WREG32(0x541c, tmp | 0x8); |
| 1582 | WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN); |
| 1583 | link_cntl2 = RREG16(0x4088); |
| 1584 | link_cntl2 &= ~TARGET_LINK_SPEED_MASK; |
| 1585 | link_cntl2 |= 0x2; |
| 1586 | WREG16(0x4088, link_cntl2); |
| 1587 | WREG32(MM_CFGREGS_CNTL, 0); |
| 1588 | |
| 1589 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 1590 | speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN; |
| 1591 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 1592 | |
| 1593 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 1594 | speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT; |
| 1595 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 1596 | |
| 1597 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 1598 | speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT; |
| 1599 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 1600 | |
| 1601 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 1602 | speed_cntl |= LC_GEN2_EN_STRAP; |
| 1603 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 1604 | |
| 1605 | } else { |
| 1606 | link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL); |
| 1607 | /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */ |
| 1608 | if (1) |
| 1609 | link_width_cntl |= LC_UPCONFIGURE_DIS; |
| 1610 | else |
| 1611 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
| 1612 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 1613 | } |
| 1614 | } |