blob: f388a1d73b635f6e385e9defbc34d0b022538c4d [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Jerome Glisse3ce0a232009-09-08 10:10:24 +100029#include <linux/seq_file.h>
30#include <linux/firmware.h>
31#include <linux/platform_device.h>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040032#include <linux/module.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033#include "drmP.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100034#include "radeon_drm.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020035#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000036#include "radeon_asic.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100037#include "radeon_mode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100038#include "r600d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100039#include "atom.h"
Jerome Glissed39c3b82009-09-28 18:34:43 +020040#include "avivod.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020041
Jerome Glisse3ce0a232009-09-08 10:10:24 +100042#define PFP_UCODE_SIZE 576
43#define PM4_UCODE_SIZE 1792
Alex Deucherd8f60cf2009-12-01 13:43:46 -050044#define RLC_UCODE_SIZE 768
Jerome Glisse3ce0a232009-09-08 10:10:24 +100045#define R700_PFP_UCODE_SIZE 848
46#define R700_PM4_UCODE_SIZE 1360
Alex Deucherd8f60cf2009-12-01 13:43:46 -050047#define R700_RLC_UCODE_SIZE 1024
Alex Deucherfe251e22010-03-24 13:36:43 -040048#define EVERGREEN_PFP_UCODE_SIZE 1120
49#define EVERGREEN_PM4_UCODE_SIZE 1376
Alex Deucher45f9a392010-03-24 13:55:51 -040050#define EVERGREEN_RLC_UCODE_SIZE 768
Alex Deucher12727802011-03-02 20:07:32 -050051#define CAYMAN_RLC_UCODE_SIZE 1024
Alex Deucherc420c742012-03-20 17:18:39 -040052#define ARUBA_RLC_UCODE_SIZE 1536
Jerome Glisse3ce0a232009-09-08 10:10:24 +100053
54/* Firmware Names */
55MODULE_FIRMWARE("radeon/R600_pfp.bin");
56MODULE_FIRMWARE("radeon/R600_me.bin");
57MODULE_FIRMWARE("radeon/RV610_pfp.bin");
58MODULE_FIRMWARE("radeon/RV610_me.bin");
59MODULE_FIRMWARE("radeon/RV630_pfp.bin");
60MODULE_FIRMWARE("radeon/RV630_me.bin");
61MODULE_FIRMWARE("radeon/RV620_pfp.bin");
62MODULE_FIRMWARE("radeon/RV620_me.bin");
63MODULE_FIRMWARE("radeon/RV635_pfp.bin");
64MODULE_FIRMWARE("radeon/RV635_me.bin");
65MODULE_FIRMWARE("radeon/RV670_pfp.bin");
66MODULE_FIRMWARE("radeon/RV670_me.bin");
67MODULE_FIRMWARE("radeon/RS780_pfp.bin");
68MODULE_FIRMWARE("radeon/RS780_me.bin");
69MODULE_FIRMWARE("radeon/RV770_pfp.bin");
70MODULE_FIRMWARE("radeon/RV770_me.bin");
71MODULE_FIRMWARE("radeon/RV730_pfp.bin");
72MODULE_FIRMWARE("radeon/RV730_me.bin");
73MODULE_FIRMWARE("radeon/RV710_pfp.bin");
74MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050075MODULE_FIRMWARE("radeon/R600_rlc.bin");
76MODULE_FIRMWARE("radeon/R700_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040077MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
78MODULE_FIRMWARE("radeon/CEDAR_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040079MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040080MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
81MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040082MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040083MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
84MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040085MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
Dave Airliea7433742010-04-09 15:31:09 +100086MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040087MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040088MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
Alex Deucher439bd6c2010-11-22 17:56:31 -050089MODULE_FIRMWARE("radeon/PALM_pfp.bin");
90MODULE_FIRMWARE("radeon/PALM_me.bin");
91MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
Alex Deucherd5c5a722011-05-31 15:42:48 -040092MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
93MODULE_FIRMWARE("radeon/SUMO_me.bin");
94MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
95MODULE_FIRMWARE("radeon/SUMO2_me.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100096
97int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020098
Jerome Glisse1a029b72009-10-06 19:04:30 +020099/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200100int r600_mc_wait_for_idle(struct radeon_device *rdev);
101void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000102void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -0400103void r600_irq_disable(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -0500104static void r600_pcie_gen2_enable(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200105
Alex Deucher21a81222010-07-02 12:58:16 -0400106/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500107int rv6xx_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400108{
109 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
110 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -0500111 int actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -0400112
Alex Deucher20d391d2011-02-01 16:12:34 -0500113 if (temp & 0x100)
114 actual_temp -= 256;
115
116 return actual_temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400117}
118
Alex Deucherce8f5372010-05-07 15:10:16 -0400119void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400120{
121 int i;
122
Alex Deucherce8f5372010-05-07 15:10:16 -0400123 rdev->pm.dynpm_can_upclock = true;
124 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400125
126 /* power state array is low to high, default is first */
127 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
128 int min_power_state_index = 0;
129
130 if (rdev->pm.num_power_states > 2)
131 min_power_state_index = 1;
132
Alex Deucherce8f5372010-05-07 15:10:16 -0400133 switch (rdev->pm.dynpm_planned_action) {
134 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400135 rdev->pm.requested_power_state_index = min_power_state_index;
136 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400137 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400138 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400139 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400140 if (rdev->pm.current_power_state_index == min_power_state_index) {
141 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400142 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400143 } else {
144 if (rdev->pm.active_crtc_count > 1) {
145 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400146 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400147 continue;
148 else if (i >= rdev->pm.current_power_state_index) {
149 rdev->pm.requested_power_state_index =
150 rdev->pm.current_power_state_index;
151 break;
152 } else {
153 rdev->pm.requested_power_state_index = i;
154 break;
155 }
156 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400157 } else {
158 if (rdev->pm.current_power_state_index == 0)
159 rdev->pm.requested_power_state_index =
160 rdev->pm.num_power_states - 1;
161 else
162 rdev->pm.requested_power_state_index =
163 rdev->pm.current_power_state_index - 1;
164 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400165 }
166 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400167 /* don't use the power state if crtcs are active and no display flag is set */
168 if ((rdev->pm.active_crtc_count > 0) &&
169 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
170 clock_info[rdev->pm.requested_clock_mode_index].flags &
171 RADEON_PM_MODE_NO_DISPLAY)) {
172 rdev->pm.requested_power_state_index++;
173 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400174 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400175 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400176 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
177 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400178 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400179 } else {
180 if (rdev->pm.active_crtc_count > 1) {
181 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400182 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400183 continue;
184 else if (i <= rdev->pm.current_power_state_index) {
185 rdev->pm.requested_power_state_index =
186 rdev->pm.current_power_state_index;
187 break;
188 } else {
189 rdev->pm.requested_power_state_index = i;
190 break;
191 }
192 }
193 } else
194 rdev->pm.requested_power_state_index =
195 rdev->pm.current_power_state_index + 1;
196 }
197 rdev->pm.requested_clock_mode_index = 0;
198 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400199 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400200 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
201 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400202 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400203 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400204 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400205 default:
206 DRM_ERROR("Requested mode for not defined action\n");
207 return;
208 }
209 } else {
210 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
211 /* for now just select the first power state and switch between clock modes */
212 /* power state array is low to high, default is first (0) */
213 if (rdev->pm.active_crtc_count > 1) {
214 rdev->pm.requested_power_state_index = -1;
215 /* start at 1 as we don't want the default mode */
216 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400217 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400218 continue;
219 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
220 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
221 rdev->pm.requested_power_state_index = i;
222 break;
223 }
224 }
225 /* if nothing selected, grab the default state. */
226 if (rdev->pm.requested_power_state_index == -1)
227 rdev->pm.requested_power_state_index = 0;
228 } else
229 rdev->pm.requested_power_state_index = 1;
230
Alex Deucherce8f5372010-05-07 15:10:16 -0400231 switch (rdev->pm.dynpm_planned_action) {
232 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400233 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400234 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400235 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400236 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400237 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
238 if (rdev->pm.current_clock_mode_index == 0) {
239 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400240 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400241 } else
242 rdev->pm.requested_clock_mode_index =
243 rdev->pm.current_clock_mode_index - 1;
244 } else {
245 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400246 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400247 }
Alex Deucherd7311172010-05-03 01:13:14 -0400248 /* don't use the power state if crtcs are active and no display flag is set */
249 if ((rdev->pm.active_crtc_count > 0) &&
250 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
251 clock_info[rdev->pm.requested_clock_mode_index].flags &
252 RADEON_PM_MODE_NO_DISPLAY)) {
253 rdev->pm.requested_clock_mode_index++;
254 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400255 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400256 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400257 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
258 if (rdev->pm.current_clock_mode_index ==
259 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
260 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400261 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400262 } else
263 rdev->pm.requested_clock_mode_index =
264 rdev->pm.current_clock_mode_index + 1;
265 } else {
266 rdev->pm.requested_clock_mode_index =
267 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400268 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400269 }
270 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400271 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400272 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
273 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400274 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400275 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400276 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400277 default:
278 DRM_ERROR("Requested mode for not defined action\n");
279 return;
280 }
281 }
282
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000283 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400284 rdev->pm.power_state[rdev->pm.requested_power_state_index].
285 clock_info[rdev->pm.requested_clock_mode_index].sclk,
286 rdev->pm.power_state[rdev->pm.requested_power_state_index].
287 clock_info[rdev->pm.requested_clock_mode_index].mclk,
288 rdev->pm.power_state[rdev->pm.requested_power_state_index].
289 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400290}
291
Alex Deucherce8f5372010-05-07 15:10:16 -0400292void rs780_pm_init_profile(struct radeon_device *rdev)
293{
294 if (rdev->pm.num_power_states == 2) {
295 /* default */
296 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
297 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
298 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
299 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
300 /* low sh */
301 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
302 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
303 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
304 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400305 /* mid sh */
306 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
307 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
308 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
309 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400310 /* high sh */
311 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
312 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
313 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
314 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
315 /* low mh */
316 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
317 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
318 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
319 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400320 /* mid mh */
321 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
322 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
323 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400325 /* high mh */
326 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
327 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
328 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
330 } else if (rdev->pm.num_power_states == 3) {
331 /* default */
332 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
333 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
334 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
335 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
336 /* low sh */
337 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
338 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
339 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
340 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400341 /* mid sh */
342 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
343 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
344 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
345 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400346 /* high sh */
347 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
348 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
349 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
350 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
351 /* low mh */
352 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
353 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
354 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
355 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400356 /* mid mh */
357 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
358 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
359 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
360 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400361 /* high mh */
362 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
363 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
364 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
365 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
366 } else {
367 /* default */
368 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
369 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
370 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
371 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
372 /* low sh */
373 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
374 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
375 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
376 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400377 /* mid sh */
378 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
379 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
380 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
381 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400382 /* high sh */
383 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
384 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
385 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
386 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
387 /* low mh */
388 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
389 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
390 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
391 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400392 /* mid mh */
393 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
394 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
395 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
396 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400397 /* high mh */
398 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
399 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
400 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
401 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
402 }
403}
404
405void r600_pm_init_profile(struct radeon_device *rdev)
406{
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400407 int idx;
408
Alex Deucherce8f5372010-05-07 15:10:16 -0400409 if (rdev->family == CHIP_R600) {
410 /* XXX */
411 /* default */
412 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
413 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
414 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400415 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400416 /* low sh */
417 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
418 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
419 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400420 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400421 /* mid sh */
422 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
423 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
424 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
425 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400426 /* high sh */
427 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
428 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
429 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400430 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400431 /* low mh */
432 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
433 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400435 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400436 /* mid mh */
437 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
438 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
440 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400441 /* high mh */
442 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
443 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400445 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400446 } else {
447 if (rdev->pm.num_power_states < 4) {
448 /* default */
449 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
450 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
451 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
452 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
453 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400454 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
455 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
456 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400457 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
458 /* mid sh */
459 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
460 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
461 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
462 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400463 /* high sh */
464 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
465 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
466 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
467 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
468 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400469 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
470 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400471 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400472 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
473 /* low mh */
474 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
475 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
476 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
477 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400478 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400479 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
480 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
481 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
482 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
483 } else {
484 /* default */
485 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
486 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
487 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
488 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
489 /* low sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400490 if (rdev->flags & RADEON_IS_MOBILITY)
491 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
492 else
493 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
494 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
495 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
496 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
497 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400498 /* mid sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400499 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
500 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
501 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
502 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400503 /* high sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400504 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
505 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
506 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
Alex Deucher4bff5172010-05-17 19:41:26 -0400507 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
508 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
509 /* low mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400510 if (rdev->flags & RADEON_IS_MOBILITY)
511 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
512 else
513 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
514 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
515 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
516 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
517 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400518 /* mid mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400519 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
520 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
521 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
522 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400523 /* high mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400524 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
525 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
526 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
Alex Deucherce8f5372010-05-07 15:10:16 -0400527 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
528 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
529 }
530 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400531}
532
Alex Deucher49e02b72010-04-23 17:57:27 -0400533void r600_pm_misc(struct radeon_device *rdev)
534{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400535 int req_ps_idx = rdev->pm.requested_power_state_index;
536 int req_cm_idx = rdev->pm.requested_clock_mode_index;
537 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
538 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400539
Alex Deucher4d601732010-06-07 18:15:18 -0400540 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
Alex Deuchera377e182011-06-20 13:00:31 -0400541 /* 0xff01 is a flag rather then an actual voltage */
542 if (voltage->voltage == 0xff01)
543 return;
Alex Deucher4d601732010-06-07 18:15:18 -0400544 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400545 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400546 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000547 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400548 }
549 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400550}
551
Alex Deucherdef9ba92010-04-22 12:39:58 -0400552bool r600_gui_idle(struct radeon_device *rdev)
553{
554 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
555 return false;
556 else
557 return true;
558}
559
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500560/* hpd for digital panel detect/disconnect */
561bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
562{
563 bool connected = false;
564
565 if (ASIC_IS_DCE3(rdev)) {
566 switch (hpd) {
567 case RADEON_HPD_1:
568 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
569 connected = true;
570 break;
571 case RADEON_HPD_2:
572 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
573 connected = true;
574 break;
575 case RADEON_HPD_3:
576 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
577 connected = true;
578 break;
579 case RADEON_HPD_4:
580 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
581 connected = true;
582 break;
583 /* DCE 3.2 */
584 case RADEON_HPD_5:
585 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
586 connected = true;
587 break;
588 case RADEON_HPD_6:
589 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
590 connected = true;
591 break;
592 default:
593 break;
594 }
595 } else {
596 switch (hpd) {
597 case RADEON_HPD_1:
598 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
599 connected = true;
600 break;
601 case RADEON_HPD_2:
602 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
603 connected = true;
604 break;
605 case RADEON_HPD_3:
606 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
607 connected = true;
608 break;
609 default:
610 break;
611 }
612 }
613 return connected;
614}
615
616void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500617 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500618{
619 u32 tmp;
620 bool connected = r600_hpd_sense(rdev, hpd);
621
622 if (ASIC_IS_DCE3(rdev)) {
623 switch (hpd) {
624 case RADEON_HPD_1:
625 tmp = RREG32(DC_HPD1_INT_CONTROL);
626 if (connected)
627 tmp &= ~DC_HPDx_INT_POLARITY;
628 else
629 tmp |= DC_HPDx_INT_POLARITY;
630 WREG32(DC_HPD1_INT_CONTROL, tmp);
631 break;
632 case RADEON_HPD_2:
633 tmp = RREG32(DC_HPD2_INT_CONTROL);
634 if (connected)
635 tmp &= ~DC_HPDx_INT_POLARITY;
636 else
637 tmp |= DC_HPDx_INT_POLARITY;
638 WREG32(DC_HPD2_INT_CONTROL, tmp);
639 break;
640 case RADEON_HPD_3:
641 tmp = RREG32(DC_HPD3_INT_CONTROL);
642 if (connected)
643 tmp &= ~DC_HPDx_INT_POLARITY;
644 else
645 tmp |= DC_HPDx_INT_POLARITY;
646 WREG32(DC_HPD3_INT_CONTROL, tmp);
647 break;
648 case RADEON_HPD_4:
649 tmp = RREG32(DC_HPD4_INT_CONTROL);
650 if (connected)
651 tmp &= ~DC_HPDx_INT_POLARITY;
652 else
653 tmp |= DC_HPDx_INT_POLARITY;
654 WREG32(DC_HPD4_INT_CONTROL, tmp);
655 break;
656 case RADEON_HPD_5:
657 tmp = RREG32(DC_HPD5_INT_CONTROL);
658 if (connected)
659 tmp &= ~DC_HPDx_INT_POLARITY;
660 else
661 tmp |= DC_HPDx_INT_POLARITY;
662 WREG32(DC_HPD5_INT_CONTROL, tmp);
663 break;
664 /* DCE 3.2 */
665 case RADEON_HPD_6:
666 tmp = RREG32(DC_HPD6_INT_CONTROL);
667 if (connected)
668 tmp &= ~DC_HPDx_INT_POLARITY;
669 else
670 tmp |= DC_HPDx_INT_POLARITY;
671 WREG32(DC_HPD6_INT_CONTROL, tmp);
672 break;
673 default:
674 break;
675 }
676 } else {
677 switch (hpd) {
678 case RADEON_HPD_1:
679 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
680 if (connected)
681 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
682 else
683 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
684 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
685 break;
686 case RADEON_HPD_2:
687 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
688 if (connected)
689 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
690 else
691 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
692 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
693 break;
694 case RADEON_HPD_3:
695 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
696 if (connected)
697 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
698 else
699 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
700 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
701 break;
702 default:
703 break;
704 }
705 }
706}
707
708void r600_hpd_init(struct radeon_device *rdev)
709{
710 struct drm_device *dev = rdev->ddev;
711 struct drm_connector *connector;
712
Alex Deucher64912e92011-11-03 11:21:39 -0400713 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
714 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500715
Jerome Glisse455c89b2012-05-04 11:06:22 -0400716 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
717 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
718 /* don't try to enable hpd on eDP or LVDS avoid breaking the
719 * aux dp channel on imac and help (but not completely fix)
720 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
721 */
722 continue;
723 }
Alex Deucher64912e92011-11-03 11:21:39 -0400724 if (ASIC_IS_DCE3(rdev)) {
725 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
726 if (ASIC_IS_DCE32(rdev))
727 tmp |= DC_HPDx_EN;
728
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500729 switch (radeon_connector->hpd.hpd) {
730 case RADEON_HPD_1:
731 WREG32(DC_HPD1_CONTROL, tmp);
732 rdev->irq.hpd[0] = true;
733 break;
734 case RADEON_HPD_2:
735 WREG32(DC_HPD2_CONTROL, tmp);
736 rdev->irq.hpd[1] = true;
737 break;
738 case RADEON_HPD_3:
739 WREG32(DC_HPD3_CONTROL, tmp);
740 rdev->irq.hpd[2] = true;
741 break;
742 case RADEON_HPD_4:
743 WREG32(DC_HPD4_CONTROL, tmp);
744 rdev->irq.hpd[3] = true;
745 break;
746 /* DCE 3.2 */
747 case RADEON_HPD_5:
748 WREG32(DC_HPD5_CONTROL, tmp);
749 rdev->irq.hpd[4] = true;
750 break;
751 case RADEON_HPD_6:
752 WREG32(DC_HPD6_CONTROL, tmp);
753 rdev->irq.hpd[5] = true;
754 break;
755 default:
756 break;
757 }
Alex Deucher64912e92011-11-03 11:21:39 -0400758 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500759 switch (radeon_connector->hpd.hpd) {
760 case RADEON_HPD_1:
761 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
762 rdev->irq.hpd[0] = true;
763 break;
764 case RADEON_HPD_2:
765 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
766 rdev->irq.hpd[1] = true;
767 break;
768 case RADEON_HPD_3:
769 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
770 rdev->irq.hpd[2] = true;
771 break;
772 default:
773 break;
774 }
775 }
Alex Deucher64912e92011-11-03 11:21:39 -0400776 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500777 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100778 if (rdev->irq.installed)
779 r600_irq_set(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500780}
781
782void r600_hpd_fini(struct radeon_device *rdev)
783{
784 struct drm_device *dev = rdev->ddev;
785 struct drm_connector *connector;
786
787 if (ASIC_IS_DCE3(rdev)) {
788 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
789 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
790 switch (radeon_connector->hpd.hpd) {
791 case RADEON_HPD_1:
792 WREG32(DC_HPD1_CONTROL, 0);
793 rdev->irq.hpd[0] = false;
794 break;
795 case RADEON_HPD_2:
796 WREG32(DC_HPD2_CONTROL, 0);
797 rdev->irq.hpd[1] = false;
798 break;
799 case RADEON_HPD_3:
800 WREG32(DC_HPD3_CONTROL, 0);
801 rdev->irq.hpd[2] = false;
802 break;
803 case RADEON_HPD_4:
804 WREG32(DC_HPD4_CONTROL, 0);
805 rdev->irq.hpd[3] = false;
806 break;
807 /* DCE 3.2 */
808 case RADEON_HPD_5:
809 WREG32(DC_HPD5_CONTROL, 0);
810 rdev->irq.hpd[4] = false;
811 break;
812 case RADEON_HPD_6:
813 WREG32(DC_HPD6_CONTROL, 0);
814 rdev->irq.hpd[5] = false;
815 break;
816 default:
817 break;
818 }
819 }
820 } else {
821 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
822 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
823 switch (radeon_connector->hpd.hpd) {
824 case RADEON_HPD_1:
825 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
826 rdev->irq.hpd[0] = false;
827 break;
828 case RADEON_HPD_2:
829 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
830 rdev->irq.hpd[1] = false;
831 break;
832 case RADEON_HPD_3:
833 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
834 rdev->irq.hpd[2] = false;
835 break;
836 default:
837 break;
838 }
839 }
840 }
841}
842
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200843/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000844 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200845 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000846void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000848 unsigned i;
849 u32 tmp;
850
Dave Airlie2e98f102010-02-15 15:54:45 +1000851 /* flush hdp cache so updates hit vram */
Alex Deucherf3886f82010-12-08 10:05:34 -0500852 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
853 !(rdev->flags & RADEON_IS_AGP)) {
Jerome Glissec9a1be92011-11-03 11:16:49 -0400854 void __iomem *ptr = (void *)rdev->gart.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -0400855 u32 tmp;
856
857 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
858 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
Alex Deucherf3886f82010-12-08 10:05:34 -0500859 * This seems to cause problems on some AGP cards. Just use the old
860 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -0400861 */
862 WREG32(HDP_DEBUG1, 0);
863 tmp = readl((void __iomem *)ptr);
864 } else
865 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +1000866
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000867 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
868 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
869 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
870 for (i = 0; i < rdev->usec_timeout; i++) {
871 /* read MC_STATUS */
872 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
873 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
874 if (tmp == 2) {
875 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
876 return;
877 }
878 if (tmp) {
879 return;
880 }
881 udelay(1);
882 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200883}
884
Jerome Glisse4aac0472009-09-14 18:29:49 +0200885int r600_pcie_gart_init(struct radeon_device *rdev)
886{
887 int r;
888
Jerome Glissec9a1be92011-11-03 11:16:49 -0400889 if (rdev->gart.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +0000890 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +0200891 return 0;
892 }
893 /* Initialize common gart structure */
894 r = radeon_gart_init(rdev);
895 if (r)
896 return r;
897 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
898 return radeon_gart_table_vram_alloc(rdev);
899}
900
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000901int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200902{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000903 u32 tmp;
904 int r, i;
905
Jerome Glissec9a1be92011-11-03 11:16:49 -0400906 if (rdev->gart.robj == NULL) {
Jerome Glisse4aac0472009-09-14 18:29:49 +0200907 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
908 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000909 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200910 r = radeon_gart_table_vram_pin(rdev);
911 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000912 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000913 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000914
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000915 /* Setup L2 cache */
916 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
917 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
918 EFFECTIVE_L2_QUEUE_SIZE(7));
919 WREG32(VM_L2_CNTL2, 0);
920 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
921 /* Setup TLB control */
922 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
923 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
924 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
925 ENABLE_WAIT_L2_QUERY;
926 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
927 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
928 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
929 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
930 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
931 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
932 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
933 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
934 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
935 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
936 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
937 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
938 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
939 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
940 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200941 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000942 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
943 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
944 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
945 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
946 (u32)(rdev->dummy_page.addr >> 12));
947 for (i = 1; i < 7; i++)
948 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
949
950 r600_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000951 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
952 (unsigned)(rdev->mc.gtt_size >> 20),
953 (unsigned long long)rdev->gart.table_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000954 rdev->gart.ready = true;
955 return 0;
956}
957
958void r600_pcie_gart_disable(struct radeon_device *rdev)
959{
960 u32 tmp;
Jerome Glissec9a1be92011-11-03 11:16:49 -0400961 int i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000962
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000963 /* Disable all tables */
964 for (i = 0; i < 7; i++)
965 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
966
967 /* Disable L2 cache */
968 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
969 EFFECTIVE_L2_QUEUE_SIZE(7));
970 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
971 /* Setup L1 TLB control */
972 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
973 ENABLE_WAIT_L2_QUERY;
974 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
975 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
976 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
977 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
978 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
979 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
980 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
981 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
982 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
983 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
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);
987 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -0400988 radeon_gart_table_vram_unpin(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200989}
990
991void r600_pcie_gart_fini(struct radeon_device *rdev)
992{
Jerome Glissef9274562010-03-17 14:44:29 +0000993 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200994 r600_pcie_gart_disable(rdev);
995 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996}
997
Jerome Glisse1a029b72009-10-06 19:04:30 +0200998void r600_agp_enable(struct radeon_device *rdev)
999{
1000 u32 tmp;
1001 int i;
1002
1003 /* Setup L2 cache */
1004 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1005 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1006 EFFECTIVE_L2_QUEUE_SIZE(7));
1007 WREG32(VM_L2_CNTL2, 0);
1008 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1009 /* Setup TLB control */
1010 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1011 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1012 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1013 ENABLE_WAIT_L2_QUERY;
1014 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1015 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1016 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1017 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1018 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1019 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1020 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1021 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1022 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1023 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1024 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1025 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1026 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1027 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1028 for (i = 0; i < 7; i++)
1029 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1030}
1031
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001032int r600_mc_wait_for_idle(struct radeon_device *rdev)
1033{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001034 unsigned i;
1035 u32 tmp;
1036
1037 for (i = 0; i < rdev->usec_timeout; i++) {
1038 /* read MC_STATUS */
1039 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1040 if (!tmp)
1041 return 0;
1042 udelay(1);
1043 }
1044 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001045}
1046
Jerome Glissea3c19452009-10-01 18:02:13 +02001047static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001048{
Jerome Glissea3c19452009-10-01 18:02:13 +02001049 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001050 u32 tmp;
1051 int i, j;
1052
1053 /* Initialize HDP */
1054 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1055 WREG32((0x2c14 + j), 0x00000000);
1056 WREG32((0x2c18 + j), 0x00000000);
1057 WREG32((0x2c1c + j), 0x00000000);
1058 WREG32((0x2c20 + j), 0x00000000);
1059 WREG32((0x2c24 + j), 0x00000000);
1060 }
1061 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1062
Jerome Glissea3c19452009-10-01 18:02:13 +02001063 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001064 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001065 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001066 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001067 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001068 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001069 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001070 if (rdev->flags & RADEON_IS_AGP) {
1071 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1072 /* VRAM before AGP */
1073 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1074 rdev->mc.vram_start >> 12);
1075 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1076 rdev->mc.gtt_end >> 12);
1077 } else {
1078 /* VRAM after AGP */
1079 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1080 rdev->mc.gtt_start >> 12);
1081 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1082 rdev->mc.vram_end >> 12);
1083 }
1084 } else {
1085 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1086 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1087 }
Alex Deucher16cdf042011-10-28 10:30:02 -04001088 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001089 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001090 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1091 WREG32(MC_VM_FB_LOCATION, tmp);
1092 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1093 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001094 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001095 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001096 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1097 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001098 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1099 } else {
1100 WREG32(MC_VM_AGP_BASE, 0);
1101 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1102 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1103 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001104 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001105 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001106 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001107 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001108 /* we need to own VRAM, so turn off the VGA renderer here
1109 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001110 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111}
1112
Jerome Glissed594e462010-02-17 21:54:29 +00001113/**
1114 * r600_vram_gtt_location - try to find VRAM & GTT location
1115 * @rdev: radeon device structure holding all necessary informations
1116 * @mc: memory controller structure holding memory informations
1117 *
1118 * Function will place try to place VRAM at same place as in CPU (PCI)
1119 * address space as some GPU seems to have issue when we reprogram at
1120 * different address space.
1121 *
1122 * If there is not enough space to fit the unvisible VRAM after the
1123 * aperture then we limit the VRAM size to the aperture.
1124 *
1125 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1126 * them to be in one from GPU point of view so that we can program GPU to
1127 * catch access outside them (weird GPU policy see ??).
1128 *
1129 * This function will never fails, worst case are limiting VRAM or GTT.
1130 *
1131 * Note: GTT start, end, size should be initialized before calling this
1132 * function on AGP platform.
1133 */
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001134static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
Jerome Glissed594e462010-02-17 21:54:29 +00001135{
1136 u64 size_bf, size_af;
1137
1138 if (mc->mc_vram_size > 0xE0000000) {
1139 /* leave room for at least 512M GTT */
1140 dev_warn(rdev->dev, "limiting VRAM\n");
1141 mc->real_vram_size = 0xE0000000;
1142 mc->mc_vram_size = 0xE0000000;
1143 }
1144 if (rdev->flags & RADEON_IS_AGP) {
1145 size_bf = mc->gtt_start;
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001146 size_af = 0xFFFFFFFF - mc->gtt_end;
Jerome Glissed594e462010-02-17 21:54:29 +00001147 if (size_bf > size_af) {
1148 if (mc->mc_vram_size > size_bf) {
1149 dev_warn(rdev->dev, "limiting VRAM\n");
1150 mc->real_vram_size = size_bf;
1151 mc->mc_vram_size = size_bf;
1152 }
1153 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1154 } else {
1155 if (mc->mc_vram_size > size_af) {
1156 dev_warn(rdev->dev, "limiting VRAM\n");
1157 mc->real_vram_size = size_af;
1158 mc->mc_vram_size = size_af;
1159 }
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001160 mc->vram_start = mc->gtt_end + 1;
Jerome Glissed594e462010-02-17 21:54:29 +00001161 }
1162 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1163 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1164 mc->mc_vram_size >> 20, mc->vram_start,
1165 mc->vram_end, mc->real_vram_size >> 20);
1166 } else {
1167 u64 base = 0;
Alex Deucher8961d522010-12-03 14:37:22 -05001168 if (rdev->flags & RADEON_IS_IGP) {
1169 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1170 base <<= 24;
1171 }
Jerome Glissed594e462010-02-17 21:54:29 +00001172 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001173 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001174 radeon_gtt_location(rdev, mc);
1175 }
1176}
1177
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001178int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001179{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001180 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001181 int chansize, numchan;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001182
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001183 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001184 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001185 tmp = RREG32(RAMCFG);
1186 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001187 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001188 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001189 chansize = 64;
1190 } else {
1191 chansize = 32;
1192 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001193 tmp = RREG32(CHMAP);
1194 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1195 case 0:
1196 default:
1197 numchan = 1;
1198 break;
1199 case 1:
1200 numchan = 2;
1201 break;
1202 case 2:
1203 numchan = 4;
1204 break;
1205 case 3:
1206 numchan = 8;
1207 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001208 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001209 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001210 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001211 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1212 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001213 /* Setup GPU memory space */
1214 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1215 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001216 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001217 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001218
Alex Deucherf8920342010-06-30 12:02:03 -04001219 if (rdev->flags & RADEON_IS_IGP) {
1220 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001221 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Alex Deucherf8920342010-06-30 12:02:03 -04001222 }
Alex Deucherf47299c2010-03-16 20:54:38 -04001223 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001224 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001225}
1226
Alex Deucher16cdf042011-10-28 10:30:02 -04001227int r600_vram_scratch_init(struct radeon_device *rdev)
1228{
1229 int r;
1230
1231 if (rdev->vram_scratch.robj == NULL) {
1232 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1233 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Alex Deucher40f5cf92012-05-10 18:33:13 -04001234 NULL, &rdev->vram_scratch.robj);
Alex Deucher16cdf042011-10-28 10:30:02 -04001235 if (r) {
1236 return r;
1237 }
1238 }
1239
1240 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1241 if (unlikely(r != 0))
1242 return r;
1243 r = radeon_bo_pin(rdev->vram_scratch.robj,
1244 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1245 if (r) {
1246 radeon_bo_unreserve(rdev->vram_scratch.robj);
1247 return r;
1248 }
1249 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1250 (void **)&rdev->vram_scratch.ptr);
1251 if (r)
1252 radeon_bo_unpin(rdev->vram_scratch.robj);
1253 radeon_bo_unreserve(rdev->vram_scratch.robj);
1254
1255 return r;
1256}
1257
1258void r600_vram_scratch_fini(struct radeon_device *rdev)
1259{
1260 int r;
1261
1262 if (rdev->vram_scratch.robj == NULL) {
1263 return;
1264 }
1265 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1266 if (likely(r == 0)) {
1267 radeon_bo_kunmap(rdev->vram_scratch.robj);
1268 radeon_bo_unpin(rdev->vram_scratch.robj);
1269 radeon_bo_unreserve(rdev->vram_scratch.robj);
1270 }
1271 radeon_bo_unref(&rdev->vram_scratch.robj);
1272}
1273
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001274/* We doesn't check that the GPU really needs a reset we simply do the
1275 * reset, it's up to the caller to determine if the GPU needs one. We
1276 * might add an helper function to check that.
1277 */
1278int r600_gpu_soft_reset(struct radeon_device *rdev)
1279{
Jerome Glissea3c19452009-10-01 18:02:13 +02001280 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001281 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1282 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1283 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1284 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1285 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1286 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1287 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1288 S_008010_GUI_ACTIVE(1);
1289 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1290 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1291 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1292 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1293 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1294 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1295 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1296 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
Jerome Glissea3c19452009-10-01 18:02:13 +02001297 u32 tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001298
Alex Deucher8d96fe92011-01-21 15:38:22 +00001299 if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
1300 return 0;
1301
Jerome Glisse1a029b72009-10-06 19:04:30 +02001302 dev_info(rdev->dev, "GPU softreset \n");
1303 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1304 RREG32(R_008010_GRBM_STATUS));
1305 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
Jerome Glissea3c19452009-10-01 18:02:13 +02001306 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse1a029b72009-10-06 19:04:30 +02001307 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1308 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001309 rv515_mc_stop(rdev, &save);
1310 if (r600_mc_wait_for_idle(rdev)) {
1311 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1312 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001313 /* Disable CP parsing/prefetching */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001314 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001315 /* Check if any of the rendering block is busy and reset it */
1316 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
1317 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001318 tmp = S_008020_SOFT_RESET_CR(1) |
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001319 S_008020_SOFT_RESET_DB(1) |
1320 S_008020_SOFT_RESET_CB(1) |
1321 S_008020_SOFT_RESET_PA(1) |
1322 S_008020_SOFT_RESET_SC(1) |
1323 S_008020_SOFT_RESET_SMX(1) |
1324 S_008020_SOFT_RESET_SPI(1) |
1325 S_008020_SOFT_RESET_SX(1) |
1326 S_008020_SOFT_RESET_SH(1) |
1327 S_008020_SOFT_RESET_TC(1) |
1328 S_008020_SOFT_RESET_TA(1) |
1329 S_008020_SOFT_RESET_VC(1) |
Jerome Glissea3c19452009-10-01 18:02:13 +02001330 S_008020_SOFT_RESET_VGT(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001331 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
Jerome Glissea3c19452009-10-01 18:02:13 +02001332 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001333 RREG32(R_008020_GRBM_SOFT_RESET);
1334 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001335 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001336 }
1337 /* Reset CP (we always reset CP) */
Jerome Glissea3c19452009-10-01 18:02:13 +02001338 tmp = S_008020_SOFT_RESET_CP(1);
1339 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1340 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001341 RREG32(R_008020_GRBM_SOFT_RESET);
1342 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001343 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001344 /* Wait a little for things to settle down */
Jerome Glisse225758d2010-03-09 14:45:10 +00001345 mdelay(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001346 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1347 RREG32(R_008010_GRBM_STATUS));
1348 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1349 RREG32(R_008014_GRBM_STATUS2));
1350 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1351 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001352 rv515_mc_resume(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001353 return 0;
1354}
1355
Christian Könige32eb502011-10-23 12:56:27 +02001356bool r600_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse225758d2010-03-09 14:45:10 +00001357{
1358 u32 srbm_status;
1359 u32 grbm_status;
1360 u32 grbm_status2;
Jerome Glisse225758d2010-03-09 14:45:10 +00001361
1362 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1363 grbm_status = RREG32(R_008010_GRBM_STATUS);
1364 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1365 if (!G_008010_GUI_ACTIVE(grbm_status)) {
Christian König069211e2012-05-02 15:11:20 +02001366 radeon_ring_lockup_update(ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001367 return false;
1368 }
1369 /* force CP activities */
Christian König7b9ef162012-05-02 15:11:23 +02001370 radeon_ring_force_activity(rdev, ring);
Christian König069211e2012-05-02 15:11:20 +02001371 return radeon_ring_test_lockup(rdev, ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001372}
1373
Jerome Glissea2d07b72010-03-09 14:45:11 +00001374int r600_asic_reset(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001375{
1376 return r600_gpu_soft_reset(rdev);
1377}
1378
1379static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
1380 u32 num_backends,
1381 u32 backend_disable_mask)
1382{
1383 u32 backend_map = 0;
1384 u32 enabled_backends_mask;
1385 u32 enabled_backends_count;
1386 u32 cur_pipe;
1387 u32 swizzle_pipe[R6XX_MAX_PIPES];
1388 u32 cur_backend;
1389 u32 i;
1390
1391 if (num_tile_pipes > R6XX_MAX_PIPES)
1392 num_tile_pipes = R6XX_MAX_PIPES;
1393 if (num_tile_pipes < 1)
1394 num_tile_pipes = 1;
1395 if (num_backends > R6XX_MAX_BACKENDS)
1396 num_backends = R6XX_MAX_BACKENDS;
1397 if (num_backends < 1)
1398 num_backends = 1;
1399
1400 enabled_backends_mask = 0;
1401 enabled_backends_count = 0;
1402 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
1403 if (((backend_disable_mask >> i) & 1) == 0) {
1404 enabled_backends_mask |= (1 << i);
1405 ++enabled_backends_count;
1406 }
1407 if (enabled_backends_count == num_backends)
1408 break;
1409 }
1410
1411 if (enabled_backends_count == 0) {
1412 enabled_backends_mask = 1;
1413 enabled_backends_count = 1;
1414 }
1415
1416 if (enabled_backends_count != num_backends)
1417 num_backends = enabled_backends_count;
1418
1419 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
1420 switch (num_tile_pipes) {
1421 case 1:
1422 swizzle_pipe[0] = 0;
1423 break;
1424 case 2:
1425 swizzle_pipe[0] = 0;
1426 swizzle_pipe[1] = 1;
1427 break;
1428 case 3:
1429 swizzle_pipe[0] = 0;
1430 swizzle_pipe[1] = 1;
1431 swizzle_pipe[2] = 2;
1432 break;
1433 case 4:
1434 swizzle_pipe[0] = 0;
1435 swizzle_pipe[1] = 1;
1436 swizzle_pipe[2] = 2;
1437 swizzle_pipe[3] = 3;
1438 break;
1439 case 5:
1440 swizzle_pipe[0] = 0;
1441 swizzle_pipe[1] = 1;
1442 swizzle_pipe[2] = 2;
1443 swizzle_pipe[3] = 3;
1444 swizzle_pipe[4] = 4;
1445 break;
1446 case 6:
1447 swizzle_pipe[0] = 0;
1448 swizzle_pipe[1] = 2;
1449 swizzle_pipe[2] = 4;
1450 swizzle_pipe[3] = 5;
1451 swizzle_pipe[4] = 1;
1452 swizzle_pipe[5] = 3;
1453 break;
1454 case 7:
1455 swizzle_pipe[0] = 0;
1456 swizzle_pipe[1] = 2;
1457 swizzle_pipe[2] = 4;
1458 swizzle_pipe[3] = 6;
1459 swizzle_pipe[4] = 1;
1460 swizzle_pipe[5] = 3;
1461 swizzle_pipe[6] = 5;
1462 break;
1463 case 8:
1464 swizzle_pipe[0] = 0;
1465 swizzle_pipe[1] = 2;
1466 swizzle_pipe[2] = 4;
1467 swizzle_pipe[3] = 6;
1468 swizzle_pipe[4] = 1;
1469 swizzle_pipe[5] = 3;
1470 swizzle_pipe[6] = 5;
1471 swizzle_pipe[7] = 7;
1472 break;
1473 }
1474
1475 cur_backend = 0;
1476 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1477 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1478 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1479
1480 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
1481
1482 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1483 }
1484
1485 return backend_map;
1486}
1487
1488int r600_count_pipe_bits(uint32_t val)
1489{
1490 int i, ret = 0;
1491
1492 for (i = 0; i < 32; i++) {
1493 ret += val & 1;
1494 val >>= 1;
1495 }
1496 return ret;
1497}
1498
1499void r600_gpu_init(struct radeon_device *rdev)
1500{
1501 u32 tiling_config;
1502 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001503 u32 backend_map;
1504 u32 cc_rb_backend_disable;
1505 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001506 u32 tmp;
1507 int i, j;
1508 u32 sq_config;
1509 u32 sq_gpr_resource_mgmt_1 = 0;
1510 u32 sq_gpr_resource_mgmt_2 = 0;
1511 u32 sq_thread_resource_mgmt = 0;
1512 u32 sq_stack_resource_mgmt_1 = 0;
1513 u32 sq_stack_resource_mgmt_2 = 0;
1514
1515 /* FIXME: implement */
1516 switch (rdev->family) {
1517 case CHIP_R600:
1518 rdev->config.r600.max_pipes = 4;
1519 rdev->config.r600.max_tile_pipes = 8;
1520 rdev->config.r600.max_simds = 4;
1521 rdev->config.r600.max_backends = 4;
1522 rdev->config.r600.max_gprs = 256;
1523 rdev->config.r600.max_threads = 192;
1524 rdev->config.r600.max_stack_entries = 256;
1525 rdev->config.r600.max_hw_contexts = 8;
1526 rdev->config.r600.max_gs_threads = 16;
1527 rdev->config.r600.sx_max_export_size = 128;
1528 rdev->config.r600.sx_max_export_pos_size = 16;
1529 rdev->config.r600.sx_max_export_smx_size = 128;
1530 rdev->config.r600.sq_num_cf_insts = 2;
1531 break;
1532 case CHIP_RV630:
1533 case CHIP_RV635:
1534 rdev->config.r600.max_pipes = 2;
1535 rdev->config.r600.max_tile_pipes = 2;
1536 rdev->config.r600.max_simds = 3;
1537 rdev->config.r600.max_backends = 1;
1538 rdev->config.r600.max_gprs = 128;
1539 rdev->config.r600.max_threads = 192;
1540 rdev->config.r600.max_stack_entries = 128;
1541 rdev->config.r600.max_hw_contexts = 8;
1542 rdev->config.r600.max_gs_threads = 4;
1543 rdev->config.r600.sx_max_export_size = 128;
1544 rdev->config.r600.sx_max_export_pos_size = 16;
1545 rdev->config.r600.sx_max_export_smx_size = 128;
1546 rdev->config.r600.sq_num_cf_insts = 2;
1547 break;
1548 case CHIP_RV610:
1549 case CHIP_RV620:
1550 case CHIP_RS780:
1551 case CHIP_RS880:
1552 rdev->config.r600.max_pipes = 1;
1553 rdev->config.r600.max_tile_pipes = 1;
1554 rdev->config.r600.max_simds = 2;
1555 rdev->config.r600.max_backends = 1;
1556 rdev->config.r600.max_gprs = 128;
1557 rdev->config.r600.max_threads = 192;
1558 rdev->config.r600.max_stack_entries = 128;
1559 rdev->config.r600.max_hw_contexts = 4;
1560 rdev->config.r600.max_gs_threads = 4;
1561 rdev->config.r600.sx_max_export_size = 128;
1562 rdev->config.r600.sx_max_export_pos_size = 16;
1563 rdev->config.r600.sx_max_export_smx_size = 128;
1564 rdev->config.r600.sq_num_cf_insts = 1;
1565 break;
1566 case CHIP_RV670:
1567 rdev->config.r600.max_pipes = 4;
1568 rdev->config.r600.max_tile_pipes = 4;
1569 rdev->config.r600.max_simds = 4;
1570 rdev->config.r600.max_backends = 4;
1571 rdev->config.r600.max_gprs = 192;
1572 rdev->config.r600.max_threads = 192;
1573 rdev->config.r600.max_stack_entries = 256;
1574 rdev->config.r600.max_hw_contexts = 8;
1575 rdev->config.r600.max_gs_threads = 16;
1576 rdev->config.r600.sx_max_export_size = 128;
1577 rdev->config.r600.sx_max_export_pos_size = 16;
1578 rdev->config.r600.sx_max_export_smx_size = 128;
1579 rdev->config.r600.sq_num_cf_insts = 2;
1580 break;
1581 default:
1582 break;
1583 }
1584
1585 /* Initialize HDP */
1586 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1587 WREG32((0x2c14 + j), 0x00000000);
1588 WREG32((0x2c18 + j), 0x00000000);
1589 WREG32((0x2c1c + j), 0x00000000);
1590 WREG32((0x2c20 + j), 0x00000000);
1591 WREG32((0x2c24 + j), 0x00000000);
1592 }
1593
1594 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1595
1596 /* Setup tiling */
1597 tiling_config = 0;
1598 ramcfg = RREG32(RAMCFG);
1599 switch (rdev->config.r600.max_tile_pipes) {
1600 case 1:
1601 tiling_config |= PIPE_TILING(0);
1602 break;
1603 case 2:
1604 tiling_config |= PIPE_TILING(1);
1605 break;
1606 case 4:
1607 tiling_config |= PIPE_TILING(2);
1608 break;
1609 case 8:
1610 tiling_config |= PIPE_TILING(3);
1611 break;
1612 default:
1613 break;
1614 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001615 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001616 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001617 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04001618 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
1619 if ((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
1620 rdev->config.r600.tiling_group_size = 512;
1621 else
1622 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001623 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1624 if (tmp > 3) {
1625 tiling_config |= ROW_TILING(3);
1626 tiling_config |= SAMPLE_SPLIT(3);
1627 } else {
1628 tiling_config |= ROW_TILING(tmp);
1629 tiling_config |= SAMPLE_SPLIT(tmp);
1630 }
1631 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001632
1633 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1634 cc_rb_backend_disable |=
1635 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1636
1637 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
1638 cc_gc_shader_pipe_config |=
1639 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1640 cc_gc_shader_pipe_config |=
1641 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1642
1643 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1644 (R6XX_MAX_BACKENDS -
1645 r600_count_pipe_bits((cc_rb_backend_disable &
1646 R6XX_MAX_BACKENDS_MASK) >> 16)),
1647 (cc_rb_backend_disable >> 16));
Alex Deuchere7aeeba62010-06-04 13:10:12 -04001648 rdev->config.r600.tile_config = tiling_config;
Alex Deuchere55b9422011-07-15 19:53:52 +00001649 rdev->config.r600.backend_map = backend_map;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001650 tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001651 WREG32(GB_TILING_CONFIG, tiling_config);
1652 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1653 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1654
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001655 /* Setup pipes */
Alex Deucherd03f5d52010-02-19 16:22:31 -05001656 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1657 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -05001658 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001659
Alex Deucherd03f5d52010-02-19 16:22:31 -05001660 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001661 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1662 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1663
1664 /* Setup some CP states */
1665 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1666 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1667
1668 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1669 SYNC_WALKER | SYNC_ALIGNER));
1670 /* Setup various GPU states */
1671 if (rdev->family == CHIP_RV670)
1672 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1673
1674 tmp = RREG32(SX_DEBUG_1);
1675 tmp |= SMX_EVENT_RELEASE;
1676 if ((rdev->family > CHIP_R600))
1677 tmp |= ENABLE_NEW_SMX_ADDRESS;
1678 WREG32(SX_DEBUG_1, tmp);
1679
1680 if (((rdev->family) == CHIP_R600) ||
1681 ((rdev->family) == CHIP_RV630) ||
1682 ((rdev->family) == CHIP_RV610) ||
1683 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001684 ((rdev->family) == CHIP_RS780) ||
1685 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001686 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1687 } else {
1688 WREG32(DB_DEBUG, 0);
1689 }
1690 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1691 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1692
1693 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1694 WREG32(VGT_NUM_INSTANCES, 0);
1695
1696 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1697 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1698
1699 tmp = RREG32(SQ_MS_FIFO_SIZES);
1700 if (((rdev->family) == CHIP_RV610) ||
1701 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001702 ((rdev->family) == CHIP_RS780) ||
1703 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001704 tmp = (CACHE_FIFO_SIZE(0xa) |
1705 FETCH_FIFO_HIWATER(0xa) |
1706 DONE_FIFO_HIWATER(0xe0) |
1707 ALU_UPDATE_FIFO_HIWATER(0x8));
1708 } else if (((rdev->family) == CHIP_R600) ||
1709 ((rdev->family) == CHIP_RV630)) {
1710 tmp &= ~DONE_FIFO_HIWATER(0xff);
1711 tmp |= DONE_FIFO_HIWATER(0x4);
1712 }
1713 WREG32(SQ_MS_FIFO_SIZES, tmp);
1714
1715 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1716 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1717 */
1718 sq_config = RREG32(SQ_CONFIG);
1719 sq_config &= ~(PS_PRIO(3) |
1720 VS_PRIO(3) |
1721 GS_PRIO(3) |
1722 ES_PRIO(3));
1723 sq_config |= (DX9_CONSTS |
1724 VC_ENABLE |
1725 PS_PRIO(0) |
1726 VS_PRIO(1) |
1727 GS_PRIO(2) |
1728 ES_PRIO(3));
1729
1730 if ((rdev->family) == CHIP_R600) {
1731 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1732 NUM_VS_GPRS(124) |
1733 NUM_CLAUSE_TEMP_GPRS(4));
1734 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1735 NUM_ES_GPRS(0));
1736 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1737 NUM_VS_THREADS(48) |
1738 NUM_GS_THREADS(4) |
1739 NUM_ES_THREADS(4));
1740 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1741 NUM_VS_STACK_ENTRIES(128));
1742 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1743 NUM_ES_STACK_ENTRIES(0));
1744 } else if (((rdev->family) == CHIP_RV610) ||
1745 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001746 ((rdev->family) == CHIP_RS780) ||
1747 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001748 /* no vertex cache */
1749 sq_config &= ~VC_ENABLE;
1750
1751 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1752 NUM_VS_GPRS(44) |
1753 NUM_CLAUSE_TEMP_GPRS(2));
1754 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1755 NUM_ES_GPRS(17));
1756 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1757 NUM_VS_THREADS(78) |
1758 NUM_GS_THREADS(4) |
1759 NUM_ES_THREADS(31));
1760 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1761 NUM_VS_STACK_ENTRIES(40));
1762 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1763 NUM_ES_STACK_ENTRIES(16));
1764 } else if (((rdev->family) == CHIP_RV630) ||
1765 ((rdev->family) == CHIP_RV635)) {
1766 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1767 NUM_VS_GPRS(44) |
1768 NUM_CLAUSE_TEMP_GPRS(2));
1769 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1770 NUM_ES_GPRS(18));
1771 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1772 NUM_VS_THREADS(78) |
1773 NUM_GS_THREADS(4) |
1774 NUM_ES_THREADS(31));
1775 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1776 NUM_VS_STACK_ENTRIES(40));
1777 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1778 NUM_ES_STACK_ENTRIES(16));
1779 } else if ((rdev->family) == CHIP_RV670) {
1780 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1781 NUM_VS_GPRS(44) |
1782 NUM_CLAUSE_TEMP_GPRS(2));
1783 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1784 NUM_ES_GPRS(17));
1785 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1786 NUM_VS_THREADS(78) |
1787 NUM_GS_THREADS(4) |
1788 NUM_ES_THREADS(31));
1789 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1790 NUM_VS_STACK_ENTRIES(64));
1791 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1792 NUM_ES_STACK_ENTRIES(64));
1793 }
1794
1795 WREG32(SQ_CONFIG, sq_config);
1796 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1797 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1798 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1799 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1800 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1801
1802 if (((rdev->family) == CHIP_RV610) ||
1803 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001804 ((rdev->family) == CHIP_RS780) ||
1805 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001806 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1807 } else {
1808 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1809 }
1810
1811 /* More default values. 2D/3D driver should adjust as needed */
1812 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1813 S1_X(0x4) | S1_Y(0xc)));
1814 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1815 S1_X(0x2) | S1_Y(0x2) |
1816 S2_X(0xa) | S2_Y(0x6) |
1817 S3_X(0x6) | S3_Y(0xa)));
1818 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1819 S1_X(0x4) | S1_Y(0xc) |
1820 S2_X(0x1) | S2_Y(0x6) |
1821 S3_X(0xa) | S3_Y(0xe)));
1822 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1823 S5_X(0x0) | S5_Y(0x0) |
1824 S6_X(0xb) | S6_Y(0x4) |
1825 S7_X(0x7) | S7_Y(0x8)));
1826
1827 WREG32(VGT_STRMOUT_EN, 0);
1828 tmp = rdev->config.r600.max_pipes * 16;
1829 switch (rdev->family) {
1830 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001831 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001832 case CHIP_RS780:
1833 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001834 tmp += 32;
1835 break;
1836 case CHIP_RV670:
1837 tmp += 128;
1838 break;
1839 default:
1840 break;
1841 }
1842 if (tmp > 256) {
1843 tmp = 256;
1844 }
1845 WREG32(VGT_ES_PER_GS, 128);
1846 WREG32(VGT_GS_PER_ES, tmp);
1847 WREG32(VGT_GS_PER_VS, 2);
1848 WREG32(VGT_GS_VERTEX_REUSE, 16);
1849
1850 /* more default values. 2D/3D driver should adjust as needed */
1851 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1852 WREG32(VGT_STRMOUT_EN, 0);
1853 WREG32(SX_MISC, 0);
1854 WREG32(PA_SC_MODE_CNTL, 0);
1855 WREG32(PA_SC_AA_CONFIG, 0);
1856 WREG32(PA_SC_LINE_STIPPLE, 0);
1857 WREG32(SPI_INPUT_Z, 0);
1858 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1859 WREG32(CB_COLOR7_FRAG, 0);
1860
1861 /* Clear render buffer base addresses */
1862 WREG32(CB_COLOR0_BASE, 0);
1863 WREG32(CB_COLOR1_BASE, 0);
1864 WREG32(CB_COLOR2_BASE, 0);
1865 WREG32(CB_COLOR3_BASE, 0);
1866 WREG32(CB_COLOR4_BASE, 0);
1867 WREG32(CB_COLOR5_BASE, 0);
1868 WREG32(CB_COLOR6_BASE, 0);
1869 WREG32(CB_COLOR7_BASE, 0);
1870 WREG32(CB_COLOR7_FRAG, 0);
1871
1872 switch (rdev->family) {
1873 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001874 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001875 case CHIP_RS780:
1876 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001877 tmp = TC_L2_SIZE(8);
1878 break;
1879 case CHIP_RV630:
1880 case CHIP_RV635:
1881 tmp = TC_L2_SIZE(4);
1882 break;
1883 case CHIP_R600:
1884 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1885 break;
1886 default:
1887 tmp = TC_L2_SIZE(0);
1888 break;
1889 }
1890 WREG32(TC_CNTL, tmp);
1891
1892 tmp = RREG32(HDP_HOST_PATH_CNTL);
1893 WREG32(HDP_HOST_PATH_CNTL, tmp);
1894
1895 tmp = RREG32(ARB_POP);
1896 tmp |= ENABLE_TC128;
1897 WREG32(ARB_POP, tmp);
1898
1899 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1900 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1901 NUM_CLIP_SEQ(3)));
1902 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1903}
1904
1905
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001906/*
1907 * Indirect registers accessor
1908 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001909u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001910{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001911 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001912
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001913 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1914 (void)RREG32(PCIE_PORT_INDEX);
1915 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001916 return r;
1917}
1918
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001919void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001920{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001921 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1922 (void)RREG32(PCIE_PORT_INDEX);
1923 WREG32(PCIE_PORT_DATA, (v));
1924 (void)RREG32(PCIE_PORT_DATA);
1925}
1926
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001927/*
1928 * CP & Ring
1929 */
1930void r600_cp_stop(struct radeon_device *rdev)
1931{
Dave Airlie53595332011-03-14 09:47:24 +10001932 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001933 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04001934 WREG32(SCRATCH_UMSK, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001935}
1936
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001937int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001938{
1939 struct platform_device *pdev;
1940 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001941 const char *rlc_chip_name;
1942 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001943 char fw_name[30];
1944 int err;
1945
1946 DRM_DEBUG("\n");
1947
1948 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1949 err = IS_ERR(pdev);
1950 if (err) {
1951 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1952 return -EINVAL;
1953 }
1954
1955 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001956 case CHIP_R600:
1957 chip_name = "R600";
1958 rlc_chip_name = "R600";
1959 break;
1960 case CHIP_RV610:
1961 chip_name = "RV610";
1962 rlc_chip_name = "R600";
1963 break;
1964 case CHIP_RV630:
1965 chip_name = "RV630";
1966 rlc_chip_name = "R600";
1967 break;
1968 case CHIP_RV620:
1969 chip_name = "RV620";
1970 rlc_chip_name = "R600";
1971 break;
1972 case CHIP_RV635:
1973 chip_name = "RV635";
1974 rlc_chip_name = "R600";
1975 break;
1976 case CHIP_RV670:
1977 chip_name = "RV670";
1978 rlc_chip_name = "R600";
1979 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001980 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001981 case CHIP_RS880:
1982 chip_name = "RS780";
1983 rlc_chip_name = "R600";
1984 break;
1985 case CHIP_RV770:
1986 chip_name = "RV770";
1987 rlc_chip_name = "R700";
1988 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001989 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001990 case CHIP_RV740:
1991 chip_name = "RV730";
1992 rlc_chip_name = "R700";
1993 break;
1994 case CHIP_RV710:
1995 chip_name = "RV710";
1996 rlc_chip_name = "R700";
1997 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04001998 case CHIP_CEDAR:
1999 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04002000 rlc_chip_name = "CEDAR";
Alex Deucherfe251e22010-03-24 13:36:43 -04002001 break;
2002 case CHIP_REDWOOD:
2003 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04002004 rlc_chip_name = "REDWOOD";
Alex Deucherfe251e22010-03-24 13:36:43 -04002005 break;
2006 case CHIP_JUNIPER:
2007 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04002008 rlc_chip_name = "JUNIPER";
Alex Deucherfe251e22010-03-24 13:36:43 -04002009 break;
2010 case CHIP_CYPRESS:
2011 case CHIP_HEMLOCK:
2012 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04002013 rlc_chip_name = "CYPRESS";
Alex Deucherfe251e22010-03-24 13:36:43 -04002014 break;
Alex Deucher439bd6c2010-11-22 17:56:31 -05002015 case CHIP_PALM:
2016 chip_name = "PALM";
2017 rlc_chip_name = "SUMO";
2018 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002019 case CHIP_SUMO:
2020 chip_name = "SUMO";
2021 rlc_chip_name = "SUMO";
2022 break;
2023 case CHIP_SUMO2:
2024 chip_name = "SUMO2";
2025 rlc_chip_name = "SUMO";
2026 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002027 default: BUG();
2028 }
2029
Alex Deucherfe251e22010-03-24 13:36:43 -04002030 if (rdev->family >= CHIP_CEDAR) {
2031 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2032 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002033 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002034 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002035 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2036 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002037 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002038 } else {
2039 pfp_req_size = PFP_UCODE_SIZE * 4;
2040 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002041 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002042 }
2043
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002044 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002045
2046 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2047 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
2048 if (err)
2049 goto out;
2050 if (rdev->pfp_fw->size != pfp_req_size) {
2051 printk(KERN_ERR
2052 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2053 rdev->pfp_fw->size, fw_name);
2054 err = -EINVAL;
2055 goto out;
2056 }
2057
2058 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2059 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
2060 if (err)
2061 goto out;
2062 if (rdev->me_fw->size != me_req_size) {
2063 printk(KERN_ERR
2064 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2065 rdev->me_fw->size, fw_name);
2066 err = -EINVAL;
2067 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002068
2069 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
2070 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
2071 if (err)
2072 goto out;
2073 if (rdev->rlc_fw->size != rlc_req_size) {
2074 printk(KERN_ERR
2075 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2076 rdev->rlc_fw->size, fw_name);
2077 err = -EINVAL;
2078 }
2079
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002080out:
2081 platform_device_unregister(pdev);
2082
2083 if (err) {
2084 if (err != -EINVAL)
2085 printk(KERN_ERR
2086 "r600_cp: Failed to load firmware \"%s\"\n",
2087 fw_name);
2088 release_firmware(rdev->pfp_fw);
2089 rdev->pfp_fw = NULL;
2090 release_firmware(rdev->me_fw);
2091 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002092 release_firmware(rdev->rlc_fw);
2093 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002094 }
2095 return err;
2096}
2097
2098static int r600_cp_load_microcode(struct radeon_device *rdev)
2099{
2100 const __be32 *fw_data;
2101 int i;
2102
2103 if (!rdev->me_fw || !rdev->pfp_fw)
2104 return -EINVAL;
2105
2106 r600_cp_stop(rdev);
2107
Cédric Cano4eace7f2011-02-11 19:45:38 -05002108 WREG32(CP_RB_CNTL,
2109#ifdef __BIG_ENDIAN
2110 BUF_SWAP_32BIT |
2111#endif
2112 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002113
2114 /* Reset cp */
2115 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2116 RREG32(GRBM_SOFT_RESET);
2117 mdelay(15);
2118 WREG32(GRBM_SOFT_RESET, 0);
2119
2120 WREG32(CP_ME_RAM_WADDR, 0);
2121
2122 fw_data = (const __be32 *)rdev->me_fw->data;
2123 WREG32(CP_ME_RAM_WADDR, 0);
2124 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
2125 WREG32(CP_ME_RAM_DATA,
2126 be32_to_cpup(fw_data++));
2127
2128 fw_data = (const __be32 *)rdev->pfp_fw->data;
2129 WREG32(CP_PFP_UCODE_ADDR, 0);
2130 for (i = 0; i < PFP_UCODE_SIZE; i++)
2131 WREG32(CP_PFP_UCODE_DATA,
2132 be32_to_cpup(fw_data++));
2133
2134 WREG32(CP_PFP_UCODE_ADDR, 0);
2135 WREG32(CP_ME_RAM_WADDR, 0);
2136 WREG32(CP_ME_RAM_RADDR, 0);
2137 return 0;
2138}
2139
2140int r600_cp_start(struct radeon_device *rdev)
2141{
Christian Könige32eb502011-10-23 12:56:27 +02002142 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002143 int r;
2144 uint32_t cp_me;
2145
Christian Könige32eb502011-10-23 12:56:27 +02002146 r = radeon_ring_lock(rdev, ring, 7);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002147 if (r) {
2148 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2149 return r;
2150 }
Christian Könige32eb502011-10-23 12:56:27 +02002151 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2152 radeon_ring_write(ring, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002153 if (rdev->family >= CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +02002154 radeon_ring_write(ring, 0x0);
2155 radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002156 } else {
Christian Könige32eb502011-10-23 12:56:27 +02002157 radeon_ring_write(ring, 0x3);
2158 radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002159 }
Christian Könige32eb502011-10-23 12:56:27 +02002160 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2161 radeon_ring_write(ring, 0);
2162 radeon_ring_write(ring, 0);
2163 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002164
2165 cp_me = 0xff;
2166 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2167 return 0;
2168}
2169
2170int r600_cp_resume(struct radeon_device *rdev)
2171{
Christian Könige32eb502011-10-23 12:56:27 +02002172 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002173 u32 tmp;
2174 u32 rb_bufsz;
2175 int r;
2176
2177 /* Reset cp */
2178 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2179 RREG32(GRBM_SOFT_RESET);
2180 mdelay(15);
2181 WREG32(GRBM_SOFT_RESET, 0);
2182
2183 /* Set ring buffer size */
Christian Könige32eb502011-10-23 12:56:27 +02002184 rb_bufsz = drm_order(ring->ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04002185 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002186#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002187 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002188#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002189 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02002190 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002191
2192 /* Set the write pointer delay */
2193 WREG32(CP_RB_WPTR_DELAY, 0);
2194
2195 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002196 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2197 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02002198 ring->wptr = 0;
2199 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04002200
2201 /* set the wb address whether it's enabled or not */
Cédric Cano4eace7f2011-02-11 19:45:38 -05002202 WREG32(CP_RB_RPTR_ADDR,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002203 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002204 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2205 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2206
2207 if (rdev->wb.enabled)
2208 WREG32(SCRATCH_UMSK, 0xff);
2209 else {
2210 tmp |= RB_NO_UPDATE;
2211 WREG32(SCRATCH_UMSK, 0);
2212 }
2213
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002214 mdelay(1);
2215 WREG32(CP_RB_CNTL, tmp);
2216
Christian Könige32eb502011-10-23 12:56:27 +02002217 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002218 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2219
Christian Könige32eb502011-10-23 12:56:27 +02002220 ring->rptr = RREG32(CP_RB_RPTR);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002221
2222 r600_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002223 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05002224 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002225 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02002226 ring->ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002227 return r;
2228 }
2229 return 0;
2230}
2231
Christian Könige32eb502011-10-23 12:56:27 +02002232void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002233{
2234 u32 rb_bufsz;
2235
2236 /* Align ring size */
2237 rb_bufsz = drm_order(ring_size / 8);
2238 ring_size = (1 << (rb_bufsz + 1)) * 4;
Christian Könige32eb502011-10-23 12:56:27 +02002239 ring->ring_size = ring_size;
2240 ring->align_mask = 16 - 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002241}
2242
Jerome Glisse655efd32010-02-02 11:51:45 +01002243void r600_cp_fini(struct radeon_device *rdev)
2244{
2245 r600_cp_stop(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002246 radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
Jerome Glisse655efd32010-02-02 11:51:45 +01002247}
2248
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002249
2250/*
2251 * GPU scratch registers helpers function.
2252 */
2253void r600_scratch_init(struct radeon_device *rdev)
2254{
2255 int i;
2256
2257 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002258 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002259 for (i = 0; i < rdev->scratch.num_reg; i++) {
2260 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002261 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002262 }
2263}
2264
Christian Könige32eb502011-10-23 12:56:27 +02002265int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002266{
2267 uint32_t scratch;
2268 uint32_t tmp = 0;
Christian Könige32eb502011-10-23 12:56:27 +02002269 unsigned i, ridx = radeon_ring_index(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002270 int r;
2271
2272 r = radeon_scratch_get(rdev, &scratch);
2273 if (r) {
2274 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2275 return r;
2276 }
2277 WREG32(scratch, 0xCAFEDEAD);
Christian Könige32eb502011-10-23 12:56:27 +02002278 r = radeon_ring_lock(rdev, ring, 3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002279 if (r) {
Christian Königbf852792011-10-13 13:19:22 +02002280 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ridx, r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002281 radeon_scratch_free(rdev, scratch);
2282 return r;
2283 }
Christian Könige32eb502011-10-23 12:56:27 +02002284 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2285 radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2286 radeon_ring_write(ring, 0xDEADBEEF);
2287 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002288 for (i = 0; i < rdev->usec_timeout; i++) {
2289 tmp = RREG32(scratch);
2290 if (tmp == 0xDEADBEEF)
2291 break;
2292 DRM_UDELAY(1);
2293 }
2294 if (i < rdev->usec_timeout) {
Christian Königbf852792011-10-13 13:19:22 +02002295 DRM_INFO("ring test on %d succeeded in %d usecs\n", ridx, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002296 } else {
Christian Königbf852792011-10-13 13:19:22 +02002297 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
2298 ridx, scratch, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002299 r = -EINVAL;
2300 }
2301 radeon_scratch_free(rdev, scratch);
2302 return r;
2303}
2304
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002305void r600_fence_ring_emit(struct radeon_device *rdev,
2306 struct radeon_fence *fence)
2307{
Christian Könige32eb502011-10-23 12:56:27 +02002308 struct radeon_ring *ring = &rdev->ring[fence->ring];
Christian König7b1f2482011-09-23 15:11:23 +02002309
Alex Deucherd0f8a852010-09-04 05:04:34 -04002310 if (rdev->wb.use_event) {
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002311 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002312 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002313 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2314 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2315 PACKET3_VC_ACTION_ENA |
2316 PACKET3_SH_ACTION_ENA);
2317 radeon_ring_write(ring, 0xFFFFFFFF);
2318 radeon_ring_write(ring, 0);
2319 radeon_ring_write(ring, 10); /* poll interval */
Alex Deucherd0f8a852010-09-04 05:04:34 -04002320 /* EVENT_WRITE_EOP - flush caches, send int */
Christian Könige32eb502011-10-23 12:56:27 +02002321 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2322 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2323 radeon_ring_write(ring, addr & 0xffffffff);
2324 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2325 radeon_ring_write(ring, fence->seq);
2326 radeon_ring_write(ring, 0);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002327 } else {
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002328 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002329 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2330 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2331 PACKET3_VC_ACTION_ENA |
2332 PACKET3_SH_ACTION_ENA);
2333 radeon_ring_write(ring, 0xFFFFFFFF);
2334 radeon_ring_write(ring, 0);
2335 radeon_ring_write(ring, 10); /* poll interval */
2336 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
2337 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
Alex Deucherd0f8a852010-09-04 05:04:34 -04002338 /* wait for 3D idle clean */
Christian Könige32eb502011-10-23 12:56:27 +02002339 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2340 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2341 radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002342 /* Emit fence sequence & fire IRQ */
Christian Könige32eb502011-10-23 12:56:27 +02002343 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2344 radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2345 radeon_ring_write(ring, fence->seq);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002346 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
Christian Könige32eb502011-10-23 12:56:27 +02002347 radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
2348 radeon_ring_write(ring, RB_INT_STAT);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002349 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002350}
2351
Christian König15d33322011-09-15 19:02:22 +02002352void r600_semaphore_ring_emit(struct radeon_device *rdev,
Christian Könige32eb502011-10-23 12:56:27 +02002353 struct radeon_ring *ring,
Christian König15d33322011-09-15 19:02:22 +02002354 struct radeon_semaphore *semaphore,
Christian König7b1f2482011-09-23 15:11:23 +02002355 bool emit_wait)
Christian König15d33322011-09-15 19:02:22 +02002356{
2357 uint64_t addr = semaphore->gpu_addr;
2358 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
2359
Christian König0be70432012-03-07 11:28:57 +01002360 if (rdev->family < CHIP_CAYMAN)
2361 sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
2362
Christian Könige32eb502011-10-23 12:56:27 +02002363 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
2364 radeon_ring_write(ring, addr & 0xffffffff);
2365 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
Christian König15d33322011-09-15 19:02:22 +02002366}
2367
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002368int r600_copy_blit(struct radeon_device *rdev,
Alex Deucher003cefe2011-09-16 12:04:08 -04002369 uint64_t src_offset,
2370 uint64_t dst_offset,
2371 unsigned num_gpu_pages,
2372 struct radeon_fence *fence)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002373{
Christian Königf2377502012-05-09 15:35:01 +02002374 struct radeon_sa_bo *vb = NULL;
Jerome Glisseff82f052010-01-22 15:19:00 +01002375 int r;
2376
Christian Königf2377502012-05-09 15:35:01 +02002377 r = r600_blit_prepare_copy(rdev, num_gpu_pages, &vb);
Jerome Glisseff82f052010-01-22 15:19:00 +01002378 if (r) {
Jerome Glisseff82f052010-01-22 15:19:00 +01002379 return r;
2380 }
Christian Königf2377502012-05-09 15:35:01 +02002381 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb);
2382 r600_blit_done_copy(rdev, fence, vb);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002383 return 0;
2384}
2385
Alex Deucher6ddddfe2011-10-14 10:51:22 -04002386void r600_blit_suspend(struct radeon_device *rdev)
2387{
2388 int r;
2389
2390 /* unpin shaders bo */
2391 if (rdev->r600_blit.shader_obj) {
2392 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
2393 if (!r) {
2394 radeon_bo_unpin(rdev->r600_blit.shader_obj);
2395 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
2396 }
2397 }
2398}
2399
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002400int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2401 uint32_t tiling_flags, uint32_t pitch,
2402 uint32_t offset, uint32_t obj_size)
2403{
2404 /* FIXME: implement */
2405 return 0;
2406}
2407
2408void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2409{
2410 /* FIXME: implement */
2411}
2412
Dave Airliefc30b8e2009-09-18 15:19:37 +10002413int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002414{
Christian Könige32eb502011-10-23 12:56:27 +02002415 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002416 int r;
2417
Alex Deucher9e46a482011-01-06 18:49:35 -05002418 /* enable pcie gen2 link */
2419 r600_pcie_gen2_enable(rdev);
2420
Alex Deucher779720a2009-12-09 19:31:44 -05002421 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2422 r = r600_init_microcode(rdev);
2423 if (r) {
2424 DRM_ERROR("Failed to load firmware!\n");
2425 return r;
2426 }
2427 }
2428
Alex Deucher16cdf042011-10-28 10:30:02 -04002429 r = r600_vram_scratch_init(rdev);
2430 if (r)
2431 return r;
2432
Jerome Glissea3c19452009-10-01 18:02:13 +02002433 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02002434 if (rdev->flags & RADEON_IS_AGP) {
2435 r600_agp_enable(rdev);
2436 } else {
2437 r = r600_pcie_gart_enable(rdev);
2438 if (r)
2439 return r;
2440 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002441 r600_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01002442 r = r600_blit_init(rdev);
2443 if (r) {
2444 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05002445 rdev->asic->copy.copy = NULL;
Jerome Glissec38c7b62010-02-04 17:27:27 +01002446 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2447 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04002448
Alex Deucher724c80e2010-08-27 18:25:25 -04002449 /* allocate wb buffer */
2450 r = radeon_wb_init(rdev);
2451 if (r)
2452 return r;
2453
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002454 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
2455 if (r) {
2456 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2457 return r;
2458 }
2459
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002460 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002461 r = r600_irq_init(rdev);
2462 if (r) {
2463 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2464 radeon_irq_kms_fini(rdev);
2465 return r;
2466 }
2467 r600_irq_set(rdev);
2468
Christian Könige32eb502011-10-23 12:56:27 +02002469 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05002470 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
2471 0, 0xfffff, RADEON_CP_PACKET2);
Christian König5596a9d2011-10-13 12:48:45 +02002472
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002473 if (r)
2474 return r;
2475 r = r600_cp_load_microcode(rdev);
2476 if (r)
2477 return r;
2478 r = r600_cp_resume(rdev);
2479 if (r)
2480 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04002481
Jerome Glisseb15ba512011-11-15 11:48:34 -05002482 r = radeon_ib_pool_start(rdev);
2483 if (r)
2484 return r;
2485
Christian König7bd560e2012-05-02 15:11:12 +02002486 r = radeon_ib_ring_tests(rdev);
2487 if (r)
Jerome Glisseb15ba512011-11-15 11:48:34 -05002488 return r;
Jerome Glisseb15ba512011-11-15 11:48:34 -05002489
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002490 return 0;
2491}
2492
Dave Airlie28d52042009-09-21 14:33:58 +10002493void r600_vga_set_state(struct radeon_device *rdev, bool state)
2494{
2495 uint32_t temp;
2496
2497 temp = RREG32(CONFIG_CNTL);
2498 if (state == false) {
2499 temp &= ~(1<<0);
2500 temp |= (1<<1);
2501 } else {
2502 temp &= ~(1<<1);
2503 }
2504 WREG32(CONFIG_CNTL, temp);
2505}
2506
Dave Airliefc30b8e2009-09-18 15:19:37 +10002507int r600_resume(struct radeon_device *rdev)
2508{
2509 int r;
2510
Jerome Glisse1a029b72009-10-06 19:04:30 +02002511 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2512 * posting will perform necessary task to bring back GPU into good
2513 * shape.
2514 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002515 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002516 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002517
Jerome Glisseb15ba512011-11-15 11:48:34 -05002518 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002519 r = r600_startup(rdev);
2520 if (r) {
2521 DRM_ERROR("r600 startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05002522 rdev->accel_working = false;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002523 return r;
2524 }
2525
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002526 r = r600_audio_init(rdev);
2527 if (r) {
2528 DRM_ERROR("radeon: audio resume failed\n");
2529 return r;
2530 }
2531
Dave Airliefc30b8e2009-09-18 15:19:37 +10002532 return r;
2533}
2534
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002535int r600_suspend(struct radeon_device *rdev)
2536{
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002537 r600_audio_fini(rdev);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002538 radeon_ib_pool_suspend(rdev);
2539 r600_blit_suspend(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002540 /* FIXME: we should wait for ring to be empty */
2541 r600_cp_stop(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002542 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01002543 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002544 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002545 r600_pcie_gart_disable(rdev);
Alex Deucher6ddddfe2011-10-14 10:51:22 -04002546
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002547 return 0;
2548}
2549
2550/* Plan is to move initialization in that function and use
2551 * helper function so that radeon_device_init pretty much
2552 * do nothing more than calling asic specific function. This
2553 * should also allow to remove a bunch of callback function
2554 * like vram_info.
2555 */
2556int r600_init(struct radeon_device *rdev)
2557{
2558 int r;
2559
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002560 if (r600_debugfs_mc_info_init(rdev)) {
2561 DRM_ERROR("Failed to register debugfs file for mc !\n");
2562 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002563 /* Read BIOS */
2564 if (!radeon_get_bios(rdev)) {
2565 if (ASIC_IS_AVIVO(rdev))
2566 return -EINVAL;
2567 }
2568 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002569 if (!rdev->is_atom_bios) {
2570 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002571 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002572 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002573 r = radeon_atombios_init(rdev);
2574 if (r)
2575 return r;
2576 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05002577 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10002578 if (!rdev->bios) {
2579 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2580 return -EINVAL;
2581 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002582 DRM_INFO("GPU not posted. posting now...\n");
2583 atom_asic_init(rdev->mode_info.atom_context);
2584 }
2585 /* Initialize scratch registers */
2586 r600_scratch_init(rdev);
2587 /* Initialize surface registers */
2588 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002589 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002590 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002591 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002592 r = radeon_fence_driver_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002593 if (r)
2594 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01002595 if (rdev->flags & RADEON_IS_AGP) {
2596 r = radeon_agp_init(rdev);
2597 if (r)
2598 radeon_agp_disable(rdev);
2599 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002600 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002601 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002602 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002603 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002604 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002605 if (r)
2606 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002607
2608 r = radeon_irq_kms_init(rdev);
2609 if (r)
2610 return r;
2611
Christian Könige32eb502011-10-23 12:56:27 +02002612 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
2613 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002614
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002615 rdev->ih.ring_obj = NULL;
2616 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002617
Jerome Glisse4aac0472009-09-14 18:29:49 +02002618 r = r600_pcie_gart_init(rdev);
2619 if (r)
2620 return r;
2621
Jerome Glisseb15ba512011-11-15 11:48:34 -05002622 r = radeon_ib_pool_init(rdev);
Alex Deucher779720a2009-12-09 19:31:44 -05002623 rdev->accel_working = true;
Jerome Glisseb15ba512011-11-15 11:48:34 -05002624 if (r) {
2625 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
2626 rdev->accel_working = false;
2627 }
2628
Dave Airliefc30b8e2009-09-18 15:19:37 +10002629 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002630 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01002631 dev_err(rdev->dev, "disabling GPU acceleration\n");
2632 r600_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002633 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002634 radeon_wb_fini(rdev);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002635 r100_ib_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002636 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002637 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002638 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002639 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002640
2641 r = r600_audio_init(rdev);
2642 if (r)
2643 return r; /* TODO error handling */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002644 return 0;
2645}
2646
2647void r600_fini(struct radeon_device *rdev)
2648{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002649 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002650 r600_blit_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002651 r600_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002652 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002653 radeon_wb_fini(rdev);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002654 r100_ib_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002655 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002656 r600_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04002657 r600_vram_scratch_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002658 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002659 radeon_gem_fini(rdev);
2660 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002661 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002662 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002663 kfree(rdev->bios);
2664 rdev->bios = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002665}
2666
2667
2668/*
2669 * CS stuff
2670 */
2671void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2672{
Christian Könige32eb502011-10-23 12:56:27 +02002673 struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
Christian König7b1f2482011-09-23 15:11:23 +02002674
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002675 /* FIXME: implement */
Christian Könige32eb502011-10-23 12:56:27 +02002676 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2677 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002678#ifdef __BIG_ENDIAN
2679 (2 << 0) |
2680#endif
2681 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02002682 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
2683 radeon_ring_write(ring, ib->length_dw);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002684}
2685
Alex Deucherf7128122012-02-23 17:53:45 -05002686int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002687{
Jerome Glissef2e39222012-05-09 15:35:02 +02002688 struct radeon_ib ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002689 uint32_t scratch;
2690 uint32_t tmp = 0;
2691 unsigned i;
2692 int r;
Alex Deucherf7128122012-02-23 17:53:45 -05002693 int ring_index = radeon_ring_index(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002694
2695 r = radeon_scratch_get(rdev, &scratch);
2696 if (r) {
2697 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2698 return r;
2699 }
2700 WREG32(scratch, 0xCAFEDEAD);
Alex Deucherf7128122012-02-23 17:53:45 -05002701 r = radeon_ib_get(rdev, ring_index, &ib, 256);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002702 if (r) {
2703 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2704 return r;
2705 }
Jerome Glissef2e39222012-05-09 15:35:02 +02002706 ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2707 ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2708 ib.ptr[2] = 0xDEADBEEF;
2709 ib.length_dw = 3;
2710 r = radeon_ib_schedule(rdev, &ib);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002711 if (r) {
2712 radeon_scratch_free(rdev, scratch);
2713 radeon_ib_free(rdev, &ib);
2714 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2715 return r;
2716 }
Jerome Glissef2e39222012-05-09 15:35:02 +02002717 r = radeon_fence_wait(ib.fence, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002718 if (r) {
2719 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2720 return r;
2721 }
2722 for (i = 0; i < rdev->usec_timeout; i++) {
2723 tmp = RREG32(scratch);
2724 if (tmp == 0xDEADBEEF)
2725 break;
2726 DRM_UDELAY(1);
2727 }
2728 if (i < rdev->usec_timeout) {
Jerome Glissef2e39222012-05-09 15:35:02 +02002729 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002730 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01002731 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002732 scratch, tmp);
2733 r = -EINVAL;
2734 }
2735 radeon_scratch_free(rdev, scratch);
2736 radeon_ib_free(rdev, &ib);
2737 return r;
2738}
2739
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002740/*
2741 * Interrupts
2742 *
2743 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2744 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2745 * writing to the ring and the GPU consuming, the GPU writes to the ring
2746 * and host consumes. As the host irq handler processes interrupts, it
2747 * increments the rptr. When the rptr catches up with the wptr, all the
2748 * current interrupts have been processed.
2749 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002750
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002751void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2752{
2753 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002754
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002755 /* Align ring size */
2756 rb_bufsz = drm_order(ring_size / 4);
2757 ring_size = (1 << rb_bufsz) * 4;
2758 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01002759 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
2760 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002761}
2762
Alex Deucher25a857f2012-03-20 17:18:22 -04002763int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002764{
2765 int r;
2766
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002767 /* Allocate ring buffer */
2768 if (rdev->ih.ring_obj == NULL) {
Daniel Vetter441921d2011-02-18 17:59:16 +01002769 r = radeon_bo_create(rdev, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05002770 PAGE_SIZE, true,
Jerome Glisse4c788672009-11-20 14:29:23 +01002771 RADEON_GEM_DOMAIN_GTT,
Alex Deucher40f5cf92012-05-10 18:33:13 -04002772 NULL, &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002773 if (r) {
2774 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2775 return r;
2776 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002777 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2778 if (unlikely(r != 0))
2779 return r;
2780 r = radeon_bo_pin(rdev->ih.ring_obj,
2781 RADEON_GEM_DOMAIN_GTT,
2782 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002783 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002784 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002785 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2786 return r;
2787 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002788 r = radeon_bo_kmap(rdev->ih.ring_obj,
2789 (void **)&rdev->ih.ring);
2790 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002791 if (r) {
2792 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2793 return r;
2794 }
2795 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002796 return 0;
2797}
2798
Alex Deucher25a857f2012-03-20 17:18:22 -04002799void r600_ih_ring_fini(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002800{
Jerome Glisse4c788672009-11-20 14:29:23 +01002801 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002802 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002803 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2804 if (likely(r == 0)) {
2805 radeon_bo_kunmap(rdev->ih.ring_obj);
2806 radeon_bo_unpin(rdev->ih.ring_obj);
2807 radeon_bo_unreserve(rdev->ih.ring_obj);
2808 }
2809 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002810 rdev->ih.ring = NULL;
2811 rdev->ih.ring_obj = NULL;
2812 }
2813}
2814
Alex Deucher45f9a392010-03-24 13:55:51 -04002815void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002816{
2817
Alex Deucher45f9a392010-03-24 13:55:51 -04002818 if ((rdev->family >= CHIP_RV770) &&
2819 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002820 /* r7xx asics need to soft reset RLC before halting */
2821 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2822 RREG32(SRBM_SOFT_RESET);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06002823 mdelay(15);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002824 WREG32(SRBM_SOFT_RESET, 0);
2825 RREG32(SRBM_SOFT_RESET);
2826 }
2827
2828 WREG32(RLC_CNTL, 0);
2829}
2830
2831static void r600_rlc_start(struct radeon_device *rdev)
2832{
2833 WREG32(RLC_CNTL, RLC_ENABLE);
2834}
2835
2836static int r600_rlc_init(struct radeon_device *rdev)
2837{
2838 u32 i;
2839 const __be32 *fw_data;
2840
2841 if (!rdev->rlc_fw)
2842 return -EINVAL;
2843
2844 r600_rlc_stop(rdev);
2845
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002846 WREG32(RLC_HB_CNTL, 0);
Alex Deucherc420c742012-03-20 17:18:39 -04002847
2848 if (rdev->family == CHIP_ARUBA) {
2849 WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
2850 WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
2851 }
2852 if (rdev->family <= CHIP_CAYMAN) {
2853 WREG32(RLC_HB_BASE, 0);
2854 WREG32(RLC_HB_RPTR, 0);
2855 WREG32(RLC_HB_WPTR, 0);
2856 }
Alex Deucher12727802011-03-02 20:07:32 -05002857 if (rdev->family <= CHIP_CAICOS) {
2858 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2859 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2860 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002861 WREG32(RLC_MC_CNTL, 0);
2862 WREG32(RLC_UCODE_CNTL, 0);
2863
2864 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucherc420c742012-03-20 17:18:39 -04002865 if (rdev->family >= CHIP_ARUBA) {
2866 for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
2867 WREG32(RLC_UCODE_ADDR, i);
2868 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2869 }
2870 } else if (rdev->family >= CHIP_CAYMAN) {
Alex Deucher12727802011-03-02 20:07:32 -05002871 for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
2872 WREG32(RLC_UCODE_ADDR, i);
2873 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2874 }
2875 } else if (rdev->family >= CHIP_CEDAR) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002876 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
2877 WREG32(RLC_UCODE_ADDR, i);
2878 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2879 }
2880 } else if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002881 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2882 WREG32(RLC_UCODE_ADDR, i);
2883 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2884 }
2885 } else {
2886 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2887 WREG32(RLC_UCODE_ADDR, i);
2888 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2889 }
2890 }
2891 WREG32(RLC_UCODE_ADDR, 0);
2892
2893 r600_rlc_start(rdev);
2894
2895 return 0;
2896}
2897
2898static void r600_enable_interrupts(struct radeon_device *rdev)
2899{
2900 u32 ih_cntl = RREG32(IH_CNTL);
2901 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2902
2903 ih_cntl |= ENABLE_INTR;
2904 ih_rb_cntl |= IH_RB_ENABLE;
2905 WREG32(IH_CNTL, ih_cntl);
2906 WREG32(IH_RB_CNTL, ih_rb_cntl);
2907 rdev->ih.enabled = true;
2908}
2909
Alex Deucher45f9a392010-03-24 13:55:51 -04002910void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002911{
2912 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2913 u32 ih_cntl = RREG32(IH_CNTL);
2914
2915 ih_rb_cntl &= ~IH_RB_ENABLE;
2916 ih_cntl &= ~ENABLE_INTR;
2917 WREG32(IH_RB_CNTL, ih_rb_cntl);
2918 WREG32(IH_CNTL, ih_cntl);
2919 /* set rptr, wptr to 0 */
2920 WREG32(IH_RB_RPTR, 0);
2921 WREG32(IH_RB_WPTR, 0);
2922 rdev->ih.enabled = false;
2923 rdev->ih.wptr = 0;
2924 rdev->ih.rptr = 0;
2925}
2926
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002927static void r600_disable_interrupt_state(struct radeon_device *rdev)
2928{
2929 u32 tmp;
2930
Alex Deucher3555e532010-10-08 12:09:12 -04002931 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002932 WREG32(GRBM_INT_CNTL, 0);
2933 WREG32(DxMODE_INT_MASK, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05002934 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
2935 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002936 if (ASIC_IS_DCE3(rdev)) {
2937 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2938 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2939 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2940 WREG32(DC_HPD1_INT_CONTROL, tmp);
2941 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2942 WREG32(DC_HPD2_INT_CONTROL, tmp);
2943 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2944 WREG32(DC_HPD3_INT_CONTROL, tmp);
2945 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2946 WREG32(DC_HPD4_INT_CONTROL, tmp);
2947 if (ASIC_IS_DCE32(rdev)) {
2948 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002949 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002950 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002951 WREG32(DC_HPD6_INT_CONTROL, tmp);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02002952 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2953 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
2954 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2955 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04002956 } else {
2957 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2958 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
2959 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2960 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002961 }
2962 } else {
2963 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2964 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2965 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002966 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002967 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002968 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002969 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002970 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04002971 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2972 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
2973 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
2974 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002975 }
2976}
2977
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002978int r600_irq_init(struct radeon_device *rdev)
2979{
2980 int ret = 0;
2981 int rb_bufsz;
2982 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2983
2984 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01002985 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002986 if (ret)
2987 return ret;
2988
2989 /* disable irqs */
2990 r600_disable_interrupts(rdev);
2991
2992 /* init rlc */
2993 ret = r600_rlc_init(rdev);
2994 if (ret) {
2995 r600_ih_ring_fini(rdev);
2996 return ret;
2997 }
2998
2999 /* setup interrupt control */
3000 /* set dummy read address to ring address */
3001 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
3002 interrupt_cntl = RREG32(INTERRUPT_CNTL);
3003 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3004 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3005 */
3006 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
3007 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3008 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
3009 WREG32(INTERRUPT_CNTL, interrupt_cntl);
3010
3011 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
3012 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
3013
3014 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
3015 IH_WPTR_OVERFLOW_CLEAR |
3016 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04003017
3018 if (rdev->wb.enabled)
3019 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
3020
3021 /* set the writeback address whether it's enabled or not */
3022 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
3023 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003024
3025 WREG32(IH_RB_CNTL, ih_rb_cntl);
3026
3027 /* set rptr, wptr to 0 */
3028 WREG32(IH_RB_RPTR, 0);
3029 WREG32(IH_RB_WPTR, 0);
3030
3031 /* Default settings for IH_CNTL (disabled at first) */
3032 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3033 /* RPTR_REARM only works if msi's are enabled */
3034 if (rdev->msi_enabled)
3035 ih_cntl |= RPTR_REARM;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003036 WREG32(IH_CNTL, ih_cntl);
3037
3038 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04003039 if (rdev->family >= CHIP_CEDAR)
3040 evergreen_disable_interrupt_state(rdev);
3041 else
3042 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003043
Dave Airlie20998102012-04-03 11:53:05 +01003044 /* at this point everything should be setup correctly to enable master */
3045 pci_set_master(rdev->pdev);
3046
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003047 /* enable irqs */
3048 r600_enable_interrupts(rdev);
3049
3050 return ret;
3051}
3052
Jerome Glisse0c452492010-01-15 14:44:37 +01003053void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003054{
Alex Deucher45f9a392010-03-24 13:55:51 -04003055 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003056 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003057}
3058
3059void r600_irq_fini(struct radeon_device *rdev)
3060{
3061 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003062 r600_ih_ring_fini(rdev);
3063}
3064
3065int r600_irq_set(struct radeon_device *rdev)
3066{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003067 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3068 u32 mode_int = 0;
3069 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04003070 u32 grbm_int_cntl = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003071 u32 hdmi0, hdmi1;
Alex Deucher6f34be52010-11-21 10:59:01 -05003072 u32 d1grph = 0, d2grph = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003073
Jerome Glisse003e69f2010-01-07 15:39:14 +01003074 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003075 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01003076 return -EINVAL;
3077 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003078 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003079 if (!rdev->ih.enabled) {
3080 r600_disable_interrupts(rdev);
3081 /* force the active interrupt state to all disabled */
3082 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003083 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003084 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003085
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003086 if (ASIC_IS_DCE3(rdev)) {
3087 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3088 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3089 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3090 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3091 if (ASIC_IS_DCE32(rdev)) {
3092 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3093 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003094 hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3095 hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
Alex Deucherf122c612012-03-30 08:59:57 -04003096 } else {
3097 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3098 hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003099 }
3100 } else {
3101 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3102 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3103 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
Alex Deucherf122c612012-03-30 08:59:57 -04003104 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3105 hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003106 }
3107
Alex Deucher1b370782011-11-17 20:13:28 -05003108 if (rdev->irq.sw_int[RADEON_RING_TYPE_GFX_INDEX]) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003109 DRM_DEBUG("r600_irq_set: sw int\n");
3110 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003111 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003112 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003113 if (rdev->irq.crtc_vblank_int[0] ||
3114 rdev->irq.pflip[0]) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003115 DRM_DEBUG("r600_irq_set: vblank 0\n");
3116 mode_int |= D1MODE_VBLANK_INT_MASK;
3117 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003118 if (rdev->irq.crtc_vblank_int[1] ||
3119 rdev->irq.pflip[1]) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003120 DRM_DEBUG("r600_irq_set: vblank 1\n");
3121 mode_int |= D2MODE_VBLANK_INT_MASK;
3122 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003123 if (rdev->irq.hpd[0]) {
3124 DRM_DEBUG("r600_irq_set: hpd 1\n");
3125 hpd1 |= DC_HPDx_INT_EN;
3126 }
3127 if (rdev->irq.hpd[1]) {
3128 DRM_DEBUG("r600_irq_set: hpd 2\n");
3129 hpd2 |= DC_HPDx_INT_EN;
3130 }
3131 if (rdev->irq.hpd[2]) {
3132 DRM_DEBUG("r600_irq_set: hpd 3\n");
3133 hpd3 |= DC_HPDx_INT_EN;
3134 }
3135 if (rdev->irq.hpd[3]) {
3136 DRM_DEBUG("r600_irq_set: hpd 4\n");
3137 hpd4 |= DC_HPDx_INT_EN;
3138 }
3139 if (rdev->irq.hpd[4]) {
3140 DRM_DEBUG("r600_irq_set: hpd 5\n");
3141 hpd5 |= DC_HPDx_INT_EN;
3142 }
3143 if (rdev->irq.hpd[5]) {
3144 DRM_DEBUG("r600_irq_set: hpd 6\n");
3145 hpd6 |= DC_HPDx_INT_EN;
3146 }
Alex Deucherf122c612012-03-30 08:59:57 -04003147 if (rdev->irq.afmt[0]) {
3148 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3149 hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003150 }
Alex Deucherf122c612012-03-30 08:59:57 -04003151 if (rdev->irq.afmt[1]) {
3152 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3153 hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003154 }
Alex Deucher2031f772010-04-22 12:52:11 -04003155 if (rdev->irq.gui_idle) {
3156 DRM_DEBUG("gui idle\n");
3157 grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
3158 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003159
3160 WREG32(CP_INT_CNTL, cp_int_cntl);
3161 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher6f34be52010-11-21 10:59:01 -05003162 WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
3163 WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
Alex Deucher2031f772010-04-22 12:52:11 -04003164 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003165 if (ASIC_IS_DCE3(rdev)) {
3166 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3167 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3168 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3169 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3170 if (ASIC_IS_DCE32(rdev)) {
3171 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3172 WREG32(DC_HPD6_INT_CONTROL, hpd6);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003173 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
3174 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
Alex Deucherf122c612012-03-30 08:59:57 -04003175 } else {
3176 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3177 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003178 }
3179 } else {
3180 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3181 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3182 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
Alex Deucherf122c612012-03-30 08:59:57 -04003183 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3184 WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003185 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003186
3187 return 0;
3188}
3189
Andi Kleence580fa2011-10-13 16:08:47 -07003190static void r600_irq_ack(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003191{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003192 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003193
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003194 if (ASIC_IS_DCE3(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003195 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3196 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3197 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
Alex Deucherf122c612012-03-30 08:59:57 -04003198 if (ASIC_IS_DCE32(rdev)) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003199 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
3200 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003201 } else {
3202 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3203 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
3204 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003205 } else {
Alex Deucher6f34be52010-11-21 10:59:01 -05003206 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3207 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3208 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003209 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3210 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003211 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003212 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3213 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003214
Alex Deucher6f34be52010-11-21 10:59:01 -05003215 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3216 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3217 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3218 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3219 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003220 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003221 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003222 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003223 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003224 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003225 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003226 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003227 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003228 if (ASIC_IS_DCE3(rdev)) {
3229 tmp = RREG32(DC_HPD1_INT_CONTROL);
3230 tmp |= DC_HPDx_INT_ACK;
3231 WREG32(DC_HPD1_INT_CONTROL, tmp);
3232 } else {
3233 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3234 tmp |= DC_HPDx_INT_ACK;
3235 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3236 }
3237 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003238 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003239 if (ASIC_IS_DCE3(rdev)) {
3240 tmp = RREG32(DC_HPD2_INT_CONTROL);
3241 tmp |= DC_HPDx_INT_ACK;
3242 WREG32(DC_HPD2_INT_CONTROL, tmp);
3243 } else {
3244 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3245 tmp |= DC_HPDx_INT_ACK;
3246 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3247 }
3248 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003249 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003250 if (ASIC_IS_DCE3(rdev)) {
3251 tmp = RREG32(DC_HPD3_INT_CONTROL);
3252 tmp |= DC_HPDx_INT_ACK;
3253 WREG32(DC_HPD3_INT_CONTROL, tmp);
3254 } else {
3255 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3256 tmp |= DC_HPDx_INT_ACK;
3257 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3258 }
3259 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003260 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003261 tmp = RREG32(DC_HPD4_INT_CONTROL);
3262 tmp |= DC_HPDx_INT_ACK;
3263 WREG32(DC_HPD4_INT_CONTROL, tmp);
3264 }
3265 if (ASIC_IS_DCE32(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003266 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003267 tmp = RREG32(DC_HPD5_INT_CONTROL);
3268 tmp |= DC_HPDx_INT_ACK;
3269 WREG32(DC_HPD5_INT_CONTROL, tmp);
3270 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003271 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003272 tmp = RREG32(DC_HPD5_INT_CONTROL);
3273 tmp |= DC_HPDx_INT_ACK;
3274 WREG32(DC_HPD6_INT_CONTROL, tmp);
3275 }
Alex Deucherf122c612012-03-30 08:59:57 -04003276 if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003277 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
Alex Deucherf122c612012-03-30 08:59:57 -04003278 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003279 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003280 }
3281 if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003282 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003283 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003284 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Christian Koenigf2594932010-04-10 03:13:16 +02003285 }
3286 } else {
Alex Deucherf122c612012-03-30 08:59:57 -04003287 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3288 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
3289 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3290 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3291 }
3292 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3293 if (ASIC_IS_DCE3(rdev)) {
3294 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
3295 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3296 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
3297 } else {
3298 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
3299 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3300 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
3301 }
Christian Koenigf2594932010-04-10 03:13:16 +02003302 }
3303 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003304}
3305
3306void r600_irq_disable(struct radeon_device *rdev)
3307{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003308 r600_disable_interrupts(rdev);
3309 /* Wait and acknowledge irq */
3310 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003311 r600_irq_ack(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003312 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003313}
3314
Andi Kleence580fa2011-10-13 16:08:47 -07003315static u32 r600_get_ih_wptr(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003316{
3317 u32 wptr, tmp;
3318
Alex Deucher724c80e2010-08-27 18:25:25 -04003319 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04003320 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04003321 else
3322 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003323
3324 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003325 /* When a ring buffer overflow happen start parsing interrupt
3326 * from the last not overwritten vector (wptr + 16). Hopefully
3327 * this should allow us to catchup.
3328 */
3329 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3330 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3331 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003332 tmp = RREG32(IH_RB_CNTL);
3333 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3334 WREG32(IH_RB_CNTL, tmp);
3335 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003336 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003337}
3338
3339/* r600 IV Ring
3340 * Each IV ring entry is 128 bits:
3341 * [7:0] - interrupt source id
3342 * [31:8] - reserved
3343 * [59:32] - interrupt source data
3344 * [127:60] - reserved
3345 *
3346 * The basic interrupt vector entries
3347 * are decoded as follows:
3348 * src_id src_data description
3349 * 1 0 D1 Vblank
3350 * 1 1 D1 Vline
3351 * 5 0 D2 Vblank
3352 * 5 1 D2 Vline
3353 * 19 0 FP Hot plug detection A
3354 * 19 1 FP Hot plug detection B
3355 * 19 2 DAC A auto-detection
3356 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003357 * 21 4 HDMI block A
3358 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003359 * 176 - CP_INT RB
3360 * 177 - CP_INT IB1
3361 * 178 - CP_INT IB2
3362 * 181 - EOP Interrupt
3363 * 233 - GUI Idle
3364 *
3365 * Note, these are based on r600 and may need to be
3366 * adjusted or added to on newer asics
3367 */
3368
3369int r600_irq_process(struct radeon_device *rdev)
3370{
Dave Airlie682f1a52011-06-18 03:59:51 +00003371 u32 wptr;
3372 u32 rptr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003373 u32 src_id, src_data;
Alex Deucher6f34be52010-11-21 10:59:01 -05003374 u32 ring_index;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003375 unsigned long flags;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003376 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04003377 bool queue_hdmi = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003378
Dave Airlie682f1a52011-06-18 03:59:51 +00003379 if (!rdev->ih.enabled || rdev->shutdown)
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003380 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003381
Benjamin Herrenschmidtf6a56932011-07-13 06:28:22 +00003382 /* No MSIs, need a dummy read to flush PCI DMAs */
3383 if (!rdev->msi_enabled)
3384 RREG32(IH_RB_WPTR);
3385
Dave Airlie682f1a52011-06-18 03:59:51 +00003386 wptr = r600_get_ih_wptr(rdev);
3387 rptr = rdev->ih.rptr;
3388 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
3389
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003390 spin_lock_irqsave(&rdev->ih.lock, flags);
3391
3392 if (rptr == wptr) {
3393 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3394 return IRQ_NONE;
3395 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003396
3397restart_ih:
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10003398 /* Order reading of wptr vs. reading of IH ring data */
3399 rmb();
3400
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003401 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05003402 r600_irq_ack(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003403
3404 rdev->ih.wptr = wptr;
3405 while (rptr != wptr) {
3406 /* wptr/rptr are in bytes! */
3407 ring_index = rptr / 4;
Cédric Cano4eace7f2011-02-11 19:45:38 -05003408 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3409 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003410
3411 switch (src_id) {
3412 case 1: /* D1 vblank/vline */
3413 switch (src_data) {
3414 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003415 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003416 if (rdev->irq.crtc_vblank_int[0]) {
3417 drm_handle_vblank(rdev->ddev, 0);
3418 rdev->pm.vblank_sync = true;
3419 wake_up(&rdev->irq.vblank_queue);
3420 }
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003421 if (rdev->irq.pflip[0])
3422 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003423 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003424 DRM_DEBUG("IH: D1 vblank\n");
3425 }
3426 break;
3427 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003428 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
3429 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003430 DRM_DEBUG("IH: D1 vline\n");
3431 }
3432 break;
3433 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003434 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003435 break;
3436 }
3437 break;
3438 case 5: /* D2 vblank/vline */
3439 switch (src_data) {
3440 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003441 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003442 if (rdev->irq.crtc_vblank_int[1]) {
3443 drm_handle_vblank(rdev->ddev, 1);
3444 rdev->pm.vblank_sync = true;
3445 wake_up(&rdev->irq.vblank_queue);
3446 }
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003447 if (rdev->irq.pflip[1])
3448 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003449 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003450 DRM_DEBUG("IH: D2 vblank\n");
3451 }
3452 break;
3453 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003454 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
3455 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003456 DRM_DEBUG("IH: D2 vline\n");
3457 }
3458 break;
3459 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003460 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003461 break;
3462 }
3463 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003464 case 19: /* HPD/DAC hotplug */
3465 switch (src_data) {
3466 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05003467 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
3468 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003469 queue_hotplug = true;
3470 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003471 }
3472 break;
3473 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05003474 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
3475 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003476 queue_hotplug = true;
3477 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003478 }
3479 break;
3480 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05003481 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
3482 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003483 queue_hotplug = true;
3484 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003485 }
3486 break;
3487 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05003488 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
3489 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003490 queue_hotplug = true;
3491 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003492 }
3493 break;
3494 case 10:
Alex Deucher6f34be52010-11-21 10:59:01 -05003495 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
3496 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003497 queue_hotplug = true;
3498 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003499 }
3500 break;
3501 case 12:
Alex Deucher6f34be52010-11-21 10:59:01 -05003502 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
3503 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003504 queue_hotplug = true;
3505 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003506 }
3507 break;
3508 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003509 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003510 break;
3511 }
3512 break;
Alex Deucherf122c612012-03-30 08:59:57 -04003513 case 21: /* hdmi */
3514 switch (src_data) {
3515 case 4:
3516 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3517 rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3518 queue_hdmi = true;
3519 DRM_DEBUG("IH: HDMI0\n");
3520 }
3521 break;
3522 case 5:
3523 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3524 rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3525 queue_hdmi = true;
3526 DRM_DEBUG("IH: HDMI1\n");
3527 }
3528 break;
3529 default:
3530 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
3531 break;
3532 }
Christian Koenigf2594932010-04-10 03:13:16 +02003533 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003534 case 176: /* CP_INT in ring buffer */
3535 case 177: /* CP_INT in IB1 */
3536 case 178: /* CP_INT in IB2 */
3537 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04003538 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003539 break;
3540 case 181: /* CP EOP event */
3541 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher74652802011-08-25 13:39:48 -04003542 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003543 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003544 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04003545 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04003546 rdev->pm.gui_idle = true;
3547 wake_up(&rdev->irq.idle_queue);
3548 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003549 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003550 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003551 break;
3552 }
3553
3554 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01003555 rptr += 16;
3556 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003557 }
3558 /* make sure wptr hasn't changed while processing */
3559 wptr = r600_get_ih_wptr(rdev);
3560 if (wptr != rdev->ih.wptr)
3561 goto restart_ih;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003562 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01003563 schedule_work(&rdev->hotplug_work);
Alex Deucherf122c612012-03-30 08:59:57 -04003564 if (queue_hdmi)
3565 schedule_work(&rdev->audio_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003566 rdev->ih.rptr = rptr;
3567 WREG32(IH_RB_RPTR, rdev->ih.rptr);
3568 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3569 return IRQ_HANDLED;
3570}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003571
3572/*
3573 * Debugfs info
3574 */
3575#if defined(CONFIG_DEBUG_FS)
3576
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003577static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3578{
3579 struct drm_info_node *node = (struct drm_info_node *) m->private;
3580 struct drm_device *dev = node->minor->dev;
3581 struct radeon_device *rdev = dev->dev_private;
3582
3583 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3584 DREG32_SYS(m, rdev, VM_L2_STATUS);
3585 return 0;
3586}
3587
3588static struct drm_info_list r600_mc_info_list[] = {
3589 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003590};
3591#endif
3592
3593int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3594{
3595#if defined(CONFIG_DEBUG_FS)
3596 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3597#else
3598 return 0;
3599#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003600}
Jerome Glisse062b3892010-02-04 20:36:39 +01003601
3602/**
3603 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3604 * rdev: radeon device structure
3605 * bo: buffer object struct which userspace is waiting for idle
3606 *
3607 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3608 * through ring buffer, this leads to corruption in rendering, see
3609 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3610 * directly perform HDP flush by writing register through MMIO.
3611 */
3612void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3613{
Alex Deucher812d0462010-07-26 18:51:53 -04003614 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
Alex Deucherf3886f82010-12-08 10:05:34 -05003615 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
3616 * This seems to cause problems on some AGP cards. Just use the old
3617 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04003618 */
Alex Deuchere4884592010-09-27 10:57:10 -04003619 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
Alex Deucherf3886f82010-12-08 10:05:34 -05003620 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04003621 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04003622 u32 tmp;
3623
3624 WREG32(HDP_DEBUG1, 0);
3625 tmp = readl((void __iomem *)ptr);
3626 } else
3627 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01003628}
Alex Deucher3313e3d2011-01-06 18:49:34 -05003629
3630void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
3631{
3632 u32 link_width_cntl, mask, target_reg;
3633
3634 if (rdev->flags & RADEON_IS_IGP)
3635 return;
3636
3637 if (!(rdev->flags & RADEON_IS_PCIE))
3638 return;
3639
3640 /* x2 cards have a special sequence */
3641 if (ASIC_IS_X2(rdev))
3642 return;
3643
3644 /* FIXME wait for idle */
3645
3646 switch (lanes) {
3647 case 0:
3648 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
3649 break;
3650 case 1:
3651 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
3652 break;
3653 case 2:
3654 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
3655 break;
3656 case 4:
3657 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
3658 break;
3659 case 8:
3660 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
3661 break;
3662 case 12:
3663 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
3664 break;
3665 case 16:
3666 default:
3667 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
3668 break;
3669 }
3670
3671 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
3672
3673 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
3674 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
3675 return;
3676
3677 if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS)
3678 return;
3679
3680 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
3681 RADEON_PCIE_LC_RECONFIG_NOW |
3682 R600_PCIE_LC_RENEGOTIATE_EN |
3683 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
3684 link_width_cntl |= mask;
3685
3686 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3687
3688 /* some northbridges can renegotiate the link rather than requiring
3689 * a complete re-config.
3690 * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.)
3691 */
3692 if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT)
3693 link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT;
3694 else
3695 link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE;
3696
3697 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
3698 RADEON_PCIE_LC_RECONFIG_NOW));
3699
3700 if (rdev->family >= CHIP_RV770)
3701 target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX;
3702 else
3703 target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX;
3704
3705 /* wait for lane set to complete */
3706 link_width_cntl = RREG32(target_reg);
3707 while (link_width_cntl == 0xffffffff)
3708 link_width_cntl = RREG32(target_reg);
3709
3710}
3711
3712int r600_get_pcie_lanes(struct radeon_device *rdev)
3713{
3714 u32 link_width_cntl;
3715
3716 if (rdev->flags & RADEON_IS_IGP)
3717 return 0;
3718
3719 if (!(rdev->flags & RADEON_IS_PCIE))
3720 return 0;
3721
3722 /* x2 cards have a special sequence */
3723 if (ASIC_IS_X2(rdev))
3724 return 0;
3725
3726 /* FIXME wait for idle */
3727
3728 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
3729
3730 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
3731 case RADEON_PCIE_LC_LINK_WIDTH_X0:
3732 return 0;
3733 case RADEON_PCIE_LC_LINK_WIDTH_X1:
3734 return 1;
3735 case RADEON_PCIE_LC_LINK_WIDTH_X2:
3736 return 2;
3737 case RADEON_PCIE_LC_LINK_WIDTH_X4:
3738 return 4;
3739 case RADEON_PCIE_LC_LINK_WIDTH_X8:
3740 return 8;
3741 case RADEON_PCIE_LC_LINK_WIDTH_X16:
3742 default:
3743 return 16;
3744 }
3745}
3746
Alex Deucher9e46a482011-01-06 18:49:35 -05003747static void r600_pcie_gen2_enable(struct radeon_device *rdev)
3748{
3749 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
3750 u16 link_cntl2;
3751
Alex Deucherd42dd572011-01-12 20:05:11 -05003752 if (radeon_pcie_gen2 == 0)
3753 return;
3754
Alex Deucher9e46a482011-01-06 18:49:35 -05003755 if (rdev->flags & RADEON_IS_IGP)
3756 return;
3757
3758 if (!(rdev->flags & RADEON_IS_PCIE))
3759 return;
3760
3761 /* x2 cards have a special sequence */
3762 if (ASIC_IS_X2(rdev))
3763 return;
3764
3765 /* only RV6xx+ chips are supported */
3766 if (rdev->family <= CHIP_R600)
3767 return;
3768
3769 /* 55 nm r6xx asics */
3770 if ((rdev->family == CHIP_RV670) ||
3771 (rdev->family == CHIP_RV620) ||
3772 (rdev->family == CHIP_RV635)) {
3773 /* advertise upconfig capability */
3774 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3775 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
3776 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3777 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3778 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
3779 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
3780 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
3781 LC_RECONFIG_ARC_MISSING_ESCAPE);
3782 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
3783 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3784 } else {
3785 link_width_cntl |= LC_UPCONFIGURE_DIS;
3786 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3787 }
3788 }
3789
3790 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3791 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
3792 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
3793
3794 /* 55 nm r6xx asics */
3795 if ((rdev->family == CHIP_RV670) ||
3796 (rdev->family == CHIP_RV620) ||
3797 (rdev->family == CHIP_RV635)) {
3798 WREG32(MM_CFGREGS_CNTL, 0x8);
3799 link_cntl2 = RREG32(0x4088);
3800 WREG32(MM_CFGREGS_CNTL, 0);
3801 /* not supported yet */
3802 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
3803 return;
3804 }
3805
3806 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
3807 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
3808 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
3809 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
3810 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
3811 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3812
3813 tmp = RREG32(0x541c);
3814 WREG32(0x541c, tmp | 0x8);
3815 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
3816 link_cntl2 = RREG16(0x4088);
3817 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
3818 link_cntl2 |= 0x2;
3819 WREG16(0x4088, link_cntl2);
3820 WREG32(MM_CFGREGS_CNTL, 0);
3821
3822 if ((rdev->family == CHIP_RV670) ||
3823 (rdev->family == CHIP_RV620) ||
3824 (rdev->family == CHIP_RV635)) {
3825 training_cntl = RREG32_PCIE_P(PCIE_LC_TRAINING_CNTL);
3826 training_cntl &= ~LC_POINT_7_PLUS_EN;
3827 WREG32_PCIE_P(PCIE_LC_TRAINING_CNTL, training_cntl);
3828 } else {
3829 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3830 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
3831 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3832 }
3833
3834 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3835 speed_cntl |= LC_GEN2_EN_STRAP;
3836 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3837
3838 } else {
3839 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3840 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
3841 if (1)
3842 link_width_cntl |= LC_UPCONFIGURE_DIS;
3843 else
3844 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
3845 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3846 }
3847}