Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 28 | #include "radeon.h" |
Daniel Vetter | e699037 | 2010-03-11 21:19:17 +0000 | [diff] [blame] | 29 | #include "radeon_asic.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 30 | #include <drm/radeon_drm.h> |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 31 | #include "evergreend.h" |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 32 | #include "atom.h" |
| 33 | #include "avivod.h" |
| 34 | #include "evergreen_reg.h" |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 35 | #include "evergreen_blit_shaders.h" |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 36 | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 37 | #define EVERGREEN_PFP_UCODE_SIZE 1120 |
| 38 | #define EVERGREEN_PM4_UCODE_SIZE 1376 |
| 39 | |
Alex Deucher | 4a15903 | 2012-08-15 17:13:53 -0400 | [diff] [blame] | 40 | static const u32 crtc_offsets[6] = |
| 41 | { |
| 42 | EVERGREEN_CRTC0_REGISTER_OFFSET, |
| 43 | EVERGREEN_CRTC1_REGISTER_OFFSET, |
| 44 | EVERGREEN_CRTC2_REGISTER_OFFSET, |
| 45 | EVERGREEN_CRTC3_REGISTER_OFFSET, |
| 46 | EVERGREEN_CRTC4_REGISTER_OFFSET, |
| 47 | EVERGREEN_CRTC5_REGISTER_OFFSET |
| 48 | }; |
| 49 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 50 | static void evergreen_gpu_init(struct radeon_device *rdev); |
| 51 | void evergreen_fini(struct radeon_device *rdev); |
Ilija Hadzic | b07759b | 2011-09-20 10:22:58 -0400 | [diff] [blame] | 52 | void evergreen_pcie_gen2_enable(struct radeon_device *rdev); |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 53 | extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev, |
| 54 | int ring, u32 cp_int_cntl); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 55 | |
Jerome Glisse | 285484e | 2011-12-16 17:03:42 -0500 | [diff] [blame] | 56 | void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw, |
| 57 | unsigned *bankh, unsigned *mtaspect, |
| 58 | unsigned *tile_split) |
| 59 | { |
| 60 | *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK; |
| 61 | *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK; |
| 62 | *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK; |
| 63 | *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK; |
| 64 | switch (*bankw) { |
| 65 | default: |
| 66 | case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break; |
| 67 | case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break; |
| 68 | case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break; |
| 69 | case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break; |
| 70 | } |
| 71 | switch (*bankh) { |
| 72 | default: |
| 73 | case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break; |
| 74 | case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break; |
| 75 | case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break; |
| 76 | case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break; |
| 77 | } |
| 78 | switch (*mtaspect) { |
| 79 | default: |
| 80 | case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break; |
| 81 | case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break; |
| 82 | case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break; |
| 83 | case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break; |
| 84 | } |
| 85 | } |
| 86 | |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 87 | void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev) |
| 88 | { |
| 89 | u16 ctl, v; |
Jiang Liu | 32195ae | 2012-07-24 17:20:30 +0800 | [diff] [blame] | 90 | int err; |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 91 | |
Jiang Liu | 32195ae | 2012-07-24 17:20:30 +0800 | [diff] [blame] | 92 | err = pcie_capability_read_word(rdev->pdev, PCI_EXP_DEVCTL, &ctl); |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 93 | if (err) |
| 94 | return; |
| 95 | |
| 96 | v = (ctl & PCI_EXP_DEVCTL_READRQ) >> 12; |
| 97 | |
| 98 | /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it |
| 99 | * to avoid hangs or perfomance issues |
| 100 | */ |
| 101 | if ((v == 0) || (v == 6) || (v == 7)) { |
| 102 | ctl &= ~PCI_EXP_DEVCTL_READRQ; |
| 103 | ctl |= (2 << 12); |
Jiang Liu | 32195ae | 2012-07-24 17:20:30 +0800 | [diff] [blame] | 104 | pcie_capability_write_word(rdev->pdev, PCI_EXP_DEVCTL, ctl); |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 108 | /** |
| 109 | * dce4_wait_for_vblank - vblank wait asic callback. |
| 110 | * |
| 111 | * @rdev: radeon_device pointer |
| 112 | * @crtc: crtc to wait for vblank on |
| 113 | * |
| 114 | * Wait for vblank on the requested crtc (evergreen+). |
| 115 | */ |
Alex Deucher | 3ae19b7 | 2012-02-23 17:53:37 -0500 | [diff] [blame] | 116 | void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc) |
| 117 | { |
Alex Deucher | 3ae19b7 | 2012-02-23 17:53:37 -0500 | [diff] [blame] | 118 | int i; |
| 119 | |
Alex Deucher | 4a15903 | 2012-08-15 17:13:53 -0400 | [diff] [blame] | 120 | if (crtc >= rdev->num_crtc) |
| 121 | return; |
| 122 | |
| 123 | if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN) { |
Alex Deucher | 3ae19b7 | 2012-02-23 17:53:37 -0500 | [diff] [blame] | 124 | for (i = 0; i < rdev->usec_timeout; i++) { |
Alex Deucher | 4a15903 | 2012-08-15 17:13:53 -0400 | [diff] [blame] | 125 | if (!(RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)) |
Alex Deucher | 3ae19b7 | 2012-02-23 17:53:37 -0500 | [diff] [blame] | 126 | break; |
| 127 | udelay(1); |
| 128 | } |
| 129 | for (i = 0; i < rdev->usec_timeout; i++) { |
Alex Deucher | 4a15903 | 2012-08-15 17:13:53 -0400 | [diff] [blame] | 130 | if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK) |
Alex Deucher | 3ae19b7 | 2012-02-23 17:53:37 -0500 | [diff] [blame] | 131 | break; |
| 132 | udelay(1); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 137 | /** |
| 138 | * radeon_irq_kms_pflip_irq_get - pre-pageflip callback. |
| 139 | * |
| 140 | * @rdev: radeon_device pointer |
| 141 | * @crtc: crtc to prepare for pageflip on |
| 142 | * |
| 143 | * Pre-pageflip callback (evergreen+). |
| 144 | * Enables the pageflip irq (vblank irq). |
| 145 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 146 | void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc) |
| 147 | { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 148 | /* enable the pflip int */ |
| 149 | radeon_irq_kms_pflip_irq_get(rdev, crtc); |
| 150 | } |
| 151 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 152 | /** |
| 153 | * evergreen_post_page_flip - pos-pageflip callback. |
| 154 | * |
| 155 | * @rdev: radeon_device pointer |
| 156 | * @crtc: crtc to cleanup pageflip on |
| 157 | * |
| 158 | * Post-pageflip callback (evergreen+). |
| 159 | * Disables the pageflip irq (vblank irq). |
| 160 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 161 | void evergreen_post_page_flip(struct radeon_device *rdev, int crtc) |
| 162 | { |
| 163 | /* disable the pflip int */ |
| 164 | radeon_irq_kms_pflip_irq_put(rdev, crtc); |
| 165 | } |
| 166 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 167 | /** |
| 168 | * evergreen_page_flip - pageflip callback. |
| 169 | * |
| 170 | * @rdev: radeon_device pointer |
| 171 | * @crtc_id: crtc to cleanup pageflip on |
| 172 | * @crtc_base: new address of the crtc (GPU MC address) |
| 173 | * |
| 174 | * Does the actual pageflip (evergreen+). |
| 175 | * During vblank we take the crtc lock and wait for the update_pending |
| 176 | * bit to go high, when it does, we release the lock, and allow the |
| 177 | * double buffered update to take place. |
| 178 | * Returns the current update pending status. |
| 179 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 180 | u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base) |
| 181 | { |
| 182 | struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; |
| 183 | u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset); |
Alex Deucher | f649647 | 2011-11-28 14:49:26 -0500 | [diff] [blame] | 184 | int i; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 185 | |
| 186 | /* Lock the graphics update lock */ |
| 187 | tmp |= EVERGREEN_GRPH_UPDATE_LOCK; |
| 188 | WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp); |
| 189 | |
| 190 | /* update the scanout addresses */ |
| 191 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 192 | upper_32_bits(crtc_base)); |
| 193 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 194 | (u32)crtc_base); |
| 195 | |
| 196 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 197 | upper_32_bits(crtc_base)); |
| 198 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 199 | (u32)crtc_base); |
| 200 | |
| 201 | /* Wait for update_pending to go high. */ |
Alex Deucher | f649647 | 2011-11-28 14:49:26 -0500 | [diff] [blame] | 202 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 203 | if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) |
| 204 | break; |
| 205 | udelay(1); |
| 206 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 207 | DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); |
| 208 | |
| 209 | /* Unlock the lock, so double-buffering can take place inside vblank */ |
| 210 | tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK; |
| 211 | WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp); |
| 212 | |
| 213 | /* Return current update_pending status: */ |
| 214 | return RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING; |
| 215 | } |
| 216 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 217 | /* get temperature in millidegrees */ |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 218 | int evergreen_get_temp(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 219 | { |
Alex Deucher | 1c88d74 | 2011-06-14 19:15:53 +0000 | [diff] [blame] | 220 | u32 temp, toffset; |
| 221 | int actual_temp = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 222 | |
Alex Deucher | 67b3f82 | 2011-05-25 18:45:37 -0400 | [diff] [blame] | 223 | if (rdev->family == CHIP_JUNIPER) { |
| 224 | toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >> |
| 225 | TOFFSET_SHIFT; |
| 226 | temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >> |
| 227 | TS0_ADC_DOUT_SHIFT; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 228 | |
Alex Deucher | 67b3f82 | 2011-05-25 18:45:37 -0400 | [diff] [blame] | 229 | if (toffset & 0x100) |
| 230 | actual_temp = temp / 2 - (0x200 - toffset); |
| 231 | else |
| 232 | actual_temp = temp / 2 + toffset; |
| 233 | |
| 234 | actual_temp = actual_temp * 1000; |
| 235 | |
| 236 | } else { |
| 237 | temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >> |
| 238 | ASIC_T_SHIFT; |
| 239 | |
| 240 | if (temp & 0x400) |
| 241 | actual_temp = -256; |
| 242 | else if (temp & 0x200) |
| 243 | actual_temp = 255; |
| 244 | else if (temp & 0x100) { |
| 245 | actual_temp = temp & 0x1ff; |
| 246 | actual_temp |= ~0x1ff; |
| 247 | } else |
| 248 | actual_temp = temp & 0xff; |
| 249 | |
| 250 | actual_temp = (actual_temp * 1000) / 2; |
| 251 | } |
| 252 | |
| 253 | return actual_temp; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 256 | int sumo_get_temp(struct radeon_device *rdev) |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 257 | { |
| 258 | u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 259 | int actual_temp = temp - 49; |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 260 | |
| 261 | return actual_temp * 1000; |
| 262 | } |
| 263 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 264 | /** |
| 265 | * sumo_pm_init_profile - Initialize power profiles callback. |
| 266 | * |
| 267 | * @rdev: radeon_device pointer |
| 268 | * |
| 269 | * Initialize the power states used in profile mode |
| 270 | * (sumo, trinity, SI). |
| 271 | * Used for profile mode only. |
| 272 | */ |
Alex Deucher | a4c9e2e | 2011-11-04 10:09:41 -0400 | [diff] [blame] | 273 | void sumo_pm_init_profile(struct radeon_device *rdev) |
| 274 | { |
| 275 | int idx; |
| 276 | |
| 277 | /* default */ |
| 278 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 279 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 280 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 281 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; |
| 282 | |
| 283 | /* low,mid sh/mh */ |
| 284 | if (rdev->flags & RADEON_IS_MOBILITY) |
| 285 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); |
| 286 | else |
| 287 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); |
| 288 | |
| 289 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx; |
| 290 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx; |
| 291 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 292 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
| 293 | |
| 294 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx; |
| 295 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx; |
| 296 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 297 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
| 298 | |
| 299 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx; |
| 300 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx; |
| 301 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 302 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; |
| 303 | |
| 304 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx; |
| 305 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx; |
| 306 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 307 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; |
| 308 | |
| 309 | /* high sh/mh */ |
| 310 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); |
| 311 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx; |
| 312 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx; |
| 313 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 314 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = |
| 315 | rdev->pm.power_state[idx].num_clock_modes - 1; |
| 316 | |
| 317 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx; |
| 318 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx; |
| 319 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 320 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = |
| 321 | rdev->pm.power_state[idx].num_clock_modes - 1; |
| 322 | } |
| 323 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 324 | /** |
Alex Deucher | 27810fb | 2012-10-01 19:25:11 -0400 | [diff] [blame] | 325 | * btc_pm_init_profile - Initialize power profiles callback. |
| 326 | * |
| 327 | * @rdev: radeon_device pointer |
| 328 | * |
| 329 | * Initialize the power states used in profile mode |
| 330 | * (BTC, cayman). |
| 331 | * Used for profile mode only. |
| 332 | */ |
| 333 | void btc_pm_init_profile(struct radeon_device *rdev) |
| 334 | { |
| 335 | int idx; |
| 336 | |
| 337 | /* default */ |
| 338 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 339 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 340 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 341 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2; |
| 342 | /* starting with BTC, there is one state that is used for both |
| 343 | * MH and SH. Difference is that we always use the high clock index for |
| 344 | * mclk. |
| 345 | */ |
| 346 | if (rdev->flags & RADEON_IS_MOBILITY) |
| 347 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); |
| 348 | else |
| 349 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); |
| 350 | /* low sh */ |
| 351 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx; |
| 352 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx; |
| 353 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 354 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
| 355 | /* mid sh */ |
| 356 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx; |
| 357 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx; |
| 358 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 359 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1; |
| 360 | /* high sh */ |
| 361 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx; |
| 362 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx; |
| 363 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 364 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2; |
| 365 | /* low mh */ |
| 366 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx; |
| 367 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx; |
| 368 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 369 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
| 370 | /* mid mh */ |
| 371 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx; |
| 372 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx; |
| 373 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 374 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1; |
| 375 | /* high mh */ |
| 376 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx; |
| 377 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx; |
| 378 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 379 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2; |
| 380 | } |
| 381 | |
| 382 | /** |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 383 | * evergreen_pm_misc - set additional pm hw parameters callback. |
| 384 | * |
| 385 | * @rdev: radeon_device pointer |
| 386 | * |
| 387 | * Set non-clock parameters associated with a power state |
| 388 | * (voltage, etc.) (evergreen+). |
| 389 | */ |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 390 | void evergreen_pm_misc(struct radeon_device *rdev) |
| 391 | { |
Rafał Miłecki | a081a9d | 2010-06-07 18:20:25 -0400 | [diff] [blame] | 392 | int req_ps_idx = rdev->pm.requested_power_state_index; |
| 393 | int req_cm_idx = rdev->pm.requested_clock_mode_index; |
| 394 | struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx]; |
| 395 | struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage; |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 396 | |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 397 | if (voltage->type == VOLTAGE_SW) { |
Alex Deucher | a377e18 | 2011-06-20 13:00:31 -0400 | [diff] [blame] | 398 | /* 0xff01 is a flag rather then an actual voltage */ |
| 399 | if (voltage->voltage == 0xff01) |
| 400 | return; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 401 | if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) { |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 402 | radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 403 | rdev->pm.current_vddc = voltage->voltage; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 404 | DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage); |
| 405 | } |
Alex Deucher | a377e18 | 2011-06-20 13:00:31 -0400 | [diff] [blame] | 406 | /* 0xff01 is a flag rather then an actual voltage */ |
| 407 | if (voltage->vddci == 0xff01) |
| 408 | return; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 409 | if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) { |
| 410 | radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI); |
| 411 | rdev->pm.current_vddci = voltage->vddci; |
| 412 | DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 413 | } |
| 414 | } |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 415 | } |
| 416 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 417 | /** |
| 418 | * evergreen_pm_prepare - pre-power state change callback. |
| 419 | * |
| 420 | * @rdev: radeon_device pointer |
| 421 | * |
| 422 | * Prepare for a power state change (evergreen+). |
| 423 | */ |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 424 | void evergreen_pm_prepare(struct radeon_device *rdev) |
| 425 | { |
| 426 | struct drm_device *ddev = rdev->ddev; |
| 427 | struct drm_crtc *crtc; |
| 428 | struct radeon_crtc *radeon_crtc; |
| 429 | u32 tmp; |
| 430 | |
| 431 | /* disable any active CRTCs */ |
| 432 | list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { |
| 433 | radeon_crtc = to_radeon_crtc(crtc); |
| 434 | if (radeon_crtc->enabled) { |
| 435 | tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset); |
| 436 | tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE; |
| 437 | WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 442 | /** |
| 443 | * evergreen_pm_finish - post-power state change callback. |
| 444 | * |
| 445 | * @rdev: radeon_device pointer |
| 446 | * |
| 447 | * Clean up after a power state change (evergreen+). |
| 448 | */ |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 449 | void evergreen_pm_finish(struct radeon_device *rdev) |
| 450 | { |
| 451 | struct drm_device *ddev = rdev->ddev; |
| 452 | struct drm_crtc *crtc; |
| 453 | struct radeon_crtc *radeon_crtc; |
| 454 | u32 tmp; |
| 455 | |
| 456 | /* enable any active CRTCs */ |
| 457 | list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) { |
| 458 | radeon_crtc = to_radeon_crtc(crtc); |
| 459 | if (radeon_crtc->enabled) { |
| 460 | tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset); |
| 461 | tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE; |
| 462 | WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 467 | /** |
| 468 | * evergreen_hpd_sense - hpd sense callback. |
| 469 | * |
| 470 | * @rdev: radeon_device pointer |
| 471 | * @hpd: hpd (hotplug detect) pin |
| 472 | * |
| 473 | * Checks if a digital monitor is connected (evergreen+). |
| 474 | * Returns true if connected, false if not connected. |
| 475 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 476 | bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) |
| 477 | { |
| 478 | bool connected = false; |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 479 | |
| 480 | switch (hpd) { |
| 481 | case RADEON_HPD_1: |
| 482 | if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE) |
| 483 | connected = true; |
| 484 | break; |
| 485 | case RADEON_HPD_2: |
| 486 | if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE) |
| 487 | connected = true; |
| 488 | break; |
| 489 | case RADEON_HPD_3: |
| 490 | if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE) |
| 491 | connected = true; |
| 492 | break; |
| 493 | case RADEON_HPD_4: |
| 494 | if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE) |
| 495 | connected = true; |
| 496 | break; |
| 497 | case RADEON_HPD_5: |
| 498 | if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE) |
| 499 | connected = true; |
| 500 | break; |
| 501 | case RADEON_HPD_6: |
| 502 | if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE) |
| 503 | connected = true; |
| 504 | break; |
| 505 | default: |
| 506 | break; |
| 507 | } |
| 508 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 509 | return connected; |
| 510 | } |
| 511 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 512 | /** |
| 513 | * evergreen_hpd_set_polarity - hpd set polarity callback. |
| 514 | * |
| 515 | * @rdev: radeon_device pointer |
| 516 | * @hpd: hpd (hotplug detect) pin |
| 517 | * |
| 518 | * Set the polarity of the hpd pin (evergreen+). |
| 519 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 520 | void evergreen_hpd_set_polarity(struct radeon_device *rdev, |
| 521 | enum radeon_hpd_id hpd) |
| 522 | { |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 523 | u32 tmp; |
| 524 | bool connected = evergreen_hpd_sense(rdev, hpd); |
| 525 | |
| 526 | switch (hpd) { |
| 527 | case RADEON_HPD_1: |
| 528 | tmp = RREG32(DC_HPD1_INT_CONTROL); |
| 529 | if (connected) |
| 530 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 531 | else |
| 532 | tmp |= DC_HPDx_INT_POLARITY; |
| 533 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 534 | break; |
| 535 | case RADEON_HPD_2: |
| 536 | tmp = RREG32(DC_HPD2_INT_CONTROL); |
| 537 | if (connected) |
| 538 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 539 | else |
| 540 | tmp |= DC_HPDx_INT_POLARITY; |
| 541 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 542 | break; |
| 543 | case RADEON_HPD_3: |
| 544 | tmp = RREG32(DC_HPD3_INT_CONTROL); |
| 545 | if (connected) |
| 546 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 547 | else |
| 548 | tmp |= DC_HPDx_INT_POLARITY; |
| 549 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 550 | break; |
| 551 | case RADEON_HPD_4: |
| 552 | tmp = RREG32(DC_HPD4_INT_CONTROL); |
| 553 | if (connected) |
| 554 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 555 | else |
| 556 | tmp |= DC_HPDx_INT_POLARITY; |
| 557 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 558 | break; |
| 559 | case RADEON_HPD_5: |
| 560 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 561 | if (connected) |
| 562 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 563 | else |
| 564 | tmp |= DC_HPDx_INT_POLARITY; |
| 565 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
| 566 | break; |
| 567 | case RADEON_HPD_6: |
| 568 | tmp = RREG32(DC_HPD6_INT_CONTROL); |
| 569 | if (connected) |
| 570 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 571 | else |
| 572 | tmp |= DC_HPDx_INT_POLARITY; |
| 573 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
| 574 | break; |
| 575 | default: |
| 576 | break; |
| 577 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 578 | } |
| 579 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 580 | /** |
| 581 | * evergreen_hpd_init - hpd setup callback. |
| 582 | * |
| 583 | * @rdev: radeon_device pointer |
| 584 | * |
| 585 | * Setup the hpd pins used by the card (evergreen+). |
| 586 | * Enable the pin, set the polarity, and enable the hpd interrupts. |
| 587 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 588 | void evergreen_hpd_init(struct radeon_device *rdev) |
| 589 | { |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 590 | struct drm_device *dev = rdev->ddev; |
| 591 | struct drm_connector *connector; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 592 | unsigned enabled = 0; |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 593 | u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | |
| 594 | DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 595 | |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 596 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 597 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 598 | switch (radeon_connector->hpd.hpd) { |
| 599 | case RADEON_HPD_1: |
| 600 | WREG32(DC_HPD1_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 601 | break; |
| 602 | case RADEON_HPD_2: |
| 603 | WREG32(DC_HPD2_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 604 | break; |
| 605 | case RADEON_HPD_3: |
| 606 | WREG32(DC_HPD3_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 607 | break; |
| 608 | case RADEON_HPD_4: |
| 609 | WREG32(DC_HPD4_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 610 | break; |
| 611 | case RADEON_HPD_5: |
| 612 | WREG32(DC_HPD5_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 613 | break; |
| 614 | case RADEON_HPD_6: |
| 615 | WREG32(DC_HPD6_CONTROL, tmp); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 616 | break; |
| 617 | default: |
| 618 | break; |
| 619 | } |
Alex Deucher | 64912e9 | 2011-11-03 11:21:39 -0400 | [diff] [blame] | 620 | radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 621 | enabled |= 1 << radeon_connector->hpd.hpd; |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 622 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 623 | radeon_irq_kms_enable_hpd(rdev, enabled); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 624 | } |
| 625 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 626 | /** |
| 627 | * evergreen_hpd_fini - hpd tear down callback. |
| 628 | * |
| 629 | * @rdev: radeon_device pointer |
| 630 | * |
| 631 | * Tear down the hpd pins used by the card (evergreen+). |
| 632 | * Disable the hpd interrupts. |
| 633 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 634 | void evergreen_hpd_fini(struct radeon_device *rdev) |
| 635 | { |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 636 | struct drm_device *dev = rdev->ddev; |
| 637 | struct drm_connector *connector; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 638 | unsigned disabled = 0; |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 639 | |
| 640 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 641 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 642 | switch (radeon_connector->hpd.hpd) { |
| 643 | case RADEON_HPD_1: |
| 644 | WREG32(DC_HPD1_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 645 | break; |
| 646 | case RADEON_HPD_2: |
| 647 | WREG32(DC_HPD2_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 648 | break; |
| 649 | case RADEON_HPD_3: |
| 650 | WREG32(DC_HPD3_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 651 | break; |
| 652 | case RADEON_HPD_4: |
| 653 | WREG32(DC_HPD4_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 654 | break; |
| 655 | case RADEON_HPD_5: |
| 656 | WREG32(DC_HPD5_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 657 | break; |
| 658 | case RADEON_HPD_6: |
| 659 | WREG32(DC_HPD6_CONTROL, 0); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 660 | break; |
| 661 | default: |
| 662 | break; |
| 663 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 664 | disabled |= 1 << radeon_connector->hpd.hpd; |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 665 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 666 | radeon_irq_kms_disable_hpd(rdev, disabled); |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 667 | } |
| 668 | |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 669 | /* watermark setup */ |
| 670 | |
| 671 | static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev, |
| 672 | struct radeon_crtc *radeon_crtc, |
| 673 | struct drm_display_mode *mode, |
| 674 | struct drm_display_mode *other_mode) |
| 675 | { |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 676 | u32 tmp; |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 677 | /* |
| 678 | * Line Buffer Setup |
| 679 | * There are 3 line buffers, each one shared by 2 display controllers. |
| 680 | * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between |
| 681 | * the display controllers. The paritioning is done via one of four |
| 682 | * preset allocations specified in bits 2:0: |
| 683 | * first display controller |
| 684 | * 0 - first half of lb (3840 * 2) |
| 685 | * 1 - first 3/4 of lb (5760 * 2) |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 686 | * 2 - whole lb (7680 * 2), other crtc must be disabled |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 687 | * 3 - first 1/4 of lb (1920 * 2) |
| 688 | * second display controller |
| 689 | * 4 - second half of lb (3840 * 2) |
| 690 | * 5 - second 3/4 of lb (5760 * 2) |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 691 | * 6 - whole lb (7680 * 2), other crtc must be disabled |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 692 | * 7 - last 1/4 of lb (1920 * 2) |
| 693 | */ |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 694 | /* this can get tricky if we have two large displays on a paired group |
| 695 | * of crtcs. Ideally for multiple large displays we'd assign them to |
| 696 | * non-linked crtcs for maximum line buffer allocation. |
| 697 | */ |
| 698 | if (radeon_crtc->base.enabled && mode) { |
| 699 | if (other_mode) |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 700 | tmp = 0; /* 1/2 */ |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 701 | else |
| 702 | tmp = 2; /* whole */ |
| 703 | } else |
| 704 | tmp = 0; |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 705 | |
| 706 | /* second controller of the pair uses second half of the lb */ |
| 707 | if (radeon_crtc->crtc_id % 2) |
| 708 | tmp += 4; |
| 709 | WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp); |
| 710 | |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 711 | if (radeon_crtc->base.enabled && mode) { |
| 712 | switch (tmp) { |
| 713 | case 0: |
| 714 | case 4: |
| 715 | default: |
| 716 | if (ASIC_IS_DCE5(rdev)) |
| 717 | return 4096 * 2; |
| 718 | else |
| 719 | return 3840 * 2; |
| 720 | case 1: |
| 721 | case 5: |
| 722 | if (ASIC_IS_DCE5(rdev)) |
| 723 | return 6144 * 2; |
| 724 | else |
| 725 | return 5760 * 2; |
| 726 | case 2: |
| 727 | case 6: |
| 728 | if (ASIC_IS_DCE5(rdev)) |
| 729 | return 8192 * 2; |
| 730 | else |
| 731 | return 7680 * 2; |
| 732 | case 3: |
| 733 | case 7: |
| 734 | if (ASIC_IS_DCE5(rdev)) |
| 735 | return 2048 * 2; |
| 736 | else |
| 737 | return 1920 * 2; |
| 738 | } |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 739 | } |
Alex Deucher | 12dfc84 | 2011-04-14 19:07:34 -0400 | [diff] [blame] | 740 | |
| 741 | /* controller not enabled, so no lb used */ |
| 742 | return 0; |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Alex Deucher | ca7db22 | 2012-03-20 17:18:30 -0400 | [diff] [blame] | 745 | u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev) |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 746 | { |
| 747 | u32 tmp = RREG32(MC_SHARED_CHMAP); |
| 748 | |
| 749 | switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { |
| 750 | case 0: |
| 751 | default: |
| 752 | return 1; |
| 753 | case 1: |
| 754 | return 2; |
| 755 | case 2: |
| 756 | return 4; |
| 757 | case 3: |
| 758 | return 8; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | struct evergreen_wm_params { |
| 763 | u32 dram_channels; /* number of dram channels */ |
| 764 | u32 yclk; /* bandwidth per dram data pin in kHz */ |
| 765 | u32 sclk; /* engine clock in kHz */ |
| 766 | u32 disp_clk; /* display clock in kHz */ |
| 767 | u32 src_width; /* viewport width */ |
| 768 | u32 active_time; /* active display time in ns */ |
| 769 | u32 blank_time; /* blank time in ns */ |
| 770 | bool interlaced; /* mode is interlaced */ |
| 771 | fixed20_12 vsc; /* vertical scale ratio */ |
| 772 | u32 num_heads; /* number of active crtcs */ |
| 773 | u32 bytes_per_pixel; /* bytes per pixel display + overlay */ |
| 774 | u32 lb_size; /* line buffer allocated to pipe */ |
| 775 | u32 vtaps; /* vertical scaler taps */ |
| 776 | }; |
| 777 | |
| 778 | static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm) |
| 779 | { |
| 780 | /* Calculate DRAM Bandwidth and the part allocated to display. */ |
| 781 | fixed20_12 dram_efficiency; /* 0.7 */ |
| 782 | fixed20_12 yclk, dram_channels, bandwidth; |
| 783 | fixed20_12 a; |
| 784 | |
| 785 | a.full = dfixed_const(1000); |
| 786 | yclk.full = dfixed_const(wm->yclk); |
| 787 | yclk.full = dfixed_div(yclk, a); |
| 788 | dram_channels.full = dfixed_const(wm->dram_channels * 4); |
| 789 | a.full = dfixed_const(10); |
| 790 | dram_efficiency.full = dfixed_const(7); |
| 791 | dram_efficiency.full = dfixed_div(dram_efficiency, a); |
| 792 | bandwidth.full = dfixed_mul(dram_channels, yclk); |
| 793 | bandwidth.full = dfixed_mul(bandwidth, dram_efficiency); |
| 794 | |
| 795 | return dfixed_trunc(bandwidth); |
| 796 | } |
| 797 | |
| 798 | static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm) |
| 799 | { |
| 800 | /* Calculate DRAM Bandwidth and the part allocated to display. */ |
| 801 | fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */ |
| 802 | fixed20_12 yclk, dram_channels, bandwidth; |
| 803 | fixed20_12 a; |
| 804 | |
| 805 | a.full = dfixed_const(1000); |
| 806 | yclk.full = dfixed_const(wm->yclk); |
| 807 | yclk.full = dfixed_div(yclk, a); |
| 808 | dram_channels.full = dfixed_const(wm->dram_channels * 4); |
| 809 | a.full = dfixed_const(10); |
| 810 | disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */ |
| 811 | disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a); |
| 812 | bandwidth.full = dfixed_mul(dram_channels, yclk); |
| 813 | bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation); |
| 814 | |
| 815 | return dfixed_trunc(bandwidth); |
| 816 | } |
| 817 | |
| 818 | static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm) |
| 819 | { |
| 820 | /* Calculate the display Data return Bandwidth */ |
| 821 | fixed20_12 return_efficiency; /* 0.8 */ |
| 822 | fixed20_12 sclk, bandwidth; |
| 823 | fixed20_12 a; |
| 824 | |
| 825 | a.full = dfixed_const(1000); |
| 826 | sclk.full = dfixed_const(wm->sclk); |
| 827 | sclk.full = dfixed_div(sclk, a); |
| 828 | a.full = dfixed_const(10); |
| 829 | return_efficiency.full = dfixed_const(8); |
| 830 | return_efficiency.full = dfixed_div(return_efficiency, a); |
| 831 | a.full = dfixed_const(32); |
| 832 | bandwidth.full = dfixed_mul(a, sclk); |
| 833 | bandwidth.full = dfixed_mul(bandwidth, return_efficiency); |
| 834 | |
| 835 | return dfixed_trunc(bandwidth); |
| 836 | } |
| 837 | |
| 838 | static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm) |
| 839 | { |
| 840 | /* Calculate the DMIF Request Bandwidth */ |
| 841 | fixed20_12 disp_clk_request_efficiency; /* 0.8 */ |
| 842 | fixed20_12 disp_clk, bandwidth; |
| 843 | fixed20_12 a; |
| 844 | |
| 845 | a.full = dfixed_const(1000); |
| 846 | disp_clk.full = dfixed_const(wm->disp_clk); |
| 847 | disp_clk.full = dfixed_div(disp_clk, a); |
| 848 | a.full = dfixed_const(10); |
| 849 | disp_clk_request_efficiency.full = dfixed_const(8); |
| 850 | disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a); |
| 851 | a.full = dfixed_const(32); |
| 852 | bandwidth.full = dfixed_mul(a, disp_clk); |
| 853 | bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency); |
| 854 | |
| 855 | return dfixed_trunc(bandwidth); |
| 856 | } |
| 857 | |
| 858 | static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm) |
| 859 | { |
| 860 | /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */ |
| 861 | u32 dram_bandwidth = evergreen_dram_bandwidth(wm); |
| 862 | u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm); |
| 863 | u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm); |
| 864 | |
| 865 | return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth)); |
| 866 | } |
| 867 | |
| 868 | static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm) |
| 869 | { |
| 870 | /* Calculate the display mode Average Bandwidth |
| 871 | * DisplayMode should contain the source and destination dimensions, |
| 872 | * timing, etc. |
| 873 | */ |
| 874 | fixed20_12 bpp; |
| 875 | fixed20_12 line_time; |
| 876 | fixed20_12 src_width; |
| 877 | fixed20_12 bandwidth; |
| 878 | fixed20_12 a; |
| 879 | |
| 880 | a.full = dfixed_const(1000); |
| 881 | line_time.full = dfixed_const(wm->active_time + wm->blank_time); |
| 882 | line_time.full = dfixed_div(line_time, a); |
| 883 | bpp.full = dfixed_const(wm->bytes_per_pixel); |
| 884 | src_width.full = dfixed_const(wm->src_width); |
| 885 | bandwidth.full = dfixed_mul(src_width, bpp); |
| 886 | bandwidth.full = dfixed_mul(bandwidth, wm->vsc); |
| 887 | bandwidth.full = dfixed_div(bandwidth, line_time); |
| 888 | |
| 889 | return dfixed_trunc(bandwidth); |
| 890 | } |
| 891 | |
| 892 | static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm) |
| 893 | { |
| 894 | /* First calcualte the latency in ns */ |
| 895 | u32 mc_latency = 2000; /* 2000 ns. */ |
| 896 | u32 available_bandwidth = evergreen_available_bandwidth(wm); |
| 897 | u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth; |
| 898 | u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth; |
| 899 | u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */ |
| 900 | u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) + |
| 901 | (wm->num_heads * cursor_line_pair_return_time); |
| 902 | u32 latency = mc_latency + other_heads_data_return_time + dc_latency; |
| 903 | u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time; |
| 904 | fixed20_12 a, b, c; |
| 905 | |
| 906 | if (wm->num_heads == 0) |
| 907 | return 0; |
| 908 | |
| 909 | a.full = dfixed_const(2); |
| 910 | b.full = dfixed_const(1); |
| 911 | if ((wm->vsc.full > a.full) || |
| 912 | ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) || |
| 913 | (wm->vtaps >= 5) || |
| 914 | ((wm->vsc.full >= a.full) && wm->interlaced)) |
| 915 | max_src_lines_per_dst_line = 4; |
| 916 | else |
| 917 | max_src_lines_per_dst_line = 2; |
| 918 | |
| 919 | a.full = dfixed_const(available_bandwidth); |
| 920 | b.full = dfixed_const(wm->num_heads); |
| 921 | a.full = dfixed_div(a, b); |
| 922 | |
| 923 | b.full = dfixed_const(1000); |
| 924 | c.full = dfixed_const(wm->disp_clk); |
| 925 | b.full = dfixed_div(c, b); |
| 926 | c.full = dfixed_const(wm->bytes_per_pixel); |
| 927 | b.full = dfixed_mul(b, c); |
| 928 | |
| 929 | lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b)); |
| 930 | |
| 931 | a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel); |
| 932 | b.full = dfixed_const(1000); |
| 933 | c.full = dfixed_const(lb_fill_bw); |
| 934 | b.full = dfixed_div(c, b); |
| 935 | a.full = dfixed_div(a, b); |
| 936 | line_fill_time = dfixed_trunc(a); |
| 937 | |
| 938 | if (line_fill_time < wm->active_time) |
| 939 | return latency; |
| 940 | else |
| 941 | return latency + (line_fill_time - wm->active_time); |
| 942 | |
| 943 | } |
| 944 | |
| 945 | static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm) |
| 946 | { |
| 947 | if (evergreen_average_bandwidth(wm) <= |
| 948 | (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads)) |
| 949 | return true; |
| 950 | else |
| 951 | return false; |
| 952 | }; |
| 953 | |
| 954 | static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm) |
| 955 | { |
| 956 | if (evergreen_average_bandwidth(wm) <= |
| 957 | (evergreen_available_bandwidth(wm) / wm->num_heads)) |
| 958 | return true; |
| 959 | else |
| 960 | return false; |
| 961 | }; |
| 962 | |
| 963 | static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm) |
| 964 | { |
| 965 | u32 lb_partitions = wm->lb_size / wm->src_width; |
| 966 | u32 line_time = wm->active_time + wm->blank_time; |
| 967 | u32 latency_tolerant_lines; |
| 968 | u32 latency_hiding; |
| 969 | fixed20_12 a; |
| 970 | |
| 971 | a.full = dfixed_const(1); |
| 972 | if (wm->vsc.full > a.full) |
| 973 | latency_tolerant_lines = 1; |
| 974 | else { |
| 975 | if (lb_partitions <= (wm->vtaps + 1)) |
| 976 | latency_tolerant_lines = 1; |
| 977 | else |
| 978 | latency_tolerant_lines = 2; |
| 979 | } |
| 980 | |
| 981 | latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time); |
| 982 | |
| 983 | if (evergreen_latency_watermark(wm) <= latency_hiding) |
| 984 | return true; |
| 985 | else |
| 986 | return false; |
| 987 | } |
| 988 | |
| 989 | static void evergreen_program_watermarks(struct radeon_device *rdev, |
| 990 | struct radeon_crtc *radeon_crtc, |
| 991 | u32 lb_size, u32 num_heads) |
| 992 | { |
| 993 | struct drm_display_mode *mode = &radeon_crtc->base.mode; |
| 994 | struct evergreen_wm_params wm; |
| 995 | u32 pixel_period; |
| 996 | u32 line_time = 0; |
| 997 | u32 latency_watermark_a = 0, latency_watermark_b = 0; |
| 998 | u32 priority_a_mark = 0, priority_b_mark = 0; |
| 999 | u32 priority_a_cnt = PRIORITY_OFF; |
| 1000 | u32 priority_b_cnt = PRIORITY_OFF; |
| 1001 | u32 pipe_offset = radeon_crtc->crtc_id * 16; |
| 1002 | u32 tmp, arb_control3; |
| 1003 | fixed20_12 a, b, c; |
| 1004 | |
| 1005 | if (radeon_crtc->base.enabled && num_heads && mode) { |
| 1006 | pixel_period = 1000000 / (u32)mode->clock; |
| 1007 | line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535); |
| 1008 | priority_a_cnt = 0; |
| 1009 | priority_b_cnt = 0; |
| 1010 | |
| 1011 | wm.yclk = rdev->pm.current_mclk * 10; |
| 1012 | wm.sclk = rdev->pm.current_sclk * 10; |
| 1013 | wm.disp_clk = mode->clock; |
| 1014 | wm.src_width = mode->crtc_hdisplay; |
| 1015 | wm.active_time = mode->crtc_hdisplay * pixel_period; |
| 1016 | wm.blank_time = line_time - wm.active_time; |
| 1017 | wm.interlaced = false; |
| 1018 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1019 | wm.interlaced = true; |
| 1020 | wm.vsc = radeon_crtc->vsc; |
| 1021 | wm.vtaps = 1; |
| 1022 | if (radeon_crtc->rmx_type != RMX_OFF) |
| 1023 | wm.vtaps = 2; |
| 1024 | wm.bytes_per_pixel = 4; /* XXX: get this from fb config */ |
| 1025 | wm.lb_size = lb_size; |
| 1026 | wm.dram_channels = evergreen_get_number_of_dram_channels(rdev); |
| 1027 | wm.num_heads = num_heads; |
| 1028 | |
| 1029 | /* set for high clocks */ |
| 1030 | latency_watermark_a = min(evergreen_latency_watermark(&wm), (u32)65535); |
| 1031 | /* set for low clocks */ |
| 1032 | /* wm.yclk = low clk; wm.sclk = low clk */ |
| 1033 | latency_watermark_b = min(evergreen_latency_watermark(&wm), (u32)65535); |
| 1034 | |
| 1035 | /* possibly force display priority to high */ |
| 1036 | /* should really do this at mode validation time... */ |
| 1037 | if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm) || |
| 1038 | !evergreen_average_bandwidth_vs_available_bandwidth(&wm) || |
| 1039 | !evergreen_check_latency_hiding(&wm) || |
| 1040 | (rdev->disp_priority == 2)) { |
Alex Deucher | 92bdfd4 | 2011-08-04 17:28:40 +0000 | [diff] [blame] | 1041 | DRM_DEBUG_KMS("force priority to high\n"); |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 1042 | priority_a_cnt |= PRIORITY_ALWAYS_ON; |
| 1043 | priority_b_cnt |= PRIORITY_ALWAYS_ON; |
| 1044 | } |
| 1045 | |
| 1046 | a.full = dfixed_const(1000); |
| 1047 | b.full = dfixed_const(mode->clock); |
| 1048 | b.full = dfixed_div(b, a); |
| 1049 | c.full = dfixed_const(latency_watermark_a); |
| 1050 | c.full = dfixed_mul(c, b); |
| 1051 | c.full = dfixed_mul(c, radeon_crtc->hsc); |
| 1052 | c.full = dfixed_div(c, a); |
| 1053 | a.full = dfixed_const(16); |
| 1054 | c.full = dfixed_div(c, a); |
| 1055 | priority_a_mark = dfixed_trunc(c); |
| 1056 | priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK; |
| 1057 | |
| 1058 | a.full = dfixed_const(1000); |
| 1059 | b.full = dfixed_const(mode->clock); |
| 1060 | b.full = dfixed_div(b, a); |
| 1061 | c.full = dfixed_const(latency_watermark_b); |
| 1062 | c.full = dfixed_mul(c, b); |
| 1063 | c.full = dfixed_mul(c, radeon_crtc->hsc); |
| 1064 | c.full = dfixed_div(c, a); |
| 1065 | a.full = dfixed_const(16); |
| 1066 | c.full = dfixed_div(c, a); |
| 1067 | priority_b_mark = dfixed_trunc(c); |
| 1068 | priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK; |
| 1069 | } |
| 1070 | |
| 1071 | /* select wm A */ |
| 1072 | arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset); |
| 1073 | tmp = arb_control3; |
| 1074 | tmp &= ~LATENCY_WATERMARK_MASK(3); |
| 1075 | tmp |= LATENCY_WATERMARK_MASK(1); |
| 1076 | WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp); |
| 1077 | WREG32(PIPE0_LATENCY_CONTROL + pipe_offset, |
| 1078 | (LATENCY_LOW_WATERMARK(latency_watermark_a) | |
| 1079 | LATENCY_HIGH_WATERMARK(line_time))); |
| 1080 | /* select wm B */ |
| 1081 | tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset); |
| 1082 | tmp &= ~LATENCY_WATERMARK_MASK(3); |
| 1083 | tmp |= LATENCY_WATERMARK_MASK(2); |
| 1084 | WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp); |
| 1085 | WREG32(PIPE0_LATENCY_CONTROL + pipe_offset, |
| 1086 | (LATENCY_LOW_WATERMARK(latency_watermark_b) | |
| 1087 | LATENCY_HIGH_WATERMARK(line_time))); |
| 1088 | /* restore original selection */ |
| 1089 | WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3); |
| 1090 | |
| 1091 | /* write the priority marks */ |
| 1092 | WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt); |
| 1093 | WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt); |
| 1094 | |
| 1095 | } |
| 1096 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 1097 | /** |
| 1098 | * evergreen_bandwidth_update - update display watermarks callback. |
| 1099 | * |
| 1100 | * @rdev: radeon_device pointer |
| 1101 | * |
| 1102 | * Update the display watermarks based on the requested mode(s) |
| 1103 | * (evergreen+). |
| 1104 | */ |
Alex Deucher | 0ca2ab5 | 2010-02-26 13:57:45 -0500 | [diff] [blame] | 1105 | void evergreen_bandwidth_update(struct radeon_device *rdev) |
| 1106 | { |
Alex Deucher | f9d9c36 | 2010-10-22 02:51:05 -0400 | [diff] [blame] | 1107 | struct drm_display_mode *mode0 = NULL; |
| 1108 | struct drm_display_mode *mode1 = NULL; |
| 1109 | u32 num_heads = 0, lb_size; |
| 1110 | int i; |
| 1111 | |
| 1112 | radeon_update_display_priority(rdev); |
| 1113 | |
| 1114 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1115 | if (rdev->mode_info.crtcs[i]->base.enabled) |
| 1116 | num_heads++; |
| 1117 | } |
| 1118 | for (i = 0; i < rdev->num_crtc; i += 2) { |
| 1119 | mode0 = &rdev->mode_info.crtcs[i]->base.mode; |
| 1120 | mode1 = &rdev->mode_info.crtcs[i+1]->base.mode; |
| 1121 | lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1); |
| 1122 | evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads); |
| 1123 | lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0); |
| 1124 | evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads); |
| 1125 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1126 | } |
| 1127 | |
Alex Deucher | 377edc8 | 2012-07-17 14:02:42 -0400 | [diff] [blame] | 1128 | /** |
| 1129 | * evergreen_mc_wait_for_idle - wait for MC idle callback. |
| 1130 | * |
| 1131 | * @rdev: radeon_device pointer |
| 1132 | * |
| 1133 | * Wait for the MC (memory controller) to be idle. |
| 1134 | * (evergreen+). |
| 1135 | * Returns 0 if the MC is idle, -1 if not. |
| 1136 | */ |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1137 | int evergreen_mc_wait_for_idle(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1138 | { |
| 1139 | unsigned i; |
| 1140 | u32 tmp; |
| 1141 | |
| 1142 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1143 | /* read MC_STATUS */ |
| 1144 | tmp = RREG32(SRBM_STATUS) & 0x1F00; |
| 1145 | if (!tmp) |
| 1146 | return 0; |
| 1147 | udelay(1); |
| 1148 | } |
| 1149 | return -1; |
| 1150 | } |
| 1151 | |
| 1152 | /* |
| 1153 | * GART |
| 1154 | */ |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1155 | void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev) |
| 1156 | { |
| 1157 | unsigned i; |
| 1158 | u32 tmp; |
| 1159 | |
Alex Deucher | 6f2f48a | 2010-12-15 11:01:56 -0500 | [diff] [blame] | 1160 | WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
| 1161 | |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1162 | WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1)); |
| 1163 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1164 | /* read MC_STATUS */ |
| 1165 | tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE); |
| 1166 | tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT; |
| 1167 | if (tmp == 2) { |
| 1168 | printk(KERN_WARNING "[drm] r600 flush TLB failed\n"); |
| 1169 | return; |
| 1170 | } |
| 1171 | if (tmp) { |
| 1172 | return; |
| 1173 | } |
| 1174 | udelay(1); |
| 1175 | } |
| 1176 | } |
| 1177 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1178 | static int evergreen_pcie_gart_enable(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1179 | { |
| 1180 | u32 tmp; |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1181 | int r; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1182 | |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 1183 | if (rdev->gart.robj == NULL) { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1184 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 1185 | return -EINVAL; |
| 1186 | } |
| 1187 | r = radeon_gart_table_vram_pin(rdev); |
| 1188 | if (r) |
| 1189 | return r; |
Dave Airlie | 8256856 | 2010-02-05 16:00:07 +1000 | [diff] [blame] | 1190 | radeon_gart_restore(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1191 | /* Setup L2 cache */ |
| 1192 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 1193 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1194 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 1195 | WREG32(VM_L2_CNTL2, 0); |
| 1196 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 1197 | /* Setup TLB control */ |
| 1198 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 1199 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 1200 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | |
| 1201 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
Alex Deucher | 8aeb96f | 2011-05-03 19:28:02 -0400 | [diff] [blame] | 1202 | if (rdev->flags & RADEON_IS_IGP) { |
| 1203 | WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 1204 | WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 1205 | WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp); |
| 1206 | } else { |
| 1207 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 1208 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 1209 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
Alex Deucher | 0b8c30b | 2012-05-31 18:54:43 -0400 | [diff] [blame] | 1210 | if ((rdev->family == CHIP_JUNIPER) || |
| 1211 | (rdev->family == CHIP_CYPRESS) || |
| 1212 | (rdev->family == CHIP_HEMLOCK) || |
| 1213 | (rdev->family == CHIP_BARTS)) |
| 1214 | WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp); |
Alex Deucher | 8aeb96f | 2011-05-03 19:28:02 -0400 | [diff] [blame] | 1215 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1216 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 1217 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 1218 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 1219 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
| 1220 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); |
| 1221 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); |
| 1222 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); |
| 1223 | WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 1224 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
| 1225 | WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, |
| 1226 | (u32)(rdev->dummy_page.addr >> 12)); |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1227 | WREG32(VM_CONTEXT1_CNTL, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1228 | |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1229 | evergreen_pcie_gart_tlb_flush(rdev); |
Tormod Volden | fcf4de5 | 2011-08-31 21:54:07 +0000 | [diff] [blame] | 1230 | DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n", |
| 1231 | (unsigned)(rdev->mc.gtt_size >> 20), |
| 1232 | (unsigned long long)rdev->gart.table_addr); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1233 | rdev->gart.ready = true; |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1237 | static void evergreen_pcie_gart_disable(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1238 | { |
| 1239 | u32 tmp; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1240 | |
| 1241 | /* Disable all tables */ |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1242 | WREG32(VM_CONTEXT0_CNTL, 0); |
| 1243 | WREG32(VM_CONTEXT1_CNTL, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1244 | |
| 1245 | /* Setup L2 cache */ |
| 1246 | WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING | |
| 1247 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 1248 | WREG32(VM_L2_CNTL2, 0); |
| 1249 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 1250 | /* Setup TLB control */ |
| 1251 | tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
| 1252 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 1253 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 1254 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
| 1255 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 1256 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 1257 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 1258 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 1259 | radeon_gart_table_vram_unpin(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1260 | } |
| 1261 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1262 | static void evergreen_pcie_gart_fini(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1263 | { |
| 1264 | evergreen_pcie_gart_disable(rdev); |
| 1265 | radeon_gart_table_vram_free(rdev); |
| 1266 | radeon_gart_fini(rdev); |
| 1267 | } |
| 1268 | |
| 1269 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1270 | static void evergreen_agp_enable(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1271 | { |
| 1272 | u32 tmp; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1273 | |
| 1274 | /* Setup L2 cache */ |
| 1275 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 1276 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1277 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 1278 | WREG32(VM_L2_CNTL2, 0); |
| 1279 | WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); |
| 1280 | /* Setup TLB control */ |
| 1281 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 1282 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 1283 | SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | |
| 1284 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); |
| 1285 | WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); |
| 1286 | WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); |
| 1287 | WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); |
| 1288 | WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); |
| 1289 | WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); |
| 1290 | WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); |
| 1291 | WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 1292 | WREG32(VM_CONTEXT0_CNTL, 0); |
| 1293 | WREG32(VM_CONTEXT1_CNTL, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1294 | } |
| 1295 | |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1296 | void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1297 | { |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1298 | u32 crtc_enabled, tmp, frame_count, blackout; |
| 1299 | int i, j; |
| 1300 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1301 | save->vga_render_control = RREG32(VGA_RENDER_CONTROL); |
| 1302 | save->vga_hdp_control = RREG32(VGA_HDP_CONTROL); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1303 | |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1304 | /* disable VGA render */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1305 | WREG32(VGA_RENDER_CONTROL, 0); |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1306 | /* blank the display controllers */ |
| 1307 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1308 | crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN; |
| 1309 | if (crtc_enabled) { |
| 1310 | save->crtc_enabled[i] = true; |
| 1311 | if (ASIC_IS_DCE6(rdev)) { |
| 1312 | tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]); |
| 1313 | if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) { |
| 1314 | radeon_wait_for_vblank(rdev, i); |
| 1315 | tmp |= EVERGREEN_CRTC_BLANK_DATA_EN; |
| 1316 | WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp); |
| 1317 | } |
| 1318 | } else { |
| 1319 | tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]); |
| 1320 | if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) { |
| 1321 | radeon_wait_for_vblank(rdev, i); |
| 1322 | tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE; |
| 1323 | WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp); |
| 1324 | } |
| 1325 | } |
| 1326 | /* wait for the next frame */ |
| 1327 | frame_count = radeon_get_vblank_counter(rdev, i); |
| 1328 | for (j = 0; j < rdev->usec_timeout; j++) { |
| 1329 | if (radeon_get_vblank_counter(rdev, i) != frame_count) |
| 1330 | break; |
| 1331 | udelay(1); |
| 1332 | } |
Alex Deucher | 804cc4a0 | 2012-11-19 09:11:27 -0500 | [diff] [blame] | 1333 | } else { |
| 1334 | save->crtc_enabled[i] = false; |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1335 | } |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 1336 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1337 | |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1338 | radeon_mc_wait_for_idle(rdev); |
| 1339 | |
| 1340 | blackout = RREG32(MC_SHARED_BLACKOUT_CNTL); |
| 1341 | if ((blackout & BLACKOUT_MODE_MASK) != 1) { |
| 1342 | /* Block CPU access */ |
| 1343 | WREG32(BIF_FB_EN, 0); |
| 1344 | /* blackout the MC */ |
| 1345 | blackout &= ~BLACKOUT_MODE_MASK; |
| 1346 | WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 1347 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1348 | } |
| 1349 | |
Alex Deucher | b9952a8 | 2011-03-02 20:07:33 -0500 | [diff] [blame] | 1350 | void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1351 | { |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1352 | u32 tmp, frame_count; |
| 1353 | int i, j; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1354 | |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1355 | /* update crtc base addresses */ |
| 1356 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1357 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i], |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 1358 | upper_32_bits(rdev->mc.vram_start)); |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1359 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i], |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 1360 | upper_32_bits(rdev->mc.vram_start)); |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1361 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i], |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 1362 | (u32)rdev->mc.vram_start); |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1363 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i], |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 1364 | (u32)rdev->mc.vram_start); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 1365 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1366 | WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start)); |
| 1367 | WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start); |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1368 | |
| 1369 | /* unblackout the MC */ |
| 1370 | tmp = RREG32(MC_SHARED_BLACKOUT_CNTL); |
| 1371 | tmp &= ~BLACKOUT_MODE_MASK; |
| 1372 | WREG32(MC_SHARED_BLACKOUT_CNTL, tmp); |
| 1373 | /* allow CPU access */ |
| 1374 | WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN); |
| 1375 | |
| 1376 | for (i = 0; i < rdev->num_crtc; i++) { |
Alex Deucher | 695ddeb | 2012-11-05 16:34:58 +0000 | [diff] [blame] | 1377 | if (save->crtc_enabled[i]) { |
Alex Deucher | 62444b7 | 2012-08-15 17:18:42 -0400 | [diff] [blame] | 1378 | if (ASIC_IS_DCE6(rdev)) { |
| 1379 | tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]); |
| 1380 | tmp |= EVERGREEN_CRTC_BLANK_DATA_EN; |
| 1381 | WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp); |
| 1382 | } else { |
| 1383 | tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]); |
| 1384 | tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE; |
| 1385 | WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp); |
| 1386 | } |
| 1387 | /* wait for the next frame */ |
| 1388 | frame_count = radeon_get_vblank_counter(rdev, i); |
| 1389 | for (j = 0; j < rdev->usec_timeout; j++) { |
| 1390 | if (radeon_get_vblank_counter(rdev, i) != frame_count) |
| 1391 | break; |
| 1392 | udelay(1); |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | /* Unlock vga access */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1397 | WREG32(VGA_HDP_CONTROL, save->vga_hdp_control); |
| 1398 | mdelay(1); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1399 | WREG32(VGA_RENDER_CONTROL, save->vga_render_control); |
| 1400 | } |
| 1401 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 1402 | void evergreen_mc_program(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1403 | { |
| 1404 | struct evergreen_mc_save save; |
| 1405 | u32 tmp; |
| 1406 | int i, j; |
| 1407 | |
| 1408 | /* Initialize HDP */ |
| 1409 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 1410 | WREG32((0x2c14 + j), 0x00000000); |
| 1411 | WREG32((0x2c18 + j), 0x00000000); |
| 1412 | WREG32((0x2c1c + j), 0x00000000); |
| 1413 | WREG32((0x2c20 + j), 0x00000000); |
| 1414 | WREG32((0x2c24 + j), 0x00000000); |
| 1415 | } |
| 1416 | WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0); |
| 1417 | |
| 1418 | evergreen_mc_stop(rdev, &save); |
| 1419 | if (evergreen_mc_wait_for_idle(rdev)) { |
| 1420 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
| 1421 | } |
| 1422 | /* Lockout access through VGA aperture*/ |
| 1423 | WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE); |
| 1424 | /* Update configuration */ |
| 1425 | if (rdev->flags & RADEON_IS_AGP) { |
| 1426 | if (rdev->mc.vram_start < rdev->mc.gtt_start) { |
| 1427 | /* VRAM before AGP */ |
| 1428 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 1429 | rdev->mc.vram_start >> 12); |
| 1430 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 1431 | rdev->mc.gtt_end >> 12); |
| 1432 | } else { |
| 1433 | /* VRAM after AGP */ |
| 1434 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 1435 | rdev->mc.gtt_start >> 12); |
| 1436 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 1437 | rdev->mc.vram_end >> 12); |
| 1438 | } |
| 1439 | } else { |
| 1440 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 1441 | rdev->mc.vram_start >> 12); |
| 1442 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 1443 | rdev->mc.vram_end >> 12); |
| 1444 | } |
Alex Deucher | 3b9832f | 2011-11-10 08:59:39 -0500 | [diff] [blame] | 1445 | WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12); |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 1446 | /* llano/ontario only */ |
| 1447 | if ((rdev->family == CHIP_PALM) || |
| 1448 | (rdev->family == CHIP_SUMO) || |
| 1449 | (rdev->family == CHIP_SUMO2)) { |
Alex Deucher | b4183e3 | 2010-12-15 11:04:10 -0500 | [diff] [blame] | 1450 | tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF; |
| 1451 | tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24; |
| 1452 | tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20; |
| 1453 | WREG32(MC_FUS_VM_FB_OFFSET, tmp); |
| 1454 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1455 | tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; |
| 1456 | tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); |
| 1457 | WREG32(MC_VM_FB_LOCATION, tmp); |
| 1458 | WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8)); |
Alex Deucher | c46cb4d | 2011-01-06 19:12:37 -0500 | [diff] [blame] | 1459 | WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30)); |
Jerome Glisse | 46fcd2b | 2010-06-03 19:34:48 +0200 | [diff] [blame] | 1460 | WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1461 | if (rdev->flags & RADEON_IS_AGP) { |
| 1462 | WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16); |
| 1463 | WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16); |
| 1464 | WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22); |
| 1465 | } else { |
| 1466 | WREG32(MC_VM_AGP_BASE, 0); |
| 1467 | WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF); |
| 1468 | WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF); |
| 1469 | } |
| 1470 | if (evergreen_mc_wait_for_idle(rdev)) { |
| 1471 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
| 1472 | } |
| 1473 | evergreen_mc_resume(rdev, &save); |
| 1474 | /* we need to own VRAM, so turn off the VGA renderer here |
| 1475 | * to stop it overwriting our objects */ |
| 1476 | rv515_vga_render_disable(rdev); |
| 1477 | } |
| 1478 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1479 | /* |
| 1480 | * CP. |
| 1481 | */ |
Alex Deucher | 1292059 | 2011-02-02 12:37:40 -0500 | [diff] [blame] | 1482 | void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 1483 | { |
Christian König | 876dc9f | 2012-05-08 14:24:01 +0200 | [diff] [blame] | 1484 | struct radeon_ring *ring = &rdev->ring[ib->ring]; |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 1485 | u32 next_rptr; |
Christian König | 7b1f248 | 2011-09-23 15:11:23 +0200 | [diff] [blame] | 1486 | |
Alex Deucher | 1292059 | 2011-02-02 12:37:40 -0500 | [diff] [blame] | 1487 | /* set to DX10/11 mode */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1488 | radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0)); |
| 1489 | radeon_ring_write(ring, 1); |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 1490 | |
| 1491 | if (ring->rptr_save_reg) { |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 1492 | next_rptr = ring->wptr + 3 + 4; |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 1493 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 1494 | radeon_ring_write(ring, ((ring->rptr_save_reg - |
| 1495 | PACKET3_SET_CONFIG_REG_START) >> 2)); |
| 1496 | radeon_ring_write(ring, next_rptr); |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 1497 | } else if (rdev->wb.enabled) { |
| 1498 | next_rptr = ring->wptr + 5 + 4; |
| 1499 | radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3)); |
| 1500 | radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc); |
| 1501 | radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18)); |
| 1502 | radeon_ring_write(ring, next_rptr); |
| 1503 | radeon_ring_write(ring, 0); |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 1504 | } |
| 1505 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1506 | radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2)); |
| 1507 | radeon_ring_write(ring, |
Alex Deucher | 0f234f5f | 2011-02-13 19:06:33 -0500 | [diff] [blame] | 1508 | #ifdef __BIG_ENDIAN |
| 1509 | (2 << 0) | |
| 1510 | #endif |
| 1511 | (ib->gpu_addr & 0xFFFFFFFC)); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1512 | radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF); |
| 1513 | radeon_ring_write(ring, ib->length_dw); |
Alex Deucher | 1292059 | 2011-02-02 12:37:40 -0500 | [diff] [blame] | 1514 | } |
| 1515 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1516 | |
| 1517 | static int evergreen_cp_load_microcode(struct radeon_device *rdev) |
| 1518 | { |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1519 | const __be32 *fw_data; |
| 1520 | int i; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1521 | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1522 | if (!rdev->me_fw || !rdev->pfp_fw) |
| 1523 | return -EINVAL; |
| 1524 | |
| 1525 | r700_cp_stop(rdev); |
Alex Deucher | 0f234f5f | 2011-02-13 19:06:33 -0500 | [diff] [blame] | 1526 | WREG32(CP_RB_CNTL, |
| 1527 | #ifdef __BIG_ENDIAN |
| 1528 | BUF_SWAP_32BIT | |
| 1529 | #endif |
| 1530 | RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3)); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1531 | |
| 1532 | fw_data = (const __be32 *)rdev->pfp_fw->data; |
| 1533 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1534 | for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++) |
| 1535 | WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 1536 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1537 | |
| 1538 | fw_data = (const __be32 *)rdev->me_fw->data; |
| 1539 | WREG32(CP_ME_RAM_WADDR, 0); |
| 1540 | for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++) |
| 1541 | WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++)); |
| 1542 | |
| 1543 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 1544 | WREG32(CP_ME_RAM_WADDR, 0); |
| 1545 | WREG32(CP_ME_RAM_RADDR, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1546 | return 0; |
| 1547 | } |
| 1548 | |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1549 | static int evergreen_cp_start(struct radeon_device *rdev) |
| 1550 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1551 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1552 | int r, i; |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1553 | uint32_t cp_me; |
| 1554 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1555 | r = radeon_ring_lock(rdev, ring, 7); |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1556 | if (r) { |
| 1557 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 1558 | return r; |
| 1559 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1560 | radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5)); |
| 1561 | radeon_ring_write(ring, 0x1); |
| 1562 | radeon_ring_write(ring, 0x0); |
| 1563 | radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1); |
| 1564 | radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1)); |
| 1565 | radeon_ring_write(ring, 0); |
| 1566 | radeon_ring_write(ring, 0); |
| 1567 | radeon_ring_unlock_commit(rdev, ring); |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1568 | |
| 1569 | cp_me = 0xff; |
| 1570 | WREG32(CP_ME_CNTL, cp_me); |
| 1571 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1572 | r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19); |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1573 | if (r) { |
| 1574 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 1575 | return r; |
| 1576 | } |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1577 | |
| 1578 | /* setup clear context state */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1579 | radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0)); |
| 1580 | radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1581 | |
| 1582 | for (i = 0; i < evergreen_default_size; i++) |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1583 | radeon_ring_write(ring, evergreen_default_state[i]); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1584 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1585 | radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0)); |
| 1586 | radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1587 | |
| 1588 | /* set clear context state */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1589 | radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0)); |
| 1590 | radeon_ring_write(ring, 0); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1591 | |
| 1592 | /* SQ_VTX_BASE_VTX_LOC */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1593 | radeon_ring_write(ring, 0xc0026f00); |
| 1594 | radeon_ring_write(ring, 0x00000000); |
| 1595 | radeon_ring_write(ring, 0x00000000); |
| 1596 | radeon_ring_write(ring, 0x00000000); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1597 | |
| 1598 | /* Clear consts */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1599 | radeon_ring_write(ring, 0xc0036f00); |
| 1600 | radeon_ring_write(ring, 0x00000bc4); |
| 1601 | radeon_ring_write(ring, 0xffffffff); |
| 1602 | radeon_ring_write(ring, 0xffffffff); |
| 1603 | radeon_ring_write(ring, 0xffffffff); |
Alex Deucher | 2281a37 | 2010-10-21 13:31:38 -0400 | [diff] [blame] | 1604 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1605 | radeon_ring_write(ring, 0xc0026900); |
| 1606 | radeon_ring_write(ring, 0x00000316); |
| 1607 | radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */ |
| 1608 | radeon_ring_write(ring, 0x00000010); /* */ |
Alex Deucher | 18ff84d | 2011-02-02 12:37:41 -0500 | [diff] [blame] | 1609 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1610 | radeon_ring_unlock_commit(rdev, ring); |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1611 | |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1615 | static int evergreen_cp_resume(struct radeon_device *rdev) |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1616 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1617 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1618 | u32 tmp; |
| 1619 | u32 rb_bufsz; |
| 1620 | int r; |
| 1621 | |
| 1622 | /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */ |
| 1623 | WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP | |
| 1624 | SOFT_RESET_PA | |
| 1625 | SOFT_RESET_SH | |
| 1626 | SOFT_RESET_VGT | |
Jerome Glisse | a49a50d | 2011-08-24 20:00:17 +0000 | [diff] [blame] | 1627 | SOFT_RESET_SPI | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1628 | SOFT_RESET_SX)); |
| 1629 | RREG32(GRBM_SOFT_RESET); |
| 1630 | mdelay(15); |
| 1631 | WREG32(GRBM_SOFT_RESET, 0); |
| 1632 | RREG32(GRBM_SOFT_RESET); |
| 1633 | |
| 1634 | /* Set ring buffer size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1635 | rb_bufsz = drm_order(ring->ring_size / 8); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1636 | tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1637 | #ifdef __BIG_ENDIAN |
| 1638 | tmp |= BUF_SWAP_32BIT; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1639 | #endif |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1640 | WREG32(CP_RB_CNTL, tmp); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 1641 | WREG32(CP_SEM_WAIT_TIMER, 0x0); |
Alex Deucher | 11ef3f1 | 2012-01-20 14:47:43 -0500 | [diff] [blame] | 1642 | WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1643 | |
| 1644 | /* Set the write pointer delay */ |
| 1645 | WREG32(CP_RB_WPTR_DELAY, 0); |
| 1646 | |
| 1647 | /* Initialize the ring buffer's read and write pointers */ |
| 1648 | WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA); |
| 1649 | WREG32(CP_RB_RPTR_WR, 0); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1650 | ring->wptr = 0; |
| 1651 | WREG32(CP_RB_WPTR, ring->wptr); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1652 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 1653 | /* set the wb address whether it's enabled or not */ |
Alex Deucher | 0f234f5f | 2011-02-13 19:06:33 -0500 | [diff] [blame] | 1654 | WREG32(CP_RB_RPTR_ADDR, |
Alex Deucher | 0f234f5f | 2011-02-13 19:06:33 -0500 | [diff] [blame] | 1655 | ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC)); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 1656 | WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF); |
| 1657 | WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF); |
| 1658 | |
| 1659 | if (rdev->wb.enabled) |
| 1660 | WREG32(SCRATCH_UMSK, 0xff); |
| 1661 | else { |
| 1662 | tmp |= RB_NO_UPDATE; |
| 1663 | WREG32(SCRATCH_UMSK, 0); |
| 1664 | } |
| 1665 | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1666 | mdelay(1); |
| 1667 | WREG32(CP_RB_CNTL, tmp); |
| 1668 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1669 | WREG32(CP_RB_BASE, ring->gpu_addr >> 8); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1670 | WREG32(CP_DEBUG, (1 << 27) | (1 << 28)); |
| 1671 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1672 | ring->rptr = RREG32(CP_RB_RPTR); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1673 | |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 1674 | evergreen_cp_start(rdev); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1675 | ring->ready = true; |
Alex Deucher | f712812 | 2012-02-23 17:53:45 -0500 | [diff] [blame] | 1676 | r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1677 | if (r) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 1678 | ring->ready = false; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 1679 | return r; |
| 1680 | } |
| 1681 | return 0; |
| 1682 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1683 | |
| 1684 | /* |
| 1685 | * Core functions |
| 1686 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1687 | static void evergreen_gpu_init(struct radeon_device *rdev) |
| 1688 | { |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1689 | u32 gb_addr_config; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1690 | u32 mc_shared_chmap, mc_arb_ramcfg; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1691 | u32 sx_debug_1; |
| 1692 | u32 smx_dc_ctl0; |
| 1693 | u32 sq_config; |
| 1694 | u32 sq_lds_resource_mgmt; |
| 1695 | u32 sq_gpr_resource_mgmt_1; |
| 1696 | u32 sq_gpr_resource_mgmt_2; |
| 1697 | u32 sq_gpr_resource_mgmt_3; |
| 1698 | u32 sq_thread_resource_mgmt; |
| 1699 | u32 sq_thread_resource_mgmt_2; |
| 1700 | u32 sq_stack_resource_mgmt_1; |
| 1701 | u32 sq_stack_resource_mgmt_2; |
| 1702 | u32 sq_stack_resource_mgmt_3; |
| 1703 | u32 vgt_cache_invalidation; |
Alex Deucher | f25a5c6 | 2011-05-19 11:07:57 -0400 | [diff] [blame] | 1704 | u32 hdp_host_path_cntl, tmp; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1705 | u32 disabled_rb_mask; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1706 | int i, j, num_shader_engines, ps_thread_count; |
| 1707 | |
| 1708 | switch (rdev->family) { |
| 1709 | case CHIP_CYPRESS: |
| 1710 | case CHIP_HEMLOCK: |
| 1711 | rdev->config.evergreen.num_ses = 2; |
| 1712 | rdev->config.evergreen.max_pipes = 4; |
| 1713 | rdev->config.evergreen.max_tile_pipes = 8; |
| 1714 | rdev->config.evergreen.max_simds = 10; |
| 1715 | rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses; |
| 1716 | rdev->config.evergreen.max_gprs = 256; |
| 1717 | rdev->config.evergreen.max_threads = 248; |
| 1718 | rdev->config.evergreen.max_gs_threads = 32; |
| 1719 | rdev->config.evergreen.max_stack_entries = 512; |
| 1720 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1721 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1722 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1723 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1724 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1725 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1726 | |
| 1727 | rdev->config.evergreen.sc_prim_fifo_size = 0x100; |
| 1728 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1729 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1730 | gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1731 | break; |
| 1732 | case CHIP_JUNIPER: |
| 1733 | rdev->config.evergreen.num_ses = 1; |
| 1734 | rdev->config.evergreen.max_pipes = 4; |
| 1735 | rdev->config.evergreen.max_tile_pipes = 4; |
| 1736 | rdev->config.evergreen.max_simds = 10; |
| 1737 | rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses; |
| 1738 | rdev->config.evergreen.max_gprs = 256; |
| 1739 | rdev->config.evergreen.max_threads = 248; |
| 1740 | rdev->config.evergreen.max_gs_threads = 32; |
| 1741 | rdev->config.evergreen.max_stack_entries = 512; |
| 1742 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1743 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1744 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1745 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1746 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1747 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1748 | |
| 1749 | rdev->config.evergreen.sc_prim_fifo_size = 0x100; |
| 1750 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1751 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1752 | gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1753 | break; |
| 1754 | case CHIP_REDWOOD: |
| 1755 | rdev->config.evergreen.num_ses = 1; |
| 1756 | rdev->config.evergreen.max_pipes = 4; |
| 1757 | rdev->config.evergreen.max_tile_pipes = 4; |
| 1758 | rdev->config.evergreen.max_simds = 5; |
| 1759 | rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses; |
| 1760 | rdev->config.evergreen.max_gprs = 256; |
| 1761 | rdev->config.evergreen.max_threads = 248; |
| 1762 | rdev->config.evergreen.max_gs_threads = 32; |
| 1763 | rdev->config.evergreen.max_stack_entries = 256; |
| 1764 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1765 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1766 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1767 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1768 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1769 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1770 | |
| 1771 | rdev->config.evergreen.sc_prim_fifo_size = 0x100; |
| 1772 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1773 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1774 | gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1775 | break; |
| 1776 | case CHIP_CEDAR: |
| 1777 | default: |
| 1778 | rdev->config.evergreen.num_ses = 1; |
| 1779 | rdev->config.evergreen.max_pipes = 2; |
| 1780 | rdev->config.evergreen.max_tile_pipes = 2; |
| 1781 | rdev->config.evergreen.max_simds = 2; |
| 1782 | rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses; |
| 1783 | rdev->config.evergreen.max_gprs = 256; |
| 1784 | rdev->config.evergreen.max_threads = 192; |
| 1785 | rdev->config.evergreen.max_gs_threads = 16; |
| 1786 | rdev->config.evergreen.max_stack_entries = 256; |
| 1787 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1788 | rdev->config.evergreen.sx_max_export_size = 128; |
| 1789 | rdev->config.evergreen.sx_max_export_pos_size = 32; |
| 1790 | rdev->config.evergreen.sx_max_export_smx_size = 96; |
| 1791 | rdev->config.evergreen.max_hw_contexts = 4; |
| 1792 | rdev->config.evergreen.sq_num_cf_insts = 1; |
| 1793 | |
| 1794 | rdev->config.evergreen.sc_prim_fifo_size = 0x40; |
| 1795 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1796 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1797 | gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1798 | break; |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 1799 | case CHIP_PALM: |
| 1800 | rdev->config.evergreen.num_ses = 1; |
| 1801 | rdev->config.evergreen.max_pipes = 2; |
| 1802 | rdev->config.evergreen.max_tile_pipes = 2; |
| 1803 | rdev->config.evergreen.max_simds = 2; |
| 1804 | rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses; |
| 1805 | rdev->config.evergreen.max_gprs = 256; |
| 1806 | rdev->config.evergreen.max_threads = 192; |
| 1807 | rdev->config.evergreen.max_gs_threads = 16; |
| 1808 | rdev->config.evergreen.max_stack_entries = 256; |
| 1809 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1810 | rdev->config.evergreen.sx_max_export_size = 128; |
| 1811 | rdev->config.evergreen.sx_max_export_pos_size = 32; |
| 1812 | rdev->config.evergreen.sx_max_export_smx_size = 96; |
| 1813 | rdev->config.evergreen.max_hw_contexts = 4; |
| 1814 | rdev->config.evergreen.sq_num_cf_insts = 1; |
| 1815 | |
| 1816 | rdev->config.evergreen.sc_prim_fifo_size = 0x40; |
| 1817 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1818 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1819 | gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 1820 | break; |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 1821 | case CHIP_SUMO: |
| 1822 | rdev->config.evergreen.num_ses = 1; |
| 1823 | rdev->config.evergreen.max_pipes = 4; |
Jerome Glisse | bd25f07 | 2012-12-11 11:56:52 -0500 | [diff] [blame] | 1824 | rdev->config.evergreen.max_tile_pipes = 4; |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 1825 | if (rdev->pdev->device == 0x9648) |
| 1826 | rdev->config.evergreen.max_simds = 3; |
| 1827 | else if ((rdev->pdev->device == 0x9647) || |
| 1828 | (rdev->pdev->device == 0x964a)) |
| 1829 | rdev->config.evergreen.max_simds = 4; |
| 1830 | else |
| 1831 | rdev->config.evergreen.max_simds = 5; |
| 1832 | rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses; |
| 1833 | rdev->config.evergreen.max_gprs = 256; |
| 1834 | rdev->config.evergreen.max_threads = 248; |
| 1835 | rdev->config.evergreen.max_gs_threads = 32; |
| 1836 | rdev->config.evergreen.max_stack_entries = 256; |
| 1837 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1838 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1839 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1840 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1841 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1842 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1843 | |
| 1844 | rdev->config.evergreen.sc_prim_fifo_size = 0x40; |
| 1845 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1846 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Jerome Glisse | bd25f07 | 2012-12-11 11:56:52 -0500 | [diff] [blame] | 1847 | gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 1848 | break; |
| 1849 | case CHIP_SUMO2: |
| 1850 | rdev->config.evergreen.num_ses = 1; |
| 1851 | rdev->config.evergreen.max_pipes = 4; |
| 1852 | rdev->config.evergreen.max_tile_pipes = 4; |
| 1853 | rdev->config.evergreen.max_simds = 2; |
| 1854 | rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses; |
| 1855 | rdev->config.evergreen.max_gprs = 256; |
| 1856 | rdev->config.evergreen.max_threads = 248; |
| 1857 | rdev->config.evergreen.max_gs_threads = 32; |
| 1858 | rdev->config.evergreen.max_stack_entries = 512; |
| 1859 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1860 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1861 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1862 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1863 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1864 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1865 | |
| 1866 | rdev->config.evergreen.sc_prim_fifo_size = 0x40; |
| 1867 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1868 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Jerome Glisse | bd25f07 | 2012-12-11 11:56:52 -0500 | [diff] [blame] | 1869 | gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 1870 | break; |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 1871 | case CHIP_BARTS: |
| 1872 | rdev->config.evergreen.num_ses = 2; |
| 1873 | rdev->config.evergreen.max_pipes = 4; |
| 1874 | rdev->config.evergreen.max_tile_pipes = 8; |
| 1875 | rdev->config.evergreen.max_simds = 7; |
| 1876 | rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses; |
| 1877 | rdev->config.evergreen.max_gprs = 256; |
| 1878 | rdev->config.evergreen.max_threads = 248; |
| 1879 | rdev->config.evergreen.max_gs_threads = 32; |
| 1880 | rdev->config.evergreen.max_stack_entries = 512; |
| 1881 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1882 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1883 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1884 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1885 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1886 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1887 | |
| 1888 | rdev->config.evergreen.sc_prim_fifo_size = 0x100; |
| 1889 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1890 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1891 | gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 1892 | break; |
| 1893 | case CHIP_TURKS: |
| 1894 | rdev->config.evergreen.num_ses = 1; |
| 1895 | rdev->config.evergreen.max_pipes = 4; |
| 1896 | rdev->config.evergreen.max_tile_pipes = 4; |
| 1897 | rdev->config.evergreen.max_simds = 6; |
| 1898 | rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses; |
| 1899 | rdev->config.evergreen.max_gprs = 256; |
| 1900 | rdev->config.evergreen.max_threads = 248; |
| 1901 | rdev->config.evergreen.max_gs_threads = 32; |
| 1902 | rdev->config.evergreen.max_stack_entries = 256; |
| 1903 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1904 | rdev->config.evergreen.sx_max_export_size = 256; |
| 1905 | rdev->config.evergreen.sx_max_export_pos_size = 64; |
| 1906 | rdev->config.evergreen.sx_max_export_smx_size = 192; |
| 1907 | rdev->config.evergreen.max_hw_contexts = 8; |
| 1908 | rdev->config.evergreen.sq_num_cf_insts = 2; |
| 1909 | |
| 1910 | rdev->config.evergreen.sc_prim_fifo_size = 0x100; |
| 1911 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1912 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1913 | gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 1914 | break; |
| 1915 | case CHIP_CAICOS: |
| 1916 | rdev->config.evergreen.num_ses = 1; |
Jerome Glisse | bd25f07 | 2012-12-11 11:56:52 -0500 | [diff] [blame] | 1917 | rdev->config.evergreen.max_pipes = 2; |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 1918 | rdev->config.evergreen.max_tile_pipes = 2; |
| 1919 | rdev->config.evergreen.max_simds = 2; |
| 1920 | rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses; |
| 1921 | rdev->config.evergreen.max_gprs = 256; |
| 1922 | rdev->config.evergreen.max_threads = 192; |
| 1923 | rdev->config.evergreen.max_gs_threads = 16; |
| 1924 | rdev->config.evergreen.max_stack_entries = 256; |
| 1925 | rdev->config.evergreen.sx_num_of_sets = 4; |
| 1926 | rdev->config.evergreen.sx_max_export_size = 128; |
| 1927 | rdev->config.evergreen.sx_max_export_pos_size = 32; |
| 1928 | rdev->config.evergreen.sx_max_export_smx_size = 96; |
| 1929 | rdev->config.evergreen.max_hw_contexts = 4; |
| 1930 | rdev->config.evergreen.sq_num_cf_insts = 1; |
| 1931 | |
| 1932 | rdev->config.evergreen.sc_prim_fifo_size = 0x40; |
| 1933 | rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; |
| 1934 | rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1935 | gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN; |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 1936 | break; |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /* Initialize HDP */ |
| 1940 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 1941 | WREG32((0x2c14 + j), 0x00000000); |
| 1942 | WREG32((0x2c18 + j), 0x00000000); |
| 1943 | WREG32((0x2c1c + j), 0x00000000); |
| 1944 | WREG32((0x2c20 + j), 0x00000000); |
| 1945 | WREG32((0x2c24 + j), 0x00000000); |
| 1946 | } |
| 1947 | |
| 1948 | WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff)); |
| 1949 | |
Alex Deucher | d054ac1 | 2011-09-01 17:46:15 +0000 | [diff] [blame] | 1950 | evergreen_fix_pci_max_read_req_size(rdev); |
| 1951 | |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1952 | mc_shared_chmap = RREG32(MC_SHARED_CHMAP); |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 1953 | if ((rdev->family == CHIP_PALM) || |
| 1954 | (rdev->family == CHIP_SUMO) || |
| 1955 | (rdev->family == CHIP_SUMO2)) |
Alex Deucher | d9282fc | 2011-05-11 03:15:24 -0400 | [diff] [blame] | 1956 | mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG); |
| 1957 | else |
| 1958 | mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 1959 | |
Alex Deucher | 1aa52bd | 2010-11-17 12:11:03 -0500 | [diff] [blame] | 1960 | /* setup tiling info dword. gb_addr_config is not adequate since it does |
| 1961 | * not have bank info, so create a custom tiling dword. |
| 1962 | * bits 3:0 num_pipes |
| 1963 | * bits 7:4 num_banks |
| 1964 | * bits 11:8 group_size |
| 1965 | * bits 15:12 row_size |
| 1966 | */ |
| 1967 | rdev->config.evergreen.tile_config = 0; |
| 1968 | switch (rdev->config.evergreen.max_tile_pipes) { |
| 1969 | case 1: |
| 1970 | default: |
| 1971 | rdev->config.evergreen.tile_config |= (0 << 0); |
| 1972 | break; |
| 1973 | case 2: |
| 1974 | rdev->config.evergreen.tile_config |= (1 << 0); |
| 1975 | break; |
| 1976 | case 4: |
| 1977 | rdev->config.evergreen.tile_config |= (2 << 0); |
| 1978 | break; |
| 1979 | case 8: |
| 1980 | rdev->config.evergreen.tile_config |= (3 << 0); |
| 1981 | break; |
| 1982 | } |
Alex Deucher | d698a34 | 2011-06-23 00:49:29 -0400 | [diff] [blame] | 1983 | /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */ |
Alex Deucher | 5bfa487 | 2011-05-20 12:35:22 -0400 | [diff] [blame] | 1984 | if (rdev->flags & RADEON_IS_IGP) |
Alex Deucher | d698a34 | 2011-06-23 00:49:29 -0400 | [diff] [blame] | 1985 | rdev->config.evergreen.tile_config |= 1 << 4; |
Alex Deucher | 29d6540 | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 1986 | else { |
Alex Deucher | c8d15ed | 2012-07-31 11:01:10 -0400 | [diff] [blame] | 1987 | switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) { |
| 1988 | case 0: /* four banks */ |
Alex Deucher | 29d6540 | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 1989 | rdev->config.evergreen.tile_config |= 0 << 4; |
Alex Deucher | c8d15ed | 2012-07-31 11:01:10 -0400 | [diff] [blame] | 1990 | break; |
| 1991 | case 1: /* eight banks */ |
| 1992 | rdev->config.evergreen.tile_config |= 1 << 4; |
| 1993 | break; |
| 1994 | case 2: /* sixteen banks */ |
| 1995 | default: |
| 1996 | rdev->config.evergreen.tile_config |= 2 << 4; |
| 1997 | break; |
| 1998 | } |
Alex Deucher | 29d6540 | 2012-05-31 18:53:36 -0400 | [diff] [blame] | 1999 | } |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 2000 | rdev->config.evergreen.tile_config |= 0 << 8; |
Alex Deucher | 1aa52bd | 2010-11-17 12:11:03 -0500 | [diff] [blame] | 2001 | rdev->config.evergreen.tile_config |= |
| 2002 | ((gb_addr_config & 0x30000000) >> 28) << 12; |
| 2003 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 2004 | num_shader_engines = (gb_addr_config & NUM_SHADER_ENGINES(3) >> 12) + 1; |
| 2005 | |
| 2006 | if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) { |
| 2007 | u32 efuse_straps_4; |
| 2008 | u32 efuse_straps_3; |
| 2009 | |
| 2010 | WREG32(RCU_IND_INDEX, 0x204); |
| 2011 | efuse_straps_4 = RREG32(RCU_IND_DATA); |
| 2012 | WREG32(RCU_IND_INDEX, 0x203); |
| 2013 | efuse_straps_3 = RREG32(RCU_IND_DATA); |
| 2014 | tmp = (((efuse_straps_4 & 0xf) << 4) | |
| 2015 | ((efuse_straps_3 & 0xf0000000) >> 28)); |
| 2016 | } else { |
| 2017 | tmp = 0; |
| 2018 | for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) { |
| 2019 | u32 rb_disable_bitmap; |
| 2020 | |
| 2021 | WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i)); |
| 2022 | WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i)); |
| 2023 | rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16; |
| 2024 | tmp <<= 4; |
| 2025 | tmp |= rb_disable_bitmap; |
| 2026 | } |
| 2027 | } |
| 2028 | /* enabled rb are just the one not disabled :) */ |
| 2029 | disabled_rb_mask = tmp; |
| 2030 | |
| 2031 | WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES); |
| 2032 | WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES); |
| 2033 | |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2034 | WREG32(GB_ADDR_CONFIG, gb_addr_config); |
| 2035 | WREG32(DMIF_ADDR_CONFIG, gb_addr_config); |
| 2036 | WREG32(HDP_ADDR_CONFIG, gb_addr_config); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 2037 | WREG32(DMA_TILING_CONFIG, gb_addr_config); |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2038 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 2039 | tmp = gb_addr_config & NUM_PIPES_MASK; |
| 2040 | tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends, |
| 2041 | EVERGREEN_MAX_BACKENDS, disabled_rb_mask); |
| 2042 | WREG32(GB_BACKEND_MAP, tmp); |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2043 | |
| 2044 | WREG32(CGTS_SYS_TCC_DISABLE, 0); |
| 2045 | WREG32(CGTS_TCC_DISABLE, 0); |
| 2046 | WREG32(CGTS_USER_SYS_TCC_DISABLE, 0); |
| 2047 | WREG32(CGTS_USER_TCC_DISABLE, 0); |
| 2048 | |
| 2049 | /* set HW defaults for 3D engine */ |
| 2050 | WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | |
| 2051 | ROQ_IB2_START(0x2b))); |
| 2052 | |
| 2053 | WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30)); |
| 2054 | |
| 2055 | WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | |
| 2056 | SYNC_GRADIENT | |
| 2057 | SYNC_WALKER | |
| 2058 | SYNC_ALIGNER)); |
| 2059 | |
| 2060 | sx_debug_1 = RREG32(SX_DEBUG_1); |
| 2061 | sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS; |
| 2062 | WREG32(SX_DEBUG_1, sx_debug_1); |
| 2063 | |
| 2064 | |
| 2065 | smx_dc_ctl0 = RREG32(SMX_DC_CTL0); |
| 2066 | smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff); |
| 2067 | smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets); |
| 2068 | WREG32(SMX_DC_CTL0, smx_dc_ctl0); |
| 2069 | |
Alex Deucher | b866d13 | 2012-06-14 22:06:36 +0200 | [diff] [blame] | 2070 | if (rdev->family <= CHIP_SUMO2) |
| 2071 | WREG32(SMX_SAR_CTL0, 0x00010000); |
| 2072 | |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2073 | WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) | |
| 2074 | POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) | |
| 2075 | SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1))); |
| 2076 | |
| 2077 | WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) | |
| 2078 | SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) | |
| 2079 | SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size))); |
| 2080 | |
| 2081 | WREG32(VGT_NUM_INSTANCES, 1); |
| 2082 | WREG32(SPI_CONFIG_CNTL, 0); |
| 2083 | WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4)); |
| 2084 | WREG32(CP_PERFMON_CNTL, 0); |
| 2085 | |
| 2086 | WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) | |
| 2087 | FETCH_FIFO_HIWATER(0x4) | |
| 2088 | DONE_FIFO_HIWATER(0xe0) | |
| 2089 | ALU_UPDATE_FIFO_HIWATER(0x8))); |
| 2090 | |
| 2091 | sq_config = RREG32(SQ_CONFIG); |
| 2092 | sq_config &= ~(PS_PRIO(3) | |
| 2093 | VS_PRIO(3) | |
| 2094 | GS_PRIO(3) | |
| 2095 | ES_PRIO(3)); |
| 2096 | sq_config |= (VC_ENABLE | |
| 2097 | EXPORT_SRC_C | |
| 2098 | PS_PRIO(0) | |
| 2099 | VS_PRIO(1) | |
| 2100 | GS_PRIO(2) | |
| 2101 | ES_PRIO(3)); |
| 2102 | |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2103 | switch (rdev->family) { |
| 2104 | case CHIP_CEDAR: |
| 2105 | case CHIP_PALM: |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 2106 | case CHIP_SUMO: |
| 2107 | case CHIP_SUMO2: |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 2108 | case CHIP_CAICOS: |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2109 | /* no vertex cache */ |
| 2110 | sq_config &= ~VC_ENABLE; |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2111 | break; |
| 2112 | default: |
| 2113 | break; |
| 2114 | } |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2115 | |
| 2116 | sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT); |
| 2117 | |
| 2118 | sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32); |
| 2119 | sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32); |
| 2120 | sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4); |
| 2121 | sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32); |
| 2122 | sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32); |
| 2123 | sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32); |
| 2124 | sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32); |
| 2125 | |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2126 | switch (rdev->family) { |
| 2127 | case CHIP_CEDAR: |
| 2128 | case CHIP_PALM: |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 2129 | case CHIP_SUMO: |
| 2130 | case CHIP_SUMO2: |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2131 | ps_thread_count = 96; |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2132 | break; |
| 2133 | default: |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2134 | ps_thread_count = 128; |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2135 | break; |
| 2136 | } |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2137 | |
| 2138 | sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count); |
Alex Deucher | f96b35c | 2010-06-16 12:24:07 -0400 | [diff] [blame] | 2139 | sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8); |
| 2140 | sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8); |
| 2141 | sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8); |
| 2142 | sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8); |
| 2143 | sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8); |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2144 | |
| 2145 | sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2146 | sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2147 | sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2148 | sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2149 | sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2150 | sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6); |
| 2151 | |
| 2152 | WREG32(SQ_CONFIG, sq_config); |
| 2153 | WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1); |
| 2154 | WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2); |
| 2155 | WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3); |
| 2156 | WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt); |
| 2157 | WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2); |
| 2158 | WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1); |
| 2159 | WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2); |
| 2160 | WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3); |
| 2161 | WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0); |
| 2162 | WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt); |
| 2163 | |
| 2164 | WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) | |
| 2165 | FORCE_EOV_MAX_REZ_CNT(255))); |
| 2166 | |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2167 | switch (rdev->family) { |
| 2168 | case CHIP_CEDAR: |
| 2169 | case CHIP_PALM: |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 2170 | case CHIP_SUMO: |
| 2171 | case CHIP_SUMO2: |
Alex Deucher | adb68fa | 2011-01-06 21:19:24 -0500 | [diff] [blame] | 2172 | case CHIP_CAICOS: |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2173 | vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY); |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2174 | break; |
| 2175 | default: |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2176 | vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC); |
Alex Deucher | d5e455e | 2010-11-22 17:56:29 -0500 | [diff] [blame] | 2177 | break; |
| 2178 | } |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2179 | vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO); |
| 2180 | WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation); |
| 2181 | |
| 2182 | WREG32(VGT_GS_VERTEX_REUSE, 16); |
Alex Deucher | 1292059 | 2011-02-02 12:37:40 -0500 | [diff] [blame] | 2183 | WREG32(PA_SU_LINE_STIPPLE_VALUE, 0); |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2184 | WREG32(PA_SC_LINE_STIPPLE_STATE, 0); |
| 2185 | |
Alex Deucher | 60a4a3e | 2010-06-29 17:03:35 -0400 | [diff] [blame] | 2186 | WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14); |
| 2187 | WREG32(VGT_OUT_DEALLOC_CNTL, 16); |
| 2188 | |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2189 | WREG32(CB_PERF_CTR0_SEL_0, 0); |
| 2190 | WREG32(CB_PERF_CTR0_SEL_1, 0); |
| 2191 | WREG32(CB_PERF_CTR1_SEL_0, 0); |
| 2192 | WREG32(CB_PERF_CTR1_SEL_1, 0); |
| 2193 | WREG32(CB_PERF_CTR2_SEL_0, 0); |
| 2194 | WREG32(CB_PERF_CTR2_SEL_1, 0); |
| 2195 | WREG32(CB_PERF_CTR3_SEL_0, 0); |
| 2196 | WREG32(CB_PERF_CTR3_SEL_1, 0); |
| 2197 | |
Alex Deucher | 60a4a3e | 2010-06-29 17:03:35 -0400 | [diff] [blame] | 2198 | /* clear render buffer base addresses */ |
| 2199 | WREG32(CB_COLOR0_BASE, 0); |
| 2200 | WREG32(CB_COLOR1_BASE, 0); |
| 2201 | WREG32(CB_COLOR2_BASE, 0); |
| 2202 | WREG32(CB_COLOR3_BASE, 0); |
| 2203 | WREG32(CB_COLOR4_BASE, 0); |
| 2204 | WREG32(CB_COLOR5_BASE, 0); |
| 2205 | WREG32(CB_COLOR6_BASE, 0); |
| 2206 | WREG32(CB_COLOR7_BASE, 0); |
| 2207 | WREG32(CB_COLOR8_BASE, 0); |
| 2208 | WREG32(CB_COLOR9_BASE, 0); |
| 2209 | WREG32(CB_COLOR10_BASE, 0); |
| 2210 | WREG32(CB_COLOR11_BASE, 0); |
| 2211 | |
| 2212 | /* set the shader const cache sizes to 0 */ |
| 2213 | for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4) |
| 2214 | WREG32(i, 0); |
| 2215 | for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4) |
| 2216 | WREG32(i, 0); |
| 2217 | |
Alex Deucher | f25a5c6 | 2011-05-19 11:07:57 -0400 | [diff] [blame] | 2218 | tmp = RREG32(HDP_MISC_CNTL); |
| 2219 | tmp |= HDP_FLUSH_INVALIDATE_CACHE; |
| 2220 | WREG32(HDP_MISC_CNTL, tmp); |
| 2221 | |
Alex Deucher | 32fcdbf | 2010-03-24 13:33:47 -0400 | [diff] [blame] | 2222 | hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL); |
| 2223 | WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl); |
| 2224 | |
| 2225 | WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3)); |
| 2226 | |
| 2227 | udelay(50); |
| 2228 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | int evergreen_mc_init(struct radeon_device *rdev) |
| 2232 | { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2233 | u32 tmp; |
| 2234 | int chansize, numchan; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2235 | |
| 2236 | /* Get VRAM informations */ |
| 2237 | rdev->mc.vram_is_ddr = true; |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 2238 | if ((rdev->family == CHIP_PALM) || |
| 2239 | (rdev->family == CHIP_SUMO) || |
| 2240 | (rdev->family == CHIP_SUMO2)) |
Alex Deucher | 8208441 | 2011-07-01 13:18:28 -0400 | [diff] [blame] | 2241 | tmp = RREG32(FUS_MC_ARB_RAMCFG); |
| 2242 | else |
| 2243 | tmp = RREG32(MC_ARB_RAMCFG); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2244 | if (tmp & CHANSIZE_OVERRIDE) { |
| 2245 | chansize = 16; |
| 2246 | } else if (tmp & CHANSIZE_MASK) { |
| 2247 | chansize = 64; |
| 2248 | } else { |
| 2249 | chansize = 32; |
| 2250 | } |
| 2251 | tmp = RREG32(MC_SHARED_CHMAP); |
| 2252 | switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { |
| 2253 | case 0: |
| 2254 | default: |
| 2255 | numchan = 1; |
| 2256 | break; |
| 2257 | case 1: |
| 2258 | numchan = 2; |
| 2259 | break; |
| 2260 | case 2: |
| 2261 | numchan = 4; |
| 2262 | break; |
| 2263 | case 3: |
| 2264 | numchan = 8; |
| 2265 | break; |
| 2266 | } |
| 2267 | rdev->mc.vram_width = numchan * chansize; |
| 2268 | /* Could aper size report 0 ? */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 2269 | rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0); |
| 2270 | rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2271 | /* Setup GPU memory space */ |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 2272 | if ((rdev->family == CHIP_PALM) || |
| 2273 | (rdev->family == CHIP_SUMO) || |
| 2274 | (rdev->family == CHIP_SUMO2)) { |
Alex Deucher | 6eb18f8 | 2010-11-22 17:56:27 -0500 | [diff] [blame] | 2275 | /* size in bytes on fusion */ |
| 2276 | rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE); |
| 2277 | rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE); |
| 2278 | } else { |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 2279 | /* size in MB on evergreen/cayman/tn */ |
Alex Deucher | 6eb18f8 | 2010-11-22 17:56:27 -0500 | [diff] [blame] | 2280 | rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; |
| 2281 | rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; |
| 2282 | } |
Jerome Glisse | 51e5fcd | 2010-02-19 14:33:54 +0000 | [diff] [blame] | 2283 | rdev->mc.visible_vram_size = rdev->mc.aper_size; |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 2284 | r700_vram_gtt_location(rdev, &rdev->mc); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 2285 | radeon_update_bandwidth_info(rdev); |
| 2286 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2287 | return 0; |
| 2288 | } |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 2289 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2290 | bool evergreen_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 2291 | { |
Alex Deucher | 17db704 | 2010-12-21 16:05:39 -0500 | [diff] [blame] | 2292 | u32 srbm_status; |
| 2293 | u32 grbm_status; |
| 2294 | u32 grbm_status_se0, grbm_status_se1; |
Alex Deucher | 17db704 | 2010-12-21 16:05:39 -0500 | [diff] [blame] | 2295 | |
| 2296 | srbm_status = RREG32(SRBM_STATUS); |
| 2297 | grbm_status = RREG32(GRBM_STATUS); |
| 2298 | grbm_status_se0 = RREG32(GRBM_STATUS_SE0); |
| 2299 | grbm_status_se1 = RREG32(GRBM_STATUS_SE1); |
| 2300 | if (!(grbm_status & GUI_ACTIVE)) { |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 2301 | radeon_ring_lockup_update(ring); |
Alex Deucher | 17db704 | 2010-12-21 16:05:39 -0500 | [diff] [blame] | 2302 | return false; |
| 2303 | } |
| 2304 | /* force CP activities */ |
Christian König | 7b9ef16 | 2012-05-02 15:11:23 +0200 | [diff] [blame] | 2305 | radeon_ring_force_activity(rdev, ring); |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 2306 | return radeon_ring_test_lockup(rdev, ring); |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2309 | static int evergreen_gpu_soft_reset(struct radeon_device *rdev) |
| 2310 | { |
| 2311 | struct evergreen_mc_save save; |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2312 | u32 grbm_reset = 0; |
| 2313 | |
Alex Deucher | 8d96fe9 | 2011-01-21 15:38:22 +0000 | [diff] [blame] | 2314 | if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE)) |
| 2315 | return 0; |
| 2316 | |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2317 | dev_info(rdev->dev, "GPU softreset \n"); |
| 2318 | dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n", |
| 2319 | RREG32(GRBM_STATUS)); |
| 2320 | dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n", |
| 2321 | RREG32(GRBM_STATUS_SE0)); |
| 2322 | dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n", |
| 2323 | RREG32(GRBM_STATUS_SE1)); |
| 2324 | dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n", |
| 2325 | RREG32(SRBM_STATUS)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 2326 | dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n", |
| 2327 | RREG32(CP_STALLED_STAT1)); |
| 2328 | dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n", |
| 2329 | RREG32(CP_STALLED_STAT2)); |
| 2330 | dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n", |
| 2331 | RREG32(CP_BUSY_STAT)); |
| 2332 | dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n", |
| 2333 | RREG32(CP_STAT)); |
Jerome Glisse | eaaa698 | 2013-01-02 15:12:15 -0500 | [diff] [blame^] | 2334 | dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n", |
| 2335 | RREG32(DMA_STATUS_REG)); |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2336 | evergreen_mc_stop(rdev, &save); |
| 2337 | if (evergreen_mc_wait_for_idle(rdev)) { |
| 2338 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
| 2339 | } |
| 2340 | /* Disable CP parsing/prefetching */ |
| 2341 | WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT); |
| 2342 | |
| 2343 | /* reset all the gfx blocks */ |
| 2344 | grbm_reset = (SOFT_RESET_CP | |
| 2345 | SOFT_RESET_CB | |
| 2346 | SOFT_RESET_DB | |
| 2347 | SOFT_RESET_PA | |
| 2348 | SOFT_RESET_SC | |
| 2349 | SOFT_RESET_SPI | |
| 2350 | SOFT_RESET_SH | |
| 2351 | SOFT_RESET_SX | |
| 2352 | SOFT_RESET_TC | |
| 2353 | SOFT_RESET_TA | |
| 2354 | SOFT_RESET_VC | |
| 2355 | SOFT_RESET_VGT); |
| 2356 | |
| 2357 | dev_info(rdev->dev, " GRBM_SOFT_RESET=0x%08X\n", grbm_reset); |
| 2358 | WREG32(GRBM_SOFT_RESET, grbm_reset); |
| 2359 | (void)RREG32(GRBM_SOFT_RESET); |
| 2360 | udelay(50); |
| 2361 | WREG32(GRBM_SOFT_RESET, 0); |
| 2362 | (void)RREG32(GRBM_SOFT_RESET); |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2363 | /* Wait a little for things to settle down */ |
| 2364 | udelay(50); |
| 2365 | dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n", |
| 2366 | RREG32(GRBM_STATUS)); |
| 2367 | dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n", |
| 2368 | RREG32(GRBM_STATUS_SE0)); |
| 2369 | dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n", |
| 2370 | RREG32(GRBM_STATUS_SE1)); |
| 2371 | dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n", |
| 2372 | RREG32(SRBM_STATUS)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 2373 | dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n", |
| 2374 | RREG32(CP_STALLED_STAT1)); |
| 2375 | dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n", |
| 2376 | RREG32(CP_STALLED_STAT2)); |
| 2377 | dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n", |
| 2378 | RREG32(CP_BUSY_STAT)); |
| 2379 | dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n", |
| 2380 | RREG32(CP_STAT)); |
Jerome Glisse | eaaa698 | 2013-01-02 15:12:15 -0500 | [diff] [blame^] | 2381 | dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n", |
| 2382 | RREG32(DMA_STATUS_REG)); |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2383 | evergreen_mc_resume(rdev, &save); |
| 2384 | return 0; |
| 2385 | } |
| 2386 | |
Jerome Glisse | a2d07b7 | 2010-03-09 14:45:11 +0000 | [diff] [blame] | 2387 | int evergreen_asic_reset(struct radeon_device *rdev) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2388 | { |
Alex Deucher | 747943e | 2010-03-24 13:26:36 -0400 | [diff] [blame] | 2389 | return evergreen_gpu_soft_reset(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2390 | } |
| 2391 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2392 | /* Interrupts */ |
| 2393 | |
| 2394 | u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc) |
| 2395 | { |
Alex Deucher | 4643705 | 2012-08-15 17:10:32 -0400 | [diff] [blame] | 2396 | if (crtc >= rdev->num_crtc) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2397 | return 0; |
Alex Deucher | 4643705 | 2012-08-15 17:10:32 -0400 | [diff] [blame] | 2398 | else |
| 2399 | return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | void evergreen_disable_interrupt_state(struct radeon_device *rdev) |
| 2403 | { |
| 2404 | u32 tmp; |
| 2405 | |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2406 | if (rdev->family >= CHIP_CAYMAN) { |
| 2407 | cayman_cp_int_cntl_setup(rdev, 0, |
| 2408 | CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE); |
| 2409 | cayman_cp_int_cntl_setup(rdev, 1, 0); |
| 2410 | cayman_cp_int_cntl_setup(rdev, 2, 0); |
Alex Deucher | f60cbd1 | 2012-12-04 15:27:33 -0500 | [diff] [blame] | 2411 | tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE; |
| 2412 | WREG32(CAYMAN_DMA1_CNTL, tmp); |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2413 | } else |
| 2414 | WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 2415 | tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE; |
| 2416 | WREG32(DMA_CNTL, tmp); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2417 | WREG32(GRBM_INT_CNTL, 0); |
| 2418 | WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); |
| 2419 | WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2420 | if (rdev->num_crtc >= 4) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2421 | WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); |
| 2422 | WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2423 | } |
| 2424 | if (rdev->num_crtc >= 6) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2425 | WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); |
| 2426 | WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); |
| 2427 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2428 | |
| 2429 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); |
| 2430 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2431 | if (rdev->num_crtc >= 4) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2432 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); |
| 2433 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2434 | } |
| 2435 | if (rdev->num_crtc >= 6) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2436 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); |
| 2437 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); |
| 2438 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2439 | |
Alex Deucher | 05b3ef6 | 2012-03-20 17:18:37 -0400 | [diff] [blame] | 2440 | /* only one DAC on DCE6 */ |
| 2441 | if (!ASIC_IS_DCE6(rdev)) |
| 2442 | WREG32(DACA_AUTODETECT_INT_CONTROL, 0); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2443 | WREG32(DACB_AUTODETECT_INT_CONTROL, 0); |
| 2444 | |
| 2445 | tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2446 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 2447 | tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2448 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 2449 | tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2450 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 2451 | tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2452 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 2453 | tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2454 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
| 2455 | tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 2456 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
| 2457 | |
| 2458 | } |
| 2459 | |
| 2460 | int evergreen_irq_set(struct radeon_device *rdev) |
| 2461 | { |
| 2462 | u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE; |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2463 | u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2464 | u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0; |
| 2465 | u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6; |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 2466 | u32 grbm_int_cntl = 0; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2467 | u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2468 | u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0; |
Alex Deucher | f60cbd1 | 2012-12-04 15:27:33 -0500 | [diff] [blame] | 2469 | u32 dma_cntl, dma_cntl1 = 0; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2470 | |
| 2471 | if (!rdev->irq.installed) { |
Joe Perches | fce7d61 | 2010-10-30 21:08:30 +0000 | [diff] [blame] | 2472 | WARN(1, "Can't enable IRQ/MSI because no handler is installed\n"); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2473 | return -EINVAL; |
| 2474 | } |
| 2475 | /* don't enable anything if the ih is disabled */ |
| 2476 | if (!rdev->ih.enabled) { |
| 2477 | r600_disable_interrupts(rdev); |
| 2478 | /* force the active interrupt state to all disabled */ |
| 2479 | evergreen_disable_interrupt_state(rdev); |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
| 2483 | hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2484 | hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2485 | hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2486 | hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2487 | hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2488 | hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 2489 | |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2490 | afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2491 | afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2492 | afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2493 | afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2494 | afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2495 | afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2496 | |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 2497 | dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE; |
| 2498 | |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2499 | if (rdev->family >= CHIP_CAYMAN) { |
| 2500 | /* enable CP interrupts on all rings */ |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2501 | if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) { |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2502 | DRM_DEBUG("evergreen_irq_set: sw int gfx\n"); |
| 2503 | cp_int_cntl |= TIME_STAMP_INT_ENABLE; |
| 2504 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2505 | if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) { |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2506 | DRM_DEBUG("evergreen_irq_set: sw int cp1\n"); |
| 2507 | cp_int_cntl1 |= TIME_STAMP_INT_ENABLE; |
| 2508 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2509 | if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) { |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2510 | DRM_DEBUG("evergreen_irq_set: sw int cp2\n"); |
| 2511 | cp_int_cntl2 |= TIME_STAMP_INT_ENABLE; |
| 2512 | } |
| 2513 | } else { |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2514 | if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) { |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2515 | DRM_DEBUG("evergreen_irq_set: sw int gfx\n"); |
| 2516 | cp_int_cntl |= RB_INT_ENABLE; |
| 2517 | cp_int_cntl |= TIME_STAMP_INT_ENABLE; |
| 2518 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2519 | } |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2520 | |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 2521 | if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) { |
| 2522 | DRM_DEBUG("r600_irq_set: sw int dma\n"); |
| 2523 | dma_cntl |= TRAP_ENABLE; |
| 2524 | } |
| 2525 | |
Alex Deucher | f60cbd1 | 2012-12-04 15:27:33 -0500 | [diff] [blame] | 2526 | if (rdev->family >= CHIP_CAYMAN) { |
| 2527 | dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE; |
| 2528 | if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) { |
| 2529 | DRM_DEBUG("r600_irq_set: sw int dma1\n"); |
| 2530 | dma_cntl1 |= TRAP_ENABLE; |
| 2531 | } |
| 2532 | } |
| 2533 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2534 | if (rdev->irq.crtc_vblank_int[0] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2535 | atomic_read(&rdev->irq.pflip[0])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2536 | DRM_DEBUG("evergreen_irq_set: vblank 0\n"); |
| 2537 | crtc1 |= VBLANK_INT_MASK; |
| 2538 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2539 | if (rdev->irq.crtc_vblank_int[1] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2540 | atomic_read(&rdev->irq.pflip[1])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2541 | DRM_DEBUG("evergreen_irq_set: vblank 1\n"); |
| 2542 | crtc2 |= VBLANK_INT_MASK; |
| 2543 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2544 | if (rdev->irq.crtc_vblank_int[2] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2545 | atomic_read(&rdev->irq.pflip[2])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2546 | DRM_DEBUG("evergreen_irq_set: vblank 2\n"); |
| 2547 | crtc3 |= VBLANK_INT_MASK; |
| 2548 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2549 | if (rdev->irq.crtc_vblank_int[3] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2550 | atomic_read(&rdev->irq.pflip[3])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2551 | DRM_DEBUG("evergreen_irq_set: vblank 3\n"); |
| 2552 | crtc4 |= VBLANK_INT_MASK; |
| 2553 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2554 | if (rdev->irq.crtc_vblank_int[4] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2555 | atomic_read(&rdev->irq.pflip[4])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2556 | DRM_DEBUG("evergreen_irq_set: vblank 4\n"); |
| 2557 | crtc5 |= VBLANK_INT_MASK; |
| 2558 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2559 | if (rdev->irq.crtc_vblank_int[5] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2560 | atomic_read(&rdev->irq.pflip[5])) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2561 | DRM_DEBUG("evergreen_irq_set: vblank 5\n"); |
| 2562 | crtc6 |= VBLANK_INT_MASK; |
| 2563 | } |
| 2564 | if (rdev->irq.hpd[0]) { |
| 2565 | DRM_DEBUG("evergreen_irq_set: hpd 1\n"); |
| 2566 | hpd1 |= DC_HPDx_INT_EN; |
| 2567 | } |
| 2568 | if (rdev->irq.hpd[1]) { |
| 2569 | DRM_DEBUG("evergreen_irq_set: hpd 2\n"); |
| 2570 | hpd2 |= DC_HPDx_INT_EN; |
| 2571 | } |
| 2572 | if (rdev->irq.hpd[2]) { |
| 2573 | DRM_DEBUG("evergreen_irq_set: hpd 3\n"); |
| 2574 | hpd3 |= DC_HPDx_INT_EN; |
| 2575 | } |
| 2576 | if (rdev->irq.hpd[3]) { |
| 2577 | DRM_DEBUG("evergreen_irq_set: hpd 4\n"); |
| 2578 | hpd4 |= DC_HPDx_INT_EN; |
| 2579 | } |
| 2580 | if (rdev->irq.hpd[4]) { |
| 2581 | DRM_DEBUG("evergreen_irq_set: hpd 5\n"); |
| 2582 | hpd5 |= DC_HPDx_INT_EN; |
| 2583 | } |
| 2584 | if (rdev->irq.hpd[5]) { |
| 2585 | DRM_DEBUG("evergreen_irq_set: hpd 6\n"); |
| 2586 | hpd6 |= DC_HPDx_INT_EN; |
| 2587 | } |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2588 | if (rdev->irq.afmt[0]) { |
| 2589 | DRM_DEBUG("evergreen_irq_set: hdmi 0\n"); |
| 2590 | afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2591 | } |
| 2592 | if (rdev->irq.afmt[1]) { |
| 2593 | DRM_DEBUG("evergreen_irq_set: hdmi 1\n"); |
| 2594 | afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2595 | } |
| 2596 | if (rdev->irq.afmt[2]) { |
| 2597 | DRM_DEBUG("evergreen_irq_set: hdmi 2\n"); |
| 2598 | afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2599 | } |
| 2600 | if (rdev->irq.afmt[3]) { |
| 2601 | DRM_DEBUG("evergreen_irq_set: hdmi 3\n"); |
| 2602 | afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2603 | } |
| 2604 | if (rdev->irq.afmt[4]) { |
| 2605 | DRM_DEBUG("evergreen_irq_set: hdmi 4\n"); |
| 2606 | afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2607 | } |
| 2608 | if (rdev->irq.afmt[5]) { |
| 2609 | DRM_DEBUG("evergreen_irq_set: hdmi 5\n"); |
| 2610 | afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK; |
| 2611 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2612 | |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 2613 | if (rdev->family >= CHIP_CAYMAN) { |
| 2614 | cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl); |
| 2615 | cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1); |
| 2616 | cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2); |
| 2617 | } else |
| 2618 | WREG32(CP_INT_CNTL, cp_int_cntl); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 2619 | |
| 2620 | WREG32(DMA_CNTL, dma_cntl); |
| 2621 | |
Alex Deucher | f60cbd1 | 2012-12-04 15:27:33 -0500 | [diff] [blame] | 2622 | if (rdev->family >= CHIP_CAYMAN) |
| 2623 | WREG32(CAYMAN_DMA1_CNTL, dma_cntl1); |
| 2624 | |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 2625 | WREG32(GRBM_INT_CNTL, grbm_int_cntl); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2626 | |
| 2627 | WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1); |
| 2628 | WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2629 | if (rdev->num_crtc >= 4) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2630 | WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3); |
| 2631 | WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2632 | } |
| 2633 | if (rdev->num_crtc >= 6) { |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 2634 | WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5); |
| 2635 | WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6); |
| 2636 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2637 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2638 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1); |
| 2639 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2640 | if (rdev->num_crtc >= 4) { |
| 2641 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3); |
| 2642 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4); |
| 2643 | } |
| 2644 | if (rdev->num_crtc >= 6) { |
| 2645 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5); |
| 2646 | WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6); |
| 2647 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2648 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2649 | WREG32(DC_HPD1_INT_CONTROL, hpd1); |
| 2650 | WREG32(DC_HPD2_INT_CONTROL, hpd2); |
| 2651 | WREG32(DC_HPD3_INT_CONTROL, hpd3); |
| 2652 | WREG32(DC_HPD4_INT_CONTROL, hpd4); |
| 2653 | WREG32(DC_HPD5_INT_CONTROL, hpd5); |
| 2654 | WREG32(DC_HPD6_INT_CONTROL, hpd6); |
| 2655 | |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2656 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1); |
| 2657 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2); |
| 2658 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3); |
| 2659 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4); |
| 2660 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5); |
| 2661 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6); |
| 2662 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 2663 | return 0; |
| 2664 | } |
| 2665 | |
Andi Kleen | cbdd450 | 2011-10-13 16:08:46 -0700 | [diff] [blame] | 2666 | static void evergreen_irq_ack(struct radeon_device *rdev) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2667 | { |
| 2668 | u32 tmp; |
| 2669 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2670 | rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS); |
| 2671 | rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE); |
| 2672 | rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2); |
| 2673 | rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3); |
| 2674 | rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4); |
| 2675 | rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5); |
| 2676 | rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET); |
| 2677 | rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET); |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2678 | if (rdev->num_crtc >= 4) { |
| 2679 | rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET); |
| 2680 | rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET); |
| 2681 | } |
| 2682 | if (rdev->num_crtc >= 6) { |
| 2683 | rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET); |
| 2684 | rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 2685 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2686 | |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2687 | rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET); |
| 2688 | rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET); |
| 2689 | rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET); |
| 2690 | rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET); |
| 2691 | rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET); |
| 2692 | rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 2693 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2694 | if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2695 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
| 2696 | if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2697 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2698 | if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2699 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2700 | if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2701 | WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2702 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2703 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2704 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2705 | WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK); |
| 2706 | |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2707 | if (rdev->num_crtc >= 4) { |
| 2708 | if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2709 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
| 2710 | if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2711 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
| 2712 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) |
| 2713 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK); |
| 2714 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) |
| 2715 | WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK); |
| 2716 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) |
| 2717 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK); |
| 2718 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) |
| 2719 | WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK); |
| 2720 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2721 | |
Alex Deucher | b7eff39 | 2011-07-08 11:44:56 -0400 | [diff] [blame] | 2722 | if (rdev->num_crtc >= 6) { |
| 2723 | if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2724 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
| 2725 | if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED) |
| 2726 | WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR); |
| 2727 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) |
| 2728 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK); |
| 2729 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) |
| 2730 | WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK); |
| 2731 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) |
| 2732 | WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK); |
| 2733 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) |
| 2734 | WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK); |
| 2735 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2736 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2737 | if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2738 | tmp = RREG32(DC_HPD1_INT_CONTROL); |
| 2739 | tmp |= DC_HPDx_INT_ACK; |
| 2740 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 2741 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2742 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2743 | tmp = RREG32(DC_HPD2_INT_CONTROL); |
| 2744 | tmp |= DC_HPDx_INT_ACK; |
| 2745 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 2746 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2747 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2748 | tmp = RREG32(DC_HPD3_INT_CONTROL); |
| 2749 | tmp |= DC_HPDx_INT_ACK; |
| 2750 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 2751 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2752 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2753 | tmp = RREG32(DC_HPD4_INT_CONTROL); |
| 2754 | tmp |= DC_HPDx_INT_ACK; |
| 2755 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 2756 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2757 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2758 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 2759 | tmp |= DC_HPDx_INT_ACK; |
| 2760 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
| 2761 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2762 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2763 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 2764 | tmp |= DC_HPDx_INT_ACK; |
| 2765 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
| 2766 | } |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2767 | if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) { |
| 2768 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET); |
| 2769 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2770 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp); |
| 2771 | } |
| 2772 | if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) { |
| 2773 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); |
| 2774 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2775 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp); |
| 2776 | } |
| 2777 | if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) { |
| 2778 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET); |
| 2779 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2780 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp); |
| 2781 | } |
| 2782 | if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) { |
| 2783 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET); |
| 2784 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2785 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp); |
| 2786 | } |
| 2787 | if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) { |
| 2788 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET); |
| 2789 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2790 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp); |
| 2791 | } |
| 2792 | if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) { |
| 2793 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 2794 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
| 2795 | WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp); |
| 2796 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2797 | } |
| 2798 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 2799 | static void evergreen_irq_disable(struct radeon_device *rdev) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2800 | { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2801 | r600_disable_interrupts(rdev); |
| 2802 | /* Wait and acknowledge irq */ |
| 2803 | mdelay(1); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2804 | evergreen_irq_ack(rdev); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2805 | evergreen_disable_interrupt_state(rdev); |
| 2806 | } |
| 2807 | |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 2808 | void evergreen_irq_suspend(struct radeon_device *rdev) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2809 | { |
| 2810 | evergreen_irq_disable(rdev); |
| 2811 | r600_rlc_stop(rdev); |
| 2812 | } |
| 2813 | |
Andi Kleen | cbdd450 | 2011-10-13 16:08:46 -0700 | [diff] [blame] | 2814 | static u32 evergreen_get_ih_wptr(struct radeon_device *rdev) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2815 | { |
| 2816 | u32 wptr, tmp; |
| 2817 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2818 | if (rdev->wb.enabled) |
Cédric Cano | 204ae24 | 2011-04-19 11:07:13 -0400 | [diff] [blame] | 2819 | wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2820 | else |
| 2821 | wptr = RREG32(IH_RB_WPTR); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2822 | |
| 2823 | if (wptr & RB_OVERFLOW) { |
| 2824 | /* When a ring buffer overflow happen start parsing interrupt |
| 2825 | * from the last not overwritten vector (wptr + 16). Hopefully |
| 2826 | * this should allow us to catchup. |
| 2827 | */ |
| 2828 | dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n", |
| 2829 | wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask); |
| 2830 | rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask; |
| 2831 | tmp = RREG32(IH_RB_CNTL); |
| 2832 | tmp |= IH_WPTR_OVERFLOW_CLEAR; |
| 2833 | WREG32(IH_RB_CNTL, tmp); |
| 2834 | } |
| 2835 | return (wptr & rdev->ih.ptr_mask); |
| 2836 | } |
| 2837 | |
| 2838 | int evergreen_irq_process(struct radeon_device *rdev) |
| 2839 | { |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 2840 | u32 wptr; |
| 2841 | u32 rptr; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2842 | u32 src_id, src_data; |
| 2843 | u32 ring_index; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2844 | bool queue_hotplug = false; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 2845 | bool queue_hdmi = false; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2846 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 2847 | if (!rdev->ih.enabled || rdev->shutdown) |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2848 | return IRQ_NONE; |
| 2849 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 2850 | wptr = evergreen_get_ih_wptr(rdev); |
Christian Koenig | c20dc36 | 2012-05-16 21:45:24 +0200 | [diff] [blame] | 2851 | |
| 2852 | restart_ih: |
| 2853 | /* is somebody else already processing irqs? */ |
| 2854 | if (atomic_xchg(&rdev->ih.lock, 1)) |
| 2855 | return IRQ_NONE; |
| 2856 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 2857 | rptr = rdev->ih.rptr; |
| 2858 | DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2859 | |
Benjamin Herrenschmidt | 964f664 | 2011-07-13 16:28:19 +1000 | [diff] [blame] | 2860 | /* Order reading of wptr vs. reading of IH ring data */ |
| 2861 | rmb(); |
| 2862 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2863 | /* display interrupts */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2864 | evergreen_irq_ack(rdev); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2865 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2866 | while (rptr != wptr) { |
| 2867 | /* wptr/rptr are in bytes! */ |
| 2868 | ring_index = rptr / 4; |
Alex Deucher | 0f234f5f | 2011-02-13 19:06:33 -0500 | [diff] [blame] | 2869 | src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff; |
| 2870 | src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2871 | |
| 2872 | switch (src_id) { |
| 2873 | case 1: /* D1 vblank/vline */ |
| 2874 | switch (src_data) { |
| 2875 | case 0: /* D1 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2876 | if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2877 | if (rdev->irq.crtc_vblank_int[0]) { |
| 2878 | drm_handle_vblank(rdev->ddev, 0); |
| 2879 | rdev->pm.vblank_sync = true; |
| 2880 | wake_up(&rdev->irq.vblank_queue); |
| 2881 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2882 | if (atomic_read(&rdev->irq.pflip[0])) |
Mario Kleiner | 3e4ea74 | 2010-11-21 10:59:02 -0500 | [diff] [blame] | 2883 | radeon_crtc_handle_flip(rdev, 0); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2884 | rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2885 | DRM_DEBUG("IH: D1 vblank\n"); |
| 2886 | } |
| 2887 | break; |
| 2888 | case 1: /* D1 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2889 | if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) { |
| 2890 | rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2891 | DRM_DEBUG("IH: D1 vline\n"); |
| 2892 | } |
| 2893 | break; |
| 2894 | default: |
| 2895 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 2896 | break; |
| 2897 | } |
| 2898 | break; |
| 2899 | case 2: /* D2 vblank/vline */ |
| 2900 | switch (src_data) { |
| 2901 | case 0: /* D2 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2902 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2903 | if (rdev->irq.crtc_vblank_int[1]) { |
| 2904 | drm_handle_vblank(rdev->ddev, 1); |
| 2905 | rdev->pm.vblank_sync = true; |
| 2906 | wake_up(&rdev->irq.vblank_queue); |
| 2907 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2908 | if (atomic_read(&rdev->irq.pflip[1])) |
Mario Kleiner | 3e4ea74 | 2010-11-21 10:59:02 -0500 | [diff] [blame] | 2909 | radeon_crtc_handle_flip(rdev, 1); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2910 | rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2911 | DRM_DEBUG("IH: D2 vblank\n"); |
| 2912 | } |
| 2913 | break; |
| 2914 | case 1: /* D2 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2915 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) { |
| 2916 | rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2917 | DRM_DEBUG("IH: D2 vline\n"); |
| 2918 | } |
| 2919 | break; |
| 2920 | default: |
| 2921 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 2922 | break; |
| 2923 | } |
| 2924 | break; |
| 2925 | case 3: /* D3 vblank/vline */ |
| 2926 | switch (src_data) { |
| 2927 | case 0: /* D3 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2928 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) { |
| 2929 | if (rdev->irq.crtc_vblank_int[2]) { |
| 2930 | drm_handle_vblank(rdev->ddev, 2); |
| 2931 | rdev->pm.vblank_sync = true; |
| 2932 | wake_up(&rdev->irq.vblank_queue); |
| 2933 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2934 | if (atomic_read(&rdev->irq.pflip[2])) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2935 | radeon_crtc_handle_flip(rdev, 2); |
| 2936 | rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2937 | DRM_DEBUG("IH: D3 vblank\n"); |
| 2938 | } |
| 2939 | break; |
| 2940 | case 1: /* D3 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2941 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) { |
| 2942 | rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2943 | DRM_DEBUG("IH: D3 vline\n"); |
| 2944 | } |
| 2945 | break; |
| 2946 | default: |
| 2947 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 2948 | break; |
| 2949 | } |
| 2950 | break; |
| 2951 | case 4: /* D4 vblank/vline */ |
| 2952 | switch (src_data) { |
| 2953 | case 0: /* D4 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2954 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) { |
| 2955 | if (rdev->irq.crtc_vblank_int[3]) { |
| 2956 | drm_handle_vblank(rdev->ddev, 3); |
| 2957 | rdev->pm.vblank_sync = true; |
| 2958 | wake_up(&rdev->irq.vblank_queue); |
| 2959 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2960 | if (atomic_read(&rdev->irq.pflip[3])) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2961 | radeon_crtc_handle_flip(rdev, 3); |
| 2962 | rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2963 | DRM_DEBUG("IH: D4 vblank\n"); |
| 2964 | } |
| 2965 | break; |
| 2966 | case 1: /* D4 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2967 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) { |
| 2968 | rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2969 | DRM_DEBUG("IH: D4 vline\n"); |
| 2970 | } |
| 2971 | break; |
| 2972 | default: |
| 2973 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 2974 | break; |
| 2975 | } |
| 2976 | break; |
| 2977 | case 5: /* D5 vblank/vline */ |
| 2978 | switch (src_data) { |
| 2979 | case 0: /* D5 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2980 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) { |
| 2981 | if (rdev->irq.crtc_vblank_int[4]) { |
| 2982 | drm_handle_vblank(rdev->ddev, 4); |
| 2983 | rdev->pm.vblank_sync = true; |
| 2984 | wake_up(&rdev->irq.vblank_queue); |
| 2985 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 2986 | if (atomic_read(&rdev->irq.pflip[4])) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2987 | radeon_crtc_handle_flip(rdev, 4); |
| 2988 | rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2989 | DRM_DEBUG("IH: D5 vblank\n"); |
| 2990 | } |
| 2991 | break; |
| 2992 | case 1: /* D5 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 2993 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) { |
| 2994 | rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2995 | DRM_DEBUG("IH: D5 vline\n"); |
| 2996 | } |
| 2997 | break; |
| 2998 | default: |
| 2999 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 3000 | break; |
| 3001 | } |
| 3002 | break; |
| 3003 | case 6: /* D6 vblank/vline */ |
| 3004 | switch (src_data) { |
| 3005 | case 0: /* D6 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3006 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) { |
| 3007 | if (rdev->irq.crtc_vblank_int[5]) { |
| 3008 | drm_handle_vblank(rdev->ddev, 5); |
| 3009 | rdev->pm.vblank_sync = true; |
| 3010 | wake_up(&rdev->irq.vblank_queue); |
| 3011 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 3012 | if (atomic_read(&rdev->irq.pflip[5])) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3013 | radeon_crtc_handle_flip(rdev, 5); |
| 3014 | rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3015 | DRM_DEBUG("IH: D6 vblank\n"); |
| 3016 | } |
| 3017 | break; |
| 3018 | case 1: /* D6 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3019 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) { |
| 3020 | rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3021 | DRM_DEBUG("IH: D6 vline\n"); |
| 3022 | } |
| 3023 | break; |
| 3024 | default: |
| 3025 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 3026 | break; |
| 3027 | } |
| 3028 | break; |
| 3029 | case 42: /* HPD hotplug */ |
| 3030 | switch (src_data) { |
| 3031 | case 0: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3032 | if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) { |
| 3033 | rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3034 | queue_hotplug = true; |
| 3035 | DRM_DEBUG("IH: HPD1\n"); |
| 3036 | } |
| 3037 | break; |
| 3038 | case 1: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3039 | if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) { |
| 3040 | rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3041 | queue_hotplug = true; |
| 3042 | DRM_DEBUG("IH: HPD2\n"); |
| 3043 | } |
| 3044 | break; |
| 3045 | case 2: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3046 | if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) { |
| 3047 | rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3048 | queue_hotplug = true; |
| 3049 | DRM_DEBUG("IH: HPD3\n"); |
| 3050 | } |
| 3051 | break; |
| 3052 | case 3: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3053 | if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) { |
| 3054 | rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3055 | queue_hotplug = true; |
| 3056 | DRM_DEBUG("IH: HPD4\n"); |
| 3057 | } |
| 3058 | break; |
| 3059 | case 4: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3060 | if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) { |
| 3061 | rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3062 | queue_hotplug = true; |
| 3063 | DRM_DEBUG("IH: HPD5\n"); |
| 3064 | } |
| 3065 | break; |
| 3066 | case 5: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3067 | if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) { |
| 3068 | rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3069 | queue_hotplug = true; |
| 3070 | DRM_DEBUG("IH: HPD6\n"); |
| 3071 | } |
| 3072 | break; |
| 3073 | default: |
| 3074 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 3075 | break; |
| 3076 | } |
| 3077 | break; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3078 | case 44: /* hdmi */ |
| 3079 | switch (src_data) { |
| 3080 | case 0: |
| 3081 | if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) { |
| 3082 | rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3083 | queue_hdmi = true; |
| 3084 | DRM_DEBUG("IH: HDMI0\n"); |
| 3085 | } |
| 3086 | break; |
| 3087 | case 1: |
| 3088 | if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) { |
| 3089 | rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3090 | queue_hdmi = true; |
| 3091 | DRM_DEBUG("IH: HDMI1\n"); |
| 3092 | } |
| 3093 | break; |
| 3094 | case 2: |
| 3095 | if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) { |
| 3096 | rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3097 | queue_hdmi = true; |
| 3098 | DRM_DEBUG("IH: HDMI2\n"); |
| 3099 | } |
| 3100 | break; |
| 3101 | case 3: |
| 3102 | if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) { |
| 3103 | rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3104 | queue_hdmi = true; |
| 3105 | DRM_DEBUG("IH: HDMI3\n"); |
| 3106 | } |
| 3107 | break; |
| 3108 | case 4: |
| 3109 | if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) { |
| 3110 | rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3111 | queue_hdmi = true; |
| 3112 | DRM_DEBUG("IH: HDMI4\n"); |
| 3113 | } |
| 3114 | break; |
| 3115 | case 5: |
| 3116 | if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) { |
| 3117 | rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG; |
| 3118 | queue_hdmi = true; |
| 3119 | DRM_DEBUG("IH: HDMI5\n"); |
| 3120 | } |
| 3121 | break; |
| 3122 | default: |
| 3123 | DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 3124 | break; |
| 3125 | } |
| 3126 | break; |
Christian König | ae133a1 | 2012-09-18 15:30:44 -0400 | [diff] [blame] | 3127 | case 146: |
| 3128 | case 147: |
| 3129 | dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data); |
| 3130 | dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n", |
| 3131 | RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR)); |
| 3132 | dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n", |
| 3133 | RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS)); |
| 3134 | /* reset addr and status */ |
| 3135 | WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1); |
| 3136 | break; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3137 | case 176: /* CP_INT in ring buffer */ |
| 3138 | case 177: /* CP_INT in IB1 */ |
| 3139 | case 178: /* CP_INT in IB2 */ |
| 3140 | DRM_DEBUG("IH: CP int: 0x%08x\n", src_data); |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 3141 | radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3142 | break; |
| 3143 | case 181: /* CP EOP event */ |
| 3144 | DRM_DEBUG("IH: CP EOP\n"); |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 3145 | if (rdev->family >= CHIP_CAYMAN) { |
| 3146 | switch (src_data) { |
| 3147 | case 0: |
| 3148 | radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); |
| 3149 | break; |
| 3150 | case 1: |
| 3151 | radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX); |
| 3152 | break; |
| 3153 | case 2: |
| 3154 | radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX); |
| 3155 | break; |
| 3156 | } |
| 3157 | } else |
| 3158 | radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3159 | break; |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3160 | case 224: /* DMA trap event */ |
| 3161 | DRM_DEBUG("IH: DMA trap\n"); |
| 3162 | radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX); |
| 3163 | break; |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 3164 | case 233: /* GUI IDLE */ |
Ilija Hadzic | 303c805 | 2011-06-07 14:54:48 -0400 | [diff] [blame] | 3165 | DRM_DEBUG("IH: GUI idle\n"); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 3166 | break; |
Alex Deucher | f60cbd1 | 2012-12-04 15:27:33 -0500 | [diff] [blame] | 3167 | case 244: /* DMA trap event */ |
| 3168 | if (rdev->family >= CHIP_CAYMAN) { |
| 3169 | DRM_DEBUG("IH: DMA1 trap\n"); |
| 3170 | radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX); |
| 3171 | } |
| 3172 | break; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3173 | default: |
| 3174 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 3175 | break; |
| 3176 | } |
| 3177 | |
| 3178 | /* wptr/rptr are in bytes! */ |
| 3179 | rptr += 16; |
| 3180 | rptr &= rdev->ih.ptr_mask; |
| 3181 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3182 | if (queue_hotplug) |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 3183 | schedule_work(&rdev->hotplug_work); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3184 | if (queue_hdmi) |
| 3185 | schedule_work(&rdev->audio_work); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3186 | rdev->ih.rptr = rptr; |
| 3187 | WREG32(IH_RB_RPTR, rdev->ih.rptr); |
Christian Koenig | c20dc36 | 2012-05-16 21:45:24 +0200 | [diff] [blame] | 3188 | atomic_set(&rdev->ih.lock, 0); |
| 3189 | |
| 3190 | /* make sure wptr hasn't changed while processing */ |
| 3191 | wptr = evergreen_get_ih_wptr(rdev); |
| 3192 | if (wptr != rptr) |
| 3193 | goto restart_ih; |
| 3194 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3195 | return IRQ_HANDLED; |
| 3196 | } |
| 3197 | |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3198 | /** |
| 3199 | * evergreen_dma_fence_ring_emit - emit a fence on the DMA ring |
| 3200 | * |
| 3201 | * @rdev: radeon_device pointer |
| 3202 | * @fence: radeon fence object |
| 3203 | * |
| 3204 | * Add a DMA fence packet to the ring to write |
| 3205 | * the fence seq number and DMA trap packet to generate |
| 3206 | * an interrupt if needed (evergreen-SI). |
| 3207 | */ |
| 3208 | void evergreen_dma_fence_ring_emit(struct radeon_device *rdev, |
| 3209 | struct radeon_fence *fence) |
| 3210 | { |
| 3211 | struct radeon_ring *ring = &rdev->ring[fence->ring]; |
| 3212 | u64 addr = rdev->fence_drv[fence->ring].gpu_addr; |
| 3213 | /* write the fence */ |
| 3214 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0, 0)); |
| 3215 | radeon_ring_write(ring, addr & 0xfffffffc); |
| 3216 | radeon_ring_write(ring, (upper_32_bits(addr) & 0xff)); |
| 3217 | radeon_ring_write(ring, fence->seq); |
| 3218 | /* generate an interrupt */ |
| 3219 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0, 0)); |
| 3220 | /* flush HDP */ |
| 3221 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0)); |
| 3222 | radeon_ring_write(ring, (0xf << 16) | HDP_MEM_COHERENCY_FLUSH_CNTL); |
| 3223 | radeon_ring_write(ring, 1); |
| 3224 | } |
| 3225 | |
| 3226 | /** |
| 3227 | * evergreen_dma_ring_ib_execute - schedule an IB on the DMA engine |
| 3228 | * |
| 3229 | * @rdev: radeon_device pointer |
| 3230 | * @ib: IB object to schedule |
| 3231 | * |
| 3232 | * Schedule an IB in the DMA ring (evergreen). |
| 3233 | */ |
| 3234 | void evergreen_dma_ring_ib_execute(struct radeon_device *rdev, |
| 3235 | struct radeon_ib *ib) |
| 3236 | { |
| 3237 | struct radeon_ring *ring = &rdev->ring[ib->ring]; |
| 3238 | |
| 3239 | if (rdev->wb.enabled) { |
| 3240 | u32 next_rptr = ring->wptr + 4; |
| 3241 | while ((next_rptr & 7) != 5) |
| 3242 | next_rptr++; |
| 3243 | next_rptr += 3; |
| 3244 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1)); |
| 3245 | radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc); |
| 3246 | radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff); |
| 3247 | radeon_ring_write(ring, next_rptr); |
| 3248 | } |
| 3249 | |
| 3250 | /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring. |
| 3251 | * Pad as necessary with NOPs. |
| 3252 | */ |
| 3253 | while ((ring->wptr & 7) != 5) |
| 3254 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0)); |
| 3255 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0, 0)); |
| 3256 | radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0)); |
| 3257 | radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF)); |
| 3258 | |
| 3259 | } |
| 3260 | |
| 3261 | /** |
| 3262 | * evergreen_copy_dma - copy pages using the DMA engine |
| 3263 | * |
| 3264 | * @rdev: radeon_device pointer |
| 3265 | * @src_offset: src GPU address |
| 3266 | * @dst_offset: dst GPU address |
| 3267 | * @num_gpu_pages: number of GPU pages to xfer |
| 3268 | * @fence: radeon fence object |
| 3269 | * |
| 3270 | * Copy GPU paging using the DMA engine (evergreen-cayman). |
| 3271 | * Used by the radeon ttm implementation to move pages if |
| 3272 | * registered as the asic copy callback. |
| 3273 | */ |
| 3274 | int evergreen_copy_dma(struct radeon_device *rdev, |
| 3275 | uint64_t src_offset, uint64_t dst_offset, |
| 3276 | unsigned num_gpu_pages, |
| 3277 | struct radeon_fence **fence) |
| 3278 | { |
| 3279 | struct radeon_semaphore *sem = NULL; |
| 3280 | int ring_index = rdev->asic->copy.dma_ring_index; |
| 3281 | struct radeon_ring *ring = &rdev->ring[ring_index]; |
| 3282 | u32 size_in_dw, cur_size_in_dw; |
| 3283 | int i, num_loops; |
| 3284 | int r = 0; |
| 3285 | |
| 3286 | r = radeon_semaphore_create(rdev, &sem); |
| 3287 | if (r) { |
| 3288 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 3289 | return r; |
| 3290 | } |
| 3291 | |
| 3292 | size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4; |
| 3293 | num_loops = DIV_ROUND_UP(size_in_dw, 0xfffff); |
| 3294 | r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11); |
| 3295 | if (r) { |
| 3296 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 3297 | radeon_semaphore_free(rdev, &sem, NULL); |
| 3298 | return r; |
| 3299 | } |
| 3300 | |
| 3301 | if (radeon_fence_need_sync(*fence, ring->idx)) { |
| 3302 | radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring, |
| 3303 | ring->idx); |
| 3304 | radeon_fence_note_sync(*fence, ring->idx); |
| 3305 | } else { |
| 3306 | radeon_semaphore_free(rdev, &sem, NULL); |
| 3307 | } |
| 3308 | |
| 3309 | for (i = 0; i < num_loops; i++) { |
| 3310 | cur_size_in_dw = size_in_dw; |
| 3311 | if (cur_size_in_dw > 0xFFFFF) |
| 3312 | cur_size_in_dw = 0xFFFFF; |
| 3313 | size_in_dw -= cur_size_in_dw; |
| 3314 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw)); |
| 3315 | radeon_ring_write(ring, dst_offset & 0xfffffffc); |
| 3316 | radeon_ring_write(ring, src_offset & 0xfffffffc); |
| 3317 | radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff); |
| 3318 | radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff); |
| 3319 | src_offset += cur_size_in_dw * 4; |
| 3320 | dst_offset += cur_size_in_dw * 4; |
| 3321 | } |
| 3322 | |
| 3323 | r = radeon_fence_emit(rdev, fence, ring->idx); |
| 3324 | if (r) { |
| 3325 | radeon_ring_unlock_undo(rdev, ring); |
| 3326 | return r; |
| 3327 | } |
| 3328 | |
| 3329 | radeon_ring_unlock_commit(rdev, ring); |
| 3330 | radeon_semaphore_free(rdev, &sem, *fence); |
| 3331 | |
| 3332 | return r; |
| 3333 | } |
| 3334 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3335 | static int evergreen_startup(struct radeon_device *rdev) |
| 3336 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3337 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3338 | int r; |
| 3339 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3340 | /* enable pcie gen2 link */ |
Ilija Hadzic | cd54033 | 2011-09-20 10:22:57 -0400 | [diff] [blame] | 3341 | evergreen_pcie_gen2_enable(rdev); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3342 | |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 3343 | if (ASIC_IS_DCE5(rdev)) { |
| 3344 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) { |
| 3345 | r = ni_init_microcode(rdev); |
| 3346 | if (r) { |
| 3347 | DRM_ERROR("Failed to load firmware!\n"); |
| 3348 | return r; |
| 3349 | } |
| 3350 | } |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 3351 | r = ni_mc_load_microcode(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3352 | if (r) { |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 3353 | DRM_ERROR("Failed to load MC firmware!\n"); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3354 | return r; |
| 3355 | } |
Alex Deucher | 0af62b0 | 2011-01-06 21:19:31 -0500 | [diff] [blame] | 3356 | } else { |
| 3357 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) { |
| 3358 | r = r600_init_microcode(rdev); |
| 3359 | if (r) { |
| 3360 | DRM_ERROR("Failed to load firmware!\n"); |
| 3361 | return r; |
| 3362 | } |
| 3363 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3364 | } |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3365 | |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 3366 | r = r600_vram_scratch_init(rdev); |
| 3367 | if (r) |
| 3368 | return r; |
| 3369 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3370 | evergreen_mc_program(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3371 | if (rdev->flags & RADEON_IS_AGP) { |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 3372 | evergreen_agp_enable(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3373 | } else { |
| 3374 | r = evergreen_pcie_gart_enable(rdev); |
| 3375 | if (r) |
| 3376 | return r; |
| 3377 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3378 | evergreen_gpu_init(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3379 | |
Alex Deucher | d7ccd8f | 2010-09-09 11:33:36 -0400 | [diff] [blame] | 3380 | r = evergreen_blit_init(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3381 | if (r) { |
Ilija Hadzic | fb3d9e9 | 2011-10-12 23:29:41 -0400 | [diff] [blame] | 3382 | r600_blit_fini(rdev); |
Alex Deucher | 27cd776 | 2012-02-23 17:53:42 -0500 | [diff] [blame] | 3383 | rdev->asic->copy.copy = NULL; |
Alex Deucher | d7ccd8f | 2010-09-09 11:33:36 -0400 | [diff] [blame] | 3384 | dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3385 | } |
| 3386 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3387 | /* allocate wb buffer */ |
| 3388 | r = radeon_wb_init(rdev); |
| 3389 | if (r) |
| 3390 | return r; |
| 3391 | |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 3392 | r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); |
| 3393 | if (r) { |
| 3394 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 3395 | return r; |
| 3396 | } |
| 3397 | |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3398 | r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX); |
| 3399 | if (r) { |
| 3400 | dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r); |
| 3401 | return r; |
| 3402 | } |
| 3403 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3404 | /* Enable IRQ */ |
| 3405 | r = r600_irq_init(rdev); |
| 3406 | if (r) { |
| 3407 | DRM_ERROR("radeon: IH init failed (%d).\n", r); |
| 3408 | radeon_irq_kms_fini(rdev); |
| 3409 | return r; |
| 3410 | } |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3411 | evergreen_irq_set(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3412 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3413 | 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] | 3414 | R600_CP_RB_RPTR, R600_CP_RB_WPTR, |
| 3415 | 0, 0xfffff, RADEON_CP_PACKET2); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3416 | if (r) |
| 3417 | return r; |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3418 | |
| 3419 | ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX]; |
| 3420 | r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET, |
| 3421 | DMA_RB_RPTR, DMA_RB_WPTR, |
| 3422 | 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0)); |
| 3423 | if (r) |
| 3424 | return r; |
| 3425 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3426 | r = evergreen_cp_load_microcode(rdev); |
| 3427 | if (r) |
| 3428 | return r; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3429 | r = evergreen_cp_resume(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3430 | if (r) |
| 3431 | return r; |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3432 | r = r600_dma_resume(rdev); |
| 3433 | if (r) |
| 3434 | return r; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3435 | |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3436 | r = radeon_ib_pool_init(rdev); |
| 3437 | if (r) { |
| 3438 | dev_err(rdev->dev, "IB initialization failed (%d).\n", r); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3439 | return r; |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3440 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3441 | |
Rafał Miłecki | 69d2ae5 | 2011-12-07 23:32:24 +0100 | [diff] [blame] | 3442 | r = r600_audio_init(rdev); |
| 3443 | if (r) { |
| 3444 | DRM_ERROR("radeon: audio init failed\n"); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3445 | return r; |
| 3446 | } |
| 3447 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3448 | return 0; |
| 3449 | } |
| 3450 | |
| 3451 | int evergreen_resume(struct radeon_device *rdev) |
| 3452 | { |
| 3453 | int r; |
| 3454 | |
Alex Deucher | 86f5c9e | 2010-12-20 12:35:04 -0500 | [diff] [blame] | 3455 | /* reset the asic, the gfx blocks are often in a bad state |
| 3456 | * after the driver is unloaded or after a resume |
| 3457 | */ |
| 3458 | if (radeon_asic_reset(rdev)) |
| 3459 | dev_warn(rdev->dev, "GPU reset failed !\n"); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3460 | /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw, |
| 3461 | * posting will perform necessary task to bring back GPU into good |
| 3462 | * shape. |
| 3463 | */ |
| 3464 | /* post card */ |
| 3465 | atom_asic_init(rdev->mode_info.atom_context); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3466 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3467 | rdev->accel_working = true; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3468 | r = evergreen_startup(rdev); |
| 3469 | if (r) { |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 3470 | DRM_ERROR("evergreen startup failed on resume\n"); |
Jerome Glisse | 6b7746e | 2012-02-20 17:57:20 -0500 | [diff] [blame] | 3471 | rdev->accel_working = false; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3472 | return r; |
| 3473 | } |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3474 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3475 | return r; |
| 3476 | |
| 3477 | } |
| 3478 | |
| 3479 | int evergreen_suspend(struct radeon_device *rdev) |
| 3480 | { |
Rafał Miłecki | 69d2ae5 | 2011-12-07 23:32:24 +0100 | [diff] [blame] | 3481 | r600_audio_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3482 | r700_cp_stop(rdev); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3483 | r600_dma_stop(rdev); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3484 | evergreen_irq_suspend(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3485 | radeon_wb_disable(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3486 | evergreen_pcie_gart_disable(rdev); |
Alex Deucher | d7ccd8f | 2010-09-09 11:33:36 -0400 | [diff] [blame] | 3487 | |
| 3488 | return 0; |
| 3489 | } |
| 3490 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3491 | /* Plan is to move initialization in that function and use |
| 3492 | * helper function so that radeon_device_init pretty much |
| 3493 | * do nothing more than calling asic specific function. This |
| 3494 | * should also allow to remove a bunch of callback function |
| 3495 | * like vram_info. |
| 3496 | */ |
| 3497 | int evergreen_init(struct radeon_device *rdev) |
| 3498 | { |
| 3499 | int r; |
| 3500 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3501 | /* Read BIOS */ |
| 3502 | if (!radeon_get_bios(rdev)) { |
| 3503 | if (ASIC_IS_AVIVO(rdev)) |
| 3504 | return -EINVAL; |
| 3505 | } |
| 3506 | /* Must be an ATOMBIOS */ |
| 3507 | if (!rdev->is_atom_bios) { |
Alex Deucher | 755d819 | 2011-03-02 20:07:34 -0500 | [diff] [blame] | 3508 | dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n"); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3509 | return -EINVAL; |
| 3510 | } |
| 3511 | r = radeon_atombios_init(rdev); |
| 3512 | if (r) |
| 3513 | return r; |
Alex Deucher | 86f5c9e | 2010-12-20 12:35:04 -0500 | [diff] [blame] | 3514 | /* reset the asic, the gfx blocks are often in a bad state |
| 3515 | * after the driver is unloaded or after a resume |
| 3516 | */ |
| 3517 | if (radeon_asic_reset(rdev)) |
| 3518 | dev_warn(rdev->dev, "GPU reset failed !\n"); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3519 | /* Post card if necessary */ |
Alex Deucher | fd909c3 | 2011-01-11 18:08:59 -0500 | [diff] [blame] | 3520 | if (!radeon_card_posted(rdev)) { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3521 | if (!rdev->bios) { |
| 3522 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 3523 | return -EINVAL; |
| 3524 | } |
| 3525 | DRM_INFO("GPU not posted. posting now...\n"); |
| 3526 | atom_asic_init(rdev->mode_info.atom_context); |
| 3527 | } |
| 3528 | /* Initialize scratch registers */ |
| 3529 | r600_scratch_init(rdev); |
| 3530 | /* Initialize surface registers */ |
| 3531 | radeon_surface_init(rdev); |
| 3532 | /* Initialize clocks */ |
| 3533 | radeon_get_clock_info(rdev->ddev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3534 | /* Fence driver */ |
| 3535 | r = radeon_fence_driver_init(rdev); |
| 3536 | if (r) |
| 3537 | return r; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 3538 | /* initialize AGP */ |
| 3539 | if (rdev->flags & RADEON_IS_AGP) { |
| 3540 | r = radeon_agp_init(rdev); |
| 3541 | if (r) |
| 3542 | radeon_agp_disable(rdev); |
| 3543 | } |
| 3544 | /* initialize memory controller */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3545 | r = evergreen_mc_init(rdev); |
| 3546 | if (r) |
| 3547 | return r; |
| 3548 | /* Memory manager */ |
| 3549 | r = radeon_bo_init(rdev); |
| 3550 | if (r) |
| 3551 | return r; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3552 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3553 | r = radeon_irq_kms_init(rdev); |
| 3554 | if (r) |
| 3555 | return r; |
| 3556 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3557 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL; |
| 3558 | r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3559 | |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3560 | rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL; |
| 3561 | r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024); |
| 3562 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3563 | rdev->ih.ring_obj = NULL; |
| 3564 | r600_ih_ring_init(rdev, 64 * 1024); |
| 3565 | |
| 3566 | r = r600_pcie_gart_init(rdev); |
| 3567 | if (r) |
| 3568 | return r; |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 3569 | |
Alex Deucher | 148a03b | 2010-06-03 19:00:03 -0400 | [diff] [blame] | 3570 | rdev->accel_working = true; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3571 | r = evergreen_startup(rdev); |
| 3572 | if (r) { |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3573 | dev_err(rdev->dev, "disabling GPU acceleration\n"); |
| 3574 | r700_cp_fini(rdev); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3575 | r600_dma_fini(rdev); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3576 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3577 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3578 | radeon_ib_pool_fini(rdev); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 3579 | radeon_irq_kms_fini(rdev); |
Alex Deucher | 0fcdb61 | 2010-03-24 13:20:41 -0400 | [diff] [blame] | 3580 | evergreen_pcie_gart_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3581 | rdev->accel_working = false; |
| 3582 | } |
Alex Deucher | 77e00f2 | 2011-12-21 11:58:17 -0500 | [diff] [blame] | 3583 | |
| 3584 | /* Don't start up if the MC ucode is missing on BTC parts. |
| 3585 | * The default clocks and voltages before the MC ucode |
| 3586 | * is loaded are not suffient for advanced operations. |
| 3587 | */ |
| 3588 | if (ASIC_IS_DCE5(rdev)) { |
| 3589 | if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) { |
| 3590 | DRM_ERROR("radeon: MC ucode required for NI+.\n"); |
| 3591 | return -EINVAL; |
| 3592 | } |
| 3593 | } |
| 3594 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3595 | return 0; |
| 3596 | } |
| 3597 | |
| 3598 | void evergreen_fini(struct radeon_device *rdev) |
| 3599 | { |
Rafał Miłecki | 69d2ae5 | 2011-12-07 23:32:24 +0100 | [diff] [blame] | 3600 | r600_audio_fini(rdev); |
Ilija Hadzic | fb3d9e9 | 2011-10-12 23:29:41 -0400 | [diff] [blame] | 3601 | r600_blit_fini(rdev); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3602 | r700_cp_fini(rdev); |
Alex Deucher | 233d1ad | 2012-12-04 15:25:59 -0500 | [diff] [blame] | 3603 | r600_dma_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3604 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3605 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3606 | radeon_ib_pool_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3607 | radeon_irq_kms_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3608 | evergreen_pcie_gart_fini(rdev); |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 3609 | r600_vram_scratch_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3610 | radeon_gem_fini(rdev); |
| 3611 | radeon_fence_driver_fini(rdev); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3612 | radeon_agp_fini(rdev); |
| 3613 | radeon_bo_fini(rdev); |
| 3614 | radeon_atombios_fini(rdev); |
| 3615 | kfree(rdev->bios); |
| 3616 | rdev->bios = NULL; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 3617 | } |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3618 | |
Ilija Hadzic | b07759b | 2011-09-20 10:22:58 -0400 | [diff] [blame] | 3619 | void evergreen_pcie_gen2_enable(struct radeon_device *rdev) |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3620 | { |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 3621 | u32 link_width_cntl, speed_cntl, mask; |
| 3622 | int ret; |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3623 | |
Alex Deucher | d42dd57 | 2011-01-12 20:05:11 -0500 | [diff] [blame] | 3624 | if (radeon_pcie_gen2 == 0) |
| 3625 | return; |
| 3626 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3627 | if (rdev->flags & RADEON_IS_IGP) |
| 3628 | return; |
| 3629 | |
| 3630 | if (!(rdev->flags & RADEON_IS_PCIE)) |
| 3631 | return; |
| 3632 | |
| 3633 | /* x2 cards have a special sequence */ |
| 3634 | if (ASIC_IS_X2(rdev)) |
| 3635 | return; |
| 3636 | |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 3637 | ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask); |
| 3638 | if (ret != 0) |
| 3639 | return; |
| 3640 | |
| 3641 | if (!(mask & DRM_PCIE_SPEED_50)) |
| 3642 | return; |
| 3643 | |
Alex Deucher | 3691fee | 2012-10-08 17:46:27 -0400 | [diff] [blame] | 3644 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 3645 | if (speed_cntl & LC_CURRENT_DATA_RATE) { |
| 3646 | DRM_INFO("PCIE gen 2 link speeds already enabled\n"); |
| 3647 | return; |
| 3648 | } |
| 3649 | |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 3650 | DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n"); |
| 3651 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3652 | if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) || |
| 3653 | (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) { |
| 3654 | |
| 3655 | link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL); |
| 3656 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
| 3657 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 3658 | |
| 3659 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 3660 | speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN; |
| 3661 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 3662 | |
| 3663 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 3664 | speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT; |
| 3665 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 3666 | |
| 3667 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 3668 | speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT; |
| 3669 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 3670 | |
| 3671 | speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL); |
| 3672 | speed_cntl |= LC_GEN2_EN_STRAP; |
| 3673 | WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl); |
| 3674 | |
| 3675 | } else { |
| 3676 | link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL); |
| 3677 | /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */ |
| 3678 | if (1) |
| 3679 | link_width_cntl |= LC_UPCONFIGURE_DIS; |
| 3680 | else |
| 3681 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
| 3682 | WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 3683 | } |
| 3684 | } |