blob: 15d58292677a42021be6d047e1a4b31484c1525b [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Jerome Glisse3ce0a232009-09-08 10:10:24 +100029#include <linux/seq_file.h>
30#include <linux/firmware.h>
31#include <linux/platform_device.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020032#include "drmP.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100033#include "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"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040
Jerome Glisse3ce0a232009-09-08 10:10:24 +100041#define PFP_UCODE_SIZE 576
42#define PM4_UCODE_SIZE 1792
Alex Deucherd8f60cf2009-12-01 13:43:46 -050043#define RLC_UCODE_SIZE 768
Jerome Glisse3ce0a232009-09-08 10:10:24 +100044#define R700_PFP_UCODE_SIZE 848
45#define R700_PM4_UCODE_SIZE 1360
Alex Deucherd8f60cf2009-12-01 13:43:46 -050046#define R700_RLC_UCODE_SIZE 1024
Alex Deucherfe251e22010-03-24 13:36:43 -040047#define EVERGREEN_PFP_UCODE_SIZE 1120
48#define EVERGREEN_PM4_UCODE_SIZE 1376
Alex Deucher45f9a392010-03-24 13:55:51 -040049#define EVERGREEN_RLC_UCODE_SIZE 768
Alex Deucher12727802011-03-02 20:07:32 -050050#define CAYMAN_RLC_UCODE_SIZE 1024
Jerome Glisse3ce0a232009-09-08 10:10:24 +100051
52/* Firmware Names */
53MODULE_FIRMWARE("radeon/R600_pfp.bin");
54MODULE_FIRMWARE("radeon/R600_me.bin");
55MODULE_FIRMWARE("radeon/RV610_pfp.bin");
56MODULE_FIRMWARE("radeon/RV610_me.bin");
57MODULE_FIRMWARE("radeon/RV630_pfp.bin");
58MODULE_FIRMWARE("radeon/RV630_me.bin");
59MODULE_FIRMWARE("radeon/RV620_pfp.bin");
60MODULE_FIRMWARE("radeon/RV620_me.bin");
61MODULE_FIRMWARE("radeon/RV635_pfp.bin");
62MODULE_FIRMWARE("radeon/RV635_me.bin");
63MODULE_FIRMWARE("radeon/RV670_pfp.bin");
64MODULE_FIRMWARE("radeon/RV670_me.bin");
65MODULE_FIRMWARE("radeon/RS780_pfp.bin");
66MODULE_FIRMWARE("radeon/RS780_me.bin");
67MODULE_FIRMWARE("radeon/RV770_pfp.bin");
68MODULE_FIRMWARE("radeon/RV770_me.bin");
69MODULE_FIRMWARE("radeon/RV730_pfp.bin");
70MODULE_FIRMWARE("radeon/RV730_me.bin");
71MODULE_FIRMWARE("radeon/RV710_pfp.bin");
72MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050073MODULE_FIRMWARE("radeon/R600_rlc.bin");
74MODULE_FIRMWARE("radeon/R700_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040075MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
76MODULE_FIRMWARE("radeon/CEDAR_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040077MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040078MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
79MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040080MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040081MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
82MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040083MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
Dave Airliea7433742010-04-09 15:31:09 +100084MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040085MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040086MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
Alex Deucher439bd6c2010-11-22 17:56:31 -050087MODULE_FIRMWARE("radeon/PALM_pfp.bin");
88MODULE_FIRMWARE("radeon/PALM_me.bin");
89MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100090
91int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020092
Jerome Glisse1a029b72009-10-06 19:04:30 +020093/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020094int r600_mc_wait_for_idle(struct radeon_device *rdev);
95void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100096void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -040097void r600_irq_disable(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -050098static void r600_pcie_gen2_enable(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020099
Alex Deucher21a81222010-07-02 12:58:16 -0400100/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500101int rv6xx_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400102{
103 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
104 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -0500105 int actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -0400106
Alex Deucher20d391d2011-02-01 16:12:34 -0500107 if (temp & 0x100)
108 actual_temp -= 256;
109
110 return actual_temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400111}
112
Alex Deucherce8f5372010-05-07 15:10:16 -0400113void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400114{
115 int i;
116
Alex Deucherce8f5372010-05-07 15:10:16 -0400117 rdev->pm.dynpm_can_upclock = true;
118 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400119
120 /* power state array is low to high, default is first */
121 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
122 int min_power_state_index = 0;
123
124 if (rdev->pm.num_power_states > 2)
125 min_power_state_index = 1;
126
Alex Deucherce8f5372010-05-07 15:10:16 -0400127 switch (rdev->pm.dynpm_planned_action) {
128 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400129 rdev->pm.requested_power_state_index = min_power_state_index;
130 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400131 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400132 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400133 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400134 if (rdev->pm.current_power_state_index == min_power_state_index) {
135 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400136 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400137 } else {
138 if (rdev->pm.active_crtc_count > 1) {
139 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400140 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400141 continue;
142 else if (i >= rdev->pm.current_power_state_index) {
143 rdev->pm.requested_power_state_index =
144 rdev->pm.current_power_state_index;
145 break;
146 } else {
147 rdev->pm.requested_power_state_index = i;
148 break;
149 }
150 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400151 } else {
152 if (rdev->pm.current_power_state_index == 0)
153 rdev->pm.requested_power_state_index =
154 rdev->pm.num_power_states - 1;
155 else
156 rdev->pm.requested_power_state_index =
157 rdev->pm.current_power_state_index - 1;
158 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400159 }
160 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400161 /* don't use the power state if crtcs are active and no display flag is set */
162 if ((rdev->pm.active_crtc_count > 0) &&
163 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
164 clock_info[rdev->pm.requested_clock_mode_index].flags &
165 RADEON_PM_MODE_NO_DISPLAY)) {
166 rdev->pm.requested_power_state_index++;
167 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400168 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400169 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400170 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
171 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400172 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400173 } else {
174 if (rdev->pm.active_crtc_count > 1) {
175 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400176 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400177 continue;
178 else if (i <= rdev->pm.current_power_state_index) {
179 rdev->pm.requested_power_state_index =
180 rdev->pm.current_power_state_index;
181 break;
182 } else {
183 rdev->pm.requested_power_state_index = i;
184 break;
185 }
186 }
187 } else
188 rdev->pm.requested_power_state_index =
189 rdev->pm.current_power_state_index + 1;
190 }
191 rdev->pm.requested_clock_mode_index = 0;
192 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400193 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400194 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
195 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400196 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400197 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400198 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400199 default:
200 DRM_ERROR("Requested mode for not defined action\n");
201 return;
202 }
203 } else {
204 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
205 /* for now just select the first power state and switch between clock modes */
206 /* power state array is low to high, default is first (0) */
207 if (rdev->pm.active_crtc_count > 1) {
208 rdev->pm.requested_power_state_index = -1;
209 /* start at 1 as we don't want the default mode */
210 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400211 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400212 continue;
213 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
214 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
215 rdev->pm.requested_power_state_index = i;
216 break;
217 }
218 }
219 /* if nothing selected, grab the default state. */
220 if (rdev->pm.requested_power_state_index == -1)
221 rdev->pm.requested_power_state_index = 0;
222 } else
223 rdev->pm.requested_power_state_index = 1;
224
Alex Deucherce8f5372010-05-07 15:10:16 -0400225 switch (rdev->pm.dynpm_planned_action) {
226 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400227 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400228 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400229 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400230 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400231 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
232 if (rdev->pm.current_clock_mode_index == 0) {
233 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400234 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400235 } else
236 rdev->pm.requested_clock_mode_index =
237 rdev->pm.current_clock_mode_index - 1;
238 } else {
239 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400240 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400241 }
Alex Deucherd7311172010-05-03 01:13:14 -0400242 /* don't use the power state if crtcs are active and no display flag is set */
243 if ((rdev->pm.active_crtc_count > 0) &&
244 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
245 clock_info[rdev->pm.requested_clock_mode_index].flags &
246 RADEON_PM_MODE_NO_DISPLAY)) {
247 rdev->pm.requested_clock_mode_index++;
248 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400249 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400250 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400251 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
252 if (rdev->pm.current_clock_mode_index ==
253 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
254 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400255 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400256 } else
257 rdev->pm.requested_clock_mode_index =
258 rdev->pm.current_clock_mode_index + 1;
259 } else {
260 rdev->pm.requested_clock_mode_index =
261 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400262 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400263 }
264 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400265 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400266 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
267 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400268 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400269 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400270 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400271 default:
272 DRM_ERROR("Requested mode for not defined action\n");
273 return;
274 }
275 }
276
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000277 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400278 rdev->pm.power_state[rdev->pm.requested_power_state_index].
279 clock_info[rdev->pm.requested_clock_mode_index].sclk,
280 rdev->pm.power_state[rdev->pm.requested_power_state_index].
281 clock_info[rdev->pm.requested_clock_mode_index].mclk,
282 rdev->pm.power_state[rdev->pm.requested_power_state_index].
283 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400284}
285
Alex Deucherce8f5372010-05-07 15:10:16 -0400286static int r600_pm_get_type_index(struct radeon_device *rdev,
287 enum radeon_pm_state_type ps_type,
288 int instance)
Alex Deucherbae6b5622010-04-22 13:38:05 -0400289{
Alex Deucherce8f5372010-05-07 15:10:16 -0400290 int i;
291 int found_instance = -1;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400292
Alex Deucherce8f5372010-05-07 15:10:16 -0400293 for (i = 0; i < rdev->pm.num_power_states; i++) {
294 if (rdev->pm.power_state[i].type == ps_type) {
295 found_instance++;
296 if (found_instance == instance)
297 return i;
Alex Deuchera4248162010-04-24 14:50:23 -0400298 }
Alex Deucherce8f5372010-05-07 15:10:16 -0400299 }
300 /* return default if no match */
301 return rdev->pm.default_power_state_index;
302}
Alex Deucherbae6b5622010-04-22 13:38:05 -0400303
Alex Deucherce8f5372010-05-07 15:10:16 -0400304void rs780_pm_init_profile(struct radeon_device *rdev)
305{
306 if (rdev->pm.num_power_states == 2) {
307 /* default */
308 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
309 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
310 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
311 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
312 /* low sh */
313 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
314 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
315 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
316 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400317 /* mid sh */
318 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
319 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
320 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
321 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400322 /* high sh */
323 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
325 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
326 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
327 /* low mh */
328 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
330 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
331 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400332 /* mid mh */
333 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
334 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
335 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
336 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400337 /* high mh */
338 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
339 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
340 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
341 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
342 } else if (rdev->pm.num_power_states == 3) {
343 /* default */
344 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
345 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
346 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
347 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
348 /* low sh */
349 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
350 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
351 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
352 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400353 /* mid sh */
354 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
355 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
356 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
357 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400358 /* high sh */
359 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
360 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
361 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
362 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
363 /* low mh */
364 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
365 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
366 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
367 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400368 /* mid mh */
369 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
370 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
371 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
372 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400373 /* high mh */
374 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
375 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
376 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
377 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
378 } else {
379 /* default */
380 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
381 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
382 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
383 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
384 /* low sh */
385 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
386 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
387 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
388 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400389 /* mid sh */
390 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
391 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
392 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
393 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400394 /* high sh */
395 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
396 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
397 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
398 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
399 /* low mh */
400 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
401 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
402 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
403 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400404 /* mid mh */
405 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
406 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
407 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
408 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400409 /* high mh */
410 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
411 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
412 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
413 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
414 }
415}
416
417void r600_pm_init_profile(struct radeon_device *rdev)
418{
419 if (rdev->family == CHIP_R600) {
420 /* XXX */
421 /* default */
422 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
423 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
424 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400425 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400426 /* low sh */
427 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
428 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
429 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400430 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400431 /* mid sh */
432 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
433 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
435 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400436 /* high sh */
437 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
438 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400440 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400441 /* low mh */
442 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
443 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400445 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400446 /* mid mh */
447 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
448 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
449 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
450 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400451 /* high mh */
452 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
453 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
454 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400455 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400456 } else {
457 if (rdev->pm.num_power_states < 4) {
458 /* default */
459 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
460 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
461 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
462 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
463 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400464 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
465 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
466 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400467 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
468 /* mid sh */
469 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
470 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
471 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
472 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400473 /* high sh */
474 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
475 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
476 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
477 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
478 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400479 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
480 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400481 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400482 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
483 /* low mh */
484 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
485 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
486 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
487 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400488 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400489 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
490 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
491 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
492 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
493 } else {
494 /* default */
495 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
496 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
497 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
498 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
499 /* low sh */
500 if (rdev->flags & RADEON_IS_MOBILITY) {
501 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
502 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
503 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
504 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
505 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400506 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400507 } else {
508 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
509 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
510 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
511 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
512 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400513 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
514 }
515 /* mid sh */
516 if (rdev->flags & RADEON_IS_MOBILITY) {
517 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx =
518 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
519 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx =
520 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
521 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
522 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
523 } else {
524 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx =
525 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
526 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx =
527 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
528 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
529 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400530 }
531 /* high sh */
532 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx =
533 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
534 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx =
535 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
536 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
537 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
538 /* low mh */
539 if (rdev->flags & RADEON_IS_MOBILITY) {
540 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
541 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
542 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
543 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
544 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400545 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400546 } else {
547 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
548 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
549 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
550 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
551 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400552 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
553 }
554 /* mid mh */
555 if (rdev->flags & RADEON_IS_MOBILITY) {
556 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx =
557 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
558 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx =
559 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
560 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
561 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
562 } else {
563 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx =
564 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
565 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx =
566 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
567 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
568 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400569 }
570 /* high mh */
571 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx =
572 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
573 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx =
574 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
Alex Deucherce8f5372010-05-07 15:10:16 -0400575 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
576 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
577 }
578 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400579}
580
Alex Deucher49e02b72010-04-23 17:57:27 -0400581void r600_pm_misc(struct radeon_device *rdev)
582{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400583 int req_ps_idx = rdev->pm.requested_power_state_index;
584 int req_cm_idx = rdev->pm.requested_clock_mode_index;
585 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
586 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400587
Alex Deucher4d601732010-06-07 18:15:18 -0400588 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
589 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400590 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400591 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000592 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400593 }
594 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400595}
596
Alex Deucherdef9ba92010-04-22 12:39:58 -0400597bool r600_gui_idle(struct radeon_device *rdev)
598{
599 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
600 return false;
601 else
602 return true;
603}
604
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500605/* hpd for digital panel detect/disconnect */
606bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
607{
608 bool connected = false;
609
610 if (ASIC_IS_DCE3(rdev)) {
611 switch (hpd) {
612 case RADEON_HPD_1:
613 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
614 connected = true;
615 break;
616 case RADEON_HPD_2:
617 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
618 connected = true;
619 break;
620 case RADEON_HPD_3:
621 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
622 connected = true;
623 break;
624 case RADEON_HPD_4:
625 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
626 connected = true;
627 break;
628 /* DCE 3.2 */
629 case RADEON_HPD_5:
630 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
631 connected = true;
632 break;
633 case RADEON_HPD_6:
634 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
635 connected = true;
636 break;
637 default:
638 break;
639 }
640 } else {
641 switch (hpd) {
642 case RADEON_HPD_1:
643 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
644 connected = true;
645 break;
646 case RADEON_HPD_2:
647 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
648 connected = true;
649 break;
650 case RADEON_HPD_3:
651 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
652 connected = true;
653 break;
654 default:
655 break;
656 }
657 }
658 return connected;
659}
660
661void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500662 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500663{
664 u32 tmp;
665 bool connected = r600_hpd_sense(rdev, hpd);
666
667 if (ASIC_IS_DCE3(rdev)) {
668 switch (hpd) {
669 case RADEON_HPD_1:
670 tmp = RREG32(DC_HPD1_INT_CONTROL);
671 if (connected)
672 tmp &= ~DC_HPDx_INT_POLARITY;
673 else
674 tmp |= DC_HPDx_INT_POLARITY;
675 WREG32(DC_HPD1_INT_CONTROL, tmp);
676 break;
677 case RADEON_HPD_2:
678 tmp = RREG32(DC_HPD2_INT_CONTROL);
679 if (connected)
680 tmp &= ~DC_HPDx_INT_POLARITY;
681 else
682 tmp |= DC_HPDx_INT_POLARITY;
683 WREG32(DC_HPD2_INT_CONTROL, tmp);
684 break;
685 case RADEON_HPD_3:
686 tmp = RREG32(DC_HPD3_INT_CONTROL);
687 if (connected)
688 tmp &= ~DC_HPDx_INT_POLARITY;
689 else
690 tmp |= DC_HPDx_INT_POLARITY;
691 WREG32(DC_HPD3_INT_CONTROL, tmp);
692 break;
693 case RADEON_HPD_4:
694 tmp = RREG32(DC_HPD4_INT_CONTROL);
695 if (connected)
696 tmp &= ~DC_HPDx_INT_POLARITY;
697 else
698 tmp |= DC_HPDx_INT_POLARITY;
699 WREG32(DC_HPD4_INT_CONTROL, tmp);
700 break;
701 case RADEON_HPD_5:
702 tmp = RREG32(DC_HPD5_INT_CONTROL);
703 if (connected)
704 tmp &= ~DC_HPDx_INT_POLARITY;
705 else
706 tmp |= DC_HPDx_INT_POLARITY;
707 WREG32(DC_HPD5_INT_CONTROL, tmp);
708 break;
709 /* DCE 3.2 */
710 case RADEON_HPD_6:
711 tmp = RREG32(DC_HPD6_INT_CONTROL);
712 if (connected)
713 tmp &= ~DC_HPDx_INT_POLARITY;
714 else
715 tmp |= DC_HPDx_INT_POLARITY;
716 WREG32(DC_HPD6_INT_CONTROL, tmp);
717 break;
718 default:
719 break;
720 }
721 } else {
722 switch (hpd) {
723 case RADEON_HPD_1:
724 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
725 if (connected)
726 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
727 else
728 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
729 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
730 break;
731 case RADEON_HPD_2:
732 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
733 if (connected)
734 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
735 else
736 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
737 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
738 break;
739 case RADEON_HPD_3:
740 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
741 if (connected)
742 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
743 else
744 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
745 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
746 break;
747 default:
748 break;
749 }
750 }
751}
752
753void r600_hpd_init(struct radeon_device *rdev)
754{
755 struct drm_device *dev = rdev->ddev;
756 struct drm_connector *connector;
757
758 if (ASIC_IS_DCE3(rdev)) {
759 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
760 if (ASIC_IS_DCE32(rdev))
761 tmp |= DC_HPDx_EN;
762
763 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
764 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
765 switch (radeon_connector->hpd.hpd) {
766 case RADEON_HPD_1:
767 WREG32(DC_HPD1_CONTROL, tmp);
768 rdev->irq.hpd[0] = true;
769 break;
770 case RADEON_HPD_2:
771 WREG32(DC_HPD2_CONTROL, tmp);
772 rdev->irq.hpd[1] = true;
773 break;
774 case RADEON_HPD_3:
775 WREG32(DC_HPD3_CONTROL, tmp);
776 rdev->irq.hpd[2] = true;
777 break;
778 case RADEON_HPD_4:
779 WREG32(DC_HPD4_CONTROL, tmp);
780 rdev->irq.hpd[3] = true;
781 break;
782 /* DCE 3.2 */
783 case RADEON_HPD_5:
784 WREG32(DC_HPD5_CONTROL, tmp);
785 rdev->irq.hpd[4] = true;
786 break;
787 case RADEON_HPD_6:
788 WREG32(DC_HPD6_CONTROL, tmp);
789 rdev->irq.hpd[5] = true;
790 break;
791 default:
792 break;
793 }
794 }
795 } else {
796 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
797 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
798 switch (radeon_connector->hpd.hpd) {
799 case RADEON_HPD_1:
800 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
801 rdev->irq.hpd[0] = true;
802 break;
803 case RADEON_HPD_2:
804 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
805 rdev->irq.hpd[1] = true;
806 break;
807 case RADEON_HPD_3:
808 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
809 rdev->irq.hpd[2] = true;
810 break;
811 default:
812 break;
813 }
814 }
815 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100816 if (rdev->irq.installed)
817 r600_irq_set(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500818}
819
820void r600_hpd_fini(struct radeon_device *rdev)
821{
822 struct drm_device *dev = rdev->ddev;
823 struct drm_connector *connector;
824
825 if (ASIC_IS_DCE3(rdev)) {
826 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
827 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
828 switch (radeon_connector->hpd.hpd) {
829 case RADEON_HPD_1:
830 WREG32(DC_HPD1_CONTROL, 0);
831 rdev->irq.hpd[0] = false;
832 break;
833 case RADEON_HPD_2:
834 WREG32(DC_HPD2_CONTROL, 0);
835 rdev->irq.hpd[1] = false;
836 break;
837 case RADEON_HPD_3:
838 WREG32(DC_HPD3_CONTROL, 0);
839 rdev->irq.hpd[2] = false;
840 break;
841 case RADEON_HPD_4:
842 WREG32(DC_HPD4_CONTROL, 0);
843 rdev->irq.hpd[3] = false;
844 break;
845 /* DCE 3.2 */
846 case RADEON_HPD_5:
847 WREG32(DC_HPD5_CONTROL, 0);
848 rdev->irq.hpd[4] = false;
849 break;
850 case RADEON_HPD_6:
851 WREG32(DC_HPD6_CONTROL, 0);
852 rdev->irq.hpd[5] = false;
853 break;
854 default:
855 break;
856 }
857 }
858 } else {
859 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
860 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
861 switch (radeon_connector->hpd.hpd) {
862 case RADEON_HPD_1:
863 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
864 rdev->irq.hpd[0] = false;
865 break;
866 case RADEON_HPD_2:
867 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
868 rdev->irq.hpd[1] = false;
869 break;
870 case RADEON_HPD_3:
871 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
872 rdev->irq.hpd[2] = false;
873 break;
874 default:
875 break;
876 }
877 }
878 }
879}
880
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200881/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000882 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200883 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000884void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200885{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000886 unsigned i;
887 u32 tmp;
888
Dave Airlie2e98f102010-02-15 15:54:45 +1000889 /* flush hdp cache so updates hit vram */
Alex Deucherf3886f82010-12-08 10:05:34 -0500890 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
891 !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher812d0462010-07-26 18:51:53 -0400892 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
893 u32 tmp;
894
895 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
896 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
Alex Deucherf3886f82010-12-08 10:05:34 -0500897 * This seems to cause problems on some AGP cards. Just use the old
898 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -0400899 */
900 WREG32(HDP_DEBUG1, 0);
901 tmp = readl((void __iomem *)ptr);
902 } else
903 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +1000904
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000905 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
906 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
907 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
908 for (i = 0; i < rdev->usec_timeout; i++) {
909 /* read MC_STATUS */
910 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
911 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
912 if (tmp == 2) {
913 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
914 return;
915 }
916 if (tmp) {
917 return;
918 }
919 udelay(1);
920 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921}
922
Jerome Glisse4aac0472009-09-14 18:29:49 +0200923int r600_pcie_gart_init(struct radeon_device *rdev)
924{
925 int r;
926
927 if (rdev->gart.table.vram.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +0000928 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +0200929 return 0;
930 }
931 /* Initialize common gart structure */
932 r = radeon_gart_init(rdev);
933 if (r)
934 return r;
935 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
936 return radeon_gart_table_vram_alloc(rdev);
937}
938
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000939int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200940{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000941 u32 tmp;
942 int r, i;
943
Jerome Glisse4aac0472009-09-14 18:29:49 +0200944 if (rdev->gart.table.vram.robj == NULL) {
945 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
946 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000947 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200948 r = radeon_gart_table_vram_pin(rdev);
949 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000950 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000951 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000952
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000953 /* Setup L2 cache */
954 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
955 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
956 EFFECTIVE_L2_QUEUE_SIZE(7));
957 WREG32(VM_L2_CNTL2, 0);
958 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
959 /* Setup TLB control */
960 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
961 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
962 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
963 ENABLE_WAIT_L2_QUERY;
964 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
965 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
966 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
967 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
968 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
969 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
970 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
971 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
972 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
973 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
974 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
975 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
976 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
977 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
978 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200979 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000980 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
981 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
982 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
983 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
984 (u32)(rdev->dummy_page.addr >> 12));
985 for (i = 1; i < 7; i++)
986 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
987
988 r600_pcie_gart_tlb_flush(rdev);
989 rdev->gart.ready = true;
990 return 0;
991}
992
993void r600_pcie_gart_disable(struct radeon_device *rdev)
994{
995 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100996 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000997
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000998 /* Disable all tables */
999 for (i = 0; i < 7; i++)
1000 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1001
1002 /* Disable L2 cache */
1003 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
1004 EFFECTIVE_L2_QUEUE_SIZE(7));
1005 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1006 /* Setup L1 TLB control */
1007 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1008 ENABLE_WAIT_L2_QUERY;
1009 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1010 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1011 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1012 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1013 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1014 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1015 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1016 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1017 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
1018 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
1019 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1020 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1021 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
1022 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001023 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001024 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
1025 if (likely(r == 0)) {
1026 radeon_bo_kunmap(rdev->gart.table.vram.robj);
1027 radeon_bo_unpin(rdev->gart.table.vram.robj);
1028 radeon_bo_unreserve(rdev->gart.table.vram.robj);
1029 }
Jerome Glisse4aac0472009-09-14 18:29:49 +02001030 }
1031}
1032
1033void r600_pcie_gart_fini(struct radeon_device *rdev)
1034{
Jerome Glissef9274562010-03-17 14:44:29 +00001035 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001036 r600_pcie_gart_disable(rdev);
1037 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001038}
1039
Jerome Glisse1a029b72009-10-06 19:04:30 +02001040void r600_agp_enable(struct radeon_device *rdev)
1041{
1042 u32 tmp;
1043 int i;
1044
1045 /* Setup L2 cache */
1046 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1047 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1048 EFFECTIVE_L2_QUEUE_SIZE(7));
1049 WREG32(VM_L2_CNTL2, 0);
1050 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1051 /* Setup TLB control */
1052 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1053 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1054 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1055 ENABLE_WAIT_L2_QUERY;
1056 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1057 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1058 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1059 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1060 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1061 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1062 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1063 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1064 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1065 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1066 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1067 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1068 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1069 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1070 for (i = 0; i < 7; i++)
1071 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1072}
1073
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001074int r600_mc_wait_for_idle(struct radeon_device *rdev)
1075{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001076 unsigned i;
1077 u32 tmp;
1078
1079 for (i = 0; i < rdev->usec_timeout; i++) {
1080 /* read MC_STATUS */
1081 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1082 if (!tmp)
1083 return 0;
1084 udelay(1);
1085 }
1086 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001087}
1088
Jerome Glissea3c19452009-10-01 18:02:13 +02001089static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001090{
Jerome Glissea3c19452009-10-01 18:02:13 +02001091 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001092 u32 tmp;
1093 int i, j;
1094
1095 /* Initialize HDP */
1096 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1097 WREG32((0x2c14 + j), 0x00000000);
1098 WREG32((0x2c18 + j), 0x00000000);
1099 WREG32((0x2c1c + j), 0x00000000);
1100 WREG32((0x2c20 + j), 0x00000000);
1101 WREG32((0x2c24 + j), 0x00000000);
1102 }
1103 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1104
Jerome Glissea3c19452009-10-01 18:02:13 +02001105 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001106 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001107 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001108 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001109 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001110 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001111 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001112 if (rdev->flags & RADEON_IS_AGP) {
1113 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1114 /* VRAM before AGP */
1115 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1116 rdev->mc.vram_start >> 12);
1117 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1118 rdev->mc.gtt_end >> 12);
1119 } else {
1120 /* VRAM after AGP */
1121 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1122 rdev->mc.gtt_start >> 12);
1123 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1124 rdev->mc.vram_end >> 12);
1125 }
1126 } else {
1127 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1128 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1129 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001130 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001131 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001132 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1133 WREG32(MC_VM_FB_LOCATION, tmp);
1134 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1135 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001136 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001137 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001138 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1139 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001140 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1141 } else {
1142 WREG32(MC_VM_AGP_BASE, 0);
1143 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1144 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1145 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001146 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001147 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001148 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001149 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001150 /* we need to own VRAM, so turn off the VGA renderer here
1151 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001152 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001153}
1154
Jerome Glissed594e462010-02-17 21:54:29 +00001155/**
1156 * r600_vram_gtt_location - try to find VRAM & GTT location
1157 * @rdev: radeon device structure holding all necessary informations
1158 * @mc: memory controller structure holding memory informations
1159 *
1160 * Function will place try to place VRAM at same place as in CPU (PCI)
1161 * address space as some GPU seems to have issue when we reprogram at
1162 * different address space.
1163 *
1164 * If there is not enough space to fit the unvisible VRAM after the
1165 * aperture then we limit the VRAM size to the aperture.
1166 *
1167 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1168 * them to be in one from GPU point of view so that we can program GPU to
1169 * catch access outside them (weird GPU policy see ??).
1170 *
1171 * This function will never fails, worst case are limiting VRAM or GTT.
1172 *
1173 * Note: GTT start, end, size should be initialized before calling this
1174 * function on AGP platform.
1175 */
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001176static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
Jerome Glissed594e462010-02-17 21:54:29 +00001177{
1178 u64 size_bf, size_af;
1179
1180 if (mc->mc_vram_size > 0xE0000000) {
1181 /* leave room for at least 512M GTT */
1182 dev_warn(rdev->dev, "limiting VRAM\n");
1183 mc->real_vram_size = 0xE0000000;
1184 mc->mc_vram_size = 0xE0000000;
1185 }
1186 if (rdev->flags & RADEON_IS_AGP) {
1187 size_bf = mc->gtt_start;
1188 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
1189 if (size_bf > size_af) {
1190 if (mc->mc_vram_size > size_bf) {
1191 dev_warn(rdev->dev, "limiting VRAM\n");
1192 mc->real_vram_size = size_bf;
1193 mc->mc_vram_size = size_bf;
1194 }
1195 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1196 } else {
1197 if (mc->mc_vram_size > size_af) {
1198 dev_warn(rdev->dev, "limiting VRAM\n");
1199 mc->real_vram_size = size_af;
1200 mc->mc_vram_size = size_af;
1201 }
1202 mc->vram_start = mc->gtt_end;
1203 }
1204 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1205 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1206 mc->mc_vram_size >> 20, mc->vram_start,
1207 mc->vram_end, mc->real_vram_size >> 20);
1208 } else {
1209 u64 base = 0;
Alex Deucher8961d522010-12-03 14:37:22 -05001210 if (rdev->flags & RADEON_IS_IGP) {
1211 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1212 base <<= 24;
1213 }
Jerome Glissed594e462010-02-17 21:54:29 +00001214 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001215 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001216 radeon_gtt_location(rdev, mc);
1217 }
1218}
1219
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001220int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001221{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001222 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001223 int chansize, numchan;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001224
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001225 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001226 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001227 tmp = RREG32(RAMCFG);
1228 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001229 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001230 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001231 chansize = 64;
1232 } else {
1233 chansize = 32;
1234 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001235 tmp = RREG32(CHMAP);
1236 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1237 case 0:
1238 default:
1239 numchan = 1;
1240 break;
1241 case 1:
1242 numchan = 2;
1243 break;
1244 case 2:
1245 numchan = 4;
1246 break;
1247 case 3:
1248 numchan = 8;
1249 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001250 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001251 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001252 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001253 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1254 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001255 /* Setup GPU memory space */
1256 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1257 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001258 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001259 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001260
Alex Deucherf8920342010-06-30 12:02:03 -04001261 if (rdev->flags & RADEON_IS_IGP) {
1262 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001263 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Alex Deucherf8920342010-06-30 12:02:03 -04001264 }
Alex Deucherf47299c2010-03-16 20:54:38 -04001265 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001266 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001267}
1268
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001269/* We doesn't check that the GPU really needs a reset we simply do the
1270 * reset, it's up to the caller to determine if the GPU needs one. We
1271 * might add an helper function to check that.
1272 */
1273int r600_gpu_soft_reset(struct radeon_device *rdev)
1274{
Jerome Glissea3c19452009-10-01 18:02:13 +02001275 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001276 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1277 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1278 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1279 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1280 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1281 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1282 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1283 S_008010_GUI_ACTIVE(1);
1284 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1285 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1286 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1287 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1288 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1289 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1290 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1291 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
Jerome Glissea3c19452009-10-01 18:02:13 +02001292 u32 tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001293
Alex Deucher8d96fe92011-01-21 15:38:22 +00001294 if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
1295 return 0;
1296
Jerome Glisse1a029b72009-10-06 19:04:30 +02001297 dev_info(rdev->dev, "GPU softreset \n");
1298 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1299 RREG32(R_008010_GRBM_STATUS));
1300 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
Jerome Glissea3c19452009-10-01 18:02:13 +02001301 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse1a029b72009-10-06 19:04:30 +02001302 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1303 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001304 rv515_mc_stop(rdev, &save);
1305 if (r600_mc_wait_for_idle(rdev)) {
1306 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1307 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001308 /* Disable CP parsing/prefetching */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001309 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001310 /* Check if any of the rendering block is busy and reset it */
1311 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
1312 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001313 tmp = S_008020_SOFT_RESET_CR(1) |
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001314 S_008020_SOFT_RESET_DB(1) |
1315 S_008020_SOFT_RESET_CB(1) |
1316 S_008020_SOFT_RESET_PA(1) |
1317 S_008020_SOFT_RESET_SC(1) |
1318 S_008020_SOFT_RESET_SMX(1) |
1319 S_008020_SOFT_RESET_SPI(1) |
1320 S_008020_SOFT_RESET_SX(1) |
1321 S_008020_SOFT_RESET_SH(1) |
1322 S_008020_SOFT_RESET_TC(1) |
1323 S_008020_SOFT_RESET_TA(1) |
1324 S_008020_SOFT_RESET_VC(1) |
Jerome Glissea3c19452009-10-01 18:02:13 +02001325 S_008020_SOFT_RESET_VGT(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001326 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
Jerome Glissea3c19452009-10-01 18:02:13 +02001327 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001328 RREG32(R_008020_GRBM_SOFT_RESET);
1329 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001330 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001331 }
1332 /* Reset CP (we always reset CP) */
Jerome Glissea3c19452009-10-01 18:02:13 +02001333 tmp = S_008020_SOFT_RESET_CP(1);
1334 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1335 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001336 RREG32(R_008020_GRBM_SOFT_RESET);
1337 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001338 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001339 /* Wait a little for things to settle down */
Jerome Glisse225758d2010-03-09 14:45:10 +00001340 mdelay(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001341 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1342 RREG32(R_008010_GRBM_STATUS));
1343 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1344 RREG32(R_008014_GRBM_STATUS2));
1345 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1346 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001347 rv515_mc_resume(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001348 return 0;
1349}
1350
Jerome Glisse225758d2010-03-09 14:45:10 +00001351bool r600_gpu_is_lockup(struct radeon_device *rdev)
1352{
1353 u32 srbm_status;
1354 u32 grbm_status;
1355 u32 grbm_status2;
Alex Deuchere29ff722010-12-21 16:05:38 -05001356 struct r100_gpu_lockup *lockup;
Jerome Glisse225758d2010-03-09 14:45:10 +00001357 int r;
1358
Alex Deuchere29ff722010-12-21 16:05:38 -05001359 if (rdev->family >= CHIP_RV770)
1360 lockup = &rdev->config.rv770.lockup;
1361 else
1362 lockup = &rdev->config.r600.lockup;
1363
Jerome Glisse225758d2010-03-09 14:45:10 +00001364 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1365 grbm_status = RREG32(R_008010_GRBM_STATUS);
1366 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1367 if (!G_008010_GUI_ACTIVE(grbm_status)) {
Alex Deuchere29ff722010-12-21 16:05:38 -05001368 r100_gpu_lockup_update(lockup, &rdev->cp);
Jerome Glisse225758d2010-03-09 14:45:10 +00001369 return false;
1370 }
1371 /* force CP activities */
1372 r = radeon_ring_lock(rdev, 2);
1373 if (!r) {
1374 /* PACKET2 NOP */
1375 radeon_ring_write(rdev, 0x80000000);
1376 radeon_ring_write(rdev, 0x80000000);
1377 radeon_ring_unlock_commit(rdev);
1378 }
1379 rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
Alex Deuchere29ff722010-12-21 16:05:38 -05001380 return r100_gpu_cp_is_lockup(rdev, lockup, &rdev->cp);
Jerome Glisse225758d2010-03-09 14:45:10 +00001381}
1382
Jerome Glissea2d07b72010-03-09 14:45:11 +00001383int r600_asic_reset(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001384{
1385 return r600_gpu_soft_reset(rdev);
1386}
1387
1388static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
1389 u32 num_backends,
1390 u32 backend_disable_mask)
1391{
1392 u32 backend_map = 0;
1393 u32 enabled_backends_mask;
1394 u32 enabled_backends_count;
1395 u32 cur_pipe;
1396 u32 swizzle_pipe[R6XX_MAX_PIPES];
1397 u32 cur_backend;
1398 u32 i;
1399
1400 if (num_tile_pipes > R6XX_MAX_PIPES)
1401 num_tile_pipes = R6XX_MAX_PIPES;
1402 if (num_tile_pipes < 1)
1403 num_tile_pipes = 1;
1404 if (num_backends > R6XX_MAX_BACKENDS)
1405 num_backends = R6XX_MAX_BACKENDS;
1406 if (num_backends < 1)
1407 num_backends = 1;
1408
1409 enabled_backends_mask = 0;
1410 enabled_backends_count = 0;
1411 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
1412 if (((backend_disable_mask >> i) & 1) == 0) {
1413 enabled_backends_mask |= (1 << i);
1414 ++enabled_backends_count;
1415 }
1416 if (enabled_backends_count == num_backends)
1417 break;
1418 }
1419
1420 if (enabled_backends_count == 0) {
1421 enabled_backends_mask = 1;
1422 enabled_backends_count = 1;
1423 }
1424
1425 if (enabled_backends_count != num_backends)
1426 num_backends = enabled_backends_count;
1427
1428 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
1429 switch (num_tile_pipes) {
1430 case 1:
1431 swizzle_pipe[0] = 0;
1432 break;
1433 case 2:
1434 swizzle_pipe[0] = 0;
1435 swizzle_pipe[1] = 1;
1436 break;
1437 case 3:
1438 swizzle_pipe[0] = 0;
1439 swizzle_pipe[1] = 1;
1440 swizzle_pipe[2] = 2;
1441 break;
1442 case 4:
1443 swizzle_pipe[0] = 0;
1444 swizzle_pipe[1] = 1;
1445 swizzle_pipe[2] = 2;
1446 swizzle_pipe[3] = 3;
1447 break;
1448 case 5:
1449 swizzle_pipe[0] = 0;
1450 swizzle_pipe[1] = 1;
1451 swizzle_pipe[2] = 2;
1452 swizzle_pipe[3] = 3;
1453 swizzle_pipe[4] = 4;
1454 break;
1455 case 6:
1456 swizzle_pipe[0] = 0;
1457 swizzle_pipe[1] = 2;
1458 swizzle_pipe[2] = 4;
1459 swizzle_pipe[3] = 5;
1460 swizzle_pipe[4] = 1;
1461 swizzle_pipe[5] = 3;
1462 break;
1463 case 7:
1464 swizzle_pipe[0] = 0;
1465 swizzle_pipe[1] = 2;
1466 swizzle_pipe[2] = 4;
1467 swizzle_pipe[3] = 6;
1468 swizzle_pipe[4] = 1;
1469 swizzle_pipe[5] = 3;
1470 swizzle_pipe[6] = 5;
1471 break;
1472 case 8:
1473 swizzle_pipe[0] = 0;
1474 swizzle_pipe[1] = 2;
1475 swizzle_pipe[2] = 4;
1476 swizzle_pipe[3] = 6;
1477 swizzle_pipe[4] = 1;
1478 swizzle_pipe[5] = 3;
1479 swizzle_pipe[6] = 5;
1480 swizzle_pipe[7] = 7;
1481 break;
1482 }
1483
1484 cur_backend = 0;
1485 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1486 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1487 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1488
1489 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
1490
1491 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1492 }
1493
1494 return backend_map;
1495}
1496
1497int r600_count_pipe_bits(uint32_t val)
1498{
1499 int i, ret = 0;
1500
1501 for (i = 0; i < 32; i++) {
1502 ret += val & 1;
1503 val >>= 1;
1504 }
1505 return ret;
1506}
1507
1508void r600_gpu_init(struct radeon_device *rdev)
1509{
1510 u32 tiling_config;
1511 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001512 u32 backend_map;
1513 u32 cc_rb_backend_disable;
1514 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001515 u32 tmp;
1516 int i, j;
1517 u32 sq_config;
1518 u32 sq_gpr_resource_mgmt_1 = 0;
1519 u32 sq_gpr_resource_mgmt_2 = 0;
1520 u32 sq_thread_resource_mgmt = 0;
1521 u32 sq_stack_resource_mgmt_1 = 0;
1522 u32 sq_stack_resource_mgmt_2 = 0;
1523
1524 /* FIXME: implement */
1525 switch (rdev->family) {
1526 case CHIP_R600:
1527 rdev->config.r600.max_pipes = 4;
1528 rdev->config.r600.max_tile_pipes = 8;
1529 rdev->config.r600.max_simds = 4;
1530 rdev->config.r600.max_backends = 4;
1531 rdev->config.r600.max_gprs = 256;
1532 rdev->config.r600.max_threads = 192;
1533 rdev->config.r600.max_stack_entries = 256;
1534 rdev->config.r600.max_hw_contexts = 8;
1535 rdev->config.r600.max_gs_threads = 16;
1536 rdev->config.r600.sx_max_export_size = 128;
1537 rdev->config.r600.sx_max_export_pos_size = 16;
1538 rdev->config.r600.sx_max_export_smx_size = 128;
1539 rdev->config.r600.sq_num_cf_insts = 2;
1540 break;
1541 case CHIP_RV630:
1542 case CHIP_RV635:
1543 rdev->config.r600.max_pipes = 2;
1544 rdev->config.r600.max_tile_pipes = 2;
1545 rdev->config.r600.max_simds = 3;
1546 rdev->config.r600.max_backends = 1;
1547 rdev->config.r600.max_gprs = 128;
1548 rdev->config.r600.max_threads = 192;
1549 rdev->config.r600.max_stack_entries = 128;
1550 rdev->config.r600.max_hw_contexts = 8;
1551 rdev->config.r600.max_gs_threads = 4;
1552 rdev->config.r600.sx_max_export_size = 128;
1553 rdev->config.r600.sx_max_export_pos_size = 16;
1554 rdev->config.r600.sx_max_export_smx_size = 128;
1555 rdev->config.r600.sq_num_cf_insts = 2;
1556 break;
1557 case CHIP_RV610:
1558 case CHIP_RV620:
1559 case CHIP_RS780:
1560 case CHIP_RS880:
1561 rdev->config.r600.max_pipes = 1;
1562 rdev->config.r600.max_tile_pipes = 1;
1563 rdev->config.r600.max_simds = 2;
1564 rdev->config.r600.max_backends = 1;
1565 rdev->config.r600.max_gprs = 128;
1566 rdev->config.r600.max_threads = 192;
1567 rdev->config.r600.max_stack_entries = 128;
1568 rdev->config.r600.max_hw_contexts = 4;
1569 rdev->config.r600.max_gs_threads = 4;
1570 rdev->config.r600.sx_max_export_size = 128;
1571 rdev->config.r600.sx_max_export_pos_size = 16;
1572 rdev->config.r600.sx_max_export_smx_size = 128;
1573 rdev->config.r600.sq_num_cf_insts = 1;
1574 break;
1575 case CHIP_RV670:
1576 rdev->config.r600.max_pipes = 4;
1577 rdev->config.r600.max_tile_pipes = 4;
1578 rdev->config.r600.max_simds = 4;
1579 rdev->config.r600.max_backends = 4;
1580 rdev->config.r600.max_gprs = 192;
1581 rdev->config.r600.max_threads = 192;
1582 rdev->config.r600.max_stack_entries = 256;
1583 rdev->config.r600.max_hw_contexts = 8;
1584 rdev->config.r600.max_gs_threads = 16;
1585 rdev->config.r600.sx_max_export_size = 128;
1586 rdev->config.r600.sx_max_export_pos_size = 16;
1587 rdev->config.r600.sx_max_export_smx_size = 128;
1588 rdev->config.r600.sq_num_cf_insts = 2;
1589 break;
1590 default:
1591 break;
1592 }
1593
1594 /* Initialize HDP */
1595 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1596 WREG32((0x2c14 + j), 0x00000000);
1597 WREG32((0x2c18 + j), 0x00000000);
1598 WREG32((0x2c1c + j), 0x00000000);
1599 WREG32((0x2c20 + j), 0x00000000);
1600 WREG32((0x2c24 + j), 0x00000000);
1601 }
1602
1603 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1604
1605 /* Setup tiling */
1606 tiling_config = 0;
1607 ramcfg = RREG32(RAMCFG);
1608 switch (rdev->config.r600.max_tile_pipes) {
1609 case 1:
1610 tiling_config |= PIPE_TILING(0);
1611 break;
1612 case 2:
1613 tiling_config |= PIPE_TILING(1);
1614 break;
1615 case 4:
1616 tiling_config |= PIPE_TILING(2);
1617 break;
1618 case 8:
1619 tiling_config |= PIPE_TILING(3);
1620 break;
1621 default:
1622 break;
1623 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001624 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001625 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001626 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04001627 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
1628 if ((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
1629 rdev->config.r600.tiling_group_size = 512;
1630 else
1631 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001632 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1633 if (tmp > 3) {
1634 tiling_config |= ROW_TILING(3);
1635 tiling_config |= SAMPLE_SPLIT(3);
1636 } else {
1637 tiling_config |= ROW_TILING(tmp);
1638 tiling_config |= SAMPLE_SPLIT(tmp);
1639 }
1640 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001641
1642 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1643 cc_rb_backend_disable |=
1644 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1645
1646 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
1647 cc_gc_shader_pipe_config |=
1648 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1649 cc_gc_shader_pipe_config |=
1650 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1651
1652 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1653 (R6XX_MAX_BACKENDS -
1654 r600_count_pipe_bits((cc_rb_backend_disable &
1655 R6XX_MAX_BACKENDS_MASK) >> 16)),
1656 (cc_rb_backend_disable >> 16));
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001657 rdev->config.r600.tile_config = tiling_config;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001658 tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001659 WREG32(GB_TILING_CONFIG, tiling_config);
1660 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1661 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1662
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001663 /* Setup pipes */
Alex Deucherd03f5d52010-02-19 16:22:31 -05001664 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1665 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -05001666 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001667
Alex Deucherd03f5d52010-02-19 16:22:31 -05001668 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 +10001669 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1670 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1671
1672 /* Setup some CP states */
1673 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1674 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1675
1676 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1677 SYNC_WALKER | SYNC_ALIGNER));
1678 /* Setup various GPU states */
1679 if (rdev->family == CHIP_RV670)
1680 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1681
1682 tmp = RREG32(SX_DEBUG_1);
1683 tmp |= SMX_EVENT_RELEASE;
1684 if ((rdev->family > CHIP_R600))
1685 tmp |= ENABLE_NEW_SMX_ADDRESS;
1686 WREG32(SX_DEBUG_1, tmp);
1687
1688 if (((rdev->family) == CHIP_R600) ||
1689 ((rdev->family) == CHIP_RV630) ||
1690 ((rdev->family) == CHIP_RV610) ||
1691 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001692 ((rdev->family) == CHIP_RS780) ||
1693 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001694 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1695 } else {
1696 WREG32(DB_DEBUG, 0);
1697 }
1698 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1699 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1700
1701 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1702 WREG32(VGT_NUM_INSTANCES, 0);
1703
1704 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1705 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1706
1707 tmp = RREG32(SQ_MS_FIFO_SIZES);
1708 if (((rdev->family) == CHIP_RV610) ||
1709 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001710 ((rdev->family) == CHIP_RS780) ||
1711 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001712 tmp = (CACHE_FIFO_SIZE(0xa) |
1713 FETCH_FIFO_HIWATER(0xa) |
1714 DONE_FIFO_HIWATER(0xe0) |
1715 ALU_UPDATE_FIFO_HIWATER(0x8));
1716 } else if (((rdev->family) == CHIP_R600) ||
1717 ((rdev->family) == CHIP_RV630)) {
1718 tmp &= ~DONE_FIFO_HIWATER(0xff);
1719 tmp |= DONE_FIFO_HIWATER(0x4);
1720 }
1721 WREG32(SQ_MS_FIFO_SIZES, tmp);
1722
1723 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1724 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1725 */
1726 sq_config = RREG32(SQ_CONFIG);
1727 sq_config &= ~(PS_PRIO(3) |
1728 VS_PRIO(3) |
1729 GS_PRIO(3) |
1730 ES_PRIO(3));
1731 sq_config |= (DX9_CONSTS |
1732 VC_ENABLE |
1733 PS_PRIO(0) |
1734 VS_PRIO(1) |
1735 GS_PRIO(2) |
1736 ES_PRIO(3));
1737
1738 if ((rdev->family) == CHIP_R600) {
1739 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1740 NUM_VS_GPRS(124) |
1741 NUM_CLAUSE_TEMP_GPRS(4));
1742 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1743 NUM_ES_GPRS(0));
1744 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1745 NUM_VS_THREADS(48) |
1746 NUM_GS_THREADS(4) |
1747 NUM_ES_THREADS(4));
1748 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1749 NUM_VS_STACK_ENTRIES(128));
1750 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1751 NUM_ES_STACK_ENTRIES(0));
1752 } else if (((rdev->family) == CHIP_RV610) ||
1753 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001754 ((rdev->family) == CHIP_RS780) ||
1755 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001756 /* no vertex cache */
1757 sq_config &= ~VC_ENABLE;
1758
1759 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1760 NUM_VS_GPRS(44) |
1761 NUM_CLAUSE_TEMP_GPRS(2));
1762 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1763 NUM_ES_GPRS(17));
1764 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1765 NUM_VS_THREADS(78) |
1766 NUM_GS_THREADS(4) |
1767 NUM_ES_THREADS(31));
1768 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1769 NUM_VS_STACK_ENTRIES(40));
1770 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1771 NUM_ES_STACK_ENTRIES(16));
1772 } else if (((rdev->family) == CHIP_RV630) ||
1773 ((rdev->family) == CHIP_RV635)) {
1774 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1775 NUM_VS_GPRS(44) |
1776 NUM_CLAUSE_TEMP_GPRS(2));
1777 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1778 NUM_ES_GPRS(18));
1779 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1780 NUM_VS_THREADS(78) |
1781 NUM_GS_THREADS(4) |
1782 NUM_ES_THREADS(31));
1783 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1784 NUM_VS_STACK_ENTRIES(40));
1785 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1786 NUM_ES_STACK_ENTRIES(16));
1787 } else if ((rdev->family) == CHIP_RV670) {
1788 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1789 NUM_VS_GPRS(44) |
1790 NUM_CLAUSE_TEMP_GPRS(2));
1791 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1792 NUM_ES_GPRS(17));
1793 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1794 NUM_VS_THREADS(78) |
1795 NUM_GS_THREADS(4) |
1796 NUM_ES_THREADS(31));
1797 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1798 NUM_VS_STACK_ENTRIES(64));
1799 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1800 NUM_ES_STACK_ENTRIES(64));
1801 }
1802
1803 WREG32(SQ_CONFIG, sq_config);
1804 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1805 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1806 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1807 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1808 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1809
1810 if (((rdev->family) == CHIP_RV610) ||
1811 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001812 ((rdev->family) == CHIP_RS780) ||
1813 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001814 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1815 } else {
1816 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1817 }
1818
1819 /* More default values. 2D/3D driver should adjust as needed */
1820 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1821 S1_X(0x4) | S1_Y(0xc)));
1822 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1823 S1_X(0x2) | S1_Y(0x2) |
1824 S2_X(0xa) | S2_Y(0x6) |
1825 S3_X(0x6) | S3_Y(0xa)));
1826 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1827 S1_X(0x4) | S1_Y(0xc) |
1828 S2_X(0x1) | S2_Y(0x6) |
1829 S3_X(0xa) | S3_Y(0xe)));
1830 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1831 S5_X(0x0) | S5_Y(0x0) |
1832 S6_X(0xb) | S6_Y(0x4) |
1833 S7_X(0x7) | S7_Y(0x8)));
1834
1835 WREG32(VGT_STRMOUT_EN, 0);
1836 tmp = rdev->config.r600.max_pipes * 16;
1837 switch (rdev->family) {
1838 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001839 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001840 case CHIP_RS780:
1841 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001842 tmp += 32;
1843 break;
1844 case CHIP_RV670:
1845 tmp += 128;
1846 break;
1847 default:
1848 break;
1849 }
1850 if (tmp > 256) {
1851 tmp = 256;
1852 }
1853 WREG32(VGT_ES_PER_GS, 128);
1854 WREG32(VGT_GS_PER_ES, tmp);
1855 WREG32(VGT_GS_PER_VS, 2);
1856 WREG32(VGT_GS_VERTEX_REUSE, 16);
1857
1858 /* more default values. 2D/3D driver should adjust as needed */
1859 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1860 WREG32(VGT_STRMOUT_EN, 0);
1861 WREG32(SX_MISC, 0);
1862 WREG32(PA_SC_MODE_CNTL, 0);
1863 WREG32(PA_SC_AA_CONFIG, 0);
1864 WREG32(PA_SC_LINE_STIPPLE, 0);
1865 WREG32(SPI_INPUT_Z, 0);
1866 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1867 WREG32(CB_COLOR7_FRAG, 0);
1868
1869 /* Clear render buffer base addresses */
1870 WREG32(CB_COLOR0_BASE, 0);
1871 WREG32(CB_COLOR1_BASE, 0);
1872 WREG32(CB_COLOR2_BASE, 0);
1873 WREG32(CB_COLOR3_BASE, 0);
1874 WREG32(CB_COLOR4_BASE, 0);
1875 WREG32(CB_COLOR5_BASE, 0);
1876 WREG32(CB_COLOR6_BASE, 0);
1877 WREG32(CB_COLOR7_BASE, 0);
1878 WREG32(CB_COLOR7_FRAG, 0);
1879
1880 switch (rdev->family) {
1881 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001882 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001883 case CHIP_RS780:
1884 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001885 tmp = TC_L2_SIZE(8);
1886 break;
1887 case CHIP_RV630:
1888 case CHIP_RV635:
1889 tmp = TC_L2_SIZE(4);
1890 break;
1891 case CHIP_R600:
1892 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1893 break;
1894 default:
1895 tmp = TC_L2_SIZE(0);
1896 break;
1897 }
1898 WREG32(TC_CNTL, tmp);
1899
1900 tmp = RREG32(HDP_HOST_PATH_CNTL);
1901 WREG32(HDP_HOST_PATH_CNTL, tmp);
1902
1903 tmp = RREG32(ARB_POP);
1904 tmp |= ENABLE_TC128;
1905 WREG32(ARB_POP, tmp);
1906
1907 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1908 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1909 NUM_CLIP_SEQ(3)));
1910 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1911}
1912
1913
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001914/*
1915 * Indirect registers accessor
1916 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001917u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001918{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001919 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001920
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001921 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1922 (void)RREG32(PCIE_PORT_INDEX);
1923 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001924 return r;
1925}
1926
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001927void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001928{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001929 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1930 (void)RREG32(PCIE_PORT_INDEX);
1931 WREG32(PCIE_PORT_DATA, (v));
1932 (void)RREG32(PCIE_PORT_DATA);
1933}
1934
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001935/*
1936 * CP & Ring
1937 */
1938void r600_cp_stop(struct radeon_device *rdev)
1939{
Dave Airlie53595332011-03-14 09:47:24 +10001940 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001941 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04001942 WREG32(SCRATCH_UMSK, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001943}
1944
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001945int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001946{
1947 struct platform_device *pdev;
1948 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001949 const char *rlc_chip_name;
1950 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001951 char fw_name[30];
1952 int err;
1953
1954 DRM_DEBUG("\n");
1955
1956 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1957 err = IS_ERR(pdev);
1958 if (err) {
1959 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1960 return -EINVAL;
1961 }
1962
1963 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001964 case CHIP_R600:
1965 chip_name = "R600";
1966 rlc_chip_name = "R600";
1967 break;
1968 case CHIP_RV610:
1969 chip_name = "RV610";
1970 rlc_chip_name = "R600";
1971 break;
1972 case CHIP_RV630:
1973 chip_name = "RV630";
1974 rlc_chip_name = "R600";
1975 break;
1976 case CHIP_RV620:
1977 chip_name = "RV620";
1978 rlc_chip_name = "R600";
1979 break;
1980 case CHIP_RV635:
1981 chip_name = "RV635";
1982 rlc_chip_name = "R600";
1983 break;
1984 case CHIP_RV670:
1985 chip_name = "RV670";
1986 rlc_chip_name = "R600";
1987 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001988 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001989 case CHIP_RS880:
1990 chip_name = "RS780";
1991 rlc_chip_name = "R600";
1992 break;
1993 case CHIP_RV770:
1994 chip_name = "RV770";
1995 rlc_chip_name = "R700";
1996 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001997 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001998 case CHIP_RV740:
1999 chip_name = "RV730";
2000 rlc_chip_name = "R700";
2001 break;
2002 case CHIP_RV710:
2003 chip_name = "RV710";
2004 rlc_chip_name = "R700";
2005 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04002006 case CHIP_CEDAR:
2007 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04002008 rlc_chip_name = "CEDAR";
Alex Deucherfe251e22010-03-24 13:36:43 -04002009 break;
2010 case CHIP_REDWOOD:
2011 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04002012 rlc_chip_name = "REDWOOD";
Alex Deucherfe251e22010-03-24 13:36:43 -04002013 break;
2014 case CHIP_JUNIPER:
2015 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04002016 rlc_chip_name = "JUNIPER";
Alex Deucherfe251e22010-03-24 13:36:43 -04002017 break;
2018 case CHIP_CYPRESS:
2019 case CHIP_HEMLOCK:
2020 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04002021 rlc_chip_name = "CYPRESS";
Alex Deucherfe251e22010-03-24 13:36:43 -04002022 break;
Alex Deucher439bd6c2010-11-22 17:56:31 -05002023 case CHIP_PALM:
2024 chip_name = "PALM";
2025 rlc_chip_name = "SUMO";
2026 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002027 default: BUG();
2028 }
2029
Alex Deucherfe251e22010-03-24 13:36:43 -04002030 if (rdev->family >= CHIP_CEDAR) {
2031 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2032 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002033 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002034 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002035 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2036 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002037 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002038 } else {
2039 pfp_req_size = PFP_UCODE_SIZE * 4;
2040 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002041 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002042 }
2043
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002044 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002045
2046 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2047 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
2048 if (err)
2049 goto out;
2050 if (rdev->pfp_fw->size != pfp_req_size) {
2051 printk(KERN_ERR
2052 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2053 rdev->pfp_fw->size, fw_name);
2054 err = -EINVAL;
2055 goto out;
2056 }
2057
2058 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2059 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
2060 if (err)
2061 goto out;
2062 if (rdev->me_fw->size != me_req_size) {
2063 printk(KERN_ERR
2064 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2065 rdev->me_fw->size, fw_name);
2066 err = -EINVAL;
2067 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002068
2069 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
2070 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
2071 if (err)
2072 goto out;
2073 if (rdev->rlc_fw->size != rlc_req_size) {
2074 printk(KERN_ERR
2075 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2076 rdev->rlc_fw->size, fw_name);
2077 err = -EINVAL;
2078 }
2079
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002080out:
2081 platform_device_unregister(pdev);
2082
2083 if (err) {
2084 if (err != -EINVAL)
2085 printk(KERN_ERR
2086 "r600_cp: Failed to load firmware \"%s\"\n",
2087 fw_name);
2088 release_firmware(rdev->pfp_fw);
2089 rdev->pfp_fw = NULL;
2090 release_firmware(rdev->me_fw);
2091 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002092 release_firmware(rdev->rlc_fw);
2093 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002094 }
2095 return err;
2096}
2097
2098static int r600_cp_load_microcode(struct radeon_device *rdev)
2099{
2100 const __be32 *fw_data;
2101 int i;
2102
2103 if (!rdev->me_fw || !rdev->pfp_fw)
2104 return -EINVAL;
2105
2106 r600_cp_stop(rdev);
2107
Cédric Cano4eace7f2011-02-11 19:45:38 -05002108 WREG32(CP_RB_CNTL,
2109#ifdef __BIG_ENDIAN
2110 BUF_SWAP_32BIT |
2111#endif
2112 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002113
2114 /* Reset cp */
2115 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2116 RREG32(GRBM_SOFT_RESET);
2117 mdelay(15);
2118 WREG32(GRBM_SOFT_RESET, 0);
2119
2120 WREG32(CP_ME_RAM_WADDR, 0);
2121
2122 fw_data = (const __be32 *)rdev->me_fw->data;
2123 WREG32(CP_ME_RAM_WADDR, 0);
2124 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
2125 WREG32(CP_ME_RAM_DATA,
2126 be32_to_cpup(fw_data++));
2127
2128 fw_data = (const __be32 *)rdev->pfp_fw->data;
2129 WREG32(CP_PFP_UCODE_ADDR, 0);
2130 for (i = 0; i < PFP_UCODE_SIZE; i++)
2131 WREG32(CP_PFP_UCODE_DATA,
2132 be32_to_cpup(fw_data++));
2133
2134 WREG32(CP_PFP_UCODE_ADDR, 0);
2135 WREG32(CP_ME_RAM_WADDR, 0);
2136 WREG32(CP_ME_RAM_RADDR, 0);
2137 return 0;
2138}
2139
2140int r600_cp_start(struct radeon_device *rdev)
2141{
2142 int r;
2143 uint32_t cp_me;
2144
2145 r = radeon_ring_lock(rdev, 7);
2146 if (r) {
2147 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2148 return r;
2149 }
2150 radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
2151 radeon_ring_write(rdev, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002152 if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002153 radeon_ring_write(rdev, 0x0);
2154 radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002155 } else {
2156 radeon_ring_write(rdev, 0x3);
2157 radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002158 }
2159 radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2160 radeon_ring_write(rdev, 0);
2161 radeon_ring_write(rdev, 0);
2162 radeon_ring_unlock_commit(rdev);
2163
2164 cp_me = 0xff;
2165 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2166 return 0;
2167}
2168
2169int r600_cp_resume(struct radeon_device *rdev)
2170{
2171 u32 tmp;
2172 u32 rb_bufsz;
2173 int r;
2174
2175 /* Reset cp */
2176 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2177 RREG32(GRBM_SOFT_RESET);
2178 mdelay(15);
2179 WREG32(GRBM_SOFT_RESET, 0);
2180
2181 /* Set ring buffer size */
2182 rb_bufsz = drm_order(rdev->cp.ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04002183 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002184#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002185 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002186#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002187 WREG32(CP_RB_CNTL, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002188 WREG32(CP_SEM_WAIT_TIMER, 0x4);
2189
2190 /* Set the write pointer delay */
2191 WREG32(CP_RB_WPTR_DELAY, 0);
2192
2193 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002194 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2195 WREG32(CP_RB_RPTR_WR, 0);
2196 WREG32(CP_RB_WPTR, 0);
Alex Deucher724c80e2010-08-27 18:25:25 -04002197
2198 /* set the wb address whether it's enabled or not */
Cédric Cano4eace7f2011-02-11 19:45:38 -05002199 WREG32(CP_RB_RPTR_ADDR,
2200#ifdef __BIG_ENDIAN
2201 RB_RPTR_SWAP(2) |
2202#endif
2203 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002204 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2205 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2206
2207 if (rdev->wb.enabled)
2208 WREG32(SCRATCH_UMSK, 0xff);
2209 else {
2210 tmp |= RB_NO_UPDATE;
2211 WREG32(SCRATCH_UMSK, 0);
2212 }
2213
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002214 mdelay(1);
2215 WREG32(CP_RB_CNTL, tmp);
2216
2217 WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
2218 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2219
2220 rdev->cp.rptr = RREG32(CP_RB_RPTR);
2221 rdev->cp.wptr = RREG32(CP_RB_WPTR);
2222
2223 r600_cp_start(rdev);
2224 rdev->cp.ready = true;
2225 r = radeon_ring_test(rdev);
2226 if (r) {
2227 rdev->cp.ready = false;
2228 return r;
2229 }
2230 return 0;
2231}
2232
2233void r600_cp_commit(struct radeon_device *rdev)
2234{
2235 WREG32(CP_RB_WPTR, rdev->cp.wptr);
2236 (void)RREG32(CP_RB_WPTR);
2237}
2238
2239void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
2240{
2241 u32 rb_bufsz;
2242
2243 /* Align ring size */
2244 rb_bufsz = drm_order(ring_size / 8);
2245 ring_size = (1 << (rb_bufsz + 1)) * 4;
2246 rdev->cp.ring_size = ring_size;
2247 rdev->cp.align_mask = 16 - 1;
2248}
2249
Jerome Glisse655efd32010-02-02 11:51:45 +01002250void r600_cp_fini(struct radeon_device *rdev)
2251{
2252 r600_cp_stop(rdev);
2253 radeon_ring_fini(rdev);
2254}
2255
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002256
2257/*
2258 * GPU scratch registers helpers function.
2259 */
2260void r600_scratch_init(struct radeon_device *rdev)
2261{
2262 int i;
2263
2264 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002265 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002266 for (i = 0; i < rdev->scratch.num_reg; i++) {
2267 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002268 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002269 }
2270}
2271
2272int r600_ring_test(struct radeon_device *rdev)
2273{
2274 uint32_t scratch;
2275 uint32_t tmp = 0;
2276 unsigned i;
2277 int r;
2278
2279 r = radeon_scratch_get(rdev, &scratch);
2280 if (r) {
2281 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2282 return r;
2283 }
2284 WREG32(scratch, 0xCAFEDEAD);
2285 r = radeon_ring_lock(rdev, 3);
2286 if (r) {
2287 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2288 radeon_scratch_free(rdev, scratch);
2289 return r;
2290 }
2291 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2292 radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2293 radeon_ring_write(rdev, 0xDEADBEEF);
2294 radeon_ring_unlock_commit(rdev);
2295 for (i = 0; i < rdev->usec_timeout; i++) {
2296 tmp = RREG32(scratch);
2297 if (tmp == 0xDEADBEEF)
2298 break;
2299 DRM_UDELAY(1);
2300 }
2301 if (i < rdev->usec_timeout) {
2302 DRM_INFO("ring test succeeded in %d usecs\n", i);
2303 } else {
2304 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
2305 scratch, tmp);
2306 r = -EINVAL;
2307 }
2308 radeon_scratch_free(rdev, scratch);
2309 return r;
2310}
2311
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002312void r600_fence_ring_emit(struct radeon_device *rdev,
2313 struct radeon_fence *fence)
2314{
Alex Deucherd0f8a852010-09-04 05:04:34 -04002315 if (rdev->wb.use_event) {
2316 u64 addr = rdev->wb.gpu_addr + R600_WB_EVENT_OFFSET +
2317 (u64)(rdev->fence_drv.scratch_reg - rdev->scratch.reg_base);
2318 /* EVENT_WRITE_EOP - flush caches, send int */
2319 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2320 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2321 radeon_ring_write(rdev, addr & 0xffffffff);
2322 radeon_ring_write(rdev, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2323 radeon_ring_write(rdev, fence->seq);
2324 radeon_ring_write(rdev, 0);
2325 } else {
2326 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
2327 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
2328 /* wait for 3D idle clean */
2329 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2330 radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2331 radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
2332 /* Emit fence sequence & fire IRQ */
2333 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2334 radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2335 radeon_ring_write(rdev, fence->seq);
2336 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2337 radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
2338 radeon_ring_write(rdev, RB_INT_STAT);
2339 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002340}
2341
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002342int r600_copy_blit(struct radeon_device *rdev,
2343 uint64_t src_offset, uint64_t dst_offset,
2344 unsigned num_pages, struct radeon_fence *fence)
2345{
Jerome Glisseff82f052010-01-22 15:19:00 +01002346 int r;
2347
2348 mutex_lock(&rdev->r600_blit.mutex);
2349 rdev->r600_blit.vb_ib = NULL;
2350 r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
2351 if (r) {
2352 if (rdev->r600_blit.vb_ib)
2353 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
2354 mutex_unlock(&rdev->r600_blit.mutex);
2355 return r;
2356 }
Matt Turnera77f1712009-10-14 00:34:41 -04002357 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002358 r600_blit_done_copy(rdev, fence);
Jerome Glisseff82f052010-01-22 15:19:00 +01002359 mutex_unlock(&rdev->r600_blit.mutex);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002360 return 0;
2361}
2362
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002363int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2364 uint32_t tiling_flags, uint32_t pitch,
2365 uint32_t offset, uint32_t obj_size)
2366{
2367 /* FIXME: implement */
2368 return 0;
2369}
2370
2371void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2372{
2373 /* FIXME: implement */
2374}
2375
Dave Airliefc30b8e2009-09-18 15:19:37 +10002376int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002377{
2378 int r;
2379
Alex Deucher9e46a482011-01-06 18:49:35 -05002380 /* enable pcie gen2 link */
2381 r600_pcie_gen2_enable(rdev);
2382
Alex Deucher779720a2009-12-09 19:31:44 -05002383 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2384 r = r600_init_microcode(rdev);
2385 if (r) {
2386 DRM_ERROR("Failed to load firmware!\n");
2387 return r;
2388 }
2389 }
2390
Jerome Glissea3c19452009-10-01 18:02:13 +02002391 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02002392 if (rdev->flags & RADEON_IS_AGP) {
2393 r600_agp_enable(rdev);
2394 } else {
2395 r = r600_pcie_gart_enable(rdev);
2396 if (r)
2397 return r;
2398 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002399 r600_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01002400 r = r600_blit_init(rdev);
2401 if (r) {
2402 r600_blit_fini(rdev);
2403 rdev->asic->copy = NULL;
2404 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2405 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04002406
Alex Deucher724c80e2010-08-27 18:25:25 -04002407 /* allocate wb buffer */
2408 r = radeon_wb_init(rdev);
2409 if (r)
2410 return r;
2411
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002412 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002413 r = r600_irq_init(rdev);
2414 if (r) {
2415 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2416 radeon_irq_kms_fini(rdev);
2417 return r;
2418 }
2419 r600_irq_set(rdev);
2420
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002421 r = radeon_ring_init(rdev, rdev->cp.ring_size);
2422 if (r)
2423 return r;
2424 r = r600_cp_load_microcode(rdev);
2425 if (r)
2426 return r;
2427 r = r600_cp_resume(rdev);
2428 if (r)
2429 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04002430
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002431 return 0;
2432}
2433
Dave Airlie28d52042009-09-21 14:33:58 +10002434void r600_vga_set_state(struct radeon_device *rdev, bool state)
2435{
2436 uint32_t temp;
2437
2438 temp = RREG32(CONFIG_CNTL);
2439 if (state == false) {
2440 temp &= ~(1<<0);
2441 temp |= (1<<1);
2442 } else {
2443 temp &= ~(1<<1);
2444 }
2445 WREG32(CONFIG_CNTL, temp);
2446}
2447
Dave Airliefc30b8e2009-09-18 15:19:37 +10002448int r600_resume(struct radeon_device *rdev)
2449{
2450 int r;
2451
Jerome Glisse1a029b72009-10-06 19:04:30 +02002452 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2453 * posting will perform necessary task to bring back GPU into good
2454 * shape.
2455 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002456 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002457 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002458
2459 r = r600_startup(rdev);
2460 if (r) {
2461 DRM_ERROR("r600 startup failed on resume\n");
2462 return r;
2463 }
2464
Jerome Glisse62a8ea32009-10-01 18:02:11 +02002465 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002466 if (r) {
Paul Bolleec4f2ac2011-01-28 23:32:04 +01002467 DRM_ERROR("radeon: failed testing IB (%d).\n", r);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002468 return r;
2469 }
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002470
2471 r = r600_audio_init(rdev);
2472 if (r) {
2473 DRM_ERROR("radeon: audio resume failed\n");
2474 return r;
2475 }
2476
Dave Airliefc30b8e2009-09-18 15:19:37 +10002477 return r;
2478}
2479
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002480int r600_suspend(struct radeon_device *rdev)
2481{
Jerome Glisse4c788672009-11-20 14:29:23 +01002482 int r;
2483
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002484 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002485 /* FIXME: we should wait for ring to be empty */
2486 r600_cp_stop(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002487 rdev->cp.ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01002488 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002489 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002490 r600_pcie_gart_disable(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002491 /* unpin shaders bo */
Jerome Glisse30d2d9a2010-01-13 10:29:27 +01002492 if (rdev->r600_blit.shader_obj) {
2493 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
2494 if (!r) {
2495 radeon_bo_unpin(rdev->r600_blit.shader_obj);
2496 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
2497 }
2498 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002499 return 0;
2500}
2501
2502/* Plan is to move initialization in that function and use
2503 * helper function so that radeon_device_init pretty much
2504 * do nothing more than calling asic specific function. This
2505 * should also allow to remove a bunch of callback function
2506 * like vram_info.
2507 */
2508int r600_init(struct radeon_device *rdev)
2509{
2510 int r;
2511
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002512 if (r600_debugfs_mc_info_init(rdev)) {
2513 DRM_ERROR("Failed to register debugfs file for mc !\n");
2514 }
2515 /* This don't do much */
2516 r = radeon_gem_init(rdev);
2517 if (r)
2518 return r;
2519 /* Read BIOS */
2520 if (!radeon_get_bios(rdev)) {
2521 if (ASIC_IS_AVIVO(rdev))
2522 return -EINVAL;
2523 }
2524 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002525 if (!rdev->is_atom_bios) {
2526 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002527 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002528 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002529 r = radeon_atombios_init(rdev);
2530 if (r)
2531 return r;
2532 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05002533 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10002534 if (!rdev->bios) {
2535 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2536 return -EINVAL;
2537 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002538 DRM_INFO("GPU not posted. posting now...\n");
2539 atom_asic_init(rdev->mode_info.atom_context);
2540 }
2541 /* Initialize scratch registers */
2542 r600_scratch_init(rdev);
2543 /* Initialize surface registers */
2544 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002545 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002546 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002547 /* Fence driver */
2548 r = radeon_fence_driver_init(rdev);
2549 if (r)
2550 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01002551 if (rdev->flags & RADEON_IS_AGP) {
2552 r = radeon_agp_init(rdev);
2553 if (r)
2554 radeon_agp_disable(rdev);
2555 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002556 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002557 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002558 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002559 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002560 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002561 if (r)
2562 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002563
2564 r = radeon_irq_kms_init(rdev);
2565 if (r)
2566 return r;
2567
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002568 rdev->cp.ring_obj = NULL;
2569 r600_ring_init(rdev, 1024 * 1024);
2570
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002571 rdev->ih.ring_obj = NULL;
2572 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002573
Jerome Glisse4aac0472009-09-14 18:29:49 +02002574 r = r600_pcie_gart_init(rdev);
2575 if (r)
2576 return r;
2577
Alex Deucher779720a2009-12-09 19:31:44 -05002578 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002579 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002580 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01002581 dev_err(rdev->dev, "disabling GPU acceleration\n");
2582 r600_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002583 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002584 radeon_wb_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002585 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002586 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002587 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002588 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002589 if (rdev->accel_working) {
2590 r = radeon_ib_pool_init(rdev);
2591 if (r) {
Jerome Glissedb963802010-01-17 21:21:56 +01002592 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02002593 rdev->accel_working = false;
Jerome Glissedb963802010-01-17 21:21:56 +01002594 } else {
2595 r = r600_ib_test(rdev);
2596 if (r) {
2597 dev_err(rdev->dev, "IB test failed (%d).\n", r);
2598 rdev->accel_working = false;
2599 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002600 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002601 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002602
2603 r = r600_audio_init(rdev);
2604 if (r)
2605 return r; /* TODO error handling */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002606 return 0;
2607}
2608
2609void r600_fini(struct radeon_device *rdev)
2610{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002611 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002612 r600_blit_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002613 r600_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002614 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002615 radeon_wb_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002616 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002617 r600_pcie_gart_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002618 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002619 radeon_gem_fini(rdev);
2620 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002621 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002622 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002623 kfree(rdev->bios);
2624 rdev->bios = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002625}
2626
2627
2628/*
2629 * CS stuff
2630 */
2631void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2632{
2633 /* FIXME: implement */
2634 radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
Cédric Cano4eace7f2011-02-11 19:45:38 -05002635 radeon_ring_write(rdev,
2636#ifdef __BIG_ENDIAN
2637 (2 << 0) |
2638#endif
2639 (ib->gpu_addr & 0xFFFFFFFC));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002640 radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
2641 radeon_ring_write(rdev, ib->length_dw);
2642}
2643
2644int r600_ib_test(struct radeon_device *rdev)
2645{
2646 struct radeon_ib *ib;
2647 uint32_t scratch;
2648 uint32_t tmp = 0;
2649 unsigned i;
2650 int r;
2651
2652 r = radeon_scratch_get(rdev, &scratch);
2653 if (r) {
2654 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2655 return r;
2656 }
2657 WREG32(scratch, 0xCAFEDEAD);
2658 r = radeon_ib_get(rdev, &ib);
2659 if (r) {
2660 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2661 return r;
2662 }
2663 ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2664 ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2665 ib->ptr[2] = 0xDEADBEEF;
2666 ib->ptr[3] = PACKET2(0);
2667 ib->ptr[4] = PACKET2(0);
2668 ib->ptr[5] = PACKET2(0);
2669 ib->ptr[6] = PACKET2(0);
2670 ib->ptr[7] = PACKET2(0);
2671 ib->ptr[8] = PACKET2(0);
2672 ib->ptr[9] = PACKET2(0);
2673 ib->ptr[10] = PACKET2(0);
2674 ib->ptr[11] = PACKET2(0);
2675 ib->ptr[12] = PACKET2(0);
2676 ib->ptr[13] = PACKET2(0);
2677 ib->ptr[14] = PACKET2(0);
2678 ib->ptr[15] = PACKET2(0);
2679 ib->length_dw = 16;
2680 r = radeon_ib_schedule(rdev, ib);
2681 if (r) {
2682 radeon_scratch_free(rdev, scratch);
2683 radeon_ib_free(rdev, &ib);
2684 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2685 return r;
2686 }
2687 r = radeon_fence_wait(ib->fence, false);
2688 if (r) {
2689 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2690 return r;
2691 }
2692 for (i = 0; i < rdev->usec_timeout; i++) {
2693 tmp = RREG32(scratch);
2694 if (tmp == 0xDEADBEEF)
2695 break;
2696 DRM_UDELAY(1);
2697 }
2698 if (i < rdev->usec_timeout) {
2699 DRM_INFO("ib test succeeded in %u usecs\n", i);
2700 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01002701 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002702 scratch, tmp);
2703 r = -EINVAL;
2704 }
2705 radeon_scratch_free(rdev, scratch);
2706 radeon_ib_free(rdev, &ib);
2707 return r;
2708}
2709
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002710/*
2711 * Interrupts
2712 *
2713 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2714 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2715 * writing to the ring and the GPU consuming, the GPU writes to the ring
2716 * and host consumes. As the host irq handler processes interrupts, it
2717 * increments the rptr. When the rptr catches up with the wptr, all the
2718 * current interrupts have been processed.
2719 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002720
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002721void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2722{
2723 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002724
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002725 /* Align ring size */
2726 rb_bufsz = drm_order(ring_size / 4);
2727 ring_size = (1 << rb_bufsz) * 4;
2728 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01002729 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
2730 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002731}
2732
Jerome Glisse0c452492010-01-15 14:44:37 +01002733static int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002734{
2735 int r;
2736
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002737 /* Allocate ring buffer */
2738 if (rdev->ih.ring_obj == NULL) {
Daniel Vetter441921d2011-02-18 17:59:16 +01002739 r = radeon_bo_create(rdev, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05002740 PAGE_SIZE, true,
Jerome Glisse4c788672009-11-20 14:29:23 +01002741 RADEON_GEM_DOMAIN_GTT,
2742 &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002743 if (r) {
2744 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2745 return r;
2746 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002747 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2748 if (unlikely(r != 0))
2749 return r;
2750 r = radeon_bo_pin(rdev->ih.ring_obj,
2751 RADEON_GEM_DOMAIN_GTT,
2752 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002753 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002754 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002755 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2756 return r;
2757 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002758 r = radeon_bo_kmap(rdev->ih.ring_obj,
2759 (void **)&rdev->ih.ring);
2760 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002761 if (r) {
2762 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2763 return r;
2764 }
2765 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002766 return 0;
2767}
2768
2769static void r600_ih_ring_fini(struct radeon_device *rdev)
2770{
Jerome Glisse4c788672009-11-20 14:29:23 +01002771 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002772 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002773 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2774 if (likely(r == 0)) {
2775 radeon_bo_kunmap(rdev->ih.ring_obj);
2776 radeon_bo_unpin(rdev->ih.ring_obj);
2777 radeon_bo_unreserve(rdev->ih.ring_obj);
2778 }
2779 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002780 rdev->ih.ring = NULL;
2781 rdev->ih.ring_obj = NULL;
2782 }
2783}
2784
Alex Deucher45f9a392010-03-24 13:55:51 -04002785void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002786{
2787
Alex Deucher45f9a392010-03-24 13:55:51 -04002788 if ((rdev->family >= CHIP_RV770) &&
2789 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002790 /* r7xx asics need to soft reset RLC before halting */
2791 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2792 RREG32(SRBM_SOFT_RESET);
2793 udelay(15000);
2794 WREG32(SRBM_SOFT_RESET, 0);
2795 RREG32(SRBM_SOFT_RESET);
2796 }
2797
2798 WREG32(RLC_CNTL, 0);
2799}
2800
2801static void r600_rlc_start(struct radeon_device *rdev)
2802{
2803 WREG32(RLC_CNTL, RLC_ENABLE);
2804}
2805
2806static int r600_rlc_init(struct radeon_device *rdev)
2807{
2808 u32 i;
2809 const __be32 *fw_data;
2810
2811 if (!rdev->rlc_fw)
2812 return -EINVAL;
2813
2814 r600_rlc_stop(rdev);
2815
2816 WREG32(RLC_HB_BASE, 0);
2817 WREG32(RLC_HB_CNTL, 0);
2818 WREG32(RLC_HB_RPTR, 0);
2819 WREG32(RLC_HB_WPTR, 0);
Alex Deucher12727802011-03-02 20:07:32 -05002820 if (rdev->family <= CHIP_CAICOS) {
2821 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2822 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2823 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002824 WREG32(RLC_MC_CNTL, 0);
2825 WREG32(RLC_UCODE_CNTL, 0);
2826
2827 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucher12727802011-03-02 20:07:32 -05002828 if (rdev->family >= CHIP_CAYMAN) {
2829 for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
2830 WREG32(RLC_UCODE_ADDR, i);
2831 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2832 }
2833 } else if (rdev->family >= CHIP_CEDAR) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002834 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
2835 WREG32(RLC_UCODE_ADDR, i);
2836 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2837 }
2838 } else if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002839 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2840 WREG32(RLC_UCODE_ADDR, i);
2841 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2842 }
2843 } else {
2844 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2845 WREG32(RLC_UCODE_ADDR, i);
2846 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2847 }
2848 }
2849 WREG32(RLC_UCODE_ADDR, 0);
2850
2851 r600_rlc_start(rdev);
2852
2853 return 0;
2854}
2855
2856static void r600_enable_interrupts(struct radeon_device *rdev)
2857{
2858 u32 ih_cntl = RREG32(IH_CNTL);
2859 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2860
2861 ih_cntl |= ENABLE_INTR;
2862 ih_rb_cntl |= IH_RB_ENABLE;
2863 WREG32(IH_CNTL, ih_cntl);
2864 WREG32(IH_RB_CNTL, ih_rb_cntl);
2865 rdev->ih.enabled = true;
2866}
2867
Alex Deucher45f9a392010-03-24 13:55:51 -04002868void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002869{
2870 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2871 u32 ih_cntl = RREG32(IH_CNTL);
2872
2873 ih_rb_cntl &= ~IH_RB_ENABLE;
2874 ih_cntl &= ~ENABLE_INTR;
2875 WREG32(IH_RB_CNTL, ih_rb_cntl);
2876 WREG32(IH_CNTL, ih_cntl);
2877 /* set rptr, wptr to 0 */
2878 WREG32(IH_RB_RPTR, 0);
2879 WREG32(IH_RB_WPTR, 0);
2880 rdev->ih.enabled = false;
2881 rdev->ih.wptr = 0;
2882 rdev->ih.rptr = 0;
2883}
2884
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002885static void r600_disable_interrupt_state(struct radeon_device *rdev)
2886{
2887 u32 tmp;
2888
Alex Deucher3555e532010-10-08 12:09:12 -04002889 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002890 WREG32(GRBM_INT_CNTL, 0);
2891 WREG32(DxMODE_INT_MASK, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05002892 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
2893 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002894 if (ASIC_IS_DCE3(rdev)) {
2895 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2896 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2897 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2898 WREG32(DC_HPD1_INT_CONTROL, tmp);
2899 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2900 WREG32(DC_HPD2_INT_CONTROL, tmp);
2901 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2902 WREG32(DC_HPD3_INT_CONTROL, tmp);
2903 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2904 WREG32(DC_HPD4_INT_CONTROL, tmp);
2905 if (ASIC_IS_DCE32(rdev)) {
2906 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002907 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002908 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002909 WREG32(DC_HPD6_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002910 }
2911 } else {
2912 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2913 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2914 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002915 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002916 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002917 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002918 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002919 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002920 }
2921}
2922
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002923int r600_irq_init(struct radeon_device *rdev)
2924{
2925 int ret = 0;
2926 int rb_bufsz;
2927 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2928
2929 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01002930 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002931 if (ret)
2932 return ret;
2933
2934 /* disable irqs */
2935 r600_disable_interrupts(rdev);
2936
2937 /* init rlc */
2938 ret = r600_rlc_init(rdev);
2939 if (ret) {
2940 r600_ih_ring_fini(rdev);
2941 return ret;
2942 }
2943
2944 /* setup interrupt control */
2945 /* set dummy read address to ring address */
2946 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
2947 interrupt_cntl = RREG32(INTERRUPT_CNTL);
2948 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2949 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2950 */
2951 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
2952 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2953 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
2954 WREG32(INTERRUPT_CNTL, interrupt_cntl);
2955
2956 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
2957 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
2958
2959 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
2960 IH_WPTR_OVERFLOW_CLEAR |
2961 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04002962
2963 if (rdev->wb.enabled)
2964 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
2965
2966 /* set the writeback address whether it's enabled or not */
2967 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
2968 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 -05002969
2970 WREG32(IH_RB_CNTL, ih_rb_cntl);
2971
2972 /* set rptr, wptr to 0 */
2973 WREG32(IH_RB_RPTR, 0);
2974 WREG32(IH_RB_WPTR, 0);
2975
2976 /* Default settings for IH_CNTL (disabled at first) */
2977 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2978 /* RPTR_REARM only works if msi's are enabled */
2979 if (rdev->msi_enabled)
2980 ih_cntl |= RPTR_REARM;
2981
2982#ifdef __BIG_ENDIAN
2983 ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
2984#endif
2985 WREG32(IH_CNTL, ih_cntl);
2986
2987 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04002988 if (rdev->family >= CHIP_CEDAR)
2989 evergreen_disable_interrupt_state(rdev);
2990 else
2991 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002992
2993 /* enable irqs */
2994 r600_enable_interrupts(rdev);
2995
2996 return ret;
2997}
2998
Jerome Glisse0c452492010-01-15 14:44:37 +01002999void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003000{
Alex Deucher45f9a392010-03-24 13:55:51 -04003001 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003002 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003003}
3004
3005void r600_irq_fini(struct radeon_device *rdev)
3006{
3007 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003008 r600_ih_ring_fini(rdev);
3009}
3010
3011int r600_irq_set(struct radeon_device *rdev)
3012{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003013 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3014 u32 mode_int = 0;
3015 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04003016 u32 grbm_int_cntl = 0;
Christian Koenigf2594932010-04-10 03:13:16 +02003017 u32 hdmi1, hdmi2;
Alex Deucher6f34be52010-11-21 10:59:01 -05003018 u32 d1grph = 0, d2grph = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003019
Jerome Glisse003e69f2010-01-07 15:39:14 +01003020 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003021 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01003022 return -EINVAL;
3023 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003024 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003025 if (!rdev->ih.enabled) {
3026 r600_disable_interrupts(rdev);
3027 /* force the active interrupt state to all disabled */
3028 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003029 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003030 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003031
Christian Koenigf2594932010-04-10 03:13:16 +02003032 hdmi1 = RREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003033 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02003034 hdmi2 = RREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003035 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3036 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3037 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3038 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3039 if (ASIC_IS_DCE32(rdev)) {
3040 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3041 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
3042 }
3043 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02003044 hdmi2 = RREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003045 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3046 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3047 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3048 }
3049
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003050 if (rdev->irq.sw_int) {
3051 DRM_DEBUG("r600_irq_set: sw int\n");
3052 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003053 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003054 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003055 if (rdev->irq.crtc_vblank_int[0] ||
3056 rdev->irq.pflip[0]) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003057 DRM_DEBUG("r600_irq_set: vblank 0\n");
3058 mode_int |= D1MODE_VBLANK_INT_MASK;
3059 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003060 if (rdev->irq.crtc_vblank_int[1] ||
3061 rdev->irq.pflip[1]) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003062 DRM_DEBUG("r600_irq_set: vblank 1\n");
3063 mode_int |= D2MODE_VBLANK_INT_MASK;
3064 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003065 if (rdev->irq.hpd[0]) {
3066 DRM_DEBUG("r600_irq_set: hpd 1\n");
3067 hpd1 |= DC_HPDx_INT_EN;
3068 }
3069 if (rdev->irq.hpd[1]) {
3070 DRM_DEBUG("r600_irq_set: hpd 2\n");
3071 hpd2 |= DC_HPDx_INT_EN;
3072 }
3073 if (rdev->irq.hpd[2]) {
3074 DRM_DEBUG("r600_irq_set: hpd 3\n");
3075 hpd3 |= DC_HPDx_INT_EN;
3076 }
3077 if (rdev->irq.hpd[3]) {
3078 DRM_DEBUG("r600_irq_set: hpd 4\n");
3079 hpd4 |= DC_HPDx_INT_EN;
3080 }
3081 if (rdev->irq.hpd[4]) {
3082 DRM_DEBUG("r600_irq_set: hpd 5\n");
3083 hpd5 |= DC_HPDx_INT_EN;
3084 }
3085 if (rdev->irq.hpd[5]) {
3086 DRM_DEBUG("r600_irq_set: hpd 6\n");
3087 hpd6 |= DC_HPDx_INT_EN;
3088 }
Christian Koenigf2594932010-04-10 03:13:16 +02003089 if (rdev->irq.hdmi[0]) {
3090 DRM_DEBUG("r600_irq_set: hdmi 1\n");
3091 hdmi1 |= R600_HDMI_INT_EN;
3092 }
3093 if (rdev->irq.hdmi[1]) {
3094 DRM_DEBUG("r600_irq_set: hdmi 2\n");
3095 hdmi2 |= R600_HDMI_INT_EN;
3096 }
Alex Deucher2031f772010-04-22 12:52:11 -04003097 if (rdev->irq.gui_idle) {
3098 DRM_DEBUG("gui idle\n");
3099 grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
3100 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003101
3102 WREG32(CP_INT_CNTL, cp_int_cntl);
3103 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher6f34be52010-11-21 10:59:01 -05003104 WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
3105 WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
Alex Deucher2031f772010-04-22 12:52:11 -04003106 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Christian Koenigf2594932010-04-10 03:13:16 +02003107 WREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003108 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02003109 WREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003110 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3111 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3112 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3113 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3114 if (ASIC_IS_DCE32(rdev)) {
3115 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3116 WREG32(DC_HPD6_INT_CONTROL, hpd6);
3117 }
3118 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02003119 WREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003120 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3121 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3122 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
3123 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003124
3125 return 0;
3126}
3127
Alex Deucher6f34be52010-11-21 10:59:01 -05003128static inline void r600_irq_ack(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003129{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003130 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003131
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003132 if (ASIC_IS_DCE3(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003133 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3134 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3135 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003136 } else {
Alex Deucher6f34be52010-11-21 10:59:01 -05003137 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3138 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3139 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003140 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003141 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3142 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003143
Alex Deucher6f34be52010-11-21 10:59:01 -05003144 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3145 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3146 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3147 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3148 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003149 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003150 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003151 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003152 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003153 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003154 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003155 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003156 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003157 if (ASIC_IS_DCE3(rdev)) {
3158 tmp = RREG32(DC_HPD1_INT_CONTROL);
3159 tmp |= DC_HPDx_INT_ACK;
3160 WREG32(DC_HPD1_INT_CONTROL, tmp);
3161 } else {
3162 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3163 tmp |= DC_HPDx_INT_ACK;
3164 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3165 }
3166 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003167 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003168 if (ASIC_IS_DCE3(rdev)) {
3169 tmp = RREG32(DC_HPD2_INT_CONTROL);
3170 tmp |= DC_HPDx_INT_ACK;
3171 WREG32(DC_HPD2_INT_CONTROL, tmp);
3172 } else {
3173 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3174 tmp |= DC_HPDx_INT_ACK;
3175 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3176 }
3177 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003178 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003179 if (ASIC_IS_DCE3(rdev)) {
3180 tmp = RREG32(DC_HPD3_INT_CONTROL);
3181 tmp |= DC_HPDx_INT_ACK;
3182 WREG32(DC_HPD3_INT_CONTROL, tmp);
3183 } else {
3184 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3185 tmp |= DC_HPDx_INT_ACK;
3186 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3187 }
3188 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003189 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003190 tmp = RREG32(DC_HPD4_INT_CONTROL);
3191 tmp |= DC_HPDx_INT_ACK;
3192 WREG32(DC_HPD4_INT_CONTROL, tmp);
3193 }
3194 if (ASIC_IS_DCE32(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003195 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003196 tmp = RREG32(DC_HPD5_INT_CONTROL);
3197 tmp |= DC_HPDx_INT_ACK;
3198 WREG32(DC_HPD5_INT_CONTROL, tmp);
3199 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003200 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003201 tmp = RREG32(DC_HPD5_INT_CONTROL);
3202 tmp |= DC_HPDx_INT_ACK;
3203 WREG32(DC_HPD6_INT_CONTROL, tmp);
3204 }
3205 }
Christian Koenigf2594932010-04-10 03:13:16 +02003206 if (RREG32(R600_HDMI_BLOCK1 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3207 WREG32_P(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3208 }
3209 if (ASIC_IS_DCE3(rdev)) {
3210 if (RREG32(R600_HDMI_BLOCK3 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3211 WREG32_P(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3212 }
3213 } else {
3214 if (RREG32(R600_HDMI_BLOCK2 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3215 WREG32_P(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3216 }
3217 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003218}
3219
3220void r600_irq_disable(struct radeon_device *rdev)
3221{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003222 r600_disable_interrupts(rdev);
3223 /* Wait and acknowledge irq */
3224 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003225 r600_irq_ack(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003226 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003227}
3228
3229static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
3230{
3231 u32 wptr, tmp;
3232
Alex Deucher724c80e2010-08-27 18:25:25 -04003233 if (rdev->wb.enabled)
3234 wptr = rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4];
3235 else
3236 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003237
3238 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003239 /* When a ring buffer overflow happen start parsing interrupt
3240 * from the last not overwritten vector (wptr + 16). Hopefully
3241 * this should allow us to catchup.
3242 */
3243 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3244 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3245 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003246 tmp = RREG32(IH_RB_CNTL);
3247 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3248 WREG32(IH_RB_CNTL, tmp);
3249 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003250 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003251}
3252
3253/* r600 IV Ring
3254 * Each IV ring entry is 128 bits:
3255 * [7:0] - interrupt source id
3256 * [31:8] - reserved
3257 * [59:32] - interrupt source data
3258 * [127:60] - reserved
3259 *
3260 * The basic interrupt vector entries
3261 * are decoded as follows:
3262 * src_id src_data description
3263 * 1 0 D1 Vblank
3264 * 1 1 D1 Vline
3265 * 5 0 D2 Vblank
3266 * 5 1 D2 Vline
3267 * 19 0 FP Hot plug detection A
3268 * 19 1 FP Hot plug detection B
3269 * 19 2 DAC A auto-detection
3270 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003271 * 21 4 HDMI block A
3272 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003273 * 176 - CP_INT RB
3274 * 177 - CP_INT IB1
3275 * 178 - CP_INT IB2
3276 * 181 - EOP Interrupt
3277 * 233 - GUI Idle
3278 *
3279 * Note, these are based on r600 and may need to be
3280 * adjusted or added to on newer asics
3281 */
3282
3283int r600_irq_process(struct radeon_device *rdev)
3284{
3285 u32 wptr = r600_get_ih_wptr(rdev);
3286 u32 rptr = rdev->ih.rptr;
3287 u32 src_id, src_data;
Alex Deucher6f34be52010-11-21 10:59:01 -05003288 u32 ring_index;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003289 unsigned long flags;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003290 bool queue_hotplug = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003291
3292 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003293 if (!rdev->ih.enabled)
3294 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003295
3296 spin_lock_irqsave(&rdev->ih.lock, flags);
3297
3298 if (rptr == wptr) {
3299 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3300 return IRQ_NONE;
3301 }
3302 if (rdev->shutdown) {
3303 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3304 return IRQ_NONE;
3305 }
3306
3307restart_ih:
3308 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05003309 r600_irq_ack(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003310
3311 rdev->ih.wptr = wptr;
3312 while (rptr != wptr) {
3313 /* wptr/rptr are in bytes! */
3314 ring_index = rptr / 4;
Cédric Cano4eace7f2011-02-11 19:45:38 -05003315 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3316 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003317
3318 switch (src_id) {
3319 case 1: /* D1 vblank/vline */
3320 switch (src_data) {
3321 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003322 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003323 if (rdev->irq.crtc_vblank_int[0]) {
3324 drm_handle_vblank(rdev->ddev, 0);
3325 rdev->pm.vblank_sync = true;
3326 wake_up(&rdev->irq.vblank_queue);
3327 }
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003328 if (rdev->irq.pflip[0])
3329 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003330 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003331 DRM_DEBUG("IH: D1 vblank\n");
3332 }
3333 break;
3334 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003335 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
3336 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003337 DRM_DEBUG("IH: D1 vline\n");
3338 }
3339 break;
3340 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003341 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003342 break;
3343 }
3344 break;
3345 case 5: /* D2 vblank/vline */
3346 switch (src_data) {
3347 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003348 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003349 if (rdev->irq.crtc_vblank_int[1]) {
3350 drm_handle_vblank(rdev->ddev, 1);
3351 rdev->pm.vblank_sync = true;
3352 wake_up(&rdev->irq.vblank_queue);
3353 }
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003354 if (rdev->irq.pflip[1])
3355 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003356 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003357 DRM_DEBUG("IH: D2 vblank\n");
3358 }
3359 break;
3360 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003361 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
3362 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003363 DRM_DEBUG("IH: D2 vline\n");
3364 }
3365 break;
3366 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003367 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003368 break;
3369 }
3370 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003371 case 19: /* HPD/DAC hotplug */
3372 switch (src_data) {
3373 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05003374 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
3375 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003376 queue_hotplug = true;
3377 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003378 }
3379 break;
3380 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05003381 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
3382 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003383 queue_hotplug = true;
3384 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003385 }
3386 break;
3387 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05003388 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
3389 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003390 queue_hotplug = true;
3391 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003392 }
3393 break;
3394 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05003395 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
3396 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003397 queue_hotplug = true;
3398 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003399 }
3400 break;
3401 case 10:
Alex Deucher6f34be52010-11-21 10:59:01 -05003402 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
3403 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003404 queue_hotplug = true;
3405 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003406 }
3407 break;
3408 case 12:
Alex Deucher6f34be52010-11-21 10:59:01 -05003409 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
3410 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003411 queue_hotplug = true;
3412 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003413 }
3414 break;
3415 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003416 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003417 break;
3418 }
3419 break;
Christian Koenigf2594932010-04-10 03:13:16 +02003420 case 21: /* HDMI */
3421 DRM_DEBUG("IH: HDMI: 0x%x\n", src_data);
3422 r600_audio_schedule_polling(rdev);
3423 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003424 case 176: /* CP_INT in ring buffer */
3425 case 177: /* CP_INT in IB1 */
3426 case 178: /* CP_INT in IB2 */
3427 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
3428 radeon_fence_process(rdev);
3429 break;
3430 case 181: /* CP EOP event */
3431 DRM_DEBUG("IH: CP EOP\n");
Alex Deucherd0f8a852010-09-04 05:04:34 -04003432 radeon_fence_process(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003433 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003434 case 233: /* GUI IDLE */
3435 DRM_DEBUG("IH: CP EOP\n");
3436 rdev->pm.gui_idle = true;
3437 wake_up(&rdev->irq.idle_queue);
3438 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003439 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003440 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003441 break;
3442 }
3443
3444 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01003445 rptr += 16;
3446 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003447 }
3448 /* make sure wptr hasn't changed while processing */
3449 wptr = r600_get_ih_wptr(rdev);
3450 if (wptr != rdev->ih.wptr)
3451 goto restart_ih;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003452 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01003453 schedule_work(&rdev->hotplug_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003454 rdev->ih.rptr = rptr;
3455 WREG32(IH_RB_RPTR, rdev->ih.rptr);
3456 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3457 return IRQ_HANDLED;
3458}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003459
3460/*
3461 * Debugfs info
3462 */
3463#if defined(CONFIG_DEBUG_FS)
3464
3465static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
3466{
3467 struct drm_info_node *node = (struct drm_info_node *) m->private;
3468 struct drm_device *dev = node->minor->dev;
3469 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003470 unsigned count, i, j;
3471
3472 radeon_ring_free_size(rdev);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003473 count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003474 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
Rafał Miłeckid6840762009-11-10 22:26:21 +01003475 seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
3476 seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
3477 seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
3478 seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003479 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
3480 seq_printf(m, "%u dwords in ring\n", count);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003481 i = rdev->cp.rptr;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003482 for (j = 0; j <= count; j++) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003483 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003484 i = (i + 1) & rdev->cp.ptr_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003485 }
3486 return 0;
3487}
3488
3489static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3490{
3491 struct drm_info_node *node = (struct drm_info_node *) m->private;
3492 struct drm_device *dev = node->minor->dev;
3493 struct radeon_device *rdev = dev->dev_private;
3494
3495 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3496 DREG32_SYS(m, rdev, VM_L2_STATUS);
3497 return 0;
3498}
3499
3500static struct drm_info_list r600_mc_info_list[] = {
3501 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
3502 {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
3503};
3504#endif
3505
3506int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3507{
3508#if defined(CONFIG_DEBUG_FS)
3509 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3510#else
3511 return 0;
3512#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003513}
Jerome Glisse062b3892010-02-04 20:36:39 +01003514
3515/**
3516 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3517 * rdev: radeon device structure
3518 * bo: buffer object struct which userspace is waiting for idle
3519 *
3520 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3521 * through ring buffer, this leads to corruption in rendering, see
3522 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3523 * directly perform HDP flush by writing register through MMIO.
3524 */
3525void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3526{
Alex Deucher812d0462010-07-26 18:51:53 -04003527 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
Alex Deucherf3886f82010-12-08 10:05:34 -05003528 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
3529 * This seems to cause problems on some AGP cards. Just use the old
3530 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04003531 */
Alex Deuchere4884592010-09-27 10:57:10 -04003532 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
Alex Deucherf3886f82010-12-08 10:05:34 -05003533 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04003534 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04003535 u32 tmp;
3536
3537 WREG32(HDP_DEBUG1, 0);
3538 tmp = readl((void __iomem *)ptr);
3539 } else
3540 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01003541}
Alex Deucher3313e3d2011-01-06 18:49:34 -05003542
3543void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
3544{
3545 u32 link_width_cntl, mask, target_reg;
3546
3547 if (rdev->flags & RADEON_IS_IGP)
3548 return;
3549
3550 if (!(rdev->flags & RADEON_IS_PCIE))
3551 return;
3552
3553 /* x2 cards have a special sequence */
3554 if (ASIC_IS_X2(rdev))
3555 return;
3556
3557 /* FIXME wait for idle */
3558
3559 switch (lanes) {
3560 case 0:
3561 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
3562 break;
3563 case 1:
3564 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
3565 break;
3566 case 2:
3567 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
3568 break;
3569 case 4:
3570 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
3571 break;
3572 case 8:
3573 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
3574 break;
3575 case 12:
3576 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
3577 break;
3578 case 16:
3579 default:
3580 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
3581 break;
3582 }
3583
3584 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
3585
3586 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
3587 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
3588 return;
3589
3590 if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS)
3591 return;
3592
3593 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
3594 RADEON_PCIE_LC_RECONFIG_NOW |
3595 R600_PCIE_LC_RENEGOTIATE_EN |
3596 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
3597 link_width_cntl |= mask;
3598
3599 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3600
3601 /* some northbridges can renegotiate the link rather than requiring
3602 * a complete re-config.
3603 * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.)
3604 */
3605 if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT)
3606 link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT;
3607 else
3608 link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE;
3609
3610 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
3611 RADEON_PCIE_LC_RECONFIG_NOW));
3612
3613 if (rdev->family >= CHIP_RV770)
3614 target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX;
3615 else
3616 target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX;
3617
3618 /* wait for lane set to complete */
3619 link_width_cntl = RREG32(target_reg);
3620 while (link_width_cntl == 0xffffffff)
3621 link_width_cntl = RREG32(target_reg);
3622
3623}
3624
3625int r600_get_pcie_lanes(struct radeon_device *rdev)
3626{
3627 u32 link_width_cntl;
3628
3629 if (rdev->flags & RADEON_IS_IGP)
3630 return 0;
3631
3632 if (!(rdev->flags & RADEON_IS_PCIE))
3633 return 0;
3634
3635 /* x2 cards have a special sequence */
3636 if (ASIC_IS_X2(rdev))
3637 return 0;
3638
3639 /* FIXME wait for idle */
3640
3641 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
3642
3643 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
3644 case RADEON_PCIE_LC_LINK_WIDTH_X0:
3645 return 0;
3646 case RADEON_PCIE_LC_LINK_WIDTH_X1:
3647 return 1;
3648 case RADEON_PCIE_LC_LINK_WIDTH_X2:
3649 return 2;
3650 case RADEON_PCIE_LC_LINK_WIDTH_X4:
3651 return 4;
3652 case RADEON_PCIE_LC_LINK_WIDTH_X8:
3653 return 8;
3654 case RADEON_PCIE_LC_LINK_WIDTH_X16:
3655 default:
3656 return 16;
3657 }
3658}
3659
Alex Deucher9e46a482011-01-06 18:49:35 -05003660static void r600_pcie_gen2_enable(struct radeon_device *rdev)
3661{
3662 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
3663 u16 link_cntl2;
3664
Alex Deucherd42dd572011-01-12 20:05:11 -05003665 if (radeon_pcie_gen2 == 0)
3666 return;
3667
Alex Deucher9e46a482011-01-06 18:49:35 -05003668 if (rdev->flags & RADEON_IS_IGP)
3669 return;
3670
3671 if (!(rdev->flags & RADEON_IS_PCIE))
3672 return;
3673
3674 /* x2 cards have a special sequence */
3675 if (ASIC_IS_X2(rdev))
3676 return;
3677
3678 /* only RV6xx+ chips are supported */
3679 if (rdev->family <= CHIP_R600)
3680 return;
3681
3682 /* 55 nm r6xx asics */
3683 if ((rdev->family == CHIP_RV670) ||
3684 (rdev->family == CHIP_RV620) ||
3685 (rdev->family == CHIP_RV635)) {
3686 /* advertise upconfig capability */
3687 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3688 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
3689 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3690 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3691 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
3692 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
3693 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
3694 LC_RECONFIG_ARC_MISSING_ESCAPE);
3695 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
3696 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3697 } else {
3698 link_width_cntl |= LC_UPCONFIGURE_DIS;
3699 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3700 }
3701 }
3702
3703 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3704 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
3705 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
3706
3707 /* 55 nm r6xx asics */
3708 if ((rdev->family == CHIP_RV670) ||
3709 (rdev->family == CHIP_RV620) ||
3710 (rdev->family == CHIP_RV635)) {
3711 WREG32(MM_CFGREGS_CNTL, 0x8);
3712 link_cntl2 = RREG32(0x4088);
3713 WREG32(MM_CFGREGS_CNTL, 0);
3714 /* not supported yet */
3715 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
3716 return;
3717 }
3718
3719 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
3720 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
3721 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
3722 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
3723 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
3724 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3725
3726 tmp = RREG32(0x541c);
3727 WREG32(0x541c, tmp | 0x8);
3728 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
3729 link_cntl2 = RREG16(0x4088);
3730 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
3731 link_cntl2 |= 0x2;
3732 WREG16(0x4088, link_cntl2);
3733 WREG32(MM_CFGREGS_CNTL, 0);
3734
3735 if ((rdev->family == CHIP_RV670) ||
3736 (rdev->family == CHIP_RV620) ||
3737 (rdev->family == CHIP_RV635)) {
3738 training_cntl = RREG32_PCIE_P(PCIE_LC_TRAINING_CNTL);
3739 training_cntl &= ~LC_POINT_7_PLUS_EN;
3740 WREG32_PCIE_P(PCIE_LC_TRAINING_CNTL, training_cntl);
3741 } else {
3742 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3743 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
3744 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3745 }
3746
3747 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3748 speed_cntl |= LC_GEN2_EN_STRAP;
3749 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
3750
3751 } else {
3752 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
3753 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
3754 if (1)
3755 link_width_cntl |= LC_UPCONFIGURE_DIS;
3756 else
3757 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
3758 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
3759 }
3760}