Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 29 | #include <linux/seq_file.h> |
| 30 | #include <linux/firmware.h> |
| 31 | #include <linux/platform_device.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 33 | #include <drm/drmP.h> |
| 34 | #include <drm/radeon_drm.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 35 | #include "radeon.h" |
Daniel Vetter | e699037 | 2010-03-11 21:19:17 +0000 | [diff] [blame] | 36 | #include "radeon_asic.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 37 | #include "radeon_mode.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 38 | #include "r600d.h" |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 39 | #include "atom.h" |
Jerome Glisse | d39c3b8 | 2009-09-28 18:34:43 +0200 | [diff] [blame] | 40 | #include "avivod.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 41 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 42 | #define PFP_UCODE_SIZE 576 |
| 43 | #define PM4_UCODE_SIZE 1792 |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 44 | #define RLC_UCODE_SIZE 768 |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 45 | #define R700_PFP_UCODE_SIZE 848 |
| 46 | #define R700_PM4_UCODE_SIZE 1360 |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 47 | #define R700_RLC_UCODE_SIZE 1024 |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 48 | #define EVERGREEN_PFP_UCODE_SIZE 1120 |
| 49 | #define EVERGREEN_PM4_UCODE_SIZE 1376 |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 50 | #define EVERGREEN_RLC_UCODE_SIZE 768 |
Alex Deucher | 1272780 | 2011-03-02 20:07:32 -0500 | [diff] [blame] | 51 | #define CAYMAN_RLC_UCODE_SIZE 1024 |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 52 | #define ARUBA_RLC_UCODE_SIZE 1536 |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 53 | |
| 54 | /* Firmware Names */ |
| 55 | MODULE_FIRMWARE("radeon/R600_pfp.bin"); |
| 56 | MODULE_FIRMWARE("radeon/R600_me.bin"); |
| 57 | MODULE_FIRMWARE("radeon/RV610_pfp.bin"); |
| 58 | MODULE_FIRMWARE("radeon/RV610_me.bin"); |
| 59 | MODULE_FIRMWARE("radeon/RV630_pfp.bin"); |
| 60 | MODULE_FIRMWARE("radeon/RV630_me.bin"); |
| 61 | MODULE_FIRMWARE("radeon/RV620_pfp.bin"); |
| 62 | MODULE_FIRMWARE("radeon/RV620_me.bin"); |
| 63 | MODULE_FIRMWARE("radeon/RV635_pfp.bin"); |
| 64 | MODULE_FIRMWARE("radeon/RV635_me.bin"); |
| 65 | MODULE_FIRMWARE("radeon/RV670_pfp.bin"); |
| 66 | MODULE_FIRMWARE("radeon/RV670_me.bin"); |
| 67 | MODULE_FIRMWARE("radeon/RS780_pfp.bin"); |
| 68 | MODULE_FIRMWARE("radeon/RS780_me.bin"); |
| 69 | MODULE_FIRMWARE("radeon/RV770_pfp.bin"); |
| 70 | MODULE_FIRMWARE("radeon/RV770_me.bin"); |
| 71 | MODULE_FIRMWARE("radeon/RV730_pfp.bin"); |
| 72 | MODULE_FIRMWARE("radeon/RV730_me.bin"); |
| 73 | MODULE_FIRMWARE("radeon/RV710_pfp.bin"); |
| 74 | MODULE_FIRMWARE("radeon/RV710_me.bin"); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 75 | MODULE_FIRMWARE("radeon/R600_rlc.bin"); |
| 76 | MODULE_FIRMWARE("radeon/R700_rlc.bin"); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 77 | MODULE_FIRMWARE("radeon/CEDAR_pfp.bin"); |
| 78 | MODULE_FIRMWARE("radeon/CEDAR_me.bin"); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 79 | MODULE_FIRMWARE("radeon/CEDAR_rlc.bin"); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 80 | MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin"); |
| 81 | MODULE_FIRMWARE("radeon/REDWOOD_me.bin"); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 82 | MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin"); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 83 | MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin"); |
| 84 | MODULE_FIRMWARE("radeon/JUNIPER_me.bin"); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 85 | MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin"); |
Dave Airlie | a743374 | 2010-04-09 15:31:09 +1000 | [diff] [blame] | 86 | MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin"); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 87 | MODULE_FIRMWARE("radeon/CYPRESS_me.bin"); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 88 | MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin"); |
Alex Deucher | 439bd6c | 2010-11-22 17:56:31 -0500 | [diff] [blame] | 89 | MODULE_FIRMWARE("radeon/PALM_pfp.bin"); |
| 90 | MODULE_FIRMWARE("radeon/PALM_me.bin"); |
| 91 | MODULE_FIRMWARE("radeon/SUMO_rlc.bin"); |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 92 | MODULE_FIRMWARE("radeon/SUMO_pfp.bin"); |
| 93 | MODULE_FIRMWARE("radeon/SUMO_me.bin"); |
| 94 | MODULE_FIRMWARE("radeon/SUMO2_pfp.bin"); |
| 95 | MODULE_FIRMWARE("radeon/SUMO2_me.bin"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 96 | |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 97 | static const u32 crtc_offsets[2] = |
| 98 | { |
| 99 | 0, |
| 100 | AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL |
| 101 | }; |
| 102 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 103 | int r600_debugfs_mc_info_init(struct radeon_device *rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 104 | |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 105 | /* r600,rv610,rv630,rv620,rv635,rv670 */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 106 | int r600_mc_wait_for_idle(struct radeon_device *rdev); |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 107 | static void r600_gpu_init(struct radeon_device *rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 108 | void r600_fini(struct radeon_device *rdev); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 109 | void r600_irq_disable(struct radeon_device *rdev); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 110 | static void r600_pcie_gen2_enable(struct radeon_device *rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 111 | |
Alex Deucher | 454d2e2 | 2013-02-14 10:04:02 -0500 | [diff] [blame] | 112 | /** |
| 113 | * r600_get_xclk - get the xclk |
| 114 | * |
| 115 | * @rdev: radeon_device pointer |
| 116 | * |
| 117 | * Returns the reference clock used by the gfx engine |
| 118 | * (r6xx, IGPs, APUs). |
| 119 | */ |
| 120 | u32 r600_get_xclk(struct radeon_device *rdev) |
| 121 | { |
| 122 | return rdev->clock.spll.reference_freq; |
| 123 | } |
| 124 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 125 | /* get temperature in millidegrees */ |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 126 | int rv6xx_get_temp(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 127 | { |
| 128 | u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >> |
| 129 | ASIC_T_SHIFT; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 130 | int actual_temp = temp & 0xff; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 131 | |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 132 | if (temp & 0x100) |
| 133 | actual_temp -= 256; |
| 134 | |
| 135 | return actual_temp * 1000; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 138 | void r600_pm_get_dynpm_state(struct radeon_device *rdev) |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 139 | { |
| 140 | int i; |
| 141 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 142 | rdev->pm.dynpm_can_upclock = true; |
| 143 | rdev->pm.dynpm_can_downclock = true; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 144 | |
| 145 | /* power state array is low to high, default is first */ |
| 146 | if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) { |
| 147 | int min_power_state_index = 0; |
| 148 | |
| 149 | if (rdev->pm.num_power_states > 2) |
| 150 | min_power_state_index = 1; |
| 151 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 152 | switch (rdev->pm.dynpm_planned_action) { |
| 153 | case DYNPM_ACTION_MINIMUM: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 154 | rdev->pm.requested_power_state_index = min_power_state_index; |
| 155 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 156 | rdev->pm.dynpm_can_downclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 157 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 158 | case DYNPM_ACTION_DOWNCLOCK: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 159 | if (rdev->pm.current_power_state_index == min_power_state_index) { |
| 160 | rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 161 | rdev->pm.dynpm_can_downclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 162 | } else { |
| 163 | if (rdev->pm.active_crtc_count > 1) { |
| 164 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 165 | if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 166 | continue; |
| 167 | else if (i >= rdev->pm.current_power_state_index) { |
| 168 | rdev->pm.requested_power_state_index = |
| 169 | rdev->pm.current_power_state_index; |
| 170 | break; |
| 171 | } else { |
| 172 | rdev->pm.requested_power_state_index = i; |
| 173 | break; |
| 174 | } |
| 175 | } |
Alex Deucher | 773c3fa | 2010-06-25 16:21:27 -0400 | [diff] [blame] | 176 | } else { |
| 177 | if (rdev->pm.current_power_state_index == 0) |
| 178 | rdev->pm.requested_power_state_index = |
| 179 | rdev->pm.num_power_states - 1; |
| 180 | else |
| 181 | rdev->pm.requested_power_state_index = |
| 182 | rdev->pm.current_power_state_index - 1; |
| 183 | } |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 184 | } |
| 185 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 186 | /* don't use the power state if crtcs are active and no display flag is set */ |
| 187 | if ((rdev->pm.active_crtc_count > 0) && |
| 188 | (rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 189 | clock_info[rdev->pm.requested_clock_mode_index].flags & |
| 190 | RADEON_PM_MODE_NO_DISPLAY)) { |
| 191 | rdev->pm.requested_power_state_index++; |
| 192 | } |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 193 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 194 | case DYNPM_ACTION_UPCLOCK: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 195 | if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) { |
| 196 | rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 197 | rdev->pm.dynpm_can_upclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 198 | } else { |
| 199 | if (rdev->pm.active_crtc_count > 1) { |
| 200 | for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) { |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 201 | if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 202 | continue; |
| 203 | else if (i <= rdev->pm.current_power_state_index) { |
| 204 | rdev->pm.requested_power_state_index = |
| 205 | rdev->pm.current_power_state_index; |
| 206 | break; |
| 207 | } else { |
| 208 | rdev->pm.requested_power_state_index = i; |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | } else |
| 213 | rdev->pm.requested_power_state_index = |
| 214 | rdev->pm.current_power_state_index + 1; |
| 215 | } |
| 216 | rdev->pm.requested_clock_mode_index = 0; |
| 217 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 218 | case DYNPM_ACTION_DEFAULT: |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 219 | rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index; |
| 220 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 221 | rdev->pm.dynpm_can_upclock = false; |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 222 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 223 | case DYNPM_ACTION_NONE: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 224 | default: |
| 225 | DRM_ERROR("Requested mode for not defined action\n"); |
| 226 | return; |
| 227 | } |
| 228 | } else { |
| 229 | /* XXX select a power state based on AC/DC, single/dualhead, etc. */ |
| 230 | /* for now just select the first power state and switch between clock modes */ |
| 231 | /* power state array is low to high, default is first (0) */ |
| 232 | if (rdev->pm.active_crtc_count > 1) { |
| 233 | rdev->pm.requested_power_state_index = -1; |
| 234 | /* start at 1 as we don't want the default mode */ |
| 235 | for (i = 1; i < rdev->pm.num_power_states; i++) { |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 236 | if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 237 | continue; |
| 238 | else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) || |
| 239 | (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) { |
| 240 | rdev->pm.requested_power_state_index = i; |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | /* if nothing selected, grab the default state. */ |
| 245 | if (rdev->pm.requested_power_state_index == -1) |
| 246 | rdev->pm.requested_power_state_index = 0; |
| 247 | } else |
| 248 | rdev->pm.requested_power_state_index = 1; |
| 249 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 250 | switch (rdev->pm.dynpm_planned_action) { |
| 251 | case DYNPM_ACTION_MINIMUM: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 252 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 253 | rdev->pm.dynpm_can_downclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 254 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 255 | case DYNPM_ACTION_DOWNCLOCK: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 256 | if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) { |
| 257 | if (rdev->pm.current_clock_mode_index == 0) { |
| 258 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 259 | rdev->pm.dynpm_can_downclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 260 | } else |
| 261 | rdev->pm.requested_clock_mode_index = |
| 262 | rdev->pm.current_clock_mode_index - 1; |
| 263 | } else { |
| 264 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 265 | rdev->pm.dynpm_can_downclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 266 | } |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 267 | /* don't use the power state if crtcs are active and no display flag is set */ |
| 268 | if ((rdev->pm.active_crtc_count > 0) && |
| 269 | (rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 270 | clock_info[rdev->pm.requested_clock_mode_index].flags & |
| 271 | RADEON_PM_MODE_NO_DISPLAY)) { |
| 272 | rdev->pm.requested_clock_mode_index++; |
| 273 | } |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 274 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 275 | case DYNPM_ACTION_UPCLOCK: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 276 | if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) { |
| 277 | if (rdev->pm.current_clock_mode_index == |
| 278 | (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) { |
| 279 | rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 280 | rdev->pm.dynpm_can_upclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 281 | } else |
| 282 | rdev->pm.requested_clock_mode_index = |
| 283 | rdev->pm.current_clock_mode_index + 1; |
| 284 | } else { |
| 285 | rdev->pm.requested_clock_mode_index = |
| 286 | rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 287 | rdev->pm.dynpm_can_upclock = false; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 288 | } |
| 289 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 290 | case DYNPM_ACTION_DEFAULT: |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 291 | rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index; |
| 292 | rdev->pm.requested_clock_mode_index = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 293 | rdev->pm.dynpm_can_upclock = false; |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 294 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 295 | case DYNPM_ACTION_NONE: |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 296 | default: |
| 297 | DRM_ERROR("Requested mode for not defined action\n"); |
| 298 | return; |
| 299 | } |
| 300 | } |
| 301 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 302 | DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n", |
Alex Deucher | ce8a3eb | 2010-05-07 16:58:27 -0400 | [diff] [blame] | 303 | rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 304 | clock_info[rdev->pm.requested_clock_mode_index].sclk, |
| 305 | rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 306 | clock_info[rdev->pm.requested_clock_mode_index].mclk, |
| 307 | rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 308 | pcie_lanes); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 311 | void rs780_pm_init_profile(struct radeon_device *rdev) |
| 312 | { |
| 313 | if (rdev->pm.num_power_states == 2) { |
| 314 | /* default */ |
| 315 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 316 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 317 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 318 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; |
| 319 | /* low sh */ |
| 320 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0; |
| 321 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0; |
| 322 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 323 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 324 | /* mid sh */ |
| 325 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0; |
| 326 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0; |
| 327 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 328 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 329 | /* high sh */ |
| 330 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0; |
| 331 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1; |
| 332 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 333 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; |
| 334 | /* low mh */ |
| 335 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0; |
| 336 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0; |
| 337 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 338 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 339 | /* mid mh */ |
| 340 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0; |
| 341 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0; |
| 342 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 343 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 344 | /* high mh */ |
| 345 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0; |
| 346 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1; |
| 347 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 348 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; |
| 349 | } else if (rdev->pm.num_power_states == 3) { |
| 350 | /* default */ |
| 351 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 352 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 353 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 354 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; |
| 355 | /* low sh */ |
| 356 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1; |
| 357 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1; |
| 358 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 359 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 360 | /* mid sh */ |
| 361 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1; |
| 362 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1; |
| 363 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 364 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 365 | /* high sh */ |
| 366 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1; |
| 367 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2; |
| 368 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 369 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; |
| 370 | /* low mh */ |
| 371 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1; |
| 372 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1; |
| 373 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 374 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 375 | /* mid mh */ |
| 376 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1; |
| 377 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1; |
| 378 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 379 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 380 | /* high mh */ |
| 381 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1; |
| 382 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2; |
| 383 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 384 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; |
| 385 | } else { |
| 386 | /* default */ |
| 387 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 388 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 389 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 390 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; |
| 391 | /* low sh */ |
| 392 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2; |
| 393 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2; |
| 394 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 395 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 396 | /* mid sh */ |
| 397 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2; |
| 398 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2; |
| 399 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 400 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 401 | /* high sh */ |
| 402 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2; |
| 403 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3; |
| 404 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 405 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; |
| 406 | /* low mh */ |
| 407 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2; |
| 408 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0; |
| 409 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 410 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 411 | /* mid mh */ |
| 412 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2; |
| 413 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0; |
| 414 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 415 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 416 | /* high mh */ |
| 417 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2; |
| 418 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3; |
| 419 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 420 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void r600_pm_init_profile(struct radeon_device *rdev) |
| 425 | { |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 426 | int idx; |
| 427 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 428 | if (rdev->family == CHIP_R600) { |
| 429 | /* XXX */ |
| 430 | /* default */ |
| 431 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 432 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 433 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 434 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 435 | /* low sh */ |
| 436 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 437 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 438 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 439 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 440 | /* mid sh */ |
| 441 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 442 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 443 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 444 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 445 | /* high sh */ |
| 446 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 447 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 448 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 449 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 450 | /* low mh */ |
| 451 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 452 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 453 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 454 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 455 | /* mid mh */ |
| 456 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 457 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 458 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 459 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 460 | /* high mh */ |
| 461 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 462 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 463 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 464 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 465 | } else { |
| 466 | if (rdev->pm.num_power_states < 4) { |
| 467 | /* default */ |
| 468 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 469 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 470 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 471 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2; |
| 472 | /* low sh */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 473 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1; |
| 474 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1; |
| 475 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 476 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
| 477 | /* mid sh */ |
| 478 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1; |
| 479 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1; |
| 480 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 481 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 482 | /* high sh */ |
| 483 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1; |
| 484 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1; |
| 485 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 486 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2; |
| 487 | /* low mh */ |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 488 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2; |
| 489 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 490 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 491 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
| 492 | /* low mh */ |
| 493 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2; |
| 494 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2; |
| 495 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 496 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 497 | /* high mh */ |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 498 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2; |
| 499 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2; |
| 500 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 501 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2; |
| 502 | } else { |
| 503 | /* default */ |
| 504 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; |
| 505 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; |
| 506 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; |
| 507 | rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2; |
| 508 | /* low sh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 509 | if (rdev->flags & RADEON_IS_MOBILITY) |
| 510 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); |
| 511 | else |
| 512 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); |
| 513 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx; |
| 514 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx; |
| 515 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; |
| 516 | rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 517 | /* mid sh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 518 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx; |
| 519 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx; |
| 520 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; |
| 521 | rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 522 | /* high sh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 523 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); |
| 524 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx; |
| 525 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 526 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; |
| 527 | rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2; |
| 528 | /* low mh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 529 | if (rdev->flags & RADEON_IS_MOBILITY) |
| 530 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1); |
| 531 | else |
| 532 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1); |
| 533 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx; |
| 534 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx; |
| 535 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; |
| 536 | rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 537 | /* mid mh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 538 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx; |
| 539 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx; |
| 540 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; |
| 541 | rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1; |
Alex Deucher | 4bff517 | 2010-05-17 19:41:26 -0400 | [diff] [blame] | 542 | /* high mh */ |
Alex Deucher | bbe26ff | 2011-11-04 10:09:42 -0400 | [diff] [blame] | 543 | idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1); |
| 544 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx; |
| 545 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 546 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; |
| 547 | rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2; |
| 548 | } |
| 549 | } |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 552 | void r600_pm_misc(struct radeon_device *rdev) |
| 553 | { |
Rafał Miłecki | a081a9d | 2010-06-07 18:20:25 -0400 | [diff] [blame] | 554 | int req_ps_idx = rdev->pm.requested_power_state_index; |
| 555 | int req_cm_idx = rdev->pm.requested_clock_mode_index; |
| 556 | struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx]; |
| 557 | struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 558 | |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 559 | if ((voltage->type == VOLTAGE_SW) && voltage->voltage) { |
Alex Deucher | a377e18 | 2011-06-20 13:00:31 -0400 | [diff] [blame] | 560 | /* 0xff01 is a flag rather then an actual voltage */ |
| 561 | if (voltage->voltage == 0xff01) |
| 562 | return; |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 563 | if (voltage->voltage != rdev->pm.current_vddc) { |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 564 | radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 565 | rdev->pm.current_vddc = voltage->voltage; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 566 | DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage); |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 567 | } |
| 568 | } |
Alex Deucher | 49e02b7 | 2010-04-23 17:57:27 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Alex Deucher | def9ba9 | 2010-04-22 12:39:58 -0400 | [diff] [blame] | 571 | bool r600_gui_idle(struct radeon_device *rdev) |
| 572 | { |
| 573 | if (RREG32(GRBM_STATUS) & GUI_ACTIVE) |
| 574 | return false; |
| 575 | else |
| 576 | return true; |
| 577 | } |
| 578 | |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 579 | /* hpd for digital panel detect/disconnect */ |
| 580 | bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) |
| 581 | { |
| 582 | bool connected = false; |
| 583 | |
| 584 | if (ASIC_IS_DCE3(rdev)) { |
| 585 | switch (hpd) { |
| 586 | case RADEON_HPD_1: |
| 587 | if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE) |
| 588 | connected = true; |
| 589 | break; |
| 590 | case RADEON_HPD_2: |
| 591 | if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE) |
| 592 | connected = true; |
| 593 | break; |
| 594 | case RADEON_HPD_3: |
| 595 | if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE) |
| 596 | connected = true; |
| 597 | break; |
| 598 | case RADEON_HPD_4: |
| 599 | if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE) |
| 600 | connected = true; |
| 601 | break; |
| 602 | /* DCE 3.2 */ |
| 603 | case RADEON_HPD_5: |
| 604 | if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE) |
| 605 | connected = true; |
| 606 | break; |
| 607 | case RADEON_HPD_6: |
| 608 | if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE) |
| 609 | connected = true; |
| 610 | break; |
| 611 | default: |
| 612 | break; |
| 613 | } |
| 614 | } else { |
| 615 | switch (hpd) { |
| 616 | case RADEON_HPD_1: |
| 617 | if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE) |
| 618 | connected = true; |
| 619 | break; |
| 620 | case RADEON_HPD_2: |
| 621 | if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE) |
| 622 | connected = true; |
| 623 | break; |
| 624 | case RADEON_HPD_3: |
| 625 | if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE) |
| 626 | connected = true; |
| 627 | break; |
| 628 | default: |
| 629 | break; |
| 630 | } |
| 631 | } |
| 632 | return connected; |
| 633 | } |
| 634 | |
| 635 | void r600_hpd_set_polarity(struct radeon_device *rdev, |
Alex Deucher | 429770b | 2009-12-04 15:26:55 -0500 | [diff] [blame] | 636 | enum radeon_hpd_id hpd) |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 637 | { |
| 638 | u32 tmp; |
| 639 | bool connected = r600_hpd_sense(rdev, hpd); |
| 640 | |
| 641 | if (ASIC_IS_DCE3(rdev)) { |
| 642 | switch (hpd) { |
| 643 | case RADEON_HPD_1: |
| 644 | tmp = RREG32(DC_HPD1_INT_CONTROL); |
| 645 | if (connected) |
| 646 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 647 | else |
| 648 | tmp |= DC_HPDx_INT_POLARITY; |
| 649 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 650 | break; |
| 651 | case RADEON_HPD_2: |
| 652 | tmp = RREG32(DC_HPD2_INT_CONTROL); |
| 653 | if (connected) |
| 654 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 655 | else |
| 656 | tmp |= DC_HPDx_INT_POLARITY; |
| 657 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 658 | break; |
| 659 | case RADEON_HPD_3: |
| 660 | tmp = RREG32(DC_HPD3_INT_CONTROL); |
| 661 | if (connected) |
| 662 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 663 | else |
| 664 | tmp |= DC_HPDx_INT_POLARITY; |
| 665 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 666 | break; |
| 667 | case RADEON_HPD_4: |
| 668 | tmp = RREG32(DC_HPD4_INT_CONTROL); |
| 669 | if (connected) |
| 670 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 671 | else |
| 672 | tmp |= DC_HPDx_INT_POLARITY; |
| 673 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 674 | break; |
| 675 | case RADEON_HPD_5: |
| 676 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 677 | if (connected) |
| 678 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 679 | else |
| 680 | tmp |= DC_HPDx_INT_POLARITY; |
| 681 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
| 682 | break; |
| 683 | /* DCE 3.2 */ |
| 684 | case RADEON_HPD_6: |
| 685 | tmp = RREG32(DC_HPD6_INT_CONTROL); |
| 686 | if (connected) |
| 687 | tmp &= ~DC_HPDx_INT_POLARITY; |
| 688 | else |
| 689 | tmp |= DC_HPDx_INT_POLARITY; |
| 690 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
| 691 | break; |
| 692 | default: |
| 693 | break; |
| 694 | } |
| 695 | } else { |
| 696 | switch (hpd) { |
| 697 | case RADEON_HPD_1: |
| 698 | tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL); |
| 699 | if (connected) |
| 700 | tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 701 | else |
| 702 | tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 703 | WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp); |
| 704 | break; |
| 705 | case RADEON_HPD_2: |
| 706 | tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL); |
| 707 | if (connected) |
| 708 | tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 709 | else |
| 710 | tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 711 | WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp); |
| 712 | break; |
| 713 | case RADEON_HPD_3: |
| 714 | tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL); |
| 715 | if (connected) |
| 716 | tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 717 | else |
| 718 | tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY; |
| 719 | WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp); |
| 720 | break; |
| 721 | default: |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | void r600_hpd_init(struct radeon_device *rdev) |
| 728 | { |
| 729 | struct drm_device *dev = rdev->ddev; |
| 730 | struct drm_connector *connector; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 731 | unsigned enable = 0; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 732 | |
Alex Deucher | 64912e9 | 2011-11-03 11:21:39 -0400 | [diff] [blame] | 733 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 734 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 735 | |
Jerome Glisse | 455c89b | 2012-05-04 11:06:22 -0400 | [diff] [blame] | 736 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP || |
| 737 | connector->connector_type == DRM_MODE_CONNECTOR_LVDS) { |
| 738 | /* don't try to enable hpd on eDP or LVDS avoid breaking the |
| 739 | * aux dp channel on imac and help (but not completely fix) |
| 740 | * https://bugzilla.redhat.com/show_bug.cgi?id=726143 |
| 741 | */ |
| 742 | continue; |
| 743 | } |
Alex Deucher | 64912e9 | 2011-11-03 11:21:39 -0400 | [diff] [blame] | 744 | if (ASIC_IS_DCE3(rdev)) { |
| 745 | u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa); |
| 746 | if (ASIC_IS_DCE32(rdev)) |
| 747 | tmp |= DC_HPDx_EN; |
| 748 | |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 749 | switch (radeon_connector->hpd.hpd) { |
| 750 | case RADEON_HPD_1: |
| 751 | WREG32(DC_HPD1_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 752 | break; |
| 753 | case RADEON_HPD_2: |
| 754 | WREG32(DC_HPD2_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 755 | break; |
| 756 | case RADEON_HPD_3: |
| 757 | WREG32(DC_HPD3_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 758 | break; |
| 759 | case RADEON_HPD_4: |
| 760 | WREG32(DC_HPD4_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 761 | break; |
| 762 | /* DCE 3.2 */ |
| 763 | case RADEON_HPD_5: |
| 764 | WREG32(DC_HPD5_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 765 | break; |
| 766 | case RADEON_HPD_6: |
| 767 | WREG32(DC_HPD6_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 768 | break; |
| 769 | default: |
| 770 | break; |
| 771 | } |
Alex Deucher | 64912e9 | 2011-11-03 11:21:39 -0400 | [diff] [blame] | 772 | } else { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 773 | switch (radeon_connector->hpd.hpd) { |
| 774 | case RADEON_HPD_1: |
| 775 | WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 776 | break; |
| 777 | case RADEON_HPD_2: |
| 778 | WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 779 | break; |
| 780 | case RADEON_HPD_3: |
| 781 | WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 782 | break; |
| 783 | default: |
| 784 | break; |
| 785 | } |
| 786 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 787 | enable |= 1 << radeon_connector->hpd.hpd; |
Alex Deucher | 64912e9 | 2011-11-03 11:21:39 -0400 | [diff] [blame] | 788 | radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 789 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 790 | radeon_irq_kms_enable_hpd(rdev, enable); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | void r600_hpd_fini(struct radeon_device *rdev) |
| 794 | { |
| 795 | struct drm_device *dev = rdev->ddev; |
| 796 | struct drm_connector *connector; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 797 | unsigned disable = 0; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 798 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 799 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 800 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 801 | if (ASIC_IS_DCE3(rdev)) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 802 | switch (radeon_connector->hpd.hpd) { |
| 803 | case RADEON_HPD_1: |
| 804 | WREG32(DC_HPD1_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 805 | break; |
| 806 | case RADEON_HPD_2: |
| 807 | WREG32(DC_HPD2_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 808 | break; |
| 809 | case RADEON_HPD_3: |
| 810 | WREG32(DC_HPD3_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 811 | break; |
| 812 | case RADEON_HPD_4: |
| 813 | WREG32(DC_HPD4_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 814 | break; |
| 815 | /* DCE 3.2 */ |
| 816 | case RADEON_HPD_5: |
| 817 | WREG32(DC_HPD5_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 818 | break; |
| 819 | case RADEON_HPD_6: |
| 820 | WREG32(DC_HPD6_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 821 | break; |
| 822 | default: |
| 823 | break; |
| 824 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 825 | } else { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 826 | switch (radeon_connector->hpd.hpd) { |
| 827 | case RADEON_HPD_1: |
| 828 | WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 829 | break; |
| 830 | case RADEON_HPD_2: |
| 831 | WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 832 | break; |
| 833 | case RADEON_HPD_3: |
| 834 | WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 835 | break; |
| 836 | default: |
| 837 | break; |
| 838 | } |
| 839 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 840 | disable |= 1 << radeon_connector->hpd.hpd; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 841 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 842 | radeon_irq_kms_disable_hpd(rdev, disable); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 843 | } |
| 844 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 845 | /* |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 846 | * R600 PCIE GART |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 847 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 848 | void r600_pcie_gart_tlb_flush(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 849 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 850 | unsigned i; |
| 851 | u32 tmp; |
| 852 | |
Dave Airlie | 2e98f10 | 2010-02-15 15:54:45 +1000 | [diff] [blame] | 853 | /* flush hdp cache so updates hit vram */ |
Alex Deucher | f3886f8 | 2010-12-08 10:05:34 -0500 | [diff] [blame] | 854 | if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) && |
| 855 | !(rdev->flags & RADEON_IS_AGP)) { |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 856 | void __iomem *ptr = (void *)rdev->gart.ptr; |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 857 | u32 tmp; |
| 858 | |
| 859 | /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read |
| 860 | * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL |
Alex Deucher | f3886f8 | 2010-12-08 10:05:34 -0500 | [diff] [blame] | 861 | * This seems to cause problems on some AGP cards. Just use the old |
| 862 | * method for them. |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 863 | */ |
| 864 | WREG32(HDP_DEBUG1, 0); |
| 865 | tmp = readl((void __iomem *)ptr); |
| 866 | } else |
| 867 | WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
Dave Airlie | 2e98f10 | 2010-02-15 15:54:45 +1000 | [diff] [blame] | 868 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 869 | WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12); |
| 870 | WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12); |
| 871 | WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1)); |
| 872 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 873 | /* read MC_STATUS */ |
| 874 | tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE); |
| 875 | tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT; |
| 876 | if (tmp == 2) { |
| 877 | printk(KERN_WARNING "[drm] r600 flush TLB failed\n"); |
| 878 | return; |
| 879 | } |
| 880 | if (tmp) { |
| 881 | return; |
| 882 | } |
| 883 | udelay(1); |
| 884 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 885 | } |
| 886 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 887 | int r600_pcie_gart_init(struct radeon_device *rdev) |
| 888 | { |
| 889 | int r; |
| 890 | |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 891 | if (rdev->gart.robj) { |
Joe Perches | fce7d61 | 2010-10-30 21:08:30 +0000 | [diff] [blame] | 892 | WARN(1, "R600 PCIE GART already initialized\n"); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 893 | return 0; |
| 894 | } |
| 895 | /* Initialize common gart structure */ |
| 896 | r = radeon_gart_init(rdev); |
| 897 | if (r) |
| 898 | return r; |
| 899 | rdev->gart.table_size = rdev->gart.num_gpu_pages * 8; |
| 900 | return radeon_gart_table_vram_alloc(rdev); |
| 901 | } |
| 902 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 903 | static int r600_pcie_gart_enable(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 904 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 905 | u32 tmp; |
| 906 | int r, i; |
| 907 | |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 908 | if (rdev->gart.robj == NULL) { |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 909 | dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); |
| 910 | return -EINVAL; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 911 | } |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 912 | r = radeon_gart_table_vram_pin(rdev); |
| 913 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 914 | return r; |
Dave Airlie | 8256856 | 2010-02-05 16:00:07 +1000 | [diff] [blame] | 915 | radeon_gart_restore(rdev); |
Dave Airlie | bc1a631 | 2009-09-15 11:07:52 +1000 | [diff] [blame] | 916 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 917 | /* Setup L2 cache */ |
| 918 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 919 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 920 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 921 | WREG32(VM_L2_CNTL2, 0); |
| 922 | WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1)); |
| 923 | /* Setup TLB control */ |
| 924 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 925 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 926 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) | |
| 927 | ENABLE_WAIT_L2_QUERY; |
| 928 | WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp); |
| 929 | WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp); |
| 930 | WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING); |
| 931 | WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp); |
| 932 | WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp); |
| 933 | WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp); |
| 934 | WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp); |
| 935 | WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp); |
| 936 | WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp); |
| 937 | WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp); |
| 938 | WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp); |
| 939 | WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp); |
| 940 | WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE); |
| 941 | WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE); |
| 942 | WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 943 | WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 944 | WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); |
| 945 | WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | |
| 946 | RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); |
| 947 | WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, |
| 948 | (u32)(rdev->dummy_page.addr >> 12)); |
| 949 | for (i = 1; i < 7; i++) |
| 950 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 951 | |
| 952 | r600_pcie_gart_tlb_flush(rdev); |
Tormod Volden | fcf4de5 | 2011-08-31 21:54:07 +0000 | [diff] [blame] | 953 | DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n", |
| 954 | (unsigned)(rdev->mc.gtt_size >> 20), |
| 955 | (unsigned long long)rdev->gart.table_addr); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 956 | rdev->gart.ready = true; |
| 957 | return 0; |
| 958 | } |
| 959 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 960 | static void r600_pcie_gart_disable(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 961 | { |
| 962 | u32 tmp; |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 963 | int i; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 964 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 965 | /* Disable all tables */ |
| 966 | for (i = 0; i < 7; i++) |
| 967 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 968 | |
| 969 | /* Disable L2 cache */ |
| 970 | WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING | |
| 971 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 972 | WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1)); |
| 973 | /* Setup L1 TLB control */ |
| 974 | tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) | |
| 975 | ENABLE_WAIT_L2_QUERY; |
| 976 | WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp); |
| 977 | WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp); |
| 978 | WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp); |
| 979 | WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp); |
| 980 | WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp); |
| 981 | WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp); |
| 982 | WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp); |
| 983 | WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp); |
| 984 | WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp); |
| 985 | WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp); |
| 986 | WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp); |
| 987 | WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp); |
| 988 | WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp); |
| 989 | WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp); |
Jerome Glisse | c9a1be9 | 2011-11-03 11:16:49 -0400 | [diff] [blame] | 990 | radeon_gart_table_vram_unpin(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 991 | } |
| 992 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 993 | static void r600_pcie_gart_fini(struct radeon_device *rdev) |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 994 | { |
Jerome Glisse | f927456 | 2010-03-17 14:44:29 +0000 | [diff] [blame] | 995 | radeon_gart_fini(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 996 | r600_pcie_gart_disable(rdev); |
| 997 | radeon_gart_table_vram_free(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 998 | } |
| 999 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1000 | static void r600_agp_enable(struct radeon_device *rdev) |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1001 | { |
| 1002 | u32 tmp; |
| 1003 | int i; |
| 1004 | |
| 1005 | /* Setup L2 cache */ |
| 1006 | WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | |
| 1007 | ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | |
| 1008 | EFFECTIVE_L2_QUEUE_SIZE(7)); |
| 1009 | WREG32(VM_L2_CNTL2, 0); |
| 1010 | WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1)); |
| 1011 | /* Setup TLB control */ |
| 1012 | tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | |
| 1013 | SYSTEM_ACCESS_MODE_NOT_IN_SYS | |
| 1014 | EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) | |
| 1015 | ENABLE_WAIT_L2_QUERY; |
| 1016 | WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp); |
| 1017 | WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp); |
| 1018 | WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING); |
| 1019 | WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp); |
| 1020 | WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp); |
| 1021 | WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp); |
| 1022 | WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp); |
| 1023 | WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp); |
| 1024 | WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp); |
| 1025 | WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp); |
| 1026 | WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp); |
| 1027 | WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp); |
| 1028 | WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE); |
| 1029 | WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE); |
| 1030 | for (i = 0; i < 7; i++) |
| 1031 | WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); |
| 1032 | } |
| 1033 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1034 | int r600_mc_wait_for_idle(struct radeon_device *rdev) |
| 1035 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1036 | unsigned i; |
| 1037 | u32 tmp; |
| 1038 | |
| 1039 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 1040 | /* read MC_STATUS */ |
| 1041 | tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00; |
| 1042 | if (!tmp) |
| 1043 | return 0; |
| 1044 | udelay(1); |
| 1045 | } |
| 1046 | return -1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1049 | static void r600_mc_program(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1050 | { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1051 | struct rv515_mc_save save; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1052 | u32 tmp; |
| 1053 | int i, j; |
| 1054 | |
| 1055 | /* Initialize HDP */ |
| 1056 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 1057 | WREG32((0x2c14 + j), 0x00000000); |
| 1058 | WREG32((0x2c18 + j), 0x00000000); |
| 1059 | WREG32((0x2c1c + j), 0x00000000); |
| 1060 | WREG32((0x2c20 + j), 0x00000000); |
| 1061 | WREG32((0x2c24 + j), 0x00000000); |
| 1062 | } |
| 1063 | WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0); |
| 1064 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1065 | rv515_mc_stop(rdev, &save); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1066 | if (r600_mc_wait_for_idle(rdev)) { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1067 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1068 | } |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1069 | /* Lockout access through VGA aperture (doesn't exist before R600) */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1070 | WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1071 | /* Update configuration */ |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1072 | if (rdev->flags & RADEON_IS_AGP) { |
| 1073 | if (rdev->mc.vram_start < rdev->mc.gtt_start) { |
| 1074 | /* VRAM before AGP */ |
| 1075 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 1076 | rdev->mc.vram_start >> 12); |
| 1077 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 1078 | rdev->mc.gtt_end >> 12); |
| 1079 | } else { |
| 1080 | /* VRAM after AGP */ |
| 1081 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, |
| 1082 | rdev->mc.gtt_start >> 12); |
| 1083 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, |
| 1084 | rdev->mc.vram_end >> 12); |
| 1085 | } |
| 1086 | } else { |
| 1087 | WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12); |
| 1088 | WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12); |
| 1089 | } |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1090 | WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1091 | tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1092 | tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); |
| 1093 | WREG32(MC_VM_FB_LOCATION, tmp); |
| 1094 | WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8)); |
| 1095 | WREG32(HDP_NONSURFACE_INFO, (2 << 7)); |
Jerome Glisse | 46fcd2b | 2010-06-03 19:34:48 +0200 | [diff] [blame] | 1096 | WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1097 | if (rdev->flags & RADEON_IS_AGP) { |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 1098 | WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22); |
| 1099 | WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1100 | WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22); |
| 1101 | } else { |
| 1102 | WREG32(MC_VM_AGP_BASE, 0); |
| 1103 | WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF); |
| 1104 | WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF); |
| 1105 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1106 | if (r600_mc_wait_for_idle(rdev)) { |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1107 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1108 | } |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1109 | rv515_mc_resume(rdev, &save); |
Dave Airlie | 698443d | 2009-09-18 14:16:38 +1000 | [diff] [blame] | 1110 | /* we need to own VRAM, so turn off the VGA renderer here |
| 1111 | * to stop it overwriting our objects */ |
Jerome Glisse | d39c3b8 | 2009-09-28 18:34:43 +0200 | [diff] [blame] | 1112 | rv515_vga_render_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1115 | /** |
| 1116 | * r600_vram_gtt_location - try to find VRAM & GTT location |
| 1117 | * @rdev: radeon device structure holding all necessary informations |
| 1118 | * @mc: memory controller structure holding memory informations |
| 1119 | * |
| 1120 | * Function will place try to place VRAM at same place as in CPU (PCI) |
| 1121 | * address space as some GPU seems to have issue when we reprogram at |
| 1122 | * different address space. |
| 1123 | * |
| 1124 | * If there is not enough space to fit the unvisible VRAM after the |
| 1125 | * aperture then we limit the VRAM size to the aperture. |
| 1126 | * |
| 1127 | * If we are using AGP then place VRAM adjacent to AGP aperture are we need |
| 1128 | * them to be in one from GPU point of view so that we can program GPU to |
| 1129 | * catch access outside them (weird GPU policy see ??). |
| 1130 | * |
| 1131 | * This function will never fails, worst case are limiting VRAM or GTT. |
| 1132 | * |
| 1133 | * Note: GTT start, end, size should be initialized before calling this |
| 1134 | * function on AGP platform. |
| 1135 | */ |
Alex Deucher | 0ef0c1f | 2010-11-22 17:56:26 -0500 | [diff] [blame] | 1136 | static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1137 | { |
| 1138 | u64 size_bf, size_af; |
| 1139 | |
| 1140 | if (mc->mc_vram_size > 0xE0000000) { |
| 1141 | /* leave room for at least 512M GTT */ |
| 1142 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1143 | mc->real_vram_size = 0xE0000000; |
| 1144 | mc->mc_vram_size = 0xE0000000; |
| 1145 | } |
| 1146 | if (rdev->flags & RADEON_IS_AGP) { |
| 1147 | size_bf = mc->gtt_start; |
Alex Deucher | 9ed8b1f | 2013-04-08 11:13:01 -0400 | [diff] [blame] | 1148 | size_af = mc->mc_mask - mc->gtt_end; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1149 | if (size_bf > size_af) { |
| 1150 | if (mc->mc_vram_size > size_bf) { |
| 1151 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1152 | mc->real_vram_size = size_bf; |
| 1153 | mc->mc_vram_size = size_bf; |
| 1154 | } |
| 1155 | mc->vram_start = mc->gtt_start - mc->mc_vram_size; |
| 1156 | } else { |
| 1157 | if (mc->mc_vram_size > size_af) { |
| 1158 | dev_warn(rdev->dev, "limiting VRAM\n"); |
| 1159 | mc->real_vram_size = size_af; |
| 1160 | mc->mc_vram_size = size_af; |
| 1161 | } |
Jerome Glisse | dfc6ae5 | 2012-04-17 16:51:38 -0400 | [diff] [blame] | 1162 | mc->vram_start = mc->gtt_end + 1; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1163 | } |
| 1164 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 1165 | dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", |
| 1166 | mc->mc_vram_size >> 20, mc->vram_start, |
| 1167 | mc->vram_end, mc->real_vram_size >> 20); |
| 1168 | } else { |
| 1169 | u64 base = 0; |
Alex Deucher | 8961d52 | 2010-12-03 14:37:22 -0500 | [diff] [blame] | 1170 | if (rdev->flags & RADEON_IS_IGP) { |
| 1171 | base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF; |
| 1172 | base <<= 24; |
| 1173 | } |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1174 | radeon_vram_location(rdev, &rdev->mc, base); |
Alex Deucher | 8d369bb | 2010-07-15 10:51:10 -0400 | [diff] [blame] | 1175 | rdev->mc.gtt_base_align = 0; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1176 | radeon_gtt_location(rdev, mc); |
| 1177 | } |
| 1178 | } |
| 1179 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1180 | static int r600_mc_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1181 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1182 | u32 tmp; |
Alex Deucher | 5885b7a | 2009-10-19 17:23:33 -0400 | [diff] [blame] | 1183 | int chansize, numchan; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1184 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1185 | /* Get VRAM informations */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1186 | rdev->mc.vram_is_ddr = true; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1187 | tmp = RREG32(RAMCFG); |
| 1188 | if (tmp & CHANSIZE_OVERRIDE) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1189 | chansize = 16; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1190 | } else if (tmp & CHANSIZE_MASK) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1191 | chansize = 64; |
| 1192 | } else { |
| 1193 | chansize = 32; |
| 1194 | } |
Alex Deucher | 5885b7a | 2009-10-19 17:23:33 -0400 | [diff] [blame] | 1195 | tmp = RREG32(CHMAP); |
| 1196 | switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { |
| 1197 | case 0: |
| 1198 | default: |
| 1199 | numchan = 1; |
| 1200 | break; |
| 1201 | case 1: |
| 1202 | numchan = 2; |
| 1203 | break; |
| 1204 | case 2: |
| 1205 | numchan = 4; |
| 1206 | break; |
| 1207 | case 3: |
| 1208 | numchan = 8; |
| 1209 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1210 | } |
Alex Deucher | 5885b7a | 2009-10-19 17:23:33 -0400 | [diff] [blame] | 1211 | rdev->mc.vram_width = numchan * chansize; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1212 | /* Could aper size report 0 ? */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 1213 | rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0); |
| 1214 | rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1215 | /* Setup GPU memory space */ |
| 1216 | rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE); |
| 1217 | rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE); |
Jerome Glisse | 51e5fcd | 2010-02-19 14:33:54 +0000 | [diff] [blame] | 1218 | rdev->mc.visible_vram_size = rdev->mc.aper_size; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 1219 | r600_vram_gtt_location(rdev, &rdev->mc); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 1220 | |
Alex Deucher | f892034 | 2010-06-30 12:02:03 -0400 | [diff] [blame] | 1221 | if (rdev->flags & RADEON_IS_IGP) { |
| 1222 | rs690_pm_info(rdev); |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1223 | rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev); |
Alex Deucher | f892034 | 2010-06-30 12:02:03 -0400 | [diff] [blame] | 1224 | } |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 1225 | radeon_update_bandwidth_info(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1226 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1229 | int r600_vram_scratch_init(struct radeon_device *rdev) |
| 1230 | { |
| 1231 | int r; |
| 1232 | |
| 1233 | if (rdev->vram_scratch.robj == NULL) { |
| 1234 | r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, |
| 1235 | PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM, |
Alex Deucher | 40f5cf9 | 2012-05-10 18:33:13 -0400 | [diff] [blame] | 1236 | NULL, &rdev->vram_scratch.robj); |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 1237 | if (r) { |
| 1238 | return r; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | r = radeon_bo_reserve(rdev->vram_scratch.robj, false); |
| 1243 | if (unlikely(r != 0)) |
| 1244 | return r; |
| 1245 | r = radeon_bo_pin(rdev->vram_scratch.robj, |
| 1246 | RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr); |
| 1247 | if (r) { |
| 1248 | radeon_bo_unreserve(rdev->vram_scratch.robj); |
| 1249 | return r; |
| 1250 | } |
| 1251 | r = radeon_bo_kmap(rdev->vram_scratch.robj, |
| 1252 | (void **)&rdev->vram_scratch.ptr); |
| 1253 | if (r) |
| 1254 | radeon_bo_unpin(rdev->vram_scratch.robj); |
| 1255 | radeon_bo_unreserve(rdev->vram_scratch.robj); |
| 1256 | |
| 1257 | return r; |
| 1258 | } |
| 1259 | |
| 1260 | void r600_vram_scratch_fini(struct radeon_device *rdev) |
| 1261 | { |
| 1262 | int r; |
| 1263 | |
| 1264 | if (rdev->vram_scratch.robj == NULL) { |
| 1265 | return; |
| 1266 | } |
| 1267 | r = radeon_bo_reserve(rdev->vram_scratch.robj, false); |
| 1268 | if (likely(r == 0)) { |
| 1269 | radeon_bo_kunmap(rdev->vram_scratch.robj); |
| 1270 | radeon_bo_unpin(rdev->vram_scratch.robj); |
| 1271 | radeon_bo_unreserve(rdev->vram_scratch.robj); |
| 1272 | } |
| 1273 | radeon_bo_unref(&rdev->vram_scratch.robj); |
| 1274 | } |
| 1275 | |
Alex Deucher | 410a341 | 2013-01-18 13:05:39 -0500 | [diff] [blame] | 1276 | void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung) |
| 1277 | { |
| 1278 | u32 tmp = RREG32(R600_BIOS_3_SCRATCH); |
| 1279 | |
| 1280 | if (hung) |
| 1281 | tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG; |
| 1282 | else |
| 1283 | tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG; |
| 1284 | |
| 1285 | WREG32(R600_BIOS_3_SCRATCH, tmp); |
| 1286 | } |
| 1287 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1288 | static void r600_print_gpu_status_regs(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1289 | { |
Jerome Glisse | 64c56e8 | 2013-01-02 17:30:35 -0500 | [diff] [blame] | 1290 | dev_info(rdev->dev, " R_008010_GRBM_STATUS = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1291 | RREG32(R_008010_GRBM_STATUS)); |
Jerome Glisse | 64c56e8 | 2013-01-02 17:30:35 -0500 | [diff] [blame] | 1292 | dev_info(rdev->dev, " R_008014_GRBM_STATUS2 = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1293 | RREG32(R_008014_GRBM_STATUS2)); |
Jerome Glisse | 64c56e8 | 2013-01-02 17:30:35 -0500 | [diff] [blame] | 1294 | dev_info(rdev->dev, " R_000E50_SRBM_STATUS = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1295 | RREG32(R_000E50_SRBM_STATUS)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 1296 | dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1297 | RREG32(CP_STALLED_STAT1)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 1298 | dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1299 | RREG32(CP_STALLED_STAT2)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 1300 | dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1301 | RREG32(CP_BUSY_STAT)); |
Jerome Glisse | 440a7cd | 2012-06-27 12:25:01 -0400 | [diff] [blame] | 1302 | dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n", |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1303 | RREG32(CP_STAT)); |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1304 | dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n", |
| 1305 | RREG32(DMA_STATUS_REG)); |
| 1306 | } |
| 1307 | |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1308 | static bool r600_is_display_hung(struct radeon_device *rdev) |
| 1309 | { |
| 1310 | u32 crtc_hung = 0; |
| 1311 | u32 crtc_status[2]; |
| 1312 | u32 i, j, tmp; |
| 1313 | |
| 1314 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1315 | if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[i]) & AVIVO_CRTC_EN) { |
| 1316 | crtc_status[i] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]); |
| 1317 | crtc_hung |= (1 << i); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | for (j = 0; j < 10; j++) { |
| 1322 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1323 | if (crtc_hung & (1 << i)) { |
| 1324 | tmp = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]); |
| 1325 | if (tmp != crtc_status[i]) |
| 1326 | crtc_hung &= ~(1 << i); |
| 1327 | } |
| 1328 | } |
| 1329 | if (crtc_hung == 0) |
| 1330 | return false; |
| 1331 | udelay(100); |
| 1332 | } |
| 1333 | |
| 1334 | return true; |
| 1335 | } |
| 1336 | |
| 1337 | static u32 r600_gpu_check_soft_reset(struct radeon_device *rdev) |
| 1338 | { |
| 1339 | u32 reset_mask = 0; |
| 1340 | u32 tmp; |
| 1341 | |
| 1342 | /* GRBM_STATUS */ |
| 1343 | tmp = RREG32(R_008010_GRBM_STATUS); |
| 1344 | if (rdev->family >= CHIP_RV770) { |
| 1345 | if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) | |
| 1346 | G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) | |
| 1347 | G_008010_TA_BUSY(tmp) | G_008010_VGT_BUSY(tmp) | |
| 1348 | G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) | |
| 1349 | G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp)) |
| 1350 | reset_mask |= RADEON_RESET_GFX; |
| 1351 | } else { |
| 1352 | if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) | |
| 1353 | G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) | |
| 1354 | G_008010_TA03_BUSY(tmp) | G_008010_VGT_BUSY(tmp) | |
| 1355 | G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) | |
| 1356 | G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp)) |
| 1357 | reset_mask |= RADEON_RESET_GFX; |
| 1358 | } |
| 1359 | |
| 1360 | if (G_008010_CF_RQ_PENDING(tmp) | G_008010_PF_RQ_PENDING(tmp) | |
| 1361 | G_008010_CP_BUSY(tmp) | G_008010_CP_COHERENCY_BUSY(tmp)) |
| 1362 | reset_mask |= RADEON_RESET_CP; |
| 1363 | |
| 1364 | if (G_008010_GRBM_EE_BUSY(tmp)) |
| 1365 | reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP; |
| 1366 | |
| 1367 | /* DMA_STATUS_REG */ |
| 1368 | tmp = RREG32(DMA_STATUS_REG); |
| 1369 | if (!(tmp & DMA_IDLE)) |
| 1370 | reset_mask |= RADEON_RESET_DMA; |
| 1371 | |
| 1372 | /* SRBM_STATUS */ |
| 1373 | tmp = RREG32(R_000E50_SRBM_STATUS); |
| 1374 | if (G_000E50_RLC_RQ_PENDING(tmp) | G_000E50_RLC_BUSY(tmp)) |
| 1375 | reset_mask |= RADEON_RESET_RLC; |
| 1376 | |
| 1377 | if (G_000E50_IH_BUSY(tmp)) |
| 1378 | reset_mask |= RADEON_RESET_IH; |
| 1379 | |
| 1380 | if (G_000E50_SEM_BUSY(tmp)) |
| 1381 | reset_mask |= RADEON_RESET_SEM; |
| 1382 | |
| 1383 | if (G_000E50_GRBM_RQ_PENDING(tmp)) |
| 1384 | reset_mask |= RADEON_RESET_GRBM; |
| 1385 | |
| 1386 | if (G_000E50_VMC_BUSY(tmp)) |
| 1387 | reset_mask |= RADEON_RESET_VMC; |
| 1388 | |
| 1389 | if (G_000E50_MCB_BUSY(tmp) | G_000E50_MCDZ_BUSY(tmp) | |
| 1390 | G_000E50_MCDY_BUSY(tmp) | G_000E50_MCDX_BUSY(tmp) | |
| 1391 | G_000E50_MCDW_BUSY(tmp)) |
| 1392 | reset_mask |= RADEON_RESET_MC; |
| 1393 | |
| 1394 | if (r600_is_display_hung(rdev)) |
| 1395 | reset_mask |= RADEON_RESET_DISPLAY; |
| 1396 | |
Alex Deucher | d808fc8 | 2013-02-28 10:03:08 -0500 | [diff] [blame] | 1397 | /* Skip MC reset as it's mostly likely not hung, just busy */ |
| 1398 | if (reset_mask & RADEON_RESET_MC) { |
| 1399 | DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask); |
| 1400 | reset_mask &= ~RADEON_RESET_MC; |
| 1401 | } |
| 1402 | |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1403 | return reset_mask; |
| 1404 | } |
| 1405 | |
| 1406 | static void r600_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask) |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1407 | { |
| 1408 | struct rv515_mc_save save; |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1409 | u32 grbm_soft_reset = 0, srbm_soft_reset = 0; |
| 1410 | u32 tmp; |
Alex Deucher | 19fc42e | 2013-01-14 11:04:39 -0500 | [diff] [blame] | 1411 | |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1412 | if (reset_mask == 0) |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1413 | return; |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1414 | |
| 1415 | dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask); |
| 1416 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1417 | r600_print_gpu_status_regs(rdev); |
| 1418 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1419 | /* Disable CP parsing/prefetching */ |
| 1420 | if (rdev->family >= CHIP_RV770) |
| 1421 | WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1)); |
| 1422 | else |
| 1423 | WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1)); |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1424 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1425 | /* disable the RLC */ |
| 1426 | WREG32(RLC_CNTL, 0); |
| 1427 | |
| 1428 | if (reset_mask & RADEON_RESET_DMA) { |
| 1429 | /* Disable DMA */ |
| 1430 | tmp = RREG32(DMA_RB_CNTL); |
| 1431 | tmp &= ~DMA_RB_ENABLE; |
| 1432 | WREG32(DMA_RB_CNTL, tmp); |
| 1433 | } |
| 1434 | |
| 1435 | mdelay(50); |
| 1436 | |
Alex Deucher | ca57802 | 2013-01-23 18:56:08 -0500 | [diff] [blame] | 1437 | rv515_mc_stop(rdev, &save); |
| 1438 | if (r600_mc_wait_for_idle(rdev)) { |
| 1439 | dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); |
| 1440 | } |
| 1441 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1442 | if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) { |
| 1443 | if (rdev->family >= CHIP_RV770) |
| 1444 | grbm_soft_reset |= S_008020_SOFT_RESET_DB(1) | |
| 1445 | S_008020_SOFT_RESET_CB(1) | |
| 1446 | S_008020_SOFT_RESET_PA(1) | |
| 1447 | S_008020_SOFT_RESET_SC(1) | |
| 1448 | S_008020_SOFT_RESET_SPI(1) | |
| 1449 | S_008020_SOFT_RESET_SX(1) | |
| 1450 | S_008020_SOFT_RESET_SH(1) | |
| 1451 | S_008020_SOFT_RESET_TC(1) | |
| 1452 | S_008020_SOFT_RESET_TA(1) | |
| 1453 | S_008020_SOFT_RESET_VC(1) | |
| 1454 | S_008020_SOFT_RESET_VGT(1); |
| 1455 | else |
| 1456 | grbm_soft_reset |= S_008020_SOFT_RESET_CR(1) | |
| 1457 | S_008020_SOFT_RESET_DB(1) | |
| 1458 | S_008020_SOFT_RESET_CB(1) | |
| 1459 | S_008020_SOFT_RESET_PA(1) | |
| 1460 | S_008020_SOFT_RESET_SC(1) | |
| 1461 | S_008020_SOFT_RESET_SMX(1) | |
| 1462 | S_008020_SOFT_RESET_SPI(1) | |
| 1463 | S_008020_SOFT_RESET_SX(1) | |
| 1464 | S_008020_SOFT_RESET_SH(1) | |
| 1465 | S_008020_SOFT_RESET_TC(1) | |
| 1466 | S_008020_SOFT_RESET_TA(1) | |
| 1467 | S_008020_SOFT_RESET_VC(1) | |
| 1468 | S_008020_SOFT_RESET_VGT(1); |
| 1469 | } |
| 1470 | |
| 1471 | if (reset_mask & RADEON_RESET_CP) { |
| 1472 | grbm_soft_reset |= S_008020_SOFT_RESET_CP(1) | |
| 1473 | S_008020_SOFT_RESET_VGT(1); |
| 1474 | |
| 1475 | srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1); |
| 1476 | } |
| 1477 | |
| 1478 | if (reset_mask & RADEON_RESET_DMA) { |
| 1479 | if (rdev->family >= CHIP_RV770) |
| 1480 | srbm_soft_reset |= RV770_SOFT_RESET_DMA; |
| 1481 | else |
| 1482 | srbm_soft_reset |= SOFT_RESET_DMA; |
| 1483 | } |
| 1484 | |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1485 | if (reset_mask & RADEON_RESET_RLC) |
| 1486 | srbm_soft_reset |= S_000E60_SOFT_RESET_RLC(1); |
| 1487 | |
| 1488 | if (reset_mask & RADEON_RESET_SEM) |
| 1489 | srbm_soft_reset |= S_000E60_SOFT_RESET_SEM(1); |
| 1490 | |
| 1491 | if (reset_mask & RADEON_RESET_IH) |
| 1492 | srbm_soft_reset |= S_000E60_SOFT_RESET_IH(1); |
| 1493 | |
| 1494 | if (reset_mask & RADEON_RESET_GRBM) |
| 1495 | srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1); |
| 1496 | |
Alex Deucher | 24178ec | 2013-01-24 15:00:17 -0500 | [diff] [blame] | 1497 | if (!(rdev->flags & RADEON_IS_IGP)) { |
| 1498 | if (reset_mask & RADEON_RESET_MC) |
| 1499 | srbm_soft_reset |= S_000E60_SOFT_RESET_MC(1); |
| 1500 | } |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1501 | |
| 1502 | if (reset_mask & RADEON_RESET_VMC) |
| 1503 | srbm_soft_reset |= S_000E60_SOFT_RESET_VMC(1); |
| 1504 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1505 | if (grbm_soft_reset) { |
| 1506 | tmp = RREG32(R_008020_GRBM_SOFT_RESET); |
| 1507 | tmp |= grbm_soft_reset; |
| 1508 | dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp); |
| 1509 | WREG32(R_008020_GRBM_SOFT_RESET, tmp); |
| 1510 | tmp = RREG32(R_008020_GRBM_SOFT_RESET); |
| 1511 | |
| 1512 | udelay(50); |
| 1513 | |
| 1514 | tmp &= ~grbm_soft_reset; |
| 1515 | WREG32(R_008020_GRBM_SOFT_RESET, tmp); |
| 1516 | tmp = RREG32(R_008020_GRBM_SOFT_RESET); |
| 1517 | } |
| 1518 | |
| 1519 | if (srbm_soft_reset) { |
| 1520 | tmp = RREG32(SRBM_SOFT_RESET); |
| 1521 | tmp |= srbm_soft_reset; |
| 1522 | dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); |
| 1523 | WREG32(SRBM_SOFT_RESET, tmp); |
| 1524 | tmp = RREG32(SRBM_SOFT_RESET); |
| 1525 | |
| 1526 | udelay(50); |
| 1527 | |
| 1528 | tmp &= ~srbm_soft_reset; |
| 1529 | WREG32(SRBM_SOFT_RESET, tmp); |
| 1530 | tmp = RREG32(SRBM_SOFT_RESET); |
| 1531 | } |
Alex Deucher | 71e3d15 | 2013-01-03 12:20:35 -0500 | [diff] [blame] | 1532 | |
| 1533 | /* Wait a little for things to settle down */ |
| 1534 | mdelay(1); |
| 1535 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 1536 | rv515_mc_resume(rdev, &save); |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1537 | udelay(50); |
Alex Deucher | 410a341 | 2013-01-18 13:05:39 -0500 | [diff] [blame] | 1538 | |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1539 | r600_print_gpu_status_regs(rdev); |
Alex Deucher | d3cb781 | 2013-01-18 13:53:37 -0500 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | int r600_asic_reset(struct radeon_device *rdev) |
| 1543 | { |
Alex Deucher | f13f773 | 2013-01-18 18:12:22 -0500 | [diff] [blame] | 1544 | u32 reset_mask; |
| 1545 | |
| 1546 | reset_mask = r600_gpu_check_soft_reset(rdev); |
| 1547 | |
| 1548 | if (reset_mask) |
| 1549 | r600_set_bios_scratch_engine_hung(rdev, true); |
| 1550 | |
| 1551 | r600_gpu_soft_reset(rdev, reset_mask); |
| 1552 | |
| 1553 | reset_mask = r600_gpu_check_soft_reset(rdev); |
| 1554 | |
| 1555 | if (!reset_mask) |
| 1556 | r600_set_bios_scratch_engine_hung(rdev, false); |
| 1557 | |
| 1558 | return 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1559 | } |
| 1560 | |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1561 | /** |
| 1562 | * r600_gfx_is_lockup - Check if the GFX engine is locked up |
| 1563 | * |
| 1564 | * @rdev: radeon_device pointer |
| 1565 | * @ring: radeon_ring structure holding ring information |
| 1566 | * |
| 1567 | * Check if the GFX engine is locked up. |
| 1568 | * Returns true if the engine appears to be locked up, false if not. |
| 1569 | */ |
| 1570 | bool r600_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 1571 | { |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1572 | u32 reset_mask = r600_gpu_check_soft_reset(rdev); |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 1573 | |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1574 | if (!(reset_mask & (RADEON_RESET_GFX | |
| 1575 | RADEON_RESET_COMPUTE | |
| 1576 | RADEON_RESET_CP))) { |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 1577 | radeon_ring_lockup_update(ring); |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
| 1580 | /* force CP activities */ |
Christian König | 7b9ef16 | 2012-05-02 15:11:23 +0200 | [diff] [blame] | 1581 | radeon_ring_force_activity(rdev, ring); |
Christian König | 069211e | 2012-05-02 15:11:20 +0200 | [diff] [blame] | 1582 | return radeon_ring_test_lockup(rdev, ring); |
Jerome Glisse | 225758d | 2010-03-09 14:45:10 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1585 | /** |
| 1586 | * r600_dma_is_lockup - Check if the DMA engine is locked up |
| 1587 | * |
| 1588 | * @rdev: radeon_device pointer |
| 1589 | * @ring: radeon_ring structure holding ring information |
| 1590 | * |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1591 | * Check if the async DMA engine is locked up. |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1592 | * Returns true if the engine appears to be locked up, false if not. |
| 1593 | */ |
| 1594 | bool r600_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring) |
| 1595 | { |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1596 | u32 reset_mask = r600_gpu_check_soft_reset(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1597 | |
Alex Deucher | 123bc18 | 2013-01-24 11:37:19 -0500 | [diff] [blame] | 1598 | if (!(reset_mask & RADEON_RESET_DMA)) { |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1599 | radeon_ring_lockup_update(ring); |
| 1600 | return false; |
| 1601 | } |
| 1602 | /* force ring activities */ |
| 1603 | radeon_ring_force_activity(rdev, ring); |
| 1604 | return radeon_ring_test_lockup(rdev, ring); |
| 1605 | } |
| 1606 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1607 | u32 r6xx_remap_render_backend(struct radeon_device *rdev, |
| 1608 | u32 tiling_pipe_num, |
| 1609 | u32 max_rb_num, |
| 1610 | u32 total_max_rb_num, |
| 1611 | u32 disabled_rb_mask) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1612 | { |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1613 | u32 rendering_pipe_num, rb_num_width, req_rb_num; |
Mikko Tiihonen | f689e3a | 2013-01-30 14:10:04 -0500 | [diff] [blame] | 1614 | u32 pipe_rb_ratio, pipe_rb_remain, tmp; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1615 | u32 data = 0, mask = 1 << (max_rb_num - 1); |
| 1616 | unsigned i, j; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1617 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1618 | /* mask out the RBs that don't exist on that asic */ |
Mikko Tiihonen | f689e3a | 2013-01-30 14:10:04 -0500 | [diff] [blame] | 1619 | tmp = disabled_rb_mask | ((0xff << max_rb_num) & 0xff); |
| 1620 | /* make sure at least one RB is available */ |
| 1621 | if ((tmp & 0xff) != 0xff) |
| 1622 | disabled_rb_mask = tmp; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1623 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1624 | rendering_pipe_num = 1 << tiling_pipe_num; |
| 1625 | req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask); |
| 1626 | BUG_ON(rendering_pipe_num < req_rb_num); |
| 1627 | |
| 1628 | pipe_rb_ratio = rendering_pipe_num / req_rb_num; |
| 1629 | pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num; |
| 1630 | |
| 1631 | if (rdev->family <= CHIP_RV740) { |
| 1632 | /* r6xx/r7xx */ |
| 1633 | rb_num_width = 2; |
| 1634 | } else { |
| 1635 | /* eg+ */ |
| 1636 | rb_num_width = 4; |
| 1637 | } |
| 1638 | |
| 1639 | for (i = 0; i < max_rb_num; i++) { |
| 1640 | if (!(mask & disabled_rb_mask)) { |
| 1641 | for (j = 0; j < pipe_rb_ratio; j++) { |
| 1642 | data <<= rb_num_width; |
| 1643 | data |= max_rb_num - i - 1; |
| 1644 | } |
| 1645 | if (pipe_rb_remain) { |
| 1646 | data <<= rb_num_width; |
| 1647 | data |= max_rb_num - i - 1; |
| 1648 | pipe_rb_remain--; |
| 1649 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1650 | } |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1651 | mask >>= 1; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1652 | } |
| 1653 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1654 | return data; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | int r600_count_pipe_bits(uint32_t val) |
| 1658 | { |
Akinobu Mita | ef8cf3a | 2012-11-09 12:10:41 +0000 | [diff] [blame] | 1659 | return hweight32(val); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1660 | } |
| 1661 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 1662 | static void r600_gpu_init(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1663 | { |
| 1664 | u32 tiling_config; |
| 1665 | u32 ramcfg; |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1666 | u32 cc_rb_backend_disable; |
| 1667 | u32 cc_gc_shader_pipe_config; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1668 | u32 tmp; |
| 1669 | int i, j; |
| 1670 | u32 sq_config; |
| 1671 | u32 sq_gpr_resource_mgmt_1 = 0; |
| 1672 | u32 sq_gpr_resource_mgmt_2 = 0; |
| 1673 | u32 sq_thread_resource_mgmt = 0; |
| 1674 | u32 sq_stack_resource_mgmt_1 = 0; |
| 1675 | u32 sq_stack_resource_mgmt_2 = 0; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1676 | u32 disabled_rb_mask; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1677 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1678 | rdev->config.r600.tiling_group_size = 256; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1679 | switch (rdev->family) { |
| 1680 | case CHIP_R600: |
| 1681 | rdev->config.r600.max_pipes = 4; |
| 1682 | rdev->config.r600.max_tile_pipes = 8; |
| 1683 | rdev->config.r600.max_simds = 4; |
| 1684 | rdev->config.r600.max_backends = 4; |
| 1685 | rdev->config.r600.max_gprs = 256; |
| 1686 | rdev->config.r600.max_threads = 192; |
| 1687 | rdev->config.r600.max_stack_entries = 256; |
| 1688 | rdev->config.r600.max_hw_contexts = 8; |
| 1689 | rdev->config.r600.max_gs_threads = 16; |
| 1690 | rdev->config.r600.sx_max_export_size = 128; |
| 1691 | rdev->config.r600.sx_max_export_pos_size = 16; |
| 1692 | rdev->config.r600.sx_max_export_smx_size = 128; |
| 1693 | rdev->config.r600.sq_num_cf_insts = 2; |
| 1694 | break; |
| 1695 | case CHIP_RV630: |
| 1696 | case CHIP_RV635: |
| 1697 | rdev->config.r600.max_pipes = 2; |
| 1698 | rdev->config.r600.max_tile_pipes = 2; |
| 1699 | rdev->config.r600.max_simds = 3; |
| 1700 | rdev->config.r600.max_backends = 1; |
| 1701 | rdev->config.r600.max_gprs = 128; |
| 1702 | rdev->config.r600.max_threads = 192; |
| 1703 | rdev->config.r600.max_stack_entries = 128; |
| 1704 | rdev->config.r600.max_hw_contexts = 8; |
| 1705 | rdev->config.r600.max_gs_threads = 4; |
| 1706 | rdev->config.r600.sx_max_export_size = 128; |
| 1707 | rdev->config.r600.sx_max_export_pos_size = 16; |
| 1708 | rdev->config.r600.sx_max_export_smx_size = 128; |
| 1709 | rdev->config.r600.sq_num_cf_insts = 2; |
| 1710 | break; |
| 1711 | case CHIP_RV610: |
| 1712 | case CHIP_RV620: |
| 1713 | case CHIP_RS780: |
| 1714 | case CHIP_RS880: |
| 1715 | rdev->config.r600.max_pipes = 1; |
| 1716 | rdev->config.r600.max_tile_pipes = 1; |
| 1717 | rdev->config.r600.max_simds = 2; |
| 1718 | rdev->config.r600.max_backends = 1; |
| 1719 | rdev->config.r600.max_gprs = 128; |
| 1720 | rdev->config.r600.max_threads = 192; |
| 1721 | rdev->config.r600.max_stack_entries = 128; |
| 1722 | rdev->config.r600.max_hw_contexts = 4; |
| 1723 | rdev->config.r600.max_gs_threads = 4; |
| 1724 | rdev->config.r600.sx_max_export_size = 128; |
| 1725 | rdev->config.r600.sx_max_export_pos_size = 16; |
| 1726 | rdev->config.r600.sx_max_export_smx_size = 128; |
| 1727 | rdev->config.r600.sq_num_cf_insts = 1; |
| 1728 | break; |
| 1729 | case CHIP_RV670: |
| 1730 | rdev->config.r600.max_pipes = 4; |
| 1731 | rdev->config.r600.max_tile_pipes = 4; |
| 1732 | rdev->config.r600.max_simds = 4; |
| 1733 | rdev->config.r600.max_backends = 4; |
| 1734 | rdev->config.r600.max_gprs = 192; |
| 1735 | rdev->config.r600.max_threads = 192; |
| 1736 | rdev->config.r600.max_stack_entries = 256; |
| 1737 | rdev->config.r600.max_hw_contexts = 8; |
| 1738 | rdev->config.r600.max_gs_threads = 16; |
| 1739 | rdev->config.r600.sx_max_export_size = 128; |
| 1740 | rdev->config.r600.sx_max_export_pos_size = 16; |
| 1741 | rdev->config.r600.sx_max_export_smx_size = 128; |
| 1742 | rdev->config.r600.sq_num_cf_insts = 2; |
| 1743 | break; |
| 1744 | default: |
| 1745 | break; |
| 1746 | } |
| 1747 | |
| 1748 | /* Initialize HDP */ |
| 1749 | for (i = 0, j = 0; i < 32; i++, j += 0x18) { |
| 1750 | WREG32((0x2c14 + j), 0x00000000); |
| 1751 | WREG32((0x2c18 + j), 0x00000000); |
| 1752 | WREG32((0x2c1c + j), 0x00000000); |
| 1753 | WREG32((0x2c20 + j), 0x00000000); |
| 1754 | WREG32((0x2c24 + j), 0x00000000); |
| 1755 | } |
| 1756 | |
| 1757 | WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff)); |
| 1758 | |
| 1759 | /* Setup tiling */ |
| 1760 | tiling_config = 0; |
| 1761 | ramcfg = RREG32(RAMCFG); |
| 1762 | switch (rdev->config.r600.max_tile_pipes) { |
| 1763 | case 1: |
| 1764 | tiling_config |= PIPE_TILING(0); |
| 1765 | break; |
| 1766 | case 2: |
| 1767 | tiling_config |= PIPE_TILING(1); |
| 1768 | break; |
| 1769 | case 4: |
| 1770 | tiling_config |= PIPE_TILING(2); |
| 1771 | break; |
| 1772 | case 8: |
| 1773 | tiling_config |= PIPE_TILING(3); |
| 1774 | break; |
| 1775 | default: |
| 1776 | break; |
| 1777 | } |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1778 | rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes; |
Jerome Glisse | 961fb59 | 2010-02-10 22:30:05 +0000 | [diff] [blame] | 1779 | rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1780 | tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT); |
Alex Deucher | 881fe6c | 2010-10-18 23:54:56 -0400 | [diff] [blame] | 1781 | tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT); |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1782 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1783 | tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT; |
| 1784 | if (tmp > 3) { |
| 1785 | tiling_config |= ROW_TILING(3); |
| 1786 | tiling_config |= SAMPLE_SPLIT(3); |
| 1787 | } else { |
| 1788 | tiling_config |= ROW_TILING(tmp); |
| 1789 | tiling_config |= SAMPLE_SPLIT(tmp); |
| 1790 | } |
| 1791 | tiling_config |= BANK_SWAPS(1); |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1792 | |
| 1793 | cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000; |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1794 | tmp = R6XX_MAX_BACKENDS - |
| 1795 | r600_count_pipe_bits((cc_rb_backend_disable >> 16) & R6XX_MAX_BACKENDS_MASK); |
| 1796 | if (tmp < rdev->config.r600.max_backends) { |
| 1797 | rdev->config.r600.max_backends = tmp; |
| 1798 | } |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1799 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1800 | cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00; |
| 1801 | tmp = R6XX_MAX_PIPES - |
| 1802 | r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R6XX_MAX_PIPES_MASK); |
| 1803 | if (tmp < rdev->config.r600.max_pipes) { |
| 1804 | rdev->config.r600.max_pipes = tmp; |
| 1805 | } |
| 1806 | tmp = R6XX_MAX_SIMDS - |
| 1807 | r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK); |
| 1808 | if (tmp < rdev->config.r600.max_simds) { |
| 1809 | rdev->config.r600.max_simds = tmp; |
| 1810 | } |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1811 | |
Alex Deucher | 416a2bd | 2012-05-31 19:00:25 -0400 | [diff] [blame] | 1812 | disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK; |
| 1813 | tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT; |
| 1814 | tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends, |
| 1815 | R6XX_MAX_BACKENDS, disabled_rb_mask); |
| 1816 | tiling_config |= tmp << 16; |
| 1817 | rdev->config.r600.backend_map = tmp; |
| 1818 | |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 1819 | rdev->config.r600.tile_config = tiling_config; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1820 | WREG32(GB_TILING_CONFIG, tiling_config); |
| 1821 | WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff); |
| 1822 | WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 1823 | WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1824 | |
Alex Deucher | d03f5d5 | 2010-02-19 16:22:31 -0500 | [diff] [blame] | 1825 | tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1826 | WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK); |
| 1827 | WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK); |
| 1828 | |
| 1829 | /* Setup some CP states */ |
| 1830 | WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b))); |
| 1831 | WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40))); |
| 1832 | |
| 1833 | WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT | |
| 1834 | SYNC_WALKER | SYNC_ALIGNER)); |
| 1835 | /* Setup various GPU states */ |
| 1836 | if (rdev->family == CHIP_RV670) |
| 1837 | WREG32(ARB_GDEC_RD_CNTL, 0x00000021); |
| 1838 | |
| 1839 | tmp = RREG32(SX_DEBUG_1); |
| 1840 | tmp |= SMX_EVENT_RELEASE; |
| 1841 | if ((rdev->family > CHIP_R600)) |
| 1842 | tmp |= ENABLE_NEW_SMX_ADDRESS; |
| 1843 | WREG32(SX_DEBUG_1, tmp); |
| 1844 | |
| 1845 | if (((rdev->family) == CHIP_R600) || |
| 1846 | ((rdev->family) == CHIP_RV630) || |
| 1847 | ((rdev->family) == CHIP_RV610) || |
| 1848 | ((rdev->family) == CHIP_RV620) || |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 1849 | ((rdev->family) == CHIP_RS780) || |
| 1850 | ((rdev->family) == CHIP_RS880)) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1851 | WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE); |
| 1852 | } else { |
| 1853 | WREG32(DB_DEBUG, 0); |
| 1854 | } |
| 1855 | WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) | |
| 1856 | DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4))); |
| 1857 | |
| 1858 | WREG32(PA_SC_MULTI_CHIP_CNTL, 0); |
| 1859 | WREG32(VGT_NUM_INSTANCES, 0); |
| 1860 | |
| 1861 | WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0)); |
| 1862 | WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0)); |
| 1863 | |
| 1864 | tmp = RREG32(SQ_MS_FIFO_SIZES); |
| 1865 | if (((rdev->family) == CHIP_RV610) || |
| 1866 | ((rdev->family) == CHIP_RV620) || |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 1867 | ((rdev->family) == CHIP_RS780) || |
| 1868 | ((rdev->family) == CHIP_RS880)) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1869 | tmp = (CACHE_FIFO_SIZE(0xa) | |
| 1870 | FETCH_FIFO_HIWATER(0xa) | |
| 1871 | DONE_FIFO_HIWATER(0xe0) | |
| 1872 | ALU_UPDATE_FIFO_HIWATER(0x8)); |
| 1873 | } else if (((rdev->family) == CHIP_R600) || |
| 1874 | ((rdev->family) == CHIP_RV630)) { |
| 1875 | tmp &= ~DONE_FIFO_HIWATER(0xff); |
| 1876 | tmp |= DONE_FIFO_HIWATER(0x4); |
| 1877 | } |
| 1878 | WREG32(SQ_MS_FIFO_SIZES, tmp); |
| 1879 | |
| 1880 | /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT |
| 1881 | * should be adjusted as needed by the 2D/3D drivers. This just sets default values |
| 1882 | */ |
| 1883 | sq_config = RREG32(SQ_CONFIG); |
| 1884 | sq_config &= ~(PS_PRIO(3) | |
| 1885 | VS_PRIO(3) | |
| 1886 | GS_PRIO(3) | |
| 1887 | ES_PRIO(3)); |
| 1888 | sq_config |= (DX9_CONSTS | |
| 1889 | VC_ENABLE | |
| 1890 | PS_PRIO(0) | |
| 1891 | VS_PRIO(1) | |
| 1892 | GS_PRIO(2) | |
| 1893 | ES_PRIO(3)); |
| 1894 | |
| 1895 | if ((rdev->family) == CHIP_R600) { |
| 1896 | sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) | |
| 1897 | NUM_VS_GPRS(124) | |
| 1898 | NUM_CLAUSE_TEMP_GPRS(4)); |
| 1899 | sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) | |
| 1900 | NUM_ES_GPRS(0)); |
| 1901 | sq_thread_resource_mgmt = (NUM_PS_THREADS(136) | |
| 1902 | NUM_VS_THREADS(48) | |
| 1903 | NUM_GS_THREADS(4) | |
| 1904 | NUM_ES_THREADS(4)); |
| 1905 | sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) | |
| 1906 | NUM_VS_STACK_ENTRIES(128)); |
| 1907 | sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) | |
| 1908 | NUM_ES_STACK_ENTRIES(0)); |
| 1909 | } else if (((rdev->family) == CHIP_RV610) || |
| 1910 | ((rdev->family) == CHIP_RV620) || |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 1911 | ((rdev->family) == CHIP_RS780) || |
| 1912 | ((rdev->family) == CHIP_RS880)) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1913 | /* no vertex cache */ |
| 1914 | sq_config &= ~VC_ENABLE; |
| 1915 | |
| 1916 | sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) | |
| 1917 | NUM_VS_GPRS(44) | |
| 1918 | NUM_CLAUSE_TEMP_GPRS(2)); |
| 1919 | sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) | |
| 1920 | NUM_ES_GPRS(17)); |
| 1921 | sq_thread_resource_mgmt = (NUM_PS_THREADS(79) | |
| 1922 | NUM_VS_THREADS(78) | |
| 1923 | NUM_GS_THREADS(4) | |
| 1924 | NUM_ES_THREADS(31)); |
| 1925 | sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) | |
| 1926 | NUM_VS_STACK_ENTRIES(40)); |
| 1927 | sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) | |
| 1928 | NUM_ES_STACK_ENTRIES(16)); |
| 1929 | } else if (((rdev->family) == CHIP_RV630) || |
| 1930 | ((rdev->family) == CHIP_RV635)) { |
| 1931 | sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) | |
| 1932 | NUM_VS_GPRS(44) | |
| 1933 | NUM_CLAUSE_TEMP_GPRS(2)); |
| 1934 | sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) | |
| 1935 | NUM_ES_GPRS(18)); |
| 1936 | sq_thread_resource_mgmt = (NUM_PS_THREADS(79) | |
| 1937 | NUM_VS_THREADS(78) | |
| 1938 | NUM_GS_THREADS(4) | |
| 1939 | NUM_ES_THREADS(31)); |
| 1940 | sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) | |
| 1941 | NUM_VS_STACK_ENTRIES(40)); |
| 1942 | sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) | |
| 1943 | NUM_ES_STACK_ENTRIES(16)); |
| 1944 | } else if ((rdev->family) == CHIP_RV670) { |
| 1945 | sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) | |
| 1946 | NUM_VS_GPRS(44) | |
| 1947 | NUM_CLAUSE_TEMP_GPRS(2)); |
| 1948 | sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) | |
| 1949 | NUM_ES_GPRS(17)); |
| 1950 | sq_thread_resource_mgmt = (NUM_PS_THREADS(79) | |
| 1951 | NUM_VS_THREADS(78) | |
| 1952 | NUM_GS_THREADS(4) | |
| 1953 | NUM_ES_THREADS(31)); |
| 1954 | sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) | |
| 1955 | NUM_VS_STACK_ENTRIES(64)); |
| 1956 | sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) | |
| 1957 | NUM_ES_STACK_ENTRIES(64)); |
| 1958 | } |
| 1959 | |
| 1960 | WREG32(SQ_CONFIG, sq_config); |
| 1961 | WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1); |
| 1962 | WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2); |
| 1963 | WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt); |
| 1964 | WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1); |
| 1965 | WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2); |
| 1966 | |
| 1967 | if (((rdev->family) == CHIP_RV610) || |
| 1968 | ((rdev->family) == CHIP_RV620) || |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 1969 | ((rdev->family) == CHIP_RS780) || |
| 1970 | ((rdev->family) == CHIP_RS880)) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1971 | WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY)); |
| 1972 | } else { |
| 1973 | WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC)); |
| 1974 | } |
| 1975 | |
| 1976 | /* More default values. 2D/3D driver should adjust as needed */ |
| 1977 | WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) | |
| 1978 | S1_X(0x4) | S1_Y(0xc))); |
| 1979 | WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) | |
| 1980 | S1_X(0x2) | S1_Y(0x2) | |
| 1981 | S2_X(0xa) | S2_Y(0x6) | |
| 1982 | S3_X(0x6) | S3_Y(0xa))); |
| 1983 | WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) | |
| 1984 | S1_X(0x4) | S1_Y(0xc) | |
| 1985 | S2_X(0x1) | S2_Y(0x6) | |
| 1986 | S3_X(0xa) | S3_Y(0xe))); |
| 1987 | WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) | |
| 1988 | S5_X(0x0) | S5_Y(0x0) | |
| 1989 | S6_X(0xb) | S6_Y(0x4) | |
| 1990 | S7_X(0x7) | S7_Y(0x8))); |
| 1991 | |
| 1992 | WREG32(VGT_STRMOUT_EN, 0); |
| 1993 | tmp = rdev->config.r600.max_pipes * 16; |
| 1994 | switch (rdev->family) { |
| 1995 | case CHIP_RV610: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1996 | case CHIP_RV620: |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 1997 | case CHIP_RS780: |
| 1998 | case CHIP_RS880: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 1999 | tmp += 32; |
| 2000 | break; |
| 2001 | case CHIP_RV670: |
| 2002 | tmp += 128; |
| 2003 | break; |
| 2004 | default: |
| 2005 | break; |
| 2006 | } |
| 2007 | if (tmp > 256) { |
| 2008 | tmp = 256; |
| 2009 | } |
| 2010 | WREG32(VGT_ES_PER_GS, 128); |
| 2011 | WREG32(VGT_GS_PER_ES, tmp); |
| 2012 | WREG32(VGT_GS_PER_VS, 2); |
| 2013 | WREG32(VGT_GS_VERTEX_REUSE, 16); |
| 2014 | |
| 2015 | /* more default values. 2D/3D driver should adjust as needed */ |
| 2016 | WREG32(PA_SC_LINE_STIPPLE_STATE, 0); |
| 2017 | WREG32(VGT_STRMOUT_EN, 0); |
| 2018 | WREG32(SX_MISC, 0); |
| 2019 | WREG32(PA_SC_MODE_CNTL, 0); |
| 2020 | WREG32(PA_SC_AA_CONFIG, 0); |
| 2021 | WREG32(PA_SC_LINE_STIPPLE, 0); |
| 2022 | WREG32(SPI_INPUT_Z, 0); |
| 2023 | WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2)); |
| 2024 | WREG32(CB_COLOR7_FRAG, 0); |
| 2025 | |
| 2026 | /* Clear render buffer base addresses */ |
| 2027 | WREG32(CB_COLOR0_BASE, 0); |
| 2028 | WREG32(CB_COLOR1_BASE, 0); |
| 2029 | WREG32(CB_COLOR2_BASE, 0); |
| 2030 | WREG32(CB_COLOR3_BASE, 0); |
| 2031 | WREG32(CB_COLOR4_BASE, 0); |
| 2032 | WREG32(CB_COLOR5_BASE, 0); |
| 2033 | WREG32(CB_COLOR6_BASE, 0); |
| 2034 | WREG32(CB_COLOR7_BASE, 0); |
| 2035 | WREG32(CB_COLOR7_FRAG, 0); |
| 2036 | |
| 2037 | switch (rdev->family) { |
| 2038 | case CHIP_RV610: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2039 | case CHIP_RV620: |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 2040 | case CHIP_RS780: |
| 2041 | case CHIP_RS880: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2042 | tmp = TC_L2_SIZE(8); |
| 2043 | break; |
| 2044 | case CHIP_RV630: |
| 2045 | case CHIP_RV635: |
| 2046 | tmp = TC_L2_SIZE(4); |
| 2047 | break; |
| 2048 | case CHIP_R600: |
| 2049 | tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT; |
| 2050 | break; |
| 2051 | default: |
| 2052 | tmp = TC_L2_SIZE(0); |
| 2053 | break; |
| 2054 | } |
| 2055 | WREG32(TC_CNTL, tmp); |
| 2056 | |
| 2057 | tmp = RREG32(HDP_HOST_PATH_CNTL); |
| 2058 | WREG32(HDP_HOST_PATH_CNTL, tmp); |
| 2059 | |
| 2060 | tmp = RREG32(ARB_POP); |
| 2061 | tmp |= ENABLE_TC128; |
| 2062 | WREG32(ARB_POP, tmp); |
| 2063 | |
| 2064 | WREG32(PA_SC_MULTI_CHIP_CNTL, 0); |
| 2065 | WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA | |
| 2066 | NUM_CLIP_SEQ(3))); |
| 2067 | WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095)); |
Alex Deucher | b866d13 | 2012-06-14 22:06:36 +0200 | [diff] [blame] | 2068 | WREG32(VC_ENHANCE, 0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2072 | /* |
| 2073 | * Indirect registers accessor |
| 2074 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2075 | u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2076 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2077 | u32 r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2078 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2079 | WREG32(PCIE_PORT_INDEX, ((reg) & 0xff)); |
| 2080 | (void)RREG32(PCIE_PORT_INDEX); |
| 2081 | r = RREG32(PCIE_PORT_DATA); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2082 | return r; |
| 2083 | } |
| 2084 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2085 | void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2086 | { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2087 | WREG32(PCIE_PORT_INDEX, ((reg) & 0xff)); |
| 2088 | (void)RREG32(PCIE_PORT_INDEX); |
| 2089 | WREG32(PCIE_PORT_DATA, (v)); |
| 2090 | (void)RREG32(PCIE_PORT_DATA); |
| 2091 | } |
| 2092 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2093 | /* |
| 2094 | * CP & Ring |
| 2095 | */ |
| 2096 | void r600_cp_stop(struct radeon_device *rdev) |
| 2097 | { |
Dave Airlie | 5359533 | 2011-03-14 09:47:24 +1000 | [diff] [blame] | 2098 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2099 | WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1)); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2100 | WREG32(SCRATCH_UMSK, 0); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2101 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2102 | } |
| 2103 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2104 | int r600_init_microcode(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2105 | { |
| 2106 | struct platform_device *pdev; |
| 2107 | const char *chip_name; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2108 | const char *rlc_chip_name; |
| 2109 | size_t pfp_req_size, me_req_size, rlc_req_size; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2110 | char fw_name[30]; |
| 2111 | int err; |
| 2112 | |
| 2113 | DRM_DEBUG("\n"); |
| 2114 | |
| 2115 | pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0); |
| 2116 | err = IS_ERR(pdev); |
| 2117 | if (err) { |
| 2118 | printk(KERN_ERR "radeon_cp: Failed to register firmware\n"); |
| 2119 | return -EINVAL; |
| 2120 | } |
| 2121 | |
| 2122 | switch (rdev->family) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2123 | case CHIP_R600: |
| 2124 | chip_name = "R600"; |
| 2125 | rlc_chip_name = "R600"; |
| 2126 | break; |
| 2127 | case CHIP_RV610: |
| 2128 | chip_name = "RV610"; |
| 2129 | rlc_chip_name = "R600"; |
| 2130 | break; |
| 2131 | case CHIP_RV630: |
| 2132 | chip_name = "RV630"; |
| 2133 | rlc_chip_name = "R600"; |
| 2134 | break; |
| 2135 | case CHIP_RV620: |
| 2136 | chip_name = "RV620"; |
| 2137 | rlc_chip_name = "R600"; |
| 2138 | break; |
| 2139 | case CHIP_RV635: |
| 2140 | chip_name = "RV635"; |
| 2141 | rlc_chip_name = "R600"; |
| 2142 | break; |
| 2143 | case CHIP_RV670: |
| 2144 | chip_name = "RV670"; |
| 2145 | rlc_chip_name = "R600"; |
| 2146 | break; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2147 | case CHIP_RS780: |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2148 | case CHIP_RS880: |
| 2149 | chip_name = "RS780"; |
| 2150 | rlc_chip_name = "R600"; |
| 2151 | break; |
| 2152 | case CHIP_RV770: |
| 2153 | chip_name = "RV770"; |
| 2154 | rlc_chip_name = "R700"; |
| 2155 | break; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2156 | case CHIP_RV730: |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2157 | case CHIP_RV740: |
| 2158 | chip_name = "RV730"; |
| 2159 | rlc_chip_name = "R700"; |
| 2160 | break; |
| 2161 | case CHIP_RV710: |
| 2162 | chip_name = "RV710"; |
| 2163 | rlc_chip_name = "R700"; |
| 2164 | break; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2165 | case CHIP_CEDAR: |
| 2166 | chip_name = "CEDAR"; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2167 | rlc_chip_name = "CEDAR"; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2168 | break; |
| 2169 | case CHIP_REDWOOD: |
| 2170 | chip_name = "REDWOOD"; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2171 | rlc_chip_name = "REDWOOD"; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2172 | break; |
| 2173 | case CHIP_JUNIPER: |
| 2174 | chip_name = "JUNIPER"; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2175 | rlc_chip_name = "JUNIPER"; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2176 | break; |
| 2177 | case CHIP_CYPRESS: |
| 2178 | case CHIP_HEMLOCK: |
| 2179 | chip_name = "CYPRESS"; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2180 | rlc_chip_name = "CYPRESS"; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2181 | break; |
Alex Deucher | 439bd6c | 2010-11-22 17:56:31 -0500 | [diff] [blame] | 2182 | case CHIP_PALM: |
| 2183 | chip_name = "PALM"; |
| 2184 | rlc_chip_name = "SUMO"; |
| 2185 | break; |
Alex Deucher | d5c5a72 | 2011-05-31 15:42:48 -0400 | [diff] [blame] | 2186 | case CHIP_SUMO: |
| 2187 | chip_name = "SUMO"; |
| 2188 | rlc_chip_name = "SUMO"; |
| 2189 | break; |
| 2190 | case CHIP_SUMO2: |
| 2191 | chip_name = "SUMO2"; |
| 2192 | rlc_chip_name = "SUMO"; |
| 2193 | break; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2194 | default: BUG(); |
| 2195 | } |
| 2196 | |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2197 | if (rdev->family >= CHIP_CEDAR) { |
| 2198 | pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4; |
| 2199 | me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4; |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 2200 | rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4; |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2201 | } else if (rdev->family >= CHIP_RV770) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2202 | pfp_req_size = R700_PFP_UCODE_SIZE * 4; |
| 2203 | me_req_size = R700_PM4_UCODE_SIZE * 4; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2204 | rlc_req_size = R700_RLC_UCODE_SIZE * 4; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2205 | } else { |
| 2206 | pfp_req_size = PFP_UCODE_SIZE * 4; |
| 2207 | me_req_size = PM4_UCODE_SIZE * 12; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2208 | rlc_req_size = RLC_UCODE_SIZE * 4; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2209 | } |
| 2210 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2211 | DRM_INFO("Loading %s Microcode\n", chip_name); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2212 | |
| 2213 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name); |
| 2214 | err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev); |
| 2215 | if (err) |
| 2216 | goto out; |
| 2217 | if (rdev->pfp_fw->size != pfp_req_size) { |
| 2218 | printk(KERN_ERR |
| 2219 | "r600_cp: Bogus length %zu in firmware \"%s\"\n", |
| 2220 | rdev->pfp_fw->size, fw_name); |
| 2221 | err = -EINVAL; |
| 2222 | goto out; |
| 2223 | } |
| 2224 | |
| 2225 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name); |
| 2226 | err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev); |
| 2227 | if (err) |
| 2228 | goto out; |
| 2229 | if (rdev->me_fw->size != me_req_size) { |
| 2230 | printk(KERN_ERR |
| 2231 | "r600_cp: Bogus length %zu in firmware \"%s\"\n", |
| 2232 | rdev->me_fw->size, fw_name); |
| 2233 | err = -EINVAL; |
| 2234 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2235 | |
| 2236 | snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name); |
| 2237 | err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev); |
| 2238 | if (err) |
| 2239 | goto out; |
| 2240 | if (rdev->rlc_fw->size != rlc_req_size) { |
| 2241 | printk(KERN_ERR |
| 2242 | "r600_rlc: Bogus length %zu in firmware \"%s\"\n", |
| 2243 | rdev->rlc_fw->size, fw_name); |
| 2244 | err = -EINVAL; |
| 2245 | } |
| 2246 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2247 | out: |
| 2248 | platform_device_unregister(pdev); |
| 2249 | |
| 2250 | if (err) { |
| 2251 | if (err != -EINVAL) |
| 2252 | printk(KERN_ERR |
| 2253 | "r600_cp: Failed to load firmware \"%s\"\n", |
| 2254 | fw_name); |
| 2255 | release_firmware(rdev->pfp_fw); |
| 2256 | rdev->pfp_fw = NULL; |
| 2257 | release_firmware(rdev->me_fw); |
| 2258 | rdev->me_fw = NULL; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 2259 | release_firmware(rdev->rlc_fw); |
| 2260 | rdev->rlc_fw = NULL; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2261 | } |
| 2262 | return err; |
| 2263 | } |
| 2264 | |
| 2265 | static int r600_cp_load_microcode(struct radeon_device *rdev) |
| 2266 | { |
| 2267 | const __be32 *fw_data; |
| 2268 | int i; |
| 2269 | |
| 2270 | if (!rdev->me_fw || !rdev->pfp_fw) |
| 2271 | return -EINVAL; |
| 2272 | |
| 2273 | r600_cp_stop(rdev); |
| 2274 | |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 2275 | WREG32(CP_RB_CNTL, |
| 2276 | #ifdef __BIG_ENDIAN |
| 2277 | BUF_SWAP_32BIT | |
| 2278 | #endif |
| 2279 | RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3)); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2280 | |
| 2281 | /* Reset cp */ |
| 2282 | WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP); |
| 2283 | RREG32(GRBM_SOFT_RESET); |
| 2284 | mdelay(15); |
| 2285 | WREG32(GRBM_SOFT_RESET, 0); |
| 2286 | |
| 2287 | WREG32(CP_ME_RAM_WADDR, 0); |
| 2288 | |
| 2289 | fw_data = (const __be32 *)rdev->me_fw->data; |
| 2290 | WREG32(CP_ME_RAM_WADDR, 0); |
| 2291 | for (i = 0; i < PM4_UCODE_SIZE * 3; i++) |
| 2292 | WREG32(CP_ME_RAM_DATA, |
| 2293 | be32_to_cpup(fw_data++)); |
| 2294 | |
| 2295 | fw_data = (const __be32 *)rdev->pfp_fw->data; |
| 2296 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 2297 | for (i = 0; i < PFP_UCODE_SIZE; i++) |
| 2298 | WREG32(CP_PFP_UCODE_DATA, |
| 2299 | be32_to_cpup(fw_data++)); |
| 2300 | |
| 2301 | WREG32(CP_PFP_UCODE_ADDR, 0); |
| 2302 | WREG32(CP_ME_RAM_WADDR, 0); |
| 2303 | WREG32(CP_ME_RAM_RADDR, 0); |
| 2304 | return 0; |
| 2305 | } |
| 2306 | |
| 2307 | int r600_cp_start(struct radeon_device *rdev) |
| 2308 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2309 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2310 | int r; |
| 2311 | uint32_t cp_me; |
| 2312 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2313 | r = radeon_ring_lock(rdev, ring, 7); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2314 | if (r) { |
| 2315 | DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r); |
| 2316 | return r; |
| 2317 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2318 | radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5)); |
| 2319 | radeon_ring_write(ring, 0x1); |
Alex Deucher | 7e7b41d | 2010-09-02 21:32:32 -0400 | [diff] [blame] | 2320 | if (rdev->family >= CHIP_RV770) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2321 | radeon_ring_write(ring, 0x0); |
| 2322 | radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1); |
Alex Deucher | fe251e2 | 2010-03-24 13:36:43 -0400 | [diff] [blame] | 2323 | } else { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2324 | radeon_ring_write(ring, 0x3); |
| 2325 | radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2326 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2327 | radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1)); |
| 2328 | radeon_ring_write(ring, 0); |
| 2329 | radeon_ring_write(ring, 0); |
| 2330 | radeon_ring_unlock_commit(rdev, ring); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2331 | |
| 2332 | cp_me = 0xff; |
| 2333 | WREG32(R_0086D8_CP_ME_CNTL, cp_me); |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
| 2337 | int r600_cp_resume(struct radeon_device *rdev) |
| 2338 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2339 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2340 | u32 tmp; |
| 2341 | u32 rb_bufsz; |
| 2342 | int r; |
| 2343 | |
| 2344 | /* Reset cp */ |
| 2345 | WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP); |
| 2346 | RREG32(GRBM_SOFT_RESET); |
| 2347 | mdelay(15); |
| 2348 | WREG32(GRBM_SOFT_RESET, 0); |
| 2349 | |
| 2350 | /* Set ring buffer size */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2351 | rb_bufsz = drm_order(ring->ring_size / 8); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2352 | tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2353 | #ifdef __BIG_ENDIAN |
Alex Deucher | d6f2893 | 2009-11-02 16:01:27 -0500 | [diff] [blame] | 2354 | tmp |= BUF_SWAP_32BIT; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2355 | #endif |
Alex Deucher | d6f2893 | 2009-11-02 16:01:27 -0500 | [diff] [blame] | 2356 | WREG32(CP_RB_CNTL, tmp); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 2357 | WREG32(CP_SEM_WAIT_TIMER, 0x0); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2358 | |
| 2359 | /* Set the write pointer delay */ |
| 2360 | WREG32(CP_RB_WPTR_DELAY, 0); |
| 2361 | |
| 2362 | /* Initialize the ring buffer's read and write pointers */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2363 | WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA); |
| 2364 | WREG32(CP_RB_RPTR_WR, 0); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2365 | ring->wptr = 0; |
| 2366 | WREG32(CP_RB_WPTR, ring->wptr); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2367 | |
| 2368 | /* set the wb address whether it's enabled or not */ |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 2369 | WREG32(CP_RB_RPTR_ADDR, |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 2370 | ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC)); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2371 | WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF); |
| 2372 | WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF); |
| 2373 | |
| 2374 | if (rdev->wb.enabled) |
| 2375 | WREG32(SCRATCH_UMSK, 0xff); |
| 2376 | else { |
| 2377 | tmp |= RB_NO_UPDATE; |
| 2378 | WREG32(SCRATCH_UMSK, 0); |
| 2379 | } |
| 2380 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2381 | mdelay(1); |
| 2382 | WREG32(CP_RB_CNTL, tmp); |
| 2383 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2384 | WREG32(CP_RB_BASE, ring->gpu_addr >> 8); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2385 | WREG32(CP_DEBUG, (1 << 27) | (1 << 28)); |
| 2386 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2387 | ring->rptr = RREG32(CP_RB_RPTR); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2388 | |
| 2389 | r600_cp_start(rdev); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2390 | ring->ready = true; |
Alex Deucher | f712812 | 2012-02-23 17:53:45 -0500 | [diff] [blame] | 2391 | r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2392 | if (r) { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2393 | ring->ready = false; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2394 | return r; |
| 2395 | } |
| 2396 | return 0; |
| 2397 | } |
| 2398 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2399 | void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2400 | { |
| 2401 | u32 rb_bufsz; |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 2402 | int r; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2403 | |
| 2404 | /* Align ring size */ |
| 2405 | rb_bufsz = drm_order(ring_size / 8); |
| 2406 | ring_size = (1 << (rb_bufsz + 1)) * 4; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2407 | ring->ring_size = ring_size; |
| 2408 | ring->align_mask = 16 - 1; |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 2409 | |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 2410 | if (radeon_ring_supports_scratch_reg(rdev, ring)) { |
| 2411 | r = radeon_scratch_get(rdev, &ring->rptr_save_reg); |
| 2412 | if (r) { |
| 2413 | DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r); |
| 2414 | ring->rptr_save_reg = 0; |
| 2415 | } |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 2416 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2417 | } |
| 2418 | |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 2419 | void r600_cp_fini(struct radeon_device *rdev) |
| 2420 | { |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 2421 | struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 2422 | r600_cp_stop(rdev); |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 2423 | radeon_ring_fini(rdev, ring); |
| 2424 | radeon_scratch_free(rdev, ring->rptr_save_reg); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2427 | /* |
| 2428 | * DMA |
| 2429 | * Starting with R600, the GPU has an asynchronous |
| 2430 | * DMA engine. The programming model is very similar |
| 2431 | * to the 3D engine (ring buffer, IBs, etc.), but the |
| 2432 | * DMA controller has it's own packet format that is |
| 2433 | * different form the PM4 format used by the 3D engine. |
| 2434 | * It supports copying data, writing embedded data, |
| 2435 | * solid fills, and a number of other things. It also |
| 2436 | * has support for tiling/detiling of buffers. |
| 2437 | */ |
| 2438 | /** |
| 2439 | * r600_dma_stop - stop the async dma engine |
| 2440 | * |
| 2441 | * @rdev: radeon_device pointer |
| 2442 | * |
| 2443 | * Stop the async dma engine (r6xx-evergreen). |
| 2444 | */ |
| 2445 | void r600_dma_stop(struct radeon_device *rdev) |
| 2446 | { |
| 2447 | u32 rb_cntl = RREG32(DMA_RB_CNTL); |
| 2448 | |
| 2449 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size); |
| 2450 | |
| 2451 | rb_cntl &= ~DMA_RB_ENABLE; |
| 2452 | WREG32(DMA_RB_CNTL, rb_cntl); |
| 2453 | |
| 2454 | rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false; |
| 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * r600_dma_resume - setup and start the async dma engine |
| 2459 | * |
| 2460 | * @rdev: radeon_device pointer |
| 2461 | * |
| 2462 | * Set up the DMA ring buffer and enable it. (r6xx-evergreen). |
| 2463 | * Returns 0 for success, error for failure. |
| 2464 | */ |
| 2465 | int r600_dma_resume(struct radeon_device *rdev) |
| 2466 | { |
| 2467 | struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX]; |
Michel Dänzer | b3dfcb2 | 2013-01-24 19:02:01 +0100 | [diff] [blame] | 2468 | u32 rb_cntl, dma_cntl, ib_cntl; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2469 | u32 rb_bufsz; |
| 2470 | int r; |
| 2471 | |
| 2472 | /* Reset dma */ |
| 2473 | if (rdev->family >= CHIP_RV770) |
| 2474 | WREG32(SRBM_SOFT_RESET, RV770_SOFT_RESET_DMA); |
| 2475 | else |
| 2476 | WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA); |
| 2477 | RREG32(SRBM_SOFT_RESET); |
| 2478 | udelay(50); |
| 2479 | WREG32(SRBM_SOFT_RESET, 0); |
| 2480 | |
| 2481 | WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL, 0); |
| 2482 | WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL, 0); |
| 2483 | |
| 2484 | /* Set ring buffer size in dwords */ |
| 2485 | rb_bufsz = drm_order(ring->ring_size / 4); |
| 2486 | rb_cntl = rb_bufsz << 1; |
| 2487 | #ifdef __BIG_ENDIAN |
| 2488 | rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE; |
| 2489 | #endif |
| 2490 | WREG32(DMA_RB_CNTL, rb_cntl); |
| 2491 | |
| 2492 | /* Initialize the ring buffer's read and write pointers */ |
| 2493 | WREG32(DMA_RB_RPTR, 0); |
| 2494 | WREG32(DMA_RB_WPTR, 0); |
| 2495 | |
| 2496 | /* set the wb address whether it's enabled or not */ |
| 2497 | WREG32(DMA_RB_RPTR_ADDR_HI, |
| 2498 | upper_32_bits(rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFF); |
| 2499 | WREG32(DMA_RB_RPTR_ADDR_LO, |
| 2500 | ((rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFFFFFFFC)); |
| 2501 | |
| 2502 | if (rdev->wb.enabled) |
| 2503 | rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE; |
| 2504 | |
| 2505 | WREG32(DMA_RB_BASE, ring->gpu_addr >> 8); |
| 2506 | |
| 2507 | /* enable DMA IBs */ |
Michel Dänzer | b3dfcb2 | 2013-01-24 19:02:01 +0100 | [diff] [blame] | 2508 | ib_cntl = DMA_IB_ENABLE; |
| 2509 | #ifdef __BIG_ENDIAN |
| 2510 | ib_cntl |= DMA_IB_SWAP_ENABLE; |
| 2511 | #endif |
| 2512 | WREG32(DMA_IB_CNTL, ib_cntl); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2513 | |
| 2514 | dma_cntl = RREG32(DMA_CNTL); |
| 2515 | dma_cntl &= ~CTXEMPTY_INT_ENABLE; |
| 2516 | WREG32(DMA_CNTL, dma_cntl); |
| 2517 | |
| 2518 | if (rdev->family >= CHIP_RV770) |
| 2519 | WREG32(DMA_MODE, 1); |
| 2520 | |
| 2521 | ring->wptr = 0; |
| 2522 | WREG32(DMA_RB_WPTR, ring->wptr << 2); |
| 2523 | |
| 2524 | ring->rptr = RREG32(DMA_RB_RPTR) >> 2; |
| 2525 | |
| 2526 | WREG32(DMA_RB_CNTL, rb_cntl | DMA_RB_ENABLE); |
| 2527 | |
| 2528 | ring->ready = true; |
| 2529 | |
| 2530 | r = radeon_ring_test(rdev, R600_RING_TYPE_DMA_INDEX, ring); |
| 2531 | if (r) { |
| 2532 | ring->ready = false; |
| 2533 | return r; |
| 2534 | } |
| 2535 | |
| 2536 | radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size); |
| 2537 | |
| 2538 | return 0; |
| 2539 | } |
| 2540 | |
| 2541 | /** |
| 2542 | * r600_dma_fini - tear down the async dma engine |
| 2543 | * |
| 2544 | * @rdev: radeon_device pointer |
| 2545 | * |
| 2546 | * Stop the async dma engine and free the ring (r6xx-evergreen). |
| 2547 | */ |
| 2548 | void r600_dma_fini(struct radeon_device *rdev) |
| 2549 | { |
| 2550 | r600_dma_stop(rdev); |
| 2551 | radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]); |
| 2552 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2553 | |
| 2554 | /* |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 2555 | * UVD |
| 2556 | */ |
| 2557 | int r600_uvd_rbc_start(struct radeon_device *rdev) |
| 2558 | { |
| 2559 | struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX]; |
| 2560 | uint64_t rptr_addr; |
| 2561 | uint32_t rb_bufsz, tmp; |
| 2562 | int r; |
| 2563 | |
| 2564 | rptr_addr = rdev->wb.gpu_addr + R600_WB_UVD_RPTR_OFFSET; |
| 2565 | |
| 2566 | if (upper_32_bits(rptr_addr) != upper_32_bits(ring->gpu_addr)) { |
| 2567 | DRM_ERROR("UVD ring and rptr not in the same 4GB segment!\n"); |
| 2568 | return -EINVAL; |
| 2569 | } |
| 2570 | |
| 2571 | /* force RBC into idle state */ |
| 2572 | WREG32(UVD_RBC_RB_CNTL, 0x11010101); |
| 2573 | |
| 2574 | /* Set the write pointer delay */ |
| 2575 | WREG32(UVD_RBC_RB_WPTR_CNTL, 0); |
| 2576 | |
| 2577 | /* set the wb address */ |
| 2578 | WREG32(UVD_RBC_RB_RPTR_ADDR, rptr_addr >> 2); |
| 2579 | |
| 2580 | /* programm the 4GB memory segment for rptr and ring buffer */ |
| 2581 | WREG32(UVD_LMI_EXT40_ADDR, upper_32_bits(rptr_addr) | |
| 2582 | (0x7 << 16) | (0x1 << 31)); |
| 2583 | |
| 2584 | /* Initialize the ring buffer's read and write pointers */ |
| 2585 | WREG32(UVD_RBC_RB_RPTR, 0x0); |
| 2586 | |
| 2587 | ring->wptr = ring->rptr = RREG32(UVD_RBC_RB_RPTR); |
| 2588 | WREG32(UVD_RBC_RB_WPTR, ring->wptr); |
| 2589 | |
| 2590 | /* set the ring address */ |
| 2591 | WREG32(UVD_RBC_RB_BASE, ring->gpu_addr); |
| 2592 | |
| 2593 | /* Set ring buffer size */ |
| 2594 | rb_bufsz = drm_order(ring->ring_size); |
| 2595 | rb_bufsz = (0x1 << 8) | rb_bufsz; |
| 2596 | WREG32(UVD_RBC_RB_CNTL, rb_bufsz); |
| 2597 | |
| 2598 | ring->ready = true; |
| 2599 | r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring); |
| 2600 | if (r) { |
| 2601 | ring->ready = false; |
| 2602 | return r; |
| 2603 | } |
| 2604 | |
| 2605 | r = radeon_ring_lock(rdev, ring, 10); |
| 2606 | if (r) { |
| 2607 | DRM_ERROR("radeon: ring failed to lock UVD ring (%d).\n", r); |
| 2608 | return r; |
| 2609 | } |
| 2610 | |
| 2611 | tmp = PACKET0(UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL, 0); |
| 2612 | radeon_ring_write(ring, tmp); |
| 2613 | radeon_ring_write(ring, 0xFFFFF); |
| 2614 | |
| 2615 | tmp = PACKET0(UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL, 0); |
| 2616 | radeon_ring_write(ring, tmp); |
| 2617 | radeon_ring_write(ring, 0xFFFFF); |
| 2618 | |
| 2619 | tmp = PACKET0(UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL, 0); |
| 2620 | radeon_ring_write(ring, tmp); |
| 2621 | radeon_ring_write(ring, 0xFFFFF); |
| 2622 | |
| 2623 | /* Clear timeout status bits */ |
| 2624 | radeon_ring_write(ring, PACKET0(UVD_SEMA_TIMEOUT_STATUS, 0)); |
| 2625 | radeon_ring_write(ring, 0x8); |
| 2626 | |
| 2627 | radeon_ring_write(ring, PACKET0(UVD_SEMA_CNTL, 0)); |
| 2628 | radeon_ring_write(ring, 1); |
| 2629 | |
| 2630 | radeon_ring_unlock_commit(rdev, ring); |
| 2631 | |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
| 2635 | void r600_uvd_rbc_stop(struct radeon_device *rdev) |
| 2636 | { |
| 2637 | struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX]; |
| 2638 | |
| 2639 | /* force RBC into idle state */ |
| 2640 | WREG32(UVD_RBC_RB_CNTL, 0x11010101); |
| 2641 | ring->ready = false; |
| 2642 | } |
| 2643 | |
| 2644 | int r600_uvd_init(struct radeon_device *rdev) |
| 2645 | { |
| 2646 | int i, j, r; |
| 2647 | |
| 2648 | /* disable clock gating */ |
| 2649 | WREG32(UVD_CGC_GATE, 0); |
| 2650 | |
| 2651 | /* disable interupt */ |
| 2652 | WREG32_P(UVD_MASTINT_EN, 0, ~(1 << 1)); |
| 2653 | |
| 2654 | /* put LMI, VCPU, RBC etc... into reset */ |
| 2655 | WREG32(UVD_SOFT_RESET, LMI_SOFT_RESET | VCPU_SOFT_RESET | |
| 2656 | LBSI_SOFT_RESET | RBC_SOFT_RESET | CSM_SOFT_RESET | |
| 2657 | CXW_SOFT_RESET | TAP_SOFT_RESET | LMI_UMC_SOFT_RESET); |
| 2658 | mdelay(5); |
| 2659 | |
| 2660 | /* take UVD block out of reset */ |
| 2661 | WREG32_P(SRBM_SOFT_RESET, 0, ~SOFT_RESET_UVD); |
| 2662 | mdelay(5); |
| 2663 | |
| 2664 | /* initialize UVD memory controller */ |
| 2665 | WREG32(UVD_LMI_CTRL, 0x40 | (1 << 8) | (1 << 13) | |
| 2666 | (1 << 21) | (1 << 9) | (1 << 20)); |
| 2667 | |
| 2668 | /* disable byte swapping */ |
| 2669 | WREG32(UVD_LMI_SWAP_CNTL, 0); |
| 2670 | WREG32(UVD_MP_SWAP_CNTL, 0); |
| 2671 | |
| 2672 | WREG32(UVD_MPC_SET_MUXA0, 0x40c2040); |
| 2673 | WREG32(UVD_MPC_SET_MUXA1, 0x0); |
| 2674 | WREG32(UVD_MPC_SET_MUXB0, 0x40c2040); |
| 2675 | WREG32(UVD_MPC_SET_MUXB1, 0x0); |
| 2676 | WREG32(UVD_MPC_SET_ALU, 0); |
| 2677 | WREG32(UVD_MPC_SET_MUX, 0x88); |
| 2678 | |
| 2679 | /* Stall UMC */ |
| 2680 | WREG32_P(UVD_LMI_CTRL2, 1 << 8, ~(1 << 8)); |
| 2681 | WREG32_P(UVD_RB_ARB_CTRL, 1 << 3, ~(1 << 3)); |
| 2682 | |
| 2683 | /* take all subblocks out of reset, except VCPU */ |
| 2684 | WREG32(UVD_SOFT_RESET, VCPU_SOFT_RESET); |
| 2685 | mdelay(5); |
| 2686 | |
| 2687 | /* enable VCPU clock */ |
| 2688 | WREG32(UVD_VCPU_CNTL, 1 << 9); |
| 2689 | |
| 2690 | /* enable UMC */ |
| 2691 | WREG32_P(UVD_LMI_CTRL2, 0, ~(1 << 8)); |
| 2692 | |
| 2693 | /* boot up the VCPU */ |
| 2694 | WREG32(UVD_SOFT_RESET, 0); |
| 2695 | mdelay(10); |
| 2696 | |
| 2697 | WREG32_P(UVD_RB_ARB_CTRL, 0, ~(1 << 3)); |
| 2698 | |
| 2699 | for (i = 0; i < 10; ++i) { |
| 2700 | uint32_t status; |
| 2701 | for (j = 0; j < 100; ++j) { |
| 2702 | status = RREG32(UVD_STATUS); |
| 2703 | if (status & 2) |
| 2704 | break; |
| 2705 | mdelay(10); |
| 2706 | } |
| 2707 | r = 0; |
| 2708 | if (status & 2) |
| 2709 | break; |
| 2710 | |
| 2711 | DRM_ERROR("UVD not responding, trying to reset the VCPU!!!\n"); |
| 2712 | WREG32_P(UVD_SOFT_RESET, VCPU_SOFT_RESET, ~VCPU_SOFT_RESET); |
| 2713 | mdelay(10); |
| 2714 | WREG32_P(UVD_SOFT_RESET, 0, ~VCPU_SOFT_RESET); |
| 2715 | mdelay(10); |
| 2716 | r = -1; |
| 2717 | } |
| 2718 | if (r) { |
| 2719 | DRM_ERROR("UVD not responding, giving up!!!\n"); |
| 2720 | return r; |
| 2721 | } |
| 2722 | /* enable interupt */ |
| 2723 | WREG32_P(UVD_MASTINT_EN, 3<<1, ~(3 << 1)); |
| 2724 | |
| 2725 | r = r600_uvd_rbc_start(rdev); |
| 2726 | if (r) |
| 2727 | return r; |
| 2728 | |
| 2729 | DRM_INFO("UVD initialized successfully.\n"); |
| 2730 | return 0; |
| 2731 | } |
| 2732 | |
| 2733 | /* |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2734 | * GPU scratch registers helpers function. |
| 2735 | */ |
| 2736 | void r600_scratch_init(struct radeon_device *rdev) |
| 2737 | { |
| 2738 | int i; |
| 2739 | |
| 2740 | rdev->scratch.num_reg = 7; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2741 | rdev->scratch.reg_base = SCRATCH_REG0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2742 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 2743 | rdev->scratch.free[i] = true; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 2744 | rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2745 | } |
| 2746 | } |
| 2747 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2748 | int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2749 | { |
| 2750 | uint32_t scratch; |
| 2751 | uint32_t tmp = 0; |
Alex Deucher | 8b25ed3 | 2012-07-17 14:02:30 -0400 | [diff] [blame] | 2752 | unsigned i; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2753 | int r; |
| 2754 | |
| 2755 | r = radeon_scratch_get(rdev, &scratch); |
| 2756 | if (r) { |
| 2757 | DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r); |
| 2758 | return r; |
| 2759 | } |
| 2760 | WREG32(scratch, 0xCAFEDEAD); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2761 | r = radeon_ring_lock(rdev, ring, 3); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2762 | if (r) { |
Alex Deucher | 8b25ed3 | 2012-07-17 14:02:30 -0400 | [diff] [blame] | 2763 | DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2764 | radeon_scratch_free(rdev, scratch); |
| 2765 | return r; |
| 2766 | } |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2767 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 2768 | radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2)); |
| 2769 | radeon_ring_write(ring, 0xDEADBEEF); |
| 2770 | radeon_ring_unlock_commit(rdev, ring); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2771 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 2772 | tmp = RREG32(scratch); |
| 2773 | if (tmp == 0xDEADBEEF) |
| 2774 | break; |
| 2775 | DRM_UDELAY(1); |
| 2776 | } |
| 2777 | if (i < rdev->usec_timeout) { |
Alex Deucher | 8b25ed3 | 2012-07-17 14:02:30 -0400 | [diff] [blame] | 2778 | DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2779 | } else { |
Christian König | bf85279 | 2011-10-13 13:19:22 +0200 | [diff] [blame] | 2780 | DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n", |
Alex Deucher | 8b25ed3 | 2012-07-17 14:02:30 -0400 | [diff] [blame] | 2781 | ring->idx, scratch, tmp); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2782 | r = -EINVAL; |
| 2783 | } |
| 2784 | radeon_scratch_free(rdev, scratch); |
| 2785 | return r; |
| 2786 | } |
| 2787 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2788 | /** |
| 2789 | * r600_dma_ring_test - simple async dma engine test |
| 2790 | * |
| 2791 | * @rdev: radeon_device pointer |
| 2792 | * @ring: radeon_ring structure holding ring information |
| 2793 | * |
| 2794 | * Test the DMA engine by writing using it to write an |
| 2795 | * value to memory. (r6xx-SI). |
| 2796 | * Returns 0 for success, error for failure. |
| 2797 | */ |
| 2798 | int r600_dma_ring_test(struct radeon_device *rdev, |
| 2799 | struct radeon_ring *ring) |
| 2800 | { |
| 2801 | unsigned i; |
| 2802 | int r; |
| 2803 | void __iomem *ptr = (void *)rdev->vram_scratch.ptr; |
| 2804 | u32 tmp; |
| 2805 | |
| 2806 | if (!ptr) { |
| 2807 | DRM_ERROR("invalid vram scratch pointer\n"); |
| 2808 | return -EINVAL; |
| 2809 | } |
| 2810 | |
| 2811 | tmp = 0xCAFEDEAD; |
| 2812 | writel(tmp, ptr); |
| 2813 | |
| 2814 | r = radeon_ring_lock(rdev, ring, 4); |
| 2815 | if (r) { |
| 2816 | DRM_ERROR("radeon: dma failed to lock ring %d (%d).\n", ring->idx, r); |
| 2817 | return r; |
| 2818 | } |
| 2819 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1)); |
| 2820 | radeon_ring_write(ring, rdev->vram_scratch.gpu_addr & 0xfffffffc); |
| 2821 | radeon_ring_write(ring, upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff); |
| 2822 | radeon_ring_write(ring, 0xDEADBEEF); |
| 2823 | radeon_ring_unlock_commit(rdev, ring); |
| 2824 | |
| 2825 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 2826 | tmp = readl(ptr); |
| 2827 | if (tmp == 0xDEADBEEF) |
| 2828 | break; |
| 2829 | DRM_UDELAY(1); |
| 2830 | } |
| 2831 | |
| 2832 | if (i < rdev->usec_timeout) { |
| 2833 | DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i); |
| 2834 | } else { |
| 2835 | DRM_ERROR("radeon: ring %d test failed (0x%08X)\n", |
| 2836 | ring->idx, tmp); |
| 2837 | r = -EINVAL; |
| 2838 | } |
| 2839 | return r; |
| 2840 | } |
| 2841 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 2842 | int r600_uvd_ring_test(struct radeon_device *rdev, struct radeon_ring *ring) |
| 2843 | { |
| 2844 | uint32_t tmp = 0; |
| 2845 | unsigned i; |
| 2846 | int r; |
| 2847 | |
| 2848 | WREG32(UVD_CONTEXT_ID, 0xCAFEDEAD); |
| 2849 | r = radeon_ring_lock(rdev, ring, 3); |
| 2850 | if (r) { |
| 2851 | DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", |
| 2852 | ring->idx, r); |
| 2853 | return r; |
| 2854 | } |
| 2855 | radeon_ring_write(ring, PACKET0(UVD_CONTEXT_ID, 0)); |
| 2856 | radeon_ring_write(ring, 0xDEADBEEF); |
| 2857 | radeon_ring_unlock_commit(rdev, ring); |
| 2858 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 2859 | tmp = RREG32(UVD_CONTEXT_ID); |
| 2860 | if (tmp == 0xDEADBEEF) |
| 2861 | break; |
| 2862 | DRM_UDELAY(1); |
| 2863 | } |
| 2864 | |
| 2865 | if (i < rdev->usec_timeout) { |
| 2866 | DRM_INFO("ring test on %d succeeded in %d usecs\n", |
| 2867 | ring->idx, i); |
| 2868 | } else { |
| 2869 | DRM_ERROR("radeon: ring %d test failed (0x%08X)\n", |
| 2870 | ring->idx, tmp); |
| 2871 | r = -EINVAL; |
| 2872 | } |
| 2873 | return r; |
| 2874 | } |
| 2875 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2876 | /* |
| 2877 | * CP fences/semaphores |
| 2878 | */ |
| 2879 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2880 | void r600_fence_ring_emit(struct radeon_device *rdev, |
| 2881 | struct radeon_fence *fence) |
| 2882 | { |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2883 | struct radeon_ring *ring = &rdev->ring[fence->ring]; |
Christian König | 7b1f248 | 2011-09-23 15:11:23 +0200 | [diff] [blame] | 2884 | |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2885 | if (rdev->wb.use_event) { |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 2886 | u64 addr = rdev->fence_drv[fence->ring].gpu_addr; |
Jerome Glisse | 77b1bad | 2011-10-26 11:41:22 -0400 | [diff] [blame] | 2887 | /* flush read cache over gart */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2888 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3)); |
| 2889 | radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | |
| 2890 | PACKET3_VC_ACTION_ENA | |
| 2891 | PACKET3_SH_ACTION_ENA); |
| 2892 | radeon_ring_write(ring, 0xFFFFFFFF); |
| 2893 | radeon_ring_write(ring, 0); |
| 2894 | radeon_ring_write(ring, 10); /* poll interval */ |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2895 | /* EVENT_WRITE_EOP - flush caches, send int */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2896 | radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4)); |
| 2897 | radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5)); |
| 2898 | radeon_ring_write(ring, addr & 0xffffffff); |
| 2899 | radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2)); |
| 2900 | radeon_ring_write(ring, fence->seq); |
| 2901 | radeon_ring_write(ring, 0); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2902 | } else { |
Jerome Glisse | 77b1bad | 2011-10-26 11:41:22 -0400 | [diff] [blame] | 2903 | /* flush read cache over gart */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2904 | radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3)); |
| 2905 | radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | |
| 2906 | PACKET3_VC_ACTION_ENA | |
| 2907 | PACKET3_SH_ACTION_ENA); |
| 2908 | radeon_ring_write(ring, 0xFFFFFFFF); |
| 2909 | radeon_ring_write(ring, 0); |
| 2910 | radeon_ring_write(ring, 10); /* poll interval */ |
| 2911 | radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0)); |
| 2912 | radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0)); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2913 | /* wait for 3D idle clean */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2914 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 2915 | radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2); |
| 2916 | radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2917 | /* Emit fence sequence & fire IRQ */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2918 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 2919 | radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2)); |
| 2920 | radeon_ring_write(ring, fence->seq); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2921 | /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */ |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2922 | radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0)); |
| 2923 | radeon_ring_write(ring, RB_INT_STAT); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 2924 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 2925 | } |
| 2926 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 2927 | void r600_uvd_fence_emit(struct radeon_device *rdev, |
| 2928 | struct radeon_fence *fence) |
| 2929 | { |
| 2930 | struct radeon_ring *ring = &rdev->ring[fence->ring]; |
| 2931 | uint32_t addr = rdev->fence_drv[fence->ring].gpu_addr; |
| 2932 | |
| 2933 | radeon_ring_write(ring, PACKET0(UVD_CONTEXT_ID, 0)); |
| 2934 | radeon_ring_write(ring, fence->seq); |
| 2935 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA0, 0)); |
| 2936 | radeon_ring_write(ring, addr & 0xffffffff); |
| 2937 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA1, 0)); |
| 2938 | radeon_ring_write(ring, upper_32_bits(addr) & 0xff); |
| 2939 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0)); |
| 2940 | radeon_ring_write(ring, 0); |
| 2941 | |
| 2942 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA0, 0)); |
| 2943 | radeon_ring_write(ring, 0); |
| 2944 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA1, 0)); |
| 2945 | radeon_ring_write(ring, 0); |
| 2946 | radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0)); |
| 2947 | radeon_ring_write(ring, 2); |
| 2948 | return; |
| 2949 | } |
| 2950 | |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 2951 | void r600_semaphore_ring_emit(struct radeon_device *rdev, |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2952 | struct radeon_ring *ring, |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 2953 | struct radeon_semaphore *semaphore, |
Christian König | 7b1f248 | 2011-09-23 15:11:23 +0200 | [diff] [blame] | 2954 | bool emit_wait) |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 2955 | { |
| 2956 | uint64_t addr = semaphore->gpu_addr; |
| 2957 | unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL; |
| 2958 | |
Christian König | 0be7043 | 2012-03-07 11:28:57 +0100 | [diff] [blame] | 2959 | if (rdev->family < CHIP_CAYMAN) |
| 2960 | sel |= PACKET3_SEM_WAIT_ON_SIGNAL; |
| 2961 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 2962 | radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1)); |
| 2963 | radeon_ring_write(ring, addr & 0xffffffff); |
| 2964 | radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel); |
Christian König | 15d3332 | 2011-09-15 19:02:22 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2967 | /* |
| 2968 | * DMA fences/semaphores |
| 2969 | */ |
| 2970 | |
| 2971 | /** |
| 2972 | * r600_dma_fence_ring_emit - emit a fence on the DMA ring |
| 2973 | * |
| 2974 | * @rdev: radeon_device pointer |
| 2975 | * @fence: radeon fence object |
| 2976 | * |
| 2977 | * Add a DMA fence packet to the ring to write |
| 2978 | * the fence seq number and DMA trap packet to generate |
| 2979 | * an interrupt if needed (r6xx-r7xx). |
| 2980 | */ |
| 2981 | void r600_dma_fence_ring_emit(struct radeon_device *rdev, |
| 2982 | struct radeon_fence *fence) |
| 2983 | { |
| 2984 | struct radeon_ring *ring = &rdev->ring[fence->ring]; |
| 2985 | u64 addr = rdev->fence_drv[fence->ring].gpu_addr; |
Jerome Glisse | 86a1881 | 2012-12-12 16:43:15 -0500 | [diff] [blame] | 2986 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2987 | /* write the fence */ |
| 2988 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0, 0)); |
| 2989 | radeon_ring_write(ring, addr & 0xfffffffc); |
| 2990 | radeon_ring_write(ring, (upper_32_bits(addr) & 0xff)); |
Jerome Glisse | 86a1881 | 2012-12-12 16:43:15 -0500 | [diff] [blame] | 2991 | radeon_ring_write(ring, lower_32_bits(fence->seq)); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 2992 | /* generate an interrupt */ |
| 2993 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0, 0)); |
| 2994 | } |
| 2995 | |
| 2996 | /** |
| 2997 | * r600_dma_semaphore_ring_emit - emit a semaphore on the dma ring |
| 2998 | * |
| 2999 | * @rdev: radeon_device pointer |
| 3000 | * @ring: radeon_ring structure holding ring information |
| 3001 | * @semaphore: radeon semaphore object |
| 3002 | * @emit_wait: wait or signal semaphore |
| 3003 | * |
| 3004 | * Add a DMA semaphore packet to the ring wait on or signal |
| 3005 | * other rings (r6xx-SI). |
| 3006 | */ |
| 3007 | void r600_dma_semaphore_ring_emit(struct radeon_device *rdev, |
| 3008 | struct radeon_ring *ring, |
| 3009 | struct radeon_semaphore *semaphore, |
| 3010 | bool emit_wait) |
| 3011 | { |
| 3012 | u64 addr = semaphore->gpu_addr; |
| 3013 | u32 s = emit_wait ? 0 : 1; |
| 3014 | |
| 3015 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SEMAPHORE, 0, s, 0)); |
| 3016 | radeon_ring_write(ring, addr & 0xfffffffc); |
| 3017 | radeon_ring_write(ring, upper_32_bits(addr) & 0xff); |
| 3018 | } |
| 3019 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 3020 | void r600_uvd_semaphore_emit(struct radeon_device *rdev, |
| 3021 | struct radeon_ring *ring, |
| 3022 | struct radeon_semaphore *semaphore, |
| 3023 | bool emit_wait) |
| 3024 | { |
| 3025 | uint64_t addr = semaphore->gpu_addr; |
| 3026 | |
| 3027 | radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_LOW, 0)); |
| 3028 | radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF); |
| 3029 | |
| 3030 | radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_HIGH, 0)); |
| 3031 | radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF); |
| 3032 | |
| 3033 | radeon_ring_write(ring, PACKET0(UVD_SEMA_CMD, 0)); |
| 3034 | radeon_ring_write(ring, emit_wait ? 1 : 0); |
| 3035 | } |
| 3036 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3037 | int r600_copy_blit(struct radeon_device *rdev, |
Alex Deucher | 003cefe | 2011-09-16 12:04:08 -0400 | [diff] [blame] | 3038 | uint64_t src_offset, |
| 3039 | uint64_t dst_offset, |
| 3040 | unsigned num_gpu_pages, |
Christian König | 876dc9f | 2012-05-08 14:24:01 +0200 | [diff] [blame] | 3041 | struct radeon_fence **fence) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3042 | { |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 3043 | struct radeon_semaphore *sem = NULL; |
Christian König | f237750 | 2012-05-09 15:35:01 +0200 | [diff] [blame] | 3044 | struct radeon_sa_bo *vb = NULL; |
Jerome Glisse | ff82f05 | 2010-01-22 15:19:00 +0100 | [diff] [blame] | 3045 | int r; |
| 3046 | |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 3047 | r = r600_blit_prepare_copy(rdev, num_gpu_pages, fence, &vb, &sem); |
Jerome Glisse | ff82f05 | 2010-01-22 15:19:00 +0100 | [diff] [blame] | 3048 | if (r) { |
Jerome Glisse | ff82f05 | 2010-01-22 15:19:00 +0100 | [diff] [blame] | 3049 | return r; |
| 3050 | } |
Christian König | f237750 | 2012-05-09 15:35:01 +0200 | [diff] [blame] | 3051 | r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb); |
Christian König | 220907d | 2012-05-10 16:46:43 +0200 | [diff] [blame] | 3052 | r600_blit_done_copy(rdev, fence, vb, sem); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3053 | return 0; |
| 3054 | } |
| 3055 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3056 | /** |
| 3057 | * r600_copy_dma - copy pages using the DMA engine |
| 3058 | * |
| 3059 | * @rdev: radeon_device pointer |
| 3060 | * @src_offset: src GPU address |
| 3061 | * @dst_offset: dst GPU address |
| 3062 | * @num_gpu_pages: number of GPU pages to xfer |
| 3063 | * @fence: radeon fence object |
| 3064 | * |
Alex Deucher | 43fb778 | 2013-01-04 09:24:18 -0500 | [diff] [blame] | 3065 | * Copy GPU paging using the DMA engine (r6xx). |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3066 | * Used by the radeon ttm implementation to move pages if |
| 3067 | * registered as the asic copy callback. |
| 3068 | */ |
| 3069 | int r600_copy_dma(struct radeon_device *rdev, |
| 3070 | uint64_t src_offset, uint64_t dst_offset, |
| 3071 | unsigned num_gpu_pages, |
| 3072 | struct radeon_fence **fence) |
| 3073 | { |
| 3074 | struct radeon_semaphore *sem = NULL; |
| 3075 | int ring_index = rdev->asic->copy.dma_ring_index; |
| 3076 | struct radeon_ring *ring = &rdev->ring[ring_index]; |
| 3077 | u32 size_in_dw, cur_size_in_dw; |
| 3078 | int i, num_loops; |
| 3079 | int r = 0; |
| 3080 | |
| 3081 | r = radeon_semaphore_create(rdev, &sem); |
| 3082 | if (r) { |
| 3083 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 3084 | return r; |
| 3085 | } |
| 3086 | |
| 3087 | size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4; |
Alex Deucher | 43fb778 | 2013-01-04 09:24:18 -0500 | [diff] [blame] | 3088 | num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFE); |
| 3089 | r = radeon_ring_lock(rdev, ring, num_loops * 4 + 8); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3090 | if (r) { |
| 3091 | DRM_ERROR("radeon: moving bo (%d).\n", r); |
| 3092 | radeon_semaphore_free(rdev, &sem, NULL); |
| 3093 | return r; |
| 3094 | } |
| 3095 | |
| 3096 | if (radeon_fence_need_sync(*fence, ring->idx)) { |
| 3097 | radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring, |
| 3098 | ring->idx); |
| 3099 | radeon_fence_note_sync(*fence, ring->idx); |
| 3100 | } else { |
| 3101 | radeon_semaphore_free(rdev, &sem, NULL); |
| 3102 | } |
| 3103 | |
| 3104 | for (i = 0; i < num_loops; i++) { |
| 3105 | cur_size_in_dw = size_in_dw; |
Alex Deucher | 909d9eb | 2013-01-02 18:30:21 -0500 | [diff] [blame] | 3106 | if (cur_size_in_dw > 0xFFFE) |
| 3107 | cur_size_in_dw = 0xFFFE; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3108 | size_in_dw -= cur_size_in_dw; |
| 3109 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw)); |
| 3110 | radeon_ring_write(ring, dst_offset & 0xfffffffc); |
| 3111 | radeon_ring_write(ring, src_offset & 0xfffffffc); |
Alex Deucher | 43fb778 | 2013-01-04 09:24:18 -0500 | [diff] [blame] | 3112 | radeon_ring_write(ring, (((upper_32_bits(dst_offset) & 0xff) << 16) | |
| 3113 | (upper_32_bits(src_offset) & 0xff))); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3114 | src_offset += cur_size_in_dw * 4; |
| 3115 | dst_offset += cur_size_in_dw * 4; |
| 3116 | } |
| 3117 | |
| 3118 | r = radeon_fence_emit(rdev, fence, ring->idx); |
| 3119 | if (r) { |
| 3120 | radeon_ring_unlock_undo(rdev, ring); |
| 3121 | return r; |
| 3122 | } |
| 3123 | |
| 3124 | radeon_ring_unlock_commit(rdev, ring); |
| 3125 | radeon_semaphore_free(rdev, &sem, *fence); |
| 3126 | |
| 3127 | return r; |
| 3128 | } |
| 3129 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3130 | int r600_set_surface_reg(struct radeon_device *rdev, int reg, |
| 3131 | uint32_t tiling_flags, uint32_t pitch, |
| 3132 | uint32_t offset, uint32_t obj_size) |
| 3133 | { |
| 3134 | /* FIXME: implement */ |
| 3135 | return 0; |
| 3136 | } |
| 3137 | |
| 3138 | void r600_clear_surface_reg(struct radeon_device *rdev, int reg) |
| 3139 | { |
| 3140 | /* FIXME: implement */ |
| 3141 | } |
| 3142 | |
Lauri Kasanen | 1109ca0 | 2012-08-31 13:43:50 -0400 | [diff] [blame] | 3143 | static int r600_startup(struct radeon_device *rdev) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3144 | { |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3145 | struct radeon_ring *ring; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3146 | int r; |
| 3147 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 3148 | /* enable pcie gen2 link */ |
| 3149 | r600_pcie_gen2_enable(rdev); |
| 3150 | |
Alex Deucher | 779720a | 2009-12-09 19:31:44 -0500 | [diff] [blame] | 3151 | if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) { |
| 3152 | r = r600_init_microcode(rdev); |
| 3153 | if (r) { |
| 3154 | DRM_ERROR("Failed to load firmware!\n"); |
| 3155 | return r; |
| 3156 | } |
| 3157 | } |
| 3158 | |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 3159 | r = r600_vram_scratch_init(rdev); |
| 3160 | if (r) |
| 3161 | return r; |
| 3162 | |
Jerome Glisse | a3c1945 | 2009-10-01 18:02:13 +0200 | [diff] [blame] | 3163 | r600_mc_program(rdev); |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 3164 | if (rdev->flags & RADEON_IS_AGP) { |
| 3165 | r600_agp_enable(rdev); |
| 3166 | } else { |
| 3167 | r = r600_pcie_gart_enable(rdev); |
| 3168 | if (r) |
| 3169 | return r; |
| 3170 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3171 | r600_gpu_init(rdev); |
Jerome Glisse | c38c7b6 | 2010-02-04 17:27:27 +0100 | [diff] [blame] | 3172 | r = r600_blit_init(rdev); |
| 3173 | if (r) { |
| 3174 | r600_blit_fini(rdev); |
Alex Deucher | 27cd776 | 2012-02-23 17:53:42 -0500 | [diff] [blame] | 3175 | rdev->asic->copy.copy = NULL; |
Jerome Glisse | c38c7b6 | 2010-02-04 17:27:27 +0100 | [diff] [blame] | 3176 | dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r); |
| 3177 | } |
Alex Deucher | b70d6bb | 2010-08-06 21:36:58 -0400 | [diff] [blame] | 3178 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3179 | /* allocate wb buffer */ |
| 3180 | r = radeon_wb_init(rdev); |
| 3181 | if (r) |
| 3182 | return r; |
| 3183 | |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 3184 | r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); |
| 3185 | if (r) { |
| 3186 | dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); |
| 3187 | return r; |
| 3188 | } |
| 3189 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3190 | r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX); |
| 3191 | if (r) { |
| 3192 | dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r); |
| 3193 | return r; |
| 3194 | } |
| 3195 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3196 | /* Enable IRQ */ |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3197 | r = r600_irq_init(rdev); |
| 3198 | if (r) { |
| 3199 | DRM_ERROR("radeon: IH init failed (%d).\n", r); |
| 3200 | radeon_irq_kms_fini(rdev); |
| 3201 | return r; |
| 3202 | } |
| 3203 | r600_irq_set(rdev); |
| 3204 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3205 | ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3206 | 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] | 3207 | R600_CP_RB_RPTR, R600_CP_RB_WPTR, |
| 3208 | 0, 0xfffff, RADEON_CP_PACKET2); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3209 | if (r) |
| 3210 | return r; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3211 | |
| 3212 | ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX]; |
| 3213 | r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET, |
| 3214 | DMA_RB_RPTR, DMA_RB_WPTR, |
| 3215 | 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0)); |
| 3216 | if (r) |
| 3217 | return r; |
| 3218 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3219 | r = r600_cp_load_microcode(rdev); |
| 3220 | if (r) |
| 3221 | return r; |
| 3222 | r = r600_cp_resume(rdev); |
| 3223 | if (r) |
| 3224 | return r; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3225 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3226 | r = r600_dma_resume(rdev); |
| 3227 | if (r) |
| 3228 | return r; |
| 3229 | |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3230 | r = radeon_ib_pool_init(rdev); |
| 3231 | if (r) { |
| 3232 | dev_err(rdev->dev, "IB initialization failed (%d).\n", r); |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3233 | return r; |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3234 | } |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3235 | |
Alex Deucher | d4e30ef | 2012-06-04 17:18:51 -0400 | [diff] [blame] | 3236 | r = r600_audio_init(rdev); |
| 3237 | if (r) { |
| 3238 | DRM_ERROR("radeon: audio init failed\n"); |
| 3239 | return r; |
| 3240 | } |
| 3241 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3242 | return 0; |
| 3243 | } |
| 3244 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 3245 | void r600_vga_set_state(struct radeon_device *rdev, bool state) |
| 3246 | { |
| 3247 | uint32_t temp; |
| 3248 | |
| 3249 | temp = RREG32(CONFIG_CNTL); |
| 3250 | if (state == false) { |
| 3251 | temp &= ~(1<<0); |
| 3252 | temp |= (1<<1); |
| 3253 | } else { |
| 3254 | temp &= ~(1<<1); |
| 3255 | } |
| 3256 | WREG32(CONFIG_CNTL, temp); |
| 3257 | } |
| 3258 | |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3259 | int r600_resume(struct radeon_device *rdev) |
| 3260 | { |
| 3261 | int r; |
| 3262 | |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 3263 | /* Do not reset GPU before posting, on r600 hw unlike on r500 hw, |
| 3264 | * posting will perform necessary task to bring back GPU into good |
| 3265 | * shape. |
| 3266 | */ |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3267 | /* post card */ |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 3268 | atom_asic_init(rdev->mode_info.atom_context); |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3269 | |
Jerome Glisse | b15ba51 | 2011-11-15 11:48:34 -0500 | [diff] [blame] | 3270 | rdev->accel_working = true; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3271 | r = r600_startup(rdev); |
| 3272 | if (r) { |
| 3273 | DRM_ERROR("r600 startup failed on resume\n"); |
Jerome Glisse | 6b7746e | 2012-02-20 17:57:20 -0500 | [diff] [blame] | 3274 | rdev->accel_working = false; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3275 | return r; |
| 3276 | } |
| 3277 | |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3278 | return r; |
| 3279 | } |
| 3280 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3281 | int r600_suspend(struct radeon_device *rdev) |
| 3282 | { |
Rafał Miłecki | 38fd2c6 | 2010-01-28 18:16:30 +0100 | [diff] [blame] | 3283 | r600_audio_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3284 | r600_cp_stop(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3285 | r600_dma_stop(rdev); |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 3286 | r600_irq_suspend(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3287 | radeon_wb_disable(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 3288 | r600_pcie_gart_disable(rdev); |
Alex Deucher | 6ddddfe | 2011-10-14 10:51:22 -0400 | [diff] [blame] | 3289 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3290 | return 0; |
| 3291 | } |
| 3292 | |
| 3293 | /* Plan is to move initialization in that function and use |
| 3294 | * helper function so that radeon_device_init pretty much |
| 3295 | * do nothing more than calling asic specific function. This |
| 3296 | * should also allow to remove a bunch of callback function |
| 3297 | * like vram_info. |
| 3298 | */ |
| 3299 | int r600_init(struct radeon_device *rdev) |
| 3300 | { |
| 3301 | int r; |
| 3302 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3303 | if (r600_debugfs_mc_info_init(rdev)) { |
| 3304 | DRM_ERROR("Failed to register debugfs file for mc !\n"); |
| 3305 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3306 | /* Read BIOS */ |
| 3307 | if (!radeon_get_bios(rdev)) { |
| 3308 | if (ASIC_IS_AVIVO(rdev)) |
| 3309 | return -EINVAL; |
| 3310 | } |
| 3311 | /* Must be an ATOMBIOS */ |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 3312 | if (!rdev->is_atom_bios) { |
| 3313 | dev_err(rdev->dev, "Expecting atombios for R600 GPU\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3314 | return -EINVAL; |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 3315 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3316 | r = radeon_atombios_init(rdev); |
| 3317 | if (r) |
| 3318 | return r; |
| 3319 | /* Post card if necessary */ |
Alex Deucher | fd909c3 | 2011-01-11 18:08:59 -0500 | [diff] [blame] | 3320 | if (!radeon_card_posted(rdev)) { |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 3321 | if (!rdev->bios) { |
| 3322 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 3323 | return -EINVAL; |
| 3324 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3325 | DRM_INFO("GPU not posted. posting now...\n"); |
| 3326 | atom_asic_init(rdev->mode_info.atom_context); |
| 3327 | } |
| 3328 | /* Initialize scratch registers */ |
| 3329 | r600_scratch_init(rdev); |
| 3330 | /* Initialize surface registers */ |
| 3331 | radeon_surface_init(rdev); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 3332 | /* Initialize clocks */ |
Michel Dänzer | 5e6dde7 | 2009-09-17 09:42:28 +0200 | [diff] [blame] | 3333 | radeon_get_clock_info(rdev->ddev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3334 | /* Fence driver */ |
Jerome Glisse | 30eb77f | 2011-11-20 20:45:34 +0000 | [diff] [blame] | 3335 | r = radeon_fence_driver_init(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3336 | if (r) |
| 3337 | return r; |
Jerome Glisse | 700a0cc | 2010-01-13 15:16:38 +0100 | [diff] [blame] | 3338 | if (rdev->flags & RADEON_IS_AGP) { |
| 3339 | r = radeon_agp_init(rdev); |
| 3340 | if (r) |
| 3341 | radeon_agp_disable(rdev); |
| 3342 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3343 | r = r600_mc_init(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 3344 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3345 | return r; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3346 | /* Memory manager */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3347 | r = radeon_bo_init(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3348 | if (r) |
| 3349 | return r; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3350 | |
| 3351 | r = radeon_irq_kms_init(rdev); |
| 3352 | if (r) |
| 3353 | return r; |
| 3354 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3355 | rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL; |
| 3356 | r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3357 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3358 | rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL; |
| 3359 | r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024); |
| 3360 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3361 | rdev->ih.ring_obj = NULL; |
| 3362 | r600_ih_ring_init(rdev, 64 * 1024); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3363 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 3364 | r = r600_pcie_gart_init(rdev); |
| 3365 | if (r) |
| 3366 | return r; |
| 3367 | |
Alex Deucher | 779720a | 2009-12-09 19:31:44 -0500 | [diff] [blame] | 3368 | rdev->accel_working = true; |
Dave Airlie | fc30b8e | 2009-09-18 15:19:37 +1000 | [diff] [blame] | 3369 | r = r600_startup(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3370 | if (r) { |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 3371 | dev_err(rdev->dev, "disabling GPU acceleration\n"); |
| 3372 | r600_cp_fini(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3373 | r600_dma_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 3374 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3375 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3376 | radeon_ib_pool_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 3377 | radeon_irq_kms_fini(rdev); |
Jerome Glisse | 75c8129 | 2009-10-01 18:02:14 +0200 | [diff] [blame] | 3378 | r600_pcie_gart_fini(rdev); |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 3379 | rdev->accel_working = false; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3380 | } |
Christian Koenig | dafc3bd | 2009-10-11 23:49:13 +0200 | [diff] [blame] | 3381 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3382 | return 0; |
| 3383 | } |
| 3384 | |
| 3385 | void r600_fini(struct radeon_device *rdev) |
| 3386 | { |
Christian Koenig | dafc3bd | 2009-10-11 23:49:13 +0200 | [diff] [blame] | 3387 | r600_audio_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3388 | r600_blit_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 3389 | r600_cp_fini(rdev); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3390 | r600_dma_fini(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3391 | r600_irq_fini(rdev); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3392 | radeon_wb_fini(rdev); |
Christian König | 2898c34 | 2012-07-05 11:55:34 +0200 | [diff] [blame] | 3393 | radeon_ib_pool_fini(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3394 | radeon_irq_kms_fini(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 3395 | r600_pcie_gart_fini(rdev); |
Alex Deucher | 16cdf04 | 2011-10-28 10:30:02 -0400 | [diff] [blame] | 3396 | r600_vram_scratch_fini(rdev); |
Jerome Glisse | 655efd3 | 2010-02-02 11:51:45 +0100 | [diff] [blame] | 3397 | radeon_agp_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3398 | radeon_gem_fini(rdev); |
| 3399 | radeon_fence_driver_fini(rdev); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3400 | radeon_bo_fini(rdev); |
Jerome Glisse | e7d40b9 | 2009-10-01 18:02:15 +0200 | [diff] [blame] | 3401 | radeon_atombios_fini(rdev); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3402 | kfree(rdev->bios); |
| 3403 | rdev->bios = NULL; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | |
| 3407 | /* |
| 3408 | * CS stuff |
| 3409 | */ |
| 3410 | void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 3411 | { |
Christian König | 876dc9f | 2012-05-08 14:24:01 +0200 | [diff] [blame] | 3412 | struct radeon_ring *ring = &rdev->ring[ib->ring]; |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 3413 | u32 next_rptr; |
Christian König | 7b1f248 | 2011-09-23 15:11:23 +0200 | [diff] [blame] | 3414 | |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 3415 | if (ring->rptr_save_reg) { |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 3416 | next_rptr = ring->wptr + 3 + 4; |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 3417 | radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); |
| 3418 | radeon_ring_write(ring, ((ring->rptr_save_reg - |
| 3419 | PACKET3_SET_CONFIG_REG_OFFSET) >> 2)); |
| 3420 | radeon_ring_write(ring, next_rptr); |
Alex Deucher | 89d3580 | 2012-07-17 14:02:31 -0400 | [diff] [blame] | 3421 | } else if (rdev->wb.enabled) { |
| 3422 | next_rptr = ring->wptr + 5 + 4; |
| 3423 | radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3)); |
| 3424 | radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc); |
| 3425 | radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18)); |
| 3426 | radeon_ring_write(ring, next_rptr); |
| 3427 | radeon_ring_write(ring, 0); |
Christian König | 45df680 | 2012-07-06 16:22:55 +0200 | [diff] [blame] | 3428 | } |
| 3429 | |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3430 | radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2)); |
| 3431 | radeon_ring_write(ring, |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 3432 | #ifdef __BIG_ENDIAN |
| 3433 | (2 << 0) | |
| 3434 | #endif |
| 3435 | (ib->gpu_addr & 0xFFFFFFFC)); |
Christian König | e32eb50 | 2011-10-23 12:56:27 +0200 | [diff] [blame] | 3436 | radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF); |
| 3437 | radeon_ring_write(ring, ib->length_dw); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3438 | } |
| 3439 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 3440 | void r600_uvd_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 3441 | { |
| 3442 | struct radeon_ring *ring = &rdev->ring[ib->ring]; |
| 3443 | |
| 3444 | radeon_ring_write(ring, PACKET0(UVD_RBC_IB_BASE, 0)); |
| 3445 | radeon_ring_write(ring, ib->gpu_addr); |
| 3446 | radeon_ring_write(ring, PACKET0(UVD_RBC_IB_SIZE, 0)); |
| 3447 | radeon_ring_write(ring, ib->length_dw); |
| 3448 | } |
| 3449 | |
Alex Deucher | f712812 | 2012-02-23 17:53:45 -0500 | [diff] [blame] | 3450 | int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3451 | { |
Jerome Glisse | f2e3922 | 2012-05-09 15:35:02 +0200 | [diff] [blame] | 3452 | struct radeon_ib ib; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3453 | uint32_t scratch; |
| 3454 | uint32_t tmp = 0; |
| 3455 | unsigned i; |
| 3456 | int r; |
| 3457 | |
| 3458 | r = radeon_scratch_get(rdev, &scratch); |
| 3459 | if (r) { |
| 3460 | DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r); |
| 3461 | return r; |
| 3462 | } |
| 3463 | WREG32(scratch, 0xCAFEDEAD); |
Christian König | 4bf3dd9 | 2012-08-06 18:57:44 +0200 | [diff] [blame] | 3464 | r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3465 | if (r) { |
| 3466 | DRM_ERROR("radeon: failed to get ib (%d).\n", r); |
Michel Dänzer | af026c5 | 2012-09-20 10:31:10 +0200 | [diff] [blame] | 3467 | goto free_scratch; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3468 | } |
Jerome Glisse | f2e3922 | 2012-05-09 15:35:02 +0200 | [diff] [blame] | 3469 | ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1); |
| 3470 | ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2); |
| 3471 | ib.ptr[2] = 0xDEADBEEF; |
| 3472 | ib.length_dw = 3; |
Christian König | 4ef7256 | 2012-07-13 13:06:00 +0200 | [diff] [blame] | 3473 | r = radeon_ib_schedule(rdev, &ib, NULL); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3474 | if (r) { |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3475 | DRM_ERROR("radeon: failed to schedule ib (%d).\n", r); |
Michel Dänzer | af026c5 | 2012-09-20 10:31:10 +0200 | [diff] [blame] | 3476 | goto free_ib; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3477 | } |
Jerome Glisse | f2e3922 | 2012-05-09 15:35:02 +0200 | [diff] [blame] | 3478 | r = radeon_fence_wait(ib.fence, false); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3479 | if (r) { |
| 3480 | DRM_ERROR("radeon: fence wait failed (%d).\n", r); |
Michel Dänzer | af026c5 | 2012-09-20 10:31:10 +0200 | [diff] [blame] | 3481 | goto free_ib; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3482 | } |
| 3483 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3484 | tmp = RREG32(scratch); |
| 3485 | if (tmp == 0xDEADBEEF) |
| 3486 | break; |
| 3487 | DRM_UDELAY(1); |
| 3488 | } |
| 3489 | if (i < rdev->usec_timeout) { |
Jerome Glisse | f2e3922 | 2012-05-09 15:35:02 +0200 | [diff] [blame] | 3490 | DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3491 | } else { |
Daniel J Blueman | 4417d7f | 2010-09-22 17:57:19 +0100 | [diff] [blame] | 3492 | DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n", |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3493 | scratch, tmp); |
| 3494 | r = -EINVAL; |
| 3495 | } |
Michel Dänzer | af026c5 | 2012-09-20 10:31:10 +0200 | [diff] [blame] | 3496 | free_ib: |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3497 | radeon_ib_free(rdev, &ib); |
Michel Dänzer | af026c5 | 2012-09-20 10:31:10 +0200 | [diff] [blame] | 3498 | free_scratch: |
| 3499 | radeon_scratch_free(rdev, scratch); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3500 | return r; |
| 3501 | } |
| 3502 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3503 | /** |
| 3504 | * r600_dma_ib_test - test an IB on the DMA engine |
| 3505 | * |
| 3506 | * @rdev: radeon_device pointer |
| 3507 | * @ring: radeon_ring structure holding ring information |
| 3508 | * |
| 3509 | * Test a simple IB in the DMA ring (r6xx-SI). |
| 3510 | * Returns 0 on success, error on failure. |
| 3511 | */ |
| 3512 | int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) |
| 3513 | { |
| 3514 | struct radeon_ib ib; |
| 3515 | unsigned i; |
| 3516 | int r; |
| 3517 | void __iomem *ptr = (void *)rdev->vram_scratch.ptr; |
| 3518 | u32 tmp = 0; |
| 3519 | |
| 3520 | if (!ptr) { |
| 3521 | DRM_ERROR("invalid vram scratch pointer\n"); |
| 3522 | return -EINVAL; |
| 3523 | } |
| 3524 | |
| 3525 | tmp = 0xCAFEDEAD; |
| 3526 | writel(tmp, ptr); |
| 3527 | |
| 3528 | r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256); |
| 3529 | if (r) { |
| 3530 | DRM_ERROR("radeon: failed to get ib (%d).\n", r); |
| 3531 | return r; |
| 3532 | } |
| 3533 | |
| 3534 | ib.ptr[0] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1); |
| 3535 | ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc; |
| 3536 | ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff; |
| 3537 | ib.ptr[3] = 0xDEADBEEF; |
| 3538 | ib.length_dw = 4; |
| 3539 | |
| 3540 | r = radeon_ib_schedule(rdev, &ib, NULL); |
| 3541 | if (r) { |
| 3542 | radeon_ib_free(rdev, &ib); |
| 3543 | DRM_ERROR("radeon: failed to schedule ib (%d).\n", r); |
| 3544 | return r; |
| 3545 | } |
| 3546 | r = radeon_fence_wait(ib.fence, false); |
| 3547 | if (r) { |
| 3548 | DRM_ERROR("radeon: fence wait failed (%d).\n", r); |
| 3549 | return r; |
| 3550 | } |
| 3551 | for (i = 0; i < rdev->usec_timeout; i++) { |
| 3552 | tmp = readl(ptr); |
| 3553 | if (tmp == 0xDEADBEEF) |
| 3554 | break; |
| 3555 | DRM_UDELAY(1); |
| 3556 | } |
| 3557 | if (i < rdev->usec_timeout) { |
| 3558 | DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i); |
| 3559 | } else { |
| 3560 | DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp); |
| 3561 | r = -EINVAL; |
| 3562 | } |
| 3563 | radeon_ib_free(rdev, &ib); |
| 3564 | return r; |
| 3565 | } |
| 3566 | |
Christian König | f2ba57b | 2013-04-08 12:41:29 +0200 | [diff] [blame] | 3567 | int r600_uvd_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) |
| 3568 | { |
| 3569 | struct radeon_fence *fence; |
| 3570 | int r; |
| 3571 | |
| 3572 | r = radeon_uvd_get_create_msg(rdev, ring->idx, 1, NULL); |
| 3573 | if (r) { |
| 3574 | DRM_ERROR("radeon: failed to get create msg (%d).\n", r); |
| 3575 | return r; |
| 3576 | } |
| 3577 | |
| 3578 | r = radeon_uvd_get_destroy_msg(rdev, ring->idx, 1, &fence); |
| 3579 | if (r) { |
| 3580 | DRM_ERROR("radeon: failed to get destroy ib (%d).\n", r); |
| 3581 | return r; |
| 3582 | } |
| 3583 | |
| 3584 | r = radeon_fence_wait(fence, false); |
| 3585 | if (r) { |
| 3586 | DRM_ERROR("radeon: fence wait failed (%d).\n", r); |
| 3587 | return r; |
| 3588 | } |
| 3589 | DRM_INFO("ib test on ring %d succeeded\n", ring->idx); |
| 3590 | radeon_fence_unref(&fence); |
| 3591 | return r; |
| 3592 | } |
| 3593 | |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3594 | /** |
| 3595 | * r600_dma_ring_ib_execute - Schedule an IB on the DMA engine |
| 3596 | * |
| 3597 | * @rdev: radeon_device pointer |
| 3598 | * @ib: IB object to schedule |
| 3599 | * |
| 3600 | * Schedule an IB in the DMA ring (r6xx-r7xx). |
| 3601 | */ |
| 3602 | void r600_dma_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib) |
| 3603 | { |
| 3604 | struct radeon_ring *ring = &rdev->ring[ib->ring]; |
| 3605 | |
| 3606 | if (rdev->wb.enabled) { |
| 3607 | u32 next_rptr = ring->wptr + 4; |
| 3608 | while ((next_rptr & 7) != 5) |
| 3609 | next_rptr++; |
| 3610 | next_rptr += 3; |
| 3611 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1)); |
| 3612 | radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc); |
| 3613 | radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff); |
| 3614 | radeon_ring_write(ring, next_rptr); |
| 3615 | } |
| 3616 | |
| 3617 | /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring. |
| 3618 | * Pad as necessary with NOPs. |
| 3619 | */ |
| 3620 | while ((ring->wptr & 7) != 5) |
| 3621 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0)); |
| 3622 | radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0, 0)); |
| 3623 | radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0)); |
| 3624 | radeon_ring_write(ring, (ib->length_dw << 16) | (upper_32_bits(ib->gpu_addr) & 0xFF)); |
| 3625 | |
| 3626 | } |
| 3627 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3628 | /* |
| 3629 | * Interrupts |
| 3630 | * |
| 3631 | * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty |
| 3632 | * the same as the CP ring buffer, but in reverse. Rather than the CPU |
| 3633 | * writing to the ring and the GPU consuming, the GPU writes to the ring |
| 3634 | * and host consumes. As the host irq handler processes interrupts, it |
| 3635 | * increments the rptr. When the rptr catches up with the wptr, all the |
| 3636 | * current interrupts have been processed. |
| 3637 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3638 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3639 | void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size) |
| 3640 | { |
| 3641 | u32 rb_bufsz; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 3642 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3643 | /* Align ring size */ |
| 3644 | rb_bufsz = drm_order(ring_size / 4); |
| 3645 | ring_size = (1 << rb_bufsz) * 4; |
| 3646 | rdev->ih.ring_size = ring_size; |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 3647 | rdev->ih.ptr_mask = rdev->ih.ring_size - 1; |
| 3648 | rdev->ih.rptr = 0; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3649 | } |
| 3650 | |
Alex Deucher | 25a857f | 2012-03-20 17:18:22 -0400 | [diff] [blame] | 3651 | int r600_ih_ring_alloc(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3652 | { |
| 3653 | int r; |
| 3654 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3655 | /* Allocate ring buffer */ |
| 3656 | if (rdev->ih.ring_obj == NULL) { |
Daniel Vetter | 441921d | 2011-02-18 17:59:16 +0100 | [diff] [blame] | 3657 | r = radeon_bo_create(rdev, rdev->ih.ring_size, |
Alex Deucher | 268b251 | 2010-11-17 19:00:26 -0500 | [diff] [blame] | 3658 | PAGE_SIZE, true, |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3659 | RADEON_GEM_DOMAIN_GTT, |
Alex Deucher | 40f5cf9 | 2012-05-10 18:33:13 -0400 | [diff] [blame] | 3660 | NULL, &rdev->ih.ring_obj); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3661 | if (r) { |
| 3662 | DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r); |
| 3663 | return r; |
| 3664 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3665 | r = radeon_bo_reserve(rdev->ih.ring_obj, false); |
| 3666 | if (unlikely(r != 0)) |
| 3667 | return r; |
| 3668 | r = radeon_bo_pin(rdev->ih.ring_obj, |
| 3669 | RADEON_GEM_DOMAIN_GTT, |
| 3670 | &rdev->ih.gpu_addr); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3671 | if (r) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3672 | radeon_bo_unreserve(rdev->ih.ring_obj); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3673 | DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r); |
| 3674 | return r; |
| 3675 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3676 | r = radeon_bo_kmap(rdev->ih.ring_obj, |
| 3677 | (void **)&rdev->ih.ring); |
| 3678 | radeon_bo_unreserve(rdev->ih.ring_obj); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3679 | if (r) { |
| 3680 | DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r); |
| 3681 | return r; |
| 3682 | } |
| 3683 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3684 | return 0; |
| 3685 | } |
| 3686 | |
Alex Deucher | 25a857f | 2012-03-20 17:18:22 -0400 | [diff] [blame] | 3687 | void r600_ih_ring_fini(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3688 | { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3689 | int r; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3690 | if (rdev->ih.ring_obj) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 3691 | r = radeon_bo_reserve(rdev->ih.ring_obj, false); |
| 3692 | if (likely(r == 0)) { |
| 3693 | radeon_bo_kunmap(rdev->ih.ring_obj); |
| 3694 | radeon_bo_unpin(rdev->ih.ring_obj); |
| 3695 | radeon_bo_unreserve(rdev->ih.ring_obj); |
| 3696 | } |
| 3697 | radeon_bo_unref(&rdev->ih.ring_obj); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3698 | rdev->ih.ring = NULL; |
| 3699 | rdev->ih.ring_obj = NULL; |
| 3700 | } |
| 3701 | } |
| 3702 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3703 | void r600_rlc_stop(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3704 | { |
| 3705 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3706 | if ((rdev->family >= CHIP_RV770) && |
| 3707 | (rdev->family <= CHIP_RV740)) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3708 | /* r7xx asics need to soft reset RLC before halting */ |
| 3709 | WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC); |
| 3710 | RREG32(SRBM_SOFT_RESET); |
Arnd Bergmann | 4de833c | 2012-04-05 12:58:22 -0600 | [diff] [blame] | 3711 | mdelay(15); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3712 | WREG32(SRBM_SOFT_RESET, 0); |
| 3713 | RREG32(SRBM_SOFT_RESET); |
| 3714 | } |
| 3715 | |
| 3716 | WREG32(RLC_CNTL, 0); |
| 3717 | } |
| 3718 | |
| 3719 | static void r600_rlc_start(struct radeon_device *rdev) |
| 3720 | { |
| 3721 | WREG32(RLC_CNTL, RLC_ENABLE); |
| 3722 | } |
| 3723 | |
| 3724 | static int r600_rlc_init(struct radeon_device *rdev) |
| 3725 | { |
| 3726 | u32 i; |
| 3727 | const __be32 *fw_data; |
| 3728 | |
| 3729 | if (!rdev->rlc_fw) |
| 3730 | return -EINVAL; |
| 3731 | |
| 3732 | r600_rlc_stop(rdev); |
| 3733 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3734 | WREG32(RLC_HB_CNTL, 0); |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 3735 | |
| 3736 | if (rdev->family == CHIP_ARUBA) { |
| 3737 | WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8); |
| 3738 | WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8); |
| 3739 | } |
| 3740 | if (rdev->family <= CHIP_CAYMAN) { |
| 3741 | WREG32(RLC_HB_BASE, 0); |
| 3742 | WREG32(RLC_HB_RPTR, 0); |
| 3743 | WREG32(RLC_HB_WPTR, 0); |
| 3744 | } |
Alex Deucher | 1272780 | 2011-03-02 20:07:32 -0500 | [diff] [blame] | 3745 | if (rdev->family <= CHIP_CAICOS) { |
| 3746 | WREG32(RLC_HB_WPTR_LSB_ADDR, 0); |
| 3747 | WREG32(RLC_HB_WPTR_MSB_ADDR, 0); |
| 3748 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3749 | WREG32(RLC_MC_CNTL, 0); |
| 3750 | WREG32(RLC_UCODE_CNTL, 0); |
| 3751 | |
| 3752 | fw_data = (const __be32 *)rdev->rlc_fw->data; |
Alex Deucher | c420c74 | 2012-03-20 17:18:39 -0400 | [diff] [blame] | 3753 | if (rdev->family >= CHIP_ARUBA) { |
| 3754 | for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) { |
| 3755 | WREG32(RLC_UCODE_ADDR, i); |
| 3756 | WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 3757 | } |
| 3758 | } else if (rdev->family >= CHIP_CAYMAN) { |
Alex Deucher | 1272780 | 2011-03-02 20:07:32 -0500 | [diff] [blame] | 3759 | for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) { |
| 3760 | WREG32(RLC_UCODE_ADDR, i); |
| 3761 | WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 3762 | } |
| 3763 | } else if (rdev->family >= CHIP_CEDAR) { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3764 | for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) { |
| 3765 | WREG32(RLC_UCODE_ADDR, i); |
| 3766 | WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 3767 | } |
| 3768 | } else if (rdev->family >= CHIP_RV770) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3769 | for (i = 0; i < R700_RLC_UCODE_SIZE; i++) { |
| 3770 | WREG32(RLC_UCODE_ADDR, i); |
| 3771 | WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 3772 | } |
| 3773 | } else { |
| 3774 | for (i = 0; i < RLC_UCODE_SIZE; i++) { |
| 3775 | WREG32(RLC_UCODE_ADDR, i); |
| 3776 | WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++)); |
| 3777 | } |
| 3778 | } |
| 3779 | WREG32(RLC_UCODE_ADDR, 0); |
| 3780 | |
| 3781 | r600_rlc_start(rdev); |
| 3782 | |
| 3783 | return 0; |
| 3784 | } |
| 3785 | |
| 3786 | static void r600_enable_interrupts(struct radeon_device *rdev) |
| 3787 | { |
| 3788 | u32 ih_cntl = RREG32(IH_CNTL); |
| 3789 | u32 ih_rb_cntl = RREG32(IH_RB_CNTL); |
| 3790 | |
| 3791 | ih_cntl |= ENABLE_INTR; |
| 3792 | ih_rb_cntl |= IH_RB_ENABLE; |
| 3793 | WREG32(IH_CNTL, ih_cntl); |
| 3794 | WREG32(IH_RB_CNTL, ih_rb_cntl); |
| 3795 | rdev->ih.enabled = true; |
| 3796 | } |
| 3797 | |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3798 | void r600_disable_interrupts(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3799 | { |
| 3800 | u32 ih_rb_cntl = RREG32(IH_RB_CNTL); |
| 3801 | u32 ih_cntl = RREG32(IH_CNTL); |
| 3802 | |
| 3803 | ih_rb_cntl &= ~IH_RB_ENABLE; |
| 3804 | ih_cntl &= ~ENABLE_INTR; |
| 3805 | WREG32(IH_RB_CNTL, ih_rb_cntl); |
| 3806 | WREG32(IH_CNTL, ih_cntl); |
| 3807 | /* set rptr, wptr to 0 */ |
| 3808 | WREG32(IH_RB_RPTR, 0); |
| 3809 | WREG32(IH_RB_WPTR, 0); |
| 3810 | rdev->ih.enabled = false; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3811 | rdev->ih.rptr = 0; |
| 3812 | } |
| 3813 | |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3814 | static void r600_disable_interrupt_state(struct radeon_device *rdev) |
| 3815 | { |
| 3816 | u32 tmp; |
| 3817 | |
Alex Deucher | 3555e53 | 2010-10-08 12:09:12 -0400 | [diff] [blame] | 3818 | WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3819 | tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE; |
| 3820 | WREG32(DMA_CNTL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3821 | WREG32(GRBM_INT_CNTL, 0); |
| 3822 | WREG32(DxMODE_INT_MASK, 0); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3823 | WREG32(D1GRPH_INTERRUPT_CONTROL, 0); |
| 3824 | WREG32(D2GRPH_INTERRUPT_CONTROL, 0); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3825 | if (ASIC_IS_DCE3(rdev)) { |
| 3826 | WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0); |
| 3827 | WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0); |
| 3828 | tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 3829 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 3830 | tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 3831 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 3832 | tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 3833 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 3834 | tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
| 3835 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 3836 | if (ASIC_IS_DCE32(rdev)) { |
| 3837 | tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
Alex Deucher | 5898b1f | 2010-03-24 13:57:29 -0400 | [diff] [blame] | 3838 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3839 | tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY; |
Alex Deucher | 5898b1f | 2010-03-24 13:57:29 -0400 | [diff] [blame] | 3840 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 3841 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3842 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp); |
| 3843 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3844 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3845 | } else { |
| 3846 | tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3847 | WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp); |
| 3848 | tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3849 | WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3850 | } |
| 3851 | } else { |
| 3852 | WREG32(DACA_AUTODETECT_INT_CONTROL, 0); |
| 3853 | WREG32(DACB_AUTODETECT_INT_CONTROL, 0); |
| 3854 | tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY; |
Alex Deucher | 5898b1f | 2010-03-24 13:57:29 -0400 | [diff] [blame] | 3855 | WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3856 | tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY; |
Alex Deucher | 5898b1f | 2010-03-24 13:57:29 -0400 | [diff] [blame] | 3857 | WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3858 | tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY; |
Alex Deucher | 5898b1f | 2010-03-24 13:57:29 -0400 | [diff] [blame] | 3859 | WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3860 | tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3861 | WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp); |
| 3862 | tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3863 | WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3867 | int r600_irq_init(struct radeon_device *rdev) |
| 3868 | { |
| 3869 | int ret = 0; |
| 3870 | int rb_bufsz; |
| 3871 | u32 interrupt_cntl, ih_cntl, ih_rb_cntl; |
| 3872 | |
| 3873 | /* allocate ring */ |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 3874 | ret = r600_ih_ring_alloc(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3875 | if (ret) |
| 3876 | return ret; |
| 3877 | |
| 3878 | /* disable irqs */ |
| 3879 | r600_disable_interrupts(rdev); |
| 3880 | |
| 3881 | /* init rlc */ |
| 3882 | ret = r600_rlc_init(rdev); |
| 3883 | if (ret) { |
| 3884 | r600_ih_ring_fini(rdev); |
| 3885 | return ret; |
| 3886 | } |
| 3887 | |
| 3888 | /* setup interrupt control */ |
| 3889 | /* set dummy read address to ring address */ |
| 3890 | WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8); |
| 3891 | interrupt_cntl = RREG32(INTERRUPT_CNTL); |
| 3892 | /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi |
| 3893 | * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN |
| 3894 | */ |
| 3895 | interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE; |
| 3896 | /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */ |
| 3897 | interrupt_cntl &= ~IH_REQ_NONSNOOP_EN; |
| 3898 | WREG32(INTERRUPT_CNTL, interrupt_cntl); |
| 3899 | |
| 3900 | WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8); |
| 3901 | rb_bufsz = drm_order(rdev->ih.ring_size / 4); |
| 3902 | |
| 3903 | ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE | |
| 3904 | IH_WPTR_OVERFLOW_CLEAR | |
| 3905 | (rb_bufsz << 1)); |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 3906 | |
| 3907 | if (rdev->wb.enabled) |
| 3908 | ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE; |
| 3909 | |
| 3910 | /* set the writeback address whether it's enabled or not */ |
| 3911 | WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC); |
| 3912 | WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3913 | |
| 3914 | WREG32(IH_RB_CNTL, ih_rb_cntl); |
| 3915 | |
| 3916 | /* set rptr, wptr to 0 */ |
| 3917 | WREG32(IH_RB_RPTR, 0); |
| 3918 | WREG32(IH_RB_WPTR, 0); |
| 3919 | |
| 3920 | /* Default settings for IH_CNTL (disabled at first) */ |
| 3921 | ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10); |
| 3922 | /* RPTR_REARM only works if msi's are enabled */ |
| 3923 | if (rdev->msi_enabled) |
| 3924 | ih_cntl |= RPTR_REARM; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3925 | WREG32(IH_CNTL, ih_cntl); |
| 3926 | |
| 3927 | /* force the active interrupt state to all disabled */ |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3928 | if (rdev->family >= CHIP_CEDAR) |
| 3929 | evergreen_disable_interrupt_state(rdev); |
| 3930 | else |
| 3931 | r600_disable_interrupt_state(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3932 | |
Dave Airlie | 2099810 | 2012-04-03 11:53:05 +0100 | [diff] [blame] | 3933 | /* at this point everything should be setup correctly to enable master */ |
| 3934 | pci_set_master(rdev->pdev); |
| 3935 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3936 | /* enable irqs */ |
| 3937 | r600_enable_interrupts(rdev); |
| 3938 | |
| 3939 | return ret; |
| 3940 | } |
| 3941 | |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 3942 | void r600_irq_suspend(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3943 | { |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 3944 | r600_irq_disable(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3945 | r600_rlc_stop(rdev); |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | void r600_irq_fini(struct radeon_device *rdev) |
| 3949 | { |
| 3950 | r600_irq_suspend(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3951 | r600_ih_ring_fini(rdev); |
| 3952 | } |
| 3953 | |
| 3954 | int r600_irq_set(struct radeon_device *rdev) |
| 3955 | { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3956 | u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE; |
| 3957 | u32 mode_int = 0; |
| 3958 | u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0; |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 3959 | u32 grbm_int_cntl = 0; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3960 | u32 hdmi0, hdmi1; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 3961 | u32 d1grph = 0, d2grph = 0; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3962 | u32 dma_cntl; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3963 | |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 3964 | if (!rdev->irq.installed) { |
Joe Perches | fce7d61 | 2010-10-30 21:08:30 +0000 | [diff] [blame] | 3965 | WARN(1, "Can't enable IRQ/MSI because no handler is installed\n"); |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 3966 | return -EINVAL; |
| 3967 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3968 | /* don't enable anything if the ih is disabled */ |
Jerome Glisse | 79c2bbc | 2010-01-15 14:44:38 +0100 | [diff] [blame] | 3969 | if (!rdev->ih.enabled) { |
| 3970 | r600_disable_interrupts(rdev); |
| 3971 | /* force the active interrupt state to all disabled */ |
| 3972 | r600_disable_interrupt_state(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3973 | return 0; |
Jerome Glisse | 79c2bbc | 2010-01-15 14:44:38 +0100 | [diff] [blame] | 3974 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 3975 | |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3976 | if (ASIC_IS_DCE3(rdev)) { |
| 3977 | hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3978 | hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3979 | hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3980 | hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3981 | if (ASIC_IS_DCE32(rdev)) { |
| 3982 | hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3983 | hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN; |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 3984 | hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
| 3985 | hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3986 | } else { |
| 3987 | hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3988 | hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3989 | } |
| 3990 | } else { |
| 3991 | hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3992 | hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN; |
| 3993 | hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 3994 | hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
| 3995 | hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3996 | } |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 3997 | dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 3998 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 3999 | if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4000 | DRM_DEBUG("r600_irq_set: sw int\n"); |
| 4001 | cp_int_cntl |= RB_INT_ENABLE; |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 4002 | cp_int_cntl |= TIME_STAMP_INT_ENABLE; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4003 | } |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 4004 | |
| 4005 | if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) { |
| 4006 | DRM_DEBUG("r600_irq_set: sw int dma\n"); |
| 4007 | dma_cntl |= TRAP_ENABLE; |
| 4008 | } |
| 4009 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4010 | if (rdev->irq.crtc_vblank_int[0] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 4011 | atomic_read(&rdev->irq.pflip[0])) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4012 | DRM_DEBUG("r600_irq_set: vblank 0\n"); |
| 4013 | mode_int |= D1MODE_VBLANK_INT_MASK; |
| 4014 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4015 | if (rdev->irq.crtc_vblank_int[1] || |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 4016 | atomic_read(&rdev->irq.pflip[1])) { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4017 | DRM_DEBUG("r600_irq_set: vblank 1\n"); |
| 4018 | mode_int |= D2MODE_VBLANK_INT_MASK; |
| 4019 | } |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4020 | if (rdev->irq.hpd[0]) { |
| 4021 | DRM_DEBUG("r600_irq_set: hpd 1\n"); |
| 4022 | hpd1 |= DC_HPDx_INT_EN; |
| 4023 | } |
| 4024 | if (rdev->irq.hpd[1]) { |
| 4025 | DRM_DEBUG("r600_irq_set: hpd 2\n"); |
| 4026 | hpd2 |= DC_HPDx_INT_EN; |
| 4027 | } |
| 4028 | if (rdev->irq.hpd[2]) { |
| 4029 | DRM_DEBUG("r600_irq_set: hpd 3\n"); |
| 4030 | hpd3 |= DC_HPDx_INT_EN; |
| 4031 | } |
| 4032 | if (rdev->irq.hpd[3]) { |
| 4033 | DRM_DEBUG("r600_irq_set: hpd 4\n"); |
| 4034 | hpd4 |= DC_HPDx_INT_EN; |
| 4035 | } |
| 4036 | if (rdev->irq.hpd[4]) { |
| 4037 | DRM_DEBUG("r600_irq_set: hpd 5\n"); |
| 4038 | hpd5 |= DC_HPDx_INT_EN; |
| 4039 | } |
| 4040 | if (rdev->irq.hpd[5]) { |
| 4041 | DRM_DEBUG("r600_irq_set: hpd 6\n"); |
| 4042 | hpd6 |= DC_HPDx_INT_EN; |
| 4043 | } |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4044 | if (rdev->irq.afmt[0]) { |
| 4045 | DRM_DEBUG("r600_irq_set: hdmi 0\n"); |
| 4046 | hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK; |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4047 | } |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4048 | if (rdev->irq.afmt[1]) { |
| 4049 | DRM_DEBUG("r600_irq_set: hdmi 0\n"); |
| 4050 | hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK; |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4051 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4052 | |
| 4053 | WREG32(CP_INT_CNTL, cp_int_cntl); |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 4054 | WREG32(DMA_CNTL, dma_cntl); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4055 | WREG32(DxMODE_INT_MASK, mode_int); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4056 | WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph); |
| 4057 | WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 4058 | WREG32(GRBM_INT_CNTL, grbm_int_cntl); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4059 | if (ASIC_IS_DCE3(rdev)) { |
| 4060 | WREG32(DC_HPD1_INT_CONTROL, hpd1); |
| 4061 | WREG32(DC_HPD2_INT_CONTROL, hpd2); |
| 4062 | WREG32(DC_HPD3_INT_CONTROL, hpd3); |
| 4063 | WREG32(DC_HPD4_INT_CONTROL, hpd4); |
| 4064 | if (ASIC_IS_DCE32(rdev)) { |
| 4065 | WREG32(DC_HPD5_INT_CONTROL, hpd5); |
| 4066 | WREG32(DC_HPD6_INT_CONTROL, hpd6); |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4067 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0); |
| 4068 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4069 | } else { |
| 4070 | WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0); |
| 4071 | WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4072 | } |
| 4073 | } else { |
| 4074 | WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1); |
| 4075 | WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2); |
| 4076 | WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4077 | WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0); |
| 4078 | WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4079 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4080 | |
| 4081 | return 0; |
| 4082 | } |
| 4083 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 4084 | static void r600_irq_ack(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4085 | { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4086 | u32 tmp; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4087 | |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4088 | if (ASIC_IS_DCE3(rdev)) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4089 | rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS); |
| 4090 | rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE); |
| 4091 | rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4092 | if (ASIC_IS_DCE32(rdev)) { |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4093 | rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0); |
| 4094 | rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4095 | } else { |
| 4096 | rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS); |
| 4097 | rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS); |
| 4098 | } |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4099 | } else { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4100 | rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS); |
| 4101 | rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE); |
| 4102 | rdev->irq.stat_regs.r600.disp_int_cont2 = 0; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4103 | rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS); |
| 4104 | rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4105 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4106 | rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS); |
| 4107 | rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4108 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4109 | if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED) |
| 4110 | WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR); |
| 4111 | if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED) |
| 4112 | WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR); |
| 4113 | if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4114 | WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4115 | if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4116 | WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4117 | if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4118 | WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4119 | if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4120 | WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4121 | if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4122 | if (ASIC_IS_DCE3(rdev)) { |
| 4123 | tmp = RREG32(DC_HPD1_INT_CONTROL); |
| 4124 | tmp |= DC_HPDx_INT_ACK; |
| 4125 | WREG32(DC_HPD1_INT_CONTROL, tmp); |
| 4126 | } else { |
| 4127 | tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL); |
| 4128 | tmp |= DC_HPDx_INT_ACK; |
| 4129 | WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp); |
| 4130 | } |
| 4131 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4132 | if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4133 | if (ASIC_IS_DCE3(rdev)) { |
| 4134 | tmp = RREG32(DC_HPD2_INT_CONTROL); |
| 4135 | tmp |= DC_HPDx_INT_ACK; |
| 4136 | WREG32(DC_HPD2_INT_CONTROL, tmp); |
| 4137 | } else { |
| 4138 | tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL); |
| 4139 | tmp |= DC_HPDx_INT_ACK; |
| 4140 | WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp); |
| 4141 | } |
| 4142 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4143 | if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4144 | if (ASIC_IS_DCE3(rdev)) { |
| 4145 | tmp = RREG32(DC_HPD3_INT_CONTROL); |
| 4146 | tmp |= DC_HPDx_INT_ACK; |
| 4147 | WREG32(DC_HPD3_INT_CONTROL, tmp); |
| 4148 | } else { |
| 4149 | tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL); |
| 4150 | tmp |= DC_HPDx_INT_ACK; |
| 4151 | WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp); |
| 4152 | } |
| 4153 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4154 | if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4155 | tmp = RREG32(DC_HPD4_INT_CONTROL); |
| 4156 | tmp |= DC_HPDx_INT_ACK; |
| 4157 | WREG32(DC_HPD4_INT_CONTROL, tmp); |
| 4158 | } |
| 4159 | if (ASIC_IS_DCE32(rdev)) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4160 | if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4161 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 4162 | tmp |= DC_HPDx_INT_ACK; |
| 4163 | WREG32(DC_HPD5_INT_CONTROL, tmp); |
| 4164 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4165 | if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) { |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4166 | tmp = RREG32(DC_HPD5_INT_CONTROL); |
| 4167 | tmp |= DC_HPDx_INT_ACK; |
| 4168 | WREG32(DC_HPD6_INT_CONTROL, tmp); |
| 4169 | } |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4170 | if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) { |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4171 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4172 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4173 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4174 | } |
| 4175 | if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) { |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4176 | tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4177 | tmp |= AFMT_AZ_FORMAT_WTRIG_ACK; |
Rafał Miłecki | c6543a6 | 2012-04-28 23:35:24 +0200 | [diff] [blame] | 4178 | WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp); |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4179 | } |
| 4180 | } else { |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4181 | if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) { |
| 4182 | tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL); |
| 4183 | tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK; |
| 4184 | WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp); |
| 4185 | } |
| 4186 | if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) { |
| 4187 | if (ASIC_IS_DCE3(rdev)) { |
| 4188 | tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL); |
| 4189 | tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK; |
| 4190 | WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp); |
| 4191 | } else { |
| 4192 | tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL); |
| 4193 | tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK; |
| 4194 | WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp); |
| 4195 | } |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4196 | } |
| 4197 | } |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | void r600_irq_disable(struct radeon_device *rdev) |
| 4201 | { |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4202 | r600_disable_interrupts(rdev); |
| 4203 | /* Wait and acknowledge irq */ |
| 4204 | mdelay(1); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4205 | r600_irq_ack(rdev); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4206 | r600_disable_interrupt_state(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4207 | } |
| 4208 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 4209 | static u32 r600_get_ih_wptr(struct radeon_device *rdev) |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4210 | { |
| 4211 | u32 wptr, tmp; |
| 4212 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 4213 | if (rdev->wb.enabled) |
Cédric Cano | 204ae24 | 2011-04-19 11:07:13 -0400 | [diff] [blame] | 4214 | 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] | 4215 | else |
| 4216 | wptr = RREG32(IH_RB_WPTR); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4217 | |
| 4218 | if (wptr & RB_OVERFLOW) { |
Jerome Glisse | 7924e5e | 2010-01-15 14:44:39 +0100 | [diff] [blame] | 4219 | /* When a ring buffer overflow happen start parsing interrupt |
| 4220 | * from the last not overwritten vector (wptr + 16). Hopefully |
| 4221 | * this should allow us to catchup. |
| 4222 | */ |
| 4223 | dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n", |
| 4224 | wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask); |
| 4225 | rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4226 | tmp = RREG32(IH_RB_CNTL); |
| 4227 | tmp |= IH_WPTR_OVERFLOW_CLEAR; |
| 4228 | WREG32(IH_RB_CNTL, tmp); |
| 4229 | } |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 4230 | return (wptr & rdev->ih.ptr_mask); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /* r600 IV Ring |
| 4234 | * Each IV ring entry is 128 bits: |
| 4235 | * [7:0] - interrupt source id |
| 4236 | * [31:8] - reserved |
| 4237 | * [59:32] - interrupt source data |
| 4238 | * [127:60] - reserved |
| 4239 | * |
| 4240 | * The basic interrupt vector entries |
| 4241 | * are decoded as follows: |
| 4242 | * src_id src_data description |
| 4243 | * 1 0 D1 Vblank |
| 4244 | * 1 1 D1 Vline |
| 4245 | * 5 0 D2 Vblank |
| 4246 | * 5 1 D2 Vline |
| 4247 | * 19 0 FP Hot plug detection A |
| 4248 | * 19 1 FP Hot plug detection B |
| 4249 | * 19 2 DAC A auto-detection |
| 4250 | * 19 3 DAC B auto-detection |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4251 | * 21 4 HDMI block A |
| 4252 | * 21 5 HDMI block B |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4253 | * 176 - CP_INT RB |
| 4254 | * 177 - CP_INT IB1 |
| 4255 | * 178 - CP_INT IB2 |
| 4256 | * 181 - EOP Interrupt |
| 4257 | * 233 - GUI Idle |
| 4258 | * |
| 4259 | * Note, these are based on r600 and may need to be |
| 4260 | * adjusted or added to on newer asics |
| 4261 | */ |
| 4262 | |
| 4263 | int r600_irq_process(struct radeon_device *rdev) |
| 4264 | { |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 4265 | u32 wptr; |
| 4266 | u32 rptr; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4267 | u32 src_id, src_data; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4268 | u32 ring_index; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4269 | bool queue_hotplug = false; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4270 | bool queue_hdmi = false; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4271 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 4272 | if (!rdev->ih.enabled || rdev->shutdown) |
Jerome Glisse | 79c2bbc | 2010-01-15 14:44:38 +0100 | [diff] [blame] | 4273 | return IRQ_NONE; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4274 | |
Benjamin Herrenschmidt | f6a5693 | 2011-07-13 06:28:22 +0000 | [diff] [blame] | 4275 | /* No MSIs, need a dummy read to flush PCI DMAs */ |
| 4276 | if (!rdev->msi_enabled) |
| 4277 | RREG32(IH_RB_WPTR); |
| 4278 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 4279 | wptr = r600_get_ih_wptr(rdev); |
Christian Koenig | c20dc36 | 2012-05-16 21:45:24 +0200 | [diff] [blame] | 4280 | |
| 4281 | restart_ih: |
| 4282 | /* is somebody else already processing irqs? */ |
| 4283 | if (atomic_xchg(&rdev->ih.lock, 1)) |
| 4284 | return IRQ_NONE; |
| 4285 | |
Dave Airlie | 682f1a5 | 2011-06-18 03:59:51 +0000 | [diff] [blame] | 4286 | rptr = rdev->ih.rptr; |
| 4287 | DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr); |
| 4288 | |
Benjamin Herrenschmidt | 964f664 | 2011-07-13 16:28:19 +1000 | [diff] [blame] | 4289 | /* Order reading of wptr vs. reading of IH ring data */ |
| 4290 | rmb(); |
| 4291 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4292 | /* display interrupts */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4293 | r600_irq_ack(rdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4294 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4295 | while (rptr != wptr) { |
| 4296 | /* wptr/rptr are in bytes! */ |
| 4297 | ring_index = rptr / 4; |
Cédric Cano | 4eace7f | 2011-02-11 19:45:38 -0500 | [diff] [blame] | 4298 | src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff; |
| 4299 | src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4300 | |
| 4301 | switch (src_id) { |
| 4302 | case 1: /* D1 vblank/vline */ |
| 4303 | switch (src_data) { |
| 4304 | case 0: /* D1 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4305 | if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4306 | if (rdev->irq.crtc_vblank_int[0]) { |
| 4307 | drm_handle_vblank(rdev->ddev, 0); |
| 4308 | rdev->pm.vblank_sync = true; |
| 4309 | wake_up(&rdev->irq.vblank_queue); |
| 4310 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 4311 | if (atomic_read(&rdev->irq.pflip[0])) |
Mario Kleiner | 3e4ea74 | 2010-11-21 10:59:02 -0500 | [diff] [blame] | 4312 | radeon_crtc_handle_flip(rdev, 0); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4313 | rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4314 | DRM_DEBUG("IH: D1 vblank\n"); |
| 4315 | } |
| 4316 | break; |
| 4317 | case 1: /* D1 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4318 | if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) { |
| 4319 | rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4320 | DRM_DEBUG("IH: D1 vline\n"); |
| 4321 | } |
| 4322 | break; |
| 4323 | default: |
Alex Deucher | b042589 | 2010-01-11 19:47:38 -0500 | [diff] [blame] | 4324 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4325 | break; |
| 4326 | } |
| 4327 | break; |
| 4328 | case 5: /* D2 vblank/vline */ |
| 4329 | switch (src_data) { |
| 4330 | case 0: /* D2 vblank */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4331 | if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4332 | if (rdev->irq.crtc_vblank_int[1]) { |
| 4333 | drm_handle_vblank(rdev->ddev, 1); |
| 4334 | rdev->pm.vblank_sync = true; |
| 4335 | wake_up(&rdev->irq.vblank_queue); |
| 4336 | } |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 4337 | if (atomic_read(&rdev->irq.pflip[1])) |
Mario Kleiner | 3e4ea74 | 2010-11-21 10:59:02 -0500 | [diff] [blame] | 4338 | radeon_crtc_handle_flip(rdev, 1); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4339 | rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4340 | DRM_DEBUG("IH: D2 vblank\n"); |
| 4341 | } |
| 4342 | break; |
| 4343 | case 1: /* D1 vline */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4344 | if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) { |
| 4345 | rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4346 | DRM_DEBUG("IH: D2 vline\n"); |
| 4347 | } |
| 4348 | break; |
| 4349 | default: |
Alex Deucher | b042589 | 2010-01-11 19:47:38 -0500 | [diff] [blame] | 4350 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4351 | break; |
| 4352 | } |
| 4353 | break; |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4354 | case 19: /* HPD/DAC hotplug */ |
| 4355 | switch (src_data) { |
| 4356 | case 0: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4357 | if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) { |
| 4358 | rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4359 | queue_hotplug = true; |
| 4360 | DRM_DEBUG("IH: HPD1\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4361 | } |
| 4362 | break; |
| 4363 | case 1: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4364 | if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) { |
| 4365 | rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4366 | queue_hotplug = true; |
| 4367 | DRM_DEBUG("IH: HPD2\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4368 | } |
| 4369 | break; |
| 4370 | case 4: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4371 | if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) { |
| 4372 | rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4373 | queue_hotplug = true; |
| 4374 | DRM_DEBUG("IH: HPD3\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4375 | } |
| 4376 | break; |
| 4377 | case 5: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4378 | if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) { |
| 4379 | rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4380 | queue_hotplug = true; |
| 4381 | DRM_DEBUG("IH: HPD4\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4382 | } |
| 4383 | break; |
| 4384 | case 10: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4385 | if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) { |
| 4386 | rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4387 | queue_hotplug = true; |
| 4388 | DRM_DEBUG("IH: HPD5\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4389 | } |
| 4390 | break; |
| 4391 | case 12: |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 4392 | if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) { |
| 4393 | rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT; |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4394 | queue_hotplug = true; |
| 4395 | DRM_DEBUG("IH: HPD6\n"); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4396 | } |
| 4397 | break; |
| 4398 | default: |
Alex Deucher | b042589 | 2010-01-11 19:47:38 -0500 | [diff] [blame] | 4399 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
Alex Deucher | e0df1ac | 2009-12-04 15:12:21 -0500 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | break; |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4403 | case 21: /* hdmi */ |
| 4404 | switch (src_data) { |
| 4405 | case 4: |
| 4406 | if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) { |
| 4407 | rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG; |
| 4408 | queue_hdmi = true; |
| 4409 | DRM_DEBUG("IH: HDMI0\n"); |
| 4410 | } |
| 4411 | break; |
| 4412 | case 5: |
| 4413 | if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) { |
| 4414 | rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG; |
| 4415 | queue_hdmi = true; |
| 4416 | DRM_DEBUG("IH: HDMI1\n"); |
| 4417 | } |
| 4418 | break; |
| 4419 | default: |
| 4420 | DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data); |
| 4421 | break; |
| 4422 | } |
Christian Koenig | f259493 | 2010-04-10 03:13:16 +0200 | [diff] [blame] | 4423 | break; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4424 | case 176: /* CP_INT in ring buffer */ |
| 4425 | case 177: /* CP_INT in IB1 */ |
| 4426 | case 178: /* CP_INT in IB2 */ |
| 4427 | DRM_DEBUG("IH: CP int: 0x%08x\n", src_data); |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 4428 | radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4429 | break; |
| 4430 | case 181: /* CP EOP event */ |
| 4431 | DRM_DEBUG("IH: CP EOP\n"); |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 4432 | radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4433 | break; |
Alex Deucher | 4d75658 | 2012-09-27 15:08:35 -0400 | [diff] [blame] | 4434 | case 224: /* DMA trap event */ |
| 4435 | DRM_DEBUG("IH: DMA trap\n"); |
| 4436 | radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX); |
| 4437 | break; |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 4438 | case 233: /* GUI IDLE */ |
Ilija Hadzic | 303c805 | 2011-06-07 14:54:48 -0400 | [diff] [blame] | 4439 | DRM_DEBUG("IH: GUI idle\n"); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 4440 | break; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4441 | default: |
Alex Deucher | b042589 | 2010-01-11 19:47:38 -0500 | [diff] [blame] | 4442 | DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4443 | break; |
| 4444 | } |
| 4445 | |
| 4446 | /* wptr/rptr are in bytes! */ |
Jerome Glisse | 0c45249 | 2010-01-15 14:44:37 +0100 | [diff] [blame] | 4447 | rptr += 16; |
| 4448 | rptr &= rdev->ih.ptr_mask; |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4449 | } |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 4450 | if (queue_hotplug) |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 4451 | schedule_work(&rdev->hotplug_work); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 4452 | if (queue_hdmi) |
| 4453 | schedule_work(&rdev->audio_work); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4454 | rdev->ih.rptr = rptr; |
| 4455 | WREG32(IH_RB_RPTR, rdev->ih.rptr); |
Christian Koenig | c20dc36 | 2012-05-16 21:45:24 +0200 | [diff] [blame] | 4456 | atomic_set(&rdev->ih.lock, 0); |
| 4457 | |
| 4458 | /* make sure wptr hasn't changed while processing */ |
| 4459 | wptr = r600_get_ih_wptr(rdev); |
| 4460 | if (wptr != rptr) |
| 4461 | goto restart_ih; |
| 4462 | |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 4463 | return IRQ_HANDLED; |
| 4464 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 4465 | |
| 4466 | /* |
| 4467 | * Debugfs info |
| 4468 | */ |
| 4469 | #if defined(CONFIG_DEBUG_FS) |
| 4470 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 4471 | static int r600_debugfs_mc_info(struct seq_file *m, void *data) |
| 4472 | { |
| 4473 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 4474 | struct drm_device *dev = node->minor->dev; |
| 4475 | struct radeon_device *rdev = dev->dev_private; |
| 4476 | |
| 4477 | DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS); |
| 4478 | DREG32_SYS(m, rdev, VM_L2_STATUS); |
| 4479 | return 0; |
| 4480 | } |
| 4481 | |
| 4482 | static struct drm_info_list r600_mc_info_list[] = { |
| 4483 | {"r600_mc_info", r600_debugfs_mc_info, 0, NULL}, |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 4484 | }; |
| 4485 | #endif |
| 4486 | |
| 4487 | int r600_debugfs_mc_info_init(struct radeon_device *rdev) |
| 4488 | { |
| 4489 | #if defined(CONFIG_DEBUG_FS) |
| 4490 | return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list)); |
| 4491 | #else |
| 4492 | return 0; |
| 4493 | #endif |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4494 | } |
Jerome Glisse | 062b389 | 2010-02-04 20:36:39 +0100 | [diff] [blame] | 4495 | |
| 4496 | /** |
| 4497 | * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl |
| 4498 | * rdev: radeon device structure |
| 4499 | * bo: buffer object struct which userspace is waiting for idle |
| 4500 | * |
| 4501 | * Some R6XX/R7XX doesn't seems to take into account HDP flush performed |
| 4502 | * through ring buffer, this leads to corruption in rendering, see |
| 4503 | * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we |
| 4504 | * directly perform HDP flush by writing register through MMIO. |
| 4505 | */ |
| 4506 | void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo) |
| 4507 | { |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 4508 | /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read |
Alex Deucher | f3886f8 | 2010-12-08 10:05:34 -0500 | [diff] [blame] | 4509 | * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL. |
| 4510 | * This seems to cause problems on some AGP cards. Just use the old |
| 4511 | * method for them. |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 4512 | */ |
Alex Deucher | e488459 | 2010-09-27 10:57:10 -0400 | [diff] [blame] | 4513 | if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) && |
Alex Deucher | f3886f8 | 2010-12-08 10:05:34 -0500 | [diff] [blame] | 4514 | rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) { |
Alex Deucher | 87cbf8f | 2010-08-27 13:59:54 -0400 | [diff] [blame] | 4515 | void __iomem *ptr = (void *)rdev->vram_scratch.ptr; |
Alex Deucher | 812d046 | 2010-07-26 18:51:53 -0400 | [diff] [blame] | 4516 | u32 tmp; |
| 4517 | |
| 4518 | WREG32(HDP_DEBUG1, 0); |
| 4519 | tmp = readl((void __iomem *)ptr); |
| 4520 | } else |
| 4521 | WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1); |
Jerome Glisse | 062b389 | 2010-02-04 20:36:39 +0100 | [diff] [blame] | 4522 | } |
Alex Deucher | 3313e3d | 2011-01-06 18:49:34 -0500 | [diff] [blame] | 4523 | |
| 4524 | void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes) |
| 4525 | { |
| 4526 | u32 link_width_cntl, mask, target_reg; |
| 4527 | |
| 4528 | if (rdev->flags & RADEON_IS_IGP) |
| 4529 | return; |
| 4530 | |
| 4531 | if (!(rdev->flags & RADEON_IS_PCIE)) |
| 4532 | return; |
| 4533 | |
| 4534 | /* x2 cards have a special sequence */ |
| 4535 | if (ASIC_IS_X2(rdev)) |
| 4536 | return; |
| 4537 | |
| 4538 | /* FIXME wait for idle */ |
| 4539 | |
| 4540 | switch (lanes) { |
| 4541 | case 0: |
| 4542 | mask = RADEON_PCIE_LC_LINK_WIDTH_X0; |
| 4543 | break; |
| 4544 | case 1: |
| 4545 | mask = RADEON_PCIE_LC_LINK_WIDTH_X1; |
| 4546 | break; |
| 4547 | case 2: |
| 4548 | mask = RADEON_PCIE_LC_LINK_WIDTH_X2; |
| 4549 | break; |
| 4550 | case 4: |
| 4551 | mask = RADEON_PCIE_LC_LINK_WIDTH_X4; |
| 4552 | break; |
| 4553 | case 8: |
| 4554 | mask = RADEON_PCIE_LC_LINK_WIDTH_X8; |
| 4555 | break; |
| 4556 | case 12: |
| 4557 | mask = RADEON_PCIE_LC_LINK_WIDTH_X12; |
| 4558 | break; |
| 4559 | case 16: |
| 4560 | default: |
| 4561 | mask = RADEON_PCIE_LC_LINK_WIDTH_X16; |
| 4562 | break; |
| 4563 | } |
| 4564 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4565 | link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL); |
Alex Deucher | 3313e3d | 2011-01-06 18:49:34 -0500 | [diff] [blame] | 4566 | |
| 4567 | if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) == |
| 4568 | (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT)) |
| 4569 | return; |
| 4570 | |
| 4571 | if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS) |
| 4572 | return; |
| 4573 | |
| 4574 | link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK | |
| 4575 | RADEON_PCIE_LC_RECONFIG_NOW | |
| 4576 | R600_PCIE_LC_RENEGOTIATE_EN | |
| 4577 | R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE); |
| 4578 | link_width_cntl |= mask; |
| 4579 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4580 | WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
Alex Deucher | 3313e3d | 2011-01-06 18:49:34 -0500 | [diff] [blame] | 4581 | |
| 4582 | /* some northbridges can renegotiate the link rather than requiring |
| 4583 | * a complete re-config. |
| 4584 | * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.) |
| 4585 | */ |
| 4586 | if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT) |
| 4587 | link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT; |
| 4588 | else |
| 4589 | link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE; |
| 4590 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4591 | WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl | |
Alex Deucher | 3313e3d | 2011-01-06 18:49:34 -0500 | [diff] [blame] | 4592 | RADEON_PCIE_LC_RECONFIG_NOW)); |
| 4593 | |
| 4594 | if (rdev->family >= CHIP_RV770) |
| 4595 | target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX; |
| 4596 | else |
| 4597 | target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX; |
| 4598 | |
| 4599 | /* wait for lane set to complete */ |
| 4600 | link_width_cntl = RREG32(target_reg); |
| 4601 | while (link_width_cntl == 0xffffffff) |
| 4602 | link_width_cntl = RREG32(target_reg); |
| 4603 | |
| 4604 | } |
| 4605 | |
| 4606 | int r600_get_pcie_lanes(struct radeon_device *rdev) |
| 4607 | { |
| 4608 | u32 link_width_cntl; |
| 4609 | |
| 4610 | if (rdev->flags & RADEON_IS_IGP) |
| 4611 | return 0; |
| 4612 | |
| 4613 | if (!(rdev->flags & RADEON_IS_PCIE)) |
| 4614 | return 0; |
| 4615 | |
| 4616 | /* x2 cards have a special sequence */ |
| 4617 | if (ASIC_IS_X2(rdev)) |
| 4618 | return 0; |
| 4619 | |
| 4620 | /* FIXME wait for idle */ |
| 4621 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4622 | link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL); |
Alex Deucher | 3313e3d | 2011-01-06 18:49:34 -0500 | [diff] [blame] | 4623 | |
| 4624 | switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) { |
| 4625 | case RADEON_PCIE_LC_LINK_WIDTH_X0: |
| 4626 | return 0; |
| 4627 | case RADEON_PCIE_LC_LINK_WIDTH_X1: |
| 4628 | return 1; |
| 4629 | case RADEON_PCIE_LC_LINK_WIDTH_X2: |
| 4630 | return 2; |
| 4631 | case RADEON_PCIE_LC_LINK_WIDTH_X4: |
| 4632 | return 4; |
| 4633 | case RADEON_PCIE_LC_LINK_WIDTH_X8: |
| 4634 | return 8; |
| 4635 | case RADEON_PCIE_LC_LINK_WIDTH_X16: |
| 4636 | default: |
| 4637 | return 16; |
| 4638 | } |
| 4639 | } |
| 4640 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4641 | static void r600_pcie_gen2_enable(struct radeon_device *rdev) |
| 4642 | { |
| 4643 | u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp; |
| 4644 | u16 link_cntl2; |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 4645 | u32 mask; |
| 4646 | int ret; |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4647 | |
Alex Deucher | d42dd57 | 2011-01-12 20:05:11 -0500 | [diff] [blame] | 4648 | if (radeon_pcie_gen2 == 0) |
| 4649 | return; |
| 4650 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4651 | if (rdev->flags & RADEON_IS_IGP) |
| 4652 | return; |
| 4653 | |
| 4654 | if (!(rdev->flags & RADEON_IS_PCIE)) |
| 4655 | return; |
| 4656 | |
| 4657 | /* x2 cards have a special sequence */ |
| 4658 | if (ASIC_IS_X2(rdev)) |
| 4659 | return; |
| 4660 | |
| 4661 | /* only RV6xx+ chips are supported */ |
| 4662 | if (rdev->family <= CHIP_R600) |
| 4663 | return; |
| 4664 | |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 4665 | ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask); |
| 4666 | if (ret != 0) |
| 4667 | return; |
| 4668 | |
| 4669 | if (!(mask & DRM_PCIE_SPEED_50)) |
| 4670 | return; |
| 4671 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4672 | speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); |
Alex Deucher | 3691fee | 2012-10-08 17:46:27 -0400 | [diff] [blame] | 4673 | if (speed_cntl & LC_CURRENT_DATA_RATE) { |
| 4674 | DRM_INFO("PCIE gen 2 link speeds already enabled\n"); |
| 4675 | return; |
| 4676 | } |
| 4677 | |
Dave Airlie | 197bbb3 | 2012-06-27 08:35:54 +0100 | [diff] [blame] | 4678 | DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n"); |
| 4679 | |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4680 | /* 55 nm r6xx asics */ |
| 4681 | if ((rdev->family == CHIP_RV670) || |
| 4682 | (rdev->family == CHIP_RV620) || |
| 4683 | (rdev->family == CHIP_RV635)) { |
| 4684 | /* advertise upconfig capability */ |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4685 | link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4686 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4687 | WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
| 4688 | link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4689 | if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) { |
| 4690 | lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT; |
| 4691 | link_width_cntl &= ~(LC_LINK_WIDTH_MASK | |
| 4692 | LC_RECONFIG_ARC_MISSING_ESCAPE); |
| 4693 | link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4694 | WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4695 | } else { |
| 4696 | link_width_cntl |= LC_UPCONFIGURE_DIS; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4697 | WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4701 | speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4702 | if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) && |
| 4703 | (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) { |
| 4704 | |
| 4705 | /* 55 nm r6xx asics */ |
| 4706 | if ((rdev->family == CHIP_RV670) || |
| 4707 | (rdev->family == CHIP_RV620) || |
| 4708 | (rdev->family == CHIP_RV635)) { |
| 4709 | WREG32(MM_CFGREGS_CNTL, 0x8); |
| 4710 | link_cntl2 = RREG32(0x4088); |
| 4711 | WREG32(MM_CFGREGS_CNTL, 0); |
| 4712 | /* not supported yet */ |
| 4713 | if (link_cntl2 & SELECTABLE_DEEMPHASIS) |
| 4714 | return; |
| 4715 | } |
| 4716 | |
| 4717 | speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK; |
| 4718 | speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT); |
| 4719 | speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK; |
| 4720 | speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE; |
| 4721 | speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4722 | WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4723 | |
| 4724 | tmp = RREG32(0x541c); |
| 4725 | WREG32(0x541c, tmp | 0x8); |
| 4726 | WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN); |
| 4727 | link_cntl2 = RREG16(0x4088); |
| 4728 | link_cntl2 &= ~TARGET_LINK_SPEED_MASK; |
| 4729 | link_cntl2 |= 0x2; |
| 4730 | WREG16(0x4088, link_cntl2); |
| 4731 | WREG32(MM_CFGREGS_CNTL, 0); |
| 4732 | |
| 4733 | if ((rdev->family == CHIP_RV670) || |
| 4734 | (rdev->family == CHIP_RV620) || |
| 4735 | (rdev->family == CHIP_RV635)) { |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4736 | training_cntl = RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4737 | training_cntl &= ~LC_POINT_7_PLUS_EN; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4738 | WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL, training_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4739 | } else { |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4740 | speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4741 | speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4742 | WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4743 | } |
| 4744 | |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4745 | speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4746 | speed_cntl |= LC_GEN2_EN_STRAP; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4747 | WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4748 | |
| 4749 | } else { |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4750 | link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4751 | /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */ |
| 4752 | if (1) |
| 4753 | link_width_cntl |= LC_UPCONFIGURE_DIS; |
| 4754 | else |
| 4755 | link_width_cntl &= ~LC_UPCONFIGURE_DIS; |
Alex Deucher | 492d2b6 | 2012-10-25 16:06:59 -0400 | [diff] [blame^] | 4756 | WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl); |
Alex Deucher | 9e46a48 | 2011-01-06 18:49:35 -0500 | [diff] [blame] | 4757 | } |
| 4758 | } |
Marek Olšák | 6759a0a | 2012-08-09 16:34:17 +0200 | [diff] [blame] | 4759 | |
| 4760 | /** |
Alex Deucher | d041889 | 2013-01-24 10:35:23 -0500 | [diff] [blame] | 4761 | * r600_get_gpu_clock_counter - return GPU clock counter snapshot |
Marek Olšák | 6759a0a | 2012-08-09 16:34:17 +0200 | [diff] [blame] | 4762 | * |
| 4763 | * @rdev: radeon_device pointer |
| 4764 | * |
| 4765 | * Fetches a GPU clock counter snapshot (R6xx-cayman). |
| 4766 | * Returns the 64 bit clock counter snapshot. |
| 4767 | */ |
Alex Deucher | d041889 | 2013-01-24 10:35:23 -0500 | [diff] [blame] | 4768 | uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev) |
Marek Olšák | 6759a0a | 2012-08-09 16:34:17 +0200 | [diff] [blame] | 4769 | { |
| 4770 | uint64_t clock; |
| 4771 | |
| 4772 | mutex_lock(&rdev->gpu_clock_mutex); |
| 4773 | WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1); |
| 4774 | clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) | |
| 4775 | ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL); |
| 4776 | mutex_unlock(&rdev->gpu_clock_mutex); |
| 4777 | return clock; |
| 4778 | } |