blob: 618d76d366a40aab897d06d450a24de3740e1832 [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 Deucherce8f5372010-05-07 15:10:16 -040095void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -040096{
97 int i;
98
Alex Deucherce8f5372010-05-07 15:10:16 -040099 rdev->pm.dynpm_can_upclock = true;
100 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400101
102 /* power state array is low to high, default is first */
103 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
104 int min_power_state_index = 0;
105
106 if (rdev->pm.num_power_states > 2)
107 min_power_state_index = 1;
108
Alex Deucherce8f5372010-05-07 15:10:16 -0400109 switch (rdev->pm.dynpm_planned_action) {
110 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400111 rdev->pm.requested_power_state_index = min_power_state_index;
112 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400113 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400114 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400115 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400116 if (rdev->pm.current_power_state_index == min_power_state_index) {
117 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400118 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400119 } else {
120 if (rdev->pm.active_crtc_count > 1) {
121 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400122 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400123 continue;
124 else if (i >= rdev->pm.current_power_state_index) {
125 rdev->pm.requested_power_state_index =
126 rdev->pm.current_power_state_index;
127 break;
128 } else {
129 rdev->pm.requested_power_state_index = i;
130 break;
131 }
132 }
133 } else
134 rdev->pm.requested_power_state_index =
135 rdev->pm.current_power_state_index - 1;
136 }
137 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400138 /* don't use the power state if crtcs are active and no display flag is set */
139 if ((rdev->pm.active_crtc_count > 0) &&
140 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
141 clock_info[rdev->pm.requested_clock_mode_index].flags &
142 RADEON_PM_MODE_NO_DISPLAY)) {
143 rdev->pm.requested_power_state_index++;
144 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400145 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400146 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400147 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
148 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400149 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400150 } else {
151 if (rdev->pm.active_crtc_count > 1) {
152 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400153 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400154 continue;
155 else if (i <= rdev->pm.current_power_state_index) {
156 rdev->pm.requested_power_state_index =
157 rdev->pm.current_power_state_index;
158 break;
159 } else {
160 rdev->pm.requested_power_state_index = i;
161 break;
162 }
163 }
164 } else
165 rdev->pm.requested_power_state_index =
166 rdev->pm.current_power_state_index + 1;
167 }
168 rdev->pm.requested_clock_mode_index = 0;
169 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400170 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400171 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
172 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400173 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400174 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400175 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400176 default:
177 DRM_ERROR("Requested mode for not defined action\n");
178 return;
179 }
180 } else {
181 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
182 /* for now just select the first power state and switch between clock modes */
183 /* power state array is low to high, default is first (0) */
184 if (rdev->pm.active_crtc_count > 1) {
185 rdev->pm.requested_power_state_index = -1;
186 /* start at 1 as we don't want the default mode */
187 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400188 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400189 continue;
190 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
191 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
192 rdev->pm.requested_power_state_index = i;
193 break;
194 }
195 }
196 /* if nothing selected, grab the default state. */
197 if (rdev->pm.requested_power_state_index == -1)
198 rdev->pm.requested_power_state_index = 0;
199 } else
200 rdev->pm.requested_power_state_index = 1;
201
Alex Deucherce8f5372010-05-07 15:10:16 -0400202 switch (rdev->pm.dynpm_planned_action) {
203 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400204 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400205 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400206 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400207 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400208 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
209 if (rdev->pm.current_clock_mode_index == 0) {
210 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400211 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400212 } else
213 rdev->pm.requested_clock_mode_index =
214 rdev->pm.current_clock_mode_index - 1;
215 } else {
216 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400217 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400218 }
Alex Deucherd7311172010-05-03 01:13:14 -0400219 /* don't use the power state if crtcs are active and no display flag is set */
220 if ((rdev->pm.active_crtc_count > 0) &&
221 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
222 clock_info[rdev->pm.requested_clock_mode_index].flags &
223 RADEON_PM_MODE_NO_DISPLAY)) {
224 rdev->pm.requested_clock_mode_index++;
225 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400226 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400227 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400228 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
229 if (rdev->pm.current_clock_mode_index ==
230 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
231 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400232 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400233 } else
234 rdev->pm.requested_clock_mode_index =
235 rdev->pm.current_clock_mode_index + 1;
236 } else {
237 rdev->pm.requested_clock_mode_index =
238 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400239 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400240 }
241 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400242 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400243 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
244 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400245 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400246 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400247 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400248 default:
249 DRM_ERROR("Requested mode for not defined action\n");
250 return;
251 }
252 }
253
254 DRM_INFO("Requested: e: %d m: %d p: %d\n",
255 rdev->pm.power_state[rdev->pm.requested_power_state_index].
256 clock_info[rdev->pm.requested_clock_mode_index].sclk,
257 rdev->pm.power_state[rdev->pm.requested_power_state_index].
258 clock_info[rdev->pm.requested_clock_mode_index].mclk,
259 rdev->pm.power_state[rdev->pm.requested_power_state_index].
Alex Deucher79daedc2010-04-22 14:25:19 -0400260 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400261}
262
Alex Deucherce8f5372010-05-07 15:10:16 -0400263static int r600_pm_get_type_index(struct radeon_device *rdev,
264 enum radeon_pm_state_type ps_type,
265 int instance)
Alex Deucherbae6b5622010-04-22 13:38:05 -0400266{
Alex Deucherce8f5372010-05-07 15:10:16 -0400267 int i;
268 int found_instance = -1;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400269
Alex Deucherce8f5372010-05-07 15:10:16 -0400270 for (i = 0; i < rdev->pm.num_power_states; i++) {
271 if (rdev->pm.power_state[i].type == ps_type) {
272 found_instance++;
273 if (found_instance == instance)
274 return i;
Alex Deuchera4248162010-04-24 14:50:23 -0400275 }
Alex Deucherce8f5372010-05-07 15:10:16 -0400276 }
277 /* return default if no match */
278 return rdev->pm.default_power_state_index;
279}
Alex Deucherbae6b5622010-04-22 13:38:05 -0400280
Alex Deucherce8f5372010-05-07 15:10:16 -0400281void rs780_pm_init_profile(struct radeon_device *rdev)
282{
283 if (rdev->pm.num_power_states == 2) {
284 /* default */
285 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
286 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
287 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
288 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
289 /* low sh */
290 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
291 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
292 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
293 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
294 /* high sh */
295 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
296 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
297 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
298 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
299 /* low mh */
300 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
301 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
302 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
303 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
304 /* high mh */
305 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
306 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
307 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
308 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
309 } else if (rdev->pm.num_power_states == 3) {
310 /* default */
311 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
312 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
313 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
314 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
315 /* low sh */
316 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
317 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
318 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
319 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
320 /* high sh */
321 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
322 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
323 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
325 /* low mh */
326 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
327 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
328 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
330 /* high mh */
331 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
332 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
333 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
334 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
335 } else {
336 /* default */
337 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
338 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
339 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
340 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
341 /* low sh */
342 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
343 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
344 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
345 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
346 /* high sh */
347 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
348 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
349 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
350 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
351 /* low mh */
352 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
353 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
354 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
355 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
356 /* high mh */
357 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
358 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
359 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
360 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
361 }
362}
363
364void r600_pm_init_profile(struct radeon_device *rdev)
365{
366 if (rdev->family == CHIP_R600) {
367 /* XXX */
368 /* default */
369 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
370 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
371 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
372 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
373 /* low sh */
374 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
375 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
376 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
377 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 2;
378 /* high sh */
379 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
380 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
381 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
382 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
383 /* low mh */
384 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
385 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
386 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
387 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 2;
388 /* high mh */
389 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
390 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
391 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
392 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
393 } else if (rdev->flags & RADEON_IS_MOBILITY) {
394 /* default */
395 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
396 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
397 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
398 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
399 /* low sh */
400 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
401 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
402 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
403 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
404 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
405 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 2;
406 /* high sh */
407 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx =
408 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
409 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx =
410 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
411 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
412 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
413 /* low mh */
414 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
415 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
416 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
417 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
418 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
419 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 2;
420 /* high mh */
421 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx =
422 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
423 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx =
424 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
425 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
426 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
427 } else {
428 if (rdev->pm.num_power_states < 4) {
429 /* default */
430 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
431 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
432 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
433 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
434 /* low sh */
435 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
436 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
437 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
438 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 2;
439 /* high sh */
440 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
441 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
442 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
443 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
444 /* low mh */
445 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
446 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
447 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
448 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 2;
449 /* high mh */
450 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
451 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
452 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
453 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
454 } else {
455 /* default */
456 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
457 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
458 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
459 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
460 /* low sh */
461 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
462 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
463 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
464 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 2;
465 /* high sh */
466 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
467 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
468 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
469 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
470 /* low mh */
471 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 3;
472 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 3;
473 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
474 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 2;
475 /* high mh */
476 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 3;
477 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
478 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
479 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
480 }
481 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400482}
483
Alex Deucher49e02b72010-04-23 17:57:27 -0400484void r600_pm_misc(struct radeon_device *rdev)
485{
486
487}
488
Alex Deucherdef9ba92010-04-22 12:39:58 -0400489bool r600_gui_idle(struct radeon_device *rdev)
490{
491 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
492 return false;
493 else
494 return true;
495}
496
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500497/* hpd for digital panel detect/disconnect */
498bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
499{
500 bool connected = false;
501
502 if (ASIC_IS_DCE3(rdev)) {
503 switch (hpd) {
504 case RADEON_HPD_1:
505 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
506 connected = true;
507 break;
508 case RADEON_HPD_2:
509 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
510 connected = true;
511 break;
512 case RADEON_HPD_3:
513 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
514 connected = true;
515 break;
516 case RADEON_HPD_4:
517 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
518 connected = true;
519 break;
520 /* DCE 3.2 */
521 case RADEON_HPD_5:
522 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
523 connected = true;
524 break;
525 case RADEON_HPD_6:
526 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
527 connected = true;
528 break;
529 default:
530 break;
531 }
532 } else {
533 switch (hpd) {
534 case RADEON_HPD_1:
535 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
536 connected = true;
537 break;
538 case RADEON_HPD_2:
539 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
540 connected = true;
541 break;
542 case RADEON_HPD_3:
543 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
544 connected = true;
545 break;
546 default:
547 break;
548 }
549 }
550 return connected;
551}
552
553void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500554 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500555{
556 u32 tmp;
557 bool connected = r600_hpd_sense(rdev, hpd);
558
559 if (ASIC_IS_DCE3(rdev)) {
560 switch (hpd) {
561 case RADEON_HPD_1:
562 tmp = RREG32(DC_HPD1_INT_CONTROL);
563 if (connected)
564 tmp &= ~DC_HPDx_INT_POLARITY;
565 else
566 tmp |= DC_HPDx_INT_POLARITY;
567 WREG32(DC_HPD1_INT_CONTROL, tmp);
568 break;
569 case RADEON_HPD_2:
570 tmp = RREG32(DC_HPD2_INT_CONTROL);
571 if (connected)
572 tmp &= ~DC_HPDx_INT_POLARITY;
573 else
574 tmp |= DC_HPDx_INT_POLARITY;
575 WREG32(DC_HPD2_INT_CONTROL, tmp);
576 break;
577 case RADEON_HPD_3:
578 tmp = RREG32(DC_HPD3_INT_CONTROL);
579 if (connected)
580 tmp &= ~DC_HPDx_INT_POLARITY;
581 else
582 tmp |= DC_HPDx_INT_POLARITY;
583 WREG32(DC_HPD3_INT_CONTROL, tmp);
584 break;
585 case RADEON_HPD_4:
586 tmp = RREG32(DC_HPD4_INT_CONTROL);
587 if (connected)
588 tmp &= ~DC_HPDx_INT_POLARITY;
589 else
590 tmp |= DC_HPDx_INT_POLARITY;
591 WREG32(DC_HPD4_INT_CONTROL, tmp);
592 break;
593 case RADEON_HPD_5:
594 tmp = RREG32(DC_HPD5_INT_CONTROL);
595 if (connected)
596 tmp &= ~DC_HPDx_INT_POLARITY;
597 else
598 tmp |= DC_HPDx_INT_POLARITY;
599 WREG32(DC_HPD5_INT_CONTROL, tmp);
600 break;
601 /* DCE 3.2 */
602 case RADEON_HPD_6:
603 tmp = RREG32(DC_HPD6_INT_CONTROL);
604 if (connected)
605 tmp &= ~DC_HPDx_INT_POLARITY;
606 else
607 tmp |= DC_HPDx_INT_POLARITY;
608 WREG32(DC_HPD6_INT_CONTROL, tmp);
609 break;
610 default:
611 break;
612 }
613 } else {
614 switch (hpd) {
615 case RADEON_HPD_1:
616 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
617 if (connected)
618 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
619 else
620 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
621 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
622 break;
623 case RADEON_HPD_2:
624 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
625 if (connected)
626 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
627 else
628 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
629 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
630 break;
631 case RADEON_HPD_3:
632 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
633 if (connected)
634 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
635 else
636 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
637 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
638 break;
639 default:
640 break;
641 }
642 }
643}
644
645void r600_hpd_init(struct radeon_device *rdev)
646{
647 struct drm_device *dev = rdev->ddev;
648 struct drm_connector *connector;
649
650 if (ASIC_IS_DCE3(rdev)) {
651 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
652 if (ASIC_IS_DCE32(rdev))
653 tmp |= DC_HPDx_EN;
654
655 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
656 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
657 switch (radeon_connector->hpd.hpd) {
658 case RADEON_HPD_1:
659 WREG32(DC_HPD1_CONTROL, tmp);
660 rdev->irq.hpd[0] = true;
661 break;
662 case RADEON_HPD_2:
663 WREG32(DC_HPD2_CONTROL, tmp);
664 rdev->irq.hpd[1] = true;
665 break;
666 case RADEON_HPD_3:
667 WREG32(DC_HPD3_CONTROL, tmp);
668 rdev->irq.hpd[2] = true;
669 break;
670 case RADEON_HPD_4:
671 WREG32(DC_HPD4_CONTROL, tmp);
672 rdev->irq.hpd[3] = true;
673 break;
674 /* DCE 3.2 */
675 case RADEON_HPD_5:
676 WREG32(DC_HPD5_CONTROL, tmp);
677 rdev->irq.hpd[4] = true;
678 break;
679 case RADEON_HPD_6:
680 WREG32(DC_HPD6_CONTROL, tmp);
681 rdev->irq.hpd[5] = true;
682 break;
683 default:
684 break;
685 }
686 }
687 } else {
688 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
689 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
690 switch (radeon_connector->hpd.hpd) {
691 case RADEON_HPD_1:
692 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
693 rdev->irq.hpd[0] = true;
694 break;
695 case RADEON_HPD_2:
696 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
697 rdev->irq.hpd[1] = true;
698 break;
699 case RADEON_HPD_3:
700 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
701 rdev->irq.hpd[2] = true;
702 break;
703 default:
704 break;
705 }
706 }
707 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100708 if (rdev->irq.installed)
709 r600_irq_set(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500710}
711
712void r600_hpd_fini(struct radeon_device *rdev)
713{
714 struct drm_device *dev = rdev->ddev;
715 struct drm_connector *connector;
716
717 if (ASIC_IS_DCE3(rdev)) {
718 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
719 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
720 switch (radeon_connector->hpd.hpd) {
721 case RADEON_HPD_1:
722 WREG32(DC_HPD1_CONTROL, 0);
723 rdev->irq.hpd[0] = false;
724 break;
725 case RADEON_HPD_2:
726 WREG32(DC_HPD2_CONTROL, 0);
727 rdev->irq.hpd[1] = false;
728 break;
729 case RADEON_HPD_3:
730 WREG32(DC_HPD3_CONTROL, 0);
731 rdev->irq.hpd[2] = false;
732 break;
733 case RADEON_HPD_4:
734 WREG32(DC_HPD4_CONTROL, 0);
735 rdev->irq.hpd[3] = false;
736 break;
737 /* DCE 3.2 */
738 case RADEON_HPD_5:
739 WREG32(DC_HPD5_CONTROL, 0);
740 rdev->irq.hpd[4] = false;
741 break;
742 case RADEON_HPD_6:
743 WREG32(DC_HPD6_CONTROL, 0);
744 rdev->irq.hpd[5] = false;
745 break;
746 default:
747 break;
748 }
749 }
750 } else {
751 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
752 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
753 switch (radeon_connector->hpd.hpd) {
754 case RADEON_HPD_1:
755 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
756 rdev->irq.hpd[0] = false;
757 break;
758 case RADEON_HPD_2:
759 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
760 rdev->irq.hpd[1] = false;
761 break;
762 case RADEON_HPD_3:
763 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
764 rdev->irq.hpd[2] = false;
765 break;
766 default:
767 break;
768 }
769 }
770 }
771}
772
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200773/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000774 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200775 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000776void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200777{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000778 unsigned i;
779 u32 tmp;
780
Dave Airlie2e98f102010-02-15 15:54:45 +1000781 /* flush hdp cache so updates hit vram */
782 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
783
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000784 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
785 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
786 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
787 for (i = 0; i < rdev->usec_timeout; i++) {
788 /* read MC_STATUS */
789 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
790 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
791 if (tmp == 2) {
792 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
793 return;
794 }
795 if (tmp) {
796 return;
797 }
798 udelay(1);
799 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200800}
801
Jerome Glisse4aac0472009-09-14 18:29:49 +0200802int r600_pcie_gart_init(struct radeon_device *rdev)
803{
804 int r;
805
806 if (rdev->gart.table.vram.robj) {
807 WARN(1, "R600 PCIE GART already initialized.\n");
808 return 0;
809 }
810 /* Initialize common gart structure */
811 r = radeon_gart_init(rdev);
812 if (r)
813 return r;
814 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
815 return radeon_gart_table_vram_alloc(rdev);
816}
817
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000818int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200819{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000820 u32 tmp;
821 int r, i;
822
Jerome Glisse4aac0472009-09-14 18:29:49 +0200823 if (rdev->gart.table.vram.robj == NULL) {
824 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
825 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000826 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200827 r = radeon_gart_table_vram_pin(rdev);
828 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000829 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000830 radeon_gart_restore(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +1000831
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000832 /* Setup L2 cache */
833 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
834 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
835 EFFECTIVE_L2_QUEUE_SIZE(7));
836 WREG32(VM_L2_CNTL2, 0);
837 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
838 /* Setup TLB control */
839 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
840 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
841 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
842 ENABLE_WAIT_L2_QUERY;
843 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
844 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
845 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
846 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
847 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
848 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
849 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
850 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
851 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
852 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
853 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
854 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
855 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
856 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
857 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200858 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000859 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
860 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
861 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
862 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
863 (u32)(rdev->dummy_page.addr >> 12));
864 for (i = 1; i < 7; i++)
865 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
866
867 r600_pcie_gart_tlb_flush(rdev);
868 rdev->gart.ready = true;
869 return 0;
870}
871
872void r600_pcie_gart_disable(struct radeon_device *rdev)
873{
874 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100875 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000876
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000877 /* Disable all tables */
878 for (i = 0; i < 7; i++)
879 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
880
881 /* Disable L2 cache */
882 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
883 EFFECTIVE_L2_QUEUE_SIZE(7));
884 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
885 /* Setup L1 TLB control */
886 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
887 ENABLE_WAIT_L2_QUERY;
888 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
889 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
890 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
891 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
892 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
893 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
894 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
895 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
896 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
897 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
898 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
899 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
900 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
901 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200902 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100903 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
904 if (likely(r == 0)) {
905 radeon_bo_kunmap(rdev->gart.table.vram.robj);
906 radeon_bo_unpin(rdev->gart.table.vram.robj);
907 radeon_bo_unreserve(rdev->gart.table.vram.robj);
908 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200909 }
910}
911
912void r600_pcie_gart_fini(struct radeon_device *rdev)
913{
Jerome Glissef9274562010-03-17 14:44:29 +0000914 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200915 r600_pcie_gart_disable(rdev);
916 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200917}
918
Jerome Glisse1a029b72009-10-06 19:04:30 +0200919void r600_agp_enable(struct radeon_device *rdev)
920{
921 u32 tmp;
922 int i;
923
924 /* Setup L2 cache */
925 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
926 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
927 EFFECTIVE_L2_QUEUE_SIZE(7));
928 WREG32(VM_L2_CNTL2, 0);
929 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
930 /* Setup TLB control */
931 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
932 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
933 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
934 ENABLE_WAIT_L2_QUERY;
935 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
936 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
937 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
938 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
939 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
940 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
941 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
942 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
943 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
944 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
945 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
946 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
947 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
948 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
949 for (i = 0; i < 7; i++)
950 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
951}
952
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200953int r600_mc_wait_for_idle(struct radeon_device *rdev)
954{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000955 unsigned i;
956 u32 tmp;
957
958 for (i = 0; i < rdev->usec_timeout; i++) {
959 /* read MC_STATUS */
960 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
961 if (!tmp)
962 return 0;
963 udelay(1);
964 }
965 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200966}
967
Jerome Glissea3c19452009-10-01 18:02:13 +0200968static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200969{
Jerome Glissea3c19452009-10-01 18:02:13 +0200970 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000971 u32 tmp;
972 int i, j;
973
974 /* Initialize HDP */
975 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
976 WREG32((0x2c14 + j), 0x00000000);
977 WREG32((0x2c18 + j), 0x00000000);
978 WREG32((0x2c1c + j), 0x00000000);
979 WREG32((0x2c20 + j), 0x00000000);
980 WREG32((0x2c24 + j), 0x00000000);
981 }
982 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
983
Jerome Glissea3c19452009-10-01 18:02:13 +0200984 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000985 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200986 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000987 }
Jerome Glissea3c19452009-10-01 18:02:13 +0200988 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000989 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000990 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +0200991 if (rdev->flags & RADEON_IS_AGP) {
992 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
993 /* VRAM before AGP */
994 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
995 rdev->mc.vram_start >> 12);
996 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
997 rdev->mc.gtt_end >> 12);
998 } else {
999 /* VRAM after AGP */
1000 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1001 rdev->mc.gtt_start >> 12);
1002 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1003 rdev->mc.vram_end >> 12);
1004 }
1005 } else {
1006 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1007 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1008 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001009 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001010 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001011 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1012 WREG32(MC_VM_FB_LOCATION, tmp);
1013 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1014 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse1a029b72009-10-06 19:04:30 +02001015 WREG32(HDP_NONSURFACE_SIZE, rdev->mc.mc_vram_size | 0x3FF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001016 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001017 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1018 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001019 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1020 } else {
1021 WREG32(MC_VM_AGP_BASE, 0);
1022 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1023 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1024 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001025 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001026 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001027 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001028 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001029 /* we need to own VRAM, so turn off the VGA renderer here
1030 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001031 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001032}
1033
Jerome Glissed594e462010-02-17 21:54:29 +00001034/**
1035 * r600_vram_gtt_location - try to find VRAM & GTT location
1036 * @rdev: radeon device structure holding all necessary informations
1037 * @mc: memory controller structure holding memory informations
1038 *
1039 * Function will place try to place VRAM at same place as in CPU (PCI)
1040 * address space as some GPU seems to have issue when we reprogram at
1041 * different address space.
1042 *
1043 * If there is not enough space to fit the unvisible VRAM after the
1044 * aperture then we limit the VRAM size to the aperture.
1045 *
1046 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1047 * them to be in one from GPU point of view so that we can program GPU to
1048 * catch access outside them (weird GPU policy see ??).
1049 *
1050 * This function will never fails, worst case are limiting VRAM or GTT.
1051 *
1052 * Note: GTT start, end, size should be initialized before calling this
1053 * function on AGP platform.
1054 */
1055void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1056{
1057 u64 size_bf, size_af;
1058
1059 if (mc->mc_vram_size > 0xE0000000) {
1060 /* leave room for at least 512M GTT */
1061 dev_warn(rdev->dev, "limiting VRAM\n");
1062 mc->real_vram_size = 0xE0000000;
1063 mc->mc_vram_size = 0xE0000000;
1064 }
1065 if (rdev->flags & RADEON_IS_AGP) {
1066 size_bf = mc->gtt_start;
1067 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
1068 if (size_bf > size_af) {
1069 if (mc->mc_vram_size > size_bf) {
1070 dev_warn(rdev->dev, "limiting VRAM\n");
1071 mc->real_vram_size = size_bf;
1072 mc->mc_vram_size = size_bf;
1073 }
1074 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1075 } else {
1076 if (mc->mc_vram_size > size_af) {
1077 dev_warn(rdev->dev, "limiting VRAM\n");
1078 mc->real_vram_size = size_af;
1079 mc->mc_vram_size = size_af;
1080 }
1081 mc->vram_start = mc->gtt_end;
1082 }
1083 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1084 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1085 mc->mc_vram_size >> 20, mc->vram_start,
1086 mc->vram_end, mc->real_vram_size >> 20);
1087 } else {
1088 u64 base = 0;
1089 if (rdev->flags & RADEON_IS_IGP)
1090 base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24;
1091 radeon_vram_location(rdev, &rdev->mc, base);
1092 radeon_gtt_location(rdev, mc);
1093 }
1094}
1095
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001096int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001097{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001098 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001099 int chansize, numchan;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001100
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001101 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001102 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001103 tmp = RREG32(RAMCFG);
1104 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001105 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001106 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001107 chansize = 64;
1108 } else {
1109 chansize = 32;
1110 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001111 tmp = RREG32(CHMAP);
1112 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1113 case 0:
1114 default:
1115 numchan = 1;
1116 break;
1117 case 1:
1118 numchan = 2;
1119 break;
1120 case 2:
1121 numchan = 4;
1122 break;
1123 case 3:
1124 numchan = 8;
1125 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001126 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001127 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001128 /* Could aper size report 0 ? */
1129 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
1130 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001131 /* Setup GPU memory space */
1132 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1133 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001134 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001135 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001136
Alex Deucher06b64762010-01-05 11:27:29 -05001137 if (rdev->flags & RADEON_IS_IGP)
1138 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Alex Deucherf47299c2010-03-16 20:54:38 -04001139 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001140 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141}
1142
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001143/* We doesn't check that the GPU really needs a reset we simply do the
1144 * reset, it's up to the caller to determine if the GPU needs one. We
1145 * might add an helper function to check that.
1146 */
1147int r600_gpu_soft_reset(struct radeon_device *rdev)
1148{
Jerome Glissea3c19452009-10-01 18:02:13 +02001149 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001150 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1151 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1152 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1153 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1154 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1155 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1156 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1157 S_008010_GUI_ACTIVE(1);
1158 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1159 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1160 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1161 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1162 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1163 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1164 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1165 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
Jerome Glissea3c19452009-10-01 18:02:13 +02001166 u32 tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001167
Jerome Glisse1a029b72009-10-06 19:04:30 +02001168 dev_info(rdev->dev, "GPU softreset \n");
1169 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1170 RREG32(R_008010_GRBM_STATUS));
1171 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
Jerome Glissea3c19452009-10-01 18:02:13 +02001172 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse1a029b72009-10-06 19:04:30 +02001173 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1174 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001175 rv515_mc_stop(rdev, &save);
1176 if (r600_mc_wait_for_idle(rdev)) {
1177 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1178 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001179 /* Disable CP parsing/prefetching */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001180 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001181 /* Check if any of the rendering block is busy and reset it */
1182 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
1183 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001184 tmp = S_008020_SOFT_RESET_CR(1) |
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001185 S_008020_SOFT_RESET_DB(1) |
1186 S_008020_SOFT_RESET_CB(1) |
1187 S_008020_SOFT_RESET_PA(1) |
1188 S_008020_SOFT_RESET_SC(1) |
1189 S_008020_SOFT_RESET_SMX(1) |
1190 S_008020_SOFT_RESET_SPI(1) |
1191 S_008020_SOFT_RESET_SX(1) |
1192 S_008020_SOFT_RESET_SH(1) |
1193 S_008020_SOFT_RESET_TC(1) |
1194 S_008020_SOFT_RESET_TA(1) |
1195 S_008020_SOFT_RESET_VC(1) |
Jerome Glissea3c19452009-10-01 18:02:13 +02001196 S_008020_SOFT_RESET_VGT(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001197 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
Jerome Glissea3c19452009-10-01 18:02:13 +02001198 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001199 RREG32(R_008020_GRBM_SOFT_RESET);
1200 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001201 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001202 }
1203 /* Reset CP (we always reset CP) */
Jerome Glissea3c19452009-10-01 18:02:13 +02001204 tmp = S_008020_SOFT_RESET_CP(1);
1205 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1206 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001207 RREG32(R_008020_GRBM_SOFT_RESET);
1208 mdelay(15);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001209 WREG32(R_008020_GRBM_SOFT_RESET, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001210 /* Wait a little for things to settle down */
Jerome Glisse225758d2010-03-09 14:45:10 +00001211 mdelay(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001212 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1213 RREG32(R_008010_GRBM_STATUS));
1214 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1215 RREG32(R_008014_GRBM_STATUS2));
1216 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1217 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +02001218 rv515_mc_resume(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001219 return 0;
1220}
1221
Jerome Glisse225758d2010-03-09 14:45:10 +00001222bool r600_gpu_is_lockup(struct radeon_device *rdev)
1223{
1224 u32 srbm_status;
1225 u32 grbm_status;
1226 u32 grbm_status2;
1227 int r;
1228
1229 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1230 grbm_status = RREG32(R_008010_GRBM_STATUS);
1231 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1232 if (!G_008010_GUI_ACTIVE(grbm_status)) {
1233 r100_gpu_lockup_update(&rdev->config.r300.lockup, &rdev->cp);
1234 return false;
1235 }
1236 /* force CP activities */
1237 r = radeon_ring_lock(rdev, 2);
1238 if (!r) {
1239 /* PACKET2 NOP */
1240 radeon_ring_write(rdev, 0x80000000);
1241 radeon_ring_write(rdev, 0x80000000);
1242 radeon_ring_unlock_commit(rdev);
1243 }
1244 rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
1245 return r100_gpu_cp_is_lockup(rdev, &rdev->config.r300.lockup, &rdev->cp);
1246}
1247
Jerome Glissea2d07b72010-03-09 14:45:11 +00001248int r600_asic_reset(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001249{
1250 return r600_gpu_soft_reset(rdev);
1251}
1252
1253static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
1254 u32 num_backends,
1255 u32 backend_disable_mask)
1256{
1257 u32 backend_map = 0;
1258 u32 enabled_backends_mask;
1259 u32 enabled_backends_count;
1260 u32 cur_pipe;
1261 u32 swizzle_pipe[R6XX_MAX_PIPES];
1262 u32 cur_backend;
1263 u32 i;
1264
1265 if (num_tile_pipes > R6XX_MAX_PIPES)
1266 num_tile_pipes = R6XX_MAX_PIPES;
1267 if (num_tile_pipes < 1)
1268 num_tile_pipes = 1;
1269 if (num_backends > R6XX_MAX_BACKENDS)
1270 num_backends = R6XX_MAX_BACKENDS;
1271 if (num_backends < 1)
1272 num_backends = 1;
1273
1274 enabled_backends_mask = 0;
1275 enabled_backends_count = 0;
1276 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
1277 if (((backend_disable_mask >> i) & 1) == 0) {
1278 enabled_backends_mask |= (1 << i);
1279 ++enabled_backends_count;
1280 }
1281 if (enabled_backends_count == num_backends)
1282 break;
1283 }
1284
1285 if (enabled_backends_count == 0) {
1286 enabled_backends_mask = 1;
1287 enabled_backends_count = 1;
1288 }
1289
1290 if (enabled_backends_count != num_backends)
1291 num_backends = enabled_backends_count;
1292
1293 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
1294 switch (num_tile_pipes) {
1295 case 1:
1296 swizzle_pipe[0] = 0;
1297 break;
1298 case 2:
1299 swizzle_pipe[0] = 0;
1300 swizzle_pipe[1] = 1;
1301 break;
1302 case 3:
1303 swizzle_pipe[0] = 0;
1304 swizzle_pipe[1] = 1;
1305 swizzle_pipe[2] = 2;
1306 break;
1307 case 4:
1308 swizzle_pipe[0] = 0;
1309 swizzle_pipe[1] = 1;
1310 swizzle_pipe[2] = 2;
1311 swizzle_pipe[3] = 3;
1312 break;
1313 case 5:
1314 swizzle_pipe[0] = 0;
1315 swizzle_pipe[1] = 1;
1316 swizzle_pipe[2] = 2;
1317 swizzle_pipe[3] = 3;
1318 swizzle_pipe[4] = 4;
1319 break;
1320 case 6:
1321 swizzle_pipe[0] = 0;
1322 swizzle_pipe[1] = 2;
1323 swizzle_pipe[2] = 4;
1324 swizzle_pipe[3] = 5;
1325 swizzle_pipe[4] = 1;
1326 swizzle_pipe[5] = 3;
1327 break;
1328 case 7:
1329 swizzle_pipe[0] = 0;
1330 swizzle_pipe[1] = 2;
1331 swizzle_pipe[2] = 4;
1332 swizzle_pipe[3] = 6;
1333 swizzle_pipe[4] = 1;
1334 swizzle_pipe[5] = 3;
1335 swizzle_pipe[6] = 5;
1336 break;
1337 case 8:
1338 swizzle_pipe[0] = 0;
1339 swizzle_pipe[1] = 2;
1340 swizzle_pipe[2] = 4;
1341 swizzle_pipe[3] = 6;
1342 swizzle_pipe[4] = 1;
1343 swizzle_pipe[5] = 3;
1344 swizzle_pipe[6] = 5;
1345 swizzle_pipe[7] = 7;
1346 break;
1347 }
1348
1349 cur_backend = 0;
1350 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1351 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1352 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1353
1354 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
1355
1356 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
1357 }
1358
1359 return backend_map;
1360}
1361
1362int r600_count_pipe_bits(uint32_t val)
1363{
1364 int i, ret = 0;
1365
1366 for (i = 0; i < 32; i++) {
1367 ret += val & 1;
1368 val >>= 1;
1369 }
1370 return ret;
1371}
1372
1373void r600_gpu_init(struct radeon_device *rdev)
1374{
1375 u32 tiling_config;
1376 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001377 u32 backend_map;
1378 u32 cc_rb_backend_disable;
1379 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001380 u32 tmp;
1381 int i, j;
1382 u32 sq_config;
1383 u32 sq_gpr_resource_mgmt_1 = 0;
1384 u32 sq_gpr_resource_mgmt_2 = 0;
1385 u32 sq_thread_resource_mgmt = 0;
1386 u32 sq_stack_resource_mgmt_1 = 0;
1387 u32 sq_stack_resource_mgmt_2 = 0;
1388
1389 /* FIXME: implement */
1390 switch (rdev->family) {
1391 case CHIP_R600:
1392 rdev->config.r600.max_pipes = 4;
1393 rdev->config.r600.max_tile_pipes = 8;
1394 rdev->config.r600.max_simds = 4;
1395 rdev->config.r600.max_backends = 4;
1396 rdev->config.r600.max_gprs = 256;
1397 rdev->config.r600.max_threads = 192;
1398 rdev->config.r600.max_stack_entries = 256;
1399 rdev->config.r600.max_hw_contexts = 8;
1400 rdev->config.r600.max_gs_threads = 16;
1401 rdev->config.r600.sx_max_export_size = 128;
1402 rdev->config.r600.sx_max_export_pos_size = 16;
1403 rdev->config.r600.sx_max_export_smx_size = 128;
1404 rdev->config.r600.sq_num_cf_insts = 2;
1405 break;
1406 case CHIP_RV630:
1407 case CHIP_RV635:
1408 rdev->config.r600.max_pipes = 2;
1409 rdev->config.r600.max_tile_pipes = 2;
1410 rdev->config.r600.max_simds = 3;
1411 rdev->config.r600.max_backends = 1;
1412 rdev->config.r600.max_gprs = 128;
1413 rdev->config.r600.max_threads = 192;
1414 rdev->config.r600.max_stack_entries = 128;
1415 rdev->config.r600.max_hw_contexts = 8;
1416 rdev->config.r600.max_gs_threads = 4;
1417 rdev->config.r600.sx_max_export_size = 128;
1418 rdev->config.r600.sx_max_export_pos_size = 16;
1419 rdev->config.r600.sx_max_export_smx_size = 128;
1420 rdev->config.r600.sq_num_cf_insts = 2;
1421 break;
1422 case CHIP_RV610:
1423 case CHIP_RV620:
1424 case CHIP_RS780:
1425 case CHIP_RS880:
1426 rdev->config.r600.max_pipes = 1;
1427 rdev->config.r600.max_tile_pipes = 1;
1428 rdev->config.r600.max_simds = 2;
1429 rdev->config.r600.max_backends = 1;
1430 rdev->config.r600.max_gprs = 128;
1431 rdev->config.r600.max_threads = 192;
1432 rdev->config.r600.max_stack_entries = 128;
1433 rdev->config.r600.max_hw_contexts = 4;
1434 rdev->config.r600.max_gs_threads = 4;
1435 rdev->config.r600.sx_max_export_size = 128;
1436 rdev->config.r600.sx_max_export_pos_size = 16;
1437 rdev->config.r600.sx_max_export_smx_size = 128;
1438 rdev->config.r600.sq_num_cf_insts = 1;
1439 break;
1440 case CHIP_RV670:
1441 rdev->config.r600.max_pipes = 4;
1442 rdev->config.r600.max_tile_pipes = 4;
1443 rdev->config.r600.max_simds = 4;
1444 rdev->config.r600.max_backends = 4;
1445 rdev->config.r600.max_gprs = 192;
1446 rdev->config.r600.max_threads = 192;
1447 rdev->config.r600.max_stack_entries = 256;
1448 rdev->config.r600.max_hw_contexts = 8;
1449 rdev->config.r600.max_gs_threads = 16;
1450 rdev->config.r600.sx_max_export_size = 128;
1451 rdev->config.r600.sx_max_export_pos_size = 16;
1452 rdev->config.r600.sx_max_export_smx_size = 128;
1453 rdev->config.r600.sq_num_cf_insts = 2;
1454 break;
1455 default:
1456 break;
1457 }
1458
1459 /* Initialize HDP */
1460 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1461 WREG32((0x2c14 + j), 0x00000000);
1462 WREG32((0x2c18 + j), 0x00000000);
1463 WREG32((0x2c1c + j), 0x00000000);
1464 WREG32((0x2c20 + j), 0x00000000);
1465 WREG32((0x2c24 + j), 0x00000000);
1466 }
1467
1468 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1469
1470 /* Setup tiling */
1471 tiling_config = 0;
1472 ramcfg = RREG32(RAMCFG);
1473 switch (rdev->config.r600.max_tile_pipes) {
1474 case 1:
1475 tiling_config |= PIPE_TILING(0);
1476 break;
1477 case 2:
1478 tiling_config |= PIPE_TILING(1);
1479 break;
1480 case 4:
1481 tiling_config |= PIPE_TILING(2);
1482 break;
1483 case 8:
1484 tiling_config |= PIPE_TILING(3);
1485 break;
1486 default:
1487 break;
1488 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05001489 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00001490 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001491 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1492 tiling_config |= GROUP_SIZE(0);
Jerome Glisse961fb592010-02-10 22:30:05 +00001493 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001494 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1495 if (tmp > 3) {
1496 tiling_config |= ROW_TILING(3);
1497 tiling_config |= SAMPLE_SPLIT(3);
1498 } else {
1499 tiling_config |= ROW_TILING(tmp);
1500 tiling_config |= SAMPLE_SPLIT(tmp);
1501 }
1502 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05001503
1504 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1505 cc_rb_backend_disable |=
1506 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1507
1508 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
1509 cc_gc_shader_pipe_config |=
1510 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1511 cc_gc_shader_pipe_config |=
1512 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1513
1514 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1515 (R6XX_MAX_BACKENDS -
1516 r600_count_pipe_bits((cc_rb_backend_disable &
1517 R6XX_MAX_BACKENDS_MASK) >> 16)),
1518 (cc_rb_backend_disable >> 16));
1519
1520 tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001521 WREG32(GB_TILING_CONFIG, tiling_config);
1522 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1523 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1524
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001525 /* Setup pipes */
Alex Deucherd03f5d52010-02-19 16:22:31 -05001526 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1527 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -05001528 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001529
Alex Deucherd03f5d52010-02-19 16:22:31 -05001530 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 +10001531 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1532 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1533
1534 /* Setup some CP states */
1535 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1536 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1537
1538 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1539 SYNC_WALKER | SYNC_ALIGNER));
1540 /* Setup various GPU states */
1541 if (rdev->family == CHIP_RV670)
1542 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1543
1544 tmp = RREG32(SX_DEBUG_1);
1545 tmp |= SMX_EVENT_RELEASE;
1546 if ((rdev->family > CHIP_R600))
1547 tmp |= ENABLE_NEW_SMX_ADDRESS;
1548 WREG32(SX_DEBUG_1, tmp);
1549
1550 if (((rdev->family) == CHIP_R600) ||
1551 ((rdev->family) == CHIP_RV630) ||
1552 ((rdev->family) == CHIP_RV610) ||
1553 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001554 ((rdev->family) == CHIP_RS780) ||
1555 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001556 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1557 } else {
1558 WREG32(DB_DEBUG, 0);
1559 }
1560 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1561 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1562
1563 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1564 WREG32(VGT_NUM_INSTANCES, 0);
1565
1566 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1567 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1568
1569 tmp = RREG32(SQ_MS_FIFO_SIZES);
1570 if (((rdev->family) == CHIP_RV610) ||
1571 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001572 ((rdev->family) == CHIP_RS780) ||
1573 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001574 tmp = (CACHE_FIFO_SIZE(0xa) |
1575 FETCH_FIFO_HIWATER(0xa) |
1576 DONE_FIFO_HIWATER(0xe0) |
1577 ALU_UPDATE_FIFO_HIWATER(0x8));
1578 } else if (((rdev->family) == CHIP_R600) ||
1579 ((rdev->family) == CHIP_RV630)) {
1580 tmp &= ~DONE_FIFO_HIWATER(0xff);
1581 tmp |= DONE_FIFO_HIWATER(0x4);
1582 }
1583 WREG32(SQ_MS_FIFO_SIZES, tmp);
1584
1585 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1586 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1587 */
1588 sq_config = RREG32(SQ_CONFIG);
1589 sq_config &= ~(PS_PRIO(3) |
1590 VS_PRIO(3) |
1591 GS_PRIO(3) |
1592 ES_PRIO(3));
1593 sq_config |= (DX9_CONSTS |
1594 VC_ENABLE |
1595 PS_PRIO(0) |
1596 VS_PRIO(1) |
1597 GS_PRIO(2) |
1598 ES_PRIO(3));
1599
1600 if ((rdev->family) == CHIP_R600) {
1601 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1602 NUM_VS_GPRS(124) |
1603 NUM_CLAUSE_TEMP_GPRS(4));
1604 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1605 NUM_ES_GPRS(0));
1606 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1607 NUM_VS_THREADS(48) |
1608 NUM_GS_THREADS(4) |
1609 NUM_ES_THREADS(4));
1610 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1611 NUM_VS_STACK_ENTRIES(128));
1612 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1613 NUM_ES_STACK_ENTRIES(0));
1614 } else if (((rdev->family) == CHIP_RV610) ||
1615 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001616 ((rdev->family) == CHIP_RS780) ||
1617 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001618 /* no vertex cache */
1619 sq_config &= ~VC_ENABLE;
1620
1621 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1622 NUM_VS_GPRS(44) |
1623 NUM_CLAUSE_TEMP_GPRS(2));
1624 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1625 NUM_ES_GPRS(17));
1626 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1627 NUM_VS_THREADS(78) |
1628 NUM_GS_THREADS(4) |
1629 NUM_ES_THREADS(31));
1630 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1631 NUM_VS_STACK_ENTRIES(40));
1632 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1633 NUM_ES_STACK_ENTRIES(16));
1634 } else if (((rdev->family) == CHIP_RV630) ||
1635 ((rdev->family) == CHIP_RV635)) {
1636 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1637 NUM_VS_GPRS(44) |
1638 NUM_CLAUSE_TEMP_GPRS(2));
1639 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1640 NUM_ES_GPRS(18));
1641 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1642 NUM_VS_THREADS(78) |
1643 NUM_GS_THREADS(4) |
1644 NUM_ES_THREADS(31));
1645 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1646 NUM_VS_STACK_ENTRIES(40));
1647 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1648 NUM_ES_STACK_ENTRIES(16));
1649 } else if ((rdev->family) == CHIP_RV670) {
1650 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1651 NUM_VS_GPRS(44) |
1652 NUM_CLAUSE_TEMP_GPRS(2));
1653 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1654 NUM_ES_GPRS(17));
1655 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1656 NUM_VS_THREADS(78) |
1657 NUM_GS_THREADS(4) |
1658 NUM_ES_THREADS(31));
1659 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1660 NUM_VS_STACK_ENTRIES(64));
1661 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1662 NUM_ES_STACK_ENTRIES(64));
1663 }
1664
1665 WREG32(SQ_CONFIG, sq_config);
1666 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1667 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1668 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1669 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1670 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1671
1672 if (((rdev->family) == CHIP_RV610) ||
1673 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001674 ((rdev->family) == CHIP_RS780) ||
1675 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001676 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1677 } else {
1678 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1679 }
1680
1681 /* More default values. 2D/3D driver should adjust as needed */
1682 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1683 S1_X(0x4) | S1_Y(0xc)));
1684 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1685 S1_X(0x2) | S1_Y(0x2) |
1686 S2_X(0xa) | S2_Y(0x6) |
1687 S3_X(0x6) | S3_Y(0xa)));
1688 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1689 S1_X(0x4) | S1_Y(0xc) |
1690 S2_X(0x1) | S2_Y(0x6) |
1691 S3_X(0xa) | S3_Y(0xe)));
1692 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1693 S5_X(0x0) | S5_Y(0x0) |
1694 S6_X(0xb) | S6_Y(0x4) |
1695 S7_X(0x7) | S7_Y(0x8)));
1696
1697 WREG32(VGT_STRMOUT_EN, 0);
1698 tmp = rdev->config.r600.max_pipes * 16;
1699 switch (rdev->family) {
1700 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001701 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001702 case CHIP_RS780:
1703 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001704 tmp += 32;
1705 break;
1706 case CHIP_RV670:
1707 tmp += 128;
1708 break;
1709 default:
1710 break;
1711 }
1712 if (tmp > 256) {
1713 tmp = 256;
1714 }
1715 WREG32(VGT_ES_PER_GS, 128);
1716 WREG32(VGT_GS_PER_ES, tmp);
1717 WREG32(VGT_GS_PER_VS, 2);
1718 WREG32(VGT_GS_VERTEX_REUSE, 16);
1719
1720 /* more default values. 2D/3D driver should adjust as needed */
1721 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1722 WREG32(VGT_STRMOUT_EN, 0);
1723 WREG32(SX_MISC, 0);
1724 WREG32(PA_SC_MODE_CNTL, 0);
1725 WREG32(PA_SC_AA_CONFIG, 0);
1726 WREG32(PA_SC_LINE_STIPPLE, 0);
1727 WREG32(SPI_INPUT_Z, 0);
1728 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1729 WREG32(CB_COLOR7_FRAG, 0);
1730
1731 /* Clear render buffer base addresses */
1732 WREG32(CB_COLOR0_BASE, 0);
1733 WREG32(CB_COLOR1_BASE, 0);
1734 WREG32(CB_COLOR2_BASE, 0);
1735 WREG32(CB_COLOR3_BASE, 0);
1736 WREG32(CB_COLOR4_BASE, 0);
1737 WREG32(CB_COLOR5_BASE, 0);
1738 WREG32(CB_COLOR6_BASE, 0);
1739 WREG32(CB_COLOR7_BASE, 0);
1740 WREG32(CB_COLOR7_FRAG, 0);
1741
1742 switch (rdev->family) {
1743 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001744 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001745 case CHIP_RS780:
1746 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001747 tmp = TC_L2_SIZE(8);
1748 break;
1749 case CHIP_RV630:
1750 case CHIP_RV635:
1751 tmp = TC_L2_SIZE(4);
1752 break;
1753 case CHIP_R600:
1754 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1755 break;
1756 default:
1757 tmp = TC_L2_SIZE(0);
1758 break;
1759 }
1760 WREG32(TC_CNTL, tmp);
1761
1762 tmp = RREG32(HDP_HOST_PATH_CNTL);
1763 WREG32(HDP_HOST_PATH_CNTL, tmp);
1764
1765 tmp = RREG32(ARB_POP);
1766 tmp |= ENABLE_TC128;
1767 WREG32(ARB_POP, tmp);
1768
1769 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1770 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1771 NUM_CLIP_SEQ(3)));
1772 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1773}
1774
1775
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001776/*
1777 * Indirect registers accessor
1778 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001779u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001780{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001781 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001782
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001783 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1784 (void)RREG32(PCIE_PORT_INDEX);
1785 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001786 return r;
1787}
1788
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001789void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001790{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001791 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1792 (void)RREG32(PCIE_PORT_INDEX);
1793 WREG32(PCIE_PORT_DATA, (v));
1794 (void)RREG32(PCIE_PORT_DATA);
1795}
1796
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001797/*
1798 * CP & Ring
1799 */
1800void r600_cp_stop(struct radeon_device *rdev)
1801{
1802 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1803}
1804
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001805int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001806{
1807 struct platform_device *pdev;
1808 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001809 const char *rlc_chip_name;
1810 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001811 char fw_name[30];
1812 int err;
1813
1814 DRM_DEBUG("\n");
1815
1816 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1817 err = IS_ERR(pdev);
1818 if (err) {
1819 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1820 return -EINVAL;
1821 }
1822
1823 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001824 case CHIP_R600:
1825 chip_name = "R600";
1826 rlc_chip_name = "R600";
1827 break;
1828 case CHIP_RV610:
1829 chip_name = "RV610";
1830 rlc_chip_name = "R600";
1831 break;
1832 case CHIP_RV630:
1833 chip_name = "RV630";
1834 rlc_chip_name = "R600";
1835 break;
1836 case CHIP_RV620:
1837 chip_name = "RV620";
1838 rlc_chip_name = "R600";
1839 break;
1840 case CHIP_RV635:
1841 chip_name = "RV635";
1842 rlc_chip_name = "R600";
1843 break;
1844 case CHIP_RV670:
1845 chip_name = "RV670";
1846 rlc_chip_name = "R600";
1847 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001848 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001849 case CHIP_RS880:
1850 chip_name = "RS780";
1851 rlc_chip_name = "R600";
1852 break;
1853 case CHIP_RV770:
1854 chip_name = "RV770";
1855 rlc_chip_name = "R700";
1856 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001857 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001858 case CHIP_RV740:
1859 chip_name = "RV730";
1860 rlc_chip_name = "R700";
1861 break;
1862 case CHIP_RV710:
1863 chip_name = "RV710";
1864 rlc_chip_name = "R700";
1865 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04001866 case CHIP_CEDAR:
1867 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04001868 rlc_chip_name = "CEDAR";
Alex Deucherfe251e22010-03-24 13:36:43 -04001869 break;
1870 case CHIP_REDWOOD:
1871 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04001872 rlc_chip_name = "REDWOOD";
Alex Deucherfe251e22010-03-24 13:36:43 -04001873 break;
1874 case CHIP_JUNIPER:
1875 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04001876 rlc_chip_name = "JUNIPER";
Alex Deucherfe251e22010-03-24 13:36:43 -04001877 break;
1878 case CHIP_CYPRESS:
1879 case CHIP_HEMLOCK:
1880 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04001881 rlc_chip_name = "CYPRESS";
Alex Deucherfe251e22010-03-24 13:36:43 -04001882 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001883 default: BUG();
1884 }
1885
Alex Deucherfe251e22010-03-24 13:36:43 -04001886 if (rdev->family >= CHIP_CEDAR) {
1887 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
1888 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04001889 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04001890 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001891 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
1892 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001893 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001894 } else {
1895 pfp_req_size = PFP_UCODE_SIZE * 4;
1896 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001897 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001898 }
1899
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001900 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001901
1902 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
1903 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
1904 if (err)
1905 goto out;
1906 if (rdev->pfp_fw->size != pfp_req_size) {
1907 printk(KERN_ERR
1908 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1909 rdev->pfp_fw->size, fw_name);
1910 err = -EINVAL;
1911 goto out;
1912 }
1913
1914 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
1915 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
1916 if (err)
1917 goto out;
1918 if (rdev->me_fw->size != me_req_size) {
1919 printk(KERN_ERR
1920 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1921 rdev->me_fw->size, fw_name);
1922 err = -EINVAL;
1923 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001924
1925 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
1926 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
1927 if (err)
1928 goto out;
1929 if (rdev->rlc_fw->size != rlc_req_size) {
1930 printk(KERN_ERR
1931 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
1932 rdev->rlc_fw->size, fw_name);
1933 err = -EINVAL;
1934 }
1935
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001936out:
1937 platform_device_unregister(pdev);
1938
1939 if (err) {
1940 if (err != -EINVAL)
1941 printk(KERN_ERR
1942 "r600_cp: Failed to load firmware \"%s\"\n",
1943 fw_name);
1944 release_firmware(rdev->pfp_fw);
1945 rdev->pfp_fw = NULL;
1946 release_firmware(rdev->me_fw);
1947 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001948 release_firmware(rdev->rlc_fw);
1949 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001950 }
1951 return err;
1952}
1953
1954static int r600_cp_load_microcode(struct radeon_device *rdev)
1955{
1956 const __be32 *fw_data;
1957 int i;
1958
1959 if (!rdev->me_fw || !rdev->pfp_fw)
1960 return -EINVAL;
1961
1962 r600_cp_stop(rdev);
1963
1964 WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
1965
1966 /* Reset cp */
1967 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
1968 RREG32(GRBM_SOFT_RESET);
1969 mdelay(15);
1970 WREG32(GRBM_SOFT_RESET, 0);
1971
1972 WREG32(CP_ME_RAM_WADDR, 0);
1973
1974 fw_data = (const __be32 *)rdev->me_fw->data;
1975 WREG32(CP_ME_RAM_WADDR, 0);
1976 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
1977 WREG32(CP_ME_RAM_DATA,
1978 be32_to_cpup(fw_data++));
1979
1980 fw_data = (const __be32 *)rdev->pfp_fw->data;
1981 WREG32(CP_PFP_UCODE_ADDR, 0);
1982 for (i = 0; i < PFP_UCODE_SIZE; i++)
1983 WREG32(CP_PFP_UCODE_DATA,
1984 be32_to_cpup(fw_data++));
1985
1986 WREG32(CP_PFP_UCODE_ADDR, 0);
1987 WREG32(CP_ME_RAM_WADDR, 0);
1988 WREG32(CP_ME_RAM_RADDR, 0);
1989 return 0;
1990}
1991
1992int r600_cp_start(struct radeon_device *rdev)
1993{
1994 int r;
1995 uint32_t cp_me;
1996
1997 r = radeon_ring_lock(rdev, 7);
1998 if (r) {
1999 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2000 return r;
2001 }
2002 radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
2003 radeon_ring_write(rdev, 0x1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002004 if (rdev->family >= CHIP_CEDAR) {
2005 radeon_ring_write(rdev, 0x0);
2006 radeon_ring_write(rdev, rdev->config.evergreen.max_hw_contexts - 1);
2007 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002008 radeon_ring_write(rdev, 0x0);
2009 radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002010 } else {
2011 radeon_ring_write(rdev, 0x3);
2012 radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002013 }
2014 radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2015 radeon_ring_write(rdev, 0);
2016 radeon_ring_write(rdev, 0);
2017 radeon_ring_unlock_commit(rdev);
2018
2019 cp_me = 0xff;
2020 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2021 return 0;
2022}
2023
2024int r600_cp_resume(struct radeon_device *rdev)
2025{
2026 u32 tmp;
2027 u32 rb_bufsz;
2028 int r;
2029
2030 /* Reset cp */
2031 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2032 RREG32(GRBM_SOFT_RESET);
2033 mdelay(15);
2034 WREG32(GRBM_SOFT_RESET, 0);
2035
2036 /* Set ring buffer size */
2037 rb_bufsz = drm_order(rdev->cp.ring_size / 8);
Alex Deucherd6f28932009-11-02 16:01:27 -05002038 tmp = RB_NO_UPDATE | (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002039#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002040 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002041#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002042 WREG32(CP_RB_CNTL, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002043 WREG32(CP_SEM_WAIT_TIMER, 0x4);
2044
2045 /* Set the write pointer delay */
2046 WREG32(CP_RB_WPTR_DELAY, 0);
2047
2048 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002049 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2050 WREG32(CP_RB_RPTR_WR, 0);
2051 WREG32(CP_RB_WPTR, 0);
2052 WREG32(CP_RB_RPTR_ADDR, rdev->cp.gpu_addr & 0xFFFFFFFF);
2053 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->cp.gpu_addr));
2054 mdelay(1);
2055 WREG32(CP_RB_CNTL, tmp);
2056
2057 WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
2058 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2059
2060 rdev->cp.rptr = RREG32(CP_RB_RPTR);
2061 rdev->cp.wptr = RREG32(CP_RB_WPTR);
2062
2063 r600_cp_start(rdev);
2064 rdev->cp.ready = true;
2065 r = radeon_ring_test(rdev);
2066 if (r) {
2067 rdev->cp.ready = false;
2068 return r;
2069 }
2070 return 0;
2071}
2072
2073void r600_cp_commit(struct radeon_device *rdev)
2074{
2075 WREG32(CP_RB_WPTR, rdev->cp.wptr);
2076 (void)RREG32(CP_RB_WPTR);
2077}
2078
2079void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
2080{
2081 u32 rb_bufsz;
2082
2083 /* Align ring size */
2084 rb_bufsz = drm_order(ring_size / 8);
2085 ring_size = (1 << (rb_bufsz + 1)) * 4;
2086 rdev->cp.ring_size = ring_size;
2087 rdev->cp.align_mask = 16 - 1;
2088}
2089
Jerome Glisse655efd32010-02-02 11:51:45 +01002090void r600_cp_fini(struct radeon_device *rdev)
2091{
2092 r600_cp_stop(rdev);
2093 radeon_ring_fini(rdev);
2094}
2095
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002096
2097/*
2098 * GPU scratch registers helpers function.
2099 */
2100void r600_scratch_init(struct radeon_device *rdev)
2101{
2102 int i;
2103
2104 rdev->scratch.num_reg = 7;
2105 for (i = 0; i < rdev->scratch.num_reg; i++) {
2106 rdev->scratch.free[i] = true;
2107 rdev->scratch.reg[i] = SCRATCH_REG0 + (i * 4);
2108 }
2109}
2110
2111int r600_ring_test(struct radeon_device *rdev)
2112{
2113 uint32_t scratch;
2114 uint32_t tmp = 0;
2115 unsigned i;
2116 int r;
2117
2118 r = radeon_scratch_get(rdev, &scratch);
2119 if (r) {
2120 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2121 return r;
2122 }
2123 WREG32(scratch, 0xCAFEDEAD);
2124 r = radeon_ring_lock(rdev, 3);
2125 if (r) {
2126 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2127 radeon_scratch_free(rdev, scratch);
2128 return r;
2129 }
2130 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2131 radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2132 radeon_ring_write(rdev, 0xDEADBEEF);
2133 radeon_ring_unlock_commit(rdev);
2134 for (i = 0; i < rdev->usec_timeout; i++) {
2135 tmp = RREG32(scratch);
2136 if (tmp == 0xDEADBEEF)
2137 break;
2138 DRM_UDELAY(1);
2139 }
2140 if (i < rdev->usec_timeout) {
2141 DRM_INFO("ring test succeeded in %d usecs\n", i);
2142 } else {
2143 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
2144 scratch, tmp);
2145 r = -EINVAL;
2146 }
2147 radeon_scratch_free(rdev, scratch);
2148 return r;
2149}
2150
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002151void r600_wb_disable(struct radeon_device *rdev)
2152{
Jerome Glisse4c788672009-11-20 14:29:23 +01002153 int r;
2154
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002155 WREG32(SCRATCH_UMSK, 0);
2156 if (rdev->wb.wb_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002157 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
2158 if (unlikely(r != 0))
2159 return;
2160 radeon_bo_kunmap(rdev->wb.wb_obj);
2161 radeon_bo_unpin(rdev->wb.wb_obj);
2162 radeon_bo_unreserve(rdev->wb.wb_obj);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002163 }
2164}
2165
2166void r600_wb_fini(struct radeon_device *rdev)
2167{
2168 r600_wb_disable(rdev);
2169 if (rdev->wb.wb_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002170 radeon_bo_unref(&rdev->wb.wb_obj);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002171 rdev->wb.wb = NULL;
2172 rdev->wb.wb_obj = NULL;
2173 }
2174}
2175
2176int r600_wb_enable(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002177{
2178 int r;
2179
2180 if (rdev->wb.wb_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002181 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
2182 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002183 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002184 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002185 return r;
2186 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002187 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
2188 if (unlikely(r != 0)) {
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002189 r600_wb_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002190 return r;
2191 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002192 r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
2193 &rdev->wb.gpu_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002194 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002195 radeon_bo_unreserve(rdev->wb.wb_obj);
2196 dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
2197 r600_wb_fini(rdev);
2198 return r;
2199 }
2200 r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
2201 radeon_bo_unreserve(rdev->wb.wb_obj);
2202 if (r) {
2203 dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002204 r600_wb_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002205 return r;
2206 }
2207 }
2208 WREG32(SCRATCH_ADDR, (rdev->wb.gpu_addr >> 8) & 0xFFFFFFFF);
2209 WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + 1024) & 0xFFFFFFFC);
2210 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + 1024) & 0xFF);
2211 WREG32(SCRATCH_UMSK, 0xff);
2212 return 0;
2213}
2214
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002215void r600_fence_ring_emit(struct radeon_device *rdev,
2216 struct radeon_fence *fence)
2217{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002218 /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
Alex Deucher44224c32010-02-04 11:01:52 -05002219
2220 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
2221 radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
2222 /* wait for 3D idle clean */
2223 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2224 radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2225 radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002226 /* Emit fence sequence & fire IRQ */
2227 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2228 radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2229 radeon_ring_write(rdev, fence->seq);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002230 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2231 radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
2232 radeon_ring_write(rdev, RB_INT_STAT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002233}
2234
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002235int r600_copy_blit(struct radeon_device *rdev,
2236 uint64_t src_offset, uint64_t dst_offset,
2237 unsigned num_pages, struct radeon_fence *fence)
2238{
Jerome Glisseff82f052010-01-22 15:19:00 +01002239 int r;
2240
2241 mutex_lock(&rdev->r600_blit.mutex);
2242 rdev->r600_blit.vb_ib = NULL;
2243 r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
2244 if (r) {
2245 if (rdev->r600_blit.vb_ib)
2246 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
2247 mutex_unlock(&rdev->r600_blit.mutex);
2248 return r;
2249 }
Matt Turnera77f1712009-10-14 00:34:41 -04002250 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002251 r600_blit_done_copy(rdev, fence);
Jerome Glisseff82f052010-01-22 15:19:00 +01002252 mutex_unlock(&rdev->r600_blit.mutex);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002253 return 0;
2254}
2255
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002256int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2257 uint32_t tiling_flags, uint32_t pitch,
2258 uint32_t offset, uint32_t obj_size)
2259{
2260 /* FIXME: implement */
2261 return 0;
2262}
2263
2264void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2265{
2266 /* FIXME: implement */
2267}
2268
2269
2270bool r600_card_posted(struct radeon_device *rdev)
2271{
2272 uint32_t reg;
2273
2274 /* first check CRTCs */
2275 reg = RREG32(D1CRTC_CONTROL) |
2276 RREG32(D2CRTC_CONTROL);
2277 if (reg & CRTC_EN)
2278 return true;
2279
2280 /* then check MEM_SIZE, in case the crtcs are off */
2281 if (RREG32(CONFIG_MEMSIZE))
2282 return true;
2283
2284 return false;
2285}
2286
Dave Airliefc30b8e2009-09-18 15:19:37 +10002287int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002288{
2289 int r;
2290
Alex Deucher779720a2009-12-09 19:31:44 -05002291 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2292 r = r600_init_microcode(rdev);
2293 if (r) {
2294 DRM_ERROR("Failed to load firmware!\n");
2295 return r;
2296 }
2297 }
2298
Jerome Glissea3c19452009-10-01 18:02:13 +02002299 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02002300 if (rdev->flags & RADEON_IS_AGP) {
2301 r600_agp_enable(rdev);
2302 } else {
2303 r = r600_pcie_gart_enable(rdev);
2304 if (r)
2305 return r;
2306 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002307 r600_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01002308 r = r600_blit_init(rdev);
2309 if (r) {
2310 r600_blit_fini(rdev);
2311 rdev->asic->copy = NULL;
2312 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2313 }
Jerome Glisseff82f052010-01-22 15:19:00 +01002314 /* pin copy shader into vram */
2315 if (rdev->r600_blit.shader_obj) {
2316 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
2317 if (unlikely(r != 0))
2318 return r;
2319 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
2320 &rdev->r600_blit.shader_gpu_addr);
2321 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Alex Deucher7923c612009-12-15 17:15:07 -05002322 if (r) {
Jerome Glisseff82f052010-01-22 15:19:00 +01002323 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
Alex Deucher7923c612009-12-15 17:15:07 -05002324 return r;
2325 }
2326 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002327 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002328 r = r600_irq_init(rdev);
2329 if (r) {
2330 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2331 radeon_irq_kms_fini(rdev);
2332 return r;
2333 }
2334 r600_irq_set(rdev);
2335
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002336 r = radeon_ring_init(rdev, rdev->cp.ring_size);
2337 if (r)
2338 return r;
2339 r = r600_cp_load_microcode(rdev);
2340 if (r)
2341 return r;
2342 r = r600_cp_resume(rdev);
2343 if (r)
2344 return r;
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002345 /* write back buffer are not vital so don't worry about failure */
2346 r600_wb_enable(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002347 return 0;
2348}
2349
Dave Airlie28d52042009-09-21 14:33:58 +10002350void r600_vga_set_state(struct radeon_device *rdev, bool state)
2351{
2352 uint32_t temp;
2353
2354 temp = RREG32(CONFIG_CNTL);
2355 if (state == false) {
2356 temp &= ~(1<<0);
2357 temp |= (1<<1);
2358 } else {
2359 temp &= ~(1<<1);
2360 }
2361 WREG32(CONFIG_CNTL, temp);
2362}
2363
Dave Airliefc30b8e2009-09-18 15:19:37 +10002364int r600_resume(struct radeon_device *rdev)
2365{
2366 int r;
2367
Jerome Glisse1a029b72009-10-06 19:04:30 +02002368 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2369 * posting will perform necessary task to bring back GPU into good
2370 * shape.
2371 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10002372 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002373 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002374 /* Initialize clocks */
2375 r = radeon_clocks_init(rdev);
2376 if (r) {
2377 return r;
2378 }
2379
2380 r = r600_startup(rdev);
2381 if (r) {
2382 DRM_ERROR("r600 startup failed on resume\n");
2383 return r;
2384 }
2385
Jerome Glisse62a8ea32009-10-01 18:02:11 +02002386 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10002387 if (r) {
2388 DRM_ERROR("radeon: failled testing IB (%d).\n", r);
2389 return r;
2390 }
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002391
2392 r = r600_audio_init(rdev);
2393 if (r) {
2394 DRM_ERROR("radeon: audio resume failed\n");
2395 return r;
2396 }
2397
Dave Airliefc30b8e2009-09-18 15:19:37 +10002398 return r;
2399}
2400
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002401int r600_suspend(struct radeon_device *rdev)
2402{
Jerome Glisse4c788672009-11-20 14:29:23 +01002403 int r;
2404
Rafał Miłecki38fd2c62010-01-28 18:16:30 +01002405 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002406 /* FIXME: we should wait for ring to be empty */
2407 r600_cp_stop(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002408 rdev->cp.ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01002409 r600_irq_suspend(rdev);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002410 r600_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002411 r600_pcie_gart_disable(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10002412 /* unpin shaders bo */
Jerome Glisse30d2d9a2010-01-13 10:29:27 +01002413 if (rdev->r600_blit.shader_obj) {
2414 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
2415 if (!r) {
2416 radeon_bo_unpin(rdev->r600_blit.shader_obj);
2417 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
2418 }
2419 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002420 return 0;
2421}
2422
2423/* Plan is to move initialization in that function and use
2424 * helper function so that radeon_device_init pretty much
2425 * do nothing more than calling asic specific function. This
2426 * should also allow to remove a bunch of callback function
2427 * like vram_info.
2428 */
2429int r600_init(struct radeon_device *rdev)
2430{
2431 int r;
2432
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002433 r = radeon_dummy_page_init(rdev);
2434 if (r)
2435 return r;
2436 if (r600_debugfs_mc_info_init(rdev)) {
2437 DRM_ERROR("Failed to register debugfs file for mc !\n");
2438 }
2439 /* This don't do much */
2440 r = radeon_gem_init(rdev);
2441 if (r)
2442 return r;
2443 /* Read BIOS */
2444 if (!radeon_get_bios(rdev)) {
2445 if (ASIC_IS_AVIVO(rdev))
2446 return -EINVAL;
2447 }
2448 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02002449 if (!rdev->is_atom_bios) {
2450 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002451 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002452 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002453 r = radeon_atombios_init(rdev);
2454 if (r)
2455 return r;
2456 /* Post card if necessary */
Dave Airlie72542d72009-12-01 14:06:31 +10002457 if (!r600_card_posted(rdev)) {
2458 if (!rdev->bios) {
2459 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2460 return -EINVAL;
2461 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002462 DRM_INFO("GPU not posted. posting now...\n");
2463 atom_asic_init(rdev->mode_info.atom_context);
2464 }
2465 /* Initialize scratch registers */
2466 r600_scratch_init(rdev);
2467 /* Initialize surface registers */
2468 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002469 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002470 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002471 r = radeon_clocks_init(rdev);
2472 if (r)
2473 return r;
2474 /* Fence driver */
2475 r = radeon_fence_driver_init(rdev);
2476 if (r)
2477 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01002478 if (rdev->flags & RADEON_IS_AGP) {
2479 r = radeon_agp_init(rdev);
2480 if (r)
2481 radeon_agp_disable(rdev);
2482 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002483 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002484 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002485 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002486 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002487 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002488 if (r)
2489 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002490
2491 r = radeon_irq_kms_init(rdev);
2492 if (r)
2493 return r;
2494
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002495 rdev->cp.ring_obj = NULL;
2496 r600_ring_init(rdev, 1024 * 1024);
2497
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002498 rdev->ih.ring_obj = NULL;
2499 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002500
Jerome Glisse4aac0472009-09-14 18:29:49 +02002501 r = r600_pcie_gart_init(rdev);
2502 if (r)
2503 return r;
2504
Alex Deucher779720a2009-12-09 19:31:44 -05002505 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002506 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002507 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01002508 dev_err(rdev->dev, "disabling GPU acceleration\n");
2509 r600_cp_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002510 r600_wb_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002511 r600_irq_fini(rdev);
2512 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002513 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002514 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002515 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002516 if (rdev->accel_working) {
2517 r = radeon_ib_pool_init(rdev);
2518 if (r) {
Jerome Glissedb963802010-01-17 21:21:56 +01002519 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02002520 rdev->accel_working = false;
Jerome Glissedb963802010-01-17 21:21:56 +01002521 } else {
2522 r = r600_ib_test(rdev);
2523 if (r) {
2524 dev_err(rdev->dev, "IB test failed (%d).\n", r);
2525 rdev->accel_working = false;
2526 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002527 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002528 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002529
2530 r = r600_audio_init(rdev);
2531 if (r)
2532 return r; /* TODO error handling */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002533 return 0;
2534}
2535
2536void r600_fini(struct radeon_device *rdev)
2537{
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002538 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002539 r600_blit_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002540 r600_cp_fini(rdev);
2541 r600_wb_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002542 r600_irq_fini(rdev);
2543 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002544 r600_pcie_gart_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01002545 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002546 radeon_gem_fini(rdev);
2547 radeon_fence_driver_fini(rdev);
2548 radeon_clocks_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002549 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002550 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002551 kfree(rdev->bios);
2552 rdev->bios = NULL;
2553 radeon_dummy_page_fini(rdev);
2554}
2555
2556
2557/*
2558 * CS stuff
2559 */
2560void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2561{
2562 /* FIXME: implement */
2563 radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2564 radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
2565 radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
2566 radeon_ring_write(rdev, ib->length_dw);
2567}
2568
2569int r600_ib_test(struct radeon_device *rdev)
2570{
2571 struct radeon_ib *ib;
2572 uint32_t scratch;
2573 uint32_t tmp = 0;
2574 unsigned i;
2575 int r;
2576
2577 r = radeon_scratch_get(rdev, &scratch);
2578 if (r) {
2579 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2580 return r;
2581 }
2582 WREG32(scratch, 0xCAFEDEAD);
2583 r = radeon_ib_get(rdev, &ib);
2584 if (r) {
2585 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2586 return r;
2587 }
2588 ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2589 ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2590 ib->ptr[2] = 0xDEADBEEF;
2591 ib->ptr[3] = PACKET2(0);
2592 ib->ptr[4] = PACKET2(0);
2593 ib->ptr[5] = PACKET2(0);
2594 ib->ptr[6] = PACKET2(0);
2595 ib->ptr[7] = PACKET2(0);
2596 ib->ptr[8] = PACKET2(0);
2597 ib->ptr[9] = PACKET2(0);
2598 ib->ptr[10] = PACKET2(0);
2599 ib->ptr[11] = PACKET2(0);
2600 ib->ptr[12] = PACKET2(0);
2601 ib->ptr[13] = PACKET2(0);
2602 ib->ptr[14] = PACKET2(0);
2603 ib->ptr[15] = PACKET2(0);
2604 ib->length_dw = 16;
2605 r = radeon_ib_schedule(rdev, ib);
2606 if (r) {
2607 radeon_scratch_free(rdev, scratch);
2608 radeon_ib_free(rdev, &ib);
2609 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2610 return r;
2611 }
2612 r = radeon_fence_wait(ib->fence, false);
2613 if (r) {
2614 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2615 return r;
2616 }
2617 for (i = 0; i < rdev->usec_timeout; i++) {
2618 tmp = RREG32(scratch);
2619 if (tmp == 0xDEADBEEF)
2620 break;
2621 DRM_UDELAY(1);
2622 }
2623 if (i < rdev->usec_timeout) {
2624 DRM_INFO("ib test succeeded in %u usecs\n", i);
2625 } else {
2626 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
2627 scratch, tmp);
2628 r = -EINVAL;
2629 }
2630 radeon_scratch_free(rdev, scratch);
2631 radeon_ib_free(rdev, &ib);
2632 return r;
2633}
2634
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002635/*
2636 * Interrupts
2637 *
2638 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2639 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2640 * writing to the ring and the GPU consuming, the GPU writes to the ring
2641 * and host consumes. As the host irq handler processes interrupts, it
2642 * increments the rptr. When the rptr catches up with the wptr, all the
2643 * current interrupts have been processed.
2644 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002645
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002646void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2647{
2648 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002649
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002650 /* Align ring size */
2651 rb_bufsz = drm_order(ring_size / 4);
2652 ring_size = (1 << rb_bufsz) * 4;
2653 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01002654 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
2655 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002656}
2657
Jerome Glisse0c452492010-01-15 14:44:37 +01002658static int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002659{
2660 int r;
2661
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002662 /* Allocate ring buffer */
2663 if (rdev->ih.ring_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002664 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
2665 true,
2666 RADEON_GEM_DOMAIN_GTT,
2667 &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002668 if (r) {
2669 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2670 return r;
2671 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002672 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2673 if (unlikely(r != 0))
2674 return r;
2675 r = radeon_bo_pin(rdev->ih.ring_obj,
2676 RADEON_GEM_DOMAIN_GTT,
2677 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002678 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002679 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002680 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2681 return r;
2682 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002683 r = radeon_bo_kmap(rdev->ih.ring_obj,
2684 (void **)&rdev->ih.ring);
2685 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002686 if (r) {
2687 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2688 return r;
2689 }
2690 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002691 return 0;
2692}
2693
2694static void r600_ih_ring_fini(struct radeon_device *rdev)
2695{
Jerome Glisse4c788672009-11-20 14:29:23 +01002696 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002697 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002698 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2699 if (likely(r == 0)) {
2700 radeon_bo_kunmap(rdev->ih.ring_obj);
2701 radeon_bo_unpin(rdev->ih.ring_obj);
2702 radeon_bo_unreserve(rdev->ih.ring_obj);
2703 }
2704 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002705 rdev->ih.ring = NULL;
2706 rdev->ih.ring_obj = NULL;
2707 }
2708}
2709
Alex Deucher45f9a392010-03-24 13:55:51 -04002710void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002711{
2712
Alex Deucher45f9a392010-03-24 13:55:51 -04002713 if ((rdev->family >= CHIP_RV770) &&
2714 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002715 /* r7xx asics need to soft reset RLC before halting */
2716 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2717 RREG32(SRBM_SOFT_RESET);
2718 udelay(15000);
2719 WREG32(SRBM_SOFT_RESET, 0);
2720 RREG32(SRBM_SOFT_RESET);
2721 }
2722
2723 WREG32(RLC_CNTL, 0);
2724}
2725
2726static void r600_rlc_start(struct radeon_device *rdev)
2727{
2728 WREG32(RLC_CNTL, RLC_ENABLE);
2729}
2730
2731static int r600_rlc_init(struct radeon_device *rdev)
2732{
2733 u32 i;
2734 const __be32 *fw_data;
2735
2736 if (!rdev->rlc_fw)
2737 return -EINVAL;
2738
2739 r600_rlc_stop(rdev);
2740
2741 WREG32(RLC_HB_BASE, 0);
2742 WREG32(RLC_HB_CNTL, 0);
2743 WREG32(RLC_HB_RPTR, 0);
2744 WREG32(RLC_HB_WPTR, 0);
2745 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2746 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2747 WREG32(RLC_MC_CNTL, 0);
2748 WREG32(RLC_UCODE_CNTL, 0);
2749
2750 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucher45f9a392010-03-24 13:55:51 -04002751 if (rdev->family >= CHIP_CEDAR) {
2752 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
2753 WREG32(RLC_UCODE_ADDR, i);
2754 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2755 }
2756 } else if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002757 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2758 WREG32(RLC_UCODE_ADDR, i);
2759 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2760 }
2761 } else {
2762 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2763 WREG32(RLC_UCODE_ADDR, i);
2764 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2765 }
2766 }
2767 WREG32(RLC_UCODE_ADDR, 0);
2768
2769 r600_rlc_start(rdev);
2770
2771 return 0;
2772}
2773
2774static void r600_enable_interrupts(struct radeon_device *rdev)
2775{
2776 u32 ih_cntl = RREG32(IH_CNTL);
2777 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2778
2779 ih_cntl |= ENABLE_INTR;
2780 ih_rb_cntl |= IH_RB_ENABLE;
2781 WREG32(IH_CNTL, ih_cntl);
2782 WREG32(IH_RB_CNTL, ih_rb_cntl);
2783 rdev->ih.enabled = true;
2784}
2785
Alex Deucher45f9a392010-03-24 13:55:51 -04002786void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002787{
2788 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2789 u32 ih_cntl = RREG32(IH_CNTL);
2790
2791 ih_rb_cntl &= ~IH_RB_ENABLE;
2792 ih_cntl &= ~ENABLE_INTR;
2793 WREG32(IH_RB_CNTL, ih_rb_cntl);
2794 WREG32(IH_CNTL, ih_cntl);
2795 /* set rptr, wptr to 0 */
2796 WREG32(IH_RB_RPTR, 0);
2797 WREG32(IH_RB_WPTR, 0);
2798 rdev->ih.enabled = false;
2799 rdev->ih.wptr = 0;
2800 rdev->ih.rptr = 0;
2801}
2802
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002803static void r600_disable_interrupt_state(struct radeon_device *rdev)
2804{
2805 u32 tmp;
2806
2807 WREG32(CP_INT_CNTL, 0);
2808 WREG32(GRBM_INT_CNTL, 0);
2809 WREG32(DxMODE_INT_MASK, 0);
2810 if (ASIC_IS_DCE3(rdev)) {
2811 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2812 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2813 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2814 WREG32(DC_HPD1_INT_CONTROL, tmp);
2815 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2816 WREG32(DC_HPD2_INT_CONTROL, tmp);
2817 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2818 WREG32(DC_HPD3_INT_CONTROL, tmp);
2819 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2820 WREG32(DC_HPD4_INT_CONTROL, tmp);
2821 if (ASIC_IS_DCE32(rdev)) {
2822 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002823 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002824 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002825 WREG32(DC_HPD6_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002826 }
2827 } else {
2828 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2829 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2830 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002831 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002832 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002833 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002834 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04002835 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002836 }
2837}
2838
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002839int r600_irq_init(struct radeon_device *rdev)
2840{
2841 int ret = 0;
2842 int rb_bufsz;
2843 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2844
2845 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01002846 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002847 if (ret)
2848 return ret;
2849
2850 /* disable irqs */
2851 r600_disable_interrupts(rdev);
2852
2853 /* init rlc */
2854 ret = r600_rlc_init(rdev);
2855 if (ret) {
2856 r600_ih_ring_fini(rdev);
2857 return ret;
2858 }
2859
2860 /* setup interrupt control */
2861 /* set dummy read address to ring address */
2862 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
2863 interrupt_cntl = RREG32(INTERRUPT_CNTL);
2864 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2865 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2866 */
2867 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
2868 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2869 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
2870 WREG32(INTERRUPT_CNTL, interrupt_cntl);
2871
2872 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
2873 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
2874
2875 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
2876 IH_WPTR_OVERFLOW_CLEAR |
2877 (rb_bufsz << 1));
2878 /* WPTR writeback, not yet */
2879 /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
2880 WREG32(IH_RB_WPTR_ADDR_LO, 0);
2881 WREG32(IH_RB_WPTR_ADDR_HI, 0);
2882
2883 WREG32(IH_RB_CNTL, ih_rb_cntl);
2884
2885 /* set rptr, wptr to 0 */
2886 WREG32(IH_RB_RPTR, 0);
2887 WREG32(IH_RB_WPTR, 0);
2888
2889 /* Default settings for IH_CNTL (disabled at first) */
2890 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2891 /* RPTR_REARM only works if msi's are enabled */
2892 if (rdev->msi_enabled)
2893 ih_cntl |= RPTR_REARM;
2894
2895#ifdef __BIG_ENDIAN
2896 ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
2897#endif
2898 WREG32(IH_CNTL, ih_cntl);
2899
2900 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04002901 if (rdev->family >= CHIP_CEDAR)
2902 evergreen_disable_interrupt_state(rdev);
2903 else
2904 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002905
2906 /* enable irqs */
2907 r600_enable_interrupts(rdev);
2908
2909 return ret;
2910}
2911
Jerome Glisse0c452492010-01-15 14:44:37 +01002912void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002913{
Alex Deucher45f9a392010-03-24 13:55:51 -04002914 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002915 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01002916}
2917
2918void r600_irq_fini(struct radeon_device *rdev)
2919{
2920 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002921 r600_ih_ring_fini(rdev);
2922}
2923
2924int r600_irq_set(struct radeon_device *rdev)
2925{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002926 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
2927 u32 mode_int = 0;
2928 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04002929 u32 grbm_int_cntl = 0;
Christian Koenigf2594932010-04-10 03:13:16 +02002930 u32 hdmi1, hdmi2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002931
Jerome Glisse003e69f2010-01-07 15:39:14 +01002932 if (!rdev->irq.installed) {
2933 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
2934 return -EINVAL;
2935 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002936 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01002937 if (!rdev->ih.enabled) {
2938 r600_disable_interrupts(rdev);
2939 /* force the active interrupt state to all disabled */
2940 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002941 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01002942 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002943
Christian Koenigf2594932010-04-10 03:13:16 +02002944 hdmi1 = RREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002945 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02002946 hdmi2 = RREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002947 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2948 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2949 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2950 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
2951 if (ASIC_IS_DCE32(rdev)) {
2952 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
2953 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
2954 }
2955 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02002956 hdmi2 = RREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002957 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2958 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2959 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2960 }
2961
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002962 if (rdev->irq.sw_int) {
2963 DRM_DEBUG("r600_irq_set: sw int\n");
2964 cp_int_cntl |= RB_INT_ENABLE;
2965 }
2966 if (rdev->irq.crtc_vblank_int[0]) {
2967 DRM_DEBUG("r600_irq_set: vblank 0\n");
2968 mode_int |= D1MODE_VBLANK_INT_MASK;
2969 }
2970 if (rdev->irq.crtc_vblank_int[1]) {
2971 DRM_DEBUG("r600_irq_set: vblank 1\n");
2972 mode_int |= D2MODE_VBLANK_INT_MASK;
2973 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002974 if (rdev->irq.hpd[0]) {
2975 DRM_DEBUG("r600_irq_set: hpd 1\n");
2976 hpd1 |= DC_HPDx_INT_EN;
2977 }
2978 if (rdev->irq.hpd[1]) {
2979 DRM_DEBUG("r600_irq_set: hpd 2\n");
2980 hpd2 |= DC_HPDx_INT_EN;
2981 }
2982 if (rdev->irq.hpd[2]) {
2983 DRM_DEBUG("r600_irq_set: hpd 3\n");
2984 hpd3 |= DC_HPDx_INT_EN;
2985 }
2986 if (rdev->irq.hpd[3]) {
2987 DRM_DEBUG("r600_irq_set: hpd 4\n");
2988 hpd4 |= DC_HPDx_INT_EN;
2989 }
2990 if (rdev->irq.hpd[4]) {
2991 DRM_DEBUG("r600_irq_set: hpd 5\n");
2992 hpd5 |= DC_HPDx_INT_EN;
2993 }
2994 if (rdev->irq.hpd[5]) {
2995 DRM_DEBUG("r600_irq_set: hpd 6\n");
2996 hpd6 |= DC_HPDx_INT_EN;
2997 }
Christian Koenigf2594932010-04-10 03:13:16 +02002998 if (rdev->irq.hdmi[0]) {
2999 DRM_DEBUG("r600_irq_set: hdmi 1\n");
3000 hdmi1 |= R600_HDMI_INT_EN;
3001 }
3002 if (rdev->irq.hdmi[1]) {
3003 DRM_DEBUG("r600_irq_set: hdmi 2\n");
3004 hdmi2 |= R600_HDMI_INT_EN;
3005 }
Alex Deucher2031f772010-04-22 12:52:11 -04003006 if (rdev->irq.gui_idle) {
3007 DRM_DEBUG("gui idle\n");
3008 grbm_int_cntl |= GUI_IDLE_INT_ENABLE;
3009 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003010
3011 WREG32(CP_INT_CNTL, cp_int_cntl);
3012 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deucher2031f772010-04-22 12:52:11 -04003013 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Christian Koenigf2594932010-04-10 03:13:16 +02003014 WREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003015 if (ASIC_IS_DCE3(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +02003016 WREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003017 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3018 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3019 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3020 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3021 if (ASIC_IS_DCE32(rdev)) {
3022 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3023 WREG32(DC_HPD6_INT_CONTROL, hpd6);
3024 }
3025 } else {
Christian Koenigf2594932010-04-10 03:13:16 +02003026 WREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, hdmi2);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003027 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3028 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3029 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
3030 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003031
3032 return 0;
3033}
3034
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003035static inline void r600_irq_ack(struct radeon_device *rdev,
3036 u32 *disp_int,
3037 u32 *disp_int_cont,
3038 u32 *disp_int_cont2)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003039{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003040 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003041
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003042 if (ASIC_IS_DCE3(rdev)) {
3043 *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3044 *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3045 *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
3046 } else {
3047 *disp_int = RREG32(DISP_INTERRUPT_STATUS);
3048 *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3049 *disp_int_cont2 = 0;
3050 }
3051
3052 if (*disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003053 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003054 if (*disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003055 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003056 if (*disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003057 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003058 if (*disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003059 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003060 if (*disp_int & DC_HPD1_INTERRUPT) {
3061 if (ASIC_IS_DCE3(rdev)) {
3062 tmp = RREG32(DC_HPD1_INT_CONTROL);
3063 tmp |= DC_HPDx_INT_ACK;
3064 WREG32(DC_HPD1_INT_CONTROL, tmp);
3065 } else {
3066 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3067 tmp |= DC_HPDx_INT_ACK;
3068 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3069 }
3070 }
3071 if (*disp_int & DC_HPD2_INTERRUPT) {
3072 if (ASIC_IS_DCE3(rdev)) {
3073 tmp = RREG32(DC_HPD2_INT_CONTROL);
3074 tmp |= DC_HPDx_INT_ACK;
3075 WREG32(DC_HPD2_INT_CONTROL, tmp);
3076 } else {
3077 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3078 tmp |= DC_HPDx_INT_ACK;
3079 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3080 }
3081 }
3082 if (*disp_int_cont & DC_HPD3_INTERRUPT) {
3083 if (ASIC_IS_DCE3(rdev)) {
3084 tmp = RREG32(DC_HPD3_INT_CONTROL);
3085 tmp |= DC_HPDx_INT_ACK;
3086 WREG32(DC_HPD3_INT_CONTROL, tmp);
3087 } else {
3088 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3089 tmp |= DC_HPDx_INT_ACK;
3090 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3091 }
3092 }
3093 if (*disp_int_cont & DC_HPD4_INTERRUPT) {
3094 tmp = RREG32(DC_HPD4_INT_CONTROL);
3095 tmp |= DC_HPDx_INT_ACK;
3096 WREG32(DC_HPD4_INT_CONTROL, tmp);
3097 }
3098 if (ASIC_IS_DCE32(rdev)) {
3099 if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
3100 tmp = RREG32(DC_HPD5_INT_CONTROL);
3101 tmp |= DC_HPDx_INT_ACK;
3102 WREG32(DC_HPD5_INT_CONTROL, tmp);
3103 }
3104 if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
3105 tmp = RREG32(DC_HPD5_INT_CONTROL);
3106 tmp |= DC_HPDx_INT_ACK;
3107 WREG32(DC_HPD6_INT_CONTROL, tmp);
3108 }
3109 }
Christian Koenigf2594932010-04-10 03:13:16 +02003110 if (RREG32(R600_HDMI_BLOCK1 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3111 WREG32_P(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3112 }
3113 if (ASIC_IS_DCE3(rdev)) {
3114 if (RREG32(R600_HDMI_BLOCK3 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3115 WREG32_P(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3116 }
3117 } else {
3118 if (RREG32(R600_HDMI_BLOCK2 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
3119 WREG32_P(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
3120 }
3121 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003122}
3123
3124void r600_irq_disable(struct radeon_device *rdev)
3125{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003126 u32 disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003127
3128 r600_disable_interrupts(rdev);
3129 /* Wait and acknowledge irq */
3130 mdelay(1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003131 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
3132 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003133}
3134
3135static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
3136{
3137 u32 wptr, tmp;
3138
3139 /* XXX use writeback */
3140 wptr = RREG32(IH_RB_WPTR);
3141
3142 if (wptr & RB_OVERFLOW) {
Jerome Glisse7924e5e2010-01-15 14:44:39 +01003143 /* When a ring buffer overflow happen start parsing interrupt
3144 * from the last not overwritten vector (wptr + 16). Hopefully
3145 * this should allow us to catchup.
3146 */
3147 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3148 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3149 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003150 tmp = RREG32(IH_RB_CNTL);
3151 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3152 WREG32(IH_RB_CNTL, tmp);
3153 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003154 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003155}
3156
3157/* r600 IV Ring
3158 * Each IV ring entry is 128 bits:
3159 * [7:0] - interrupt source id
3160 * [31:8] - reserved
3161 * [59:32] - interrupt source data
3162 * [127:60] - reserved
3163 *
3164 * The basic interrupt vector entries
3165 * are decoded as follows:
3166 * src_id src_data description
3167 * 1 0 D1 Vblank
3168 * 1 1 D1 Vline
3169 * 5 0 D2 Vblank
3170 * 5 1 D2 Vline
3171 * 19 0 FP Hot plug detection A
3172 * 19 1 FP Hot plug detection B
3173 * 19 2 DAC A auto-detection
3174 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02003175 * 21 4 HDMI block A
3176 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003177 * 176 - CP_INT RB
3178 * 177 - CP_INT IB1
3179 * 178 - CP_INT IB2
3180 * 181 - EOP Interrupt
3181 * 233 - GUI Idle
3182 *
3183 * Note, these are based on r600 and may need to be
3184 * adjusted or added to on newer asics
3185 */
3186
3187int r600_irq_process(struct radeon_device *rdev)
3188{
3189 u32 wptr = r600_get_ih_wptr(rdev);
3190 u32 rptr = rdev->ih.rptr;
3191 u32 src_id, src_data;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003192 u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003193 unsigned long flags;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003194 bool queue_hotplug = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003195
3196 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003197 if (!rdev->ih.enabled)
3198 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003199
3200 spin_lock_irqsave(&rdev->ih.lock, flags);
3201
3202 if (rptr == wptr) {
3203 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3204 return IRQ_NONE;
3205 }
3206 if (rdev->shutdown) {
3207 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3208 return IRQ_NONE;
3209 }
3210
3211restart_ih:
3212 /* display interrupts */
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003213 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003214
3215 rdev->ih.wptr = wptr;
3216 while (rptr != wptr) {
3217 /* wptr/rptr are in bytes! */
3218 ring_index = rptr / 4;
3219 src_id = rdev->ih.ring[ring_index] & 0xff;
3220 src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
3221
3222 switch (src_id) {
3223 case 1: /* D1 vblank/vline */
3224 switch (src_data) {
3225 case 0: /* D1 vblank */
3226 if (disp_int & LB_D1_VBLANK_INTERRUPT) {
3227 drm_handle_vblank(rdev->ddev, 0);
Rafał Miłecki839461d2010-03-02 22:06:51 +01003228 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +01003229 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003230 disp_int &= ~LB_D1_VBLANK_INTERRUPT;
3231 DRM_DEBUG("IH: D1 vblank\n");
3232 }
3233 break;
3234 case 1: /* D1 vline */
3235 if (disp_int & LB_D1_VLINE_INTERRUPT) {
3236 disp_int &= ~LB_D1_VLINE_INTERRUPT;
3237 DRM_DEBUG("IH: D1 vline\n");
3238 }
3239 break;
3240 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003241 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003242 break;
3243 }
3244 break;
3245 case 5: /* D2 vblank/vline */
3246 switch (src_data) {
3247 case 0: /* D2 vblank */
3248 if (disp_int & LB_D2_VBLANK_INTERRUPT) {
3249 drm_handle_vblank(rdev->ddev, 1);
Rafał Miłecki839461d2010-03-02 22:06:51 +01003250 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +01003251 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003252 disp_int &= ~LB_D2_VBLANK_INTERRUPT;
3253 DRM_DEBUG("IH: D2 vblank\n");
3254 }
3255 break;
3256 case 1: /* D1 vline */
3257 if (disp_int & LB_D2_VLINE_INTERRUPT) {
3258 disp_int &= ~LB_D2_VLINE_INTERRUPT;
3259 DRM_DEBUG("IH: D2 vline\n");
3260 }
3261 break;
3262 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003263 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003264 break;
3265 }
3266 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003267 case 19: /* HPD/DAC hotplug */
3268 switch (src_data) {
3269 case 0:
3270 if (disp_int & DC_HPD1_INTERRUPT) {
3271 disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003272 queue_hotplug = true;
3273 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003274 }
3275 break;
3276 case 1:
3277 if (disp_int & DC_HPD2_INTERRUPT) {
3278 disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003279 queue_hotplug = true;
3280 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003281 }
3282 break;
3283 case 4:
3284 if (disp_int_cont & DC_HPD3_INTERRUPT) {
3285 disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003286 queue_hotplug = true;
3287 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003288 }
3289 break;
3290 case 5:
3291 if (disp_int_cont & DC_HPD4_INTERRUPT) {
3292 disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003293 queue_hotplug = true;
3294 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003295 }
3296 break;
3297 case 10:
3298 if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deucher5898b1f2010-03-24 13:57:29 -04003299 disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003300 queue_hotplug = true;
3301 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003302 }
3303 break;
3304 case 12:
3305 if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deucher5898b1f2010-03-24 13:57:29 -04003306 disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003307 queue_hotplug = true;
3308 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003309 }
3310 break;
3311 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003312 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003313 break;
3314 }
3315 break;
Christian Koenigf2594932010-04-10 03:13:16 +02003316 case 21: /* HDMI */
3317 DRM_DEBUG("IH: HDMI: 0x%x\n", src_data);
3318 r600_audio_schedule_polling(rdev);
3319 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003320 case 176: /* CP_INT in ring buffer */
3321 case 177: /* CP_INT in IB1 */
3322 case 178: /* CP_INT in IB2 */
3323 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
3324 radeon_fence_process(rdev);
3325 break;
3326 case 181: /* CP EOP event */
3327 DRM_DEBUG("IH: CP EOP\n");
3328 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003329 case 233: /* GUI IDLE */
3330 DRM_DEBUG("IH: CP EOP\n");
3331 rdev->pm.gui_idle = true;
3332 wake_up(&rdev->irq.idle_queue);
3333 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003334 default:
Alex Deucherb0425892010-01-11 19:47:38 -05003335 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003336 break;
3337 }
3338
3339 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01003340 rptr += 16;
3341 rptr &= rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003342 }
3343 /* make sure wptr hasn't changed while processing */
3344 wptr = r600_get_ih_wptr(rdev);
3345 if (wptr != rdev->ih.wptr)
3346 goto restart_ih;
Alex Deucherd4877cf2009-12-04 16:56:37 -05003347 if (queue_hotplug)
3348 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003349 rdev->ih.rptr = rptr;
3350 WREG32(IH_RB_RPTR, rdev->ih.rptr);
3351 spin_unlock_irqrestore(&rdev->ih.lock, flags);
3352 return IRQ_HANDLED;
3353}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003354
3355/*
3356 * Debugfs info
3357 */
3358#if defined(CONFIG_DEBUG_FS)
3359
3360static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
3361{
3362 struct drm_info_node *node = (struct drm_info_node *) m->private;
3363 struct drm_device *dev = node->minor->dev;
3364 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003365 unsigned count, i, j;
3366
3367 radeon_ring_free_size(rdev);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003368 count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003369 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
Rafał Miłeckid6840762009-11-10 22:26:21 +01003370 seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
3371 seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
3372 seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
3373 seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003374 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
3375 seq_printf(m, "%u dwords in ring\n", count);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003376 i = rdev->cp.rptr;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003377 for (j = 0; j <= count; j++) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003378 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
Rafał Miłeckid6840762009-11-10 22:26:21 +01003379 i = (i + 1) & rdev->cp.ptr_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003380 }
3381 return 0;
3382}
3383
3384static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3385{
3386 struct drm_info_node *node = (struct drm_info_node *) m->private;
3387 struct drm_device *dev = node->minor->dev;
3388 struct radeon_device *rdev = dev->dev_private;
3389
3390 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3391 DREG32_SYS(m, rdev, VM_L2_STATUS);
3392 return 0;
3393}
3394
3395static struct drm_info_list r600_mc_info_list[] = {
3396 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
3397 {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
3398};
3399#endif
3400
3401int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3402{
3403#if defined(CONFIG_DEBUG_FS)
3404 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3405#else
3406 return 0;
3407#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003408}
Jerome Glisse062b3892010-02-04 20:36:39 +01003409
3410/**
3411 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3412 * rdev: radeon device structure
3413 * bo: buffer object struct which userspace is waiting for idle
3414 *
3415 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3416 * through ring buffer, this leads to corruption in rendering, see
3417 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3418 * directly perform HDP flush by writing register through MMIO.
3419 */
3420void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3421{
3422 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
3423}