blob: 2a1b1876b4312eb332c017cb027aeb346bf2c850 [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>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040031#include <linux/module.h>
David Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
33#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020034#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000035#include "radeon_asic.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100036#include "radeon_mode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100037#include "r600d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100038#include "atom.h"
Jerome Glissed39c3b82009-09-28 18:34:43 +020039#include "avivod.h"
Alex Deucher138e4e12013-01-11 15:33:13 -050040#include "radeon_ucode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100041
42/* Firmware Names */
43MODULE_FIRMWARE("radeon/R600_pfp.bin");
44MODULE_FIRMWARE("radeon/R600_me.bin");
45MODULE_FIRMWARE("radeon/RV610_pfp.bin");
46MODULE_FIRMWARE("radeon/RV610_me.bin");
47MODULE_FIRMWARE("radeon/RV630_pfp.bin");
48MODULE_FIRMWARE("radeon/RV630_me.bin");
49MODULE_FIRMWARE("radeon/RV620_pfp.bin");
50MODULE_FIRMWARE("radeon/RV620_me.bin");
51MODULE_FIRMWARE("radeon/RV635_pfp.bin");
52MODULE_FIRMWARE("radeon/RV635_me.bin");
53MODULE_FIRMWARE("radeon/RV670_pfp.bin");
54MODULE_FIRMWARE("radeon/RV670_me.bin");
55MODULE_FIRMWARE("radeon/RS780_pfp.bin");
56MODULE_FIRMWARE("radeon/RS780_me.bin");
57MODULE_FIRMWARE("radeon/RV770_pfp.bin");
58MODULE_FIRMWARE("radeon/RV770_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040059MODULE_FIRMWARE("radeon/RV770_smc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100060MODULE_FIRMWARE("radeon/RV730_pfp.bin");
61MODULE_FIRMWARE("radeon/RV730_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040062MODULE_FIRMWARE("radeon/RV730_smc.bin");
63MODULE_FIRMWARE("radeon/RV740_smc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100064MODULE_FIRMWARE("radeon/RV710_pfp.bin");
65MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040066MODULE_FIRMWARE("radeon/RV710_smc.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050067MODULE_FIRMWARE("radeon/R600_rlc.bin");
68MODULE_FIRMWARE("radeon/R700_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040069MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
70MODULE_FIRMWARE("radeon/CEDAR_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040071MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040072MODULE_FIRMWARE("radeon/CEDAR_smc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040073MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
74MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040075MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040076MODULE_FIRMWARE("radeon/REDWOOD_smc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040077MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
78MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040079MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040080MODULE_FIRMWARE("radeon/JUNIPER_smc.bin");
Dave Airliea7433742010-04-09 15:31:09 +100081MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040082MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040083MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040084MODULE_FIRMWARE("radeon/CYPRESS_smc.bin");
Alex Deucher439bd6c2010-11-22 17:56:31 -050085MODULE_FIRMWARE("radeon/PALM_pfp.bin");
86MODULE_FIRMWARE("radeon/PALM_me.bin");
87MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
Alex Deucherd5c5a722011-05-31 15:42:48 -040088MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
89MODULE_FIRMWARE("radeon/SUMO_me.bin");
90MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
91MODULE_FIRMWARE("radeon/SUMO2_me.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100092
Alex Deucherf13f7732013-01-18 18:12:22 -050093static const u32 crtc_offsets[2] =
94{
95 0,
96 AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
97};
98
Jerome Glisse3ce0a232009-09-08 10:10:24 +100099int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200100
Jerome Glisse1a029b72009-10-06 19:04:30 +0200101/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200102int r600_mc_wait_for_idle(struct radeon_device *rdev);
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400103static void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000104void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -0400105void r600_irq_disable(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -0500106static void r600_pcie_gen2_enable(struct radeon_device *rdev);
Alex Deucher2948f5e2013-04-12 13:52:52 -0400107extern int evergreen_rlc_resume(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200108
Alex Deucher454d2e22013-02-14 10:04:02 -0500109/**
110 * r600_get_xclk - get the xclk
111 *
112 * @rdev: radeon_device pointer
113 *
114 * Returns the reference clock used by the gfx engine
115 * (r6xx, IGPs, APUs).
116 */
117u32 r600_get_xclk(struct radeon_device *rdev)
118{
119 return rdev->clock.spll.reference_freq;
120}
121
Alex Deucher1b9ba702013-09-05 09:52:37 -0400122int r600_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
123{
124 return 0;
125}
126
Alex Deucher21a81222010-07-02 12:58:16 -0400127/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500128int rv6xx_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400129{
130 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
131 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -0500132 int actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -0400133
Alex Deucher20d391d2011-02-01 16:12:34 -0500134 if (temp & 0x100)
135 actual_temp -= 256;
136
137 return actual_temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400138}
139
Alex Deucherce8f5372010-05-07 15:10:16 -0400140void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400141{
142 int i;
143
Alex Deucherce8f5372010-05-07 15:10:16 -0400144 rdev->pm.dynpm_can_upclock = true;
145 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400146
147 /* power state array is low to high, default is first */
148 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
149 int min_power_state_index = 0;
150
151 if (rdev->pm.num_power_states > 2)
152 min_power_state_index = 1;
153
Alex Deucherce8f5372010-05-07 15:10:16 -0400154 switch (rdev->pm.dynpm_planned_action) {
155 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400156 rdev->pm.requested_power_state_index = min_power_state_index;
157 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400158 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400159 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400160 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400161 if (rdev->pm.current_power_state_index == min_power_state_index) {
162 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400163 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400164 } else {
165 if (rdev->pm.active_crtc_count > 1) {
166 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400167 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400168 continue;
169 else if (i >= rdev->pm.current_power_state_index) {
170 rdev->pm.requested_power_state_index =
171 rdev->pm.current_power_state_index;
172 break;
173 } else {
174 rdev->pm.requested_power_state_index = i;
175 break;
176 }
177 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400178 } else {
179 if (rdev->pm.current_power_state_index == 0)
180 rdev->pm.requested_power_state_index =
181 rdev->pm.num_power_states - 1;
182 else
183 rdev->pm.requested_power_state_index =
184 rdev->pm.current_power_state_index - 1;
185 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400186 }
187 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400188 /* don't use the power state if crtcs are active and no display flag is set */
189 if ((rdev->pm.active_crtc_count > 0) &&
190 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
191 clock_info[rdev->pm.requested_clock_mode_index].flags &
192 RADEON_PM_MODE_NO_DISPLAY)) {
193 rdev->pm.requested_power_state_index++;
194 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400195 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400196 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400197 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
198 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400199 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400200 } else {
201 if (rdev->pm.active_crtc_count > 1) {
202 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400203 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400204 continue;
205 else if (i <= rdev->pm.current_power_state_index) {
206 rdev->pm.requested_power_state_index =
207 rdev->pm.current_power_state_index;
208 break;
209 } else {
210 rdev->pm.requested_power_state_index = i;
211 break;
212 }
213 }
214 } else
215 rdev->pm.requested_power_state_index =
216 rdev->pm.current_power_state_index + 1;
217 }
218 rdev->pm.requested_clock_mode_index = 0;
219 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400220 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400221 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
222 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400223 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400224 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400225 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400226 default:
227 DRM_ERROR("Requested mode for not defined action\n");
228 return;
229 }
230 } else {
231 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
232 /* for now just select the first power state and switch between clock modes */
233 /* power state array is low to high, default is first (0) */
234 if (rdev->pm.active_crtc_count > 1) {
235 rdev->pm.requested_power_state_index = -1;
236 /* start at 1 as we don't want the default mode */
237 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400238 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400239 continue;
240 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
241 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
242 rdev->pm.requested_power_state_index = i;
243 break;
244 }
245 }
246 /* if nothing selected, grab the default state. */
247 if (rdev->pm.requested_power_state_index == -1)
248 rdev->pm.requested_power_state_index = 0;
249 } else
250 rdev->pm.requested_power_state_index = 1;
251
Alex Deucherce8f5372010-05-07 15:10:16 -0400252 switch (rdev->pm.dynpm_planned_action) {
253 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400254 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400255 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400256 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400257 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400258 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
259 if (rdev->pm.current_clock_mode_index == 0) {
260 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400261 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400262 } else
263 rdev->pm.requested_clock_mode_index =
264 rdev->pm.current_clock_mode_index - 1;
265 } else {
266 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400267 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400268 }
Alex Deucherd7311172010-05-03 01:13:14 -0400269 /* don't use the power state if crtcs are active and no display flag is set */
270 if ((rdev->pm.active_crtc_count > 0) &&
271 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
272 clock_info[rdev->pm.requested_clock_mode_index].flags &
273 RADEON_PM_MODE_NO_DISPLAY)) {
274 rdev->pm.requested_clock_mode_index++;
275 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400276 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400277 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400278 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
279 if (rdev->pm.current_clock_mode_index ==
280 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
281 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400282 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400283 } else
284 rdev->pm.requested_clock_mode_index =
285 rdev->pm.current_clock_mode_index + 1;
286 } else {
287 rdev->pm.requested_clock_mode_index =
288 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400289 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400290 }
291 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400292 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400293 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
294 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400295 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400296 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400297 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400298 default:
299 DRM_ERROR("Requested mode for not defined action\n");
300 return;
301 }
302 }
303
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000304 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400305 rdev->pm.power_state[rdev->pm.requested_power_state_index].
306 clock_info[rdev->pm.requested_clock_mode_index].sclk,
307 rdev->pm.power_state[rdev->pm.requested_power_state_index].
308 clock_info[rdev->pm.requested_clock_mode_index].mclk,
309 rdev->pm.power_state[rdev->pm.requested_power_state_index].
310 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400311}
312
Alex Deucherce8f5372010-05-07 15:10:16 -0400313void rs780_pm_init_profile(struct radeon_device *rdev)
314{
315 if (rdev->pm.num_power_states == 2) {
316 /* default */
317 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
318 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
319 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
320 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
321 /* low sh */
322 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
323 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
325 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400326 /* mid sh */
327 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
328 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
330 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400331 /* high sh */
332 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
333 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
334 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
335 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
336 /* low mh */
337 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
338 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
339 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
340 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400341 /* mid mh */
342 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
343 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
344 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
345 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400346 /* high mh */
347 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
348 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
349 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
350 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
351 } else if (rdev->pm.num_power_states == 3) {
352 /* default */
353 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
354 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
355 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
356 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
357 /* low sh */
358 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
359 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
360 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
361 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400362 /* mid sh */
363 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
364 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
365 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
366 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400367 /* high sh */
368 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
369 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
370 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
371 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
372 /* low mh */
373 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
374 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
375 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
376 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400377 /* mid mh */
378 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
379 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
380 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
381 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400382 /* high mh */
383 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
384 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
385 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
386 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
387 } else {
388 /* default */
389 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
390 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
391 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
392 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
393 /* low sh */
394 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
395 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
396 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
397 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400398 /* mid sh */
399 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
400 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
401 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
402 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400403 /* high sh */
404 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
405 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
406 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
407 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
408 /* low mh */
409 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
410 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
411 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
412 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400413 /* mid mh */
414 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
415 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
416 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
417 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400418 /* high mh */
419 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
420 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
421 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
422 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
423 }
424}
425
426void r600_pm_init_profile(struct radeon_device *rdev)
427{
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400428 int idx;
429
Alex Deucherce8f5372010-05-07 15:10:16 -0400430 if (rdev->family == CHIP_R600) {
431 /* XXX */
432 /* default */
433 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
435 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400436 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400437 /* low sh */
438 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
440 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400441 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400442 /* mid sh */
443 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
445 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
446 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400447 /* high sh */
448 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
449 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
450 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400451 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400452 /* low mh */
453 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
454 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
455 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400456 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400457 /* mid mh */
458 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
459 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
460 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
461 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400462 /* high mh */
463 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
464 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
465 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400466 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400467 } else {
468 if (rdev->pm.num_power_states < 4) {
469 /* default */
470 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
471 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
472 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
473 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
474 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400475 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
476 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
477 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400478 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
479 /* mid sh */
480 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
481 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
482 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
483 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400484 /* high sh */
485 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
486 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
487 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
488 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
489 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400490 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
491 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400492 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400493 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
494 /* low mh */
495 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
496 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
497 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
498 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400499 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400500 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
501 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
502 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
503 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
504 } else {
505 /* default */
506 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
507 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
508 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
509 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
510 /* low sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400511 if (rdev->flags & RADEON_IS_MOBILITY)
512 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
513 else
514 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
515 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
516 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
517 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
518 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400519 /* mid sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400520 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
521 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
522 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
523 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400524 /* high sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400525 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
526 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
527 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
Alex Deucher4bff5172010-05-17 19:41:26 -0400528 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
529 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
530 /* low mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400531 if (rdev->flags & RADEON_IS_MOBILITY)
532 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
533 else
534 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
535 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
536 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
537 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
538 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400539 /* mid mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400540 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
541 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
542 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
543 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400544 /* high mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400545 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
546 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
547 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
Alex Deucherce8f5372010-05-07 15:10:16 -0400548 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
549 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
550 }
551 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400552}
553
Alex Deucher49e02b72010-04-23 17:57:27 -0400554void r600_pm_misc(struct radeon_device *rdev)
555{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400556 int req_ps_idx = rdev->pm.requested_power_state_index;
557 int req_cm_idx = rdev->pm.requested_clock_mode_index;
558 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
559 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400560
Alex Deucher4d601732010-06-07 18:15:18 -0400561 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
Alex Deuchera377e182011-06-20 13:00:31 -0400562 /* 0xff01 is a flag rather then an actual voltage */
563 if (voltage->voltage == 0xff01)
564 return;
Alex Deucher4d601732010-06-07 18:15:18 -0400565 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400566 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400567 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000568 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400569 }
570 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400571}
572
Alex Deucherdef9ba92010-04-22 12:39:58 -0400573bool r600_gui_idle(struct radeon_device *rdev)
574{
575 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
576 return false;
577 else
578 return true;
579}
580
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500581/* hpd for digital panel detect/disconnect */
582bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
583{
584 bool connected = false;
585
586 if (ASIC_IS_DCE3(rdev)) {
587 switch (hpd) {
588 case RADEON_HPD_1:
589 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
590 connected = true;
591 break;
592 case RADEON_HPD_2:
593 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
594 connected = true;
595 break;
596 case RADEON_HPD_3:
597 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
598 connected = true;
599 break;
600 case RADEON_HPD_4:
601 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
602 connected = true;
603 break;
604 /* DCE 3.2 */
605 case RADEON_HPD_5:
606 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
607 connected = true;
608 break;
609 case RADEON_HPD_6:
610 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
611 connected = true;
612 break;
613 default:
614 break;
615 }
616 } else {
617 switch (hpd) {
618 case RADEON_HPD_1:
619 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
620 connected = true;
621 break;
622 case RADEON_HPD_2:
623 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
624 connected = true;
625 break;
626 case RADEON_HPD_3:
627 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
628 connected = true;
629 break;
630 default:
631 break;
632 }
633 }
634 return connected;
635}
636
637void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500638 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500639{
640 u32 tmp;
641 bool connected = r600_hpd_sense(rdev, hpd);
642
643 if (ASIC_IS_DCE3(rdev)) {
644 switch (hpd) {
645 case RADEON_HPD_1:
646 tmp = RREG32(DC_HPD1_INT_CONTROL);
647 if (connected)
648 tmp &= ~DC_HPDx_INT_POLARITY;
649 else
650 tmp |= DC_HPDx_INT_POLARITY;
651 WREG32(DC_HPD1_INT_CONTROL, tmp);
652 break;
653 case RADEON_HPD_2:
654 tmp = RREG32(DC_HPD2_INT_CONTROL);
655 if (connected)
656 tmp &= ~DC_HPDx_INT_POLARITY;
657 else
658 tmp |= DC_HPDx_INT_POLARITY;
659 WREG32(DC_HPD2_INT_CONTROL, tmp);
660 break;
661 case RADEON_HPD_3:
662 tmp = RREG32(DC_HPD3_INT_CONTROL);
663 if (connected)
664 tmp &= ~DC_HPDx_INT_POLARITY;
665 else
666 tmp |= DC_HPDx_INT_POLARITY;
667 WREG32(DC_HPD3_INT_CONTROL, tmp);
668 break;
669 case RADEON_HPD_4:
670 tmp = RREG32(DC_HPD4_INT_CONTROL);
671 if (connected)
672 tmp &= ~DC_HPDx_INT_POLARITY;
673 else
674 tmp |= DC_HPDx_INT_POLARITY;
675 WREG32(DC_HPD4_INT_CONTROL, tmp);
676 break;
677 case RADEON_HPD_5:
678 tmp = RREG32(DC_HPD5_INT_CONTROL);
679 if (connected)
680 tmp &= ~DC_HPDx_INT_POLARITY;
681 else
682 tmp |= DC_HPDx_INT_POLARITY;
683 WREG32(DC_HPD5_INT_CONTROL, tmp);
684 break;
685 /* DCE 3.2 */
686 case RADEON_HPD_6:
687 tmp = RREG32(DC_HPD6_INT_CONTROL);
688 if (connected)
689 tmp &= ~DC_HPDx_INT_POLARITY;
690 else
691 tmp |= DC_HPDx_INT_POLARITY;
692 WREG32(DC_HPD6_INT_CONTROL, tmp);
693 break;
694 default:
695 break;
696 }
697 } else {
698 switch (hpd) {
699 case RADEON_HPD_1:
700 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
701 if (connected)
702 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
703 else
704 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
705 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
706 break;
707 case RADEON_HPD_2:
708 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
709 if (connected)
710 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
711 else
712 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
713 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
714 break;
715 case RADEON_HPD_3:
716 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
717 if (connected)
718 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
719 else
720 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
721 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
722 break;
723 default:
724 break;
725 }
726 }
727}
728
729void r600_hpd_init(struct radeon_device *rdev)
730{
731 struct drm_device *dev = rdev->ddev;
732 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200733 unsigned enable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500734
Alex Deucher64912e92011-11-03 11:21:39 -0400735 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
736 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500737
Jerome Glisse455c89b2012-05-04 11:06:22 -0400738 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
739 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
740 /* don't try to enable hpd on eDP or LVDS avoid breaking the
741 * aux dp channel on imac and help (but not completely fix)
742 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
743 */
744 continue;
745 }
Alex Deucher64912e92011-11-03 11:21:39 -0400746 if (ASIC_IS_DCE3(rdev)) {
747 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
748 if (ASIC_IS_DCE32(rdev))
749 tmp |= DC_HPDx_EN;
750
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500751 switch (radeon_connector->hpd.hpd) {
752 case RADEON_HPD_1:
753 WREG32(DC_HPD1_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500754 break;
755 case RADEON_HPD_2:
756 WREG32(DC_HPD2_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500757 break;
758 case RADEON_HPD_3:
759 WREG32(DC_HPD3_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500760 break;
761 case RADEON_HPD_4:
762 WREG32(DC_HPD4_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500763 break;
764 /* DCE 3.2 */
765 case RADEON_HPD_5:
766 WREG32(DC_HPD5_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500767 break;
768 case RADEON_HPD_6:
769 WREG32(DC_HPD6_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500770 break;
771 default:
772 break;
773 }
Alex Deucher64912e92011-11-03 11:21:39 -0400774 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500775 switch (radeon_connector->hpd.hpd) {
776 case RADEON_HPD_1:
777 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500778 break;
779 case RADEON_HPD_2:
780 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500781 break;
782 case RADEON_HPD_3:
783 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500784 break;
785 default:
786 break;
787 }
788 }
Christian Koenigfb982572012-05-17 01:33:30 +0200789 enable |= 1 << radeon_connector->hpd.hpd;
Alex Deucher64912e92011-11-03 11:21:39 -0400790 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500791 }
Christian Koenigfb982572012-05-17 01:33:30 +0200792 radeon_irq_kms_enable_hpd(rdev, enable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500793}
794
795void r600_hpd_fini(struct radeon_device *rdev)
796{
797 struct drm_device *dev = rdev->ddev;
798 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200799 unsigned disable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500800
Christian Koenigfb982572012-05-17 01:33:30 +0200801 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
802 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
803 if (ASIC_IS_DCE3(rdev)) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500804 switch (radeon_connector->hpd.hpd) {
805 case RADEON_HPD_1:
806 WREG32(DC_HPD1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500807 break;
808 case RADEON_HPD_2:
809 WREG32(DC_HPD2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500810 break;
811 case RADEON_HPD_3:
812 WREG32(DC_HPD3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500813 break;
814 case RADEON_HPD_4:
815 WREG32(DC_HPD4_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500816 break;
817 /* DCE 3.2 */
818 case RADEON_HPD_5:
819 WREG32(DC_HPD5_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500820 break;
821 case RADEON_HPD_6:
822 WREG32(DC_HPD6_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500823 break;
824 default:
825 break;
826 }
Christian Koenigfb982572012-05-17 01:33:30 +0200827 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500828 switch (radeon_connector->hpd.hpd) {
829 case RADEON_HPD_1:
830 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500831 break;
832 case RADEON_HPD_2:
833 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500834 break;
835 case RADEON_HPD_3:
836 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500837 break;
838 default:
839 break;
840 }
841 }
Christian Koenigfb982572012-05-17 01:33:30 +0200842 disable |= 1 << radeon_connector->hpd.hpd;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500843 }
Christian Koenigfb982572012-05-17 01:33:30 +0200844 radeon_irq_kms_disable_hpd(rdev, disable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500845}
846
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000848 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200849 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000850void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200851{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000852 unsigned i;
853 u32 tmp;
854
Dave Airlie2e98f102010-02-15 15:54:45 +1000855 /* flush hdp cache so updates hit vram */
Alex Deucherf3886f82010-12-08 10:05:34 -0500856 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
857 !(rdev->flags & RADEON_IS_AGP)) {
Jerome Glissec9a1be92011-11-03 11:16:49 -0400858 void __iomem *ptr = (void *)rdev->gart.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -0400859 u32 tmp;
860
861 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
862 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
Alex Deucherf3886f82010-12-08 10:05:34 -0500863 * This seems to cause problems on some AGP cards. Just use the old
864 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -0400865 */
866 WREG32(HDP_DEBUG1, 0);
867 tmp = readl((void __iomem *)ptr);
868 } else
869 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +1000870
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000871 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
872 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
873 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
874 for (i = 0; i < rdev->usec_timeout; i++) {
875 /* read MC_STATUS */
876 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
877 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
878 if (tmp == 2) {
879 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
880 return;
881 }
882 if (tmp) {
883 return;
884 }
885 udelay(1);
886 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887}
888
Jerome Glisse4aac0472009-09-14 18:29:49 +0200889int r600_pcie_gart_init(struct radeon_device *rdev)
890{
891 int r;
892
Jerome Glissec9a1be92011-11-03 11:16:49 -0400893 if (rdev->gart.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +0000894 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +0200895 return 0;
896 }
897 /* Initialize common gart structure */
898 r = radeon_gart_init(rdev);
899 if (r)
900 return r;
901 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
902 return radeon_gart_table_vram_alloc(rdev);
903}
904
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400905static int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200906{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000907 u32 tmp;
908 int r, i;
909
Jerome Glissec9a1be92011-11-03 11:16:49 -0400910 if (rdev->gart.robj == NULL) {
Jerome Glisse4aac0472009-09-14 18:29:49 +0200911 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
912 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000913 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200914 r = radeon_gart_table_vram_pin(rdev);
915 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000916 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000917 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000918
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000919 /* Setup L2 cache */
920 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
921 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
922 EFFECTIVE_L2_QUEUE_SIZE(7));
923 WREG32(VM_L2_CNTL2, 0);
924 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
925 /* Setup TLB control */
926 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
927 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
928 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
929 ENABLE_WAIT_L2_QUERY;
930 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
931 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
932 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
933 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
934 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
935 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
936 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
937 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
938 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
939 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
940 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
941 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
942 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
943 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
944 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200945 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000946 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
947 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
948 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
949 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
950 (u32)(rdev->dummy_page.addr >> 12));
951 for (i = 1; i < 7; i++)
952 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
953
954 r600_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000955 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
956 (unsigned)(rdev->mc.gtt_size >> 20),
957 (unsigned long long)rdev->gart.table_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000958 rdev->gart.ready = true;
959 return 0;
960}
961
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400962static void r600_pcie_gart_disable(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000963{
964 u32 tmp;
Jerome Glissec9a1be92011-11-03 11:16:49 -0400965 int i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000966
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000967 /* Disable all tables */
968 for (i = 0; i < 7; i++)
969 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
970
971 /* Disable L2 cache */
972 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
973 EFFECTIVE_L2_QUEUE_SIZE(7));
974 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
975 /* Setup L1 TLB control */
976 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
977 ENABLE_WAIT_L2_QUERY;
978 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
979 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
980 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
981 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
982 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
983 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
984 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
985 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
986 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
987 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
988 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
989 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
990 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
991 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -0400992 radeon_gart_table_vram_unpin(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200993}
994
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400995static void r600_pcie_gart_fini(struct radeon_device *rdev)
Jerome Glisse4aac0472009-09-14 18:29:49 +0200996{
Jerome Glissef9274562010-03-17 14:44:29 +0000997 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200998 r600_pcie_gart_disable(rdev);
999 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001000}
1001
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001002static void r600_agp_enable(struct radeon_device *rdev)
Jerome Glisse1a029b72009-10-06 19:04:30 +02001003{
1004 u32 tmp;
1005 int i;
1006
1007 /* Setup L2 cache */
1008 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1009 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1010 EFFECTIVE_L2_QUEUE_SIZE(7));
1011 WREG32(VM_L2_CNTL2, 0);
1012 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1013 /* Setup TLB control */
1014 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1015 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1016 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1017 ENABLE_WAIT_L2_QUERY;
1018 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1019 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1020 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1021 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1022 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1023 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1024 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1025 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1026 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1027 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1028 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1029 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1030 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1031 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1032 for (i = 0; i < 7; i++)
1033 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1034}
1035
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001036int r600_mc_wait_for_idle(struct radeon_device *rdev)
1037{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001038 unsigned i;
1039 u32 tmp;
1040
1041 for (i = 0; i < rdev->usec_timeout; i++) {
1042 /* read MC_STATUS */
1043 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1044 if (!tmp)
1045 return 0;
1046 udelay(1);
1047 }
1048 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001049}
1050
Samuel Li65337e62013-04-05 17:50:53 -04001051uint32_t rs780_mc_rreg(struct radeon_device *rdev, uint32_t reg)
1052{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001053 unsigned long flags;
Samuel Li65337e62013-04-05 17:50:53 -04001054 uint32_t r;
1055
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001056 spin_lock_irqsave(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001057 WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg));
1058 r = RREG32(R_0028FC_MC_DATA);
1059 WREG32(R_0028F8_MC_INDEX, ~C_0028F8_MC_IND_ADDR);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001060 spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001061 return r;
1062}
1063
1064void rs780_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1065{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001066 unsigned long flags;
1067
1068 spin_lock_irqsave(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001069 WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg) |
1070 S_0028F8_MC_IND_WR_EN(1));
1071 WREG32(R_0028FC_MC_DATA, v);
1072 WREG32(R_0028F8_MC_INDEX, 0x7F);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001073 spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001074}
1075
Jerome Glissea3c19452009-10-01 18:02:13 +02001076static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001077{
Jerome Glissea3c19452009-10-01 18:02:13 +02001078 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001079 u32 tmp;
1080 int i, j;
1081
1082 /* Initialize HDP */
1083 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1084 WREG32((0x2c14 + j), 0x00000000);
1085 WREG32((0x2c18 + j), 0x00000000);
1086 WREG32((0x2c1c + j), 0x00000000);
1087 WREG32((0x2c20 + j), 0x00000000);
1088 WREG32((0x2c24 + j), 0x00000000);
1089 }
1090 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1091
Jerome Glissea3c19452009-10-01 18:02:13 +02001092 rv515_mc_stop(rdev, &save);
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 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001097 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001098 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001099 if (rdev->flags & RADEON_IS_AGP) {
1100 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1101 /* VRAM before AGP */
1102 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1103 rdev->mc.vram_start >> 12);
1104 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1105 rdev->mc.gtt_end >> 12);
1106 } else {
1107 /* VRAM after AGP */
1108 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1109 rdev->mc.gtt_start >> 12);
1110 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1111 rdev->mc.vram_end >> 12);
1112 }
1113 } else {
1114 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1115 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1116 }
Alex Deucher16cdf042011-10-28 10:30:02 -04001117 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001118 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001119 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1120 WREG32(MC_VM_FB_LOCATION, tmp);
1121 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1122 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001123 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001124 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001125 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1126 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001127 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1128 } else {
1129 WREG32(MC_VM_AGP_BASE, 0);
1130 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1131 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1132 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001133 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001134 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001135 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001136 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001137 /* we need to own VRAM, so turn off the VGA renderer here
1138 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001139 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001140}
1141
Jerome Glissed594e462010-02-17 21:54:29 +00001142/**
1143 * r600_vram_gtt_location - try to find VRAM & GTT location
1144 * @rdev: radeon device structure holding all necessary informations
1145 * @mc: memory controller structure holding memory informations
1146 *
1147 * Function will place try to place VRAM at same place as in CPU (PCI)
1148 * address space as some GPU seems to have issue when we reprogram at
1149 * different address space.
1150 *
1151 * If there is not enough space to fit the unvisible VRAM after the
1152 * aperture then we limit the VRAM size to the aperture.
1153 *
1154 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1155 * them to be in one from GPU point of view so that we can program GPU to
1156 * catch access outside them (weird GPU policy see ??).
1157 *
1158 * This function will never fails, worst case are limiting VRAM or GTT.
1159 *
1160 * Note: GTT start, end, size should be initialized before calling this
1161 * function on AGP platform.
1162 */
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001163static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
Jerome Glissed594e462010-02-17 21:54:29 +00001164{
1165 u64 size_bf, size_af;
1166
1167 if (mc->mc_vram_size > 0xE0000000) {
1168 /* leave room for at least 512M GTT */
1169 dev_warn(rdev->dev, "limiting VRAM\n");
1170 mc->real_vram_size = 0xE0000000;
1171 mc->mc_vram_size = 0xE0000000;
1172 }
1173 if (rdev->flags & RADEON_IS_AGP) {
1174 size_bf = mc->gtt_start;
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04001175 size_af = mc->mc_mask - mc->gtt_end;
Jerome Glissed594e462010-02-17 21:54:29 +00001176 if (size_bf > size_af) {
1177 if (mc->mc_vram_size > size_bf) {
1178 dev_warn(rdev->dev, "limiting VRAM\n");
1179 mc->real_vram_size = size_bf;
1180 mc->mc_vram_size = size_bf;
1181 }
1182 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1183 } else {
1184 if (mc->mc_vram_size > size_af) {
1185 dev_warn(rdev->dev, "limiting VRAM\n");
1186 mc->real_vram_size = size_af;
1187 mc->mc_vram_size = size_af;
1188 }
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001189 mc->vram_start = mc->gtt_end + 1;
Jerome Glissed594e462010-02-17 21:54:29 +00001190 }
1191 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1192 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1193 mc->mc_vram_size >> 20, mc->vram_start,
1194 mc->vram_end, mc->real_vram_size >> 20);
1195 } else {
1196 u64 base = 0;
Alex Deucher8961d522010-12-03 14:37:22 -05001197 if (rdev->flags & RADEON_IS_IGP) {
1198 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1199 base <<= 24;
1200 }
Jerome Glissed594e462010-02-17 21:54:29 +00001201 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001202 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001203 radeon_gtt_location(rdev, mc);
1204 }
1205}
1206
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001207static int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001208{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001209 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001210 int chansize, numchan;
Samuel Li65337e62013-04-05 17:50:53 -04001211 uint32_t h_addr, l_addr;
1212 unsigned long long k8_addr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001213
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001214 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001215 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001216 tmp = RREG32(RAMCFG);
1217 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001218 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001219 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001220 chansize = 64;
1221 } else {
1222 chansize = 32;
1223 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001224 tmp = RREG32(CHMAP);
1225 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1226 case 0:
1227 default:
1228 numchan = 1;
1229 break;
1230 case 1:
1231 numchan = 2;
1232 break;
1233 case 2:
1234 numchan = 4;
1235 break;
1236 case 3:
1237 numchan = 8;
1238 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001239 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001240 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001241 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001242 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1243 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001244 /* Setup GPU memory space */
1245 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1246 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001247 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001248 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001249
Alex Deucherf8920342010-06-30 12:02:03 -04001250 if (rdev->flags & RADEON_IS_IGP) {
1251 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001252 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Samuel Li65337e62013-04-05 17:50:53 -04001253
1254 if (rdev->family == CHIP_RS780 || rdev->family == CHIP_RS880) {
1255 /* Use K8 direct mapping for fast fb access. */
1256 rdev->fastfb_working = false;
1257 h_addr = G_000012_K8_ADDR_EXT(RREG32_MC(R_000012_MC_MISC_UMA_CNTL));
1258 l_addr = RREG32_MC(R_000011_K8_FB_LOCATION);
1259 k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
1260#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
1261 if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
1262#endif
1263 {
1264 /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
1265 * memory is present.
1266 */
1267 if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
1268 DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
1269 (unsigned long long)rdev->mc.aper_base, k8_addr);
1270 rdev->mc.aper_base = (resource_size_t)k8_addr;
1271 rdev->fastfb_working = true;
1272 }
1273 }
1274 }
Alex Deucherf8920342010-06-30 12:02:03 -04001275 }
Samuel Li65337e62013-04-05 17:50:53 -04001276
Alex Deucherf47299c2010-03-16 20:54:38 -04001277 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001278 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001279}
1280
Alex Deucher16cdf042011-10-28 10:30:02 -04001281int r600_vram_scratch_init(struct radeon_device *rdev)
1282{
1283 int r;
1284
1285 if (rdev->vram_scratch.robj == NULL) {
1286 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1287 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Alex Deucher40f5cf92012-05-10 18:33:13 -04001288 NULL, &rdev->vram_scratch.robj);
Alex Deucher16cdf042011-10-28 10:30:02 -04001289 if (r) {
1290 return r;
1291 }
1292 }
1293
1294 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1295 if (unlikely(r != 0))
1296 return r;
1297 r = radeon_bo_pin(rdev->vram_scratch.robj,
1298 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1299 if (r) {
1300 radeon_bo_unreserve(rdev->vram_scratch.robj);
1301 return r;
1302 }
1303 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1304 (void **)&rdev->vram_scratch.ptr);
1305 if (r)
1306 radeon_bo_unpin(rdev->vram_scratch.robj);
1307 radeon_bo_unreserve(rdev->vram_scratch.robj);
1308
1309 return r;
1310}
1311
1312void r600_vram_scratch_fini(struct radeon_device *rdev)
1313{
1314 int r;
1315
1316 if (rdev->vram_scratch.robj == NULL) {
1317 return;
1318 }
1319 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1320 if (likely(r == 0)) {
1321 radeon_bo_kunmap(rdev->vram_scratch.robj);
1322 radeon_bo_unpin(rdev->vram_scratch.robj);
1323 radeon_bo_unreserve(rdev->vram_scratch.robj);
1324 }
1325 radeon_bo_unref(&rdev->vram_scratch.robj);
1326}
1327
Alex Deucher410a3412013-01-18 13:05:39 -05001328void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung)
1329{
1330 u32 tmp = RREG32(R600_BIOS_3_SCRATCH);
1331
1332 if (hung)
1333 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1334 else
1335 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1336
1337 WREG32(R600_BIOS_3_SCRATCH, tmp);
1338}
1339
Alex Deucherd3cb7812013-01-18 13:53:37 -05001340static void r600_print_gpu_status_regs(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001341{
Jerome Glisse64c56e82013-01-02 17:30:35 -05001342 dev_info(rdev->dev, " R_008010_GRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001343 RREG32(R_008010_GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001344 dev_info(rdev->dev, " R_008014_GRBM_STATUS2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001345 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001346 dev_info(rdev->dev, " R_000E50_SRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001347 RREG32(R_000E50_SRBM_STATUS));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001348 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001349 RREG32(CP_STALLED_STAT1));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001350 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001351 RREG32(CP_STALLED_STAT2));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001352 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001353 RREG32(CP_BUSY_STAT));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001354 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001355 RREG32(CP_STAT));
Alex Deucher71e3d152013-01-03 12:20:35 -05001356 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1357 RREG32(DMA_STATUS_REG));
1358}
1359
Alex Deucherf13f7732013-01-18 18:12:22 -05001360static bool r600_is_display_hung(struct radeon_device *rdev)
1361{
1362 u32 crtc_hung = 0;
1363 u32 crtc_status[2];
1364 u32 i, j, tmp;
1365
1366 for (i = 0; i < rdev->num_crtc; i++) {
1367 if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[i]) & AVIVO_CRTC_EN) {
1368 crtc_status[i] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1369 crtc_hung |= (1 << i);
1370 }
1371 }
1372
1373 for (j = 0; j < 10; j++) {
1374 for (i = 0; i < rdev->num_crtc; i++) {
1375 if (crtc_hung & (1 << i)) {
1376 tmp = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1377 if (tmp != crtc_status[i])
1378 crtc_hung &= ~(1 << i);
1379 }
1380 }
1381 if (crtc_hung == 0)
1382 return false;
1383 udelay(100);
1384 }
1385
1386 return true;
1387}
1388
Christian König2483b4e2013-08-13 11:56:54 +02001389u32 r600_gpu_check_soft_reset(struct radeon_device *rdev)
Alex Deucherf13f7732013-01-18 18:12:22 -05001390{
1391 u32 reset_mask = 0;
1392 u32 tmp;
1393
1394 /* GRBM_STATUS */
1395 tmp = RREG32(R_008010_GRBM_STATUS);
1396 if (rdev->family >= CHIP_RV770) {
1397 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1398 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1399 G_008010_TA_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1400 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1401 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1402 reset_mask |= RADEON_RESET_GFX;
1403 } else {
1404 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1405 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1406 G_008010_TA03_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1407 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1408 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1409 reset_mask |= RADEON_RESET_GFX;
1410 }
1411
1412 if (G_008010_CF_RQ_PENDING(tmp) | G_008010_PF_RQ_PENDING(tmp) |
1413 G_008010_CP_BUSY(tmp) | G_008010_CP_COHERENCY_BUSY(tmp))
1414 reset_mask |= RADEON_RESET_CP;
1415
1416 if (G_008010_GRBM_EE_BUSY(tmp))
1417 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
1418
1419 /* DMA_STATUS_REG */
1420 tmp = RREG32(DMA_STATUS_REG);
1421 if (!(tmp & DMA_IDLE))
1422 reset_mask |= RADEON_RESET_DMA;
1423
1424 /* SRBM_STATUS */
1425 tmp = RREG32(R_000E50_SRBM_STATUS);
1426 if (G_000E50_RLC_RQ_PENDING(tmp) | G_000E50_RLC_BUSY(tmp))
1427 reset_mask |= RADEON_RESET_RLC;
1428
1429 if (G_000E50_IH_BUSY(tmp))
1430 reset_mask |= RADEON_RESET_IH;
1431
1432 if (G_000E50_SEM_BUSY(tmp))
1433 reset_mask |= RADEON_RESET_SEM;
1434
1435 if (G_000E50_GRBM_RQ_PENDING(tmp))
1436 reset_mask |= RADEON_RESET_GRBM;
1437
1438 if (G_000E50_VMC_BUSY(tmp))
1439 reset_mask |= RADEON_RESET_VMC;
1440
1441 if (G_000E50_MCB_BUSY(tmp) | G_000E50_MCDZ_BUSY(tmp) |
1442 G_000E50_MCDY_BUSY(tmp) | G_000E50_MCDX_BUSY(tmp) |
1443 G_000E50_MCDW_BUSY(tmp))
1444 reset_mask |= RADEON_RESET_MC;
1445
1446 if (r600_is_display_hung(rdev))
1447 reset_mask |= RADEON_RESET_DISPLAY;
1448
Alex Deucherd808fc82013-02-28 10:03:08 -05001449 /* Skip MC reset as it's mostly likely not hung, just busy */
1450 if (reset_mask & RADEON_RESET_MC) {
1451 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
1452 reset_mask &= ~RADEON_RESET_MC;
1453 }
1454
Alex Deucherf13f7732013-01-18 18:12:22 -05001455 return reset_mask;
1456}
1457
1458static void r600_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher71e3d152013-01-03 12:20:35 -05001459{
1460 struct rv515_mc_save save;
Alex Deucherd3cb7812013-01-18 13:53:37 -05001461 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
1462 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05001463
Alex Deucher71e3d152013-01-03 12:20:35 -05001464 if (reset_mask == 0)
Alex Deucherf13f7732013-01-18 18:12:22 -05001465 return;
Alex Deucher71e3d152013-01-03 12:20:35 -05001466
1467 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
1468
Alex Deucherd3cb7812013-01-18 13:53:37 -05001469 r600_print_gpu_status_regs(rdev);
1470
Alex Deucherd3cb7812013-01-18 13:53:37 -05001471 /* Disable CP parsing/prefetching */
1472 if (rdev->family >= CHIP_RV770)
1473 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
1474 else
1475 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher71e3d152013-01-03 12:20:35 -05001476
Alex Deucherd3cb7812013-01-18 13:53:37 -05001477 /* disable the RLC */
1478 WREG32(RLC_CNTL, 0);
1479
1480 if (reset_mask & RADEON_RESET_DMA) {
1481 /* Disable DMA */
1482 tmp = RREG32(DMA_RB_CNTL);
1483 tmp &= ~DMA_RB_ENABLE;
1484 WREG32(DMA_RB_CNTL, tmp);
1485 }
1486
1487 mdelay(50);
1488
Alex Deucherca578022013-01-23 18:56:08 -05001489 rv515_mc_stop(rdev, &save);
1490 if (r600_mc_wait_for_idle(rdev)) {
1491 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1492 }
1493
Alex Deucherd3cb7812013-01-18 13:53:37 -05001494 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
1495 if (rdev->family >= CHIP_RV770)
1496 grbm_soft_reset |= S_008020_SOFT_RESET_DB(1) |
1497 S_008020_SOFT_RESET_CB(1) |
1498 S_008020_SOFT_RESET_PA(1) |
1499 S_008020_SOFT_RESET_SC(1) |
1500 S_008020_SOFT_RESET_SPI(1) |
1501 S_008020_SOFT_RESET_SX(1) |
1502 S_008020_SOFT_RESET_SH(1) |
1503 S_008020_SOFT_RESET_TC(1) |
1504 S_008020_SOFT_RESET_TA(1) |
1505 S_008020_SOFT_RESET_VC(1) |
1506 S_008020_SOFT_RESET_VGT(1);
1507 else
1508 grbm_soft_reset |= S_008020_SOFT_RESET_CR(1) |
1509 S_008020_SOFT_RESET_DB(1) |
1510 S_008020_SOFT_RESET_CB(1) |
1511 S_008020_SOFT_RESET_PA(1) |
1512 S_008020_SOFT_RESET_SC(1) |
1513 S_008020_SOFT_RESET_SMX(1) |
1514 S_008020_SOFT_RESET_SPI(1) |
1515 S_008020_SOFT_RESET_SX(1) |
1516 S_008020_SOFT_RESET_SH(1) |
1517 S_008020_SOFT_RESET_TC(1) |
1518 S_008020_SOFT_RESET_TA(1) |
1519 S_008020_SOFT_RESET_VC(1) |
1520 S_008020_SOFT_RESET_VGT(1);
1521 }
1522
1523 if (reset_mask & RADEON_RESET_CP) {
1524 grbm_soft_reset |= S_008020_SOFT_RESET_CP(1) |
1525 S_008020_SOFT_RESET_VGT(1);
1526
1527 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1528 }
1529
1530 if (reset_mask & RADEON_RESET_DMA) {
1531 if (rdev->family >= CHIP_RV770)
1532 srbm_soft_reset |= RV770_SOFT_RESET_DMA;
1533 else
1534 srbm_soft_reset |= SOFT_RESET_DMA;
1535 }
1536
Alex Deucherf13f7732013-01-18 18:12:22 -05001537 if (reset_mask & RADEON_RESET_RLC)
1538 srbm_soft_reset |= S_000E60_SOFT_RESET_RLC(1);
1539
1540 if (reset_mask & RADEON_RESET_SEM)
1541 srbm_soft_reset |= S_000E60_SOFT_RESET_SEM(1);
1542
1543 if (reset_mask & RADEON_RESET_IH)
1544 srbm_soft_reset |= S_000E60_SOFT_RESET_IH(1);
1545
1546 if (reset_mask & RADEON_RESET_GRBM)
1547 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1548
Alex Deucher24178ec2013-01-24 15:00:17 -05001549 if (!(rdev->flags & RADEON_IS_IGP)) {
1550 if (reset_mask & RADEON_RESET_MC)
1551 srbm_soft_reset |= S_000E60_SOFT_RESET_MC(1);
1552 }
Alex Deucherf13f7732013-01-18 18:12:22 -05001553
1554 if (reset_mask & RADEON_RESET_VMC)
1555 srbm_soft_reset |= S_000E60_SOFT_RESET_VMC(1);
1556
Alex Deucherd3cb7812013-01-18 13:53:37 -05001557 if (grbm_soft_reset) {
1558 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1559 tmp |= grbm_soft_reset;
1560 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1561 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1562 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1563
1564 udelay(50);
1565
1566 tmp &= ~grbm_soft_reset;
1567 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1568 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1569 }
1570
1571 if (srbm_soft_reset) {
1572 tmp = RREG32(SRBM_SOFT_RESET);
1573 tmp |= srbm_soft_reset;
1574 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1575 WREG32(SRBM_SOFT_RESET, tmp);
1576 tmp = RREG32(SRBM_SOFT_RESET);
1577
1578 udelay(50);
1579
1580 tmp &= ~srbm_soft_reset;
1581 WREG32(SRBM_SOFT_RESET, tmp);
1582 tmp = RREG32(SRBM_SOFT_RESET);
1583 }
Alex Deucher71e3d152013-01-03 12:20:35 -05001584
1585 /* Wait a little for things to settle down */
1586 mdelay(1);
1587
Jerome Glissea3c19452009-10-01 18:02:13 +02001588 rv515_mc_resume(rdev, &save);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001589 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05001590
Alex Deucherd3cb7812013-01-18 13:53:37 -05001591 r600_print_gpu_status_regs(rdev);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001592}
1593
1594int r600_asic_reset(struct radeon_device *rdev)
1595{
Alex Deucherf13f7732013-01-18 18:12:22 -05001596 u32 reset_mask;
1597
1598 reset_mask = r600_gpu_check_soft_reset(rdev);
1599
1600 if (reset_mask)
1601 r600_set_bios_scratch_engine_hung(rdev, true);
1602
1603 r600_gpu_soft_reset(rdev, reset_mask);
1604
1605 reset_mask = r600_gpu_check_soft_reset(rdev);
1606
1607 if (!reset_mask)
1608 r600_set_bios_scratch_engine_hung(rdev, false);
1609
1610 return 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001611}
1612
Alex Deucher123bc182013-01-24 11:37:19 -05001613/**
1614 * r600_gfx_is_lockup - Check if the GFX engine is locked up
1615 *
1616 * @rdev: radeon_device pointer
1617 * @ring: radeon_ring structure holding ring information
1618 *
1619 * Check if the GFX engine is locked up.
1620 * Returns true if the engine appears to be locked up, false if not.
1621 */
1622bool r600_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse225758d2010-03-09 14:45:10 +00001623{
Alex Deucher123bc182013-01-24 11:37:19 -05001624 u32 reset_mask = r600_gpu_check_soft_reset(rdev);
Jerome Glisse225758d2010-03-09 14:45:10 +00001625
Alex Deucher123bc182013-01-24 11:37:19 -05001626 if (!(reset_mask & (RADEON_RESET_GFX |
1627 RADEON_RESET_COMPUTE |
1628 RADEON_RESET_CP))) {
Christian König069211e2012-05-02 15:11:20 +02001629 radeon_ring_lockup_update(ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001630 return false;
1631 }
1632 /* force CP activities */
Christian König7b9ef162012-05-02 15:11:23 +02001633 radeon_ring_force_activity(rdev, ring);
Christian König069211e2012-05-02 15:11:20 +02001634 return radeon_ring_test_lockup(rdev, ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001635}
1636
Alex Deucher416a2bd2012-05-31 19:00:25 -04001637u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1638 u32 tiling_pipe_num,
1639 u32 max_rb_num,
1640 u32 total_max_rb_num,
1641 u32 disabled_rb_mask)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001642{
Alex Deucher416a2bd2012-05-31 19:00:25 -04001643 u32 rendering_pipe_num, rb_num_width, req_rb_num;
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001644 u32 pipe_rb_ratio, pipe_rb_remain, tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001645 u32 data = 0, mask = 1 << (max_rb_num - 1);
1646 unsigned i, j;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001647
Alex Deucher416a2bd2012-05-31 19:00:25 -04001648 /* mask out the RBs that don't exist on that asic */
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001649 tmp = disabled_rb_mask | ((0xff << max_rb_num) & 0xff);
1650 /* make sure at least one RB is available */
1651 if ((tmp & 0xff) != 0xff)
1652 disabled_rb_mask = tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001653
Alex Deucher416a2bd2012-05-31 19:00:25 -04001654 rendering_pipe_num = 1 << tiling_pipe_num;
1655 req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
1656 BUG_ON(rendering_pipe_num < req_rb_num);
1657
1658 pipe_rb_ratio = rendering_pipe_num / req_rb_num;
1659 pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
1660
1661 if (rdev->family <= CHIP_RV740) {
1662 /* r6xx/r7xx */
1663 rb_num_width = 2;
1664 } else {
1665 /* eg+ */
1666 rb_num_width = 4;
1667 }
1668
1669 for (i = 0; i < max_rb_num; i++) {
1670 if (!(mask & disabled_rb_mask)) {
1671 for (j = 0; j < pipe_rb_ratio; j++) {
1672 data <<= rb_num_width;
1673 data |= max_rb_num - i - 1;
1674 }
1675 if (pipe_rb_remain) {
1676 data <<= rb_num_width;
1677 data |= max_rb_num - i - 1;
1678 pipe_rb_remain--;
1679 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001680 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04001681 mask >>= 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001682 }
1683
Alex Deucher416a2bd2012-05-31 19:00:25 -04001684 return data;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001685}
1686
1687int r600_count_pipe_bits(uint32_t val)
1688{
Akinobu Mitaef8cf3a2012-11-09 12:10:41 +00001689 return hweight32(val);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001690}
1691
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001692static void r600_gpu_init(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001693{
1694 u32 tiling_config;
1695 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001696 u32 cc_rb_backend_disable;
1697 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001698 u32 tmp;
1699 int i, j;
1700 u32 sq_config;
1701 u32 sq_gpr_resource_mgmt_1 = 0;
1702 u32 sq_gpr_resource_mgmt_2 = 0;
1703 u32 sq_thread_resource_mgmt = 0;
1704 u32 sq_stack_resource_mgmt_1 = 0;
1705 u32 sq_stack_resource_mgmt_2 = 0;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001706 u32 disabled_rb_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001707
Alex Deucher416a2bd2012-05-31 19:00:25 -04001708 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001709 switch (rdev->family) {
1710 case CHIP_R600:
1711 rdev->config.r600.max_pipes = 4;
1712 rdev->config.r600.max_tile_pipes = 8;
1713 rdev->config.r600.max_simds = 4;
1714 rdev->config.r600.max_backends = 4;
1715 rdev->config.r600.max_gprs = 256;
1716 rdev->config.r600.max_threads = 192;
1717 rdev->config.r600.max_stack_entries = 256;
1718 rdev->config.r600.max_hw_contexts = 8;
1719 rdev->config.r600.max_gs_threads = 16;
1720 rdev->config.r600.sx_max_export_size = 128;
1721 rdev->config.r600.sx_max_export_pos_size = 16;
1722 rdev->config.r600.sx_max_export_smx_size = 128;
1723 rdev->config.r600.sq_num_cf_insts = 2;
1724 break;
1725 case CHIP_RV630:
1726 case CHIP_RV635:
1727 rdev->config.r600.max_pipes = 2;
1728 rdev->config.r600.max_tile_pipes = 2;
1729 rdev->config.r600.max_simds = 3;
1730 rdev->config.r600.max_backends = 1;
1731 rdev->config.r600.max_gprs = 128;
1732 rdev->config.r600.max_threads = 192;
1733 rdev->config.r600.max_stack_entries = 128;
1734 rdev->config.r600.max_hw_contexts = 8;
1735 rdev->config.r600.max_gs_threads = 4;
1736 rdev->config.r600.sx_max_export_size = 128;
1737 rdev->config.r600.sx_max_export_pos_size = 16;
1738 rdev->config.r600.sx_max_export_smx_size = 128;
1739 rdev->config.r600.sq_num_cf_insts = 2;
1740 break;
1741 case CHIP_RV610:
1742 case CHIP_RV620:
1743 case CHIP_RS780:
1744 case CHIP_RS880:
1745 rdev->config.r600.max_pipes = 1;
1746 rdev->config.r600.max_tile_pipes = 1;
1747 rdev->config.r600.max_simds = 2;
1748 rdev->config.r600.max_backends = 1;
1749 rdev->config.r600.max_gprs = 128;
1750 rdev->config.r600.max_threads = 192;
1751 rdev->config.r600.max_stack_entries = 128;
1752 rdev->config.r600.max_hw_contexts = 4;
1753 rdev->config.r600.max_gs_threads = 4;
1754 rdev->config.r600.sx_max_export_size = 128;
1755 rdev->config.r600.sx_max_export_pos_size = 16;
1756 rdev->config.r600.sx_max_export_smx_size = 128;
1757 rdev->config.r600.sq_num_cf_insts = 1;
1758 break;
1759 case CHIP_RV670:
1760 rdev->config.r600.max_pipes = 4;
1761 rdev->config.r600.max_tile_pipes = 4;
1762 rdev->config.r600.max_simds = 4;
1763 rdev->config.r600.max_backends = 4;
1764 rdev->config.r600.max_gprs = 192;
1765 rdev->config.r600.max_threads = 192;
1766 rdev->config.r600.max_stack_entries = 256;
1767 rdev->config.r600.max_hw_contexts = 8;
1768 rdev->config.r600.max_gs_threads = 16;
1769 rdev->config.r600.sx_max_export_size = 128;
1770 rdev->config.r600.sx_max_export_pos_size = 16;
1771 rdev->config.r600.sx_max_export_smx_size = 128;
1772 rdev->config.r600.sq_num_cf_insts = 2;
1773 break;
1774 default:
1775 break;
1776 }
1777
1778 /* Initialize HDP */
1779 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1780 WREG32((0x2c14 + j), 0x00000000);
1781 WREG32((0x2c18 + j), 0x00000000);
1782 WREG32((0x2c1c + j), 0x00000000);
1783 WREG32((0x2c20 + j), 0x00000000);
1784 WREG32((0x2c24 + j), 0x00000000);
1785 }
1786
1787 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1788
1789 /* Setup tiling */
1790 tiling_config = 0;
1791 ramcfg = RREG32(RAMCFG);
1792 switch (rdev->config.r600.max_tile_pipes) {
1793 case 1:
1794 tiling_config |= PIPE_TILING(0);
1795 break;
1796 case 2:
1797 tiling_config |= PIPE_TILING(1);
1798 break;
1799 case 4:
1800 tiling_config |= PIPE_TILING(2);
1801 break;
1802 case 8:
1803 tiling_config |= PIPE_TILING(3);
1804 break;
1805 default:
1806 break;
1807 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001808 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001809 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001810 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04001811 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
Alex Deucher416a2bd2012-05-31 19:00:25 -04001812
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001813 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1814 if (tmp > 3) {
1815 tiling_config |= ROW_TILING(3);
1816 tiling_config |= SAMPLE_SPLIT(3);
1817 } else {
1818 tiling_config |= ROW_TILING(tmp);
1819 tiling_config |= SAMPLE_SPLIT(tmp);
1820 }
1821 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001822
1823 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001824 tmp = R6XX_MAX_BACKENDS -
1825 r600_count_pipe_bits((cc_rb_backend_disable >> 16) & R6XX_MAX_BACKENDS_MASK);
1826 if (tmp < rdev->config.r600.max_backends) {
1827 rdev->config.r600.max_backends = tmp;
1828 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001829
Alex Deucher416a2bd2012-05-31 19:00:25 -04001830 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
1831 tmp = R6XX_MAX_PIPES -
1832 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R6XX_MAX_PIPES_MASK);
1833 if (tmp < rdev->config.r600.max_pipes) {
1834 rdev->config.r600.max_pipes = tmp;
1835 }
1836 tmp = R6XX_MAX_SIMDS -
1837 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
1838 if (tmp < rdev->config.r600.max_simds) {
1839 rdev->config.r600.max_simds = tmp;
1840 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001841
Alex Deucher416a2bd2012-05-31 19:00:25 -04001842 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
1843 tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
1844 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
1845 R6XX_MAX_BACKENDS, disabled_rb_mask);
1846 tiling_config |= tmp << 16;
1847 rdev->config.r600.backend_map = tmp;
1848
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001849 rdev->config.r600.tile_config = tiling_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001850 WREG32(GB_TILING_CONFIG, tiling_config);
1851 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1852 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
Alex Deucher4d756582012-09-27 15:08:35 -04001853 WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001854
Alex Deucherd03f5d52010-02-19 16:22:31 -05001855 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 +10001856 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1857 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1858
1859 /* Setup some CP states */
1860 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1861 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1862
1863 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1864 SYNC_WALKER | SYNC_ALIGNER));
1865 /* Setup various GPU states */
1866 if (rdev->family == CHIP_RV670)
1867 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1868
1869 tmp = RREG32(SX_DEBUG_1);
1870 tmp |= SMX_EVENT_RELEASE;
1871 if ((rdev->family > CHIP_R600))
1872 tmp |= ENABLE_NEW_SMX_ADDRESS;
1873 WREG32(SX_DEBUG_1, tmp);
1874
1875 if (((rdev->family) == CHIP_R600) ||
1876 ((rdev->family) == CHIP_RV630) ||
1877 ((rdev->family) == CHIP_RV610) ||
1878 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001879 ((rdev->family) == CHIP_RS780) ||
1880 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001881 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1882 } else {
1883 WREG32(DB_DEBUG, 0);
1884 }
1885 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1886 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1887
1888 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1889 WREG32(VGT_NUM_INSTANCES, 0);
1890
1891 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1892 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1893
1894 tmp = RREG32(SQ_MS_FIFO_SIZES);
1895 if (((rdev->family) == CHIP_RV610) ||
1896 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001897 ((rdev->family) == CHIP_RS780) ||
1898 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001899 tmp = (CACHE_FIFO_SIZE(0xa) |
1900 FETCH_FIFO_HIWATER(0xa) |
1901 DONE_FIFO_HIWATER(0xe0) |
1902 ALU_UPDATE_FIFO_HIWATER(0x8));
1903 } else if (((rdev->family) == CHIP_R600) ||
1904 ((rdev->family) == CHIP_RV630)) {
1905 tmp &= ~DONE_FIFO_HIWATER(0xff);
1906 tmp |= DONE_FIFO_HIWATER(0x4);
1907 }
1908 WREG32(SQ_MS_FIFO_SIZES, tmp);
1909
1910 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1911 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1912 */
1913 sq_config = RREG32(SQ_CONFIG);
1914 sq_config &= ~(PS_PRIO(3) |
1915 VS_PRIO(3) |
1916 GS_PRIO(3) |
1917 ES_PRIO(3));
1918 sq_config |= (DX9_CONSTS |
1919 VC_ENABLE |
1920 PS_PRIO(0) |
1921 VS_PRIO(1) |
1922 GS_PRIO(2) |
1923 ES_PRIO(3));
1924
1925 if ((rdev->family) == CHIP_R600) {
1926 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1927 NUM_VS_GPRS(124) |
1928 NUM_CLAUSE_TEMP_GPRS(4));
1929 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1930 NUM_ES_GPRS(0));
1931 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1932 NUM_VS_THREADS(48) |
1933 NUM_GS_THREADS(4) |
1934 NUM_ES_THREADS(4));
1935 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1936 NUM_VS_STACK_ENTRIES(128));
1937 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1938 NUM_ES_STACK_ENTRIES(0));
1939 } else if (((rdev->family) == CHIP_RV610) ||
1940 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001941 ((rdev->family) == CHIP_RS780) ||
1942 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001943 /* no vertex cache */
1944 sq_config &= ~VC_ENABLE;
1945
1946 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1947 NUM_VS_GPRS(44) |
1948 NUM_CLAUSE_TEMP_GPRS(2));
1949 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1950 NUM_ES_GPRS(17));
1951 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1952 NUM_VS_THREADS(78) |
1953 NUM_GS_THREADS(4) |
1954 NUM_ES_THREADS(31));
1955 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1956 NUM_VS_STACK_ENTRIES(40));
1957 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1958 NUM_ES_STACK_ENTRIES(16));
1959 } else if (((rdev->family) == CHIP_RV630) ||
1960 ((rdev->family) == CHIP_RV635)) {
1961 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1962 NUM_VS_GPRS(44) |
1963 NUM_CLAUSE_TEMP_GPRS(2));
1964 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1965 NUM_ES_GPRS(18));
1966 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1967 NUM_VS_THREADS(78) |
1968 NUM_GS_THREADS(4) |
1969 NUM_ES_THREADS(31));
1970 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1971 NUM_VS_STACK_ENTRIES(40));
1972 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1973 NUM_ES_STACK_ENTRIES(16));
1974 } else if ((rdev->family) == CHIP_RV670) {
1975 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1976 NUM_VS_GPRS(44) |
1977 NUM_CLAUSE_TEMP_GPRS(2));
1978 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1979 NUM_ES_GPRS(17));
1980 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1981 NUM_VS_THREADS(78) |
1982 NUM_GS_THREADS(4) |
1983 NUM_ES_THREADS(31));
1984 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1985 NUM_VS_STACK_ENTRIES(64));
1986 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1987 NUM_ES_STACK_ENTRIES(64));
1988 }
1989
1990 WREG32(SQ_CONFIG, sq_config);
1991 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1992 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1993 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1994 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1995 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1996
1997 if (((rdev->family) == CHIP_RV610) ||
1998 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001999 ((rdev->family) == CHIP_RS780) ||
2000 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002001 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
2002 } else {
2003 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
2004 }
2005
2006 /* More default values. 2D/3D driver should adjust as needed */
2007 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
2008 S1_X(0x4) | S1_Y(0xc)));
2009 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
2010 S1_X(0x2) | S1_Y(0x2) |
2011 S2_X(0xa) | S2_Y(0x6) |
2012 S3_X(0x6) | S3_Y(0xa)));
2013 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
2014 S1_X(0x4) | S1_Y(0xc) |
2015 S2_X(0x1) | S2_Y(0x6) |
2016 S3_X(0xa) | S3_Y(0xe)));
2017 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
2018 S5_X(0x0) | S5_Y(0x0) |
2019 S6_X(0xb) | S6_Y(0x4) |
2020 S7_X(0x7) | S7_Y(0x8)));
2021
2022 WREG32(VGT_STRMOUT_EN, 0);
2023 tmp = rdev->config.r600.max_pipes * 16;
2024 switch (rdev->family) {
2025 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002026 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05002027 case CHIP_RS780:
2028 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002029 tmp += 32;
2030 break;
2031 case CHIP_RV670:
2032 tmp += 128;
2033 break;
2034 default:
2035 break;
2036 }
2037 if (tmp > 256) {
2038 tmp = 256;
2039 }
2040 WREG32(VGT_ES_PER_GS, 128);
2041 WREG32(VGT_GS_PER_ES, tmp);
2042 WREG32(VGT_GS_PER_VS, 2);
2043 WREG32(VGT_GS_VERTEX_REUSE, 16);
2044
2045 /* more default values. 2D/3D driver should adjust as needed */
2046 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
2047 WREG32(VGT_STRMOUT_EN, 0);
2048 WREG32(SX_MISC, 0);
2049 WREG32(PA_SC_MODE_CNTL, 0);
2050 WREG32(PA_SC_AA_CONFIG, 0);
2051 WREG32(PA_SC_LINE_STIPPLE, 0);
2052 WREG32(SPI_INPUT_Z, 0);
2053 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
2054 WREG32(CB_COLOR7_FRAG, 0);
2055
2056 /* Clear render buffer base addresses */
2057 WREG32(CB_COLOR0_BASE, 0);
2058 WREG32(CB_COLOR1_BASE, 0);
2059 WREG32(CB_COLOR2_BASE, 0);
2060 WREG32(CB_COLOR3_BASE, 0);
2061 WREG32(CB_COLOR4_BASE, 0);
2062 WREG32(CB_COLOR5_BASE, 0);
2063 WREG32(CB_COLOR6_BASE, 0);
2064 WREG32(CB_COLOR7_BASE, 0);
2065 WREG32(CB_COLOR7_FRAG, 0);
2066
2067 switch (rdev->family) {
2068 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002069 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05002070 case CHIP_RS780:
2071 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002072 tmp = TC_L2_SIZE(8);
2073 break;
2074 case CHIP_RV630:
2075 case CHIP_RV635:
2076 tmp = TC_L2_SIZE(4);
2077 break;
2078 case CHIP_R600:
2079 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
2080 break;
2081 default:
2082 tmp = TC_L2_SIZE(0);
2083 break;
2084 }
2085 WREG32(TC_CNTL, tmp);
2086
2087 tmp = RREG32(HDP_HOST_PATH_CNTL);
2088 WREG32(HDP_HOST_PATH_CNTL, tmp);
2089
2090 tmp = RREG32(ARB_POP);
2091 tmp |= ENABLE_TC128;
2092 WREG32(ARB_POP, tmp);
2093
2094 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
2095 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
2096 NUM_CLIP_SEQ(3)));
2097 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
Alex Deucherb866d132012-06-14 22:06:36 +02002098 WREG32(VC_ENHANCE, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002099}
2100
2101
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002102/*
2103 * Indirect registers accessor
2104 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002105u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002106{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002107 unsigned long flags;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002108 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002109
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002110 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002111 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2112 (void)RREG32(PCIE_PORT_INDEX);
2113 r = RREG32(PCIE_PORT_DATA);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002114 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002115 return r;
2116}
2117
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002118void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002119{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002120 unsigned long flags;
2121
2122 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002123 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2124 (void)RREG32(PCIE_PORT_INDEX);
2125 WREG32(PCIE_PORT_DATA, (v));
2126 (void)RREG32(PCIE_PORT_DATA);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002127 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002128}
2129
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002130/*
2131 * CP & Ring
2132 */
2133void r600_cp_stop(struct radeon_device *rdev)
2134{
Dave Airlie53595332011-03-14 09:47:24 +10002135 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002136 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04002137 WREG32(SCRATCH_UMSK, 0);
Alex Deucher4d756582012-09-27 15:08:35 -04002138 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002139}
2140
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002141int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002142{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002143 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002144 const char *rlc_chip_name;
Alex Deucher66229b22013-06-26 00:11:19 -04002145 const char *smc_chip_name = "RV770";
2146 size_t pfp_req_size, me_req_size, rlc_req_size, smc_req_size = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002147 char fw_name[30];
2148 int err;
2149
2150 DRM_DEBUG("\n");
2151
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002152 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002153 case CHIP_R600:
2154 chip_name = "R600";
2155 rlc_chip_name = "R600";
2156 break;
2157 case CHIP_RV610:
2158 chip_name = "RV610";
2159 rlc_chip_name = "R600";
2160 break;
2161 case CHIP_RV630:
2162 chip_name = "RV630";
2163 rlc_chip_name = "R600";
2164 break;
2165 case CHIP_RV620:
2166 chip_name = "RV620";
2167 rlc_chip_name = "R600";
2168 break;
2169 case CHIP_RV635:
2170 chip_name = "RV635";
2171 rlc_chip_name = "R600";
2172 break;
2173 case CHIP_RV670:
2174 chip_name = "RV670";
2175 rlc_chip_name = "R600";
2176 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002177 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002178 case CHIP_RS880:
2179 chip_name = "RS780";
2180 rlc_chip_name = "R600";
2181 break;
2182 case CHIP_RV770:
2183 chip_name = "RV770";
2184 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002185 smc_chip_name = "RV770";
2186 smc_req_size = ALIGN(RV770_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002187 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002188 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002189 chip_name = "RV730";
2190 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002191 smc_chip_name = "RV730";
2192 smc_req_size = ALIGN(RV730_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002193 break;
2194 case CHIP_RV710:
2195 chip_name = "RV710";
2196 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002197 smc_chip_name = "RV710";
2198 smc_req_size = ALIGN(RV710_SMC_UCODE_SIZE, 4);
2199 break;
2200 case CHIP_RV740:
2201 chip_name = "RV730";
2202 rlc_chip_name = "R700";
2203 smc_chip_name = "RV740";
2204 smc_req_size = ALIGN(RV740_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002205 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04002206 case CHIP_CEDAR:
2207 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04002208 rlc_chip_name = "CEDAR";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002209 smc_chip_name = "CEDAR";
2210 smc_req_size = ALIGN(CEDAR_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002211 break;
2212 case CHIP_REDWOOD:
2213 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04002214 rlc_chip_name = "REDWOOD";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002215 smc_chip_name = "REDWOOD";
2216 smc_req_size = ALIGN(REDWOOD_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002217 break;
2218 case CHIP_JUNIPER:
2219 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04002220 rlc_chip_name = "JUNIPER";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002221 smc_chip_name = "JUNIPER";
2222 smc_req_size = ALIGN(JUNIPER_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002223 break;
2224 case CHIP_CYPRESS:
2225 case CHIP_HEMLOCK:
2226 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04002227 rlc_chip_name = "CYPRESS";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002228 smc_chip_name = "CYPRESS";
2229 smc_req_size = ALIGN(CYPRESS_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002230 break;
Alex Deucher439bd6c2010-11-22 17:56:31 -05002231 case CHIP_PALM:
2232 chip_name = "PALM";
2233 rlc_chip_name = "SUMO";
2234 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002235 case CHIP_SUMO:
2236 chip_name = "SUMO";
2237 rlc_chip_name = "SUMO";
2238 break;
2239 case CHIP_SUMO2:
2240 chip_name = "SUMO2";
2241 rlc_chip_name = "SUMO";
2242 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002243 default: BUG();
2244 }
2245
Alex Deucherfe251e22010-03-24 13:36:43 -04002246 if (rdev->family >= CHIP_CEDAR) {
2247 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2248 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002249 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002250 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002251 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2252 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002253 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002254 } else {
Alex Deucher138e4e12013-01-11 15:33:13 -05002255 pfp_req_size = R600_PFP_UCODE_SIZE * 4;
2256 me_req_size = R600_PM4_UCODE_SIZE * 12;
2257 rlc_req_size = R600_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002258 }
2259
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002260 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002261
2262 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002263 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002264 if (err)
2265 goto out;
2266 if (rdev->pfp_fw->size != pfp_req_size) {
2267 printk(KERN_ERR
2268 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2269 rdev->pfp_fw->size, fw_name);
2270 err = -EINVAL;
2271 goto out;
2272 }
2273
2274 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002275 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002276 if (err)
2277 goto out;
2278 if (rdev->me_fw->size != me_req_size) {
2279 printk(KERN_ERR
2280 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2281 rdev->me_fw->size, fw_name);
2282 err = -EINVAL;
2283 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002284
2285 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002286 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002287 if (err)
2288 goto out;
2289 if (rdev->rlc_fw->size != rlc_req_size) {
2290 printk(KERN_ERR
2291 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2292 rdev->rlc_fw->size, fw_name);
2293 err = -EINVAL;
2294 }
2295
Alex Deucherdc50ba72013-06-26 00:33:35 -04002296 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_HEMLOCK)) {
Alex Deucher66229b22013-06-26 00:11:19 -04002297 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", smc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002298 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
Alex Deucher8a53fa22013-08-07 16:09:08 -04002299 if (err) {
2300 printk(KERN_ERR
2301 "smc: error loading firmware \"%s\"\n",
2302 fw_name);
2303 release_firmware(rdev->smc_fw);
2304 rdev->smc_fw = NULL;
2305 } else if (rdev->smc_fw->size != smc_req_size) {
Alex Deucher66229b22013-06-26 00:11:19 -04002306 printk(KERN_ERR
2307 "smc: Bogus length %zu in firmware \"%s\"\n",
2308 rdev->smc_fw->size, fw_name);
2309 err = -EINVAL;
2310 }
2311 }
2312
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002313out:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002314 if (err) {
2315 if (err != -EINVAL)
2316 printk(KERN_ERR
2317 "r600_cp: Failed to load firmware \"%s\"\n",
2318 fw_name);
2319 release_firmware(rdev->pfp_fw);
2320 rdev->pfp_fw = NULL;
2321 release_firmware(rdev->me_fw);
2322 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002323 release_firmware(rdev->rlc_fw);
2324 rdev->rlc_fw = NULL;
Alex Deucher66229b22013-06-26 00:11:19 -04002325 release_firmware(rdev->smc_fw);
2326 rdev->smc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002327 }
2328 return err;
2329}
2330
2331static int r600_cp_load_microcode(struct radeon_device *rdev)
2332{
2333 const __be32 *fw_data;
2334 int i;
2335
2336 if (!rdev->me_fw || !rdev->pfp_fw)
2337 return -EINVAL;
2338
2339 r600_cp_stop(rdev);
2340
Cédric Cano4eace7f2011-02-11 19:45:38 -05002341 WREG32(CP_RB_CNTL,
2342#ifdef __BIG_ENDIAN
2343 BUF_SWAP_32BIT |
2344#endif
2345 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002346
2347 /* Reset cp */
2348 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2349 RREG32(GRBM_SOFT_RESET);
2350 mdelay(15);
2351 WREG32(GRBM_SOFT_RESET, 0);
2352
2353 WREG32(CP_ME_RAM_WADDR, 0);
2354
2355 fw_data = (const __be32 *)rdev->me_fw->data;
2356 WREG32(CP_ME_RAM_WADDR, 0);
Alex Deucher138e4e12013-01-11 15:33:13 -05002357 for (i = 0; i < R600_PM4_UCODE_SIZE * 3; i++)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002358 WREG32(CP_ME_RAM_DATA,
2359 be32_to_cpup(fw_data++));
2360
2361 fw_data = (const __be32 *)rdev->pfp_fw->data;
2362 WREG32(CP_PFP_UCODE_ADDR, 0);
Alex Deucher138e4e12013-01-11 15:33:13 -05002363 for (i = 0; i < R600_PFP_UCODE_SIZE; i++)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002364 WREG32(CP_PFP_UCODE_DATA,
2365 be32_to_cpup(fw_data++));
2366
2367 WREG32(CP_PFP_UCODE_ADDR, 0);
2368 WREG32(CP_ME_RAM_WADDR, 0);
2369 WREG32(CP_ME_RAM_RADDR, 0);
2370 return 0;
2371}
2372
2373int r600_cp_start(struct radeon_device *rdev)
2374{
Christian Könige32eb502011-10-23 12:56:27 +02002375 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002376 int r;
2377 uint32_t cp_me;
2378
Christian Könige32eb502011-10-23 12:56:27 +02002379 r = radeon_ring_lock(rdev, ring, 7);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002380 if (r) {
2381 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2382 return r;
2383 }
Christian Könige32eb502011-10-23 12:56:27 +02002384 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2385 radeon_ring_write(ring, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002386 if (rdev->family >= CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +02002387 radeon_ring_write(ring, 0x0);
2388 radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002389 } else {
Christian Könige32eb502011-10-23 12:56:27 +02002390 radeon_ring_write(ring, 0x3);
2391 radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002392 }
Christian Könige32eb502011-10-23 12:56:27 +02002393 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2394 radeon_ring_write(ring, 0);
2395 radeon_ring_write(ring, 0);
2396 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002397
2398 cp_me = 0xff;
2399 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2400 return 0;
2401}
2402
2403int r600_cp_resume(struct radeon_device *rdev)
2404{
Christian Könige32eb502011-10-23 12:56:27 +02002405 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002406 u32 tmp;
2407 u32 rb_bufsz;
2408 int r;
2409
2410 /* Reset cp */
2411 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2412 RREG32(GRBM_SOFT_RESET);
2413 mdelay(15);
2414 WREG32(GRBM_SOFT_RESET, 0);
2415
2416 /* Set ring buffer size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02002417 rb_bufsz = order_base_2(ring->ring_size / 8);
2418 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002419#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002420 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002421#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002422 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02002423 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002424
2425 /* Set the write pointer delay */
2426 WREG32(CP_RB_WPTR_DELAY, 0);
2427
2428 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002429 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2430 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02002431 ring->wptr = 0;
2432 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04002433
2434 /* set the wb address whether it's enabled or not */
Cédric Cano4eace7f2011-02-11 19:45:38 -05002435 WREG32(CP_RB_RPTR_ADDR,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002436 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002437 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2438 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2439
2440 if (rdev->wb.enabled)
2441 WREG32(SCRATCH_UMSK, 0xff);
2442 else {
2443 tmp |= RB_NO_UPDATE;
2444 WREG32(SCRATCH_UMSK, 0);
2445 }
2446
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002447 mdelay(1);
2448 WREG32(CP_RB_CNTL, tmp);
2449
Christian Könige32eb502011-10-23 12:56:27 +02002450 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002451 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2452
Christian Könige32eb502011-10-23 12:56:27 +02002453 ring->rptr = RREG32(CP_RB_RPTR);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002454
2455 r600_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002456 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05002457 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002458 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02002459 ring->ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002460 return r;
2461 }
2462 return 0;
2463}
2464
Christian Könige32eb502011-10-23 12:56:27 +02002465void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002466{
2467 u32 rb_bufsz;
Christian König45df6802012-07-06 16:22:55 +02002468 int r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002469
2470 /* Align ring size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02002471 rb_bufsz = order_base_2(ring_size / 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002472 ring_size = (1 << (rb_bufsz + 1)) * 4;
Christian Könige32eb502011-10-23 12:56:27 +02002473 ring->ring_size = ring_size;
2474 ring->align_mask = 16 - 1;
Christian König45df6802012-07-06 16:22:55 +02002475
Alex Deucher89d35802012-07-17 14:02:31 -04002476 if (radeon_ring_supports_scratch_reg(rdev, ring)) {
2477 r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
2478 if (r) {
2479 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
2480 ring->rptr_save_reg = 0;
2481 }
Christian König45df6802012-07-06 16:22:55 +02002482 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002483}
2484
Jerome Glisse655efd32010-02-02 11:51:45 +01002485void r600_cp_fini(struct radeon_device *rdev)
2486{
Christian König45df6802012-07-06 16:22:55 +02002487 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse655efd32010-02-02 11:51:45 +01002488 r600_cp_stop(rdev);
Christian König45df6802012-07-06 16:22:55 +02002489 radeon_ring_fini(rdev, ring);
2490 radeon_scratch_free(rdev, ring->rptr_save_reg);
Jerome Glisse655efd32010-02-02 11:51:45 +01002491}
2492
Alex Deucher4d756582012-09-27 15:08:35 -04002493/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002494 * GPU scratch registers helpers function.
2495 */
2496void r600_scratch_init(struct radeon_device *rdev)
2497{
2498 int i;
2499
2500 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002501 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002502 for (i = 0; i < rdev->scratch.num_reg; i++) {
2503 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002504 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002505 }
2506}
2507
Christian Könige32eb502011-10-23 12:56:27 +02002508int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002509{
2510 uint32_t scratch;
2511 uint32_t tmp = 0;
Alex Deucher8b25ed32012-07-17 14:02:30 -04002512 unsigned i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002513 int r;
2514
2515 r = radeon_scratch_get(rdev, &scratch);
2516 if (r) {
2517 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2518 return r;
2519 }
2520 WREG32(scratch, 0xCAFEDEAD);
Christian Könige32eb502011-10-23 12:56:27 +02002521 r = radeon_ring_lock(rdev, ring, 3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002522 if (r) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002523 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002524 radeon_scratch_free(rdev, scratch);
2525 return r;
2526 }
Christian Könige32eb502011-10-23 12:56:27 +02002527 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2528 radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2529 radeon_ring_write(ring, 0xDEADBEEF);
2530 radeon_ring_unlock_commit(rdev, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002531 for (i = 0; i < rdev->usec_timeout; i++) {
2532 tmp = RREG32(scratch);
2533 if (tmp == 0xDEADBEEF)
2534 break;
2535 DRM_UDELAY(1);
2536 }
2537 if (i < rdev->usec_timeout) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002538 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002539 } else {
Christian Königbf852792011-10-13 13:19:22 +02002540 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
Alex Deucher8b25ed32012-07-17 14:02:30 -04002541 ring->idx, scratch, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002542 r = -EINVAL;
2543 }
2544 radeon_scratch_free(rdev, scratch);
2545 return r;
2546}
2547
Alex Deucher4d756582012-09-27 15:08:35 -04002548/*
2549 * CP fences/semaphores
2550 */
2551
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002552void r600_fence_ring_emit(struct radeon_device *rdev,
2553 struct radeon_fence *fence)
2554{
Christian Könige32eb502011-10-23 12:56:27 +02002555 struct radeon_ring *ring = &rdev->ring[fence->ring];
Christian König7b1f2482011-09-23 15:11:23 +02002556
Alex Deucherd0f8a852010-09-04 05:04:34 -04002557 if (rdev->wb.use_event) {
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002558 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002559 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002560 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2561 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2562 PACKET3_VC_ACTION_ENA |
2563 PACKET3_SH_ACTION_ENA);
2564 radeon_ring_write(ring, 0xFFFFFFFF);
2565 radeon_ring_write(ring, 0);
2566 radeon_ring_write(ring, 10); /* poll interval */
Alex Deucherd0f8a852010-09-04 05:04:34 -04002567 /* EVENT_WRITE_EOP - flush caches, send int */
Christian Könige32eb502011-10-23 12:56:27 +02002568 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2569 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2570 radeon_ring_write(ring, addr & 0xffffffff);
2571 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2572 radeon_ring_write(ring, fence->seq);
2573 radeon_ring_write(ring, 0);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002574 } else {
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002575 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002576 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2577 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2578 PACKET3_VC_ACTION_ENA |
2579 PACKET3_SH_ACTION_ENA);
2580 radeon_ring_write(ring, 0xFFFFFFFF);
2581 radeon_ring_write(ring, 0);
2582 radeon_ring_write(ring, 10); /* poll interval */
2583 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
2584 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
Alex Deucherd0f8a852010-09-04 05:04:34 -04002585 /* wait for 3D idle clean */
Christian Könige32eb502011-10-23 12:56:27 +02002586 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2587 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2588 radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002589 /* Emit fence sequence & fire IRQ */
Christian Könige32eb502011-10-23 12:56:27 +02002590 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2591 radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2592 radeon_ring_write(ring, fence->seq);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002593 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
Christian Könige32eb502011-10-23 12:56:27 +02002594 radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
2595 radeon_ring_write(ring, RB_INT_STAT);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002596 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002597}
2598
Christian König15d33322011-09-15 19:02:22 +02002599void r600_semaphore_ring_emit(struct radeon_device *rdev,
Christian Könige32eb502011-10-23 12:56:27 +02002600 struct radeon_ring *ring,
Christian König15d33322011-09-15 19:02:22 +02002601 struct radeon_semaphore *semaphore,
Christian König7b1f2482011-09-23 15:11:23 +02002602 bool emit_wait)
Christian König15d33322011-09-15 19:02:22 +02002603{
2604 uint64_t addr = semaphore->gpu_addr;
2605 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
2606
Christian König0be70432012-03-07 11:28:57 +01002607 if (rdev->family < CHIP_CAYMAN)
2608 sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
2609
Christian Könige32eb502011-10-23 12:56:27 +02002610 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
2611 radeon_ring_write(ring, addr & 0xffffffff);
2612 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
Christian König15d33322011-09-15 19:02:22 +02002613}
2614
Alex Deucher4d756582012-09-27 15:08:35 -04002615/**
Alex Deucher072b5ac2013-07-11 14:48:05 -04002616 * r600_copy_cpdma - copy pages using the CP DMA engine
2617 *
2618 * @rdev: radeon_device pointer
2619 * @src_offset: src GPU address
2620 * @dst_offset: dst GPU address
2621 * @num_gpu_pages: number of GPU pages to xfer
2622 * @fence: radeon fence object
2623 *
2624 * Copy GPU paging using the CP DMA engine (r6xx+).
2625 * Used by the radeon ttm implementation to move pages if
2626 * registered as the asic copy callback.
2627 */
2628int r600_copy_cpdma(struct radeon_device *rdev,
2629 uint64_t src_offset, uint64_t dst_offset,
2630 unsigned num_gpu_pages,
2631 struct radeon_fence **fence)
2632{
2633 struct radeon_semaphore *sem = NULL;
2634 int ring_index = rdev->asic->copy.blit_ring_index;
2635 struct radeon_ring *ring = &rdev->ring[ring_index];
2636 u32 size_in_bytes, cur_size_in_bytes, tmp;
2637 int i, num_loops;
2638 int r = 0;
2639
2640 r = radeon_semaphore_create(rdev, &sem);
2641 if (r) {
2642 DRM_ERROR("radeon: moving bo (%d).\n", r);
2643 return r;
2644 }
2645
2646 size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
2647 num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
Alex Deucher745a39a2013-07-18 09:24:37 -04002648 r = radeon_ring_lock(rdev, ring, num_loops * 6 + 24);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002649 if (r) {
2650 DRM_ERROR("radeon: moving bo (%d).\n", r);
2651 radeon_semaphore_free(rdev, &sem, NULL);
2652 return r;
2653 }
2654
2655 if (radeon_fence_need_sync(*fence, ring->idx)) {
2656 radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
2657 ring->idx);
2658 radeon_fence_note_sync(*fence, ring->idx);
2659 } else {
2660 radeon_semaphore_free(rdev, &sem, NULL);
2661 }
2662
Alex Deucher745a39a2013-07-18 09:24:37 -04002663 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2664 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2665 radeon_ring_write(ring, WAIT_3D_IDLE_bit);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002666 for (i = 0; i < num_loops; i++) {
2667 cur_size_in_bytes = size_in_bytes;
2668 if (cur_size_in_bytes > 0x1fffff)
2669 cur_size_in_bytes = 0x1fffff;
2670 size_in_bytes -= cur_size_in_bytes;
2671 tmp = upper_32_bits(src_offset) & 0xff;
2672 if (size_in_bytes == 0)
2673 tmp |= PACKET3_CP_DMA_CP_SYNC;
2674 radeon_ring_write(ring, PACKET3(PACKET3_CP_DMA, 4));
2675 radeon_ring_write(ring, src_offset & 0xffffffff);
2676 radeon_ring_write(ring, tmp);
2677 radeon_ring_write(ring, dst_offset & 0xffffffff);
2678 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
2679 radeon_ring_write(ring, cur_size_in_bytes);
2680 src_offset += cur_size_in_bytes;
2681 dst_offset += cur_size_in_bytes;
2682 }
2683 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2684 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2685 radeon_ring_write(ring, WAIT_CP_DMA_IDLE_bit);
2686
2687 r = radeon_fence_emit(rdev, fence, ring->idx);
2688 if (r) {
2689 radeon_ring_unlock_undo(rdev, ring);
2690 return r;
2691 }
2692
2693 radeon_ring_unlock_commit(rdev, ring);
2694 radeon_semaphore_free(rdev, &sem, *fence);
2695
2696 return r;
2697}
2698
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002699int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2700 uint32_t tiling_flags, uint32_t pitch,
2701 uint32_t offset, uint32_t obj_size)
2702{
2703 /* FIXME: implement */
2704 return 0;
2705}
2706
2707void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2708{
2709 /* FIXME: implement */
2710}
2711
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002712static int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002713{
Alex Deucher4d756582012-09-27 15:08:35 -04002714 struct radeon_ring *ring;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002715 int r;
2716
Alex Deucher9e46a482011-01-06 18:49:35 -05002717 /* enable pcie gen2 link */
2718 r600_pcie_gen2_enable(rdev);
2719
Alex Deuchere5903d32013-08-30 08:58:20 -04002720 /* scratch needs to be initialized before MC */
2721 r = r600_vram_scratch_init(rdev);
2722 if (r)
2723 return r;
2724
Alex Deucher6fab3feb2013-08-04 12:13:17 -04002725 r600_mc_program(rdev);
2726
Alex Deucher779720a2009-12-09 19:31:44 -05002727 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2728 r = r600_init_microcode(rdev);
2729 if (r) {
2730 DRM_ERROR("Failed to load firmware!\n");
2731 return r;
2732 }
2733 }
2734
Jerome Glisse1a029b72009-10-06 19:04:30 +02002735 if (rdev->flags & RADEON_IS_AGP) {
2736 r600_agp_enable(rdev);
2737 } else {
2738 r = r600_pcie_gart_enable(rdev);
2739 if (r)
2740 return r;
2741 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002742 r600_gpu_init(rdev);
Alex Deucherb70d6bb2010-08-06 21:36:58 -04002743
Alex Deucher724c80e2010-08-27 18:25:25 -04002744 /* allocate wb buffer */
2745 r = radeon_wb_init(rdev);
2746 if (r)
2747 return r;
2748
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002749 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
2750 if (r) {
2751 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2752 return r;
2753 }
2754
Alex Deucher4d756582012-09-27 15:08:35 -04002755 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
2756 if (r) {
2757 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
2758 return r;
2759 }
2760
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002761 /* Enable IRQ */
Adis Hamziće49f3952013-06-02 16:47:54 +02002762 if (!rdev->irq.installed) {
2763 r = radeon_irq_kms_init(rdev);
2764 if (r)
2765 return r;
2766 }
2767
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002768 r = r600_irq_init(rdev);
2769 if (r) {
2770 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2771 radeon_irq_kms_fini(rdev);
2772 return r;
2773 }
2774 r600_irq_set(rdev);
2775
Alex Deucher4d756582012-09-27 15:08:35 -04002776 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Christian Könige32eb502011-10-23 12:56:27 +02002777 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05002778 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02002779 RADEON_CP_PACKET2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002780 if (r)
2781 return r;
Alex Deucher4d756582012-09-27 15:08:35 -04002782
2783 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2784 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
2785 DMA_RB_RPTR, DMA_RB_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02002786 DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
Alex Deucher4d756582012-09-27 15:08:35 -04002787 if (r)
2788 return r;
2789
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002790 r = r600_cp_load_microcode(rdev);
2791 if (r)
2792 return r;
2793 r = r600_cp_resume(rdev);
2794 if (r)
2795 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04002796
Alex Deucher4d756582012-09-27 15:08:35 -04002797 r = r600_dma_resume(rdev);
2798 if (r)
2799 return r;
2800
Christian König2898c342012-07-05 11:55:34 +02002801 r = radeon_ib_pool_init(rdev);
2802 if (r) {
2803 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002804 return r;
Christian König2898c342012-07-05 11:55:34 +02002805 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05002806
Alex Deucherd4e30ef2012-06-04 17:18:51 -04002807 r = r600_audio_init(rdev);
2808 if (r) {
2809 DRM_ERROR("radeon: audio init failed\n");
2810 return r;
2811 }
2812
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002813 return 0;
2814}
2815
Dave Airlie28d52042009-09-21 14:33:58 +10002816void r600_vga_set_state(struct radeon_device *rdev, bool state)
2817{
2818 uint32_t temp;
2819
2820 temp = RREG32(CONFIG_CNTL);
2821 if (state == false) {
2822 temp &= ~(1<<0);
2823 temp |= (1<<1);
2824 } else {
2825 temp &= ~(1<<1);
2826 }
2827 WREG32(CONFIG_CNTL, temp);
2828}
2829
Dave Airliefc30b8e2009-09-18 15:19:37 +10002830int r600_resume(struct radeon_device *rdev)
2831{
2832 int r;
2833
Jerome Glisse1a029b72009-10-06 19:04:30 +02002834 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2835 * posting will perform necessary task to bring back GPU into good
2836 * shape.
2837 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002838 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002839 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002840
Jerome Glisseb15ba512011-11-15 11:48:34 -05002841 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002842 r = r600_startup(rdev);
2843 if (r) {
2844 DRM_ERROR("r600 startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05002845 rdev->accel_working = false;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002846 return r;
2847 }
2848
Dave Airliefc30b8e2009-09-18 15:19:37 +10002849 return r;
2850}
2851
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002852int r600_suspend(struct radeon_device *rdev)
2853{
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002854 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002855 r600_cp_stop(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04002856 r600_dma_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01002857 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002858 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002859 r600_pcie_gart_disable(rdev);
Alex Deucher6ddddfe2011-10-14 10:51:22 -04002860
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002861 return 0;
2862}
2863
2864/* Plan is to move initialization in that function and use
2865 * helper function so that radeon_device_init pretty much
2866 * do nothing more than calling asic specific function. This
2867 * should also allow to remove a bunch of callback function
2868 * like vram_info.
2869 */
2870int r600_init(struct radeon_device *rdev)
2871{
2872 int r;
2873
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002874 if (r600_debugfs_mc_info_init(rdev)) {
2875 DRM_ERROR("Failed to register debugfs file for mc !\n");
2876 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002877 /* Read BIOS */
2878 if (!radeon_get_bios(rdev)) {
2879 if (ASIC_IS_AVIVO(rdev))
2880 return -EINVAL;
2881 }
2882 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002883 if (!rdev->is_atom_bios) {
2884 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002885 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002886 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002887 r = radeon_atombios_init(rdev);
2888 if (r)
2889 return r;
2890 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05002891 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10002892 if (!rdev->bios) {
2893 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2894 return -EINVAL;
2895 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002896 DRM_INFO("GPU not posted. posting now...\n");
2897 atom_asic_init(rdev->mode_info.atom_context);
2898 }
2899 /* Initialize scratch registers */
2900 r600_scratch_init(rdev);
2901 /* Initialize surface registers */
2902 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002903 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002904 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002905 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002906 r = radeon_fence_driver_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002907 if (r)
2908 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01002909 if (rdev->flags & RADEON_IS_AGP) {
2910 r = radeon_agp_init(rdev);
2911 if (r)
2912 radeon_agp_disable(rdev);
2913 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002914 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002915 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002916 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002917 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002918 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002919 if (r)
2920 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002921
Christian Könige32eb502011-10-23 12:56:27 +02002922 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
2923 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002924
Alex Deucher4d756582012-09-27 15:08:35 -04002925 rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
2926 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
2927
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002928 rdev->ih.ring_obj = NULL;
2929 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002930
Jerome Glisse4aac0472009-09-14 18:29:49 +02002931 r = r600_pcie_gart_init(rdev);
2932 if (r)
2933 return r;
2934
Alex Deucher779720a2009-12-09 19:31:44 -05002935 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002936 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002937 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01002938 dev_err(rdev->dev, "disabling GPU acceleration\n");
2939 r600_cp_fini(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04002940 r600_dma_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002941 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002942 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02002943 radeon_ib_pool_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002944 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002945 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002946 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002947 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002948
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002949 return 0;
2950}
2951
2952void r600_fini(struct radeon_device *rdev)
2953{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002954 r600_audio_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002955 r600_cp_fini(rdev);
Alex Deucher4d756582012-09-27 15:08:35 -04002956 r600_dma_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002957 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002958 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02002959 radeon_ib_pool_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002960 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002961 r600_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04002962 r600_vram_scratch_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002963 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002964 radeon_gem_fini(rdev);
2965 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002966 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002967 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002968 kfree(rdev->bios);
2969 rdev->bios = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002970}
2971
2972
2973/*
2974 * CS stuff
2975 */
2976void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2977{
Christian König876dc9f2012-05-08 14:24:01 +02002978 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher89d35802012-07-17 14:02:31 -04002979 u32 next_rptr;
Christian König7b1f2482011-09-23 15:11:23 +02002980
Christian König45df6802012-07-06 16:22:55 +02002981 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04002982 next_rptr = ring->wptr + 3 + 4;
Christian König45df6802012-07-06 16:22:55 +02002983 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2984 radeon_ring_write(ring, ((ring->rptr_save_reg -
2985 PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2986 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04002987 } else if (rdev->wb.enabled) {
2988 next_rptr = ring->wptr + 5 + 4;
2989 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
2990 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
2991 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
2992 radeon_ring_write(ring, next_rptr);
2993 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02002994 }
2995
Christian Könige32eb502011-10-23 12:56:27 +02002996 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2997 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002998#ifdef __BIG_ENDIAN
2999 (2 << 0) |
3000#endif
3001 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02003002 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
3003 radeon_ring_write(ring, ib->length_dw);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003004}
3005
Alex Deucherf7128122012-02-23 17:53:45 -05003006int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003007{
Jerome Glissef2e39222012-05-09 15:35:02 +02003008 struct radeon_ib ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003009 uint32_t scratch;
3010 uint32_t tmp = 0;
3011 unsigned i;
3012 int r;
3013
3014 r = radeon_scratch_get(rdev, &scratch);
3015 if (r) {
3016 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3017 return r;
3018 }
3019 WREG32(scratch, 0xCAFEDEAD);
Christian König4bf3dd92012-08-06 18:57:44 +02003020 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003021 if (r) {
3022 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003023 goto free_scratch;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003024 }
Jerome Glissef2e39222012-05-09 15:35:02 +02003025 ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
3026 ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
3027 ib.ptr[2] = 0xDEADBEEF;
3028 ib.length_dw = 3;
Christian König4ef72562012-07-13 13:06:00 +02003029 r = radeon_ib_schedule(rdev, &ib, NULL);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003030 if (r) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003031 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003032 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003033 }
Jerome Glissef2e39222012-05-09 15:35:02 +02003034 r = radeon_fence_wait(ib.fence, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003035 if (r) {
3036 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003037 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003038 }
3039 for (i = 0; i < rdev->usec_timeout; i++) {
3040 tmp = RREG32(scratch);
3041 if (tmp == 0xDEADBEEF)
3042 break;
3043 DRM_UDELAY(1);
3044 }
3045 if (i < rdev->usec_timeout) {
Jerome Glissef2e39222012-05-09 15:35:02 +02003046 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003047 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01003048 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003049 scratch, tmp);
3050 r = -EINVAL;
3051 }
Michel Dänzeraf026c52012-09-20 10:31:10 +02003052free_ib:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003053 radeon_ib_free(rdev, &ib);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003054free_scratch:
3055 radeon_scratch_free(rdev, scratch);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003056 return r;
3057}
3058
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003059/*
3060 * Interrupts
3061 *
3062 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3063 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3064 * writing to the ring and the GPU consuming, the GPU writes to the ring
3065 * and host consumes. As the host irq handler processes interrupts, it
3066 * increments the rptr. When the rptr catches up with the wptr, all the
3067 * current interrupts have been processed.
3068 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003069
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003070void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
3071{
3072 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003073
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003074 /* Align ring size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02003075 rb_bufsz = order_base_2(ring_size / 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003076 ring_size = (1 << rb_bufsz) * 4;
3077 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01003078 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
3079 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003080}
3081
Alex Deucher25a857f2012-03-20 17:18:22 -04003082int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003083{
3084 int r;
3085
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003086 /* Allocate ring buffer */
3087 if (rdev->ih.ring_obj == NULL) {
Daniel Vetter441921d2011-02-18 17:59:16 +01003088 r = radeon_bo_create(rdev, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05003089 PAGE_SIZE, true,
Jerome Glisse4c788672009-11-20 14:29:23 +01003090 RADEON_GEM_DOMAIN_GTT,
Alex Deucher40f5cf92012-05-10 18:33:13 -04003091 NULL, &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003092 if (r) {
3093 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
3094 return r;
3095 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003096 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3097 if (unlikely(r != 0))
3098 return r;
3099 r = radeon_bo_pin(rdev->ih.ring_obj,
3100 RADEON_GEM_DOMAIN_GTT,
3101 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003102 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003103 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003104 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
3105 return r;
3106 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003107 r = radeon_bo_kmap(rdev->ih.ring_obj,
3108 (void **)&rdev->ih.ring);
3109 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003110 if (r) {
3111 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
3112 return r;
3113 }
3114 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003115 return 0;
3116}
3117
Alex Deucher25a857f2012-03-20 17:18:22 -04003118void r600_ih_ring_fini(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003119{
Jerome Glisse4c788672009-11-20 14:29:23 +01003120 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003121 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003122 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3123 if (likely(r == 0)) {
3124 radeon_bo_kunmap(rdev->ih.ring_obj);
3125 radeon_bo_unpin(rdev->ih.ring_obj);
3126 radeon_bo_unreserve(rdev->ih.ring_obj);
3127 }
3128 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003129 rdev->ih.ring = NULL;
3130 rdev->ih.ring_obj = NULL;
3131 }
3132}
3133
Alex Deucher45f9a392010-03-24 13:55:51 -04003134void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003135{
3136
Alex Deucher45f9a392010-03-24 13:55:51 -04003137 if ((rdev->family >= CHIP_RV770) &&
3138 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003139 /* r7xx asics need to soft reset RLC before halting */
3140 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
3141 RREG32(SRBM_SOFT_RESET);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003142 mdelay(15);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003143 WREG32(SRBM_SOFT_RESET, 0);
3144 RREG32(SRBM_SOFT_RESET);
3145 }
3146
3147 WREG32(RLC_CNTL, 0);
3148}
3149
3150static void r600_rlc_start(struct radeon_device *rdev)
3151{
3152 WREG32(RLC_CNTL, RLC_ENABLE);
3153}
3154
Alex Deucher2948f5e2013-04-12 13:52:52 -04003155static int r600_rlc_resume(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003156{
3157 u32 i;
3158 const __be32 *fw_data;
3159
3160 if (!rdev->rlc_fw)
3161 return -EINVAL;
3162
3163 r600_rlc_stop(rdev);
3164
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003165 WREG32(RLC_HB_CNTL, 0);
Alex Deucherc420c742012-03-20 17:18:39 -04003166
Alex Deucher2948f5e2013-04-12 13:52:52 -04003167 WREG32(RLC_HB_BASE, 0);
3168 WREG32(RLC_HB_RPTR, 0);
3169 WREG32(RLC_HB_WPTR, 0);
3170 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
3171 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003172 WREG32(RLC_MC_CNTL, 0);
3173 WREG32(RLC_UCODE_CNTL, 0);
3174
3175 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucher2948f5e2013-04-12 13:52:52 -04003176 if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003177 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
3178 WREG32(RLC_UCODE_ADDR, i);
3179 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3180 }
3181 } else {
Alex Deucher138e4e12013-01-11 15:33:13 -05003182 for (i = 0; i < R600_RLC_UCODE_SIZE; i++) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003183 WREG32(RLC_UCODE_ADDR, i);
3184 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3185 }
3186 }
3187 WREG32(RLC_UCODE_ADDR, 0);
3188
3189 r600_rlc_start(rdev);
3190
3191 return 0;
3192}
3193
3194static void r600_enable_interrupts(struct radeon_device *rdev)
3195{
3196 u32 ih_cntl = RREG32(IH_CNTL);
3197 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3198
3199 ih_cntl |= ENABLE_INTR;
3200 ih_rb_cntl |= IH_RB_ENABLE;
3201 WREG32(IH_CNTL, ih_cntl);
3202 WREG32(IH_RB_CNTL, ih_rb_cntl);
3203 rdev->ih.enabled = true;
3204}
3205
Alex Deucher45f9a392010-03-24 13:55:51 -04003206void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003207{
3208 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3209 u32 ih_cntl = RREG32(IH_CNTL);
3210
3211 ih_rb_cntl &= ~IH_RB_ENABLE;
3212 ih_cntl &= ~ENABLE_INTR;
3213 WREG32(IH_RB_CNTL, ih_rb_cntl);
3214 WREG32(IH_CNTL, ih_cntl);
3215 /* set rptr, wptr to 0 */
3216 WREG32(IH_RB_RPTR, 0);
3217 WREG32(IH_RB_WPTR, 0);
3218 rdev->ih.enabled = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003219 rdev->ih.rptr = 0;
3220}
3221
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003222static void r600_disable_interrupt_state(struct radeon_device *rdev)
3223{
3224 u32 tmp;
3225
Alex Deucher3555e532010-10-08 12:09:12 -04003226 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher4d756582012-09-27 15:08:35 -04003227 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3228 WREG32(DMA_CNTL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003229 WREG32(GRBM_INT_CNTL, 0);
3230 WREG32(DxMODE_INT_MASK, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003231 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
3232 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003233 if (ASIC_IS_DCE3(rdev)) {
3234 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
3235 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
3236 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3237 WREG32(DC_HPD1_INT_CONTROL, tmp);
3238 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3239 WREG32(DC_HPD2_INT_CONTROL, tmp);
3240 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3241 WREG32(DC_HPD3_INT_CONTROL, tmp);
3242 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3243 WREG32(DC_HPD4_INT_CONTROL, tmp);
3244 if (ASIC_IS_DCE32(rdev)) {
3245 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003246 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003247 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003248 WREG32(DC_HPD6_INT_CONTROL, tmp);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003249 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3250 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
3251 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3252 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003253 } else {
3254 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3255 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3256 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3257 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003258 }
3259 } else {
3260 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
3261 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
3262 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003263 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003264 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003265 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003266 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003267 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003268 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3269 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3270 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3271 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003272 }
3273}
3274
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003275int r600_irq_init(struct radeon_device *rdev)
3276{
3277 int ret = 0;
3278 int rb_bufsz;
3279 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
3280
3281 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01003282 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003283 if (ret)
3284 return ret;
3285
3286 /* disable irqs */
3287 r600_disable_interrupts(rdev);
3288
3289 /* init rlc */
Alex Deucher2948f5e2013-04-12 13:52:52 -04003290 if (rdev->family >= CHIP_CEDAR)
3291 ret = evergreen_rlc_resume(rdev);
3292 else
3293 ret = r600_rlc_resume(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003294 if (ret) {
3295 r600_ih_ring_fini(rdev);
3296 return ret;
3297 }
3298
3299 /* setup interrupt control */
3300 /* set dummy read address to ring address */
3301 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
3302 interrupt_cntl = RREG32(INTERRUPT_CNTL);
3303 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3304 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3305 */
3306 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
3307 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3308 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
3309 WREG32(INTERRUPT_CNTL, interrupt_cntl);
3310
3311 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
Daniel Vetterb72a8922013-07-10 14:11:59 +02003312 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003313
3314 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
3315 IH_WPTR_OVERFLOW_CLEAR |
3316 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04003317
3318 if (rdev->wb.enabled)
3319 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
3320
3321 /* set the writeback address whether it's enabled or not */
3322 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
3323 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 -05003324
3325 WREG32(IH_RB_CNTL, ih_rb_cntl);
3326
3327 /* set rptr, wptr to 0 */
3328 WREG32(IH_RB_RPTR, 0);
3329 WREG32(IH_RB_WPTR, 0);
3330
3331 /* Default settings for IH_CNTL (disabled at first) */
3332 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3333 /* RPTR_REARM only works if msi's are enabled */
3334 if (rdev->msi_enabled)
3335 ih_cntl |= RPTR_REARM;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003336 WREG32(IH_CNTL, ih_cntl);
3337
3338 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04003339 if (rdev->family >= CHIP_CEDAR)
3340 evergreen_disable_interrupt_state(rdev);
3341 else
3342 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003343
Dave Airlie20998102012-04-03 11:53:05 +01003344 /* at this point everything should be setup correctly to enable master */
3345 pci_set_master(rdev->pdev);
3346
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003347 /* enable irqs */
3348 r600_enable_interrupts(rdev);
3349
3350 return ret;
3351}
3352
Jerome Glisse0c452492010-01-15 14:44:37 +01003353void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003354{
Alex Deucher45f9a392010-03-24 13:55:51 -04003355 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003356 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003357}
3358
3359void r600_irq_fini(struct radeon_device *rdev)
3360{
3361 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003362 r600_ih_ring_fini(rdev);
3363}
3364
3365int r600_irq_set(struct radeon_device *rdev)
3366{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003367 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3368 u32 mode_int = 0;
3369 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04003370 u32 grbm_int_cntl = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003371 u32 hdmi0, hdmi1;
Alex Deucher6f34be52010-11-21 10:59:01 -05003372 u32 d1grph = 0, d2grph = 0;
Alex Deucher4d756582012-09-27 15:08:35 -04003373 u32 dma_cntl;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003374 u32 thermal_int = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003375
Jerome Glisse003e69f2010-01-07 15:39:14 +01003376 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003377 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01003378 return -EINVAL;
3379 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003380 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003381 if (!rdev->ih.enabled) {
3382 r600_disable_interrupts(rdev);
3383 /* force the active interrupt state to all disabled */
3384 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003385 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003386 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003387
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003388 if (ASIC_IS_DCE3(rdev)) {
3389 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3390 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3391 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3392 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3393 if (ASIC_IS_DCE32(rdev)) {
3394 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3395 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003396 hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3397 hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
Alex Deucherf122c612012-03-30 08:59:57 -04003398 } else {
3399 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3400 hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003401 }
3402 } else {
3403 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3404 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3405 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
Alex Deucherf122c612012-03-30 08:59:57 -04003406 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3407 hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003408 }
Alex Deucher4a6369e2013-04-12 14:04:10 -04003409
Alex Deucher4d756582012-09-27 15:08:35 -04003410 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003411
Alex Deucher4a6369e2013-04-12 14:04:10 -04003412 if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
3413 thermal_int = RREG32(CG_THERMAL_INT) &
3414 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
Alex Deucher66229b22013-06-26 00:11:19 -04003415 } else if (rdev->family >= CHIP_RV770) {
3416 thermal_int = RREG32(RV770_CG_THERMAL_INT) &
3417 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
3418 }
3419 if (rdev->irq.dpm_thermal) {
3420 DRM_DEBUG("dpm thermal\n");
3421 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003422 }
3423
Christian Koenig736fc372012-05-17 19:52:00 +02003424 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003425 DRM_DEBUG("r600_irq_set: sw int\n");
3426 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003427 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003428 }
Alex Deucher4d756582012-09-27 15:08:35 -04003429
3430 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
3431 DRM_DEBUG("r600_irq_set: sw int dma\n");
3432 dma_cntl |= TRAP_ENABLE;
3433 }
3434
Alex Deucher6f34be52010-11-21 10:59:01 -05003435 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003436 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003437 DRM_DEBUG("r600_irq_set: vblank 0\n");
3438 mode_int |= D1MODE_VBLANK_INT_MASK;
3439 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003440 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003441 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003442 DRM_DEBUG("r600_irq_set: vblank 1\n");
3443 mode_int |= D2MODE_VBLANK_INT_MASK;
3444 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003445 if (rdev->irq.hpd[0]) {
3446 DRM_DEBUG("r600_irq_set: hpd 1\n");
3447 hpd1 |= DC_HPDx_INT_EN;
3448 }
3449 if (rdev->irq.hpd[1]) {
3450 DRM_DEBUG("r600_irq_set: hpd 2\n");
3451 hpd2 |= DC_HPDx_INT_EN;
3452 }
3453 if (rdev->irq.hpd[2]) {
3454 DRM_DEBUG("r600_irq_set: hpd 3\n");
3455 hpd3 |= DC_HPDx_INT_EN;
3456 }
3457 if (rdev->irq.hpd[3]) {
3458 DRM_DEBUG("r600_irq_set: hpd 4\n");
3459 hpd4 |= DC_HPDx_INT_EN;
3460 }
3461 if (rdev->irq.hpd[4]) {
3462 DRM_DEBUG("r600_irq_set: hpd 5\n");
3463 hpd5 |= DC_HPDx_INT_EN;
3464 }
3465 if (rdev->irq.hpd[5]) {
3466 DRM_DEBUG("r600_irq_set: hpd 6\n");
3467 hpd6 |= DC_HPDx_INT_EN;
3468 }
Alex Deucherf122c612012-03-30 08:59:57 -04003469 if (rdev->irq.afmt[0]) {
3470 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3471 hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003472 }
Alex Deucherf122c612012-03-30 08:59:57 -04003473 if (rdev->irq.afmt[1]) {
3474 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3475 hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003476 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003477
3478 WREG32(CP_INT_CNTL, cp_int_cntl);
Alex Deucher4d756582012-09-27 15:08:35 -04003479 WREG32(DMA_CNTL, dma_cntl);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003480 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher6f34be52010-11-21 10:59:01 -05003481 WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
3482 WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
Alex Deucher2031f772010-04-22 12:52:11 -04003483 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003484 if (ASIC_IS_DCE3(rdev)) {
3485 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3486 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3487 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3488 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3489 if (ASIC_IS_DCE32(rdev)) {
3490 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3491 WREG32(DC_HPD6_INT_CONTROL, hpd6);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003492 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
3493 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
Alex Deucherf122c612012-03-30 08:59:57 -04003494 } else {
3495 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3496 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003497 }
3498 } else {
3499 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3500 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3501 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
Alex Deucherf122c612012-03-30 08:59:57 -04003502 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3503 WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003504 }
Alex Deucher4a6369e2013-04-12 14:04:10 -04003505 if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
3506 WREG32(CG_THERMAL_INT, thermal_int);
Alex Deucher66229b22013-06-26 00:11:19 -04003507 } else if (rdev->family >= CHIP_RV770) {
3508 WREG32(RV770_CG_THERMAL_INT, thermal_int);
Alex Deucher4a6369e2013-04-12 14:04:10 -04003509 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003510
3511 return 0;
3512}
3513
Andi Kleence580fa2011-10-13 16:08:47 -07003514static void r600_irq_ack(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003515{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003516 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003517
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003518 if (ASIC_IS_DCE3(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003519 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3520 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3521 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
Alex Deucherf122c612012-03-30 08:59:57 -04003522 if (ASIC_IS_DCE32(rdev)) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003523 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
3524 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003525 } else {
3526 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3527 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
3528 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003529 } else {
Alex Deucher6f34be52010-11-21 10:59:01 -05003530 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3531 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3532 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003533 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3534 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003535 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003536 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3537 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003538
Alex Deucher6f34be52010-11-21 10:59:01 -05003539 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3540 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3541 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3542 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3543 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003544 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003545 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003546 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003547 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003548 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003549 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003550 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003551 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003552 if (ASIC_IS_DCE3(rdev)) {
3553 tmp = RREG32(DC_HPD1_INT_CONTROL);
3554 tmp |= DC_HPDx_INT_ACK;
3555 WREG32(DC_HPD1_INT_CONTROL, tmp);
3556 } else {
3557 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3558 tmp |= DC_HPDx_INT_ACK;
3559 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3560 }
3561 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003562 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003563 if (ASIC_IS_DCE3(rdev)) {
3564 tmp = RREG32(DC_HPD2_INT_CONTROL);
3565 tmp |= DC_HPDx_INT_ACK;
3566 WREG32(DC_HPD2_INT_CONTROL, tmp);
3567 } else {
3568 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3569 tmp |= DC_HPDx_INT_ACK;
3570 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3571 }
3572 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003573 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003574 if (ASIC_IS_DCE3(rdev)) {
3575 tmp = RREG32(DC_HPD3_INT_CONTROL);
3576 tmp |= DC_HPDx_INT_ACK;
3577 WREG32(DC_HPD3_INT_CONTROL, tmp);
3578 } else {
3579 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3580 tmp |= DC_HPDx_INT_ACK;
3581 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3582 }
3583 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003584 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003585 tmp = RREG32(DC_HPD4_INT_CONTROL);
3586 tmp |= DC_HPDx_INT_ACK;
3587 WREG32(DC_HPD4_INT_CONTROL, tmp);
3588 }
3589 if (ASIC_IS_DCE32(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003590 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003591 tmp = RREG32(DC_HPD5_INT_CONTROL);
3592 tmp |= DC_HPDx_INT_ACK;
3593 WREG32(DC_HPD5_INT_CONTROL, tmp);
3594 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003595 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003596 tmp = RREG32(DC_HPD5_INT_CONTROL);
3597 tmp |= DC_HPDx_INT_ACK;
3598 WREG32(DC_HPD6_INT_CONTROL, tmp);
3599 }
Alex Deucherf122c612012-03-30 08:59:57 -04003600 if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003601 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
Alex Deucherf122c612012-03-30 08:59:57 -04003602 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003603 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003604 }
3605 if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003606 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003607 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003608 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Christian Koenigf2594932010-04-10 03:13:16 +02003609 }
3610 } else {
Alex Deucherf122c612012-03-30 08:59:57 -04003611 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3612 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
3613 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3614 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3615 }
3616 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3617 if (ASIC_IS_DCE3(rdev)) {
3618 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
3619 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3620 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
3621 } else {
3622 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
3623 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3624 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
3625 }
Christian Koenigf2594932010-04-10 03:13:16 +02003626 }
3627 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003628}
3629
3630void r600_irq_disable(struct radeon_device *rdev)
3631{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003632 r600_disable_interrupts(rdev);
3633 /* Wait and acknowledge irq */
3634 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003635 r600_irq_ack(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003636 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003637}
3638
Andi Kleence580fa2011-10-13 16:08:47 -07003639static u32 r600_get_ih_wptr(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003640{
3641 u32 wptr, tmp;
3642
Alex Deucher724c80e2010-08-27 18:25:25 -04003643 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04003644 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04003645 else
3646 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003647
3648 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003649 /* When a ring buffer overflow happen start parsing interrupt
3650 * from the last not overwritten vector (wptr + 16). Hopefully
3651 * this should allow us to catchup.
3652 */
3653 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3654 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3655 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003656 tmp = RREG32(IH_RB_CNTL);
3657 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3658 WREG32(IH_RB_CNTL, tmp);
3659 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003660 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003661}
3662
3663/* r600 IV Ring
3664 * Each IV ring entry is 128 bits:
3665 * [7:0] - interrupt source id
3666 * [31:8] - reserved
3667 * [59:32] - interrupt source data
3668 * [127:60] - reserved
3669 *
3670 * The basic interrupt vector entries
3671 * are decoded as follows:
3672 * src_id src_data description
3673 * 1 0 D1 Vblank
3674 * 1 1 D1 Vline
3675 * 5 0 D2 Vblank
3676 * 5 1 D2 Vline
3677 * 19 0 FP Hot plug detection A
3678 * 19 1 FP Hot plug detection B
3679 * 19 2 DAC A auto-detection
3680 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003681 * 21 4 HDMI block A
3682 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003683 * 176 - CP_INT RB
3684 * 177 - CP_INT IB1
3685 * 178 - CP_INT IB2
3686 * 181 - EOP Interrupt
3687 * 233 - GUI Idle
3688 *
3689 * Note, these are based on r600 and may need to be
3690 * adjusted or added to on newer asics
3691 */
3692
3693int r600_irq_process(struct radeon_device *rdev)
3694{
Dave Airlie682f1a52011-06-18 03:59:51 +00003695 u32 wptr;
3696 u32 rptr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003697 u32 src_id, src_data;
Alex Deucher6f34be52010-11-21 10:59:01 -05003698 u32 ring_index;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003699 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04003700 bool queue_hdmi = false;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003701 bool queue_thermal = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003702
Dave Airlie682f1a52011-06-18 03:59:51 +00003703 if (!rdev->ih.enabled || rdev->shutdown)
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003704 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003705
Benjamin Herrenschmidtf6a56932011-07-13 06:28:22 +00003706 /* No MSIs, need a dummy read to flush PCI DMAs */
3707 if (!rdev->msi_enabled)
3708 RREG32(IH_RB_WPTR);
3709
Dave Airlie682f1a52011-06-18 03:59:51 +00003710 wptr = r600_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02003711
3712restart_ih:
3713 /* is somebody else already processing irqs? */
3714 if (atomic_xchg(&rdev->ih.lock, 1))
3715 return IRQ_NONE;
3716
Dave Airlie682f1a52011-06-18 03:59:51 +00003717 rptr = rdev->ih.rptr;
3718 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
3719
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10003720 /* Order reading of wptr vs. reading of IH ring data */
3721 rmb();
3722
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003723 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05003724 r600_irq_ack(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003725
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003726 while (rptr != wptr) {
3727 /* wptr/rptr are in bytes! */
3728 ring_index = rptr / 4;
Cédric Cano4eace7f2011-02-11 19:45:38 -05003729 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3730 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003731
3732 switch (src_id) {
3733 case 1: /* D1 vblank/vline */
3734 switch (src_data) {
3735 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003736 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003737 if (rdev->irq.crtc_vblank_int[0]) {
3738 drm_handle_vblank(rdev->ddev, 0);
3739 rdev->pm.vblank_sync = true;
3740 wake_up(&rdev->irq.vblank_queue);
3741 }
Christian Koenig736fc372012-05-17 19:52:00 +02003742 if (atomic_read(&rdev->irq.pflip[0]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003743 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003744 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003745 DRM_DEBUG("IH: D1 vblank\n");
3746 }
3747 break;
3748 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003749 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
3750 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003751 DRM_DEBUG("IH: D1 vline\n");
3752 }
3753 break;
3754 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003755 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003756 break;
3757 }
3758 break;
3759 case 5: /* D2 vblank/vline */
3760 switch (src_data) {
3761 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003762 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003763 if (rdev->irq.crtc_vblank_int[1]) {
3764 drm_handle_vblank(rdev->ddev, 1);
3765 rdev->pm.vblank_sync = true;
3766 wake_up(&rdev->irq.vblank_queue);
3767 }
Christian Koenig736fc372012-05-17 19:52:00 +02003768 if (atomic_read(&rdev->irq.pflip[1]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003769 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003770 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003771 DRM_DEBUG("IH: D2 vblank\n");
3772 }
3773 break;
3774 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003775 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
3776 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003777 DRM_DEBUG("IH: D2 vline\n");
3778 }
3779 break;
3780 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003781 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003782 break;
3783 }
3784 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003785 case 19: /* HPD/DAC hotplug */
3786 switch (src_data) {
3787 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05003788 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
3789 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003790 queue_hotplug = true;
3791 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003792 }
3793 break;
3794 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05003795 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
3796 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003797 queue_hotplug = true;
3798 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003799 }
3800 break;
3801 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05003802 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
3803 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003804 queue_hotplug = true;
3805 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003806 }
3807 break;
3808 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05003809 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
3810 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003811 queue_hotplug = true;
3812 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003813 }
3814 break;
3815 case 10:
Alex Deucher6f34be52010-11-21 10:59:01 -05003816 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
3817 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003818 queue_hotplug = true;
3819 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003820 }
3821 break;
3822 case 12:
Alex Deucher6f34be52010-11-21 10:59:01 -05003823 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
3824 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003825 queue_hotplug = true;
3826 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003827 }
3828 break;
3829 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003830 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003831 break;
3832 }
3833 break;
Alex Deucherf122c612012-03-30 08:59:57 -04003834 case 21: /* hdmi */
3835 switch (src_data) {
3836 case 4:
3837 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3838 rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3839 queue_hdmi = true;
3840 DRM_DEBUG("IH: HDMI0\n");
3841 }
3842 break;
3843 case 5:
3844 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3845 rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3846 queue_hdmi = true;
3847 DRM_DEBUG("IH: HDMI1\n");
3848 }
3849 break;
3850 default:
3851 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
3852 break;
3853 }
Christian Koenigf2594932010-04-10 03:13:16 +02003854 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003855 case 176: /* CP_INT in ring buffer */
3856 case 177: /* CP_INT in IB1 */
3857 case 178: /* CP_INT in IB2 */
3858 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04003859 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003860 break;
3861 case 181: /* CP EOP event */
3862 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher74652802011-08-25 13:39:48 -04003863 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003864 break;
Alex Deucher4d756582012-09-27 15:08:35 -04003865 case 224: /* DMA trap event */
3866 DRM_DEBUG("IH: DMA trap\n");
3867 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
3868 break;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003869 case 230: /* thermal low to high */
3870 DRM_DEBUG("IH: thermal low to high\n");
3871 rdev->pm.dpm.thermal.high_to_low = false;
3872 queue_thermal = true;
3873 break;
3874 case 231: /* thermal high to low */
3875 DRM_DEBUG("IH: thermal high to low\n");
3876 rdev->pm.dpm.thermal.high_to_low = true;
3877 queue_thermal = true;
3878 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003879 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04003880 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04003881 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003882 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003883 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003884 break;
3885 }
3886
3887 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01003888 rptr += 16;
3889 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003890 }
Alex Deucherd4877cf2009-12-04 16:56:37 -05003891 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01003892 schedule_work(&rdev->hotplug_work);
Alex Deucherf122c612012-03-30 08:59:57 -04003893 if (queue_hdmi)
3894 schedule_work(&rdev->audio_work);
Alex Deucher4a6369e2013-04-12 14:04:10 -04003895 if (queue_thermal && rdev->pm.dpm_enabled)
3896 schedule_work(&rdev->pm.dpm.thermal.work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003897 rdev->ih.rptr = rptr;
3898 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02003899 atomic_set(&rdev->ih.lock, 0);
3900
3901 /* make sure wptr hasn't changed while processing */
3902 wptr = r600_get_ih_wptr(rdev);
3903 if (wptr != rptr)
3904 goto restart_ih;
3905
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003906 return IRQ_HANDLED;
3907}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003908
3909/*
3910 * Debugfs info
3911 */
3912#if defined(CONFIG_DEBUG_FS)
3913
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003914static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3915{
3916 struct drm_info_node *node = (struct drm_info_node *) m->private;
3917 struct drm_device *dev = node->minor->dev;
3918 struct radeon_device *rdev = dev->dev_private;
3919
3920 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3921 DREG32_SYS(m, rdev, VM_L2_STATUS);
3922 return 0;
3923}
3924
3925static struct drm_info_list r600_mc_info_list[] = {
3926 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003927};
3928#endif
3929
3930int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3931{
3932#if defined(CONFIG_DEBUG_FS)
3933 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3934#else
3935 return 0;
3936#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003937}
Jerome Glisse062b3892010-02-04 20:36:39 +01003938
3939/**
3940 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3941 * rdev: radeon device structure
3942 * bo: buffer object struct which userspace is waiting for idle
3943 *
3944 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3945 * through ring buffer, this leads to corruption in rendering, see
3946 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3947 * directly perform HDP flush by writing register through MMIO.
3948 */
3949void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3950{
Alex Deucher812d0462010-07-26 18:51:53 -04003951 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
Alex Deucherf3886f82010-12-08 10:05:34 -05003952 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
3953 * This seems to cause problems on some AGP cards. Just use the old
3954 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04003955 */
Alex Deuchere4884592010-09-27 10:57:10 -04003956 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
Alex Deucherf3886f82010-12-08 10:05:34 -05003957 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04003958 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04003959 u32 tmp;
3960
3961 WREG32(HDP_DEBUG1, 0);
3962 tmp = readl((void __iomem *)ptr);
3963 } else
3964 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01003965}
Alex Deucher3313e3d2011-01-06 18:49:34 -05003966
3967void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
3968{
Alex Deucherd5445a12013-03-18 18:52:13 -04003969 u32 link_width_cntl, mask;
Alex Deucher3313e3d2011-01-06 18:49:34 -05003970
3971 if (rdev->flags & RADEON_IS_IGP)
3972 return;
3973
3974 if (!(rdev->flags & RADEON_IS_PCIE))
3975 return;
3976
3977 /* x2 cards have a special sequence */
3978 if (ASIC_IS_X2(rdev))
3979 return;
3980
Alex Deucherd5445a12013-03-18 18:52:13 -04003981 radeon_gui_idle(rdev);
Alex Deucher3313e3d2011-01-06 18:49:34 -05003982
3983 switch (lanes) {
3984 case 0:
3985 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
3986 break;
3987 case 1:
3988 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
3989 break;
3990 case 2:
3991 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
3992 break;
3993 case 4:
3994 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
3995 break;
3996 case 8:
3997 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
3998 break;
3999 case 12:
Alex Deucherd5445a12013-03-18 18:52:13 -04004000 /* not actually supported */
Alex Deucher3313e3d2011-01-06 18:49:34 -05004001 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
4002 break;
4003 case 16:
Alex Deucher3313e3d2011-01-06 18:49:34 -05004004 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
4005 break;
Alex Deucherd5445a12013-03-18 18:52:13 -04004006 default:
4007 DRM_ERROR("invalid pcie lane request: %d\n", lanes);
4008 return;
Alex Deucher3313e3d2011-01-06 18:49:34 -05004009 }
4010
Alex Deucher492d2b62012-10-25 16:06:59 -04004011 link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucherd5445a12013-03-18 18:52:13 -04004012 link_width_cntl &= ~RADEON_PCIE_LC_LINK_WIDTH_MASK;
4013 link_width_cntl |= mask << RADEON_PCIE_LC_LINK_WIDTH_SHIFT;
4014 link_width_cntl |= (RADEON_PCIE_LC_RECONFIG_NOW |
4015 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004016
Alex Deucher492d2b62012-10-25 16:06:59 -04004017 WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004018}
4019
4020int r600_get_pcie_lanes(struct radeon_device *rdev)
4021{
4022 u32 link_width_cntl;
4023
4024 if (rdev->flags & RADEON_IS_IGP)
4025 return 0;
4026
4027 if (!(rdev->flags & RADEON_IS_PCIE))
4028 return 0;
4029
4030 /* x2 cards have a special sequence */
4031 if (ASIC_IS_X2(rdev))
4032 return 0;
4033
Alex Deucherd5445a12013-03-18 18:52:13 -04004034 radeon_gui_idle(rdev);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004035
Alex Deucher492d2b62012-10-25 16:06:59 -04004036 link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004037
4038 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
Alex Deucher3313e3d2011-01-06 18:49:34 -05004039 case RADEON_PCIE_LC_LINK_WIDTH_X1:
4040 return 1;
4041 case RADEON_PCIE_LC_LINK_WIDTH_X2:
4042 return 2;
4043 case RADEON_PCIE_LC_LINK_WIDTH_X4:
4044 return 4;
4045 case RADEON_PCIE_LC_LINK_WIDTH_X8:
4046 return 8;
Alex Deucherd5445a12013-03-18 18:52:13 -04004047 case RADEON_PCIE_LC_LINK_WIDTH_X12:
4048 /* not actually supported */
4049 return 12;
4050 case RADEON_PCIE_LC_LINK_WIDTH_X0:
Alex Deucher3313e3d2011-01-06 18:49:34 -05004051 case RADEON_PCIE_LC_LINK_WIDTH_X16:
4052 default:
4053 return 16;
4054 }
4055}
4056
Alex Deucher9e46a482011-01-06 18:49:35 -05004057static void r600_pcie_gen2_enable(struct radeon_device *rdev)
4058{
4059 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
4060 u16 link_cntl2;
4061
Alex Deucherd42dd572011-01-12 20:05:11 -05004062 if (radeon_pcie_gen2 == 0)
4063 return;
4064
Alex Deucher9e46a482011-01-06 18:49:35 -05004065 if (rdev->flags & RADEON_IS_IGP)
4066 return;
4067
4068 if (!(rdev->flags & RADEON_IS_PCIE))
4069 return;
4070
4071 /* x2 cards have a special sequence */
4072 if (ASIC_IS_X2(rdev))
4073 return;
4074
4075 /* only RV6xx+ chips are supported */
4076 if (rdev->family <= CHIP_R600)
4077 return;
4078
Kleber Sacilotto de Souza7e0e4192013-05-03 19:43:13 -03004079 if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
4080 (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
Dave Airlie197bbb32012-06-27 08:35:54 +01004081 return;
4082
Alex Deucher492d2b62012-10-25 16:06:59 -04004083 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher3691fee2012-10-08 17:46:27 -04004084 if (speed_cntl & LC_CURRENT_DATA_RATE) {
4085 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4086 return;
4087 }
4088
Dave Airlie197bbb32012-06-27 08:35:54 +01004089 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4090
Alex Deucher9e46a482011-01-06 18:49:35 -05004091 /* 55 nm r6xx asics */
4092 if ((rdev->family == CHIP_RV670) ||
4093 (rdev->family == CHIP_RV620) ||
4094 (rdev->family == CHIP_RV635)) {
4095 /* advertise upconfig capability */
Alex Deucher492d2b62012-10-25 16:06:59 -04004096 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004097 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004098 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4099 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004100 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
4101 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
4102 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
4103 LC_RECONFIG_ARC_MISSING_ESCAPE);
4104 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004105 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004106 } else {
4107 link_width_cntl |= LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004108 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004109 }
4110 }
4111
Alex Deucher492d2b62012-10-25 16:06:59 -04004112 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004113 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
4114 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
4115
4116 /* 55 nm r6xx asics */
4117 if ((rdev->family == CHIP_RV670) ||
4118 (rdev->family == CHIP_RV620) ||
4119 (rdev->family == CHIP_RV635)) {
4120 WREG32(MM_CFGREGS_CNTL, 0x8);
4121 link_cntl2 = RREG32(0x4088);
4122 WREG32(MM_CFGREGS_CNTL, 0);
4123 /* not supported yet */
4124 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
4125 return;
4126 }
4127
4128 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
4129 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
4130 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
4131 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
4132 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
Alex Deucher492d2b62012-10-25 16:06:59 -04004133 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004134
4135 tmp = RREG32(0x541c);
4136 WREG32(0x541c, tmp | 0x8);
4137 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
4138 link_cntl2 = RREG16(0x4088);
4139 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
4140 link_cntl2 |= 0x2;
4141 WREG16(0x4088, link_cntl2);
4142 WREG32(MM_CFGREGS_CNTL, 0);
4143
4144 if ((rdev->family == CHIP_RV670) ||
4145 (rdev->family == CHIP_RV620) ||
4146 (rdev->family == CHIP_RV635)) {
Alex Deucher492d2b62012-10-25 16:06:59 -04004147 training_cntl = RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004148 training_cntl &= ~LC_POINT_7_PLUS_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004149 WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL, training_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004150 } else {
Alex Deucher492d2b62012-10-25 16:06:59 -04004151 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004152 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004153 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004154 }
4155
Alex Deucher492d2b62012-10-25 16:06:59 -04004156 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004157 speed_cntl |= LC_GEN2_EN_STRAP;
Alex Deucher492d2b62012-10-25 16:06:59 -04004158 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004159
4160 } else {
Alex Deucher492d2b62012-10-25 16:06:59 -04004161 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004162 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4163 if (1)
4164 link_width_cntl |= LC_UPCONFIGURE_DIS;
4165 else
4166 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004167 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004168 }
4169}
Marek Olšák6759a0a2012-08-09 16:34:17 +02004170
4171/**
Alex Deucherd0418892013-01-24 10:35:23 -05004172 * r600_get_gpu_clock_counter - return GPU clock counter snapshot
Marek Olšák6759a0a2012-08-09 16:34:17 +02004173 *
4174 * @rdev: radeon_device pointer
4175 *
4176 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4177 * Returns the 64 bit clock counter snapshot.
4178 */
Alex Deucherd0418892013-01-24 10:35:23 -05004179uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev)
Marek Olšák6759a0a2012-08-09 16:34:17 +02004180{
4181 uint64_t clock;
4182
4183 mutex_lock(&rdev->gpu_clock_mutex);
4184 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
4185 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
4186 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
4187 mutex_unlock(&rdev->gpu_clock_mutex);
4188 return clock;
4189}