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