1771fe6b9SJerome Glisse /* 2771fe6b9SJerome Glisse * Copyright 2008 Advanced Micro Devices, Inc. 3771fe6b9SJerome Glisse * Copyright 2008 Red Hat Inc. 4771fe6b9SJerome Glisse * Copyright 2009 Jerome Glisse. 5771fe6b9SJerome Glisse * 6771fe6b9SJerome Glisse * Permission is hereby granted, free of charge, to any person obtaining a 7771fe6b9SJerome Glisse * copy of this software and associated documentation files (the "Software"), 8771fe6b9SJerome Glisse * to deal in the Software without restriction, including without limitation 9771fe6b9SJerome Glisse * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10771fe6b9SJerome Glisse * and/or sell copies of the Software, and to permit persons to whom the 11771fe6b9SJerome Glisse * Software is furnished to do so, subject to the following conditions: 12771fe6b9SJerome Glisse * 13771fe6b9SJerome Glisse * The above copyright notice and this permission notice shall be included in 14771fe6b9SJerome Glisse * all copies or substantial portions of the Software. 15771fe6b9SJerome Glisse * 16771fe6b9SJerome Glisse * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17771fe6b9SJerome Glisse * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18771fe6b9SJerome Glisse * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19771fe6b9SJerome Glisse * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20771fe6b9SJerome Glisse * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21771fe6b9SJerome Glisse * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22771fe6b9SJerome Glisse * OTHER DEALINGS IN THE SOFTWARE. 23771fe6b9SJerome Glisse * 24771fe6b9SJerome Glisse * Authors: Dave Airlie 25771fe6b9SJerome Glisse * Alex Deucher 26771fe6b9SJerome Glisse * Jerome Glisse 27771fe6b9SJerome Glisse */ 28771fe6b9SJerome Glisse #include <linux/seq_file.h> 295a0e3ad6STejun Heo #include <linux/slab.h> 30771fe6b9SJerome Glisse #include "drmP.h" 31771fe6b9SJerome Glisse #include "radeon_reg.h" 32771fe6b9SJerome Glisse #include "radeon.h" 33e6990375SDaniel Vetter #include "radeon_asic.h" 349f022ddfSJerome Glisse #include "atom.h" 3562cdc0c2SCorbin Simpson #include "r100d.h" 36905b6822SJerome Glisse #include "r420d.h" 37804c7559SAlex Deucher #include "r420_reg_safe.h" 38804c7559SAlex Deucher 39*ce8f5370SAlex Deucher void r420_pm_init_profile(struct radeon_device *rdev) 40*ce8f5370SAlex Deucher { 41*ce8f5370SAlex Deucher /* default */ 42*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; 43*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 44*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; 45*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; 46*ce8f5370SAlex Deucher /* low sh */ 47*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0; 48*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1; 49*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; 50*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; 51*ce8f5370SAlex Deucher /* high sh */ 52*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0; 53*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 54*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; 55*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; 56*ce8f5370SAlex Deucher /* low mh */ 57*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0; 58*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 59*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; 60*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; 61*ce8f5370SAlex Deucher /* high mh */ 62*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0; 63*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 64*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; 65*ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; 66*ce8f5370SAlex Deucher } 67*ce8f5370SAlex Deucher 68804c7559SAlex Deucher static void r420_set_reg_safe(struct radeon_device *rdev) 69804c7559SAlex Deucher { 70804c7559SAlex Deucher rdev->config.r300.reg_safe_bm = r420_reg_safe_bm; 71804c7559SAlex Deucher rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm); 72804c7559SAlex Deucher } 73771fe6b9SJerome Glisse 74771fe6b9SJerome Glisse void r420_pipes_init(struct radeon_device *rdev) 75771fe6b9SJerome Glisse { 76771fe6b9SJerome Glisse unsigned tmp; 77771fe6b9SJerome Glisse unsigned gb_pipe_select; 78771fe6b9SJerome Glisse unsigned num_pipes; 79771fe6b9SJerome Glisse 80771fe6b9SJerome Glisse /* GA_ENHANCE workaround TCL deadlock issue */ 814612dc97SAlex Deucher WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL | 824612dc97SAlex Deucher (1 << 2) | (1 << 3)); 8318a4cd2eSDave Airlie /* add idle wait as per freedesktop.org bug 24041 */ 8418a4cd2eSDave Airlie if (r100_gui_wait_for_idle(rdev)) { 8518a4cd2eSDave Airlie printk(KERN_WARNING "Failed to wait GUI idle while " 8618a4cd2eSDave Airlie "programming pipes. Bad things might happen.\n"); 8718a4cd2eSDave Airlie } 88771fe6b9SJerome Glisse /* get max number of pipes */ 89771fe6b9SJerome Glisse gb_pipe_select = RREG32(0x402C); 90771fe6b9SJerome Glisse num_pipes = ((gb_pipe_select >> 12) & 3) + 1; 91771fe6b9SJerome Glisse rdev->num_gb_pipes = num_pipes; 92771fe6b9SJerome Glisse tmp = 0; 93771fe6b9SJerome Glisse switch (num_pipes) { 94771fe6b9SJerome Glisse default: 95771fe6b9SJerome Glisse /* force to 1 pipe */ 96771fe6b9SJerome Glisse num_pipes = 1; 97771fe6b9SJerome Glisse case 1: 98771fe6b9SJerome Glisse tmp = (0 << 1); 99771fe6b9SJerome Glisse break; 100771fe6b9SJerome Glisse case 2: 101771fe6b9SJerome Glisse tmp = (3 << 1); 102771fe6b9SJerome Glisse break; 103771fe6b9SJerome Glisse case 3: 104771fe6b9SJerome Glisse tmp = (6 << 1); 105771fe6b9SJerome Glisse break; 106771fe6b9SJerome Glisse case 4: 107771fe6b9SJerome Glisse tmp = (7 << 1); 108771fe6b9SJerome Glisse break; 109771fe6b9SJerome Glisse } 1104612dc97SAlex Deucher WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1); 111771fe6b9SJerome Glisse /* Sub pixel 1/12 so we can have 4K rendering according to doc */ 1124612dc97SAlex Deucher tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING; 1134612dc97SAlex Deucher WREG32(R300_GB_TILE_CONFIG, tmp); 114771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 115771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 116771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 117771fe6b9SJerome Glisse } 118771fe6b9SJerome Glisse 1194612dc97SAlex Deucher tmp = RREG32(R300_DST_PIPE_CONFIG); 1204612dc97SAlex Deucher WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG); 121771fe6b9SJerome Glisse 122771fe6b9SJerome Glisse WREG32(R300_RB2D_DSTCACHE_MODE, 123771fe6b9SJerome Glisse RREG32(R300_RB2D_DSTCACHE_MODE) | 124771fe6b9SJerome Glisse R300_DC_AUTOFLUSH_ENABLE | 125771fe6b9SJerome Glisse R300_DC_DC_DISABLE_IGNORE_PE); 126771fe6b9SJerome Glisse 127771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 128771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 129771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 130771fe6b9SJerome Glisse } 131f779b3e5SAlex Deucher 132f779b3e5SAlex Deucher if (rdev->family == CHIP_RV530) { 133f779b3e5SAlex Deucher tmp = RREG32(RV530_GB_PIPE_SELECT2); 134f779b3e5SAlex Deucher if ((tmp & 3) == 3) 135f779b3e5SAlex Deucher rdev->num_z_pipes = 2; 136f779b3e5SAlex Deucher else 137f779b3e5SAlex Deucher rdev->num_z_pipes = 1; 138f779b3e5SAlex Deucher } else 139f779b3e5SAlex Deucher rdev->num_z_pipes = 1; 140f779b3e5SAlex Deucher 141f779b3e5SAlex Deucher DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n", 142f779b3e5SAlex Deucher rdev->num_gb_pipes, rdev->num_z_pipes); 143771fe6b9SJerome Glisse } 144771fe6b9SJerome Glisse 1459f022ddfSJerome Glisse u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg) 146771fe6b9SJerome Glisse { 1479f022ddfSJerome Glisse u32 r; 1489f022ddfSJerome Glisse 1499f022ddfSJerome Glisse WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg)); 1509f022ddfSJerome Glisse r = RREG32(R_0001FC_MC_IND_DATA); 1519f022ddfSJerome Glisse return r; 1529f022ddfSJerome Glisse } 1539f022ddfSJerome Glisse 1549f022ddfSJerome Glisse void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v) 1559f022ddfSJerome Glisse { 1569f022ddfSJerome Glisse WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) | 1579f022ddfSJerome Glisse S_0001F8_MC_IND_WR_EN(1)); 1589f022ddfSJerome Glisse WREG32(R_0001FC_MC_IND_DATA, v); 1599f022ddfSJerome Glisse } 1609f022ddfSJerome Glisse 1619f022ddfSJerome Glisse static void r420_debugfs(struct radeon_device *rdev) 1629f022ddfSJerome Glisse { 1639f022ddfSJerome Glisse if (r100_debugfs_rbbm_init(rdev)) { 1649f022ddfSJerome Glisse DRM_ERROR("Failed to register debugfs file for RBBM !\n"); 1659f022ddfSJerome Glisse } 1669f022ddfSJerome Glisse if (r420_debugfs_pipes_info_init(rdev)) { 1679f022ddfSJerome Glisse DRM_ERROR("Failed to register debugfs file for pipes !\n"); 1689f022ddfSJerome Glisse } 1699f022ddfSJerome Glisse } 1709f022ddfSJerome Glisse 1719f022ddfSJerome Glisse static void r420_clock_resume(struct radeon_device *rdev) 1729f022ddfSJerome Glisse { 1739f022ddfSJerome Glisse u32 sclk_cntl; 174ca6ffc64SJerome Glisse 175ca6ffc64SJerome Glisse if (radeon_dynclks != -1 && radeon_dynclks) 176ca6ffc64SJerome Glisse radeon_atom_set_clock_gating(rdev, 1); 1779f022ddfSJerome Glisse sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL); 1789f022ddfSJerome Glisse sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 1799f022ddfSJerome Glisse if (rdev->family == CHIP_R420) 1809f022ddfSJerome Glisse sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1); 1819f022ddfSJerome Glisse WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl); 1829f022ddfSJerome Glisse } 1839f022ddfSJerome Glisse 18462cdc0c2SCorbin Simpson static void r420_cp_errata_init(struct radeon_device *rdev) 18562cdc0c2SCorbin Simpson { 18662cdc0c2SCorbin Simpson /* RV410 and R420 can lock up if CP DMA to host memory happens 18762cdc0c2SCorbin Simpson * while the 2D engine is busy. 18862cdc0c2SCorbin Simpson * 18962cdc0c2SCorbin Simpson * The proper workaround is to queue a RESYNC at the beginning 19062cdc0c2SCorbin Simpson * of the CP init, apparently. 19162cdc0c2SCorbin Simpson */ 19262cdc0c2SCorbin Simpson radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch); 19362cdc0c2SCorbin Simpson radeon_ring_lock(rdev, 8); 19462cdc0c2SCorbin Simpson radeon_ring_write(rdev, PACKET0(R300_CP_RESYNC_ADDR, 1)); 19562cdc0c2SCorbin Simpson radeon_ring_write(rdev, rdev->config.r300.resync_scratch); 19662cdc0c2SCorbin Simpson radeon_ring_write(rdev, 0xDEADBEEF); 19762cdc0c2SCorbin Simpson radeon_ring_unlock_commit(rdev); 19862cdc0c2SCorbin Simpson } 19962cdc0c2SCorbin Simpson 20062cdc0c2SCorbin Simpson static void r420_cp_errata_fini(struct radeon_device *rdev) 20162cdc0c2SCorbin Simpson { 20262cdc0c2SCorbin Simpson /* Catch the RESYNC we dispatched all the way back, 20362cdc0c2SCorbin Simpson * at the very beginning of the CP init. 20462cdc0c2SCorbin Simpson */ 20562cdc0c2SCorbin Simpson radeon_ring_lock(rdev, 8); 20662cdc0c2SCorbin Simpson radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); 20762cdc0c2SCorbin Simpson radeon_ring_write(rdev, R300_RB3D_DC_FINISH); 20862cdc0c2SCorbin Simpson radeon_ring_unlock_commit(rdev); 20962cdc0c2SCorbin Simpson radeon_scratch_free(rdev, rdev->config.r300.resync_scratch); 21062cdc0c2SCorbin Simpson } 21162cdc0c2SCorbin Simpson 212fc30b8efSDave Airlie static int r420_startup(struct radeon_device *rdev) 2139f022ddfSJerome Glisse { 2149f022ddfSJerome Glisse int r; 2159f022ddfSJerome Glisse 21692cde00cSAlex Deucher /* set common regs */ 21792cde00cSAlex Deucher r100_set_common_regs(rdev); 21892cde00cSAlex Deucher /* program mc */ 2199f022ddfSJerome Glisse r300_mc_program(rdev); 220ca6ffc64SJerome Glisse /* Resume clock */ 221ca6ffc64SJerome Glisse r420_clock_resume(rdev); 2229f022ddfSJerome Glisse /* Initialize GART (initialize after TTM so we can allocate 2239f022ddfSJerome Glisse * memory through TTM but finalize after TTM) */ 2244aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 2254aac0473SJerome Glisse r = rv370_pcie_gart_enable(rdev); 2264aac0473SJerome Glisse if (r) 2274aac0473SJerome Glisse return r; 2284aac0473SJerome Glisse } 2294aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 2304aac0473SJerome Glisse r = r100_pci_gart_enable(rdev); 2314aac0473SJerome Glisse if (r) 2329f022ddfSJerome Glisse return r; 2339f022ddfSJerome Glisse } 234771fe6b9SJerome Glisse r420_pipes_init(rdev); 2359f022ddfSJerome Glisse /* Enable IRQ */ 2369f022ddfSJerome Glisse r100_irq_set(rdev); 237cafe6609SJerome Glisse rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 2389f022ddfSJerome Glisse /* 1M ring buffer */ 2399f022ddfSJerome Glisse r = r100_cp_init(rdev, 1024 * 1024); 2409f022ddfSJerome Glisse if (r) { 2419f022ddfSJerome Glisse dev_err(rdev->dev, "failled initializing CP (%d).\n", r); 2429f022ddfSJerome Glisse return r; 243771fe6b9SJerome Glisse } 24462cdc0c2SCorbin Simpson r420_cp_errata_init(rdev); 2459f022ddfSJerome Glisse r = r100_wb_init(rdev); 2469f022ddfSJerome Glisse if (r) { 2479f022ddfSJerome Glisse dev_err(rdev->dev, "failled initializing WB (%d).\n", r); 2489f022ddfSJerome Glisse } 2499f022ddfSJerome Glisse r = r100_ib_init(rdev); 2509f022ddfSJerome Glisse if (r) { 2519f022ddfSJerome Glisse dev_err(rdev->dev, "failled initializing IB (%d).\n", r); 2529f022ddfSJerome Glisse return r; 2539f022ddfSJerome Glisse } 2549f022ddfSJerome Glisse return 0; 255771fe6b9SJerome Glisse } 256771fe6b9SJerome Glisse 257fc30b8efSDave Airlie int r420_resume(struct radeon_device *rdev) 258fc30b8efSDave Airlie { 259fc30b8efSDave Airlie /* Make sur GART are not working */ 260fc30b8efSDave Airlie if (rdev->flags & RADEON_IS_PCIE) 261fc30b8efSDave Airlie rv370_pcie_gart_disable(rdev); 262fc30b8efSDave Airlie if (rdev->flags & RADEON_IS_PCI) 263fc30b8efSDave Airlie r100_pci_gart_disable(rdev); 264fc30b8efSDave Airlie /* Resume clock before doing reset */ 265fc30b8efSDave Airlie r420_clock_resume(rdev); 266fc30b8efSDave Airlie /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 267a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 268fc30b8efSDave Airlie dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 269fc30b8efSDave Airlie RREG32(R_000E40_RBBM_STATUS), 270fc30b8efSDave Airlie RREG32(R_0007C0_CP_STAT)); 271fc30b8efSDave Airlie } 272fc30b8efSDave Airlie /* check if cards are posted or not */ 273fc30b8efSDave Airlie if (rdev->is_atom_bios) { 274fc30b8efSDave Airlie atom_asic_init(rdev->mode_info.atom_context); 275fc30b8efSDave Airlie } else { 276fc30b8efSDave Airlie radeon_combios_asic_init(rdev->ddev); 277fc30b8efSDave Airlie } 278fc30b8efSDave Airlie /* Resume clock after posting */ 279fc30b8efSDave Airlie r420_clock_resume(rdev); 280550e2d92SDave Airlie /* Initialize surface registers */ 281550e2d92SDave Airlie radeon_surface_init(rdev); 282fc30b8efSDave Airlie return r420_startup(rdev); 283fc30b8efSDave Airlie } 284fc30b8efSDave Airlie 2859f022ddfSJerome Glisse int r420_suspend(struct radeon_device *rdev) 286771fe6b9SJerome Glisse { 28762cdc0c2SCorbin Simpson r420_cp_errata_fini(rdev); 2889f022ddfSJerome Glisse r100_cp_disable(rdev); 2899f022ddfSJerome Glisse r100_wb_disable(rdev); 2909f022ddfSJerome Glisse r100_irq_disable(rdev); 2914aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 2924aac0473SJerome Glisse rv370_pcie_gart_disable(rdev); 2934aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 2944aac0473SJerome Glisse r100_pci_gart_disable(rdev); 2959f022ddfSJerome Glisse return 0; 296771fe6b9SJerome Glisse } 297771fe6b9SJerome Glisse 2989f022ddfSJerome Glisse void r420_fini(struct radeon_device *rdev) 2999f022ddfSJerome Glisse { 3009f022ddfSJerome Glisse r100_cp_fini(rdev); 3019f022ddfSJerome Glisse r100_wb_fini(rdev); 3029f022ddfSJerome Glisse r100_ib_fini(rdev); 3039f022ddfSJerome Glisse radeon_gem_fini(rdev); 3044aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 3054aac0473SJerome Glisse rv370_pcie_gart_fini(rdev); 3064aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3074aac0473SJerome Glisse r100_pci_gart_fini(rdev); 3089f022ddfSJerome Glisse radeon_agp_fini(rdev); 3099f022ddfSJerome Glisse radeon_irq_kms_fini(rdev); 3109f022ddfSJerome Glisse radeon_fence_driver_fini(rdev); 3114c788679SJerome Glisse radeon_bo_fini(rdev); 3129f022ddfSJerome Glisse if (rdev->is_atom_bios) { 3139f022ddfSJerome Glisse radeon_atombios_fini(rdev); 3149f022ddfSJerome Glisse } else { 3159f022ddfSJerome Glisse radeon_combios_fini(rdev); 3169f022ddfSJerome Glisse } 3179f022ddfSJerome Glisse kfree(rdev->bios); 3189f022ddfSJerome Glisse rdev->bios = NULL; 3199f022ddfSJerome Glisse } 3209f022ddfSJerome Glisse 3219f022ddfSJerome Glisse int r420_init(struct radeon_device *rdev) 3229f022ddfSJerome Glisse { 3239f022ddfSJerome Glisse int r; 3249f022ddfSJerome Glisse 3259f022ddfSJerome Glisse /* Initialize scratch registers */ 3269f022ddfSJerome Glisse radeon_scratch_init(rdev); 3279f022ddfSJerome Glisse /* Initialize surface registers */ 3289f022ddfSJerome Glisse radeon_surface_init(rdev); 3299f022ddfSJerome Glisse /* TODO: disable VGA need to use VGA request */ 3309f022ddfSJerome Glisse /* BIOS*/ 3319f022ddfSJerome Glisse if (!radeon_get_bios(rdev)) { 3329f022ddfSJerome Glisse if (ASIC_IS_AVIVO(rdev)) 3339f022ddfSJerome Glisse return -EINVAL; 3349f022ddfSJerome Glisse } 3359f022ddfSJerome Glisse if (rdev->is_atom_bios) { 3369f022ddfSJerome Glisse r = radeon_atombios_init(rdev); 3379f022ddfSJerome Glisse if (r) { 3389f022ddfSJerome Glisse return r; 3399f022ddfSJerome Glisse } 3409f022ddfSJerome Glisse } else { 3419f022ddfSJerome Glisse r = radeon_combios_init(rdev); 3429f022ddfSJerome Glisse if (r) { 3439f022ddfSJerome Glisse return r; 3449f022ddfSJerome Glisse } 3459f022ddfSJerome Glisse } 3469f022ddfSJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 347a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 3489f022ddfSJerome Glisse dev_warn(rdev->dev, 3499f022ddfSJerome Glisse "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3509f022ddfSJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3519f022ddfSJerome Glisse RREG32(R_0007C0_CP_STAT)); 3529f022ddfSJerome Glisse } 3539f022ddfSJerome Glisse /* check if cards are posted or not */ 35472542d77SDave Airlie if (radeon_boot_test_post_card(rdev) == false) 35572542d77SDave Airlie return -EINVAL; 35672542d77SDave Airlie 3579f022ddfSJerome Glisse /* Initialize clocks */ 3589f022ddfSJerome Glisse radeon_get_clock_info(rdev->ddev); 359d594e46aSJerome Glisse /* initialize AGP */ 360d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 361d594e46aSJerome Glisse r = radeon_agp_init(rdev); 3629f022ddfSJerome Glisse if (r) { 363d594e46aSJerome Glisse radeon_agp_disable(rdev); 3649f022ddfSJerome Glisse } 365d594e46aSJerome Glisse } 366d594e46aSJerome Glisse /* initialize memory controller */ 367d594e46aSJerome Glisse r300_mc_init(rdev); 3689f022ddfSJerome Glisse r420_debugfs(rdev); 3699f022ddfSJerome Glisse /* Fence driver */ 3709f022ddfSJerome Glisse r = radeon_fence_driver_init(rdev); 3719f022ddfSJerome Glisse if (r) { 3729f022ddfSJerome Glisse return r; 3739f022ddfSJerome Glisse } 3749f022ddfSJerome Glisse r = radeon_irq_kms_init(rdev); 3759f022ddfSJerome Glisse if (r) { 3769f022ddfSJerome Glisse return r; 3779f022ddfSJerome Glisse } 3789f022ddfSJerome Glisse /* Memory manager */ 3794c788679SJerome Glisse r = radeon_bo_init(rdev); 3809f022ddfSJerome Glisse if (r) { 3819f022ddfSJerome Glisse return r; 3829f022ddfSJerome Glisse } 38317e15b0cSDave Airlie if (rdev->family == CHIP_R420) 38417e15b0cSDave Airlie r100_enable_bm(rdev); 38517e15b0cSDave Airlie 3864aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 3874aac0473SJerome Glisse r = rv370_pcie_gart_init(rdev); 3884aac0473SJerome Glisse if (r) 3894aac0473SJerome Glisse return r; 3904aac0473SJerome Glisse } 3914aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 3924aac0473SJerome Glisse r = r100_pci_gart_init(rdev); 3934aac0473SJerome Glisse if (r) 3944aac0473SJerome Glisse return r; 3954aac0473SJerome Glisse } 396804c7559SAlex Deucher r420_set_reg_safe(rdev); 397733289c2SJerome Glisse rdev->accel_working = true; 398fc30b8efSDave Airlie r = r420_startup(rdev); 3999f022ddfSJerome Glisse if (r) { 4009f022ddfSJerome Glisse /* Somethings want wront with the accel init stop accel */ 4019f022ddfSJerome Glisse dev_err(rdev->dev, "Disabling GPU acceleration\n"); 4029f022ddfSJerome Glisse r100_cp_fini(rdev); 4039f022ddfSJerome Glisse r100_wb_fini(rdev); 4049f022ddfSJerome Glisse r100_ib_fini(rdev); 405655efd3dSJerome Glisse radeon_irq_kms_fini(rdev); 4064aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 4074aac0473SJerome Glisse rv370_pcie_gart_fini(rdev); 4084aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 4094aac0473SJerome Glisse r100_pci_gart_fini(rdev); 4109f022ddfSJerome Glisse radeon_agp_fini(rdev); 411733289c2SJerome Glisse rdev->accel_working = false; 4129f022ddfSJerome Glisse } 4139f022ddfSJerome Glisse return 0; 4149f022ddfSJerome Glisse } 415771fe6b9SJerome Glisse 416771fe6b9SJerome Glisse /* 417771fe6b9SJerome Glisse * Debugfs info 418771fe6b9SJerome Glisse */ 419771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 420771fe6b9SJerome Glisse static int r420_debugfs_pipes_info(struct seq_file *m, void *data) 421771fe6b9SJerome Glisse { 422771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 423771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 424771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 425771fe6b9SJerome Glisse uint32_t tmp; 426771fe6b9SJerome Glisse 427771fe6b9SJerome Glisse tmp = RREG32(R400_GB_PIPE_SELECT); 428771fe6b9SJerome Glisse seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp); 429771fe6b9SJerome Glisse tmp = RREG32(R300_GB_TILE_CONFIG); 430771fe6b9SJerome Glisse seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp); 431771fe6b9SJerome Glisse tmp = RREG32(R300_DST_PIPE_CONFIG); 432771fe6b9SJerome Glisse seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp); 433771fe6b9SJerome Glisse return 0; 434771fe6b9SJerome Glisse } 435771fe6b9SJerome Glisse 436771fe6b9SJerome Glisse static struct drm_info_list r420_pipes_info_list[] = { 437771fe6b9SJerome Glisse {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL}, 438771fe6b9SJerome Glisse }; 439771fe6b9SJerome Glisse #endif 440771fe6b9SJerome Glisse 441771fe6b9SJerome Glisse int r420_debugfs_pipes_info_init(struct radeon_device *rdev) 442771fe6b9SJerome Glisse { 443771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 444771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1); 445771fe6b9SJerome Glisse #else 446771fe6b9SJerome Glisse return 0; 447771fe6b9SJerome Glisse #endif 448771fe6b9SJerome Glisse } 449