2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
28 * $FreeBSD: head/sys/dev/drm2/radeon/r420.c 254885 2013-08-25 19:37:15Z dumbbell $
32 #include "radeon_reg.h"
34 #include "radeon_asic.h"
38 #include "r420_reg_safe.h"
40 void r420_pm_init_profile(struct radeon_device *rdev)
43 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
44 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
45 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
46 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
48 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
49 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
50 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
51 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
53 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
54 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
55 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
56 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
58 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
59 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
60 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
61 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
63 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
64 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
65 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
66 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
68 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
69 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
70 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
71 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
73 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
74 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
75 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
76 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
79 static void r420_set_reg_safe(struct radeon_device *rdev)
81 rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
82 rdev->config.r300.reg_safe_bm_size = DRM_ARRAY_SIZE(r420_reg_safe_bm);
85 void r420_pipes_init(struct radeon_device *rdev)
88 unsigned gb_pipe_select;
91 /* GA_ENHANCE workaround TCL deadlock issue */
92 WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
94 /* add idle wait as per freedesktop.org bug 24041 */
95 if (r100_gui_wait_for_idle(rdev)) {
96 DRM_ERROR("Failed to wait GUI idle while "
97 "programming pipes. Bad things might happen.\n");
99 /* get max number of pipes */
100 gb_pipe_select = RREG32(R400_GB_PIPE_SELECT);
101 num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
103 /* SE chips have 1 pipe */
104 if ((rdev->ddev->pci_device == 0x5e4c) ||
105 (rdev->ddev->pci_device == 0x5e4f))
108 rdev->num_gb_pipes = num_pipes;
112 /* force to 1 pipe */
127 WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
128 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
129 tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
130 WREG32(R300_GB_TILE_CONFIG, tmp);
131 if (r100_gui_wait_for_idle(rdev)) {
132 DRM_ERROR("Failed to wait GUI idle while "
133 "programming pipes. Bad things might happen.\n");
136 tmp = RREG32(R300_DST_PIPE_CONFIG);
137 WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
139 WREG32(R300_RB2D_DSTCACHE_MODE,
140 RREG32(R300_RB2D_DSTCACHE_MODE) |
141 R300_DC_AUTOFLUSH_ENABLE |
142 R300_DC_DC_DISABLE_IGNORE_PE);
144 if (r100_gui_wait_for_idle(rdev)) {
145 DRM_ERROR("Failed to wait GUI idle while "
146 "programming pipes. Bad things might happen.\n");
149 if (rdev->family == CHIP_RV530) {
150 tmp = RREG32(RV530_GB_PIPE_SELECT2);
152 rdev->num_z_pipes = 2;
154 rdev->num_z_pipes = 1;
156 rdev->num_z_pipes = 1;
158 DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
159 rdev->num_gb_pipes, rdev->num_z_pipes);
162 u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
166 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
167 r = RREG32(R_0001FC_MC_IND_DATA);
171 void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
173 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
174 S_0001F8_MC_IND_WR_EN(1));
175 WREG32(R_0001FC_MC_IND_DATA, v);
178 static void r420_debugfs(struct radeon_device *rdev)
180 if (r100_debugfs_rbbm_init(rdev)) {
181 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
183 if (r420_debugfs_pipes_info_init(rdev)) {
184 DRM_ERROR("Failed to register debugfs file for pipes !\n");
188 static void r420_clock_resume(struct radeon_device *rdev)
192 if (radeon_dynclks != -1 && radeon_dynclks)
193 radeon_atom_set_clock_gating(rdev, 1);
194 sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
195 sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
196 if (rdev->family == CHIP_R420)
197 sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
198 WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
201 static void r420_cp_errata_init(struct radeon_device *rdev)
203 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
205 /* RV410 and R420 can lock up if CP DMA to host memory happens
206 * while the 2D engine is busy.
208 * The proper workaround is to queue a RESYNC at the beginning
209 * of the CP init, apparently.
211 radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
212 radeon_ring_lock(rdev, ring, 8);
213 radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1));
214 radeon_ring_write(ring, rdev->config.r300.resync_scratch);
215 radeon_ring_write(ring, 0xDEADBEEF);
216 radeon_ring_unlock_commit(rdev, ring);
219 static void r420_cp_errata_fini(struct radeon_device *rdev)
221 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
223 /* Catch the RESYNC we dispatched all the way back,
224 * at the very beginning of the CP init.
226 radeon_ring_lock(rdev, ring, 8);
227 radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
228 radeon_ring_write(ring, R300_RB3D_DC_FINISH);
229 radeon_ring_unlock_commit(rdev, ring);
230 radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
233 static int r420_startup(struct radeon_device *rdev)
237 /* set common regs */
238 r100_set_common_regs(rdev);
240 r300_mc_program(rdev);
242 r420_clock_resume(rdev);
243 /* Initialize GART (initialize after TTM so we can allocate
244 * memory through TTM but finalize after TTM) */
245 if (rdev->flags & RADEON_IS_PCIE) {
246 r = rv370_pcie_gart_enable(rdev);
250 if (rdev->flags & RADEON_IS_PCI) {
251 r = r100_pci_gart_enable(rdev);
255 r420_pipes_init(rdev);
257 /* allocate wb buffer */
258 r = radeon_wb_init(rdev);
262 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
264 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
270 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
272 r = r100_cp_init(rdev, 1024 * 1024);
274 dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
277 r420_cp_errata_init(rdev);
279 r = radeon_ib_pool_init(rdev);
281 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
288 int r420_resume(struct radeon_device *rdev)
292 /* Make sur GART are not working */
293 if (rdev->flags & RADEON_IS_PCIE)
294 rv370_pcie_gart_disable(rdev);
295 if (rdev->flags & RADEON_IS_PCI)
296 r100_pci_gart_disable(rdev);
297 /* Resume clock before doing reset */
298 r420_clock_resume(rdev);
299 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
300 if (radeon_asic_reset(rdev)) {
301 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
302 RREG32(R_000E40_RBBM_STATUS),
303 RREG32(R_0007C0_CP_STAT));
305 /* check if cards are posted or not */
306 if (rdev->is_atom_bios) {
307 atom_asic_init(rdev->mode_info.atom_context);
309 radeon_combios_asic_init(rdev->ddev);
311 /* Resume clock after posting */
312 r420_clock_resume(rdev);
313 /* Initialize surface registers */
314 radeon_surface_init(rdev);
316 rdev->accel_working = true;
317 r = r420_startup(rdev);
319 rdev->accel_working = false;
324 int r420_suspend(struct radeon_device *rdev)
326 r420_cp_errata_fini(rdev);
327 r100_cp_disable(rdev);
328 radeon_wb_disable(rdev);
329 r100_irq_disable(rdev);
330 if (rdev->flags & RADEON_IS_PCIE)
331 rv370_pcie_gart_disable(rdev);
332 if (rdev->flags & RADEON_IS_PCI)
333 r100_pci_gart_disable(rdev);
337 void r420_fini(struct radeon_device *rdev)
340 radeon_wb_fini(rdev);
341 radeon_ib_pool_fini(rdev);
342 radeon_gem_fini(rdev);
343 if (rdev->flags & RADEON_IS_PCIE)
344 rv370_pcie_gart_fini(rdev);
345 if (rdev->flags & RADEON_IS_PCI)
346 r100_pci_gart_fini(rdev);
347 radeon_agp_fini(rdev);
348 radeon_irq_kms_fini(rdev);
349 radeon_fence_driver_fini(rdev);
350 radeon_bo_fini(rdev);
351 if (rdev->is_atom_bios) {
352 radeon_atombios_fini(rdev);
354 radeon_combios_fini(rdev);
356 drm_free(rdev->bios, DRM_MEM_DRIVER);
360 int r420_init(struct radeon_device *rdev)
364 /* Initialize scratch registers */
365 radeon_scratch_init(rdev);
366 /* Initialize surface registers */
367 radeon_surface_init(rdev);
368 /* TODO: disable VGA need to use VGA request */
369 /* restore some register to sane defaults */
370 r100_restore_sanity(rdev);
372 if (!radeon_get_bios(rdev)) {
373 if (ASIC_IS_AVIVO(rdev))
376 if (rdev->is_atom_bios) {
377 r = radeon_atombios_init(rdev);
382 r = radeon_combios_init(rdev);
387 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
388 if (radeon_asic_reset(rdev)) {
390 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
391 RREG32(R_000E40_RBBM_STATUS),
392 RREG32(R_0007C0_CP_STAT));
394 /* check if cards are posted or not */
395 if (radeon_boot_test_post_card(rdev) == false)
398 /* Initialize clocks */
399 radeon_get_clock_info(rdev->ddev);
401 if (rdev->flags & RADEON_IS_AGP) {
402 r = radeon_agp_init(rdev);
404 radeon_agp_disable(rdev);
407 /* initialize memory controller */
411 r = radeon_fence_driver_init(rdev);
415 r = radeon_irq_kms_init(rdev);
420 r = radeon_bo_init(rdev);
424 if (rdev->family == CHIP_R420)
425 r100_enable_bm(rdev);
427 if (rdev->flags & RADEON_IS_PCIE) {
428 r = rv370_pcie_gart_init(rdev);
432 if (rdev->flags & RADEON_IS_PCI) {
433 r = r100_pci_gart_init(rdev);
437 r420_set_reg_safe(rdev);
439 rdev->accel_working = true;
440 r = r420_startup(rdev);
442 /* Somethings want wront with the accel init stop accel */
443 dev_err(rdev->dev, "Disabling GPU acceleration\n");
445 radeon_wb_fini(rdev);
446 radeon_ib_pool_fini(rdev);
447 radeon_irq_kms_fini(rdev);
448 if (rdev->flags & RADEON_IS_PCIE)
449 rv370_pcie_gart_fini(rdev);
450 if (rdev->flags & RADEON_IS_PCI)
451 r100_pci_gart_fini(rdev);
452 radeon_agp_fini(rdev);
453 rdev->accel_working = false;
461 #if defined(CONFIG_DEBUG_FS)
462 static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
464 struct drm_info_node *node = (struct drm_info_node *) m->private;
465 struct drm_device *dev = node->minor->dev;
466 struct radeon_device *rdev = dev->dev_private;
469 tmp = RREG32(R400_GB_PIPE_SELECT);
470 seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
471 tmp = RREG32(R300_GB_TILE_CONFIG);
472 seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
473 tmp = RREG32(R300_DST_PIPE_CONFIG);
474 seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
478 static struct drm_info_list r420_pipes_info_list[] = {
479 {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
483 int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
485 #if defined(CONFIG_DEBUG_FS)
486 return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);