1 1.3 riastrad /* $NetBSD: radeon_r420.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2008 Advanced Micro Devices, Inc. 5 1.1 riastrad * Copyright 2008 Red Hat Inc. 6 1.1 riastrad * Copyright 2009 Jerome Glisse. 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 10 1.1 riastrad * to deal in the Software without restriction, including without limitation 11 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 13 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice shall be included in 16 1.1 riastrad * all copies or substantial portions of the Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: Dave Airlie 27 1.1 riastrad * Alex Deucher 28 1.1 riastrad * Jerome Glisse 29 1.1 riastrad */ 30 1.3 riastrad 31 1.1 riastrad #include <sys/cdefs.h> 32 1.3 riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_r420.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $"); 33 1.1 riastrad 34 1.3 riastrad #include <linux/pci.h> 35 1.1 riastrad #include <linux/seq_file.h> 36 1.1 riastrad #include <linux/slab.h> 37 1.3 riastrad 38 1.3 riastrad #include <drm/drm_debugfs.h> 39 1.3 riastrad #include <drm/drm_device.h> 40 1.3 riastrad #include <drm/drm_file.h> 41 1.3 riastrad 42 1.1 riastrad #include "atom.h" 43 1.1 riastrad #include "r100d.h" 44 1.3 riastrad #include "r420_reg_safe.h" 45 1.1 riastrad #include "r420d.h" 46 1.3 riastrad #include "radeon.h" 47 1.3 riastrad #include "radeon_asic.h" 48 1.3 riastrad #include "radeon_reg.h" 49 1.1 riastrad 50 1.1 riastrad void r420_pm_init_profile(struct radeon_device *rdev) 51 1.1 riastrad { 52 1.1 riastrad /* default */ 53 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; 54 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 55 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; 56 1.1 riastrad rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; 57 1.1 riastrad /* low sh */ 58 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0; 59 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0; 60 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; 61 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; 62 1.1 riastrad /* mid sh */ 63 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0; 64 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1; 65 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; 66 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; 67 1.1 riastrad /* high sh */ 68 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0; 69 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 70 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; 71 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; 72 1.1 riastrad /* low mh */ 73 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0; 74 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 75 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; 76 1.1 riastrad rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; 77 1.1 riastrad /* mid mh */ 78 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0; 79 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 80 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; 81 1.1 riastrad rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; 82 1.1 riastrad /* high mh */ 83 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0; 84 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 85 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; 86 1.1 riastrad rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; 87 1.1 riastrad } 88 1.1 riastrad 89 1.1 riastrad static void r420_set_reg_safe(struct radeon_device *rdev) 90 1.1 riastrad { 91 1.1 riastrad rdev->config.r300.reg_safe_bm = r420_reg_safe_bm; 92 1.1 riastrad rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm); 93 1.1 riastrad } 94 1.1 riastrad 95 1.1 riastrad void r420_pipes_init(struct radeon_device *rdev) 96 1.1 riastrad { 97 1.1 riastrad unsigned tmp; 98 1.1 riastrad unsigned gb_pipe_select; 99 1.1 riastrad unsigned num_pipes; 100 1.1 riastrad 101 1.1 riastrad /* GA_ENHANCE workaround TCL deadlock issue */ 102 1.1 riastrad WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL | 103 1.1 riastrad (1 << 2) | (1 << 3)); 104 1.1 riastrad /* add idle wait as per freedesktop.org bug 24041 */ 105 1.1 riastrad if (r100_gui_wait_for_idle(rdev)) { 106 1.3 riastrad pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n"); 107 1.1 riastrad } 108 1.1 riastrad /* get max number of pipes */ 109 1.1 riastrad gb_pipe_select = RREG32(R400_GB_PIPE_SELECT); 110 1.1 riastrad num_pipes = ((gb_pipe_select >> 12) & 3) + 1; 111 1.1 riastrad 112 1.1 riastrad /* SE chips have 1 pipe */ 113 1.1 riastrad if ((rdev->pdev->device == 0x5e4c) || 114 1.1 riastrad (rdev->pdev->device == 0x5e4f)) 115 1.1 riastrad num_pipes = 1; 116 1.1 riastrad 117 1.1 riastrad rdev->num_gb_pipes = num_pipes; 118 1.1 riastrad tmp = 0; 119 1.1 riastrad switch (num_pipes) { 120 1.1 riastrad default: 121 1.1 riastrad /* force to 1 pipe */ 122 1.1 riastrad num_pipes = 1; 123 1.3 riastrad /* fall through */ 124 1.1 riastrad case 1: 125 1.1 riastrad tmp = (0 << 1); 126 1.1 riastrad break; 127 1.1 riastrad case 2: 128 1.1 riastrad tmp = (3 << 1); 129 1.1 riastrad break; 130 1.1 riastrad case 3: 131 1.1 riastrad tmp = (6 << 1); 132 1.1 riastrad break; 133 1.1 riastrad case 4: 134 1.1 riastrad tmp = (7 << 1); 135 1.1 riastrad break; 136 1.1 riastrad } 137 1.1 riastrad WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1); 138 1.1 riastrad /* Sub pixel 1/12 so we can have 4K rendering according to doc */ 139 1.1 riastrad tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING; 140 1.1 riastrad WREG32(R300_GB_TILE_CONFIG, tmp); 141 1.1 riastrad if (r100_gui_wait_for_idle(rdev)) { 142 1.3 riastrad pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n"); 143 1.1 riastrad } 144 1.1 riastrad 145 1.1 riastrad tmp = RREG32(R300_DST_PIPE_CONFIG); 146 1.1 riastrad WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG); 147 1.1 riastrad 148 1.1 riastrad WREG32(R300_RB2D_DSTCACHE_MODE, 149 1.1 riastrad RREG32(R300_RB2D_DSTCACHE_MODE) | 150 1.1 riastrad R300_DC_AUTOFLUSH_ENABLE | 151 1.1 riastrad R300_DC_DC_DISABLE_IGNORE_PE); 152 1.1 riastrad 153 1.1 riastrad if (r100_gui_wait_for_idle(rdev)) { 154 1.3 riastrad pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n"); 155 1.1 riastrad } 156 1.1 riastrad 157 1.1 riastrad if (rdev->family == CHIP_RV530) { 158 1.1 riastrad tmp = RREG32(RV530_GB_PIPE_SELECT2); 159 1.1 riastrad if ((tmp & 3) == 3) 160 1.1 riastrad rdev->num_z_pipes = 2; 161 1.1 riastrad else 162 1.1 riastrad rdev->num_z_pipes = 1; 163 1.1 riastrad } else 164 1.1 riastrad rdev->num_z_pipes = 1; 165 1.1 riastrad 166 1.1 riastrad DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n", 167 1.1 riastrad rdev->num_gb_pipes, rdev->num_z_pipes); 168 1.1 riastrad } 169 1.1 riastrad 170 1.1 riastrad u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg) 171 1.1 riastrad { 172 1.1 riastrad unsigned long flags; 173 1.1 riastrad u32 r; 174 1.1 riastrad 175 1.1 riastrad spin_lock_irqsave(&rdev->mc_idx_lock, flags); 176 1.1 riastrad WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg)); 177 1.1 riastrad r = RREG32(R_0001FC_MC_IND_DATA); 178 1.1 riastrad spin_unlock_irqrestore(&rdev->mc_idx_lock, flags); 179 1.1 riastrad return r; 180 1.1 riastrad } 181 1.1 riastrad 182 1.1 riastrad void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v) 183 1.1 riastrad { 184 1.1 riastrad unsigned long flags; 185 1.1 riastrad 186 1.1 riastrad spin_lock_irqsave(&rdev->mc_idx_lock, flags); 187 1.1 riastrad WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) | 188 1.1 riastrad S_0001F8_MC_IND_WR_EN(1)); 189 1.1 riastrad WREG32(R_0001FC_MC_IND_DATA, v); 190 1.1 riastrad spin_unlock_irqrestore(&rdev->mc_idx_lock, flags); 191 1.1 riastrad } 192 1.1 riastrad 193 1.1 riastrad static void r420_debugfs(struct radeon_device *rdev) 194 1.1 riastrad { 195 1.1 riastrad if (r100_debugfs_rbbm_init(rdev)) { 196 1.1 riastrad DRM_ERROR("Failed to register debugfs file for RBBM !\n"); 197 1.1 riastrad } 198 1.1 riastrad if (r420_debugfs_pipes_info_init(rdev)) { 199 1.1 riastrad DRM_ERROR("Failed to register debugfs file for pipes !\n"); 200 1.1 riastrad } 201 1.1 riastrad } 202 1.1 riastrad 203 1.1 riastrad static void r420_clock_resume(struct radeon_device *rdev) 204 1.1 riastrad { 205 1.1 riastrad u32 sclk_cntl; 206 1.1 riastrad 207 1.1 riastrad if (radeon_dynclks != -1 && radeon_dynclks) 208 1.1 riastrad radeon_atom_set_clock_gating(rdev, 1); 209 1.1 riastrad sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL); 210 1.1 riastrad sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 211 1.1 riastrad if (rdev->family == CHIP_R420) 212 1.1 riastrad sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1); 213 1.1 riastrad WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl); 214 1.1 riastrad } 215 1.1 riastrad 216 1.1 riastrad static void r420_cp_errata_init(struct radeon_device *rdev) 217 1.1 riastrad { 218 1.3 riastrad int r; 219 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 220 1.1 riastrad 221 1.1 riastrad /* RV410 and R420 can lock up if CP DMA to host memory happens 222 1.1 riastrad * while the 2D engine is busy. 223 1.1 riastrad * 224 1.1 riastrad * The proper workaround is to queue a RESYNC at the beginning 225 1.1 riastrad * of the CP init, apparently. 226 1.1 riastrad */ 227 1.1 riastrad radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch); 228 1.3 riastrad r = radeon_ring_lock(rdev, ring, 8); 229 1.3 riastrad WARN_ON(r); 230 1.1 riastrad radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1)); 231 1.1 riastrad radeon_ring_write(ring, rdev->config.r300.resync_scratch); 232 1.1 riastrad radeon_ring_write(ring, 0xDEADBEEF); 233 1.1 riastrad radeon_ring_unlock_commit(rdev, ring, false); 234 1.1 riastrad } 235 1.1 riastrad 236 1.1 riastrad static void r420_cp_errata_fini(struct radeon_device *rdev) 237 1.1 riastrad { 238 1.3 riastrad int r; 239 1.1 riastrad struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 240 1.1 riastrad 241 1.1 riastrad /* Catch the RESYNC we dispatched all the way back, 242 1.1 riastrad * at the very beginning of the CP init. 243 1.1 riastrad */ 244 1.3 riastrad r = radeon_ring_lock(rdev, ring, 8); 245 1.3 riastrad WARN_ON(r); 246 1.1 riastrad radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); 247 1.1 riastrad radeon_ring_write(ring, R300_RB3D_DC_FINISH); 248 1.1 riastrad radeon_ring_unlock_commit(rdev, ring, false); 249 1.1 riastrad radeon_scratch_free(rdev, rdev->config.r300.resync_scratch); 250 1.1 riastrad } 251 1.1 riastrad 252 1.1 riastrad static int r420_startup(struct radeon_device *rdev) 253 1.1 riastrad { 254 1.1 riastrad int r; 255 1.1 riastrad 256 1.1 riastrad /* set common regs */ 257 1.1 riastrad r100_set_common_regs(rdev); 258 1.1 riastrad /* program mc */ 259 1.1 riastrad r300_mc_program(rdev); 260 1.1 riastrad /* Resume clock */ 261 1.1 riastrad r420_clock_resume(rdev); 262 1.1 riastrad /* Initialize GART (initialize after TTM so we can allocate 263 1.1 riastrad * memory through TTM but finalize after TTM) */ 264 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) { 265 1.1 riastrad r = rv370_pcie_gart_enable(rdev); 266 1.1 riastrad if (r) 267 1.1 riastrad return r; 268 1.1 riastrad } 269 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) { 270 1.1 riastrad r = r100_pci_gart_enable(rdev); 271 1.1 riastrad if (r) 272 1.1 riastrad return r; 273 1.1 riastrad } 274 1.1 riastrad r420_pipes_init(rdev); 275 1.1 riastrad 276 1.1 riastrad /* allocate wb buffer */ 277 1.1 riastrad r = radeon_wb_init(rdev); 278 1.1 riastrad if (r) 279 1.1 riastrad return r; 280 1.1 riastrad 281 1.1 riastrad r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); 282 1.1 riastrad if (r) { 283 1.1 riastrad dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); 284 1.1 riastrad return r; 285 1.1 riastrad } 286 1.1 riastrad 287 1.1 riastrad /* Enable IRQ */ 288 1.1 riastrad if (!rdev->irq.installed) { 289 1.1 riastrad r = radeon_irq_kms_init(rdev); 290 1.1 riastrad if (r) 291 1.1 riastrad return r; 292 1.1 riastrad } 293 1.1 riastrad 294 1.1 riastrad r100_irq_set(rdev); 295 1.1 riastrad rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 296 1.1 riastrad /* 1M ring buffer */ 297 1.1 riastrad r = r100_cp_init(rdev, 1024 * 1024); 298 1.1 riastrad if (r) { 299 1.1 riastrad dev_err(rdev->dev, "failed initializing CP (%d).\n", r); 300 1.1 riastrad return r; 301 1.1 riastrad } 302 1.1 riastrad r420_cp_errata_init(rdev); 303 1.1 riastrad 304 1.1 riastrad r = radeon_ib_pool_init(rdev); 305 1.1 riastrad if (r) { 306 1.1 riastrad dev_err(rdev->dev, "IB initialization failed (%d).\n", r); 307 1.1 riastrad return r; 308 1.1 riastrad } 309 1.1 riastrad 310 1.1 riastrad return 0; 311 1.1 riastrad } 312 1.1 riastrad 313 1.1 riastrad int r420_resume(struct radeon_device *rdev) 314 1.1 riastrad { 315 1.1 riastrad int r; 316 1.1 riastrad 317 1.1 riastrad /* Make sur GART are not working */ 318 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 319 1.1 riastrad rv370_pcie_gart_disable(rdev); 320 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 321 1.1 riastrad r100_pci_gart_disable(rdev); 322 1.1 riastrad /* Resume clock before doing reset */ 323 1.1 riastrad r420_clock_resume(rdev); 324 1.1 riastrad /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 325 1.1 riastrad if (radeon_asic_reset(rdev)) { 326 1.1 riastrad dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 327 1.1 riastrad RREG32(R_000E40_RBBM_STATUS), 328 1.1 riastrad RREG32(R_0007C0_CP_STAT)); 329 1.1 riastrad } 330 1.1 riastrad /* check if cards are posted or not */ 331 1.1 riastrad if (rdev->is_atom_bios) { 332 1.1 riastrad atom_asic_init(rdev->mode_info.atom_context); 333 1.1 riastrad } else { 334 1.1 riastrad radeon_combios_asic_init(rdev->ddev); 335 1.1 riastrad } 336 1.1 riastrad /* Resume clock after posting */ 337 1.1 riastrad r420_clock_resume(rdev); 338 1.1 riastrad /* Initialize surface registers */ 339 1.1 riastrad radeon_surface_init(rdev); 340 1.1 riastrad 341 1.1 riastrad rdev->accel_working = true; 342 1.1 riastrad r = r420_startup(rdev); 343 1.1 riastrad if (r) { 344 1.1 riastrad rdev->accel_working = false; 345 1.1 riastrad } 346 1.1 riastrad return r; 347 1.1 riastrad } 348 1.1 riastrad 349 1.1 riastrad int r420_suspend(struct radeon_device *rdev) 350 1.1 riastrad { 351 1.1 riastrad radeon_pm_suspend(rdev); 352 1.1 riastrad r420_cp_errata_fini(rdev); 353 1.1 riastrad r100_cp_disable(rdev); 354 1.1 riastrad radeon_wb_disable(rdev); 355 1.1 riastrad r100_irq_disable(rdev); 356 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 357 1.1 riastrad rv370_pcie_gart_disable(rdev); 358 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 359 1.1 riastrad r100_pci_gart_disable(rdev); 360 1.1 riastrad return 0; 361 1.1 riastrad } 362 1.1 riastrad 363 1.1 riastrad void r420_fini(struct radeon_device *rdev) 364 1.1 riastrad { 365 1.1 riastrad radeon_pm_fini(rdev); 366 1.1 riastrad r100_cp_fini(rdev); 367 1.1 riastrad radeon_wb_fini(rdev); 368 1.1 riastrad radeon_ib_pool_fini(rdev); 369 1.1 riastrad radeon_gem_fini(rdev); 370 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 371 1.1 riastrad rv370_pcie_gart_fini(rdev); 372 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 373 1.1 riastrad r100_pci_gart_fini(rdev); 374 1.1 riastrad radeon_agp_fini(rdev); 375 1.1 riastrad radeon_irq_kms_fini(rdev); 376 1.1 riastrad radeon_fence_driver_fini(rdev); 377 1.1 riastrad radeon_bo_fini(rdev); 378 1.1 riastrad if (rdev->is_atom_bios) { 379 1.1 riastrad radeon_atombios_fini(rdev); 380 1.1 riastrad } else { 381 1.1 riastrad radeon_combios_fini(rdev); 382 1.1 riastrad } 383 1.1 riastrad kfree(rdev->bios); 384 1.1 riastrad rdev->bios = NULL; 385 1.1 riastrad } 386 1.1 riastrad 387 1.1 riastrad int r420_init(struct radeon_device *rdev) 388 1.1 riastrad { 389 1.1 riastrad int r; 390 1.1 riastrad 391 1.1 riastrad /* Initialize scratch registers */ 392 1.1 riastrad radeon_scratch_init(rdev); 393 1.1 riastrad /* Initialize surface registers */ 394 1.1 riastrad radeon_surface_init(rdev); 395 1.1 riastrad /* TODO: disable VGA need to use VGA request */ 396 1.1 riastrad /* restore some register to sane defaults */ 397 1.1 riastrad r100_restore_sanity(rdev); 398 1.1 riastrad /* BIOS*/ 399 1.1 riastrad if (!radeon_get_bios(rdev)) { 400 1.1 riastrad if (ASIC_IS_AVIVO(rdev)) 401 1.1 riastrad return -EINVAL; 402 1.1 riastrad } 403 1.1 riastrad if (rdev->is_atom_bios) { 404 1.1 riastrad r = radeon_atombios_init(rdev); 405 1.1 riastrad if (r) { 406 1.1 riastrad return r; 407 1.1 riastrad } 408 1.1 riastrad } else { 409 1.1 riastrad r = radeon_combios_init(rdev); 410 1.1 riastrad if (r) { 411 1.1 riastrad return r; 412 1.1 riastrad } 413 1.1 riastrad } 414 1.1 riastrad /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 415 1.1 riastrad if (radeon_asic_reset(rdev)) { 416 1.1 riastrad dev_warn(rdev->dev, 417 1.1 riastrad "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 418 1.1 riastrad RREG32(R_000E40_RBBM_STATUS), 419 1.1 riastrad RREG32(R_0007C0_CP_STAT)); 420 1.1 riastrad } 421 1.1 riastrad /* check if cards are posted or not */ 422 1.1 riastrad if (radeon_boot_test_post_card(rdev) == false) 423 1.1 riastrad return -EINVAL; 424 1.1 riastrad 425 1.1 riastrad /* Initialize clocks */ 426 1.1 riastrad radeon_get_clock_info(rdev->ddev); 427 1.1 riastrad /* initialize AGP */ 428 1.1 riastrad if (rdev->flags & RADEON_IS_AGP) { 429 1.1 riastrad r = radeon_agp_init(rdev); 430 1.1 riastrad if (r) { 431 1.1 riastrad radeon_agp_disable(rdev); 432 1.1 riastrad } 433 1.1 riastrad } 434 1.1 riastrad /* initialize memory controller */ 435 1.1 riastrad r300_mc_init(rdev); 436 1.1 riastrad r420_debugfs(rdev); 437 1.1 riastrad /* Fence driver */ 438 1.1 riastrad r = radeon_fence_driver_init(rdev); 439 1.1 riastrad if (r) { 440 1.1 riastrad return r; 441 1.1 riastrad } 442 1.1 riastrad /* Memory manager */ 443 1.1 riastrad r = radeon_bo_init(rdev); 444 1.1 riastrad if (r) { 445 1.1 riastrad return r; 446 1.1 riastrad } 447 1.1 riastrad if (rdev->family == CHIP_R420) 448 1.1 riastrad r100_enable_bm(rdev); 449 1.1 riastrad 450 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) { 451 1.1 riastrad r = rv370_pcie_gart_init(rdev); 452 1.1 riastrad if (r) 453 1.1 riastrad return r; 454 1.1 riastrad } 455 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) { 456 1.1 riastrad r = r100_pci_gart_init(rdev); 457 1.1 riastrad if (r) 458 1.1 riastrad return r; 459 1.1 riastrad } 460 1.1 riastrad r420_set_reg_safe(rdev); 461 1.1 riastrad 462 1.1 riastrad /* Initialize power management */ 463 1.1 riastrad radeon_pm_init(rdev); 464 1.1 riastrad 465 1.1 riastrad rdev->accel_working = true; 466 1.1 riastrad r = r420_startup(rdev); 467 1.1 riastrad if (r) { 468 1.1 riastrad /* Somethings want wront with the accel init stop accel */ 469 1.1 riastrad dev_err(rdev->dev, "Disabling GPU acceleration\n"); 470 1.1 riastrad r100_cp_fini(rdev); 471 1.1 riastrad radeon_wb_fini(rdev); 472 1.1 riastrad radeon_ib_pool_fini(rdev); 473 1.1 riastrad radeon_irq_kms_fini(rdev); 474 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 475 1.1 riastrad rv370_pcie_gart_fini(rdev); 476 1.1 riastrad if (rdev->flags & RADEON_IS_PCI) 477 1.1 riastrad r100_pci_gart_fini(rdev); 478 1.1 riastrad radeon_agp_fini(rdev); 479 1.1 riastrad rdev->accel_working = false; 480 1.1 riastrad } 481 1.1 riastrad return 0; 482 1.1 riastrad } 483 1.1 riastrad 484 1.1 riastrad /* 485 1.1 riastrad * Debugfs info 486 1.1 riastrad */ 487 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 488 1.1 riastrad static int r420_debugfs_pipes_info(struct seq_file *m, void *data) 489 1.1 riastrad { 490 1.1 riastrad struct drm_info_node *node = (struct drm_info_node *) m->private; 491 1.1 riastrad struct drm_device *dev = node->minor->dev; 492 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 493 1.1 riastrad uint32_t tmp; 494 1.1 riastrad 495 1.1 riastrad tmp = RREG32(R400_GB_PIPE_SELECT); 496 1.1 riastrad seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp); 497 1.1 riastrad tmp = RREG32(R300_GB_TILE_CONFIG); 498 1.1 riastrad seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp); 499 1.1 riastrad tmp = RREG32(R300_DST_PIPE_CONFIG); 500 1.1 riastrad seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp); 501 1.1 riastrad return 0; 502 1.1 riastrad } 503 1.1 riastrad 504 1.1 riastrad static struct drm_info_list r420_pipes_info_list[] = { 505 1.1 riastrad {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL}, 506 1.1 riastrad }; 507 1.1 riastrad #endif 508 1.1 riastrad 509 1.1 riastrad int r420_debugfs_pipes_info_init(struct radeon_device *rdev) 510 1.1 riastrad { 511 1.1 riastrad #if defined(CONFIG_DEBUG_FS) 512 1.1 riastrad return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1); 513 1.1 riastrad #else 514 1.1 riastrad return 0; 515 1.1 riastrad #endif 516 1.1 riastrad } 517