blob: abb143c0bdca7816217a7b57f34887f910e46881 [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>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
34#include <drm/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
Alex Deucherf13f7732013-01-18 18:12:22 -050097static const u32 crtc_offsets[2] =
98{
99 0,
100 AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
101};
102
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000103int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200104
Jerome Glisse1a029b72009-10-06 19:04:30 +0200105/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200106int r600_mc_wait_for_idle(struct radeon_device *rdev);
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400107static void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000108void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -0400109void r600_irq_disable(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -0500110static void r600_pcie_gen2_enable(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200111
Alex Deucher21a81222010-07-02 12:58:16 -0400112/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500113int rv6xx_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400114{
115 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
116 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -0500117 int actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -0400118
Alex Deucher20d391d2011-02-01 16:12:34 -0500119 if (temp & 0x100)
120 actual_temp -= 256;
121
122 return actual_temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400123}
124
Alex Deucherce8f5372010-05-07 15:10:16 -0400125void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400126{
127 int i;
128
Alex Deucherce8f5372010-05-07 15:10:16 -0400129 rdev->pm.dynpm_can_upclock = true;
130 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400131
132 /* power state array is low to high, default is first */
133 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
134 int min_power_state_index = 0;
135
136 if (rdev->pm.num_power_states > 2)
137 min_power_state_index = 1;
138
Alex Deucherce8f5372010-05-07 15:10:16 -0400139 switch (rdev->pm.dynpm_planned_action) {
140 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400141 rdev->pm.requested_power_state_index = min_power_state_index;
142 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400143 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400144 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400145 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400146 if (rdev->pm.current_power_state_index == min_power_state_index) {
147 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400148 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400149 } else {
150 if (rdev->pm.active_crtc_count > 1) {
151 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400152 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400153 continue;
154 else if (i >= rdev->pm.current_power_state_index) {
155 rdev->pm.requested_power_state_index =
156 rdev->pm.current_power_state_index;
157 break;
158 } else {
159 rdev->pm.requested_power_state_index = i;
160 break;
161 }
162 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400163 } else {
164 if (rdev->pm.current_power_state_index == 0)
165 rdev->pm.requested_power_state_index =
166 rdev->pm.num_power_states - 1;
167 else
168 rdev->pm.requested_power_state_index =
169 rdev->pm.current_power_state_index - 1;
170 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400171 }
172 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400173 /* don't use the power state if crtcs are active and no display flag is set */
174 if ((rdev->pm.active_crtc_count > 0) &&
175 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
176 clock_info[rdev->pm.requested_clock_mode_index].flags &
177 RADEON_PM_MODE_NO_DISPLAY)) {
178 rdev->pm.requested_power_state_index++;
179 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400180 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400181 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400182 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
183 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400184 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400185 } else {
186 if (rdev->pm.active_crtc_count > 1) {
187 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400188 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400189 continue;
190 else if (i <= rdev->pm.current_power_state_index) {
191 rdev->pm.requested_power_state_index =
192 rdev->pm.current_power_state_index;
193 break;
194 } else {
195 rdev->pm.requested_power_state_index = i;
196 break;
197 }
198 }
199 } else
200 rdev->pm.requested_power_state_index =
201 rdev->pm.current_power_state_index + 1;
202 }
203 rdev->pm.requested_clock_mode_index = 0;
204 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400205 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400206 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
207 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400208 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400209 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400210 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400211 default:
212 DRM_ERROR("Requested mode for not defined action\n");
213 return;
214 }
215 } else {
216 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
217 /* for now just select the first power state and switch between clock modes */
218 /* power state array is low to high, default is first (0) */
219 if (rdev->pm.active_crtc_count > 1) {
220 rdev->pm.requested_power_state_index = -1;
221 /* start at 1 as we don't want the default mode */
222 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400223 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400224 continue;
225 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
226 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
227 rdev->pm.requested_power_state_index = i;
228 break;
229 }
230 }
231 /* if nothing selected, grab the default state. */
232 if (rdev->pm.requested_power_state_index == -1)
233 rdev->pm.requested_power_state_index = 0;
234 } else
235 rdev->pm.requested_power_state_index = 1;
236
Alex Deucherce8f5372010-05-07 15:10:16 -0400237 switch (rdev->pm.dynpm_planned_action) {
238 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400239 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 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400242 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400243 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
244 if (rdev->pm.current_clock_mode_index == 0) {
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 } else
248 rdev->pm.requested_clock_mode_index =
249 rdev->pm.current_clock_mode_index - 1;
250 } else {
251 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400252 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400253 }
Alex Deucherd7311172010-05-03 01:13:14 -0400254 /* don't use the power state if crtcs are active and no display flag is set */
255 if ((rdev->pm.active_crtc_count > 0) &&
256 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
257 clock_info[rdev->pm.requested_clock_mode_index].flags &
258 RADEON_PM_MODE_NO_DISPLAY)) {
259 rdev->pm.requested_clock_mode_index++;
260 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400261 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400262 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400263 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
264 if (rdev->pm.current_clock_mode_index ==
265 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
266 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400267 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400268 } else
269 rdev->pm.requested_clock_mode_index =
270 rdev->pm.current_clock_mode_index + 1;
271 } else {
272 rdev->pm.requested_clock_mode_index =
273 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400274 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400275 }
276 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400277 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400278 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
279 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400280 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400281 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400282 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400283 default:
284 DRM_ERROR("Requested mode for not defined action\n");
285 return;
286 }
287 }
288
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000289 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400290 rdev->pm.power_state[rdev->pm.requested_power_state_index].
291 clock_info[rdev->pm.requested_clock_mode_index].sclk,
292 rdev->pm.power_state[rdev->pm.requested_power_state_index].
293 clock_info[rdev->pm.requested_clock_mode_index].mclk,
294 rdev->pm.power_state[rdev->pm.requested_power_state_index].
295 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400296}
297
Alex Deucherce8f5372010-05-07 15:10:16 -0400298void rs780_pm_init_profile(struct radeon_device *rdev)
299{
300 if (rdev->pm.num_power_states == 2) {
301 /* default */
302 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
303 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
304 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
305 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
306 /* low sh */
307 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
308 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
309 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
310 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400311 /* mid sh */
312 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
313 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
314 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
315 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400316 /* high sh */
317 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
318 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
319 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
320 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
321 /* low mh */
322 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
323 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
325 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400326 /* mid mh */
327 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
328 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
330 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400331 /* high mh */
332 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
333 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
334 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
335 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
336 } else if (rdev->pm.num_power_states == 3) {
337 /* default */
338 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
339 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
340 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
341 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
342 /* low sh */
343 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
344 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
345 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
346 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400347 /* mid sh */
348 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
349 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
350 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
351 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400352 /* high sh */
353 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
354 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
355 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
356 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
357 /* low mh */
358 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
359 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
360 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
361 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400362 /* mid mh */
363 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
364 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
365 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
366 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400367 /* high mh */
368 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
369 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
370 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
371 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
372 } else {
373 /* default */
374 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
375 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
376 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
377 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
378 /* low sh */
379 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
380 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
381 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
382 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400383 /* mid sh */
384 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
385 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
386 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
387 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400388 /* high sh */
389 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
390 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
391 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
392 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
393 /* low mh */
394 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
395 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
396 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
397 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400398 /* mid mh */
399 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
400 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
401 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
402 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400403 /* high mh */
404 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
405 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
406 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
407 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
408 }
409}
410
411void r600_pm_init_profile(struct radeon_device *rdev)
412{
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400413 int idx;
414
Alex Deucherce8f5372010-05-07 15:10:16 -0400415 if (rdev->family == CHIP_R600) {
416 /* XXX */
417 /* default */
418 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
419 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
420 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400421 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400422 /* low sh */
423 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
424 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
425 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400426 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400427 /* mid sh */
428 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
429 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
430 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
431 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400432 /* high sh */
433 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
435 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400436 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400437 /* low mh */
438 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
440 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400441 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400442 /* mid mh */
443 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
445 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
446 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400447 /* high mh */
448 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
449 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
450 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400451 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400452 } else {
453 if (rdev->pm.num_power_states < 4) {
454 /* default */
455 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
456 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
457 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
458 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
459 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400460 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
461 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
462 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400463 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
464 /* mid sh */
465 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
466 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
467 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
468 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400469 /* high sh */
470 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
471 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
472 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
473 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
474 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400475 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
476 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400477 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400478 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
479 /* low mh */
480 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
481 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
482 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
483 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400484 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400485 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
486 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
487 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
488 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
489 } else {
490 /* default */
491 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
492 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
493 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
494 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
495 /* low sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400496 if (rdev->flags & RADEON_IS_MOBILITY)
497 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
498 else
499 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
500 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
501 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
502 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
503 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400504 /* mid sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400505 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
506 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
507 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
508 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400509 /* high sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400510 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
511 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
512 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
Alex Deucher4bff5172010-05-17 19:41:26 -0400513 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
514 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
515 /* low mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400516 if (rdev->flags & RADEON_IS_MOBILITY)
517 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
518 else
519 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
520 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
521 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
522 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
523 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400524 /* mid mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400525 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
526 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
527 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
528 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400529 /* high mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400530 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
531 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
532 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
Alex Deucherce8f5372010-05-07 15:10:16 -0400533 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
534 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
535 }
536 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400537}
538
Alex Deucher49e02b72010-04-23 17:57:27 -0400539void r600_pm_misc(struct radeon_device *rdev)
540{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400541 int req_ps_idx = rdev->pm.requested_power_state_index;
542 int req_cm_idx = rdev->pm.requested_clock_mode_index;
543 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
544 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400545
Alex Deucher4d601732010-06-07 18:15:18 -0400546 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
Alex Deuchera377e182011-06-20 13:00:31 -0400547 /* 0xff01 is a flag rather then an actual voltage */
548 if (voltage->voltage == 0xff01)
549 return;
Alex Deucher4d601732010-06-07 18:15:18 -0400550 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400551 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400552 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000553 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400554 }
555 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400556}
557
Alex Deucherdef9ba92010-04-22 12:39:58 -0400558bool r600_gui_idle(struct radeon_device *rdev)
559{
560 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
561 return false;
562 else
563 return true;
564}
565
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500566/* hpd for digital panel detect/disconnect */
567bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
568{
569 bool connected = false;
570
571 if (ASIC_IS_DCE3(rdev)) {
572 switch (hpd) {
573 case RADEON_HPD_1:
574 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
575 connected = true;
576 break;
577 case RADEON_HPD_2:
578 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
579 connected = true;
580 break;
581 case RADEON_HPD_3:
582 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
583 connected = true;
584 break;
585 case RADEON_HPD_4:
586 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
587 connected = true;
588 break;
589 /* DCE 3.2 */
590 case RADEON_HPD_5:
591 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
592 connected = true;
593 break;
594 case RADEON_HPD_6:
595 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
596 connected = true;
597 break;
598 default:
599 break;
600 }
601 } else {
602 switch (hpd) {
603 case RADEON_HPD_1:
604 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
605 connected = true;
606 break;
607 case RADEON_HPD_2:
608 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
609 connected = true;
610 break;
611 case RADEON_HPD_3:
612 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
613 connected = true;
614 break;
615 default:
616 break;
617 }
618 }
619 return connected;
620}
621
622void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500623 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500624{
625 u32 tmp;
626 bool connected = r600_hpd_sense(rdev, hpd);
627
628 if (ASIC_IS_DCE3(rdev)) {
629 switch (hpd) {
630 case RADEON_HPD_1:
631 tmp = RREG32(DC_HPD1_INT_CONTROL);
632 if (connected)
633 tmp &= ~DC_HPDx_INT_POLARITY;
634 else
635 tmp |= DC_HPDx_INT_POLARITY;
636 WREG32(DC_HPD1_INT_CONTROL, tmp);
637 break;
638 case RADEON_HPD_2:
639 tmp = RREG32(DC_HPD2_INT_CONTROL);
640 if (connected)
641 tmp &= ~DC_HPDx_INT_POLARITY;
642 else
643 tmp |= DC_HPDx_INT_POLARITY;
644 WREG32(DC_HPD2_INT_CONTROL, tmp);
645 break;
646 case RADEON_HPD_3:
647 tmp = RREG32(DC_HPD3_INT_CONTROL);
648 if (connected)
649 tmp &= ~DC_HPDx_INT_POLARITY;
650 else
651 tmp |= DC_HPDx_INT_POLARITY;
652 WREG32(DC_HPD3_INT_CONTROL, tmp);
653 break;
654 case RADEON_HPD_4:
655 tmp = RREG32(DC_HPD4_INT_CONTROL);
656 if (connected)
657 tmp &= ~DC_HPDx_INT_POLARITY;
658 else
659 tmp |= DC_HPDx_INT_POLARITY;
660 WREG32(DC_HPD4_INT_CONTROL, tmp);
661 break;
662 case RADEON_HPD_5:
663 tmp = RREG32(DC_HPD5_INT_CONTROL);
664 if (connected)
665 tmp &= ~DC_HPDx_INT_POLARITY;
666 else
667 tmp |= DC_HPDx_INT_POLARITY;
668 WREG32(DC_HPD5_INT_CONTROL, tmp);
669 break;
670 /* DCE 3.2 */
671 case RADEON_HPD_6:
672 tmp = RREG32(DC_HPD6_INT_CONTROL);
673 if (connected)
674 tmp &= ~DC_HPDx_INT_POLARITY;
675 else
676 tmp |= DC_HPDx_INT_POLARITY;
677 WREG32(DC_HPD6_INT_CONTROL, tmp);
678 break;
679 default:
680 break;
681 }
682 } else {
683 switch (hpd) {
684 case RADEON_HPD_1:
685 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
686 if (connected)
687 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
688 else
689 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
690 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
691 break;
692 case RADEON_HPD_2:
693 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
694 if (connected)
695 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
696 else
697 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
698 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
699 break;
700 case RADEON_HPD_3:
701 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
702 if (connected)
703 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
704 else
705 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
706 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
707 break;
708 default:
709 break;
710 }
711 }
712}
713
714void r600_hpd_init(struct radeon_device *rdev)
715{
716 struct drm_device *dev = rdev->ddev;
717 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200718 unsigned enable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500719
Alex Deucher64912e92011-11-03 11:21:39 -0400720 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
721 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500722
Jerome Glisse455c89b2012-05-04 11:06:22 -0400723 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
724 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
725 /* don't try to enable hpd on eDP or LVDS avoid breaking the
726 * aux dp channel on imac and help (but not completely fix)
727 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
728 */
729 continue;
730 }
Alex Deucher64912e92011-11-03 11:21:39 -0400731 if (ASIC_IS_DCE3(rdev)) {
732 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
733 if (ASIC_IS_DCE32(rdev))
734 tmp |= DC_HPDx_EN;
735
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500736 switch (radeon_connector->hpd.hpd) {
737 case RADEON_HPD_1:
738 WREG32(DC_HPD1_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500739 break;
740 case RADEON_HPD_2:
741 WREG32(DC_HPD2_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500742 break;
743 case RADEON_HPD_3:
744 WREG32(DC_HPD3_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500745 break;
746 case RADEON_HPD_4:
747 WREG32(DC_HPD4_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500748 break;
749 /* DCE 3.2 */
750 case RADEON_HPD_5:
751 WREG32(DC_HPD5_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500752 break;
753 case RADEON_HPD_6:
754 WREG32(DC_HPD6_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500755 break;
756 default:
757 break;
758 }
Alex Deucher64912e92011-11-03 11:21:39 -0400759 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500760 switch (radeon_connector->hpd.hpd) {
761 case RADEON_HPD_1:
762 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500763 break;
764 case RADEON_HPD_2:
765 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500766 break;
767 case RADEON_HPD_3:
768 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500769 break;
770 default:
771 break;
772 }
773 }
Christian Koenigfb982572012-05-17 01:33:30 +0200774 enable |= 1 << radeon_connector->hpd.hpd;
Alex Deucher64912e92011-11-03 11:21:39 -0400775 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500776 }
Christian Koenigfb982572012-05-17 01:33:30 +0200777 radeon_irq_kms_enable_hpd(rdev, enable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500778}
779
780void r600_hpd_fini(struct radeon_device *rdev)
781{
782 struct drm_device *dev = rdev->ddev;
783 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200784 unsigned disable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500785
Christian Koenigfb982572012-05-17 01:33:30 +0200786 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
787 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
788 if (ASIC_IS_DCE3(rdev)) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500789 switch (radeon_connector->hpd.hpd) {
790 case RADEON_HPD_1:
791 WREG32(DC_HPD1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500792 break;
793 case RADEON_HPD_2:
794 WREG32(DC_HPD2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500795 break;
796 case RADEON_HPD_3:
797 WREG32(DC_HPD3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500798 break;
799 case RADEON_HPD_4:
800 WREG32(DC_HPD4_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500801 break;
802 /* DCE 3.2 */
803 case RADEON_HPD_5:
804 WREG32(DC_HPD5_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500805 break;
806 case RADEON_HPD_6:
807 WREG32(DC_HPD6_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500808 break;
809 default:
810 break;
811 }
Christian Koenigfb982572012-05-17 01:33:30 +0200812 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500813 switch (radeon_connector->hpd.hpd) {
814 case RADEON_HPD_1:
815 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500816 break;
817 case RADEON_HPD_2:
818 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500819 break;
820 case RADEON_HPD_3:
821 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500822 break;
823 default:
824 break;
825 }
826 }
Christian Koenigfb982572012-05-17 01:33:30 +0200827 disable |= 1 << radeon_connector->hpd.hpd;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500828 }
Christian Koenigfb982572012-05-17 01:33:30 +0200829 radeon_irq_kms_disable_hpd(rdev, disable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500830}
831
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200832/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000833 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200834 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000835void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200836{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000837 unsigned i;
838 u32 tmp;
839
Dave Airlie2e98f102010-02-15 15:54:45 +1000840 /* flush hdp cache so updates hit vram */
Alex Deucherf3886f82010-12-08 10:05:34 -0500841 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
842 !(rdev->flags & RADEON_IS_AGP)) {
Jerome Glissec9a1be92011-11-03 11:16:49 -0400843 void __iomem *ptr = (void *)rdev->gart.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -0400844 u32 tmp;
845
846 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
847 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
Alex Deucherf3886f82010-12-08 10:05:34 -0500848 * This seems to cause problems on some AGP cards. Just use the old
849 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -0400850 */
851 WREG32(HDP_DEBUG1, 0);
852 tmp = readl((void __iomem *)ptr);
853 } else
854 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +1000855
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000856 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
857 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
858 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
859 for (i = 0; i < rdev->usec_timeout; i++) {
860 /* read MC_STATUS */
861 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
862 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
863 if (tmp == 2) {
864 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
865 return;
866 }
867 if (tmp) {
868 return;
869 }
870 udelay(1);
871 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200872}
873
Jerome Glisse4aac0472009-09-14 18:29:49 +0200874int r600_pcie_gart_init(struct radeon_device *rdev)
875{
876 int r;
877
Jerome Glissec9a1be92011-11-03 11:16:49 -0400878 if (rdev->gart.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +0000879 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +0200880 return 0;
881 }
882 /* Initialize common gart structure */
883 r = radeon_gart_init(rdev);
884 if (r)
885 return r;
886 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
887 return radeon_gart_table_vram_alloc(rdev);
888}
889
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400890static int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200891{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000892 u32 tmp;
893 int r, i;
894
Jerome Glissec9a1be92011-11-03 11:16:49 -0400895 if (rdev->gart.robj == NULL) {
Jerome Glisse4aac0472009-09-14 18:29:49 +0200896 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
897 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000898 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200899 r = radeon_gart_table_vram_pin(rdev);
900 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000901 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000902 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000903
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000904 /* Setup L2 cache */
905 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
906 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
907 EFFECTIVE_L2_QUEUE_SIZE(7));
908 WREG32(VM_L2_CNTL2, 0);
909 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
910 /* Setup TLB control */
911 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
912 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
913 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
914 ENABLE_WAIT_L2_QUERY;
915 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
916 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
917 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
918 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
919 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
920 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
921 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
922 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
923 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
924 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
925 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
926 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
927 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
928 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
929 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200930 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000931 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
932 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
933 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
934 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
935 (u32)(rdev->dummy_page.addr >> 12));
936 for (i = 1; i < 7; i++)
937 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
938
939 r600_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000940 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
941 (unsigned)(rdev->mc.gtt_size >> 20),
942 (unsigned long long)rdev->gart.table_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000943 rdev->gart.ready = true;
944 return 0;
945}
946
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400947static void r600_pcie_gart_disable(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000948{
949 u32 tmp;
Jerome Glissec9a1be92011-11-03 11:16:49 -0400950 int i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000951
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000952 /* Disable all tables */
953 for (i = 0; i < 7; i++)
954 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
955
956 /* Disable L2 cache */
957 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
958 EFFECTIVE_L2_QUEUE_SIZE(7));
959 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
960 /* Setup L1 TLB control */
961 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
962 ENABLE_WAIT_L2_QUERY;
963 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
964 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
965 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
966 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
967 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
968 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
969 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
970 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
971 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
972 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
973 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
974 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
975 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
976 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -0400977 radeon_gart_table_vram_unpin(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200978}
979
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400980static void r600_pcie_gart_fini(struct radeon_device *rdev)
Jerome Glisse4aac0472009-09-14 18:29:49 +0200981{
Jerome Glissef9274562010-03-17 14:44:29 +0000982 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200983 r600_pcie_gart_disable(rdev);
984 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200985}
986
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400987static void r600_agp_enable(struct radeon_device *rdev)
Jerome Glisse1a029b72009-10-06 19:04:30 +0200988{
989 u32 tmp;
990 int i;
991
992 /* Setup L2 cache */
993 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
994 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
995 EFFECTIVE_L2_QUEUE_SIZE(7));
996 WREG32(VM_L2_CNTL2, 0);
997 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
998 /* Setup TLB control */
999 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1000 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1001 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1002 ENABLE_WAIT_L2_QUERY;
1003 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1004 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1005 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1006 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1007 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1008 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1009 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1010 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1011 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1012 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1013 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1014 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1015 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1016 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1017 for (i = 0; i < 7; i++)
1018 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1019}
1020
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001021int r600_mc_wait_for_idle(struct radeon_device *rdev)
1022{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001023 unsigned i;
1024 u32 tmp;
1025
1026 for (i = 0; i < rdev->usec_timeout; i++) {
1027 /* read MC_STATUS */
1028 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1029 if (!tmp)
1030 return 0;
1031 udelay(1);
1032 }
1033 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001034}
1035
Jerome Glissea3c19452009-10-01 18:02:13 +02001036static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037{
Jerome Glissea3c19452009-10-01 18:02:13 +02001038 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001039 u32 tmp;
1040 int i, j;
1041
1042 /* Initialize HDP */
1043 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1044 WREG32((0x2c14 + j), 0x00000000);
1045 WREG32((0x2c18 + j), 0x00000000);
1046 WREG32((0x2c1c + j), 0x00000000);
1047 WREG32((0x2c20 + j), 0x00000000);
1048 WREG32((0x2c24 + j), 0x00000000);
1049 }
1050 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1051
Jerome Glissea3c19452009-10-01 18:02:13 +02001052 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001053 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001054 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001055 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001056 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001057 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001058 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001059 if (rdev->flags & RADEON_IS_AGP) {
1060 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1061 /* VRAM before AGP */
1062 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1063 rdev->mc.vram_start >> 12);
1064 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1065 rdev->mc.gtt_end >> 12);
1066 } else {
1067 /* VRAM after AGP */
1068 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1069 rdev->mc.gtt_start >> 12);
1070 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1071 rdev->mc.vram_end >> 12);
1072 }
1073 } else {
1074 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1075 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1076 }
Alex Deucher16cdf042011-10-28 10:30:02 -04001077 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001078 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001079 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1080 WREG32(MC_VM_FB_LOCATION, tmp);
1081 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1082 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001083 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001084 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001085 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1086 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001087 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1088 } else {
1089 WREG32(MC_VM_AGP_BASE, 0);
1090 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1091 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1092 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001093 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001094 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001095 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001096 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001097 /* we need to own VRAM, so turn off the VGA renderer here
1098 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001099 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001100}
1101
Jerome Glissed594e462010-02-17 21:54:29 +00001102/**
1103 * r600_vram_gtt_location - try to find VRAM & GTT location
1104 * @rdev: radeon device structure holding all necessary informations
1105 * @mc: memory controller structure holding memory informations
1106 *
1107 * Function will place try to place VRAM at same place as in CPU (PCI)
1108 * address space as some GPU seems to have issue when we reprogram at
1109 * different address space.
1110 *
1111 * If there is not enough space to fit the unvisible VRAM after the
1112 * aperture then we limit the VRAM size to the aperture.
1113 *
1114 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1115 * them to be in one from GPU point of view so that we can program GPU to
1116 * catch access outside them (weird GPU policy see ??).
1117 *
1118 * This function will never fails, worst case are limiting VRAM or GTT.
1119 *
1120 * Note: GTT start, end, size should be initialized before calling this
1121 * function on AGP platform.
1122 */
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001123static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
Jerome Glissed594e462010-02-17 21:54:29 +00001124{
1125 u64 size_bf, size_af;
1126
1127 if (mc->mc_vram_size > 0xE0000000) {
1128 /* leave room for at least 512M GTT */
1129 dev_warn(rdev->dev, "limiting VRAM\n");
1130 mc->real_vram_size = 0xE0000000;
1131 mc->mc_vram_size = 0xE0000000;
1132 }
1133 if (rdev->flags & RADEON_IS_AGP) {
1134 size_bf = mc->gtt_start;
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001135 size_af = 0xFFFFFFFF - mc->gtt_end;
Jerome Glissed594e462010-02-17 21:54:29 +00001136 if (size_bf > size_af) {
1137 if (mc->mc_vram_size > size_bf) {
1138 dev_warn(rdev->dev, "limiting VRAM\n");
1139 mc->real_vram_size = size_bf;
1140 mc->mc_vram_size = size_bf;
1141 }
1142 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1143 } else {
1144 if (mc->mc_vram_size > size_af) {
1145 dev_warn(rdev->dev, "limiting VRAM\n");
1146 mc->real_vram_size = size_af;
1147 mc->mc_vram_size = size_af;
1148 }
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001149 mc->vram_start = mc->gtt_end + 1;
Jerome Glissed594e462010-02-17 21:54:29 +00001150 }
1151 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1152 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1153 mc->mc_vram_size >> 20, mc->vram_start,
1154 mc->vram_end, mc->real_vram_size >> 20);
1155 } else {
1156 u64 base = 0;
Alex Deucher8961d522010-12-03 14:37:22 -05001157 if (rdev->flags & RADEON_IS_IGP) {
1158 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1159 base <<= 24;
1160 }
Jerome Glissed594e462010-02-17 21:54:29 +00001161 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001162 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001163 radeon_gtt_location(rdev, mc);
1164 }
1165}
1166
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001167static int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001168{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001169 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001170 int chansize, numchan;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001171
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001172 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001173 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001174 tmp = RREG32(RAMCFG);
1175 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001177 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001178 chansize = 64;
1179 } else {
1180 chansize = 32;
1181 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001182 tmp = RREG32(CHMAP);
1183 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1184 case 0:
1185 default:
1186 numchan = 1;
1187 break;
1188 case 1:
1189 numchan = 2;
1190 break;
1191 case 2:
1192 numchan = 4;
1193 break;
1194 case 3:
1195 numchan = 8;
1196 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001197 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001198 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001199 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001200 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1201 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001202 /* Setup GPU memory space */
1203 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1204 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001205 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001206 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001207
Alex Deucherf8920342010-06-30 12:02:03 -04001208 if (rdev->flags & RADEON_IS_IGP) {
1209 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001210 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Alex Deucherf8920342010-06-30 12:02:03 -04001211 }
Alex Deucherf47299c2010-03-16 20:54:38 -04001212 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001213 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001214}
1215
Alex Deucher16cdf042011-10-28 10:30:02 -04001216int r600_vram_scratch_init(struct radeon_device *rdev)
1217{
1218 int r;
1219
1220 if (rdev->vram_scratch.robj == NULL) {
1221 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1222 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Alex Deucher40f5cf92012-05-10 18:33:13 -04001223 NULL, &rdev->vram_scratch.robj);
Alex Deucher16cdf042011-10-28 10:30:02 -04001224 if (r) {
1225 return r;
1226 }
1227 }
1228
1229 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1230 if (unlikely(r != 0))
1231 return r;
1232 r = radeon_bo_pin(rdev->vram_scratch.robj,
1233 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1234 if (r) {
1235 radeon_bo_unreserve(rdev->vram_scratch.robj);
1236 return r;
1237 }
1238 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1239 (void **)&rdev->vram_scratch.ptr);
1240 if (r)
1241 radeon_bo_unpin(rdev->vram_scratch.robj);
1242 radeon_bo_unreserve(rdev->vram_scratch.robj);
1243
1244 return r;
1245}
1246
1247void r600_vram_scratch_fini(struct radeon_device *rdev)
1248{
1249 int r;
1250
1251 if (rdev->vram_scratch.robj == NULL) {
1252 return;
1253 }
1254 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1255 if (likely(r == 0)) {
1256 radeon_bo_kunmap(rdev->vram_scratch.robj);
1257 radeon_bo_unpin(rdev->vram_scratch.robj);
1258 radeon_bo_unreserve(rdev->vram_scratch.robj);
1259 }
1260 radeon_bo_unref(&rdev->vram_scratch.robj);
1261}
1262
Alex Deucher410a3412013-01-18 13:05:39 -05001263void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung)
1264{
1265 u32 tmp = RREG32(R600_BIOS_3_SCRATCH);
1266
1267 if (hung)
1268 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1269 else
1270 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1271
1272 WREG32(R600_BIOS_3_SCRATCH, tmp);
1273}
1274
Alex Deucherd3cb7812013-01-18 13:53:37 -05001275static void r600_print_gpu_status_regs(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001276{
Jerome Glisse64c56e82013-01-02 17:30:35 -05001277 dev_info(rdev->dev, " R_008010_GRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001278 RREG32(R_008010_GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001279 dev_info(rdev->dev, " R_008014_GRBM_STATUS2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001280 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001281 dev_info(rdev->dev, " R_000E50_SRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001282 RREG32(R_000E50_SRBM_STATUS));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001283 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001284 RREG32(CP_STALLED_STAT1));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001285 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001286 RREG32(CP_STALLED_STAT2));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001287 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001288 RREG32(CP_BUSY_STAT));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001289 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001290 RREG32(CP_STAT));
Alex Deucher71e3d152013-01-03 12:20:35 -05001291 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1292 RREG32(DMA_STATUS_REG));
1293}
1294
Alex Deucherf13f7732013-01-18 18:12:22 -05001295static bool r600_is_display_hung(struct radeon_device *rdev)
1296{
1297 u32 crtc_hung = 0;
1298 u32 crtc_status[2];
1299 u32 i, j, tmp;
1300
1301 for (i = 0; i < rdev->num_crtc; i++) {
1302 if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[i]) & AVIVO_CRTC_EN) {
1303 crtc_status[i] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1304 crtc_hung |= (1 << i);
1305 }
1306 }
1307
1308 for (j = 0; j < 10; j++) {
1309 for (i = 0; i < rdev->num_crtc; i++) {
1310 if (crtc_hung & (1 << i)) {
1311 tmp = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1312 if (tmp != crtc_status[i])
1313 crtc_hung &= ~(1 << i);
1314 }
1315 }
1316 if (crtc_hung == 0)
1317 return false;
1318 udelay(100);
1319 }
1320
1321 return true;
1322}
1323
1324static u32 r600_gpu_check_soft_reset(struct radeon_device *rdev)
1325{
1326 u32 reset_mask = 0;
1327 u32 tmp;
1328
1329 /* GRBM_STATUS */
1330 tmp = RREG32(R_008010_GRBM_STATUS);
1331 if (rdev->family >= CHIP_RV770) {
1332 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1333 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1334 G_008010_TA_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1335 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1336 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1337 reset_mask |= RADEON_RESET_GFX;
1338 } else {
1339 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1340 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1341 G_008010_TA03_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1342 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1343 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1344 reset_mask |= RADEON_RESET_GFX;
1345 }
1346
1347 if (G_008010_CF_RQ_PENDING(tmp) | G_008010_PF_RQ_PENDING(tmp) |
1348 G_008010_CP_BUSY(tmp) | G_008010_CP_COHERENCY_BUSY(tmp))
1349 reset_mask |= RADEON_RESET_CP;
1350
1351 if (G_008010_GRBM_EE_BUSY(tmp))
1352 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
1353
1354 /* DMA_STATUS_REG */
1355 tmp = RREG32(DMA_STATUS_REG);
1356 if (!(tmp & DMA_IDLE))
1357 reset_mask |= RADEON_RESET_DMA;
1358
1359 /* SRBM_STATUS */
1360 tmp = RREG32(R_000E50_SRBM_STATUS);
1361 if (G_000E50_RLC_RQ_PENDING(tmp) | G_000E50_RLC_BUSY(tmp))
1362 reset_mask |= RADEON_RESET_RLC;
1363
1364 if (G_000E50_IH_BUSY(tmp))
1365 reset_mask |= RADEON_RESET_IH;
1366
1367 if (G_000E50_SEM_BUSY(tmp))
1368 reset_mask |= RADEON_RESET_SEM;
1369
1370 if (G_000E50_GRBM_RQ_PENDING(tmp))
1371 reset_mask |= RADEON_RESET_GRBM;
1372
1373 if (G_000E50_VMC_BUSY(tmp))
1374 reset_mask |= RADEON_RESET_VMC;
1375
1376 if (G_000E50_MCB_BUSY(tmp) | G_000E50_MCDZ_BUSY(tmp) |
1377 G_000E50_MCDY_BUSY(tmp) | G_000E50_MCDX_BUSY(tmp) |
1378 G_000E50_MCDW_BUSY(tmp))
1379 reset_mask |= RADEON_RESET_MC;
1380
1381 if (r600_is_display_hung(rdev))
1382 reset_mask |= RADEON_RESET_DISPLAY;
1383
1384 return reset_mask;
1385}
1386
1387static void r600_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher71e3d152013-01-03 12:20:35 -05001388{
1389 struct rv515_mc_save save;
Alex Deucherd3cb7812013-01-18 13:53:37 -05001390 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
1391 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05001392
Alex Deucher71e3d152013-01-03 12:20:35 -05001393 if (reset_mask == 0)
Alex Deucherf13f7732013-01-18 18:12:22 -05001394 return;
Alex Deucher71e3d152013-01-03 12:20:35 -05001395
1396 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
1397
Alex Deucherd3cb7812013-01-18 13:53:37 -05001398 r600_print_gpu_status_regs(rdev);
1399
Alex Deucherd3cb7812013-01-18 13:53:37 -05001400 /* Disable CP parsing/prefetching */
1401 if (rdev->family >= CHIP_RV770)
1402 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
1403 else
1404 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher71e3d152013-01-03 12:20:35 -05001405
Alex Deucherd3cb7812013-01-18 13:53:37 -05001406 /* disable the RLC */
1407 WREG32(RLC_CNTL, 0);
1408
1409 if (reset_mask & RADEON_RESET_DMA) {
1410 /* Disable DMA */
1411 tmp = RREG32(DMA_RB_CNTL);
1412 tmp &= ~DMA_RB_ENABLE;
1413 WREG32(DMA_RB_CNTL, tmp);
1414 }
1415
1416 mdelay(50);
1417
Alex Deucherca578022013-01-23 18:56:08 -05001418 rv515_mc_stop(rdev, &save);
1419 if (r600_mc_wait_for_idle(rdev)) {
1420 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1421 }
1422
Alex Deucherd3cb7812013-01-18 13:53:37 -05001423 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
1424 if (rdev->family >= CHIP_RV770)
1425 grbm_soft_reset |= S_008020_SOFT_RESET_DB(1) |
1426 S_008020_SOFT_RESET_CB(1) |
1427 S_008020_SOFT_RESET_PA(1) |
1428 S_008020_SOFT_RESET_SC(1) |
1429 S_008020_SOFT_RESET_SPI(1) |
1430 S_008020_SOFT_RESET_SX(1) |
1431 S_008020_SOFT_RESET_SH(1) |
1432 S_008020_SOFT_RESET_TC(1) |
1433 S_008020_SOFT_RESET_TA(1) |
1434 S_008020_SOFT_RESET_VC(1) |
1435 S_008020_SOFT_RESET_VGT(1);
1436 else
1437 grbm_soft_reset |= S_008020_SOFT_RESET_CR(1) |
1438 S_008020_SOFT_RESET_DB(1) |
1439 S_008020_SOFT_RESET_CB(1) |
1440 S_008020_SOFT_RESET_PA(1) |
1441 S_008020_SOFT_RESET_SC(1) |
1442 S_008020_SOFT_RESET_SMX(1) |
1443 S_008020_SOFT_RESET_SPI(1) |
1444 S_008020_SOFT_RESET_SX(1) |
1445 S_008020_SOFT_RESET_SH(1) |
1446 S_008020_SOFT_RESET_TC(1) |
1447 S_008020_SOFT_RESET_TA(1) |
1448 S_008020_SOFT_RESET_VC(1) |
1449 S_008020_SOFT_RESET_VGT(1);
1450 }
1451
1452 if (reset_mask & RADEON_RESET_CP) {
1453 grbm_soft_reset |= S_008020_SOFT_RESET_CP(1) |
1454 S_008020_SOFT_RESET_VGT(1);
1455
1456 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1457 }
1458
1459 if (reset_mask & RADEON_RESET_DMA) {
1460 if (rdev->family >= CHIP_RV770)
1461 srbm_soft_reset |= RV770_SOFT_RESET_DMA;
1462 else
1463 srbm_soft_reset |= SOFT_RESET_DMA;
1464 }
1465
Alex Deucherf13f7732013-01-18 18:12:22 -05001466 if (reset_mask & RADEON_RESET_RLC)
1467 srbm_soft_reset |= S_000E60_SOFT_RESET_RLC(1);
1468
1469 if (reset_mask & RADEON_RESET_SEM)
1470 srbm_soft_reset |= S_000E60_SOFT_RESET_SEM(1);
1471
1472 if (reset_mask & RADEON_RESET_IH)
1473 srbm_soft_reset |= S_000E60_SOFT_RESET_IH(1);
1474
1475 if (reset_mask & RADEON_RESET_GRBM)
1476 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1477
1478 if (reset_mask & RADEON_RESET_MC)
1479 srbm_soft_reset |= S_000E60_SOFT_RESET_MC(1);
1480
1481 if (reset_mask & RADEON_RESET_VMC)
1482 srbm_soft_reset |= S_000E60_SOFT_RESET_VMC(1);
1483
Alex Deucherd3cb7812013-01-18 13:53:37 -05001484 if (grbm_soft_reset) {
1485 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1486 tmp |= grbm_soft_reset;
1487 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1488 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1489 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1490
1491 udelay(50);
1492
1493 tmp &= ~grbm_soft_reset;
1494 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1495 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1496 }
1497
1498 if (srbm_soft_reset) {
1499 tmp = RREG32(SRBM_SOFT_RESET);
1500 tmp |= srbm_soft_reset;
1501 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1502 WREG32(SRBM_SOFT_RESET, tmp);
1503 tmp = RREG32(SRBM_SOFT_RESET);
1504
1505 udelay(50);
1506
1507 tmp &= ~srbm_soft_reset;
1508 WREG32(SRBM_SOFT_RESET, tmp);
1509 tmp = RREG32(SRBM_SOFT_RESET);
1510 }
Alex Deucher71e3d152013-01-03 12:20:35 -05001511
1512 /* Wait a little for things to settle down */
1513 mdelay(1);
1514
Jerome Glissea3c19452009-10-01 18:02:13 +02001515 rv515_mc_resume(rdev, &save);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001516 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05001517
Alex Deucherd3cb7812013-01-18 13:53:37 -05001518 r600_print_gpu_status_regs(rdev);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001519}
1520
1521int r600_asic_reset(struct radeon_device *rdev)
1522{
Alex Deucherf13f7732013-01-18 18:12:22 -05001523 u32 reset_mask;
1524
1525 reset_mask = r600_gpu_check_soft_reset(rdev);
1526
1527 if (reset_mask)
1528 r600_set_bios_scratch_engine_hung(rdev, true);
1529
1530 r600_gpu_soft_reset(rdev, reset_mask);
1531
1532 reset_mask = r600_gpu_check_soft_reset(rdev);
1533
1534 if (!reset_mask)
1535 r600_set_bios_scratch_engine_hung(rdev, false);
1536
1537 return 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001538}
1539
Christian Könige32eb502011-10-23 12:56:27 +02001540bool r600_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse225758d2010-03-09 14:45:10 +00001541{
1542 u32 srbm_status;
1543 u32 grbm_status;
1544 u32 grbm_status2;
Jerome Glisse225758d2010-03-09 14:45:10 +00001545
1546 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1547 grbm_status = RREG32(R_008010_GRBM_STATUS);
1548 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1549 if (!G_008010_GUI_ACTIVE(grbm_status)) {
Christian König069211e2012-05-02 15:11:20 +02001550 radeon_ring_lockup_update(ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001551 return false;
1552 }
1553 /* force CP activities */
Christian König7b9ef162012-05-02 15:11:23 +02001554 radeon_ring_force_activity(rdev, ring);
Christian König069211e2012-05-02 15:11:20 +02001555 return radeon_ring_test_lockup(rdev, ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001556}
1557
Alex Deucher4d756582012-09-27 15:08:35 -04001558/**
1559 * r600_dma_is_lockup - Check if the DMA engine is locked up
1560 *
1561 * @rdev: radeon_device pointer
1562 * @ring: radeon_ring structure holding ring information
1563 *
1564 * Check if the async DMA engine is locked up (r6xx-evergreen).
1565 * Returns true if the engine appears to be locked up, false if not.
1566 */
1567bool r600_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1568{
1569 u32 dma_status_reg;
1570
1571 dma_status_reg = RREG32(DMA_STATUS_REG);
1572 if (dma_status_reg & DMA_IDLE) {
1573 radeon_ring_lockup_update(ring);
1574 return false;
1575 }
1576 /* force ring activities */
1577 radeon_ring_force_activity(rdev, ring);
1578 return radeon_ring_test_lockup(rdev, ring);
1579}
1580
Alex Deucher416a2bd2012-05-31 19:00:25 -04001581u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1582 u32 tiling_pipe_num,
1583 u32 max_rb_num,
1584 u32 total_max_rb_num,
1585 u32 disabled_rb_mask)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001586{
Alex Deucher416a2bd2012-05-31 19:00:25 -04001587 u32 rendering_pipe_num, rb_num_width, req_rb_num;
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001588 u32 pipe_rb_ratio, pipe_rb_remain, tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001589 u32 data = 0, mask = 1 << (max_rb_num - 1);
1590 unsigned i, j;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001591
Alex Deucher416a2bd2012-05-31 19:00:25 -04001592 /* mask out the RBs that don't exist on that asic */
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001593 tmp = disabled_rb_mask | ((0xff << max_rb_num) & 0xff);
1594 /* make sure at least one RB is available */
1595 if ((tmp & 0xff) != 0xff)
1596 disabled_rb_mask = tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001597
Alex Deucher416a2bd2012-05-31 19:00:25 -04001598 rendering_pipe_num = 1 << tiling_pipe_num;
1599 req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
1600 BUG_ON(rendering_pipe_num < req_rb_num);
1601
1602 pipe_rb_ratio = rendering_pipe_num / req_rb_num;
1603 pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
1604
1605 if (rdev->family <= CHIP_RV740) {
1606 /* r6xx/r7xx */
1607 rb_num_width = 2;
1608 } else {
1609 /* eg+ */
1610 rb_num_width = 4;
1611 }
1612
1613 for (i = 0; i < max_rb_num; i++) {
1614 if (!(mask & disabled_rb_mask)) {
1615 for (j = 0; j < pipe_rb_ratio; j++) {
1616 data <<= rb_num_width;
1617 data |= max_rb_num - i - 1;
1618 }
1619 if (pipe_rb_remain) {
1620 data <<= rb_num_width;
1621 data |= max_rb_num - i - 1;
1622 pipe_rb_remain--;
1623 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001624 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04001625 mask >>= 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001626 }
1627
Alex Deucher416a2bd2012-05-31 19:00:25 -04001628 return data;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001629}
1630
1631int r600_count_pipe_bits(uint32_t val)
1632{
Akinobu Mitaef8cf3a2012-11-09 12:10:41 +00001633 return hweight32(val);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001634}
1635
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001636static void r600_gpu_init(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001637{
1638 u32 tiling_config;
1639 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001640 u32 cc_rb_backend_disable;
1641 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001642 u32 tmp;
1643 int i, j;
1644 u32 sq_config;
1645 u32 sq_gpr_resource_mgmt_1 = 0;
1646 u32 sq_gpr_resource_mgmt_2 = 0;
1647 u32 sq_thread_resource_mgmt = 0;
1648 u32 sq_stack_resource_mgmt_1 = 0;
1649 u32 sq_stack_resource_mgmt_2 = 0;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001650 u32 disabled_rb_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001651
Alex Deucher416a2bd2012-05-31 19:00:25 -04001652 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001653 switch (rdev->family) {
1654 case CHIP_R600:
1655 rdev->config.r600.max_pipes = 4;
1656 rdev->config.r600.max_tile_pipes = 8;
1657 rdev->config.r600.max_simds = 4;
1658 rdev->config.r600.max_backends = 4;
1659 rdev->config.r600.max_gprs = 256;
1660 rdev->config.r600.max_threads = 192;
1661 rdev->config.r600.max_stack_entries = 256;
1662 rdev->config.r600.max_hw_contexts = 8;
1663 rdev->config.r600.max_gs_threads = 16;
1664 rdev->config.r600.sx_max_export_size = 128;
1665 rdev->config.r600.sx_max_export_pos_size = 16;
1666 rdev->config.r600.sx_max_export_smx_size = 128;
1667 rdev->config.r600.sq_num_cf_insts = 2;
1668 break;
1669 case CHIP_RV630:
1670 case CHIP_RV635:
1671 rdev->config.r600.max_pipes = 2;
1672 rdev->config.r600.max_tile_pipes = 2;
1673 rdev->config.r600.max_simds = 3;
1674 rdev->config.r600.max_backends = 1;
1675 rdev->config.r600.max_gprs = 128;
1676 rdev->config.r600.max_threads = 192;
1677 rdev->config.r600.max_stack_entries = 128;
1678 rdev->config.r600.max_hw_contexts = 8;
1679 rdev->config.r600.max_gs_threads = 4;
1680 rdev->config.r600.sx_max_export_size = 128;
1681 rdev->config.r600.sx_max_export_pos_size = 16;
1682 rdev->config.r600.sx_max_export_smx_size = 128;
1683 rdev->config.r600.sq_num_cf_insts = 2;
1684 break;
1685 case CHIP_RV610:
1686 case CHIP_RV620:
1687 case CHIP_RS780:
1688 case CHIP_RS880:
1689 rdev->config.r600.max_pipes = 1;
1690 rdev->config.r600.max_tile_pipes = 1;
1691 rdev->config.r600.max_simds = 2;
1692 rdev->config.r600.max_backends = 1;
1693 rdev->config.r600.max_gprs = 128;
1694 rdev->config.r600.max_threads = 192;
1695 rdev->config.r600.max_stack_entries = 128;
1696 rdev->config.r600.max_hw_contexts = 4;
1697 rdev->config.r600.max_gs_threads = 4;
1698 rdev->config.r600.sx_max_export_size = 128;
1699 rdev->config.r600.sx_max_export_pos_size = 16;
1700 rdev->config.r600.sx_max_export_smx_size = 128;
1701 rdev->config.r600.sq_num_cf_insts = 1;
1702 break;
1703 case CHIP_RV670:
1704 rdev->config.r600.max_pipes = 4;
1705 rdev->config.r600.max_tile_pipes = 4;
1706 rdev->config.r600.max_simds = 4;
1707 rdev->config.r600.max_backends = 4;
1708 rdev->config.r600.max_gprs = 192;
1709 rdev->config.r600.max_threads = 192;
1710 rdev->config.r600.max_stack_entries = 256;
1711 rdev->config.r600.max_hw_contexts = 8;
1712 rdev->config.r600.max_gs_threads = 16;
1713 rdev->config.r600.sx_max_export_size = 128;
1714 rdev->config.r600.sx_max_export_pos_size = 16;
1715 rdev->config.r600.sx_max_export_smx_size = 128;
1716 rdev->config.r600.sq_num_cf_insts = 2;
1717 break;
1718 default:
1719 break;
1720 }
1721
1722 /* Initialize HDP */
1723 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1724 WREG32((0x2c14 + j), 0x00000000);
1725 WREG32((0x2c18 + j), 0x00000000);
1726 WREG32((0x2c1c + j), 0x00000000);
1727 WREG32((0x2c20 + j), 0x00000000);
1728 WREG32((0x2c24 + j), 0x00000000);
1729 }
1730
1731 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1732
1733 /* Setup tiling */
1734 tiling_config = 0;
1735 ramcfg = RREG32(RAMCFG);
1736 switch (rdev->config.r600.max_tile_pipes) {
1737 case 1:
1738 tiling_config |= PIPE_TILING(0);
1739 break;
1740 case 2:
1741 tiling_config |= PIPE_TILING(1);
1742 break;
1743 case 4:
1744 tiling_config |= PIPE_TILING(2);
1745 break;
1746 case 8:
1747 tiling_config |= PIPE_TILING(3);
1748 break;
1749 default:
1750 break;
1751 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001752 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001753 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001754 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04001755 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
Alex Deucher416a2bd2012-05-31 19:00:25 -04001756
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001757 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1758 if (tmp > 3) {
1759 tiling_config |= ROW_TILING(3);
1760 tiling_config |= SAMPLE_SPLIT(3);
1761 } else {
1762 tiling_config |= ROW_TILING(tmp);
1763 tiling_config |= SAMPLE_SPLIT(tmp);
1764 }
1765 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001766
1767 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001768 tmp = R6XX_MAX_BACKENDS -
1769 r600_count_pipe_bits((cc_rb_backend_disable >> 16) & R6XX_MAX_BACKENDS_MASK);
1770 if (tmp < rdev->config.r600.max_backends) {
1771 rdev->config.r600.max_backends = tmp;
1772 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001773
Alex Deucher416a2bd2012-05-31 19:00:25 -04001774 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
1775 tmp = R6XX_MAX_PIPES -
1776 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R6XX_MAX_PIPES_MASK);
1777 if (tmp < rdev->config.r600.max_pipes) {
1778 rdev->config.r600.max_pipes = tmp;
1779 }
1780 tmp = R6XX_MAX_SIMDS -
1781 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
1782 if (tmp < rdev->config.r600.max_simds) {
1783 rdev->config.r600.max_simds = tmp;
1784 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001785
Alex Deucher416a2bd2012-05-31 19:00:25 -04001786 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
1787 tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
1788 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
1789 R6XX_MAX_BACKENDS, disabled_rb_mask);
1790 tiling_config |= tmp << 16;
1791 rdev->config.r600.backend_map = tmp;
1792
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001793 rdev->config.r600.tile_config = tiling_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001794 WREG32(GB_TILING_CONFIG, tiling_config);
1795 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1796 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
Alex Deucher4d756582012-09-27 15:08:35 -04001797 WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001798
Alex Deucherd03f5d52010-02-19 16:22:31 -05001799 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 +10001800 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1801 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1802
1803 /* Setup some CP states */
1804 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1805 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1806
1807 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1808 SYNC_WALKER | SYNC_ALIGNER));
1809 /* Setup various GPU states */
1810 if (rdev->family == CHIP_RV670)
1811 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1812
1813 tmp = RREG32(SX_DEBUG_1);
1814 tmp |= SMX_EVENT_RELEASE;
1815 if ((rdev->family > CHIP_R600))
1816 tmp |= ENABLE_NEW_SMX_ADDRESS;
1817 WREG32(SX_DEBUG_1, tmp);
1818
1819 if (((rdev->family) == CHIP_R600) ||
1820 ((rdev->family) == CHIP_RV630) ||
1821 ((rdev->family) == CHIP_RV610) ||
1822 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001823 ((rdev->family) == CHIP_RS780) ||
1824 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001825 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1826 } else {
1827 WREG32(DB_DEBUG, 0);
1828 }
1829 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1830 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1831
1832 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1833 WREG32(VGT_NUM_INSTANCES, 0);
1834
1835 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1836 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1837
1838 tmp = RREG32(SQ_MS_FIFO_SIZES);
1839 if (((rdev->family) == CHIP_RV610) ||
1840 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001841 ((rdev->family) == CHIP_RS780) ||
1842 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001843 tmp = (CACHE_FIFO_SIZE(0xa) |
1844 FETCH_FIFO_HIWATER(0xa) |
1845 DONE_FIFO_HIWATER(0xe0) |
1846 ALU_UPDATE_FIFO_HIWATER(0x8));
1847 } else if (((rdev->family) == CHIP_R600) ||
1848 ((rdev->family) == CHIP_RV630)) {
1849 tmp &= ~DONE_FIFO_HIWATER(0xff);
1850 tmp |= DONE_FIFO_HIWATER(0x4);
1851 }
1852 WREG32(SQ_MS_FIFO_SIZES, tmp);
1853
1854 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1855 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1856 */
1857 sq_config = RREG32(SQ_CONFIG);
1858 sq_config &= ~(PS_PRIO(3) |
1859 VS_PRIO(3) |
1860 GS_PRIO(3) |
1861 ES_PRIO(3));
1862 sq_config |= (DX9_CONSTS |
1863 VC_ENABLE |
1864 PS_PRIO(0) |
1865 VS_PRIO(1) |
1866 GS_PRIO(2) |
1867 ES_PRIO(3));
1868
1869 if ((rdev->family) == CHIP_R600) {
1870 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1871 NUM_VS_GPRS(124) |
1872 NUM_CLAUSE_TEMP_GPRS(4));
1873 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1874 NUM_ES_GPRS(0));
1875 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1876 NUM_VS_THREADS(48) |
1877 NUM_GS_THREADS(4) |
1878 NUM_ES_THREADS(4));
1879 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1880 NUM_VS_STACK_ENTRIES(128));
1881 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1882 NUM_ES_STACK_ENTRIES(0));
1883 } else if (((rdev->family) == CHIP_RV610) ||
1884 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001885 ((rdev->family) == CHIP_RS780) ||
1886 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001887 /* no vertex cache */
1888 sq_config &= ~VC_ENABLE;
1889
1890 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1891 NUM_VS_GPRS(44) |
1892 NUM_CLAUSE_TEMP_GPRS(2));
1893 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1894 NUM_ES_GPRS(17));
1895 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1896 NUM_VS_THREADS(78) |
1897 NUM_GS_THREADS(4) |
1898 NUM_ES_THREADS(31));
1899 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1900 NUM_VS_STACK_ENTRIES(40));
1901 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1902 NUM_ES_STACK_ENTRIES(16));
1903 } else if (((rdev->family) == CHIP_RV630) ||
1904 ((rdev->family) == CHIP_RV635)) {
1905 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1906 NUM_VS_GPRS(44) |
1907 NUM_CLAUSE_TEMP_GPRS(2));
1908 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1909 NUM_ES_GPRS(18));
1910 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1911 NUM_VS_THREADS(78) |
1912 NUM_GS_THREADS(4) |
1913 NUM_ES_THREADS(31));
1914 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1915 NUM_VS_STACK_ENTRIES(40));
1916 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1917 NUM_ES_STACK_ENTRIES(16));
1918 } else if ((rdev->family) == CHIP_RV670) {
1919 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1920 NUM_VS_GPRS(44) |
1921 NUM_CLAUSE_TEMP_GPRS(2));
1922 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1923 NUM_ES_GPRS(17));
1924 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1925 NUM_VS_THREADS(78) |
1926 NUM_GS_THREADS(4) |
1927 NUM_ES_THREADS(31));
1928 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1929 NUM_VS_STACK_ENTRIES(64));
1930 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1931 NUM_ES_STACK_ENTRIES(64));
1932 }
1933
1934 WREG32(SQ_CONFIG, sq_config);
1935 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1936 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1937 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1938 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1939 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1940
1941 if (((rdev->family) == CHIP_RV610) ||
1942 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001943 ((rdev->family) == CHIP_RS780) ||
1944 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001945 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1946 } else {
1947 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1948 }
1949
1950 /* More default values. 2D/3D driver should adjust as needed */
1951 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1952 S1_X(0x4) | S1_Y(0xc)));
1953 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1954 S1_X(0x2) | S1_Y(0x2) |
1955 S2_X(0xa) | S2_Y(0x6) |
1956 S3_X(0x6) | S3_Y(0xa)));
1957 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1958 S1_X(0x4) | S1_Y(0xc) |
1959 S2_X(0x1) | S2_Y(0x6) |
1960 S3_X(0xa) | S3_Y(0xe)));
1961 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1962 S5_X(0x0) | S5_Y(0x0) |
1963 S6_X(0xb) | S6_Y(0x4) |
1964 S7_X(0x7) | S7_Y(0x8)));
1965
1966 WREG32(VGT_STRMOUT_EN, 0);
1967 tmp = rdev->config.r600.max_pipes * 16;
1968 switch (rdev->family) {
1969 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001970 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001971 case CHIP_RS780:
1972 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001973 tmp += 32;
1974 break;
1975 case CHIP_RV670:
1976 tmp += 128;
1977 break;
1978 default:
1979 break;
1980 }
1981 if (tmp > 256) {
1982 tmp = 256;
1983 }
1984 WREG32(VGT_ES_PER_GS, 128);
1985 WREG32(VGT_GS_PER_ES, tmp);
1986 WREG32(VGT_GS_PER_VS, 2);
1987 WREG32(VGT_GS_VERTEX_REUSE, 16);
1988
1989 /* more default values. 2D/3D driver should adjust as needed */
1990 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1991 WREG32(VGT_STRMOUT_EN, 0);
1992 WREG32(SX_MISC, 0);
1993 WREG32(PA_SC_MODE_CNTL, 0);
1994 WREG32(PA_SC_AA_CONFIG, 0);
1995 WREG32(PA_SC_LINE_STIPPLE, 0);
1996 WREG32(SPI_INPUT_Z, 0);
1997 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1998 WREG32(CB_COLOR7_FRAG, 0);
1999
2000 /* Clear render buffer base addresses */
2001 WREG32(CB_COLOR0_BASE, 0);
2002 WREG32(CB_COLOR1_BASE, 0);
2003 WREG32(CB_COLOR2_BASE, 0);
2004 WREG32(CB_COLOR3_BASE, 0);
2005 WREG32(CB_COLOR4_BASE, 0);
2006 WREG32(CB_COLOR5_BASE, 0);
2007 WREG32(CB_COLOR6_BASE, 0);
2008 WREG32(CB_COLOR7_BASE, 0);
2009 WREG32(CB_COLOR7_FRAG, 0);
2010
2011 switch (rdev->family) {
2012 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002013 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05002014 case CHIP_RS780:
2015 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002016 tmp = TC_L2_SIZE(8);
2017 break;
2018 case CHIP_RV630:
2019 case CHIP_RV635:
2020 tmp = TC_L2_SIZE(4);
2021 break;
2022 case CHIP_R600:
2023 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
2024 break;
2025 default:
2026 tmp = TC_L2_SIZE(0);
2027 break;
2028 }
2029 WREG32(TC_CNTL, tmp);
2030
2031 tmp = RREG32(HDP_HOST_PATH_CNTL);
2032 WREG32(HDP_HOST_PATH_CNTL, tmp);
2033
2034 tmp = RREG32(ARB_POP);
2035 tmp |= ENABLE_TC128;
2036 WREG32(ARB_POP, tmp);
2037
2038 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
2039 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
2040 NUM_CLIP_SEQ(3)));
2041 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
Alex Deucherb866d132012-06-14 22:06:36 +02002042 WREG32(VC_ENHANCE, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002043}
2044
2045
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002046/*
2047 * Indirect registers accessor
2048 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002049u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002050{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002051 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002052
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002053 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2054 (void)RREG32(PCIE_PORT_INDEX);
2055 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002056 return r;
2057}
2058
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002059void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002060{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002061 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2062 (void)RREG32(PCIE_PORT_INDEX);
2063 WREG32(PCIE_PORT_DATA, (v));
2064 (void)RREG32(PCIE_PORT_DATA);
2065}
2066
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002067/*
2068 * CP & Ring
2069 */
2070void r600_cp_stop(struct radeon_device *rdev)
2071{
Dave Airlie53595332011-03-14 09:47:24 +10002072 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002073 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04002074 WREG32(SCRATCH_UMSK, 0);
Alex Deucher4d756582012-09-27 15:08:35 -04002075 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002076}
2077
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002078int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002079{
2080 struct platform_device *pdev;
2081 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002082 const char *rlc_chip_name;
2083 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002084 char fw_name[30];
2085 int err;
2086
2087 DRM_DEBUG("\n");
2088
2089 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
2090 err = IS_ERR(pdev);
2091 if (err) {
2092 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
2093 return -EINVAL;
2094 }
2095
2096 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002097 case CHIP_R600:
2098 chip_name = "R600";
2099 rlc_chip_name = "R600";
2100 break;
2101 case CHIP_RV610:
2102 chip_name = "RV610";
2103 rlc_chip_name = "R600";
2104 break;
2105 case CHIP_RV630:
2106 chip_name = "RV630";
2107 rlc_chip_name = "R600";
2108 break;
2109 case CHIP_RV620:
2110 chip_name = "RV620";
2111 rlc_chip_name = "R600";
2112 break;
2113 case CHIP_RV635:
2114 chip_name = "RV635";
2115 rlc_chip_name = "R600";
2116 break;
2117 case CHIP_RV670:
2118 chip_name = "RV670";
2119 rlc_chip_name = "R600";
2120 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002121 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002122 case CHIP_RS880:
2123 chip_name = "RS780";
2124 rlc_chip_name = "R600";
2125 break;
2126 case CHIP_RV770:
2127 chip_name = "RV770";
2128 rlc_chip_name = "R700";
2129 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002130 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002131 case CHIP_RV740:
2132 chip_name = "RV730";
2133 rlc_chip_name = "R700";
2134 break;
2135 case CHIP_RV710:
2136 chip_name = "RV710";
2137 rlc_chip_name = "R700";
2138 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04002139 case CHIP_CEDAR:
2140 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04002141 rlc_chip_name = "CEDAR";
Alex Deucherfe251e22010-03-24 13:36:43 -04002142 break;
2143 case CHIP_REDWOOD:
2144 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04002145 rlc_chip_name = "REDWOOD";
Alex Deucherfe251e22010-03-24 13:36:43 -04002146 break;
2147 case CHIP_JUNIPER:
2148 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04002149 rlc_chip_name = "JUNIPER";
Alex Deucherfe251e22010-03-24 13:36:43 -04002150 break;
2151 case CHIP_CYPRESS:
2152 case CHIP_HEMLOCK:
2153 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04002154 rlc_chip_name = "CYPRESS";
Alex Deucherfe251e22010-03-24 13:36:43 -04002155 break;
Alex Deucher439bd6c2010-11-22 17:56:31 -05002156 case CHIP_PALM:
2157 chip_name = "PALM";
2158 rlc_chip_name = "SUMO";
2159 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002160 case CHIP_SUMO:
2161 chip_name = "SUMO";
2162 rlc_chip_name = "SUMO";
2163 break;
2164 case CHIP_SUMO2:
2165 chip_name = "SUMO2";
2166 rlc_chip_name = "SUMO";
2167 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002168 default: BUG();
2169 }
2170
Alex Deucherfe251e22010-03-24 13:36:43 -04002171 if (rdev->family >= CHIP_CEDAR) {
2172 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2173 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002174 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002175 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002176 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2177 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002178 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002179 } else {
2180 pfp_req_size = PFP_UCODE_SIZE * 4;
2181 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002182 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002183 }
2184
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002185 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002186
2187 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2188 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
2189 if (err)
2190 goto out;
2191 if (rdev->pfp_fw->size != pfp_req_size) {
2192 printk(KERN_ERR
2193 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2194 rdev->pfp_fw->size, fw_name);
2195 err = -EINVAL;
2196 goto out;
2197 }
2198
2199 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2200 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
2201 if (err)
2202 goto out;
2203 if (rdev->me_fw->size != me_req_size) {
2204 printk(KERN_ERR
2205 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2206 rdev->me_fw->size, fw_name);
2207 err = -EINVAL;
2208 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002209
2210 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
2211 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
2212 if (err)
2213 goto out;
2214 if (rdev->rlc_fw->size != rlc_req_size) {
2215 printk(KERN_ERR
2216 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2217 rdev->rlc_fw->size, fw_name);
2218 err = -EINVAL;
2219 }
2220
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002221out:
2222 platform_device_unregister(pdev);
2223
2224 if (err) {
2225 if (err != -EINVAL)
2226 printk(KERN_ERR
2227 "r600_cp: Failed to load firmware \"%s\"\n",
2228 fw_name);
2229 release_firmware(rdev->pfp_fw);
2230 rdev->pfp_fw = NULL;
2231 release_firmware(rdev->me_fw);
2232 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002233 release_firmware(rdev->rlc_fw);
2234 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002235 }
2236 return err;
2237}
2238
2239static int r600_cp_load_microcode(struct radeon_device *rdev)
2240{
2241 const __be32 *fw_data;
2242 int i;
2243
2244 if (!rdev->me_fw || !rdev->pfp_fw)
2245 return -EINVAL;
2246
2247 r600_cp_stop(rdev);
2248
Cédric Cano4eace7f2011-02-11 19:45:38 -05002249 WREG32(CP_RB_CNTL,
2250#ifdef __BIG_ENDIAN
2251 BUF_SWAP_32BIT |
2252#endif
2253 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002254
2255 /* Reset cp */
2256 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2257 RREG32(GRBM_SOFT_RESET);
2258 mdelay(15);
2259 WREG32(GRBM_SOFT_RESET, 0);
2260
2261 WREG32(CP_ME_RAM_WADDR, 0);
2262
2263 fw_data = (const __be32 *)rdev->me_fw->data;
2264 WREG32(CP_ME_RAM_WADDR, 0);
2265 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
2266 WREG32(CP_ME_RAM_DATA,
2267 be32_to_cpup(fw_data++));
2268
2269 fw_data = (const __be32 *)rdev->pfp_fw->data;
2270 WREG32(CP_PFP_UCODE_ADDR, 0);
2271 for (i = 0; i < PFP_UCODE_SIZE; i++)
2272 WREG32(CP_PFP_UCODE_DATA,
2273 be32_to_cpup(fw_data++));
2274
2275 WREG32(CP_PFP_UCODE_ADDR, 0);
2276 WREG32(CP_ME_RAM_WADDR, 0);
2277 WREG32(CP_ME_RAM_RADDR, 0);
2278 return 0;
2279}
2280
2281int r600_cp_start(struct radeon_device *rdev)
2282{
Christian Könige32eb502011-10-23 12:56:27 +02002283 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002284 int r;
2285 uint32_t cp_me;
2286
Christian Könige32eb502011-10-23 12:56:27 +02002287 r = radeon_ring_lock(rdev, ring, 7);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002288 if (r) {
2289 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2290 return r;
2291 }
Christian Könige32eb502011-10-23 12:56:27 +02002292 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2293 radeon_ring_write(ring, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002294 if (rdev->family >= CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +02002295 radeon_ring_write(ring, 0x0);
2296 radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002297 } else {
Christian Könige32eb502011-10-23 12:56:27 +02002298 radeon_ring_write(ring, 0x3);
2299 radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002300 }
Christian Könige32eb502011-10-23 12:56:27 +02002301 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2302 radeon_ring_write(ring, 0);
2303 radeon_ring_write(ring, 0);
2304 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002305
2306 cp_me = 0xff;
2307 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2308 return 0;
2309}
2310
2311int r600_cp_resume(struct radeon_device *rdev)
2312{
Christian Könige32eb502011-10-23 12:56:27 +02002313 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002314 u32 tmp;
2315 u32 rb_bufsz;
2316 int r;
2317
2318 /* Reset cp */
2319 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2320 RREG32(GRBM_SOFT_RESET);
2321 mdelay(15);
2322 WREG32(GRBM_SOFT_RESET, 0);
2323
2324 /* Set ring buffer size */
Christian Könige32eb502011-10-23 12:56:27 +02002325 rb_bufsz = drm_order(ring->ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04002326 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002327#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002328 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002329#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002330 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02002331 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002332
2333 /* Set the write pointer delay */
2334 WREG32(CP_RB_WPTR_DELAY, 0);
2335
2336 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002337 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2338 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02002339 ring->wptr = 0;
2340 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04002341
2342 /* set the wb address whether it's enabled or not */
Cédric Cano4eace7f2011-02-11 19:45:38 -05002343 WREG32(CP_RB_RPTR_ADDR,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002344 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002345 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2346 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2347
2348 if (rdev->wb.enabled)
2349 WREG32(SCRATCH_UMSK, 0xff);
2350 else {
2351 tmp |= RB_NO_UPDATE;
2352 WREG32(SCRATCH_UMSK, 0);
2353 }
2354
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002355 mdelay(1);
2356 WREG32(CP_RB_CNTL, tmp);
2357
Christian Könige32eb502011-10-23 12:56:27 +02002358 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002359 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2360
Christian Könige32eb502011-10-23 12:56:27 +02002361 ring->rptr = RREG32(CP_RB_RPTR);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002362
2363 r600_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002364 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05002365 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002366 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02002367 ring->ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002368 return r;
2369 }
2370 return 0;
2371}
2372
Christian Könige32eb502011-10-23 12:56:27 +02002373void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002374{
2375 u32 rb_bufsz;
Christian König45df6802012-07-06 16:22:55 +02002376 int r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002377
2378 /* Align ring size */
2379 rb_bufsz = drm_order(ring_size / 8);
2380 ring_size = (1 << (rb_bufsz + 1)) * 4;
Christian Könige32eb502011-10-23 12:56:27 +02002381 ring->ring_size = ring_size;
2382 ring->align_mask = 16 - 1;
Christian König45df6802012-07-06 16:22:55 +02002383
Alex Deucher89d35802012-07-17 14:02:31 -04002384 if (radeon_ring_supports_scratch_reg(rdev, ring)) {
2385 r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
2386 if (r) {
2387 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
2388 ring->rptr_save_reg = 0;
2389 }
Christian König45df6802012-07-06 16:22:55 +02002390 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002391}
2392
Jerome Glisse655efd32010-02-02 11:51:45 +01002393void r600_cp_fini(struct radeon_device *rdev)
2394{
Christian König45df6802012-07-06 16:22:55 +02002395 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse655efd32010-02-02 11:51:45 +01002396 r600_cp_stop(rdev);
Christian König45df6802012-07-06 16:22:55 +02002397 radeon_ring_fini(rdev, ring);
2398 radeon_scratch_free(rdev, ring->rptr_save_reg);
Jerome Glisse655efd32010-02-02 11:51:45 +01002399}
2400
Alex Deucher4d756582012-09-27 15:08:35 -04002401/*
2402 * DMA
2403 * Starting with R600, the GPU has an asynchronous
2404 * DMA engine. The programming model is very similar
2405 * to the 3D engine (ring buffer, IBs, etc.), but the
2406 * DMA controller has it's own packet format that is
2407 * different form the PM4 format used by the 3D engine.
2408 * It supports copying data, writing embedded data,
2409 * solid fills, and a number of other things. It also
2410 * has support for tiling/detiling of buffers.
2411 */
2412/**
2413 * r600_dma_stop - stop the async dma engine
2414 *
2415 * @rdev: radeon_device pointer
2416 *
2417 * Stop the async dma engine (r6xx-evergreen).
2418 */
2419void r600_dma_stop(struct radeon_device *rdev)
2420{
2421 u32 rb_cntl = RREG32(DMA_RB_CNTL);
2422
2423 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
2424
2425 rb_cntl &= ~DMA_RB_ENABLE;
2426 WREG32(DMA_RB_CNTL, rb_cntl);
2427
2428 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
2429}
2430
2431/**
2432 * r600_dma_resume - setup and start the async dma engine
2433 *
2434 * @rdev: radeon_device pointer
2435 *
2436 * Set up the DMA ring buffer and enable it. (r6xx-evergreen).
2437 * Returns 0 for success, error for failure.
2438 */
2439int r600_dma_resume(struct radeon_device *rdev)
2440{
2441 struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01002442 u32 rb_cntl, dma_cntl, ib_cntl;
Alex Deucher4d756582012-09-27 15:08:35 -04002443 u32 rb_bufsz;
2444 int r;
2445
2446 /* Reset dma */
2447 if (rdev->family >= CHIP_RV770)
2448 WREG32(SRBM_SOFT_RESET, RV770_SOFT_RESET_DMA);
2449 else
2450 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA);
2451 RREG32(SRBM_SOFT_RESET);
2452 udelay(50);
2453 WREG32(SRBM_SOFT_RESET, 0);
2454
2455 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL, 0);
2456 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL, 0);
2457
2458 /* Set ring buffer size in dwords */
2459 rb_bufsz = drm_order(ring->ring_size / 4);
2460 rb_cntl = rb_bufsz << 1;
2461#ifdef __BIG_ENDIAN
2462 rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE;
2463#endif
2464 WREG32(DMA_RB_CNTL, rb_cntl);
2465
2466 /* Initialize the ring buffer's read and write pointers */
2467 WREG32(DMA_RB_RPTR, 0);
2468 WREG32(DMA_RB_WPTR, 0);
2469
2470 /* set the wb address whether it's enabled or not */
2471 WREG32(DMA_RB_RPTR_ADDR_HI,
2472 upper_32_bits(rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFF);
2473 WREG32(DMA_RB_RPTR_ADDR_LO,
2474 ((rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFFFFFFFC));
2475
2476 if (rdev->wb.enabled)
2477 rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE;
2478
2479 WREG32(DMA_RB_BASE, ring->gpu_addr >> 8);
2480
2481 /* enable DMA IBs */
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01002482 ib_cntl = DMA_IB_ENABLE;
2483#ifdef __BIG_ENDIAN
2484 ib_cntl |= DMA_IB_SWAP_ENABLE;
2485#endif
2486 WREG32(DMA_IB_CNTL, ib_cntl);
Alex Deucher4d756582012-09-27 15:08:35 -04002487
2488 dma_cntl = RREG32(DMA_CNTL);
2489 dma_cntl &= ~CTXEMPTY_INT_ENABLE;
2490 WREG32(DMA_CNTL, dma_cntl);
2491
2492 if (rdev->family >= CHIP_RV770)
2493 WREG32(DMA_MODE, 1);
2494
2495 ring->wptr = 0;
2496 WREG32(DMA_RB_WPTR, ring->wptr << 2);
2497
2498 ring->rptr = RREG32(DMA_RB_RPTR) >> 2;
2499
2500 WREG32(DMA_RB_CNTL, rb_cntl | DMA_RB_ENABLE);
2501
2502 ring->ready = true;
2503
2504 r = radeon_ring_test(rdev, R600_RING_TYPE_DMA_INDEX, ring);
2505 if (r) {
2506 ring->ready = false;
2507 return r;
2508 }
2509
2510 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
2511
2512 return 0;
2513}
2514
2515/**
2516 * r600_dma_fini - tear down the async dma engine
2517 *
2518 * @rdev: radeon_device pointer
2519 *
2520 * Stop the async dma engine and free the ring (r6xx-evergreen).
2521 */
2522void r600_dma_fini(struct radeon_device *rdev)
2523{
2524 r600_dma_stop(rdev);
2525 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
2526}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002527
2528/*
2529 * GPU scratch registers helpers function.
2530 */
2531void r600_scratch_init(struct radeon_device *rdev)
2532{
2533 int i;
2534
2535 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002536 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002537 for (i = 0; i < rdev->scratch.num_reg; i++) {
2538 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002539 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002540 }
2541}
2542
Christian Könige32eb502011-10-23 12:56:27 +02002543int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002544{
2545 uint32_t scratch;
2546 uint32_t tmp = 0;
Alex Deucher8b25ed32012-07-17 14:02:30 -04002547 unsigned i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002548 int r;
2549
2550 r = radeon_scratch_get(rdev, &scratch);
2551 if (r) {
2552 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2553 return r;
2554 }
2555 WREG32(scratch, 0xCAFEDEAD);
Christian Könige32eb502011-10-23 12:56:27 +02002556 r = radeon_ring_lock(rdev, ring, 3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002557 if (r) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002558 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002559 radeon_scratch_free(rdev, scratch);
2560 return r;
2561 }
Christian Könige32eb502011-10-23 12:56:27 +02002562 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2563 radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2564 radeon_ring_write(ring, 0xDEADBEEF);
2565 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002566 for (i = 0; i < rdev->usec_timeout; i++) {
2567 tmp = RREG32(scratch);
2568 if (tmp == 0xDEADBEEF)
2569 break;
2570 DRM_UDELAY(1);
2571 }
2572 if (i < rdev->usec_timeout) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002573 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002574 } else {
Christian Königbf852792011-10-13 13:19:22 +02002575 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
Alex Deucher8b25ed32012-07-17 14:02:30 -04002576 ring->idx, scratch, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002577 r = -EINVAL;
2578 }
2579 radeon_scratch_free(rdev, scratch);
2580 return r;
2581}
2582
Alex Deucher4d756582012-09-27 15:08:35 -04002583/**
2584 * r600_dma_ring_test - simple async dma engine test
2585 *
2586 * @rdev: radeon_device pointer
2587 * @ring: radeon_ring structure holding ring information
2588 *
2589 * Test the DMA engine by writing using it to write an
2590 * value to memory. (r6xx-SI).
2591 * Returns 0 for success, error for failure.
2592 */
2593int r600_dma_ring_test(struct radeon_device *rdev,
2594 struct radeon_ring *ring)
2595{
2596 unsigned i;
2597 int r;
2598 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
2599 u32 tmp;
2600
2601 if (!ptr) {
2602 DRM_ERROR("invalid vram scratch pointer\n");
2603 return -EINVAL;
2604 }
2605
2606 tmp = 0xCAFEDEAD;
2607 writel(tmp, ptr);
2608
2609 r = radeon_ring_lock(rdev, ring, 4);
2610 if (r) {
2611 DRM_ERROR("radeon: dma failed to lock ring %d (%d).\n", ring->idx, r);
2612 return r;
2613 }
2614 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
2615 radeon_ring_write(ring, rdev->vram_scratch.gpu_addr & 0xfffffffc);
2616 radeon_ring_write(ring, upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff);
2617 radeon_ring_write(ring, 0xDEADBEEF);
2618 radeon_ring_unlock_commit(rdev, ring);
2619
2620 for (i = 0; i < rdev->usec_timeout; i++) {
2621 tmp = readl(ptr);
2622 if (tmp == 0xDEADBEEF)
2623 break;
2624 DRM_UDELAY(1);
2625 }
2626
2627 if (i < rdev->usec_timeout) {
2628 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
2629 } else {
2630 DRM_ERROR("radeon: ring %d test failed (0x%08X)\n",
2631 ring->idx, tmp);
2632 r = -EINVAL;
2633 }
2634 return r;
2635}
2636
2637/*
2638 * CP fences/semaphores
2639 */
2640
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002641void r600_fence_ring_emit(struct radeon_device *rdev,
2642 struct radeon_fence *fence)
2643{
Christian Könige32eb502011-10-23 12:56:27 +02002644 struct radeon_ring *ring = &rdev->ring[fence->ring];
Christian König7b1f2482011-09-23 15:11:23 +02002645
Alex Deucherd0f8a852010-09-04 05:04:34 -04002646 if (rdev->wb.use_event) {
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002647 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002648 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002649 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2650 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2651 PACKET3_VC_ACTION_ENA |
2652 PACKET3_SH_ACTION_ENA);
2653 radeon_ring_write(ring, 0xFFFFFFFF);
2654 radeon_ring_write(ring, 0);
2655 radeon_ring_write(ring, 10); /* poll interval */
Alex Deucherd0f8a852010-09-04 05:04:34 -04002656 /* EVENT_WRITE_EOP - flush caches, send int */
Christian Könige32eb502011-10-23 12:56:27 +02002657 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2658 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2659 radeon_ring_write(ring, addr & 0xffffffff);
2660 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2661 radeon_ring_write(ring, fence->seq);
2662 radeon_ring_write(ring, 0);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002663 } else {
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002664 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002665 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2666 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2667 PACKET3_VC_ACTION_ENA |
2668 PACKET3_SH_ACTION_ENA);
2669 radeon_ring_write(ring, 0xFFFFFFFF);
2670 radeon_ring_write(ring, 0);
2671 radeon_ring_write(ring, 10); /* poll interval */
2672 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
2673 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
Alex Deucherd0f8a852010-09-04 05:04:34 -04002674 /* wait for 3D idle clean */
Christian Könige32eb502011-10-23 12:56:27 +02002675 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2676 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2677 radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002678 /* Emit fence sequence & fire IRQ */
Christian Könige32eb502011-10-23 12:56:27 +02002679 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2680 radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2681 radeon_ring_write(ring, fence->seq);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002682 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
Christian Könige32eb502011-10-23 12:56:27 +02002683 radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
2684 radeon_ring_write(ring, RB_INT_STAT);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002685 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002686}
2687
Christian König15d33322011-09-15 19:02:22 +02002688void r600_semaphore_ring_emit(struct radeon_device *rdev,
Christian Könige32eb502011-10-23 12:56:27 +02002689 struct radeon_ring *ring,
Christian König15d33322011-09-15 19:02:22 +02002690 struct radeon_semaphore *semaphore,
Christian König7b1f2482011-09-23 15:11:23 +02002691 bool emit_wait)
Christian König15d33322011-09-15 19:02:22 +02002692{
2693 uint64_t addr = semaphore->gpu_addr;
2694 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
2695
Christian König0be70432012-03-07 11:28:57 +01002696 if (rdev->family < CHIP_CAYMAN)
2697 sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
2698
Christian Könige32eb502011-10-23 12:56:27 +02002699 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
2700 radeon_ring_write(ring, addr & 0xffffffff);
2701 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
Christian König15d33322011-09-15 19:02:22 +02002702}
2703
Alex Deucher4d756582012-09-27 15:08:35 -04002704/*
2705 * DMA fences/semaphores
2706 */
2707
2708/**
2709 * r600_dma_fence_ring_emit - emit a fence on the DMA ring
2710 *
2711 * @rdev: radeon_device pointer
2712 * @fence: radeon fence object
2713 *
2714 * Add a DMA fence packet to the ring to write
2715 * the fence seq number and DMA trap packet to generate
2716 * an interrupt if needed (r6xx-r7xx).
2717 */
2718void r600_dma_fence_ring_emit(struct radeon_device *rdev,
2719 struct radeon_fence *fence)
2720{
2721 struct radeon_ring *ring = &rdev->ring[fence->ring];
2722 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
Jerome Glisse86a18812012-12-12 16:43:15 -05002723
Alex Deucher4d756582012-09-27 15:08:35 -04002724 /* write the fence */
2725 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0, 0));
2726 radeon_ring_write(ring, addr & 0xfffffffc);
2727 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff));
Jerome Glisse86a18812012-12-12 16:43:15 -05002728 radeon_ring_write(ring, lower_32_bits(fence->seq));
Alex Deucher4d756582012-09-27 15:08:35 -04002729 /* generate an interrupt */
2730 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0, 0));
2731}
2732
2733/**
2734 * r600_dma_semaphore_ring_emit - emit a semaphore on the dma ring
2735 *
2736 * @rdev: radeon_device pointer
2737 * @ring: radeon_ring structure holding ring information
2738 * @semaphore: radeon semaphore object
2739 * @emit_wait: wait or signal semaphore
2740 *
2741 * Add a DMA semaphore packet to the ring wait on or signal
2742 * other rings (r6xx-SI).
2743 */
2744void r600_dma_semaphore_ring_emit(struct radeon_device *rdev,
2745 struct radeon_ring *ring,
2746 struct radeon_semaphore *semaphore,
2747 bool emit_wait)
2748{
2749 u64 addr = semaphore->gpu_addr;
2750 u32 s = emit_wait ? 0 : 1;
2751
2752 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SEMAPHORE, 0, s, 0));
2753 radeon_ring_write(ring, addr & 0xfffffffc);
2754 radeon_ring_write(ring, upper_32_bits(addr) & 0xff);
2755}
2756
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002757int r600_copy_blit(struct radeon_device *rdev,
Alex Deucher003cefe2011-09-16 12:04:08 -04002758 uint64_t src_offset,
2759 uint64_t dst_offset,
2760 unsigned num_gpu_pages,
Christian König876dc9f2012-05-08 14:24:01 +02002761 struct radeon_fence **fence)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002762{
Christian König220907d2012-05-10 16:46:43 +02002763 struct radeon_semaphore *sem = NULL;
Christian Königf2377502012-05-09 15:35:01 +02002764 struct radeon_sa_bo *vb = NULL;
Jerome Glisseff82f052010-01-22 15:19:00 +01002765 int r;
2766
Christian König220907d2012-05-10 16:46:43 +02002767 r = r600_blit_prepare_copy(rdev, num_gpu_pages, fence, &vb, &sem);
Jerome Glisseff82f052010-01-22 15:19:00 +01002768 if (r) {
Jerome Glisseff82f052010-01-22 15:19:00 +01002769 return r;
2770 }
Christian Königf2377502012-05-09 15:35:01 +02002771 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb);
Christian König220907d2012-05-10 16:46:43 +02002772 r600_blit_done_copy(rdev, fence, vb, sem);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002773 return 0;
2774}
2775
Alex Deucher4d756582012-09-27 15:08:35 -04002776/**
2777 * r600_copy_dma - copy pages using the DMA engine
2778 *
2779 * @rdev: radeon_device pointer
2780 * @src_offset: src GPU address
2781 * @dst_offset: dst GPU address
2782 * @num_gpu_pages: number of GPU pages to xfer
2783 * @fence: radeon fence object
2784 *
Alex Deucher43fb7782013-01-04 09:24:18 -05002785 * Copy GPU paging using the DMA engine (r6xx).
Alex Deucher4d756582012-09-27 15:08:35 -04002786 * Used by the radeon ttm implementation to move pages if
2787 * registered as the asic copy callback.
2788 */
2789int r600_copy_dma(struct radeon_device *rdev,
2790 uint64_t src_offset, uint64_t dst_offset,
2791 unsigned num_gpu_pages,
2792 struct radeon_fence **fence)
2793{
2794 struct radeon_semaphore *sem = NULL;
2795 int ring_index = rdev->asic->copy.dma_ring_index;
2796 struct radeon_ring *ring = &rdev->ring[ring_index];
2797 u32 size_in_dw, cur_size_in_dw;
2798 int i, num_loops;
2799 int r = 0;
2800
2801 r = radeon_semaphore_create(rdev, &sem);
2802 if (r) {
2803 DRM_ERROR("radeon: moving bo (%d).\n", r);
2804 return r;
2805 }
2806
2807 size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
Alex Deucher43fb7782013-01-04 09:24:18 -05002808 num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFE);
2809 r = radeon_ring_lock(rdev, ring, num_loops * 4 + 8);
Alex Deucher4d756582012-09-27 15:08:35 -04002810 if (r) {
2811 DRM_ERROR("radeon: moving bo (%d).\n", r);
2812 radeon_semaphore_free(rdev, &sem, NULL);
2813 return r;
2814 }
2815
2816 if (radeon_fence_need_sync(*fence, ring->idx)) {
2817 radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
2818 ring->idx);
2819 radeon_fence_note_sync(*fence, ring->idx);
2820 } else {
2821 radeon_semaphore_free(rdev, &sem, NULL);
2822 }
2823
2824 for (i = 0; i < num_loops; i++) {
2825 cur_size_in_dw = size_in_dw;
Alex Deucher909d9eb2013-01-02 18:30:21 -05002826 if (cur_size_in_dw > 0xFFFE)
2827 cur_size_in_dw = 0xFFFE;
Alex Deucher4d756582012-09-27 15:08:35 -04002828 size_in_dw -= cur_size_in_dw;
2829 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
2830 radeon_ring_write(ring, dst_offset & 0xfffffffc);
2831 radeon_ring_write(ring, src_offset & 0xfffffffc);
Alex Deucher43fb7782013-01-04 09:24:18 -05002832 radeon_ring_write(ring, (((upper_32_bits(dst_offset) & 0xff) << 16) |
2833 (upper_32_bits(src_offset) & 0xff)));
Alex Deucher4d756582012-09-27 15:08:35 -04002834 src_offset += cur_size_in_dw * 4;
2835 dst_offset += cur_size_in_dw * 4;
2836 }
2837
2838 r = radeon_fence_emit(rdev, fence, ring->idx);
2839 if (r) {
2840 radeon_ring_unlock_undo(rdev, ring);
2841 return r;
2842 }
2843
2844 radeon_ring_unlock_commit(rdev, ring);
2845 radeon_semaphore_free(rdev, &sem, *fence);
2846
2847 return r;
2848}
2849
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002850int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2851 uint32_t tiling_flags, uint32_t pitch,
2852 uint32_t offset, uint32_t obj_size)
2853{
2854 /* FIXME: implement */
2855 return 0;
2856}
2857
2858void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2859{
2860 /* FIXME: implement */
2861}
2862
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002863static int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002864{
Alex Deucher4d756582012-09-27 15:08:35 -04002865 struct radeon_ring *ring;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002866 int r;
2867
Alex Deucher9e46a482011-01-06 18:49:35 -05002868 /* enable pcie gen2 link */
2869 r600_pcie_gen2_enable(rdev);
2870
Alex Deucher779720a2009-12-09 19:31:44 -05002871 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2872 r = r600_init_microcode(rdev);
2873 if (r) {
2874 DRM_ERROR("Failed to load firmware!\n");
2875 return r;
2876 }
2877 }
2878
Alex Deucher16cdf042011-10-28 10:30:02 -04002879 r = r600_vram_scratch_init(rdev);
2880 if (r)
2881 return r;
2882
Jerome Glissea3c19452009-10-01 18:02:13 +02002883 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02002884 if (rdev->flags & RADEON_IS_AGP) {
2885 r600_agp_enable(rdev);
2886 } else {
2887 r = r600_pcie_gart_enable(rdev);
2888 if (r)
2889 return r;
2890 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002891 r600_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01002892 r = r600_blit_init(rdev);
2893 if (r) {
2894 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05002895 rdev->asic->copy.copy = NULL;
Jerome Glissec38c7b62010-02-04 17:27:27 +01002896 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2897 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04002898
Alex Deucher724c80e2010-08-27 18:25:25 -04002899 /* allocate wb buffer */
2900 r = radeon_wb_init(rdev);
2901 if (r)
2902 return r;
2903
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002904 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
2905 if (r) {
2906 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2907 return r;
2908 }
2909
Alex Deucher4d756582012-09-27 15:08:35 -04002910 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
2911 if (r) {
2912 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
2913 return r;
2914 }
2915
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002916 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002917 r = r600_irq_init(rdev);
2918 if (r) {
2919 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2920 radeon_irq_kms_fini(rdev);
2921 return r;
2922 }
2923 r600_irq_set(rdev);
2924
Alex Deucher4d756582012-09-27 15:08:35 -04002925 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Christian Könige32eb502011-10-23 12:56:27 +02002926 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05002927 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
2928 0, 0xfffff, RADEON_CP_PACKET2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002929 if (r)
2930 return r;
Alex Deucher4d756582012-09-27 15:08:35 -04002931
2932 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2933 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
2934 DMA_RB_RPTR, DMA_RB_WPTR,
2935 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
2936 if (r)
2937 return r;
2938
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002939 r = r600_cp_load_microcode(rdev);
2940 if (r)
2941 return r;
2942 r = r600_cp_resume(rdev);
2943 if (r)
2944 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04002945
Alex Deucher4d756582012-09-27 15:08:35 -04002946 r = r600_dma_resume(rdev);
2947 if (r)
2948 return r;
2949
Christian König2898c342012-07-05 11:55:34 +02002950 r = radeon_ib_pool_init(rdev);
2951 if (r) {
2952 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002953 return r;
Christian König2898c342012-07-05 11:55:34 +02002954 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05002955
Alex Deucherd4e30ef2012-06-04 17:18:51 -04002956 r = r600_audio_init(rdev);
2957 if (r) {
2958 DRM_ERROR("radeon: audio init failed\n");
2959 return r;
2960 }
2961
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002962 return 0;
2963}
2964
Dave Airlie28d52042009-09-21 14:33:58 +10002965void r600_vga_set_state(struct radeon_device *rdev, bool state)
2966{
2967 uint32_t temp;
2968
2969 temp = RREG32(CONFIG_CNTL);
2970 if (state == false) {
2971 temp &= ~(1<<0);
2972 temp |= (1<<1);
2973 } else {
2974 temp &= ~(1<<1);
2975 }
2976 WREG32(CONFIG_CNTL, temp);
2977}
2978
Dave Airliefc30b8e2009-09-18 15:19:37 +10002979int r600_resume(struct radeon_device *rdev)
2980{
2981 int r;
2982
Jerome Glisse1a029b72009-10-06 19:04:30 +02002983 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2984 * posting will perform necessary task to bring back GPU into good
2985 * shape.
2986 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002987 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002988 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002989
Jerome Glisseb15ba512011-11-15 11:48:34 -05002990 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002991 r = r600_startup(rdev);
2992 if (r) {
2993 DRM_ERROR("r600 startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05002994 rdev->accel_working = false;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002995 return r;
2996 }
2997
Dave Airliefc30b8e2009-09-18 15:19:37 +10002998 return r;
2999}
3000
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003001int r600_suspend(struct radeon_device *rdev)
3002{
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01003003 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003004 r600_cp_stop(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04003005 r600_dma_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003006 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003007 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02003008 r600_pcie_gart_disable(rdev);
Alex Deucher6ddddfe2011-10-14 10:51:22 -04003009
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003010 return 0;
3011}
3012
3013/* Plan is to move initialization in that function and use
3014 * helper function so that radeon_device_init pretty much
3015 * do nothing more than calling asic specific function. This
3016 * should also allow to remove a bunch of callback function
3017 * like vram_info.
3018 */
3019int r600_init(struct radeon_device *rdev)
3020{
3021 int r;
3022
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003023 if (r600_debugfs_mc_info_init(rdev)) {
3024 DRM_ERROR("Failed to register debugfs file for mc !\n");
3025 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003026 /* Read BIOS */
3027 if (!radeon_get_bios(rdev)) {
3028 if (ASIC_IS_AVIVO(rdev))
3029 return -EINVAL;
3030 }
3031 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02003032 if (!rdev->is_atom_bios) {
3033 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003034 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02003035 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003036 r = radeon_atombios_init(rdev);
3037 if (r)
3038 return r;
3039 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05003040 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10003041 if (!rdev->bios) {
3042 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
3043 return -EINVAL;
3044 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003045 DRM_INFO("GPU not posted. posting now...\n");
3046 atom_asic_init(rdev->mode_info.atom_context);
3047 }
3048 /* Initialize scratch registers */
3049 r600_scratch_init(rdev);
3050 /* Initialize surface registers */
3051 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01003052 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02003053 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003054 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00003055 r = radeon_fence_driver_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003056 if (r)
3057 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01003058 if (rdev->flags & RADEON_IS_AGP) {
3059 r = radeon_agp_init(rdev);
3060 if (r)
3061 radeon_agp_disable(rdev);
3062 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003063 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02003064 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003065 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003066 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01003067 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003068 if (r)
3069 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003070
3071 r = radeon_irq_kms_init(rdev);
3072 if (r)
3073 return r;
3074
Christian Könige32eb502011-10-23 12:56:27 +02003075 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
3076 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003077
Alex Deucher4d756582012-09-27 15:08:35 -04003078 rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
3079 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
3080
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003081 rdev->ih.ring_obj = NULL;
3082 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003083
Jerome Glisse4aac0472009-09-14 18:29:49 +02003084 r = r600_pcie_gart_init(rdev);
3085 if (r)
3086 return r;
3087
Alex Deucher779720a2009-12-09 19:31:44 -05003088 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10003089 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003090 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01003091 dev_err(rdev->dev, "disabling GPU acceleration\n");
3092 r600_cp_fini(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04003093 r600_dma_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003094 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003095 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02003096 radeon_ib_pool_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003097 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02003098 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02003099 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003100 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02003101
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003102 return 0;
3103}
3104
3105void r600_fini(struct radeon_device *rdev)
3106{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02003107 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003108 r600_blit_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003109 r600_cp_fini(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04003110 r600_dma_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003111 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003112 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02003113 radeon_ib_pool_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003114 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02003115 r600_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04003116 r600_vram_scratch_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003117 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003118 radeon_gem_fini(rdev);
3119 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01003120 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02003121 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003122 kfree(rdev->bios);
3123 rdev->bios = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003124}
3125
3126
3127/*
3128 * CS stuff
3129 */
3130void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3131{
Christian König876dc9f2012-05-08 14:24:01 +02003132 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher89d35802012-07-17 14:02:31 -04003133 u32 next_rptr;
Christian König7b1f2482011-09-23 15:11:23 +02003134
Christian König45df6802012-07-06 16:22:55 +02003135 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04003136 next_rptr = ring->wptr + 3 + 4;
Christian König45df6802012-07-06 16:22:55 +02003137 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3138 radeon_ring_write(ring, ((ring->rptr_save_reg -
3139 PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
3140 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04003141 } else if (rdev->wb.enabled) {
3142 next_rptr = ring->wptr + 5 + 4;
3143 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
3144 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3145 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
3146 radeon_ring_write(ring, next_rptr);
3147 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02003148 }
3149
Christian Könige32eb502011-10-23 12:56:27 +02003150 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
3151 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -05003152#ifdef __BIG_ENDIAN
3153 (2 << 0) |
3154#endif
3155 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02003156 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
3157 radeon_ring_write(ring, ib->length_dw);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003158}
3159
Alex Deucherf7128122012-02-23 17:53:45 -05003160int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003161{
Jerome Glissef2e39222012-05-09 15:35:02 +02003162 struct radeon_ib ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003163 uint32_t scratch;
3164 uint32_t tmp = 0;
3165 unsigned i;
3166 int r;
3167
3168 r = radeon_scratch_get(rdev, &scratch);
3169 if (r) {
3170 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3171 return r;
3172 }
3173 WREG32(scratch, 0xCAFEDEAD);
Christian König4bf3dd92012-08-06 18:57:44 +02003174 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003175 if (r) {
3176 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003177 goto free_scratch;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003178 }
Jerome Glissef2e39222012-05-09 15:35:02 +02003179 ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
3180 ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
3181 ib.ptr[2] = 0xDEADBEEF;
3182 ib.length_dw = 3;
Christian König4ef72562012-07-13 13:06:00 +02003183 r = radeon_ib_schedule(rdev, &ib, NULL);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003184 if (r) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003185 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003186 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003187 }
Jerome Glissef2e39222012-05-09 15:35:02 +02003188 r = radeon_fence_wait(ib.fence, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003189 if (r) {
3190 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003191 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003192 }
3193 for (i = 0; i < rdev->usec_timeout; i++) {
3194 tmp = RREG32(scratch);
3195 if (tmp == 0xDEADBEEF)
3196 break;
3197 DRM_UDELAY(1);
3198 }
3199 if (i < rdev->usec_timeout) {
Jerome Glissef2e39222012-05-09 15:35:02 +02003200 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003201 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01003202 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003203 scratch, tmp);
3204 r = -EINVAL;
3205 }
Michel Dänzeraf026c52012-09-20 10:31:10 +02003206free_ib:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003207 radeon_ib_free(rdev, &ib);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003208free_scratch:
3209 radeon_scratch_free(rdev, scratch);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003210 return r;
3211}
3212
Alex Deucher4d756582012-09-27 15:08:35 -04003213/**
3214 * r600_dma_ib_test - test an IB on the DMA engine
3215 *
3216 * @rdev: radeon_device pointer
3217 * @ring: radeon_ring structure holding ring information
3218 *
3219 * Test a simple IB in the DMA ring (r6xx-SI).
3220 * Returns 0 on success, error on failure.
3221 */
3222int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3223{
3224 struct radeon_ib ib;
3225 unsigned i;
3226 int r;
3227 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
3228 u32 tmp = 0;
3229
3230 if (!ptr) {
3231 DRM_ERROR("invalid vram scratch pointer\n");
3232 return -EINVAL;
3233 }
3234
3235 tmp = 0xCAFEDEAD;
3236 writel(tmp, ptr);
3237
3238 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
3239 if (r) {
3240 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
3241 return r;
3242 }
3243
3244 ib.ptr[0] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1);
3245 ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc;
3246 ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff;
3247 ib.ptr[3] = 0xDEADBEEF;
3248 ib.length_dw = 4;
3249
3250 r = radeon_ib_schedule(rdev, &ib, NULL);
3251 if (r) {
3252 radeon_ib_free(rdev, &ib);
3253 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
3254 return r;
3255 }
3256 r = radeon_fence_wait(ib.fence, false);
3257 if (r) {
3258 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3259 return r;
3260 }
3261 for (i = 0; i < rdev->usec_timeout; i++) {
3262 tmp = readl(ptr);
3263 if (tmp == 0xDEADBEEF)
3264 break;
3265 DRM_UDELAY(1);
3266 }
3267 if (i < rdev->usec_timeout) {
3268 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
3269 } else {
3270 DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp);
3271 r = -EINVAL;
3272 }
3273 radeon_ib_free(rdev, &ib);
3274 return r;
3275}
3276
3277/**
3278 * r600_dma_ring_ib_execute - Schedule an IB on the DMA engine
3279 *
3280 * @rdev: radeon_device pointer
3281 * @ib: IB object to schedule
3282 *
3283 * Schedule an IB in the DMA ring (r6xx-r7xx).
3284 */
3285void r600_dma_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3286{
3287 struct radeon_ring *ring = &rdev->ring[ib->ring];
3288
3289 if (rdev->wb.enabled) {
3290 u32 next_rptr = ring->wptr + 4;
3291 while ((next_rptr & 7) != 5)
3292 next_rptr++;
3293 next_rptr += 3;
3294 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
3295 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3296 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
3297 radeon_ring_write(ring, next_rptr);
3298 }
3299
3300 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
3301 * Pad as necessary with NOPs.
3302 */
3303 while ((ring->wptr & 7) != 5)
3304 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
3305 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0, 0));
3306 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
3307 radeon_ring_write(ring, (ib->length_dw << 16) | (upper_32_bits(ib->gpu_addr) & 0xFF));
3308
3309}
3310
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003311/*
3312 * Interrupts
3313 *
3314 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3315 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3316 * writing to the ring and the GPU consuming, the GPU writes to the ring
3317 * and host consumes. As the host irq handler processes interrupts, it
3318 * increments the rptr. When the rptr catches up with the wptr, all the
3319 * current interrupts have been processed.
3320 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003321
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003322void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
3323{
3324 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003325
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003326 /* Align ring size */
3327 rb_bufsz = drm_order(ring_size / 4);
3328 ring_size = (1 << rb_bufsz) * 4;
3329 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01003330 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
3331 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003332}
3333
Alex Deucher25a857f2012-03-20 17:18:22 -04003334int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003335{
3336 int r;
3337
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003338 /* Allocate ring buffer */
3339 if (rdev->ih.ring_obj == NULL) {
Daniel Vetter441921d2011-02-18 17:59:16 +01003340 r = radeon_bo_create(rdev, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05003341 PAGE_SIZE, true,
Jerome Glisse4c788672009-11-20 14:29:23 +01003342 RADEON_GEM_DOMAIN_GTT,
Alex Deucher40f5cf92012-05-10 18:33:13 -04003343 NULL, &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003344 if (r) {
3345 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
3346 return r;
3347 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003348 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3349 if (unlikely(r != 0))
3350 return r;
3351 r = radeon_bo_pin(rdev->ih.ring_obj,
3352 RADEON_GEM_DOMAIN_GTT,
3353 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003354 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003355 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003356 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
3357 return r;
3358 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003359 r = radeon_bo_kmap(rdev->ih.ring_obj,
3360 (void **)&rdev->ih.ring);
3361 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003362 if (r) {
3363 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
3364 return r;
3365 }
3366 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003367 return 0;
3368}
3369
Alex Deucher25a857f2012-03-20 17:18:22 -04003370void r600_ih_ring_fini(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003371{
Jerome Glisse4c788672009-11-20 14:29:23 +01003372 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003373 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003374 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3375 if (likely(r == 0)) {
3376 radeon_bo_kunmap(rdev->ih.ring_obj);
3377 radeon_bo_unpin(rdev->ih.ring_obj);
3378 radeon_bo_unreserve(rdev->ih.ring_obj);
3379 }
3380 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003381 rdev->ih.ring = NULL;
3382 rdev->ih.ring_obj = NULL;
3383 }
3384}
3385
Alex Deucher45f9a392010-03-24 13:55:51 -04003386void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003387{
3388
Alex Deucher45f9a392010-03-24 13:55:51 -04003389 if ((rdev->family >= CHIP_RV770) &&
3390 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003391 /* r7xx asics need to soft reset RLC before halting */
3392 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
3393 RREG32(SRBM_SOFT_RESET);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003394 mdelay(15);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003395 WREG32(SRBM_SOFT_RESET, 0);
3396 RREG32(SRBM_SOFT_RESET);
3397 }
3398
3399 WREG32(RLC_CNTL, 0);
3400}
3401
3402static void r600_rlc_start(struct radeon_device *rdev)
3403{
3404 WREG32(RLC_CNTL, RLC_ENABLE);
3405}
3406
3407static int r600_rlc_init(struct radeon_device *rdev)
3408{
3409 u32 i;
3410 const __be32 *fw_data;
3411
3412 if (!rdev->rlc_fw)
3413 return -EINVAL;
3414
3415 r600_rlc_stop(rdev);
3416
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003417 WREG32(RLC_HB_CNTL, 0);
Alex Deucherc420c742012-03-20 17:18:39 -04003418
3419 if (rdev->family == CHIP_ARUBA) {
3420 WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
3421 WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
3422 }
3423 if (rdev->family <= CHIP_CAYMAN) {
3424 WREG32(RLC_HB_BASE, 0);
3425 WREG32(RLC_HB_RPTR, 0);
3426 WREG32(RLC_HB_WPTR, 0);
3427 }
Alex Deucher12727802011-03-02 20:07:32 -05003428 if (rdev->family <= CHIP_CAICOS) {
3429 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
3430 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
3431 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003432 WREG32(RLC_MC_CNTL, 0);
3433 WREG32(RLC_UCODE_CNTL, 0);
3434
3435 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucherc420c742012-03-20 17:18:39 -04003436 if (rdev->family >= CHIP_ARUBA) {
3437 for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
3438 WREG32(RLC_UCODE_ADDR, i);
3439 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3440 }
3441 } else if (rdev->family >= CHIP_CAYMAN) {
Alex Deucher12727802011-03-02 20:07:32 -05003442 for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
3443 WREG32(RLC_UCODE_ADDR, i);
3444 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3445 }
3446 } else if (rdev->family >= CHIP_CEDAR) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003447 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
3448 WREG32(RLC_UCODE_ADDR, i);
3449 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3450 }
3451 } else if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003452 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
3453 WREG32(RLC_UCODE_ADDR, i);
3454 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3455 }
3456 } else {
3457 for (i = 0; i < RLC_UCODE_SIZE; i++) {
3458 WREG32(RLC_UCODE_ADDR, i);
3459 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3460 }
3461 }
3462 WREG32(RLC_UCODE_ADDR, 0);
3463
3464 r600_rlc_start(rdev);
3465
3466 return 0;
3467}
3468
3469static void r600_enable_interrupts(struct radeon_device *rdev)
3470{
3471 u32 ih_cntl = RREG32(IH_CNTL);
3472 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3473
3474 ih_cntl |= ENABLE_INTR;
3475 ih_rb_cntl |= IH_RB_ENABLE;
3476 WREG32(IH_CNTL, ih_cntl);
3477 WREG32(IH_RB_CNTL, ih_rb_cntl);
3478 rdev->ih.enabled = true;
3479}
3480
Alex Deucher45f9a392010-03-24 13:55:51 -04003481void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003482{
3483 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3484 u32 ih_cntl = RREG32(IH_CNTL);
3485
3486 ih_rb_cntl &= ~IH_RB_ENABLE;
3487 ih_cntl &= ~ENABLE_INTR;
3488 WREG32(IH_RB_CNTL, ih_rb_cntl);
3489 WREG32(IH_CNTL, ih_cntl);
3490 /* set rptr, wptr to 0 */
3491 WREG32(IH_RB_RPTR, 0);
3492 WREG32(IH_RB_WPTR, 0);
3493 rdev->ih.enabled = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003494 rdev->ih.rptr = 0;
3495}
3496
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003497static void r600_disable_interrupt_state(struct radeon_device *rdev)
3498{
3499 u32 tmp;
3500
Alex Deucher3555e532010-10-08 12:09:12 -04003501 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher4d756582012-09-27 15:08:35 -04003502 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3503 WREG32(DMA_CNTL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003504 WREG32(GRBM_INT_CNTL, 0);
3505 WREG32(DxMODE_INT_MASK, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003506 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
3507 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003508 if (ASIC_IS_DCE3(rdev)) {
3509 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
3510 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
3511 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3512 WREG32(DC_HPD1_INT_CONTROL, tmp);
3513 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3514 WREG32(DC_HPD2_INT_CONTROL, tmp);
3515 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3516 WREG32(DC_HPD3_INT_CONTROL, tmp);
3517 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3518 WREG32(DC_HPD4_INT_CONTROL, tmp);
3519 if (ASIC_IS_DCE32(rdev)) {
3520 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003521 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003522 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003523 WREG32(DC_HPD6_INT_CONTROL, tmp);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003524 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3525 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
3526 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3527 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003528 } else {
3529 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3530 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3531 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3532 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003533 }
3534 } else {
3535 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
3536 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
3537 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003538 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003539 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003540 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003541 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003542 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003543 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3544 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3545 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3546 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003547 }
3548}
3549
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003550int r600_irq_init(struct radeon_device *rdev)
3551{
3552 int ret = 0;
3553 int rb_bufsz;
3554 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
3555
3556 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01003557 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003558 if (ret)
3559 return ret;
3560
3561 /* disable irqs */
3562 r600_disable_interrupts(rdev);
3563
3564 /* init rlc */
3565 ret = r600_rlc_init(rdev);
3566 if (ret) {
3567 r600_ih_ring_fini(rdev);
3568 return ret;
3569 }
3570
3571 /* setup interrupt control */
3572 /* set dummy read address to ring address */
3573 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
3574 interrupt_cntl = RREG32(INTERRUPT_CNTL);
3575 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3576 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3577 */
3578 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
3579 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3580 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
3581 WREG32(INTERRUPT_CNTL, interrupt_cntl);
3582
3583 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
3584 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
3585
3586 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
3587 IH_WPTR_OVERFLOW_CLEAR |
3588 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04003589
3590 if (rdev->wb.enabled)
3591 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
3592
3593 /* set the writeback address whether it's enabled or not */
3594 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
3595 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 -05003596
3597 WREG32(IH_RB_CNTL, ih_rb_cntl);
3598
3599 /* set rptr, wptr to 0 */
3600 WREG32(IH_RB_RPTR, 0);
3601 WREG32(IH_RB_WPTR, 0);
3602
3603 /* Default settings for IH_CNTL (disabled at first) */
3604 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3605 /* RPTR_REARM only works if msi's are enabled */
3606 if (rdev->msi_enabled)
3607 ih_cntl |= RPTR_REARM;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003608 WREG32(IH_CNTL, ih_cntl);
3609
3610 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04003611 if (rdev->family >= CHIP_CEDAR)
3612 evergreen_disable_interrupt_state(rdev);
3613 else
3614 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003615
Dave Airlie20998102012-04-03 11:53:05 +01003616 /* at this point everything should be setup correctly to enable master */
3617 pci_set_master(rdev->pdev);
3618
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003619 /* enable irqs */
3620 r600_enable_interrupts(rdev);
3621
3622 return ret;
3623}
3624
Jerome Glisse0c452492010-01-15 14:44:37 +01003625void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003626{
Alex Deucher45f9a392010-03-24 13:55:51 -04003627 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003628 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003629}
3630
3631void r600_irq_fini(struct radeon_device *rdev)
3632{
3633 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003634 r600_ih_ring_fini(rdev);
3635}
3636
3637int r600_irq_set(struct radeon_device *rdev)
3638{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003639 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3640 u32 mode_int = 0;
3641 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04003642 u32 grbm_int_cntl = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003643 u32 hdmi0, hdmi1;
Alex Deucher6f34be52010-11-21 10:59:01 -05003644 u32 d1grph = 0, d2grph = 0;
Alex Deucher4d756582012-09-27 15:08:35 -04003645 u32 dma_cntl;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003646
Jerome Glisse003e69f2010-01-07 15:39:14 +01003647 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003648 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01003649 return -EINVAL;
3650 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003651 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003652 if (!rdev->ih.enabled) {
3653 r600_disable_interrupts(rdev);
3654 /* force the active interrupt state to all disabled */
3655 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003656 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003657 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003658
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003659 if (ASIC_IS_DCE3(rdev)) {
3660 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3661 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3662 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3663 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3664 if (ASIC_IS_DCE32(rdev)) {
3665 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3666 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003667 hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3668 hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
Alex Deucherf122c612012-03-30 08:59:57 -04003669 } else {
3670 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3671 hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003672 }
3673 } else {
3674 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3675 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3676 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
Alex Deucherf122c612012-03-30 08:59:57 -04003677 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3678 hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003679 }
Alex Deucher4d756582012-09-27 15:08:35 -04003680 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003681
Christian Koenig736fc372012-05-17 19:52:00 +02003682 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003683 DRM_DEBUG("r600_irq_set: sw int\n");
3684 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003685 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003686 }
Alex Deucher4d756582012-09-27 15:08:35 -04003687
3688 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
3689 DRM_DEBUG("r600_irq_set: sw int dma\n");
3690 dma_cntl |= TRAP_ENABLE;
3691 }
3692
Alex Deucher6f34be52010-11-21 10:59:01 -05003693 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003694 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003695 DRM_DEBUG("r600_irq_set: vblank 0\n");
3696 mode_int |= D1MODE_VBLANK_INT_MASK;
3697 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003698 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003699 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003700 DRM_DEBUG("r600_irq_set: vblank 1\n");
3701 mode_int |= D2MODE_VBLANK_INT_MASK;
3702 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003703 if (rdev->irq.hpd[0]) {
3704 DRM_DEBUG("r600_irq_set: hpd 1\n");
3705 hpd1 |= DC_HPDx_INT_EN;
3706 }
3707 if (rdev->irq.hpd[1]) {
3708 DRM_DEBUG("r600_irq_set: hpd 2\n");
3709 hpd2 |= DC_HPDx_INT_EN;
3710 }
3711 if (rdev->irq.hpd[2]) {
3712 DRM_DEBUG("r600_irq_set: hpd 3\n");
3713 hpd3 |= DC_HPDx_INT_EN;
3714 }
3715 if (rdev->irq.hpd[3]) {
3716 DRM_DEBUG("r600_irq_set: hpd 4\n");
3717 hpd4 |= DC_HPDx_INT_EN;
3718 }
3719 if (rdev->irq.hpd[4]) {
3720 DRM_DEBUG("r600_irq_set: hpd 5\n");
3721 hpd5 |= DC_HPDx_INT_EN;
3722 }
3723 if (rdev->irq.hpd[5]) {
3724 DRM_DEBUG("r600_irq_set: hpd 6\n");
3725 hpd6 |= DC_HPDx_INT_EN;
3726 }
Alex Deucherf122c612012-03-30 08:59:57 -04003727 if (rdev->irq.afmt[0]) {
3728 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3729 hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003730 }
Alex Deucherf122c612012-03-30 08:59:57 -04003731 if (rdev->irq.afmt[1]) {
3732 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3733 hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003734 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003735
3736 WREG32(CP_INT_CNTL, cp_int_cntl);
Alex Deucher4d756582012-09-27 15:08:35 -04003737 WREG32(DMA_CNTL, dma_cntl);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003738 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher6f34be52010-11-21 10:59:01 -05003739 WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
3740 WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
Alex Deucher2031f772010-04-22 12:52:11 -04003741 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003742 if (ASIC_IS_DCE3(rdev)) {
3743 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3744 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3745 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3746 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3747 if (ASIC_IS_DCE32(rdev)) {
3748 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3749 WREG32(DC_HPD6_INT_CONTROL, hpd6);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003750 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
3751 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
Alex Deucherf122c612012-03-30 08:59:57 -04003752 } else {
3753 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3754 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003755 }
3756 } else {
3757 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3758 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3759 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
Alex Deucherf122c612012-03-30 08:59:57 -04003760 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3761 WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003762 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003763
3764 return 0;
3765}
3766
Andi Kleence580fa2011-10-13 16:08:47 -07003767static void r600_irq_ack(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003768{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003769 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003770
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003771 if (ASIC_IS_DCE3(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003772 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3773 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3774 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
Alex Deucherf122c612012-03-30 08:59:57 -04003775 if (ASIC_IS_DCE32(rdev)) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003776 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
3777 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003778 } else {
3779 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3780 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
3781 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003782 } else {
Alex Deucher6f34be52010-11-21 10:59:01 -05003783 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3784 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3785 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003786 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3787 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003788 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003789 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3790 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003791
Alex Deucher6f34be52010-11-21 10:59:01 -05003792 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3793 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3794 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3795 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3796 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003797 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003798 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003799 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003800 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003801 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003802 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003803 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003804 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003805 if (ASIC_IS_DCE3(rdev)) {
3806 tmp = RREG32(DC_HPD1_INT_CONTROL);
3807 tmp |= DC_HPDx_INT_ACK;
3808 WREG32(DC_HPD1_INT_CONTROL, tmp);
3809 } else {
3810 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3811 tmp |= DC_HPDx_INT_ACK;
3812 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3813 }
3814 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003815 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003816 if (ASIC_IS_DCE3(rdev)) {
3817 tmp = RREG32(DC_HPD2_INT_CONTROL);
3818 tmp |= DC_HPDx_INT_ACK;
3819 WREG32(DC_HPD2_INT_CONTROL, tmp);
3820 } else {
3821 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3822 tmp |= DC_HPDx_INT_ACK;
3823 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3824 }
3825 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003826 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003827 if (ASIC_IS_DCE3(rdev)) {
3828 tmp = RREG32(DC_HPD3_INT_CONTROL);
3829 tmp |= DC_HPDx_INT_ACK;
3830 WREG32(DC_HPD3_INT_CONTROL, tmp);
3831 } else {
3832 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3833 tmp |= DC_HPDx_INT_ACK;
3834 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3835 }
3836 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003837 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003838 tmp = RREG32(DC_HPD4_INT_CONTROL);
3839 tmp |= DC_HPDx_INT_ACK;
3840 WREG32(DC_HPD4_INT_CONTROL, tmp);
3841 }
3842 if (ASIC_IS_DCE32(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003843 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003844 tmp = RREG32(DC_HPD5_INT_CONTROL);
3845 tmp |= DC_HPDx_INT_ACK;
3846 WREG32(DC_HPD5_INT_CONTROL, tmp);
3847 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003848 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003849 tmp = RREG32(DC_HPD5_INT_CONTROL);
3850 tmp |= DC_HPDx_INT_ACK;
3851 WREG32(DC_HPD6_INT_CONTROL, tmp);
3852 }
Alex Deucherf122c612012-03-30 08:59:57 -04003853 if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003854 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
Alex Deucherf122c612012-03-30 08:59:57 -04003855 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003856 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003857 }
3858 if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003859 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003860 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003861 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Christian Koenigf2594932010-04-10 03:13:16 +02003862 }
3863 } else {
Alex Deucherf122c612012-03-30 08:59:57 -04003864 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3865 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
3866 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3867 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3868 }
3869 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3870 if (ASIC_IS_DCE3(rdev)) {
3871 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
3872 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3873 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
3874 } else {
3875 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
3876 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3877 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
3878 }
Christian Koenigf2594932010-04-10 03:13:16 +02003879 }
3880 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003881}
3882
3883void r600_irq_disable(struct radeon_device *rdev)
3884{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003885 r600_disable_interrupts(rdev);
3886 /* Wait and acknowledge irq */
3887 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003888 r600_irq_ack(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003889 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003890}
3891
Andi Kleence580fa2011-10-13 16:08:47 -07003892static u32 r600_get_ih_wptr(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003893{
3894 u32 wptr, tmp;
3895
Alex Deucher724c80e2010-08-27 18:25:25 -04003896 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04003897 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04003898 else
3899 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003900
3901 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003902 /* When a ring buffer overflow happen start parsing interrupt
3903 * from the last not overwritten vector (wptr + 16). Hopefully
3904 * this should allow us to catchup.
3905 */
3906 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3907 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3908 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003909 tmp = RREG32(IH_RB_CNTL);
3910 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3911 WREG32(IH_RB_CNTL, tmp);
3912 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003913 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003914}
3915
3916/* r600 IV Ring
3917 * Each IV ring entry is 128 bits:
3918 * [7:0] - interrupt source id
3919 * [31:8] - reserved
3920 * [59:32] - interrupt source data
3921 * [127:60] - reserved
3922 *
3923 * The basic interrupt vector entries
3924 * are decoded as follows:
3925 * src_id src_data description
3926 * 1 0 D1 Vblank
3927 * 1 1 D1 Vline
3928 * 5 0 D2 Vblank
3929 * 5 1 D2 Vline
3930 * 19 0 FP Hot plug detection A
3931 * 19 1 FP Hot plug detection B
3932 * 19 2 DAC A auto-detection
3933 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003934 * 21 4 HDMI block A
3935 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003936 * 176 - CP_INT RB
3937 * 177 - CP_INT IB1
3938 * 178 - CP_INT IB2
3939 * 181 - EOP Interrupt
3940 * 233 - GUI Idle
3941 *
3942 * Note, these are based on r600 and may need to be
3943 * adjusted or added to on newer asics
3944 */
3945
3946int r600_irq_process(struct radeon_device *rdev)
3947{
Dave Airlie682f1a52011-06-18 03:59:51 +00003948 u32 wptr;
3949 u32 rptr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003950 u32 src_id, src_data;
Alex Deucher6f34be52010-11-21 10:59:01 -05003951 u32 ring_index;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003952 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04003953 bool queue_hdmi = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003954
Dave Airlie682f1a52011-06-18 03:59:51 +00003955 if (!rdev->ih.enabled || rdev->shutdown)
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003956 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003957
Benjamin Herrenschmidtf6a56932011-07-13 06:28:22 +00003958 /* No MSIs, need a dummy read to flush PCI DMAs */
3959 if (!rdev->msi_enabled)
3960 RREG32(IH_RB_WPTR);
3961
Dave Airlie682f1a52011-06-18 03:59:51 +00003962 wptr = r600_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02003963
3964restart_ih:
3965 /* is somebody else already processing irqs? */
3966 if (atomic_xchg(&rdev->ih.lock, 1))
3967 return IRQ_NONE;
3968
Dave Airlie682f1a52011-06-18 03:59:51 +00003969 rptr = rdev->ih.rptr;
3970 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
3971
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10003972 /* Order reading of wptr vs. reading of IH ring data */
3973 rmb();
3974
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003975 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05003976 r600_irq_ack(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003977
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003978 while (rptr != wptr) {
3979 /* wptr/rptr are in bytes! */
3980 ring_index = rptr / 4;
Cédric Cano4eace7f2011-02-11 19:45:38 -05003981 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3982 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003983
3984 switch (src_id) {
3985 case 1: /* D1 vblank/vline */
3986 switch (src_data) {
3987 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003988 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003989 if (rdev->irq.crtc_vblank_int[0]) {
3990 drm_handle_vblank(rdev->ddev, 0);
3991 rdev->pm.vblank_sync = true;
3992 wake_up(&rdev->irq.vblank_queue);
3993 }
Christian Koenig736fc372012-05-17 19:52:00 +02003994 if (atomic_read(&rdev->irq.pflip[0]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003995 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003996 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003997 DRM_DEBUG("IH: D1 vblank\n");
3998 }
3999 break;
4000 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004001 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
4002 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004003 DRM_DEBUG("IH: D1 vline\n");
4004 }
4005 break;
4006 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004007 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004008 break;
4009 }
4010 break;
4011 case 5: /* D2 vblank/vline */
4012 switch (src_data) {
4013 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004014 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05004015 if (rdev->irq.crtc_vblank_int[1]) {
4016 drm_handle_vblank(rdev->ddev, 1);
4017 rdev->pm.vblank_sync = true;
4018 wake_up(&rdev->irq.vblank_queue);
4019 }
Christian Koenig736fc372012-05-17 19:52:00 +02004020 if (atomic_read(&rdev->irq.pflip[1]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05004021 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05004022 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004023 DRM_DEBUG("IH: D2 vblank\n");
4024 }
4025 break;
4026 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004027 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
4028 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004029 DRM_DEBUG("IH: D2 vline\n");
4030 }
4031 break;
4032 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004033 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004034 break;
4035 }
4036 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004037 case 19: /* HPD/DAC hotplug */
4038 switch (src_data) {
4039 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05004040 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
4041 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004042 queue_hotplug = true;
4043 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004044 }
4045 break;
4046 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05004047 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
4048 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004049 queue_hotplug = true;
4050 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004051 }
4052 break;
4053 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05004054 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
4055 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004056 queue_hotplug = true;
4057 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004058 }
4059 break;
4060 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05004061 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
4062 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004063 queue_hotplug = true;
4064 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004065 }
4066 break;
4067 case 10:
Alex Deucher6f34be52010-11-21 10:59:01 -05004068 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
4069 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004070 queue_hotplug = true;
4071 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004072 }
4073 break;
4074 case 12:
Alex Deucher6f34be52010-11-21 10:59:01 -05004075 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
4076 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004077 queue_hotplug = true;
4078 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004079 }
4080 break;
4081 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004082 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004083 break;
4084 }
4085 break;
Alex Deucherf122c612012-03-30 08:59:57 -04004086 case 21: /* hdmi */
4087 switch (src_data) {
4088 case 4:
4089 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
4090 rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
4091 queue_hdmi = true;
4092 DRM_DEBUG("IH: HDMI0\n");
4093 }
4094 break;
4095 case 5:
4096 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
4097 rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
4098 queue_hdmi = true;
4099 DRM_DEBUG("IH: HDMI1\n");
4100 }
4101 break;
4102 default:
4103 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
4104 break;
4105 }
Christian Koenigf2594932010-04-10 03:13:16 +02004106 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004107 case 176: /* CP_INT in ring buffer */
4108 case 177: /* CP_INT in IB1 */
4109 case 178: /* CP_INT in IB2 */
4110 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04004111 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004112 break;
4113 case 181: /* CP EOP event */
4114 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher74652802011-08-25 13:39:48 -04004115 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004116 break;
Alex Deucher4d756582012-09-27 15:08:35 -04004117 case 224: /* DMA trap event */
4118 DRM_DEBUG("IH: DMA trap\n");
4119 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
4120 break;
Alex Deucher2031f772010-04-22 12:52:11 -04004121 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04004122 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04004123 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004124 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004125 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004126 break;
4127 }
4128
4129 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01004130 rptr += 16;
4131 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004132 }
Alex Deucherd4877cf2009-12-04 16:56:37 -05004133 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01004134 schedule_work(&rdev->hotplug_work);
Alex Deucherf122c612012-03-30 08:59:57 -04004135 if (queue_hdmi)
4136 schedule_work(&rdev->audio_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004137 rdev->ih.rptr = rptr;
4138 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02004139 atomic_set(&rdev->ih.lock, 0);
4140
4141 /* make sure wptr hasn't changed while processing */
4142 wptr = r600_get_ih_wptr(rdev);
4143 if (wptr != rptr)
4144 goto restart_ih;
4145
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004146 return IRQ_HANDLED;
4147}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004148
4149/*
4150 * Debugfs info
4151 */
4152#if defined(CONFIG_DEBUG_FS)
4153
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004154static int r600_debugfs_mc_info(struct seq_file *m, void *data)
4155{
4156 struct drm_info_node *node = (struct drm_info_node *) m->private;
4157 struct drm_device *dev = node->minor->dev;
4158 struct radeon_device *rdev = dev->dev_private;
4159
4160 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
4161 DREG32_SYS(m, rdev, VM_L2_STATUS);
4162 return 0;
4163}
4164
4165static struct drm_info_list r600_mc_info_list[] = {
4166 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004167};
4168#endif
4169
4170int r600_debugfs_mc_info_init(struct radeon_device *rdev)
4171{
4172#if defined(CONFIG_DEBUG_FS)
4173 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
4174#else
4175 return 0;
4176#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004177}
Jerome Glisse062b3892010-02-04 20:36:39 +01004178
4179/**
4180 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
4181 * rdev: radeon device structure
4182 * bo: buffer object struct which userspace is waiting for idle
4183 *
4184 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
4185 * through ring buffer, this leads to corruption in rendering, see
4186 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
4187 * directly perform HDP flush by writing register through MMIO.
4188 */
4189void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
4190{
Alex Deucher812d0462010-07-26 18:51:53 -04004191 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
Alex Deucherf3886f82010-12-08 10:05:34 -05004192 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
4193 * This seems to cause problems on some AGP cards. Just use the old
4194 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04004195 */
Alex Deuchere4884592010-09-27 10:57:10 -04004196 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
Alex Deucherf3886f82010-12-08 10:05:34 -05004197 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04004198 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04004199 u32 tmp;
4200
4201 WREG32(HDP_DEBUG1, 0);
4202 tmp = readl((void __iomem *)ptr);
4203 } else
4204 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01004205}
Alex Deucher3313e3d2011-01-06 18:49:34 -05004206
4207void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
4208{
4209 u32 link_width_cntl, mask, target_reg;
4210
4211 if (rdev->flags & RADEON_IS_IGP)
4212 return;
4213
4214 if (!(rdev->flags & RADEON_IS_PCIE))
4215 return;
4216
4217 /* x2 cards have a special sequence */
4218 if (ASIC_IS_X2(rdev))
4219 return;
4220
4221 /* FIXME wait for idle */
4222
4223 switch (lanes) {
4224 case 0:
4225 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
4226 break;
4227 case 1:
4228 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
4229 break;
4230 case 2:
4231 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
4232 break;
4233 case 4:
4234 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
4235 break;
4236 case 8:
4237 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
4238 break;
4239 case 12:
4240 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
4241 break;
4242 case 16:
4243 default:
4244 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
4245 break;
4246 }
4247
4248 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
4249
4250 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
4251 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
4252 return;
4253
4254 if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS)
4255 return;
4256
4257 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
4258 RADEON_PCIE_LC_RECONFIG_NOW |
4259 R600_PCIE_LC_RENEGOTIATE_EN |
4260 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
4261 link_width_cntl |= mask;
4262
4263 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4264
4265 /* some northbridges can renegotiate the link rather than requiring
4266 * a complete re-config.
4267 * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.)
4268 */
4269 if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT)
4270 link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT;
4271 else
4272 link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE;
4273
4274 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
4275 RADEON_PCIE_LC_RECONFIG_NOW));
4276
4277 if (rdev->family >= CHIP_RV770)
4278 target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX;
4279 else
4280 target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX;
4281
4282 /* wait for lane set to complete */
4283 link_width_cntl = RREG32(target_reg);
4284 while (link_width_cntl == 0xffffffff)
4285 link_width_cntl = RREG32(target_reg);
4286
4287}
4288
4289int r600_get_pcie_lanes(struct radeon_device *rdev)
4290{
4291 u32 link_width_cntl;
4292
4293 if (rdev->flags & RADEON_IS_IGP)
4294 return 0;
4295
4296 if (!(rdev->flags & RADEON_IS_PCIE))
4297 return 0;
4298
4299 /* x2 cards have a special sequence */
4300 if (ASIC_IS_X2(rdev))
4301 return 0;
4302
4303 /* FIXME wait for idle */
4304
4305 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
4306
4307 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
4308 case RADEON_PCIE_LC_LINK_WIDTH_X0:
4309 return 0;
4310 case RADEON_PCIE_LC_LINK_WIDTH_X1:
4311 return 1;
4312 case RADEON_PCIE_LC_LINK_WIDTH_X2:
4313 return 2;
4314 case RADEON_PCIE_LC_LINK_WIDTH_X4:
4315 return 4;
4316 case RADEON_PCIE_LC_LINK_WIDTH_X8:
4317 return 8;
4318 case RADEON_PCIE_LC_LINK_WIDTH_X16:
4319 default:
4320 return 16;
4321 }
4322}
4323
Alex Deucher9e46a482011-01-06 18:49:35 -05004324static void r600_pcie_gen2_enable(struct radeon_device *rdev)
4325{
4326 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
4327 u16 link_cntl2;
Dave Airlie197bbb32012-06-27 08:35:54 +01004328 u32 mask;
4329 int ret;
Alex Deucher9e46a482011-01-06 18:49:35 -05004330
Alex Deucherd42dd572011-01-12 20:05:11 -05004331 if (radeon_pcie_gen2 == 0)
4332 return;
4333
Alex Deucher9e46a482011-01-06 18:49:35 -05004334 if (rdev->flags & RADEON_IS_IGP)
4335 return;
4336
4337 if (!(rdev->flags & RADEON_IS_PCIE))
4338 return;
4339
4340 /* x2 cards have a special sequence */
4341 if (ASIC_IS_X2(rdev))
4342 return;
4343
4344 /* only RV6xx+ chips are supported */
4345 if (rdev->family <= CHIP_R600)
4346 return;
4347
Dave Airlie197bbb32012-06-27 08:35:54 +01004348 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
4349 if (ret != 0)
4350 return;
4351
4352 if (!(mask & DRM_PCIE_SPEED_50))
4353 return;
4354
Alex Deucher3691fee2012-10-08 17:46:27 -04004355 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4356 if (speed_cntl & LC_CURRENT_DATA_RATE) {
4357 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4358 return;
4359 }
4360
Dave Airlie197bbb32012-06-27 08:35:54 +01004361 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4362
Alex Deucher9e46a482011-01-06 18:49:35 -05004363 /* 55 nm r6xx asics */
4364 if ((rdev->family == CHIP_RV670) ||
4365 (rdev->family == CHIP_RV620) ||
4366 (rdev->family == CHIP_RV635)) {
4367 /* advertise upconfig capability */
4368 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4369 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4370 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4371 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4372 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
4373 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
4374 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
4375 LC_RECONFIG_ARC_MISSING_ESCAPE);
4376 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
4377 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4378 } else {
4379 link_width_cntl |= LC_UPCONFIGURE_DIS;
4380 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4381 }
4382 }
4383
4384 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4385 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
4386 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
4387
4388 /* 55 nm r6xx asics */
4389 if ((rdev->family == CHIP_RV670) ||
4390 (rdev->family == CHIP_RV620) ||
4391 (rdev->family == CHIP_RV635)) {
4392 WREG32(MM_CFGREGS_CNTL, 0x8);
4393 link_cntl2 = RREG32(0x4088);
4394 WREG32(MM_CFGREGS_CNTL, 0);
4395 /* not supported yet */
4396 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
4397 return;
4398 }
4399
4400 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
4401 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
4402 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
4403 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
4404 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
4405 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4406
4407 tmp = RREG32(0x541c);
4408 WREG32(0x541c, tmp | 0x8);
4409 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
4410 link_cntl2 = RREG16(0x4088);
4411 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
4412 link_cntl2 |= 0x2;
4413 WREG16(0x4088, link_cntl2);
4414 WREG32(MM_CFGREGS_CNTL, 0);
4415
4416 if ((rdev->family == CHIP_RV670) ||
4417 (rdev->family == CHIP_RV620) ||
4418 (rdev->family == CHIP_RV635)) {
4419 training_cntl = RREG32_PCIE_P(PCIE_LC_TRAINING_CNTL);
4420 training_cntl &= ~LC_POINT_7_PLUS_EN;
4421 WREG32_PCIE_P(PCIE_LC_TRAINING_CNTL, training_cntl);
4422 } else {
4423 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4424 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
4425 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4426 }
4427
4428 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4429 speed_cntl |= LC_GEN2_EN_STRAP;
4430 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4431
4432 } else {
4433 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4434 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4435 if (1)
4436 link_width_cntl |= LC_UPCONFIGURE_DIS;
4437 else
4438 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4439 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4440 }
4441}
Marek Olšák6759a0a2012-08-09 16:34:17 +02004442
4443/**
4444 * r600_get_gpu_clock - return GPU clock counter snapshot
4445 *
4446 * @rdev: radeon_device pointer
4447 *
4448 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4449 * Returns the 64 bit clock counter snapshot.
4450 */
4451uint64_t r600_get_gpu_clock(struct radeon_device *rdev)
4452{
4453 uint64_t clock;
4454
4455 mutex_lock(&rdev->gpu_clock_mutex);
4456 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
4457 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
4458 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
4459 mutex_unlock(&rdev->gpu_clock_mutex);
4460 return clock;
4461}