blob: a3552594ccc44c69b398980e539daf348d62322a [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
Jerome Glisse3ce0a232009-09-08 10:10:24 +100050
51/* Firmware Names */
52MODULE_FIRMWARE("radeon/R600_pfp.bin");
53MODULE_FIRMWARE("radeon/R600_me.bin");
54MODULE_FIRMWARE("radeon/RV610_pfp.bin");
55MODULE_FIRMWARE("radeon/RV610_me.bin");
56MODULE_FIRMWARE("radeon/RV630_pfp.bin");
57MODULE_FIRMWARE("radeon/RV630_me.bin");
58MODULE_FIRMWARE("radeon/RV620_pfp.bin");
59MODULE_FIRMWARE("radeon/RV620_me.bin");
60MODULE_FIRMWARE("radeon/RV635_pfp.bin");
61MODULE_FIRMWARE("radeon/RV635_me.bin");
62MODULE_FIRMWARE("radeon/RV670_pfp.bin");
63MODULE_FIRMWARE("radeon/RV670_me.bin");
64MODULE_FIRMWARE("radeon/RS780_pfp.bin");
65MODULE_FIRMWARE("radeon/RS780_me.bin");
66MODULE_FIRMWARE("radeon/RV770_pfp.bin");
67MODULE_FIRMWARE("radeon/RV770_me.bin");
68MODULE_FIRMWARE("radeon/RV730_pfp.bin");
69MODULE_FIRMWARE("radeon/RV730_me.bin");
70MODULE_FIRMWARE("radeon/RV710_pfp.bin");
71MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050072MODULE_FIRMWARE("radeon/R600_rlc.bin");
73MODULE_FIRMWARE("radeon/R700_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040074MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
75MODULE_FIRMWARE("radeon/CEDAR_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040076MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040077MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
78MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040079MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040080MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
81MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040082MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
Dave Airliea7433742010-04-09 15:31:09 +100083MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040084MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040085MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100086
87int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020088
Jerome Glisse1a029b72009-10-06 19:04:30 +020089/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020090int r600_mc_wait_for_idle(struct radeon_device *rdev);
91void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100092void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -040093void r600_irq_disable(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020094
Alex Deucher21a81222010-07-02 12:58:16 -040095/* get temperature in millidegrees */
96u32 rv6xx_get_temp(struct radeon_device *rdev)
97{
98 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
99 ASIC_T_SHIFT;
Alex Deucher21a81222010-07-02 12:58:16 -0400100
Alex Deucherb2298fd2010-11-08 18:39:18 +0000101 return temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400102}
103
Alex Deucherce8f5372010-05-07 15:10:16 -0400104void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400105{
106 int i;
107
Alex Deucherce8f5372010-05-07 15:10:16 -0400108 rdev->pm.dynpm_can_upclock = true;
109 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400110
111 /* power state array is low to high, default is first */
112 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
113 int min_power_state_index = 0;
114
115 if (rdev->pm.num_power_states > 2)
116 min_power_state_index = 1;
117
Alex Deucherce8f5372010-05-07 15:10:16 -0400118 switch (rdev->pm.dynpm_planned_action) {
119 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400120 rdev->pm.requested_power_state_index = min_power_state_index;
121 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400122 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400123 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400124 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400125 if (rdev->pm.current_power_state_index == min_power_state_index) {
126 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400127 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400128 } else {
129 if (rdev->pm.active_crtc_count > 1) {
130 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400131 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400132 continue;
133 else if (i >= rdev->pm.current_power_state_index) {
134 rdev->pm.requested_power_state_index =
135 rdev->pm.current_power_state_index;
136 break;
137 } else {
138 rdev->pm.requested_power_state_index = i;
139 break;
140 }
141 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400142 } else {
143 if (rdev->pm.current_power_state_index == 0)
144 rdev->pm.requested_power_state_index =
145 rdev->pm.num_power_states - 1;
146 else
147 rdev->pm.requested_power_state_index =
148 rdev->pm.current_power_state_index - 1;
149 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400150 }
151 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400152 /* don't use the power state if crtcs are active and no display flag is set */
153 if ((rdev->pm.active_crtc_count > 0) &&
154 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
155 clock_info[rdev->pm.requested_clock_mode_index].flags &
156 RADEON_PM_MODE_NO_DISPLAY)) {
157 rdev->pm.requested_power_state_index++;
158 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400159 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400160 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400161 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
162 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400163 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400164 } else {
165 if (rdev->pm.active_crtc_count > 1) {
166 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400167 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400168 continue;
169 else if (i <= rdev->pm.current_power_state_index) {
170 rdev->pm.requested_power_state_index =
171 rdev->pm.current_power_state_index;
172 break;
173 } else {
174 rdev->pm.requested_power_state_index = i;
175 break;
176 }
177 }
178 } else
179 rdev->pm.requested_power_state_index =
180 rdev->pm.current_power_state_index + 1;
181 }
182 rdev->pm.requested_clock_mode_index = 0;
183 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400184 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400185 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
186 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400187 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400188 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400189 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400190 default:
191 DRM_ERROR("Requested mode for not defined action\n");
192 return;
193 }
194 } else {
195 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
196 /* for now just select the first power state and switch between clock modes */
197 /* power state array is low to high, default is first (0) */
198 if (rdev->pm.active_crtc_count > 1) {
199 rdev->pm.requested_power_state_index = -1;
200 /* start at 1 as we don't want the default mode */
201 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400202 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400203 continue;
204 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
205 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
206 rdev->pm.requested_power_state_index = i;
207 break;
208 }
209 }
210 /* if nothing selected, grab the default state. */
211 if (rdev->pm.requested_power_state_index == -1)
212 rdev->pm.requested_power_state_index = 0;
213 } else
214 rdev->pm.requested_power_state_index = 1;
215
Alex Deucherce8f5372010-05-07 15:10:16 -0400216 switch (rdev->pm.dynpm_planned_action) {
217 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400218 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400219 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400220 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400221 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400222 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
223 if (rdev->pm.current_clock_mode_index == 0) {
224 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400225 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400226 } else
227 rdev->pm.requested_clock_mode_index =
228 rdev->pm.current_clock_mode_index - 1;
229 } else {
230 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400231 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400232 }
Alex Deucherd7311172010-05-03 01:13:14 -0400233 /* don't use the power state if crtcs are active and no display flag is set */
234 if ((rdev->pm.active_crtc_count > 0) &&
235 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
236 clock_info[rdev->pm.requested_clock_mode_index].flags &
237 RADEON_PM_MODE_NO_DISPLAY)) {
238 rdev->pm.requested_clock_mode_index++;
239 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400240 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400241 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400242 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
243 if (rdev->pm.current_clock_mode_index ==
244 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
245 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400246 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400247 } else
248 rdev->pm.requested_clock_mode_index =
249 rdev->pm.current_clock_mode_index + 1;
250 } else {
251 rdev->pm.requested_clock_mode_index =
252 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400253 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400254 }
255 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400256 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400257 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
258 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400259 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400260 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400261 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400262 default:
263 DRM_ERROR("Requested mode for not defined action\n");
264 return;
265 }
266 }
267
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000268 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400269 rdev->pm.power_state[rdev->pm.requested_power_state_index].
270 clock_info[rdev->pm.requested_clock_mode_index].sclk,
271 rdev->pm.power_state[rdev->pm.requested_power_state_index].
272 clock_info[rdev->pm.requested_clock_mode_index].mclk,
273 rdev->pm.power_state[rdev->pm.requested_power_state_index].
274 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400275}
276
Alex Deucherce8f5372010-05-07 15:10:16 -0400277static int r600_pm_get_type_index(struct radeon_device *rdev,
278 enum radeon_pm_state_type ps_type,
279 int instance)
Alex Deucherbae6b5622010-04-22 13:38:05 -0400280{
Alex Deucherce8f5372010-05-07 15:10:16 -0400281 int i;
282 int found_instance = -1;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400283
Alex Deucherce8f5372010-05-07 15:10:16 -0400284 for (i = 0; i < rdev->pm.num_power_states; i++) {
285 if (rdev->pm.power_state[i].type == ps_type) {
286 found_instance++;
287 if (found_instance == instance)
288 return i;
Alex Deuchera4248162010-04-24 14:50:23 -0400289 }
Alex Deucherce8f5372010-05-07 15:10:16 -0400290 }
291 /* return default if no match */
292 return rdev->pm.default_power_state_index;
293}
Alex Deucherbae6b5622010-04-22 13:38:05 -0400294
Alex Deucherce8f5372010-05-07 15:10:16 -0400295void rs780_pm_init_profile(struct radeon_device *rdev)
296{
297 if (rdev->pm.num_power_states == 2) {
298 /* default */
299 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
300 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
301 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
302 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
303 /* low sh */
304 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
305 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
306 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
307 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400308 /* mid sh */
309 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
310 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
311 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
312 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400313 /* high sh */
314 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
315 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
316 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
317 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
318 /* low mh */
319 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
320 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
321 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
322 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400323 /* mid mh */
324 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
325 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
326 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
327 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400328 /* high mh */
329 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
330 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
331 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
332 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
333 } else if (rdev->pm.num_power_states == 3) {
334 /* default */
335 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
336 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
337 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
338 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
339 /* low sh */
340 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
341 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
342 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
343 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400344 /* mid sh */
345 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
346 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
347 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
348 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400349 /* high sh */
350 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
351 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
352 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
353 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
354 /* low mh */
355 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
356 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
357 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
358 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400359 /* mid mh */
360 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
361 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
362 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
363 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400364 /* high mh */
365 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
366 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
367 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
368 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
369 } else {
370 /* default */
371 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
372 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
373 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
374 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
375 /* low sh */
376 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
377 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
378 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
379 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400380 /* mid sh */
381 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
382 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
383 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
384 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400385 /* high sh */
386 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
387 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
388 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
389 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
390 /* low mh */
391 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
392 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
393 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
394 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400395 /* mid mh */
396 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
397 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
398 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
399 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400400 /* high mh */
401 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
402 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
403 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
404 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
405 }
406}
407
408void r600_pm_init_profile(struct radeon_device *rdev)
409{
410 if (rdev->family == CHIP_R600) {
411 /* XXX */
412 /* default */
413 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
414 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
415 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400416 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400417 /* low sh */
418 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
419 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
420 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400421 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400422 /* mid sh */
423 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
424 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
425 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
426 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400427 /* high sh */
428 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
429 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
430 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400431 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400432 /* low mh */
433 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
435 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400436 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400437 /* mid mh */
438 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
440 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
441 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400442 /* high mh */
443 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
445 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400446 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400447 } else {
448 if (rdev->pm.num_power_states < 4) {
449 /* default */
450 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
451 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
452 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
453 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
454 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400455 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
456 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
457 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400458 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
459 /* mid sh */
460 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
461 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
462 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
463 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400464 /* high sh */
465 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
466 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
467 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
468 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
469 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400470 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
471 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400472 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400473 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
474 /* low mh */
475 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
476 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
477 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
478 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400479 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400480 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
481 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
482 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
483 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
484 } else {
485 /* default */
486 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
487 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
488 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
489 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
490 /* low sh */
491 if (rdev->flags & RADEON_IS_MOBILITY) {
492 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
493 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
494 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
495 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
496 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400497 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400498 } else {
499 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
500 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
501 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
502 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
503 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400504 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
505 }
506 /* mid sh */
507 if (rdev->flags & RADEON_IS_MOBILITY) {
508 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx =
509 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
510 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx =
511 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
512 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
513 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
514 } else {
515 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx =
516 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
517 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx =
518 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
519 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
520 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400521 }
522 /* high sh */
523 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx =
524 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
525 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx =
526 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
527 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
528 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
529 /* low mh */
530 if (rdev->flags & RADEON_IS_MOBILITY) {
531 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
532 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
533 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
534 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
535 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400536 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400537 } else {
538 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
539 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
540 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
541 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
542 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400543 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
544 }
545 /* mid mh */
546 if (rdev->flags & RADEON_IS_MOBILITY) {
547 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx =
548 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
549 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx =
550 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
551 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
552 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
553 } else {
554 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx =
555 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
556 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx =
557 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
558 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
559 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400560 }
561 /* high mh */
562 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx =
563 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
564 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx =
565 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
Alex Deucherce8f5372010-05-07 15:10:16 -0400566 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
567 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
568 }
569 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400570}
571
Alex Deucher49e02b72010-04-23 17:57:27 -0400572void r600_pm_misc(struct radeon_device *rdev)
573{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400574 int req_ps_idx = rdev->pm.requested_power_state_index;
575 int req_cm_idx = rdev->pm.requested_clock_mode_index;
576 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
577 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400578
Alex Deucher4d601732010-06-07 18:15:18 -0400579 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
580 if (voltage->voltage != rdev->pm.current_vddc) {
581 radeon_atom_set_voltage(rdev, voltage->voltage);
582 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000583 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400584 }
585 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400586}
587
Alex Deucherdef9ba92010-04-22 12:39:58 -0400588bool r600_gui_idle(struct radeon_device *rdev)
589{
590 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
591 return false;
592 else
593 return true;
594}
595
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500596/* hpd for digital panel detect/disconnect */
597bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
598{
599 bool connected = false;
600
601 if (ASIC_IS_DCE3(rdev)) {
602 switch (hpd) {
603 case RADEON_HPD_1:
604 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
605 connected = true;
606 break;
607 case RADEON_HPD_2:
608 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
609 connected = true;
610 break;
611 case RADEON_HPD_3:
612 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
613 connected = true;
614 break;
615 case RADEON_HPD_4:
616 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
617 connected = true;
618 break;
619 /* DCE 3.2 */
620 case RADEON_HPD_5:
621 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
622 connected = true;
623 break;
624 case RADEON_HPD_6:
625 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
626 connected = true;
627 break;
628 default:
629 break;
630 }
631 } else {
632 switch (hpd) {
633 case RADEON_HPD_1:
634 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
635 connected = true;
636 break;
637 case RADEON_HPD_2:
638 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
639 connected = true;
640 break;
641 case RADEON_HPD_3:
642 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
643 connected = true;
644 break;
645 default:
646 break;
647 }
648 }
649 return connected;
650}
651
652void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500653 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500654{
655 u32 tmp;
656 bool connected = r600_hpd_sense(rdev, hpd);
657
658 if (ASIC_IS_DCE3(rdev)) {
659 switch (hpd) {
660 case RADEON_HPD_1:
661 tmp = RREG32(DC_HPD1_INT_CONTROL);
662 if (connected)
663 tmp &= ~DC_HPDx_INT_POLARITY;
664 else
665 tmp |= DC_HPDx_INT_POLARITY;
666 WREG32(DC_HPD1_INT_CONTROL, tmp);
667 break;
668 case RADEON_HPD_2:
669 tmp = RREG32(DC_HPD2_INT_CONTROL);
670 if (connected)
671 tmp &= ~DC_HPDx_INT_POLARITY;
672 else
673 tmp |= DC_HPDx_INT_POLARITY;
674 WREG32(DC_HPD2_INT_CONTROL, tmp);
675 break;
676 case RADEON_HPD_3:
677 tmp = RREG32(DC_HPD3_INT_CONTROL);
678 if (connected)
679 tmp &= ~DC_HPDx_INT_POLARITY;
680 else
681 tmp |= DC_HPDx_INT_POLARITY;
682 WREG32(DC_HPD3_INT_CONTROL, tmp);
683 break;
684 case RADEON_HPD_4:
685 tmp = RREG32(DC_HPD4_INT_CONTROL);
686 if (connected)
687 tmp &= ~DC_HPDx_INT_POLARITY;
688 else
689 tmp |= DC_HPDx_INT_POLARITY;
690 WREG32(DC_HPD4_INT_CONTROL, tmp);
691 break;
692 case RADEON_HPD_5:
693 tmp = RREG32(DC_HPD5_INT_CONTROL);
694 if (connected)
695 tmp &= ~DC_HPDx_INT_POLARITY;
696 else
697 tmp |= DC_HPDx_INT_POLARITY;
698 WREG32(DC_HPD5_INT_CONTROL, tmp);
699 break;
700 /* DCE 3.2 */
701 case RADEON_HPD_6:
702 tmp = RREG32(DC_HPD6_INT_CONTROL);
703 if (connected)
704 tmp &= ~DC_HPDx_INT_POLARITY;
705 else
706 tmp |= DC_HPDx_INT_POLARITY;
707 WREG32(DC_HPD6_INT_CONTROL, tmp);
708 break;
709 default:
710 break;
711 }
712 } else {
713 switch (hpd) {
714 case RADEON_HPD_1:
715 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
716 if (connected)
717 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
718 else
719 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
720 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
721 break;
722 case RADEON_HPD_2:
723 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
724 if (connected)
725 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
726 else
727 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
728 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
729 break;
730 case RADEON_HPD_3:
731 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
732 if (connected)
733 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
734 else
735 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
736 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
737 break;
738 default:
739 break;
740 }
741 }
742}
743
744void r600_hpd_init(struct radeon_device *rdev)
745{
746 struct drm_device *dev = rdev->ddev;
747 struct drm_connector *connector;
748
749 if (ASIC_IS_DCE3(rdev)) {
750 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
751 if (ASIC_IS_DCE32(rdev))
752 tmp |= DC_HPDx_EN;
753
754 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
755 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
756 switch (radeon_connector->hpd.hpd) {
757 case RADEON_HPD_1:
758 WREG32(DC_HPD1_CONTROL, tmp);
759 rdev->irq.hpd[0] = true;
760 break;
761 case RADEON_HPD_2:
762 WREG32(DC_HPD2_CONTROL, tmp);
763 rdev->irq.hpd[1] = true;
764 break;
765 case RADEON_HPD_3:
766 WREG32(DC_HPD3_CONTROL, tmp);
767 rdev->irq.hpd[2] = true;
768 break;
769 case RADEON_HPD_4:
770 WREG32(DC_HPD4_CONTROL, tmp);
771 rdev->irq.hpd[3] = true;
772 break;
773 /* DCE 3.2 */
774 case RADEON_HPD_5:
775 WREG32(DC_HPD5_CONTROL, tmp);
776 rdev->irq.hpd[4] = true;
777 break;
778 case RADEON_HPD_6:
779 WREG32(DC_HPD6_CONTROL, tmp);
780 rdev->irq.hpd[5] = true;
781 break;
782 default:
783 break;
784 }
785 }
786 } else {
787 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
788 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
789 switch (radeon_connector->hpd.hpd) {
790 case RADEON_HPD_1:
791 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
792 rdev->irq.hpd[0] = true;
793 break;
794 case RADEON_HPD_2:
795 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
796 rdev->irq.hpd[1] = true;
797 break;
798 case RADEON_HPD_3:
799 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
800 rdev->irq.hpd[2] = true;
801 break;
802 default:
803 break;
804 }
805 }
806 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100807 if (rdev->irq.installed)
808 r600_irq_set(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500809}
810
811void r600_hpd_fini(struct radeon_device *rdev)
812{
813 struct drm_device *dev = rdev->ddev;
814 struct drm_connector *connector;
815
816 if (ASIC_IS_DCE3(rdev)) {
817 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
818 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
819 switch (radeon_connector->hpd.hpd) {
820 case RADEON_HPD_1:
821 WREG32(DC_HPD1_CONTROL, 0);
822 rdev->irq.hpd[0] = false;
823 break;
824 case RADEON_HPD_2:
825 WREG32(DC_HPD2_CONTROL, 0);
826 rdev->irq.hpd[1] = false;
827 break;
828 case RADEON_HPD_3:
829 WREG32(DC_HPD3_CONTROL, 0);
830 rdev->irq.hpd[2] = false;
831 break;
832 case RADEON_HPD_4:
833 WREG32(DC_HPD4_CONTROL, 0);
834 rdev->irq.hpd[3] = false;
835 break;
836 /* DCE 3.2 */
837 case RADEON_HPD_5:
838 WREG32(DC_HPD5_CONTROL, 0);
839 rdev->irq.hpd[4] = false;
840 break;
841 case RADEON_HPD_6:
842 WREG32(DC_HPD6_CONTROL, 0);
843 rdev->irq.hpd[5] = false;
844 break;
845 default:
846 break;
847 }
848 }
849 } else {
850 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
851 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
852 switch (radeon_connector->hpd.hpd) {
853 case RADEON_HPD_1:
854 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
855 rdev->irq.hpd[0] = false;
856 break;
857 case RADEON_HPD_2:
858 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
859 rdev->irq.hpd[1] = false;
860 break;
861 case RADEON_HPD_3:
862 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
863 rdev->irq.hpd[2] = false;
864 break;
865 default:
866 break;
867 }
868 }
869 }
870}
871
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200872/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000873 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200874 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000875void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200876{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000877 unsigned i;
878 u32 tmp;
879
Dave Airlie2e98f102010-02-15 15:54:45 +1000880 /* flush hdp cache so updates hit vram */
Alex Deucher812d0462010-07-26 18:51:53 -0400881 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740)) {
882 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
883 u32 tmp;
884
885 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
886 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
887 */
888 WREG32(HDP_DEBUG1, 0);
889 tmp = readl((void __iomem *)ptr);
890 } else
891 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +1000892
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000893 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
894 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
895 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
896 for (i = 0; i < rdev->usec_timeout; i++) {
897 /* read MC_STATUS */
898 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
899 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
900 if (tmp == 2) {
901 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
902 return;
903 }
904 if (tmp) {
905 return;
906 }
907 udelay(1);
908 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200909}
910
Jerome Glisse4aac0472009-09-14 18:29:49 +0200911int r600_pcie_gart_init(struct radeon_device *rdev)
912{
913 int r;
914
915 if (rdev->gart.table.vram.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +0000916 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +0200917 return 0;
918 }
919 /* Initialize common gart structure */
920 r = radeon_gart_init(rdev);
921 if (r)
922 return r;
923 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
924 return radeon_gart_table_vram_alloc(rdev);
925}
926
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000927int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200928{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000929 u32 tmp;
930 int r, i;
931
Jerome Glisse4aac0472009-09-14 18:29:49 +0200932 if (rdev->gart.table.vram.robj == NULL) {
933 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
934 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000935 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200936 r = radeon_gart_table_vram_pin(rdev);
937 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000938 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000939 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000940
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000941 /* Setup L2 cache */
942 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
943 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
944 EFFECTIVE_L2_QUEUE_SIZE(7));
945 WREG32(VM_L2_CNTL2, 0);
946 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
947 /* Setup TLB control */
948 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
949 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
950 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
951 ENABLE_WAIT_L2_QUERY;
952 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
953 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
954 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
955 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
956 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
957 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
958 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
959 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
960 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
961 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
962 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
963 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
964 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
965 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
966 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200967 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000968 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
969 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
970 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
971 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
972 (u32)(rdev->dummy_page.addr >> 12));
973 for (i = 1; i < 7; i++)
974 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
975
976 r600_pcie_gart_tlb_flush(rdev);
977 rdev->gart.ready = true;
978 return 0;
979}
980
981void r600_pcie_gart_disable(struct radeon_device *rdev)
982{
983 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100984 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000985
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000986 /* Disable all tables */
987 for (i = 0; i < 7; i++)
988 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
989
990 /* Disable L2 cache */
991 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
992 EFFECTIVE_L2_QUEUE_SIZE(7));
993 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
994 /* Setup L1 TLB control */
995 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
996 ENABLE_WAIT_L2_QUERY;
997 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
998 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
999 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1000 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1001 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1002 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1003 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1004 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1005 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
1006 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
1007 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1008 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1009 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
1010 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001011 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001012 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
1013 if (likely(r == 0)) {
1014 radeon_bo_kunmap(rdev->gart.table.vram.robj);
1015 radeon_bo_unpin(rdev->gart.table.vram.robj);
1016 radeon_bo_unreserve(rdev->gart.table.vram.robj);
1017 }
Jerome Glisse4aac0472009-09-14 18:29:49 +02001018 }
1019}
1020
1021void r600_pcie_gart_fini(struct radeon_device *rdev)
1022{
Jerome Glissef9274562010-03-17 14:44:29 +00001023 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001024 r600_pcie_gart_disable(rdev);
1025 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001026}
1027
Jerome Glisse1a029b72009-10-06 19:04:30 +02001028void r600_agp_enable(struct radeon_device *rdev)
1029{
1030 u32 tmp;
1031 int i;
1032
1033 /* Setup L2 cache */
1034 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1035 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1036 EFFECTIVE_L2_QUEUE_SIZE(7));
1037 WREG32(VM_L2_CNTL2, 0);
1038 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1039 /* Setup TLB control */
1040 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1041 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1042 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1043 ENABLE_WAIT_L2_QUERY;
1044 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1045 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1046 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1047 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1048 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1049 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1050 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1051 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1052 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1053 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1054 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1055 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1056 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1057 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1058 for (i = 0; i < 7; i++)
1059 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1060}
1061
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001062int r600_mc_wait_for_idle(struct radeon_device *rdev)
1063{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001064 unsigned i;
1065 u32 tmp;
1066
1067 for (i = 0; i < rdev->usec_timeout; i++) {
1068 /* read MC_STATUS */
1069 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1070 if (!tmp)
1071 return 0;
1072 udelay(1);
1073 }
1074 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001075}
1076
Jerome Glissea3c19452009-10-01 18:02:13 +02001077static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001078{
Jerome Glissea3c19452009-10-01 18:02:13 +02001079 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001080 u32 tmp;
1081 int i, j;
1082
1083 /* Initialize HDP */
1084 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1085 WREG32((0x2c14 + j), 0x00000000);
1086 WREG32((0x2c18 + j), 0x00000000);
1087 WREG32((0x2c1c + j), 0x00000000);
1088 WREG32((0x2c20 + j), 0x00000000);
1089 WREG32((0x2c24 + j), 0x00000000);
1090 }
1091 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1092
Jerome Glissea3c19452009-10-01 18:02:13 +02001093 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001094 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001095 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001096 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001097 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001098 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001099 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001100 if (rdev->flags & RADEON_IS_AGP) {
1101 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1102 /* VRAM before AGP */
1103 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1104 rdev->mc.vram_start >> 12);
1105 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1106 rdev->mc.gtt_end >> 12);
1107 } else {
1108 /* VRAM after AGP */
1109 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1110 rdev->mc.gtt_start >> 12);
1111 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1112 rdev->mc.vram_end >> 12);
1113 }
1114 } else {
1115 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1116 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1117 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001118 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001119 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001120 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1121 WREG32(MC_VM_FB_LOCATION, tmp);
1122 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1123 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001124 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001125 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001126 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1127 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001128 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1129 } else {
1130 WREG32(MC_VM_AGP_BASE, 0);
1131 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1132 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1133 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001134 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001135 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001136 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001137 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001138 /* we need to own VRAM, so turn off the VGA renderer here
1139 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001140 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141}
1142
Jerome Glissed594e462010-02-17 21:54:29 +00001143/**
1144 * r600_vram_gtt_location - try to find VRAM & GTT location
1145 * @rdev: radeon device structure holding all necessary informations
1146 * @mc: memory controller structure holding memory informations
1147 *
1148 * Function will place try to place VRAM at same place as in CPU (PCI)
1149 * address space as some GPU seems to have issue when we reprogram at
1150 * different address space.
1151 *
1152 * If there is not enough space to fit the unvisible VRAM after the
1153 * aperture then we limit the VRAM size to the aperture.
1154 *
1155 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1156 * them to be in one from GPU point of view so that we can program GPU to
1157 * catch access outside them (weird GPU policy see ??).
1158 *
1159 * This function will never fails, worst case are limiting VRAM or GTT.
1160 *
1161 * Note: GTT start, end, size should be initialized before calling this
1162 * function on AGP platform.
1163 */
1164void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1165{
1166 u64 size_bf, size_af;
1167
1168 if (mc->mc_vram_size > 0xE0000000) {
1169 /* leave room for at least 512M GTT */
1170 dev_warn(rdev->dev, "limiting VRAM\n");
1171 mc->real_vram_size = 0xE0000000;
1172 mc->mc_vram_size = 0xE0000000;
1173 }
1174 if (rdev->flags & RADEON_IS_AGP) {
1175 size_bf = mc->gtt_start;
1176 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
1177 if (size_bf > size_af) {
1178 if (mc->mc_vram_size > size_bf) {
1179 dev_warn(rdev->dev, "limiting VRAM\n");
1180 mc->real_vram_size = size_bf;
1181 mc->mc_vram_size = size_bf;
1182 }
1183 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1184 } else {
1185 if (mc->mc_vram_size > size_af) {
1186 dev_warn(rdev->dev, "limiting VRAM\n");
1187 mc->real_vram_size = size_af;
1188 mc->mc_vram_size = size_af;
1189 }
1190 mc->vram_start = mc->gtt_end;
1191 }
1192 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1193 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1194 mc->mc_vram_size >> 20, mc->vram_start,
1195 mc->vram_end, mc->real_vram_size >> 20);
1196 } else {
1197 u64 base = 0;
1198 if (rdev->flags & RADEON_IS_IGP)
1199 base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24;
1200 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001201 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001202 radeon_gtt_location(rdev, mc);
1203 }
1204}
1205
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001206int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001207{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001208 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001209 int chansize, numchan;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001210
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001211 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001212 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001213 tmp = RREG32(RAMCFG);
1214 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001215 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001216 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001217 chansize = 64;
1218 } else {
1219 chansize = 32;
1220 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001221 tmp = RREG32(CHMAP);
1222 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1223 case 0:
1224 default:
1225 numchan = 1;
1226 break;
1227 case 1:
1228 numchan = 2;
1229 break;
1230 case 2:
1231 numchan = 4;
1232 break;
1233 case 3:
1234 numchan = 8;
1235 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001236 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001237 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001238 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001239 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1240 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001241 /* Setup GPU memory space */
1242 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1243 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001244 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissec919b372010-08-10 17:41:31 -04001245 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001246 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001247
Alex Deucherf8920342010-06-30 12:02:03 -04001248 if (rdev->flags & RADEON_IS_IGP) {
1249 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001250 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Alex Deucherf8920342010-06-30 12:02:03 -04001251 }
Alex Deucherf47299c2010-03-16 20:54:38 -04001252 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001253 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254}
1255
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001256/* We doesn't check that the GPU really needs a reset we simply do the
1257 * reset, it's up to the caller to determine if the GPU needs one. We
1258 * might add an helper function to check that.
1259 */
1260int r600_gpu_soft_reset(struct radeon_device *rdev)
1261{
Jerome Glissea3c19452009-10-01 18:02:13 +02001262 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001263 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1264 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1265 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1266 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1267 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1268 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1269 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1270 S_008010_GUI_ACTIVE(1);
1271 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1272 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1273 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1274 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1275 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1276 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1277 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1278 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
Jerome Glissea3c19452009-10-01 18:02:13 +02001279 u32 tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001280
Jerome Glisse1a029b72009-10-06 19:04:30 +02001281 dev_info(rdev->dev, "GPU softreset \n");
1282 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1283 RREG32(R_008010_GRBM_STATUS));
1284 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
Jerome Glissea3c19452009-10-01 18:02:13 +02001285 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse1a029b72009-10-06 19:04:30 +02001286 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1287 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001288 rv515_mc_stop(rdev, &save);
1289 if (r600_mc_wait_for_idle(rdev)) {
1290 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1291 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001292 /* Disable CP parsing/prefetching */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001293 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001294 /* Check if any of the rendering block is busy and reset it */
1295 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
1296 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001297 tmp = S_008020_SOFT_RESET_CR(1) |
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001298 S_008020_SOFT_RESET_DB(1) |
1299 S_008020_SOFT_RESET_CB(1) |
1300 S_008020_SOFT_RESET_PA(1) |
1301 S_008020_SOFT_RESET_SC(1) |
1302 S_008020_SOFT_RESET_SMX(1) |
1303 S_008020_SOFT_RESET_SPI(1) |
1304 S_008020_SOFT_RESET_SX(1) |
1305 S_008020_SOFT_RESET_SH(1) |
1306 S_008020_SOFT_RESET_TC(1) |
1307 S_008020_SOFT_RESET_TA(1) |
1308 S_008020_SOFT_RESET_VC(1) |
Jerome Glissea3c19452009-10-01 18:02:13 +02001309 S_008020_SOFT_RESET_VGT(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001310 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
Jerome Glissea3c19452009-10-01 18:02:13 +02001311 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001312 RREG32(R_008020_GRBM_SOFT_RESET);
1313 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001314 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001315 }
1316 /* Reset CP (we always reset CP) */
Jerome Glissea3c19452009-10-01 18:02:13 +02001317 tmp = S_008020_SOFT_RESET_CP(1);
1318 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1319 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001320 RREG32(R_008020_GRBM_SOFT_RESET);
1321 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001322 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001323 /* Wait a little for things to settle down */
Jerome Glisse225758d2010-03-09 14:45:10 +00001324 mdelay(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001325 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1326 RREG32(R_008010_GRBM_STATUS));
1327 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1328 RREG32(R_008014_GRBM_STATUS2));
1329 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1330 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001331 rv515_mc_resume(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001332 return 0;
1333}
1334
Jerome Glisse225758d2010-03-09 14:45:10 +00001335bool r600_gpu_is_lockup(struct radeon_device *rdev)
1336{
1337 u32 srbm_status;
1338 u32 grbm_status;
1339 u32 grbm_status2;
1340 int r;
1341
1342 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1343 grbm_status = RREG32(R_008010_GRBM_STATUS);
1344 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1345 if (!G_008010_GUI_ACTIVE(grbm_status)) {
1346 r100_gpu_lockup_update(&rdev->config.r300.lockup, &rdev->cp);
1347 return false;
1348 }
1349 /* force CP activities */
1350 r = radeon_ring_lock(rdev, 2);
1351 if (!r) {
1352 /* PACKET2 NOP */
1353 radeon_ring_write(rdev, 0x80000000);
1354 radeon_ring_write(rdev, 0x80000000);
1355 radeon_ring_unlock_commit(rdev);
1356 }
1357 rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
1358 return r100_gpu_cp_is_lockup(rdev, &rdev->config.r300.lockup, &rdev->cp);
1359}
1360
Jerome Glissea2d07b72010-03-09 14:45:11 +00001361int r600_asic_reset(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001362{
1363 return r600_gpu_soft_reset(rdev);
1364}
1365
1366static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
1367 u32 num_backends,
1368 u32 backend_disable_mask)
1369{
1370 u32 backend_map = 0;
1371 u32 enabled_backends_mask;
1372 u32 enabled_backends_count;
1373 u32 cur_pipe;
1374 u32 swizzle_pipe[R6XX_MAX_PIPES];
1375 u32 cur_backend;
1376 u32 i;
1377
1378 if (num_tile_pipes > R6XX_MAX_PIPES)
1379 num_tile_pipes = R6XX_MAX_PIPES;
1380 if (num_tile_pipes < 1)
1381 num_tile_pipes = 1;
1382 if (num_backends > R6XX_MAX_BACKENDS)
1383 num_backends = R6XX_MAX_BACKENDS;
1384 if (num_backends < 1)
1385 num_backends = 1;
1386
1387 enabled_backends_mask = 0;
1388 enabled_backends_count = 0;
1389 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
1390 if (((backend_disable_mask >> i) & 1) == 0) {
1391 enabled_backends_mask |= (1 << i);
1392 ++enabled_backends_count;
1393 }
1394 if (enabled_backends_count == num_backends)
1395 break;
1396 }
1397
1398 if (enabled_backends_count == 0) {
1399 enabled_backends_mask = 1;
1400 enabled_backends_count = 1;
1401 }
1402
1403 if (enabled_backends_count != num_backends)
1404 num_backends = enabled_backends_count;
1405
1406 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
1407 switch (num_tile_pipes) {
1408 case 1:
1409 swizzle_pipe[0] = 0;
1410 break;
1411 case 2:
1412 swizzle_pipe[0] = 0;
1413 swizzle_pipe[1] = 1;
1414 break;
1415 case 3:
1416 swizzle_pipe[0] = 0;
1417 swizzle_pipe[1] = 1;
1418 swizzle_pipe[2] = 2;
1419 break;
1420 case 4:
1421 swizzle_pipe[0] = 0;
1422 swizzle_pipe[1] = 1;
1423 swizzle_pipe[2] = 2;
1424 swizzle_pipe[3] = 3;
1425 break;
1426 case 5:
1427 swizzle_pipe[0] = 0;
1428 swizzle_pipe[1] = 1;
1429 swizzle_pipe[2] = 2;
1430 swizzle_pipe[3] = 3;
1431 swizzle_pipe[4] = 4;
1432 break;
1433 case 6:
1434 swizzle_pipe[0] = 0;
1435 swizzle_pipe[1] = 2;
1436 swizzle_pipe[2] = 4;
1437 swizzle_pipe[3] = 5;
1438 swizzle_pipe[4] = 1;
1439 swizzle_pipe[5] = 3;
1440 break;
1441 case 7:
1442 swizzle_pipe[0] = 0;
1443 swizzle_pipe[1] = 2;
1444 swizzle_pipe[2] = 4;
1445 swizzle_pipe[3] = 6;
1446 swizzle_pipe[4] = 1;
1447 swizzle_pipe[5] = 3;
1448 swizzle_pipe[6] = 5;
1449 break;
1450 case 8:
1451 swizzle_pipe[0] = 0;
1452 swizzle_pipe[1] = 2;
1453 swizzle_pipe[2] = 4;
1454 swizzle_pipe[3] = 6;
1455 swizzle_pipe[4] = 1;
1456 swizzle_pipe[5] = 3;
1457 swizzle_pipe[6] = 5;
1458 swizzle_pipe[7] = 7;
1459 break;
1460 }
1461
1462 cur_backend = 0;
1463 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1464 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1465 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1466
1467 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
1468
1469 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1470 }
1471
1472 return backend_map;
1473}
1474
1475int r600_count_pipe_bits(uint32_t val)
1476{
1477 int i, ret = 0;
1478
1479 for (i = 0; i < 32; i++) {
1480 ret += val & 1;
1481 val >>= 1;
1482 }
1483 return ret;
1484}
1485
1486void r600_gpu_init(struct radeon_device *rdev)
1487{
1488 u32 tiling_config;
1489 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001490 u32 backend_map;
1491 u32 cc_rb_backend_disable;
1492 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001493 u32 tmp;
1494 int i, j;
1495 u32 sq_config;
1496 u32 sq_gpr_resource_mgmt_1 = 0;
1497 u32 sq_gpr_resource_mgmt_2 = 0;
1498 u32 sq_thread_resource_mgmt = 0;
1499 u32 sq_stack_resource_mgmt_1 = 0;
1500 u32 sq_stack_resource_mgmt_2 = 0;
1501
1502 /* FIXME: implement */
1503 switch (rdev->family) {
1504 case CHIP_R600:
1505 rdev->config.r600.max_pipes = 4;
1506 rdev->config.r600.max_tile_pipes = 8;
1507 rdev->config.r600.max_simds = 4;
1508 rdev->config.r600.max_backends = 4;
1509 rdev->config.r600.max_gprs = 256;
1510 rdev->config.r600.max_threads = 192;
1511 rdev->config.r600.max_stack_entries = 256;
1512 rdev->config.r600.max_hw_contexts = 8;
1513 rdev->config.r600.max_gs_threads = 16;
1514 rdev->config.r600.sx_max_export_size = 128;
1515 rdev->config.r600.sx_max_export_pos_size = 16;
1516 rdev->config.r600.sx_max_export_smx_size = 128;
1517 rdev->config.r600.sq_num_cf_insts = 2;
1518 break;
1519 case CHIP_RV630:
1520 case CHIP_RV635:
1521 rdev->config.r600.max_pipes = 2;
1522 rdev->config.r600.max_tile_pipes = 2;
1523 rdev->config.r600.max_simds = 3;
1524 rdev->config.r600.max_backends = 1;
1525 rdev->config.r600.max_gprs = 128;
1526 rdev->config.r600.max_threads = 192;
1527 rdev->config.r600.max_stack_entries = 128;
1528 rdev->config.r600.max_hw_contexts = 8;
1529 rdev->config.r600.max_gs_threads = 4;
1530 rdev->config.r600.sx_max_export_size = 128;
1531 rdev->config.r600.sx_max_export_pos_size = 16;
1532 rdev->config.r600.sx_max_export_smx_size = 128;
1533 rdev->config.r600.sq_num_cf_insts = 2;
1534 break;
1535 case CHIP_RV610:
1536 case CHIP_RV620:
1537 case CHIP_RS780:
1538 case CHIP_RS880:
1539 rdev->config.r600.max_pipes = 1;
1540 rdev->config.r600.max_tile_pipes = 1;
1541 rdev->config.r600.max_simds = 2;
1542 rdev->config.r600.max_backends = 1;
1543 rdev->config.r600.max_gprs = 128;
1544 rdev->config.r600.max_threads = 192;
1545 rdev->config.r600.max_stack_entries = 128;
1546 rdev->config.r600.max_hw_contexts = 4;
1547 rdev->config.r600.max_gs_threads = 4;
1548 rdev->config.r600.sx_max_export_size = 128;
1549 rdev->config.r600.sx_max_export_pos_size = 16;
1550 rdev->config.r600.sx_max_export_smx_size = 128;
1551 rdev->config.r600.sq_num_cf_insts = 1;
1552 break;
1553 case CHIP_RV670:
1554 rdev->config.r600.max_pipes = 4;
1555 rdev->config.r600.max_tile_pipes = 4;
1556 rdev->config.r600.max_simds = 4;
1557 rdev->config.r600.max_backends = 4;
1558 rdev->config.r600.max_gprs = 192;
1559 rdev->config.r600.max_threads = 192;
1560 rdev->config.r600.max_stack_entries = 256;
1561 rdev->config.r600.max_hw_contexts = 8;
1562 rdev->config.r600.max_gs_threads = 16;
1563 rdev->config.r600.sx_max_export_size = 128;
1564 rdev->config.r600.sx_max_export_pos_size = 16;
1565 rdev->config.r600.sx_max_export_smx_size = 128;
1566 rdev->config.r600.sq_num_cf_insts = 2;
1567 break;
1568 default:
1569 break;
1570 }
1571
1572 /* Initialize HDP */
1573 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1574 WREG32((0x2c14 + j), 0x00000000);
1575 WREG32((0x2c18 + j), 0x00000000);
1576 WREG32((0x2c1c + j), 0x00000000);
1577 WREG32((0x2c20 + j), 0x00000000);
1578 WREG32((0x2c24 + j), 0x00000000);
1579 }
1580
1581 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1582
1583 /* Setup tiling */
1584 tiling_config = 0;
1585 ramcfg = RREG32(RAMCFG);
1586 switch (rdev->config.r600.max_tile_pipes) {
1587 case 1:
1588 tiling_config |= PIPE_TILING(0);
1589 break;
1590 case 2:
1591 tiling_config |= PIPE_TILING(1);
1592 break;
1593 case 4:
1594 tiling_config |= PIPE_TILING(2);
1595 break;
1596 case 8:
1597 tiling_config |= PIPE_TILING(3);
1598 break;
1599 default:
1600 break;
1601 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001602 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001603 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001604 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04001605 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
1606 if ((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
1607 rdev->config.r600.tiling_group_size = 512;
1608 else
1609 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001610 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1611 if (tmp > 3) {
1612 tiling_config |= ROW_TILING(3);
1613 tiling_config |= SAMPLE_SPLIT(3);
1614 } else {
1615 tiling_config |= ROW_TILING(tmp);
1616 tiling_config |= SAMPLE_SPLIT(tmp);
1617 }
1618 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001619
1620 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1621 cc_rb_backend_disable |=
1622 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1623
1624 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
1625 cc_gc_shader_pipe_config |=
1626 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1627 cc_gc_shader_pipe_config |=
1628 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1629
1630 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1631 (R6XX_MAX_BACKENDS -
1632 r600_count_pipe_bits((cc_rb_backend_disable &
1633 R6XX_MAX_BACKENDS_MASK) >> 16)),
1634 (cc_rb_backend_disable >> 16));
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001635 rdev->config.r600.tile_config = tiling_config;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001636 tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001637 WREG32(GB_TILING_CONFIG, tiling_config);
1638 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1639 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1640
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001641 /* Setup pipes */
Alex Deucherd03f5d52010-02-19 16:22:31 -05001642 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1643 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -05001644 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001645
Alex Deucherd03f5d52010-02-19 16:22:31 -05001646 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 +10001647 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1648 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1649
1650 /* Setup some CP states */
1651 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1652 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1653
1654 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1655 SYNC_WALKER | SYNC_ALIGNER));
1656 /* Setup various GPU states */
1657 if (rdev->family == CHIP_RV670)
1658 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1659
1660 tmp = RREG32(SX_DEBUG_1);
1661 tmp |= SMX_EVENT_RELEASE;
1662 if ((rdev->family > CHIP_R600))
1663 tmp |= ENABLE_NEW_SMX_ADDRESS;
1664 WREG32(SX_DEBUG_1, tmp);
1665
1666 if (((rdev->family) == CHIP_R600) ||
1667 ((rdev->family) == CHIP_RV630) ||
1668 ((rdev->family) == CHIP_RV610) ||
1669 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001670 ((rdev->family) == CHIP_RS780) ||
1671 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001672 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1673 } else {
1674 WREG32(DB_DEBUG, 0);
1675 }
1676 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1677 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1678
1679 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1680 WREG32(VGT_NUM_INSTANCES, 0);
1681
1682 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1683 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1684
1685 tmp = RREG32(SQ_MS_FIFO_SIZES);
1686 if (((rdev->family) == CHIP_RV610) ||
1687 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001688 ((rdev->family) == CHIP_RS780) ||
1689 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001690 tmp = (CACHE_FIFO_SIZE(0xa) |
1691 FETCH_FIFO_HIWATER(0xa) |
1692 DONE_FIFO_HIWATER(0xe0) |
1693 ALU_UPDATE_FIFO_HIWATER(0x8));
1694 } else if (((rdev->family) == CHIP_R600) ||
1695 ((rdev->family) == CHIP_RV630)) {
1696 tmp &= ~DONE_FIFO_HIWATER(0xff);
1697 tmp |= DONE_FIFO_HIWATER(0x4);
1698 }
1699 WREG32(SQ_MS_FIFO_SIZES, tmp);
1700
1701 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1702 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1703 */
1704 sq_config = RREG32(SQ_CONFIG);
1705 sq_config &= ~(PS_PRIO(3) |
1706 VS_PRIO(3) |
1707 GS_PRIO(3) |
1708 ES_PRIO(3));
1709 sq_config |= (DX9_CONSTS |
1710 VC_ENABLE |
1711 PS_PRIO(0) |
1712 VS_PRIO(1) |
1713 GS_PRIO(2) |
1714 ES_PRIO(3));
1715
1716 if ((rdev->family) == CHIP_R600) {
1717 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1718 NUM_VS_GPRS(124) |
1719 NUM_CLAUSE_TEMP_GPRS(4));
1720 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1721 NUM_ES_GPRS(0));
1722 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1723 NUM_VS_THREADS(48) |
1724 NUM_GS_THREADS(4) |
1725 NUM_ES_THREADS(4));
1726 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1727 NUM_VS_STACK_ENTRIES(128));
1728 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1729 NUM_ES_STACK_ENTRIES(0));
1730 } else if (((rdev->family) == CHIP_RV610) ||
1731 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001732 ((rdev->family) == CHIP_RS780) ||
1733 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001734 /* no vertex cache */
1735 sq_config &= ~VC_ENABLE;
1736
1737 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1738 NUM_VS_GPRS(44) |
1739 NUM_CLAUSE_TEMP_GPRS(2));
1740 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1741 NUM_ES_GPRS(17));
1742 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1743 NUM_VS_THREADS(78) |
1744 NUM_GS_THREADS(4) |
1745 NUM_ES_THREADS(31));
1746 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1747 NUM_VS_STACK_ENTRIES(40));
1748 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1749 NUM_ES_STACK_ENTRIES(16));
1750 } else if (((rdev->family) == CHIP_RV630) ||
1751 ((rdev->family) == CHIP_RV635)) {
1752 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1753 NUM_VS_GPRS(44) |
1754 NUM_CLAUSE_TEMP_GPRS(2));
1755 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1756 NUM_ES_GPRS(18));
1757 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1758 NUM_VS_THREADS(78) |
1759 NUM_GS_THREADS(4) |
1760 NUM_ES_THREADS(31));
1761 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1762 NUM_VS_STACK_ENTRIES(40));
1763 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1764 NUM_ES_STACK_ENTRIES(16));
1765 } else if ((rdev->family) == CHIP_RV670) {
1766 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1767 NUM_VS_GPRS(44) |
1768 NUM_CLAUSE_TEMP_GPRS(2));
1769 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1770 NUM_ES_GPRS(17));
1771 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1772 NUM_VS_THREADS(78) |
1773 NUM_GS_THREADS(4) |
1774 NUM_ES_THREADS(31));
1775 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1776 NUM_VS_STACK_ENTRIES(64));
1777 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1778 NUM_ES_STACK_ENTRIES(64));
1779 }
1780
1781 WREG32(SQ_CONFIG, sq_config);
1782 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1783 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1784 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1785 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1786 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1787
1788 if (((rdev->family) == CHIP_RV610) ||
1789 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001790 ((rdev->family) == CHIP_RS780) ||
1791 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001792 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1793 } else {
1794 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1795 }
1796
1797 /* More default values. 2D/3D driver should adjust as needed */
1798 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1799 S1_X(0x4) | S1_Y(0xc)));
1800 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1801 S1_X(0x2) | S1_Y(0x2) |
1802 S2_X(0xa) | S2_Y(0x6) |
1803 S3_X(0x6) | S3_Y(0xa)));
1804 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1805 S1_X(0x4) | S1_Y(0xc) |
1806 S2_X(0x1) | S2_Y(0x6) |
1807 S3_X(0xa) | S3_Y(0xe)));
1808 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1809 S5_X(0x0) | S5_Y(0x0) |
1810 S6_X(0xb) | S6_Y(0x4) |
1811 S7_X(0x7) | S7_Y(0x8)));
1812
1813 WREG32(VGT_STRMOUT_EN, 0);
1814 tmp = rdev->config.r600.max_pipes * 16;
1815 switch (rdev->family) {
1816 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001817 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001818 case CHIP_RS780:
1819 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001820 tmp += 32;
1821 break;
1822 case CHIP_RV670:
1823 tmp += 128;
1824 break;
1825 default:
1826 break;
1827 }
1828 if (tmp > 256) {
1829 tmp = 256;
1830 }
1831 WREG32(VGT_ES_PER_GS, 128);
1832 WREG32(VGT_GS_PER_ES, tmp);
1833 WREG32(VGT_GS_PER_VS, 2);
1834 WREG32(VGT_GS_VERTEX_REUSE, 16);
1835
1836 /* more default values. 2D/3D driver should adjust as needed */
1837 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1838 WREG32(VGT_STRMOUT_EN, 0);
1839 WREG32(SX_MISC, 0);
1840 WREG32(PA_SC_MODE_CNTL, 0);
1841 WREG32(PA_SC_AA_CONFIG, 0);
1842 WREG32(PA_SC_LINE_STIPPLE, 0);
1843 WREG32(SPI_INPUT_Z, 0);
1844 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1845 WREG32(CB_COLOR7_FRAG, 0);
1846
1847 /* Clear render buffer base addresses */
1848 WREG32(CB_COLOR0_BASE, 0);
1849 WREG32(CB_COLOR1_BASE, 0);
1850 WREG32(CB_COLOR2_BASE, 0);
1851 WREG32(CB_COLOR3_BASE, 0);
1852 WREG32(CB_COLOR4_BASE, 0);
1853 WREG32(CB_COLOR5_BASE, 0);
1854 WREG32(CB_COLOR6_BASE, 0);
1855 WREG32(CB_COLOR7_BASE, 0);
1856 WREG32(CB_COLOR7_FRAG, 0);
1857
1858 switch (rdev->family) {
1859 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001860 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001861 case CHIP_RS780:
1862 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001863 tmp = TC_L2_SIZE(8);
1864 break;
1865 case CHIP_RV630:
1866 case CHIP_RV635:
1867 tmp = TC_L2_SIZE(4);
1868 break;
1869 case CHIP_R600:
1870 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1871 break;
1872 default:
1873 tmp = TC_L2_SIZE(0);
1874 break;
1875 }
1876 WREG32(TC_CNTL, tmp);
1877
1878 tmp = RREG32(HDP_HOST_PATH_CNTL);
1879 WREG32(HDP_HOST_PATH_CNTL, tmp);
1880
1881 tmp = RREG32(ARB_POP);
1882 tmp |= ENABLE_TC128;
1883 WREG32(ARB_POP, tmp);
1884
1885 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1886 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1887 NUM_CLIP_SEQ(3)));
1888 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1889}
1890
1891
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001892/*
1893 * Indirect registers accessor
1894 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001895u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001896{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001897 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001898
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001899 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1900 (void)RREG32(PCIE_PORT_INDEX);
1901 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001902 return r;
1903}
1904
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001905void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001906{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001907 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1908 (void)RREG32(PCIE_PORT_INDEX);
1909 WREG32(PCIE_PORT_DATA, (v));
1910 (void)RREG32(PCIE_PORT_DATA);
1911}
1912
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001913/*
1914 * CP & Ring
1915 */
1916void r600_cp_stop(struct radeon_device *rdev)
1917{
Jerome Glissec919b372010-08-10 17:41:31 -04001918 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001919 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04001920 WREG32(SCRATCH_UMSK, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001921}
1922
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001923int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001924{
1925 struct platform_device *pdev;
1926 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001927 const char *rlc_chip_name;
1928 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001929 char fw_name[30];
1930 int err;
1931
1932 DRM_DEBUG("\n");
1933
1934 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1935 err = IS_ERR(pdev);
1936 if (err) {
1937 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1938 return -EINVAL;
1939 }
1940
1941 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001942 case CHIP_R600:
1943 chip_name = "R600";
1944 rlc_chip_name = "R600";
1945 break;
1946 case CHIP_RV610:
1947 chip_name = "RV610";
1948 rlc_chip_name = "R600";
1949 break;
1950 case CHIP_RV630:
1951 chip_name = "RV630";
1952 rlc_chip_name = "R600";
1953 break;
1954 case CHIP_RV620:
1955 chip_name = "RV620";
1956 rlc_chip_name = "R600";
1957 break;
1958 case CHIP_RV635:
1959 chip_name = "RV635";
1960 rlc_chip_name = "R600";
1961 break;
1962 case CHIP_RV670:
1963 chip_name = "RV670";
1964 rlc_chip_name = "R600";
1965 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001966 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001967 case CHIP_RS880:
1968 chip_name = "RS780";
1969 rlc_chip_name = "R600";
1970 break;
1971 case CHIP_RV770:
1972 chip_name = "RV770";
1973 rlc_chip_name = "R700";
1974 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001975 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001976 case CHIP_RV740:
1977 chip_name = "RV730";
1978 rlc_chip_name = "R700";
1979 break;
1980 case CHIP_RV710:
1981 chip_name = "RV710";
1982 rlc_chip_name = "R700";
1983 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04001984 case CHIP_CEDAR:
1985 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04001986 rlc_chip_name = "CEDAR";
Alex Deucherfe251e22010-03-24 13:36:43 -04001987 break;
1988 case CHIP_REDWOOD:
1989 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04001990 rlc_chip_name = "REDWOOD";
Alex Deucherfe251e22010-03-24 13:36:43 -04001991 break;
1992 case CHIP_JUNIPER:
1993 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04001994 rlc_chip_name = "JUNIPER";
Alex Deucherfe251e22010-03-24 13:36:43 -04001995 break;
1996 case CHIP_CYPRESS:
1997 case CHIP_HEMLOCK:
1998 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04001999 rlc_chip_name = "CYPRESS";
Alex Deucherfe251e22010-03-24 13:36:43 -04002000 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002001 default: BUG();
2002 }
2003
Alex Deucherfe251e22010-03-24 13:36:43 -04002004 if (rdev->family >= CHIP_CEDAR) {
2005 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2006 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002007 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002008 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002009 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2010 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002011 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002012 } else {
2013 pfp_req_size = PFP_UCODE_SIZE * 4;
2014 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002015 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002016 }
2017
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002018 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002019
2020 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2021 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
2022 if (err)
2023 goto out;
2024 if (rdev->pfp_fw->size != pfp_req_size) {
2025 printk(KERN_ERR
2026 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2027 rdev->pfp_fw->size, fw_name);
2028 err = -EINVAL;
2029 goto out;
2030 }
2031
2032 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2033 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
2034 if (err)
2035 goto out;
2036 if (rdev->me_fw->size != me_req_size) {
2037 printk(KERN_ERR
2038 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2039 rdev->me_fw->size, fw_name);
2040 err = -EINVAL;
2041 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002042
2043 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
2044 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
2045 if (err)
2046 goto out;
2047 if (rdev->rlc_fw->size != rlc_req_size) {
2048 printk(KERN_ERR
2049 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2050 rdev->rlc_fw->size, fw_name);
2051 err = -EINVAL;
2052 }
2053
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002054out:
2055 platform_device_unregister(pdev);
2056
2057 if (err) {
2058 if (err != -EINVAL)
2059 printk(KERN_ERR
2060 "r600_cp: Failed to load firmware \"%s\"\n",
2061 fw_name);
2062 release_firmware(rdev->pfp_fw);
2063 rdev->pfp_fw = NULL;
2064 release_firmware(rdev->me_fw);
2065 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002066 release_firmware(rdev->rlc_fw);
2067 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002068 }
2069 return err;
2070}
2071
2072static int r600_cp_load_microcode(struct radeon_device *rdev)
2073{
2074 const __be32 *fw_data;
2075 int i;
2076
2077 if (!rdev->me_fw || !rdev->pfp_fw)
2078 return -EINVAL;
2079
2080 r600_cp_stop(rdev);
2081
2082 WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
2083
2084 /* Reset cp */
2085 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2086 RREG32(GRBM_SOFT_RESET);
2087 mdelay(15);
2088 WREG32(GRBM_SOFT_RESET, 0);
2089
2090 WREG32(CP_ME_RAM_WADDR, 0);
2091
2092 fw_data = (const __be32 *)rdev->me_fw->data;
2093 WREG32(CP_ME_RAM_WADDR, 0);
2094 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
2095 WREG32(CP_ME_RAM_DATA,
2096 be32_to_cpup(fw_data++));
2097
2098 fw_data = (const __be32 *)rdev->pfp_fw->data;
2099 WREG32(CP_PFP_UCODE_ADDR, 0);
2100 for (i = 0; i < PFP_UCODE_SIZE; i++)
2101 WREG32(CP_PFP_UCODE_DATA,
2102 be32_to_cpup(fw_data++));
2103
2104 WREG32(CP_PFP_UCODE_ADDR, 0);
2105 WREG32(CP_ME_RAM_WADDR, 0);
2106 WREG32(CP_ME_RAM_RADDR, 0);
2107 return 0;
2108}
2109
2110int r600_cp_start(struct radeon_device *rdev)
2111{
2112 int r;
2113 uint32_t cp_me;
2114
2115 r = radeon_ring_lock(rdev, 7);
2116 if (r) {
2117 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2118 return r;
2119 }
2120 radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
2121 radeon_ring_write(rdev, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002122 if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002123 radeon_ring_write(rdev, 0x0);
2124 radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002125 } else {
2126 radeon_ring_write(rdev, 0x3);
2127 radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002128 }
2129 radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2130 radeon_ring_write(rdev, 0);
2131 radeon_ring_write(rdev, 0);
2132 radeon_ring_unlock_commit(rdev);
2133
2134 cp_me = 0xff;
2135 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2136 return 0;
2137}
2138
2139int r600_cp_resume(struct radeon_device *rdev)
2140{
2141 u32 tmp;
2142 u32 rb_bufsz;
2143 int r;
2144
2145 /* Reset cp */
2146 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2147 RREG32(GRBM_SOFT_RESET);
2148 mdelay(15);
2149 WREG32(GRBM_SOFT_RESET, 0);
2150
2151 /* Set ring buffer size */
2152 rb_bufsz = drm_order(rdev->cp.ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04002153 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002154#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002155 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002156#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002157 WREG32(CP_RB_CNTL, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002158 WREG32(CP_SEM_WAIT_TIMER, 0x4);
2159
2160 /* Set the write pointer delay */
2161 WREG32(CP_RB_WPTR_DELAY, 0);
2162
2163 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002164 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2165 WREG32(CP_RB_RPTR_WR, 0);
2166 WREG32(CP_RB_WPTR, 0);
Alex Deucher724c80e2010-08-27 18:25:25 -04002167
2168 /* set the wb address whether it's enabled or not */
2169 WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
2170 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2171 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2172
2173 if (rdev->wb.enabled)
2174 WREG32(SCRATCH_UMSK, 0xff);
2175 else {
2176 tmp |= RB_NO_UPDATE;
2177 WREG32(SCRATCH_UMSK, 0);
2178 }
2179
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002180 mdelay(1);
2181 WREG32(CP_RB_CNTL, tmp);
2182
2183 WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
2184 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2185
2186 rdev->cp.rptr = RREG32(CP_RB_RPTR);
2187 rdev->cp.wptr = RREG32(CP_RB_WPTR);
2188
2189 r600_cp_start(rdev);
2190 rdev->cp.ready = true;
2191 r = radeon_ring_test(rdev);
2192 if (r) {
2193 rdev->cp.ready = false;
2194 return r;
2195 }
2196 return 0;
2197}
2198
2199void r600_cp_commit(struct radeon_device *rdev)
2200{
2201 WREG32(CP_RB_WPTR, rdev->cp.wptr);
2202 (void)RREG32(CP_RB_WPTR);
2203}
2204
2205void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
2206{
2207 u32 rb_bufsz;
2208
2209 /* Align ring size */
2210 rb_bufsz = drm_order(ring_size / 8);
2211 ring_size = (1 << (rb_bufsz + 1)) * 4;
2212 rdev->cp.ring_size = ring_size;
2213 rdev->cp.align_mask = 16 - 1;
2214}
2215
Jerome Glisse655efd32010-02-02 11:51:45 +01002216void r600_cp_fini(struct radeon_device *rdev)
2217{
2218 r600_cp_stop(rdev);
2219 radeon_ring_fini(rdev);
2220}
2221
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002222
2223/*
2224 * GPU scratch registers helpers function.
2225 */
2226void r600_scratch_init(struct radeon_device *rdev)
2227{
2228 int i;
2229
2230 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002231 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002232 for (i = 0; i < rdev->scratch.num_reg; i++) {
2233 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002234 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002235 }
2236}
2237
2238int r600_ring_test(struct radeon_device *rdev)
2239{
2240 uint32_t scratch;
2241 uint32_t tmp = 0;
2242 unsigned i;
2243 int r;
2244
2245 r = radeon_scratch_get(rdev, &scratch);
2246 if (r) {
2247 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2248 return r;
2249 }
2250 WREG32(scratch, 0xCAFEDEAD);
2251 r = radeon_ring_lock(rdev, 3);
2252 if (r) {
2253 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2254 radeon_scratch_free(rdev, scratch);
2255 return r;
2256 }
2257 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2258 radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2259 radeon_ring_write(rdev, 0xDEADBEEF);
2260 radeon_ring_unlock_commit(rdev);
2261 for (i = 0; i < rdev->usec_timeout; i++) {
2262 tmp = RREG32(scratch);
2263 if (tmp == 0xDEADBEEF)
2264 break;
2265 DRM_UDELAY(1);
2266 }
2267 if (i < rdev->usec_timeout) {
2268 DRM_INFO("ring test succeeded in %d usecs\n", i);
2269 } else {
2270 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
2271 scratch, tmp);
2272 r = -EINVAL;
2273 }
2274 radeon_scratch_free(rdev, scratch);
2275 return r;
2276}
2277
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002278void r600_fence_ring_emit(struct radeon_device *rdev,
2279 struct radeon_fence *fence)
2280{
Alex Deucherd0f8a852010-09-04 05:04:34 -04002281 if (rdev->wb.use_event) {
2282 u64 addr = rdev->wb.gpu_addr + R600_WB_EVENT_OFFSET +
2283 (u64)(rdev->fence_drv.scratch_reg - rdev->scratch.reg_base);
2284 /* EVENT_WRITE_EOP - flush caches, send int */
2285 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2286 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2287 radeon_ring_write(rdev, addr & 0xffffffff);
2288 radeon_ring_write(rdev, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2289 radeon_ring_write(rdev, fence->seq);
2290 radeon_ring_write(rdev, 0);
2291 } else {
2292 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
2293 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
2294 /* wait for 3D idle clean */
2295 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2296 radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2297 radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
2298 /* Emit fence sequence & fire IRQ */
2299 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2300 radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2301 radeon_ring_write(rdev, fence->seq);
2302 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2303 radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
2304 radeon_ring_write(rdev, RB_INT_STAT);
2305 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002306}
2307
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002308int r600_copy_blit(struct radeon_device *rdev,
2309 uint64_t src_offset, uint64_t dst_offset,
2310 unsigned num_pages, struct radeon_fence *fence)
2311{
Jerome Glisseff82f052010-01-22 15:19:00 +01002312 int r;
2313
2314 mutex_lock(&rdev->r600_blit.mutex);
2315 rdev->r600_blit.vb_ib = NULL;
2316 r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
2317 if (r) {
2318 if (rdev->r600_blit.vb_ib)
2319 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
2320 mutex_unlock(&rdev->r600_blit.mutex);
2321 return r;
2322 }
Matt Turnera77f1712009-10-14 00:34:41 -04002323 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002324 r600_blit_done_copy(rdev, fence);
Jerome Glisseff82f052010-01-22 15:19:00 +01002325 mutex_unlock(&rdev->r600_blit.mutex);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002326 return 0;
2327}
2328
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002329int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2330 uint32_t tiling_flags, uint32_t pitch,
2331 uint32_t offset, uint32_t obj_size)
2332{
2333 /* FIXME: implement */
2334 return 0;
2335}
2336
2337void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2338{
2339 /* FIXME: implement */
2340}
2341
2342
2343bool r600_card_posted(struct radeon_device *rdev)
2344{
2345 uint32_t reg;
2346
2347 /* first check CRTCs */
2348 reg = RREG32(D1CRTC_CONTROL) |
2349 RREG32(D2CRTC_CONTROL);
2350 if (reg & CRTC_EN)
2351 return true;
2352
2353 /* then check MEM_SIZE, in case the crtcs are off */
2354 if (RREG32(CONFIG_MEMSIZE))
2355 return true;
2356
2357 return false;
2358}
2359
Dave Airliefc30b8e2009-09-18 15:19:37 +10002360int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002361{
2362 int r;
2363
Alex Deucher779720a2009-12-09 19:31:44 -05002364 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2365 r = r600_init_microcode(rdev);
2366 if (r) {
2367 DRM_ERROR("Failed to load firmware!\n");
2368 return r;
2369 }
2370 }
2371
Jerome Glissea3c19452009-10-01 18:02:13 +02002372 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02002373 if (rdev->flags & RADEON_IS_AGP) {
2374 r600_agp_enable(rdev);
2375 } else {
2376 r = r600_pcie_gart_enable(rdev);
2377 if (r)
2378 return r;
2379 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002380 r600_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01002381 r = r600_blit_init(rdev);
2382 if (r) {
2383 r600_blit_fini(rdev);
2384 rdev->asic->copy = NULL;
2385 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2386 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04002387
Alex Deucher724c80e2010-08-27 18:25:25 -04002388 /* allocate wb buffer */
2389 r = radeon_wb_init(rdev);
2390 if (r)
2391 return r;
2392
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002393 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002394 r = r600_irq_init(rdev);
2395 if (r) {
2396 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2397 radeon_irq_kms_fini(rdev);
2398 return r;
2399 }
2400 r600_irq_set(rdev);
2401
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002402 r = radeon_ring_init(rdev, rdev->cp.ring_size);
2403 if (r)
2404 return r;
2405 r = r600_cp_load_microcode(rdev);
2406 if (r)
2407 return r;
2408 r = r600_cp_resume(rdev);
2409 if (r)
2410 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04002411
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002412 return 0;
2413}
2414
Dave Airlie28d52042009-09-21 14:33:58 +10002415void r600_vga_set_state(struct radeon_device *rdev, bool state)
2416{
2417 uint32_t temp;
2418
2419 temp = RREG32(CONFIG_CNTL);
2420 if (state == false) {
2421 temp &= ~(1<<0);
2422 temp |= (1<<1);
2423 } else {
2424 temp &= ~(1<<1);
2425 }
2426 WREG32(CONFIG_CNTL, temp);
2427}
2428
Dave Airliefc30b8e2009-09-18 15:19:37 +10002429int r600_resume(struct radeon_device *rdev)
2430{
2431 int r;
2432
Jerome Glisse1a029b72009-10-06 19:04:30 +02002433 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2434 * posting will perform necessary task to bring back GPU into good
2435 * shape.
2436 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002437 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002438 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002439
2440 r = r600_startup(rdev);
2441 if (r) {
2442 DRM_ERROR("r600 startup failed on resume\n");
2443 return r;
2444 }
2445
Jerome Glisse62a8ea32009-10-01 18:02:11 +02002446 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002447 if (r) {
2448 DRM_ERROR("radeon: failled testing IB (%d).\n", r);
2449 return r;
2450 }
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002451
2452 r = r600_audio_init(rdev);
2453 if (r) {
2454 DRM_ERROR("radeon: audio resume failed\n");
2455 return r;
2456 }
2457
Dave Airliefc30b8e2009-09-18 15:19:37 +10002458 return r;
2459}
2460
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002461int r600_suspend(struct radeon_device *rdev)
2462{
Jerome Glisse4c788672009-11-20 14:29:23 +01002463 int r;
2464
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002465 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002466 /* FIXME: we should wait for ring to be empty */
2467 r600_cp_stop(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002468 rdev->cp.ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01002469 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002470 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002471 r600_pcie_gart_disable(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002472 /* unpin shaders bo */
Jerome Glisse30d2d9a2010-01-13 10:29:27 +01002473 if (rdev->r600_blit.shader_obj) {
2474 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
2475 if (!r) {
2476 radeon_bo_unpin(rdev->r600_blit.shader_obj);
2477 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
2478 }
2479 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002480 return 0;
2481}
2482
2483/* Plan is to move initialization in that function and use
2484 * helper function so that radeon_device_init pretty much
2485 * do nothing more than calling asic specific function. This
2486 * should also allow to remove a bunch of callback function
2487 * like vram_info.
2488 */
2489int r600_init(struct radeon_device *rdev)
2490{
2491 int r;
2492
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002493 r = radeon_dummy_page_init(rdev);
2494 if (r)
2495 return r;
2496 if (r600_debugfs_mc_info_init(rdev)) {
2497 DRM_ERROR("Failed to register debugfs file for mc !\n");
2498 }
2499 /* This don't do much */
2500 r = radeon_gem_init(rdev);
2501 if (r)
2502 return r;
2503 /* Read BIOS */
2504 if (!radeon_get_bios(rdev)) {
2505 if (ASIC_IS_AVIVO(rdev))
2506 return -EINVAL;
2507 }
2508 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002509 if (!rdev->is_atom_bios) {
2510 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002511 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002512 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002513 r = radeon_atombios_init(rdev);
2514 if (r)
2515 return r;
2516 /* Post card if necessary */
Dave Airlie72542d72009-12-01 14:06:31 +10002517 if (!r600_card_posted(rdev)) {
2518 if (!rdev->bios) {
2519 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2520 return -EINVAL;
2521 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002522 DRM_INFO("GPU not posted. posting now...\n");
2523 atom_asic_init(rdev->mode_info.atom_context);
2524 }
2525 /* Initialize scratch registers */
2526 r600_scratch_init(rdev);
2527 /* Initialize surface registers */
2528 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002529 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002530 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002531 /* Fence driver */
2532 r = radeon_fence_driver_init(rdev);
2533 if (r)
2534 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01002535 if (rdev->flags & RADEON_IS_AGP) {
2536 r = radeon_agp_init(rdev);
2537 if (r)
2538 radeon_agp_disable(rdev);
2539 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002540 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002541 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002542 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002543 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002544 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002545 if (r)
2546 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002547
2548 r = radeon_irq_kms_init(rdev);
2549 if (r)
2550 return r;
2551
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002552 rdev->cp.ring_obj = NULL;
2553 r600_ring_init(rdev, 1024 * 1024);
2554
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002555 rdev->ih.ring_obj = NULL;
2556 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002557
Jerome Glisse4aac0472009-09-14 18:29:49 +02002558 r = r600_pcie_gart_init(rdev);
2559 if (r)
2560 return r;
2561
Alex Deucher779720a2009-12-09 19:31:44 -05002562 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002563 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002564 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01002565 dev_err(rdev->dev, "disabling GPU acceleration\n");
2566 r600_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002567 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002568 radeon_wb_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002569 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002570 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002571 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002572 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002573 if (rdev->accel_working) {
2574 r = radeon_ib_pool_init(rdev);
2575 if (r) {
Jerome Glissedb963802010-01-17 21:21:56 +01002576 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02002577 rdev->accel_working = false;
Jerome Glissedb963802010-01-17 21:21:56 +01002578 } else {
2579 r = r600_ib_test(rdev);
2580 if (r) {
2581 dev_err(rdev->dev, "IB test failed (%d).\n", r);
2582 rdev->accel_working = false;
2583 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002584 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002585 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002586
2587 r = r600_audio_init(rdev);
2588 if (r)
2589 return r; /* TODO error handling */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002590 return 0;
2591}
2592
2593void r600_fini(struct radeon_device *rdev)
2594{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002595 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002596 r600_blit_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002597 r600_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002598 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04002599 radeon_wb_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002600 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002601 r600_pcie_gart_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002602 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002603 radeon_gem_fini(rdev);
2604 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002605 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002606 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002607 kfree(rdev->bios);
2608 rdev->bios = NULL;
2609 radeon_dummy_page_fini(rdev);
2610}
2611
2612
2613/*
2614 * CS stuff
2615 */
2616void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2617{
2618 /* FIXME: implement */
2619 radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2620 radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
2621 radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
2622 radeon_ring_write(rdev, ib->length_dw);
2623}
2624
2625int r600_ib_test(struct radeon_device *rdev)
2626{
2627 struct radeon_ib *ib;
2628 uint32_t scratch;
2629 uint32_t tmp = 0;
2630 unsigned i;
2631 int r;
2632
2633 r = radeon_scratch_get(rdev, &scratch);
2634 if (r) {
2635 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2636 return r;
2637 }
2638 WREG32(scratch, 0xCAFEDEAD);
2639 r = radeon_ib_get(rdev, &ib);
2640 if (r) {
2641 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2642 return r;
2643 }
2644 ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2645 ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2646 ib->ptr[2] = 0xDEADBEEF;
2647 ib->ptr[3] = PACKET2(0);
2648 ib->ptr[4] = PACKET2(0);
2649 ib->ptr[5] = PACKET2(0);
2650 ib->ptr[6] = PACKET2(0);
2651 ib->ptr[7] = PACKET2(0);
2652 ib->ptr[8] = PACKET2(0);
2653 ib->ptr[9] = PACKET2(0);
2654 ib->ptr[10] = PACKET2(0);
2655 ib->ptr[11] = PACKET2(0);
2656 ib->ptr[12] = PACKET2(0);
2657 ib->ptr[13] = PACKET2(0);
2658 ib->ptr[14] = PACKET2(0);
2659 ib->ptr[15] = PACKET2(0);
2660 ib->length_dw = 16;
2661 r = radeon_ib_schedule(rdev, ib);
2662 if (r) {
2663 radeon_scratch_free(rdev, scratch);
2664 radeon_ib_free(rdev, &ib);
2665 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2666 return r;
2667 }
2668 r = radeon_fence_wait(ib->fence, false);
2669 if (r) {
2670 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2671 return r;
2672 }
2673 for (i = 0; i < rdev->usec_timeout; i++) {
2674 tmp = RREG32(scratch);
2675 if (tmp == 0xDEADBEEF)
2676 break;
2677 DRM_UDELAY(1);
2678 }
2679 if (i < rdev->usec_timeout) {
2680 DRM_INFO("ib test succeeded in %u usecs\n", i);
2681 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01002682 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002683 scratch, tmp);
2684 r = -EINVAL;
2685 }
2686 radeon_scratch_free(rdev, scratch);
2687 radeon_ib_free(rdev, &ib);
2688 return r;
2689}
2690
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002691/*
2692 * Interrupts
2693 *
2694 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2695 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2696 * writing to the ring and the GPU consuming, the GPU writes to the ring
2697 * and host consumes. As the host irq handler processes interrupts, it
2698 * increments the rptr. When the rptr catches up with the wptr, all the
2699 * current interrupts have been processed.
2700 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002701
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002702void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2703{
2704 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002705
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002706 /* Align ring size */
2707 rb_bufsz = drm_order(ring_size / 4);
2708 ring_size = (1 << rb_bufsz) * 4;
2709 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01002710 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
2711 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002712}
2713
Jerome Glisse0c452492010-01-15 14:44:37 +01002714static int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002715{
2716 int r;
2717
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002718 /* Allocate ring buffer */
2719 if (rdev->ih.ring_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002720 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05002721 PAGE_SIZE, true,
Jerome Glisse4c788672009-11-20 14:29:23 +01002722 RADEON_GEM_DOMAIN_GTT,
2723 &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002724 if (r) {
2725 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2726 return r;
2727 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002728 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2729 if (unlikely(r != 0))
2730 return r;
2731 r = radeon_bo_pin(rdev->ih.ring_obj,
2732 RADEON_GEM_DOMAIN_GTT,
2733 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002734 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002735 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002736 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2737 return r;
2738 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002739 r = radeon_bo_kmap(rdev->ih.ring_obj,
2740 (void **)&rdev->ih.ring);
2741 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002742 if (r) {
2743 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2744 return r;
2745 }
2746 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002747 return 0;
2748}
2749
2750static void r600_ih_ring_fini(struct radeon_device *rdev)
2751{
Jerome Glisse4c788672009-11-20 14:29:23 +01002752 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002753 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002754 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2755 if (likely(r == 0)) {
2756 radeon_bo_kunmap(rdev->ih.ring_obj);
2757 radeon_bo_unpin(rdev->ih.ring_obj);
2758 radeon_bo_unreserve(rdev->ih.ring_obj);
2759 }
2760 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002761 rdev->ih.ring = NULL;
2762 rdev->ih.ring_obj = NULL;
2763 }
2764}
2765
Alex Deucher45f9a392010-03-24 13:55:51 -04002766void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002767{
2768
Alex Deucher45f9a392010-03-24 13:55:51 -04002769 if ((rdev->family >= CHIP_RV770) &&
2770 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002771 /* r7xx asics need to soft reset RLC before halting */
2772 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2773 RREG32(SRBM_SOFT_RESET);
2774 udelay(15000);
2775 WREG32(SRBM_SOFT_RESET, 0);
2776 RREG32(SRBM_SOFT_RESET);
2777 }
2778
2779 WREG32(RLC_CNTL, 0);
2780}
2781
2782static void r600_rlc_start(struct radeon_device *rdev)
2783{
2784 WREG32(RLC_CNTL, RLC_ENABLE);
2785}
2786
2787static int r600_rlc_init(struct radeon_device *rdev)
2788{
2789 u32 i;
2790 const __be32 *fw_data;
2791
2792 if (!rdev->rlc_fw)
2793 return -EINVAL;
2794
2795 r600_rlc_stop(rdev);
2796
2797 WREG32(RLC_HB_BASE, 0);
2798 WREG32(RLC_HB_CNTL, 0);
2799 WREG32(RLC_HB_RPTR, 0);
2800 WREG32(RLC_HB_WPTR, 0);
2801 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2802 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2803 WREG32(RLC_MC_CNTL, 0);
2804 WREG32(RLC_UCODE_CNTL, 0);
2805
2806 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucher45f9a392010-03-24 13:55:51 -04002807 if (rdev->family >= CHIP_CEDAR) {
2808 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
2809 WREG32(RLC_UCODE_ADDR, i);
2810 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2811 }
2812 } else if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002813 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2814 WREG32(RLC_UCODE_ADDR, i);
2815 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2816 }
2817 } else {
2818 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2819 WREG32(RLC_UCODE_ADDR, i);
2820 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2821 }
2822 }
2823 WREG32(RLC_UCODE_ADDR, 0);
2824
2825 r600_rlc_start(rdev);
2826
2827 return 0;
2828}
2829
2830static void r600_enable_interrupts(struct radeon_device *rdev)
2831{
2832 u32 ih_cntl = RREG32(IH_CNTL);
2833 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2834
2835 ih_cntl |= ENABLE_INTR;
2836 ih_rb_cntl |= IH_RB_ENABLE;
2837 WREG32(IH_CNTL, ih_cntl);
2838 WREG32(IH_RB_CNTL, ih_rb_cntl);
2839 rdev->ih.enabled = true;
2840}
2841
Alex Deucher45f9a392010-03-24 13:55:51 -04002842void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002843{
2844 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2845 u32 ih_cntl = RREG32(IH_CNTL);
2846
2847 ih_rb_cntl &= ~IH_RB_ENABLE;
2848 ih_cntl &= ~ENABLE_INTR;
2849 WREG32(IH_RB_CNTL, ih_rb_cntl);
2850 WREG32(IH_CNTL, ih_cntl);
2851 /* set rptr, wptr to 0 */
2852 WREG32(IH_RB_RPTR, 0);
2853 WREG32(IH_RB_WPTR, 0);
2854 rdev->ih.enabled = false;
2855 rdev->ih.wptr = 0;
2856 rdev->ih.rptr = 0;
2857}
2858
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002859static void r600_disable_interrupt_state(struct radeon_device *rdev)
2860{
2861 u32 tmp;
2862
Alex Deucher3555e532010-10-08 12:09:12 -04002863 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002864 WREG32(GRBM_INT_CNTL, 0);
2865 WREG32(DxMODE_INT_MASK, 0);
2866 if (ASIC_IS_DCE3(rdev)) {
2867 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2868 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2869 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2870 WREG32(DC_HPD1_INT_CONTROL, tmp);
2871 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2872 WREG32(DC_HPD2_INT_CONTROL, tmp);
2873 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2874 WREG32(DC_HPD3_INT_CONTROL, tmp);
2875 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2876 WREG32(DC_HPD4_INT_CONTROL, tmp);
2877 if (ASIC_IS_DCE32(rdev)) {
2878 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002879 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002880 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002881 WREG32(DC_HPD6_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002882 }
2883 } else {
2884 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2885 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2886 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002887 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002888 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002889 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002890 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002891 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002892 }
2893}
2894
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002895int r600_irq_init(struct radeon_device *rdev)
2896{
2897 int ret = 0;
2898 int rb_bufsz;
2899 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2900
2901 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01002902 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002903 if (ret)
2904 return ret;
2905
2906 /* disable irqs */
2907 r600_disable_interrupts(rdev);
2908
2909 /* init rlc */
2910 ret = r600_rlc_init(rdev);
2911 if (ret) {
2912 r600_ih_ring_fini(rdev);
2913 return ret;
2914 }
2915
2916 /* setup interrupt control */
2917 /* set dummy read address to ring address */
2918 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
2919 interrupt_cntl = RREG32(INTERRUPT_CNTL);
2920 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2921 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2922 */
2923 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
2924 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2925 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
2926 WREG32(INTERRUPT_CNTL, interrupt_cntl);
2927
2928 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
2929 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
2930
2931 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
2932 IH_WPTR_OVERFLOW_CLEAR |
2933 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04002934
2935 if (rdev->wb.enabled)
2936 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
2937
2938 /* set the writeback address whether it's enabled or not */
2939 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
2940 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 -05002941
2942 WREG32(IH_RB_CNTL, ih_rb_cntl);
2943
2944 /* set rptr, wptr to 0 */
2945 WREG32(IH_RB_RPTR, 0);
2946 WREG32(IH_RB_WPTR, 0);
2947
2948 /* Default settings for IH_CNTL (disabled at first) */
2949 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2950 /* RPTR_REARM only works if msi's are enabled */
2951 if (rdev->msi_enabled)
2952 ih_cntl |= RPTR_REARM;
2953
2954#ifdef __BIG_ENDIAN
2955 ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
2956#endif
2957 WREG32(IH_CNTL, ih_cntl);
2958
2959 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04002960 if (rdev->family >= CHIP_CEDAR)
2961 evergreen_disable_interrupt_state(rdev);
2962 else
2963 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002964
2965 /* enable irqs */
2966 r600_enable_interrupts(rdev);
2967
2968 return ret;
2969}
2970
Jerome Glisse0c452492010-01-15 14:44:37 +01002971void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002972{
Alex Deucher45f9a392010-03-24 13:55:51 -04002973 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002974 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01002975}
2976
2977void r600_irq_fini(struct radeon_device *rdev)
2978{
2979 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002980 r600_ih_ring_fini(rdev);
2981}
2982
2983int r600_irq_set(struct radeon_device *rdev)
2984{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002985 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
2986 u32 mode_int = 0;
2987 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04002988 u32 grbm_int_cntl = 0;
Christian Koenigf2594932010-04-10 03:13:16 +02002989 u32 hdmi1, hdmi2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002990
Jerome Glisse003e69f2010-01-07 15:39:14 +01002991 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00002992 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01002993 return -EINVAL;
2994 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002995 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01002996 if (!rdev->ih.enabled) {
2997 r600_disable_interrupts(rdev);
2998 /* force the active interrupt state to all disabled */
2999 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003000 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003001 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003002
Christian Koenigf2594932010-04-10 03:13:16 +02003003 hdmi1 = RREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003004 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02003005 hdmi2 = RREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003006 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3007 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3008 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3009 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3010 if (ASIC_IS_DCE32(rdev)) {
3011 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3012 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
3013 }
3014 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02003015 hdmi2 = RREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003016 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3017 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3018 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3019 }
3020
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003021 if (rdev->irq.sw_int) {
3022 DRM_DEBUG("r600_irq_set: sw int\n");
3023 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003024 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003025 }
3026 if (rdev->irq.crtc_vblank_int[0]) {
3027 DRM_DEBUG("r600_irq_set: vblank 0\n");
3028 mode_int |= D1MODE_VBLANK_INT_MASK;
3029 }
3030 if (rdev->irq.crtc_vblank_int[1]) {
3031 DRM_DEBUG("r600_irq_set: vblank 1\n");
3032 mode_int |= D2MODE_VBLANK_INT_MASK;
3033 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003034 if (rdev->irq.hpd[0]) {
3035 DRM_DEBUG("r600_irq_set: hpd 1\n");
3036 hpd1 |= DC_HPDx_INT_EN;
3037 }
3038 if (rdev->irq.hpd[1]) {
3039 DRM_DEBUG("r600_irq_set: hpd 2\n");
3040 hpd2 |= DC_HPDx_INT_EN;
3041 }
3042 if (rdev->irq.hpd[2]) {
3043 DRM_DEBUG("r600_irq_set: hpd 3\n");
3044 hpd3 |= DC_HPDx_INT_EN;
3045 }
3046 if (rdev->irq.hpd[3]) {
3047 DRM_DEBUG("r600_irq_set: hpd 4\n");
3048 hpd4 |= DC_HPDx_INT_EN;
3049 }
3050 if (rdev->irq.hpd[4]) {
3051 DRM_DEBUG("r600_irq_set: hpd 5\n");
3052 hpd5 |= DC_HPDx_INT_EN;
3053 }
3054 if (rdev->irq.hpd[5]) {
3055 DRM_DEBUG("r600_irq_set: hpd 6\n");
3056 hpd6 |= DC_HPDx_INT_EN;
3057 }
Christian Koenigf2594932010-04-10 03:13:16 +02003058 if (rdev->irq.hdmi[0]) {
3059 DRM_DEBUG("r600_irq_set: hdmi 1\n");
3060 hdmi1 |= R600_HDMI_INT_EN;
3061 }
3062 if (rdev->irq.hdmi[1]) {
3063 DRM_DEBUG("r600_irq_set: hdmi 2\n");
3064 hdmi2 |= R600_HDMI_INT_EN;
3065 }
Alex Deucher2031f772010-04-22 12:52:11 -04003066 if (rdev->irq.gui_idle) {
3067 DRM_DEBUG("gui idle\n");
3068 grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
3069 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003070
3071 WREG32(CP_INT_CNTL, cp_int_cntl);
3072 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher2031f772010-04-22 12:52:11 -04003073 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Christian Koenigf2594932010-04-10 03:13:16 +02003074 WREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003075 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02003076 WREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003077 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3078 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3079 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3080 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3081 if (ASIC_IS_DCE32(rdev)) {
3082 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3083 WREG32(DC_HPD6_INT_CONTROL, hpd6);
3084 }
3085 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02003086 WREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003087 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3088 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3089 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
3090 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003091
3092 return 0;
3093}
3094
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003095static inline void r600_irq_ack(struct radeon_device *rdev,
3096 u32 *disp_int,
3097 u32 *disp_int_cont,
3098 u32 *disp_int_cont2)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003099{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003100 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003101
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003102 if (ASIC_IS_DCE3(rdev)) {
3103 *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3104 *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3105 *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
3106 } else {
3107 *disp_int = RREG32(DISP_INTERRUPT_STATUS);
3108 *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3109 *disp_int_cont2 = 0;
3110 }
3111
3112 if (*disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003113 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003114 if (*disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003115 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003116 if (*disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003117 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003118 if (*disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003119 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003120 if (*disp_int & DC_HPD1_INTERRUPT) {
3121 if (ASIC_IS_DCE3(rdev)) {
3122 tmp = RREG32(DC_HPD1_INT_CONTROL);
3123 tmp |= DC_HPDx_INT_ACK;
3124 WREG32(DC_HPD1_INT_CONTROL, tmp);
3125 } else {
3126 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3127 tmp |= DC_HPDx_INT_ACK;
3128 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3129 }
3130 }
3131 if (*disp_int & DC_HPD2_INTERRUPT) {
3132 if (ASIC_IS_DCE3(rdev)) {
3133 tmp = RREG32(DC_HPD2_INT_CONTROL);
3134 tmp |= DC_HPDx_INT_ACK;
3135 WREG32(DC_HPD2_INT_CONTROL, tmp);
3136 } else {
3137 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3138 tmp |= DC_HPDx_INT_ACK;
3139 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3140 }
3141 }
3142 if (*disp_int_cont & DC_HPD3_INTERRUPT) {
3143 if (ASIC_IS_DCE3(rdev)) {
3144 tmp = RREG32(DC_HPD3_INT_CONTROL);
3145 tmp |= DC_HPDx_INT_ACK;
3146 WREG32(DC_HPD3_INT_CONTROL, tmp);
3147 } else {
3148 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3149 tmp |= DC_HPDx_INT_ACK;
3150 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3151 }
3152 }
3153 if (*disp_int_cont & DC_HPD4_INTERRUPT) {
3154 tmp = RREG32(DC_HPD4_INT_CONTROL);
3155 tmp |= DC_HPDx_INT_ACK;
3156 WREG32(DC_HPD4_INT_CONTROL, tmp);
3157 }
3158 if (ASIC_IS_DCE32(rdev)) {
3159 if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
3160 tmp = RREG32(DC_HPD5_INT_CONTROL);
3161 tmp |= DC_HPDx_INT_ACK;
3162 WREG32(DC_HPD5_INT_CONTROL, tmp);
3163 }
3164 if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
3165 tmp = RREG32(DC_HPD5_INT_CONTROL);
3166 tmp |= DC_HPDx_INT_ACK;
3167 WREG32(DC_HPD6_INT_CONTROL, tmp);
3168 }
3169 }
Christian Koenigf2594932010-04-10 03:13:16 +02003170 if (RREG32(R600_HDMI_BLOCK1 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3171 WREG32_P(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3172 }
3173 if (ASIC_IS_DCE3(rdev)) {
3174 if (RREG32(R600_HDMI_BLOCK3 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3175 WREG32_P(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3176 }
3177 } else {
3178 if (RREG32(R600_HDMI_BLOCK2 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3179 WREG32_P(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3180 }
3181 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003182}
3183
3184void r600_irq_disable(struct radeon_device *rdev)
3185{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003186 u32 disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003187
3188 r600_disable_interrupts(rdev);
3189 /* Wait and acknowledge irq */
3190 mdelay(1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003191 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
3192 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003193}
3194
3195static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
3196{
3197 u32 wptr, tmp;
3198
Alex Deucher724c80e2010-08-27 18:25:25 -04003199 if (rdev->wb.enabled)
3200 wptr = rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4];
3201 else
3202 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003203
3204 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003205 /* When a ring buffer overflow happen start parsing interrupt
3206 * from the last not overwritten vector (wptr + 16). Hopefully
3207 * this should allow us to catchup.
3208 */
3209 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3210 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3211 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003212 tmp = RREG32(IH_RB_CNTL);
3213 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3214 WREG32(IH_RB_CNTL, tmp);
3215 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003216 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003217}
3218
3219/* r600 IV Ring
3220 * Each IV ring entry is 128 bits:
3221 * [7:0] - interrupt source id
3222 * [31:8] - reserved
3223 * [59:32] - interrupt source data
3224 * [127:60] - reserved
3225 *
3226 * The basic interrupt vector entries
3227 * are decoded as follows:
3228 * src_id src_data description
3229 * 1 0 D1 Vblank
3230 * 1 1 D1 Vline
3231 * 5 0 D2 Vblank
3232 * 5 1 D2 Vline
3233 * 19 0 FP Hot plug detection A
3234 * 19 1 FP Hot plug detection B
3235 * 19 2 DAC A auto-detection
3236 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003237 * 21 4 HDMI block A
3238 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003239 * 176 - CP_INT RB
3240 * 177 - CP_INT IB1
3241 * 178 - CP_INT IB2
3242 * 181 - EOP Interrupt
3243 * 233 - GUI Idle
3244 *
3245 * Note, these are based on r600 and may need to be
3246 * adjusted or added to on newer asics
3247 */
3248
3249int r600_irq_process(struct radeon_device *rdev)
3250{
3251 u32 wptr = r600_get_ih_wptr(rdev);
3252 u32 rptr = rdev->ih.rptr;
3253 u32 src_id, src_data;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003254 u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003255 unsigned long flags;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003256 bool queue_hotplug = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003257
3258 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003259 if (!rdev->ih.enabled)
3260 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003261
3262 spin_lock_irqsave(&rdev->ih.lock, flags);
3263
3264 if (rptr == wptr) {
3265 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3266 return IRQ_NONE;
3267 }
3268 if (rdev->shutdown) {
3269 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3270 return IRQ_NONE;
3271 }
3272
3273restart_ih:
3274 /* display interrupts */
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003275 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003276
3277 rdev->ih.wptr = wptr;
3278 while (rptr != wptr) {
3279 /* wptr/rptr are in bytes! */
3280 ring_index = rptr / 4;
3281 src_id = rdev->ih.ring[ring_index] & 0xff;
3282 src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
3283
3284 switch (src_id) {
3285 case 1: /* D1 vblank/vline */
3286 switch (src_data) {
3287 case 0: /* D1 vblank */
3288 if (disp_int & LB_D1_VBLANK_INTERRUPT) {
3289 drm_handle_vblank(rdev->ddev, 0);
Rafał Miłecki839461d2010-03-02 22:06:51 +01003290 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +01003291 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003292 disp_int &= ~LB_D1_VBLANK_INTERRUPT;
3293 DRM_DEBUG("IH: D1 vblank\n");
3294 }
3295 break;
3296 case 1: /* D1 vline */
3297 if (disp_int & LB_D1_VLINE_INTERRUPT) {
3298 disp_int &= ~LB_D1_VLINE_INTERRUPT;
3299 DRM_DEBUG("IH: D1 vline\n");
3300 }
3301 break;
3302 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003303 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003304 break;
3305 }
3306 break;
3307 case 5: /* D2 vblank/vline */
3308 switch (src_data) {
3309 case 0: /* D2 vblank */
3310 if (disp_int & LB_D2_VBLANK_INTERRUPT) {
3311 drm_handle_vblank(rdev->ddev, 1);
Rafał Miłecki839461d2010-03-02 22:06:51 +01003312 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +01003313 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003314 disp_int &= ~LB_D2_VBLANK_INTERRUPT;
3315 DRM_DEBUG("IH: D2 vblank\n");
3316 }
3317 break;
3318 case 1: /* D1 vline */
3319 if (disp_int & LB_D2_VLINE_INTERRUPT) {
3320 disp_int &= ~LB_D2_VLINE_INTERRUPT;
3321 DRM_DEBUG("IH: D2 vline\n");
3322 }
3323 break;
3324 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003325 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003326 break;
3327 }
3328 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003329 case 19: /* HPD/DAC hotplug */
3330 switch (src_data) {
3331 case 0:
3332 if (disp_int & DC_HPD1_INTERRUPT) {
3333 disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003334 queue_hotplug = true;
3335 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003336 }
3337 break;
3338 case 1:
3339 if (disp_int & DC_HPD2_INTERRUPT) {
3340 disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003341 queue_hotplug = true;
3342 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003343 }
3344 break;
3345 case 4:
3346 if (disp_int_cont & DC_HPD3_INTERRUPT) {
3347 disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003348 queue_hotplug = true;
3349 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003350 }
3351 break;
3352 case 5:
3353 if (disp_int_cont & DC_HPD4_INTERRUPT) {
3354 disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003355 queue_hotplug = true;
3356 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003357 }
3358 break;
3359 case 10:
3360 if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deucher5898b1f2010-03-24 13:57:29 -04003361 disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003362 queue_hotplug = true;
3363 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003364 }
3365 break;
3366 case 12:
3367 if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deucher5898b1f2010-03-24 13:57:29 -04003368 disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003369 queue_hotplug = true;
3370 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003371 }
3372 break;
3373 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003374 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003375 break;
3376 }
3377 break;
Christian Koenigf2594932010-04-10 03:13:16 +02003378 case 21: /* HDMI */
3379 DRM_DEBUG("IH: HDMI: 0x%x\n", src_data);
3380 r600_audio_schedule_polling(rdev);
3381 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003382 case 176: /* CP_INT in ring buffer */
3383 case 177: /* CP_INT in IB1 */
3384 case 178: /* CP_INT in IB2 */
3385 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
3386 radeon_fence_process(rdev);
3387 break;
3388 case 181: /* CP EOP event */
3389 DRM_DEBUG("IH: CP EOP\n");
Alex Deucherd0f8a852010-09-04 05:04:34 -04003390 radeon_fence_process(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003391 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003392 case 233: /* GUI IDLE */
3393 DRM_DEBUG("IH: CP EOP\n");
3394 rdev->pm.gui_idle = true;
3395 wake_up(&rdev->irq.idle_queue);
3396 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003397 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003398 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003399 break;
3400 }
3401
3402 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01003403 rptr += 16;
3404 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003405 }
3406 /* make sure wptr hasn't changed while processing */
3407 wptr = r600_get_ih_wptr(rdev);
3408 if (wptr != rdev->ih.wptr)
3409 goto restart_ih;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003410 if (queue_hotplug)
3411 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003412 rdev->ih.rptr = rptr;
3413 WREG32(IH_RB_RPTR, rdev->ih.rptr);
3414 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3415 return IRQ_HANDLED;
3416}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003417
3418/*
3419 * Debugfs info
3420 */
3421#if defined(CONFIG_DEBUG_FS)
3422
3423static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
3424{
3425 struct drm_info_node *node = (struct drm_info_node *) m->private;
3426 struct drm_device *dev = node->minor->dev;
3427 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003428 unsigned count, i, j;
3429
3430 radeon_ring_free_size(rdev);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003431 count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003432 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
Rafał Miłeckid6840762009-11-10 22:26:21 +01003433 seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
3434 seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
3435 seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
3436 seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003437 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
3438 seq_printf(m, "%u dwords in ring\n", count);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003439 i = rdev->cp.rptr;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003440 for (j = 0; j <= count; j++) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003441 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003442 i = (i + 1) & rdev->cp.ptr_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003443 }
3444 return 0;
3445}
3446
3447static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3448{
3449 struct drm_info_node *node = (struct drm_info_node *) m->private;
3450 struct drm_device *dev = node->minor->dev;
3451 struct radeon_device *rdev = dev->dev_private;
3452
3453 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3454 DREG32_SYS(m, rdev, VM_L2_STATUS);
3455 return 0;
3456}
3457
3458static struct drm_info_list r600_mc_info_list[] = {
3459 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
3460 {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
3461};
3462#endif
3463
3464int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3465{
3466#if defined(CONFIG_DEBUG_FS)
3467 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3468#else
3469 return 0;
3470#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003471}
Jerome Glisse062b3892010-02-04 20:36:39 +01003472
3473/**
3474 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3475 * rdev: radeon device structure
3476 * bo: buffer object struct which userspace is waiting for idle
3477 *
3478 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3479 * through ring buffer, this leads to corruption in rendering, see
3480 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3481 * directly perform HDP flush by writing register through MMIO.
3482 */
3483void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3484{
Alex Deucher812d0462010-07-26 18:51:53 -04003485 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
3486 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
3487 */
Alex Deuchere4884592010-09-27 10:57:10 -04003488 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
3489 rdev->vram_scratch.ptr) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04003490 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04003491 u32 tmp;
3492
3493 WREG32(HDP_DEBUG1, 0);
3494 tmp = readl((void __iomem *)ptr);
3495 } else
3496 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01003497}