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 39ce8f5370SAlex Deucher void r420_pm_init_profile(struct radeon_device *rdev) 40ce8f5370SAlex Deucher { 41ce8f5370SAlex Deucher /* default */ 42ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index; 43ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 44ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; 45ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0; 46ce8f5370SAlex Deucher /* low sh */ 47ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0; 48c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0; 49ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; 50ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; 51c9e75b21SAlex Deucher /* mid sh */ 52c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0; 53c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1; 54c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0; 55c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0; 56ce8f5370SAlex Deucher /* high sh */ 57ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0; 58ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 59ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; 60ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0; 61ce8f5370SAlex Deucher /* low mh */ 62ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0; 63ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 64ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; 65ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; 66c9e75b21SAlex Deucher /* mid mh */ 67c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0; 68c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 69c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0; 70c9e75b21SAlex Deucher rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0; 71ce8f5370SAlex Deucher /* high mh */ 72ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0; 73ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index; 74ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; 75ce8f5370SAlex Deucher rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0; 76ce8f5370SAlex Deucher } 77ce8f5370SAlex Deucher 78804c7559SAlex Deucher static void r420_set_reg_safe(struct radeon_device *rdev) 79804c7559SAlex Deucher { 80804c7559SAlex Deucher rdev->config.r300.reg_safe_bm = r420_reg_safe_bm; 81804c7559SAlex Deucher rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm); 82804c7559SAlex Deucher } 83771fe6b9SJerome Glisse 84771fe6b9SJerome Glisse void r420_pipes_init(struct radeon_device *rdev) 85771fe6b9SJerome Glisse { 86771fe6b9SJerome Glisse unsigned tmp; 87771fe6b9SJerome Glisse unsigned gb_pipe_select; 88771fe6b9SJerome Glisse unsigned num_pipes; 89771fe6b9SJerome Glisse 90771fe6b9SJerome Glisse /* GA_ENHANCE workaround TCL deadlock issue */ 914612dc97SAlex Deucher WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL | 924612dc97SAlex Deucher (1 << 2) | (1 << 3)); 9318a4cd2eSDave Airlie /* add idle wait as per freedesktop.org bug 24041 */ 9418a4cd2eSDave Airlie if (r100_gui_wait_for_idle(rdev)) { 9518a4cd2eSDave Airlie printk(KERN_WARNING "Failed to wait GUI idle while " 9618a4cd2eSDave Airlie "programming pipes. Bad things might happen.\n"); 9718a4cd2eSDave Airlie } 98771fe6b9SJerome Glisse /* get max number of pipes */ 99d75ee3beSAlex Deucher gb_pipe_select = RREG32(R400_GB_PIPE_SELECT); 100771fe6b9SJerome Glisse num_pipes = ((gb_pipe_select >> 12) & 3) + 1; 10194f7bf64STormod Volden 10294f7bf64STormod Volden /* SE chips have 1 pipe */ 10394f7bf64STormod Volden if ((rdev->pdev->device == 0x5e4c) || 10494f7bf64STormod Volden (rdev->pdev->device == 0x5e4f)) 10594f7bf64STormod Volden num_pipes = 1; 10694f7bf64STormod Volden 107771fe6b9SJerome Glisse rdev->num_gb_pipes = num_pipes; 108771fe6b9SJerome Glisse tmp = 0; 109771fe6b9SJerome Glisse switch (num_pipes) { 110771fe6b9SJerome Glisse default: 111771fe6b9SJerome Glisse /* force to 1 pipe */ 112771fe6b9SJerome Glisse num_pipes = 1; 113771fe6b9SJerome Glisse case 1: 114771fe6b9SJerome Glisse tmp = (0 << 1); 115771fe6b9SJerome Glisse break; 116771fe6b9SJerome Glisse case 2: 117771fe6b9SJerome Glisse tmp = (3 << 1); 118771fe6b9SJerome Glisse break; 119771fe6b9SJerome Glisse case 3: 120771fe6b9SJerome Glisse tmp = (6 << 1); 121771fe6b9SJerome Glisse break; 122771fe6b9SJerome Glisse case 4: 123771fe6b9SJerome Glisse tmp = (7 << 1); 124771fe6b9SJerome Glisse break; 125771fe6b9SJerome Glisse } 1264612dc97SAlex Deucher WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1); 127771fe6b9SJerome Glisse /* Sub pixel 1/12 so we can have 4K rendering according to doc */ 1284612dc97SAlex Deucher tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING; 1294612dc97SAlex Deucher WREG32(R300_GB_TILE_CONFIG, tmp); 130771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 131771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 132771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 133771fe6b9SJerome Glisse } 134771fe6b9SJerome Glisse 1354612dc97SAlex Deucher tmp = RREG32(R300_DST_PIPE_CONFIG); 1364612dc97SAlex Deucher WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG); 137771fe6b9SJerome Glisse 138771fe6b9SJerome Glisse WREG32(R300_RB2D_DSTCACHE_MODE, 139771fe6b9SJerome Glisse RREG32(R300_RB2D_DSTCACHE_MODE) | 140771fe6b9SJerome Glisse R300_DC_AUTOFLUSH_ENABLE | 141771fe6b9SJerome Glisse R300_DC_DC_DISABLE_IGNORE_PE); 142771fe6b9SJerome Glisse 143771fe6b9SJerome Glisse if (r100_gui_wait_for_idle(rdev)) { 144771fe6b9SJerome Glisse printk(KERN_WARNING "Failed to wait GUI idle while " 145771fe6b9SJerome Glisse "programming pipes. Bad things might happen.\n"); 146771fe6b9SJerome Glisse } 147f779b3e5SAlex Deucher 148f779b3e5SAlex Deucher if (rdev->family == CHIP_RV530) { 149f779b3e5SAlex Deucher tmp = RREG32(RV530_GB_PIPE_SELECT2); 150f779b3e5SAlex Deucher if ((tmp & 3) == 3) 151f779b3e5SAlex Deucher rdev->num_z_pipes = 2; 152f779b3e5SAlex Deucher else 153f779b3e5SAlex Deucher rdev->num_z_pipes = 1; 154f779b3e5SAlex Deucher } else 155f779b3e5SAlex Deucher rdev->num_z_pipes = 1; 156f779b3e5SAlex Deucher 157f779b3e5SAlex Deucher DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n", 158f779b3e5SAlex Deucher rdev->num_gb_pipes, rdev->num_z_pipes); 159771fe6b9SJerome Glisse } 160771fe6b9SJerome Glisse 1619f022ddfSJerome Glisse u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg) 162771fe6b9SJerome Glisse { 1639f022ddfSJerome Glisse u32 r; 1649f022ddfSJerome Glisse 1659f022ddfSJerome Glisse WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg)); 1669f022ddfSJerome Glisse r = RREG32(R_0001FC_MC_IND_DATA); 1679f022ddfSJerome Glisse return r; 1689f022ddfSJerome Glisse } 1699f022ddfSJerome Glisse 1709f022ddfSJerome Glisse void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v) 1719f022ddfSJerome Glisse { 1729f022ddfSJerome Glisse WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) | 1739f022ddfSJerome Glisse S_0001F8_MC_IND_WR_EN(1)); 1749f022ddfSJerome Glisse WREG32(R_0001FC_MC_IND_DATA, v); 1759f022ddfSJerome Glisse } 1769f022ddfSJerome Glisse 1779f022ddfSJerome Glisse static void r420_debugfs(struct radeon_device *rdev) 1789f022ddfSJerome Glisse { 1799f022ddfSJerome Glisse if (r100_debugfs_rbbm_init(rdev)) { 1809f022ddfSJerome Glisse DRM_ERROR("Failed to register debugfs file for RBBM !\n"); 1819f022ddfSJerome Glisse } 1829f022ddfSJerome Glisse if (r420_debugfs_pipes_info_init(rdev)) { 1839f022ddfSJerome Glisse DRM_ERROR("Failed to register debugfs file for pipes !\n"); 1849f022ddfSJerome Glisse } 1859f022ddfSJerome Glisse } 1869f022ddfSJerome Glisse 1879f022ddfSJerome Glisse static void r420_clock_resume(struct radeon_device *rdev) 1889f022ddfSJerome Glisse { 1899f022ddfSJerome Glisse u32 sclk_cntl; 190ca6ffc64SJerome Glisse 191ca6ffc64SJerome Glisse if (radeon_dynclks != -1 && radeon_dynclks) 192ca6ffc64SJerome Glisse radeon_atom_set_clock_gating(rdev, 1); 1939f022ddfSJerome Glisse sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL); 1949f022ddfSJerome Glisse sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1); 1959f022ddfSJerome Glisse if (rdev->family == CHIP_R420) 1969f022ddfSJerome Glisse sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1); 1979f022ddfSJerome Glisse WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl); 1989f022ddfSJerome Glisse } 1999f022ddfSJerome Glisse 20062cdc0c2SCorbin Simpson static void r420_cp_errata_init(struct radeon_device *rdev) 20162cdc0c2SCorbin Simpson { 202e32eb50dSChristian König struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 2037b1f2485SChristian König 20462cdc0c2SCorbin Simpson /* RV410 and R420 can lock up if CP DMA to host memory happens 20562cdc0c2SCorbin Simpson * while the 2D engine is busy. 20662cdc0c2SCorbin Simpson * 20762cdc0c2SCorbin Simpson * The proper workaround is to queue a RESYNC at the beginning 20862cdc0c2SCorbin Simpson * of the CP init, apparently. 20962cdc0c2SCorbin Simpson */ 21062cdc0c2SCorbin Simpson radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch); 211e32eb50dSChristian König radeon_ring_lock(rdev, ring, 8); 212e32eb50dSChristian König radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1)); 213e32eb50dSChristian König radeon_ring_write(ring, rdev->config.r300.resync_scratch); 214e32eb50dSChristian König radeon_ring_write(ring, 0xDEADBEEF); 215e32eb50dSChristian König radeon_ring_unlock_commit(rdev, ring); 21662cdc0c2SCorbin Simpson } 21762cdc0c2SCorbin Simpson 21862cdc0c2SCorbin Simpson static void r420_cp_errata_fini(struct radeon_device *rdev) 21962cdc0c2SCorbin Simpson { 220e32eb50dSChristian König struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]; 2217b1f2485SChristian König 22262cdc0c2SCorbin Simpson /* Catch the RESYNC we dispatched all the way back, 22362cdc0c2SCorbin Simpson * at the very beginning of the CP init. 22462cdc0c2SCorbin Simpson */ 225e32eb50dSChristian König radeon_ring_lock(rdev, ring, 8); 226e32eb50dSChristian König radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0)); 227e32eb50dSChristian König radeon_ring_write(ring, R300_RB3D_DC_FINISH); 228e32eb50dSChristian König radeon_ring_unlock_commit(rdev, ring); 22962cdc0c2SCorbin Simpson radeon_scratch_free(rdev, rdev->config.r300.resync_scratch); 23062cdc0c2SCorbin Simpson } 23162cdc0c2SCorbin Simpson 232fc30b8efSDave Airlie static int r420_startup(struct radeon_device *rdev) 2339f022ddfSJerome Glisse { 2349f022ddfSJerome Glisse int r; 2359f022ddfSJerome Glisse 23692cde00cSAlex Deucher /* set common regs */ 23792cde00cSAlex Deucher r100_set_common_regs(rdev); 23892cde00cSAlex Deucher /* program mc */ 2399f022ddfSJerome Glisse r300_mc_program(rdev); 240ca6ffc64SJerome Glisse /* Resume clock */ 241ca6ffc64SJerome Glisse r420_clock_resume(rdev); 2429f022ddfSJerome Glisse /* Initialize GART (initialize after TTM so we can allocate 2439f022ddfSJerome Glisse * memory through TTM but finalize after TTM) */ 2444aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 2454aac0473SJerome Glisse r = rv370_pcie_gart_enable(rdev); 2464aac0473SJerome Glisse if (r) 2474aac0473SJerome Glisse return r; 2484aac0473SJerome Glisse } 2494aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 2504aac0473SJerome Glisse r = r100_pci_gart_enable(rdev); 2514aac0473SJerome Glisse if (r) 2529f022ddfSJerome Glisse return r; 2539f022ddfSJerome Glisse } 254771fe6b9SJerome Glisse r420_pipes_init(rdev); 255724c80e1SAlex Deucher 256724c80e1SAlex Deucher /* allocate wb buffer */ 257724c80e1SAlex Deucher r = radeon_wb_init(rdev); 258724c80e1SAlex Deucher if (r) 259724c80e1SAlex Deucher return r; 260724c80e1SAlex Deucher 26130eb77f4SJerome Glisse r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX); 26230eb77f4SJerome Glisse if (r) { 26330eb77f4SJerome Glisse dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r); 26430eb77f4SJerome Glisse return r; 26530eb77f4SJerome Glisse } 26630eb77f4SJerome Glisse 2679f022ddfSJerome Glisse /* Enable IRQ */ 2689f022ddfSJerome Glisse r100_irq_set(rdev); 269cafe6609SJerome Glisse rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL); 2709f022ddfSJerome Glisse /* 1M ring buffer */ 2719f022ddfSJerome Glisse r = r100_cp_init(rdev, 1024 * 1024); 2729f022ddfSJerome Glisse if (r) { 273ec4f2ac4SPaul Bolle dev_err(rdev->dev, "failed initializing CP (%d).\n", r); 2749f022ddfSJerome Glisse return r; 275771fe6b9SJerome Glisse } 27662cdc0c2SCorbin Simpson r420_cp_errata_init(rdev); 277*b15ba512SJerome Glisse 278*b15ba512SJerome Glisse r = radeon_ib_pool_start(rdev); 279*b15ba512SJerome Glisse if (r) 280*b15ba512SJerome Glisse return r; 281*b15ba512SJerome Glisse 282*b15ba512SJerome Glisse r = r100_ib_test(rdev); 2839f022ddfSJerome Glisse if (r) { 284*b15ba512SJerome Glisse dev_err(rdev->dev, "failed testing IB (%d).\n", r); 285*b15ba512SJerome Glisse rdev->accel_working = false; 2869f022ddfSJerome Glisse return r; 2879f022ddfSJerome Glisse } 288*b15ba512SJerome Glisse 2899f022ddfSJerome Glisse return 0; 290771fe6b9SJerome Glisse } 291771fe6b9SJerome Glisse 292fc30b8efSDave Airlie int r420_resume(struct radeon_device *rdev) 293fc30b8efSDave Airlie { 294fc30b8efSDave Airlie /* Make sur GART are not working */ 295fc30b8efSDave Airlie if (rdev->flags & RADEON_IS_PCIE) 296fc30b8efSDave Airlie rv370_pcie_gart_disable(rdev); 297fc30b8efSDave Airlie if (rdev->flags & RADEON_IS_PCI) 298fc30b8efSDave Airlie r100_pci_gart_disable(rdev); 299fc30b8efSDave Airlie /* Resume clock before doing reset */ 300fc30b8efSDave Airlie r420_clock_resume(rdev); 301fc30b8efSDave Airlie /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 302a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 303fc30b8efSDave Airlie dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 304fc30b8efSDave Airlie RREG32(R_000E40_RBBM_STATUS), 305fc30b8efSDave Airlie RREG32(R_0007C0_CP_STAT)); 306fc30b8efSDave Airlie } 307fc30b8efSDave Airlie /* check if cards are posted or not */ 308fc30b8efSDave Airlie if (rdev->is_atom_bios) { 309fc30b8efSDave Airlie atom_asic_init(rdev->mode_info.atom_context); 310fc30b8efSDave Airlie } else { 311fc30b8efSDave Airlie radeon_combios_asic_init(rdev->ddev); 312fc30b8efSDave Airlie } 313fc30b8efSDave Airlie /* Resume clock after posting */ 314fc30b8efSDave Airlie r420_clock_resume(rdev); 315550e2d92SDave Airlie /* Initialize surface registers */ 316550e2d92SDave Airlie radeon_surface_init(rdev); 317*b15ba512SJerome Glisse 318*b15ba512SJerome Glisse rdev->accel_working = true; 319fc30b8efSDave Airlie return r420_startup(rdev); 320fc30b8efSDave Airlie } 321fc30b8efSDave Airlie 3229f022ddfSJerome Glisse int r420_suspend(struct radeon_device *rdev) 323771fe6b9SJerome Glisse { 324*b15ba512SJerome Glisse radeon_ib_pool_suspend(rdev); 32562cdc0c2SCorbin Simpson r420_cp_errata_fini(rdev); 3269f022ddfSJerome Glisse r100_cp_disable(rdev); 327724c80e1SAlex Deucher radeon_wb_disable(rdev); 3289f022ddfSJerome Glisse r100_irq_disable(rdev); 3294aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 3304aac0473SJerome Glisse rv370_pcie_gart_disable(rdev); 3314aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3324aac0473SJerome Glisse r100_pci_gart_disable(rdev); 3339f022ddfSJerome Glisse return 0; 334771fe6b9SJerome Glisse } 335771fe6b9SJerome Glisse 3369f022ddfSJerome Glisse void r420_fini(struct radeon_device *rdev) 3379f022ddfSJerome Glisse { 3389f022ddfSJerome Glisse r100_cp_fini(rdev); 339724c80e1SAlex Deucher radeon_wb_fini(rdev); 3409f022ddfSJerome Glisse r100_ib_fini(rdev); 3419f022ddfSJerome Glisse radeon_gem_fini(rdev); 3424aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 3434aac0473SJerome Glisse rv370_pcie_gart_fini(rdev); 3444aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 3454aac0473SJerome Glisse r100_pci_gart_fini(rdev); 3469f022ddfSJerome Glisse radeon_agp_fini(rdev); 3479f022ddfSJerome Glisse radeon_irq_kms_fini(rdev); 3489f022ddfSJerome Glisse radeon_fence_driver_fini(rdev); 3494c788679SJerome Glisse radeon_bo_fini(rdev); 3509f022ddfSJerome Glisse if (rdev->is_atom_bios) { 3519f022ddfSJerome Glisse radeon_atombios_fini(rdev); 3529f022ddfSJerome Glisse } else { 3539f022ddfSJerome Glisse radeon_combios_fini(rdev); 3549f022ddfSJerome Glisse } 3559f022ddfSJerome Glisse kfree(rdev->bios); 3569f022ddfSJerome Glisse rdev->bios = NULL; 3579f022ddfSJerome Glisse } 3589f022ddfSJerome Glisse 3599f022ddfSJerome Glisse int r420_init(struct radeon_device *rdev) 3609f022ddfSJerome Glisse { 3619f022ddfSJerome Glisse int r; 3629f022ddfSJerome Glisse 3639f022ddfSJerome Glisse /* Initialize scratch registers */ 3649f022ddfSJerome Glisse radeon_scratch_init(rdev); 3659f022ddfSJerome Glisse /* Initialize surface registers */ 3669f022ddfSJerome Glisse radeon_surface_init(rdev); 3679f022ddfSJerome Glisse /* TODO: disable VGA need to use VGA request */ 3684c712e6cSDave Airlie /* restore some register to sane defaults */ 3694c712e6cSDave Airlie r100_restore_sanity(rdev); 3709f022ddfSJerome Glisse /* BIOS*/ 3719f022ddfSJerome Glisse if (!radeon_get_bios(rdev)) { 3729f022ddfSJerome Glisse if (ASIC_IS_AVIVO(rdev)) 3739f022ddfSJerome Glisse return -EINVAL; 3749f022ddfSJerome Glisse } 3759f022ddfSJerome Glisse if (rdev->is_atom_bios) { 3769f022ddfSJerome Glisse r = radeon_atombios_init(rdev); 3779f022ddfSJerome Glisse if (r) { 3789f022ddfSJerome Glisse return r; 3799f022ddfSJerome Glisse } 3809f022ddfSJerome Glisse } else { 3819f022ddfSJerome Glisse r = radeon_combios_init(rdev); 3829f022ddfSJerome Glisse if (r) { 3839f022ddfSJerome Glisse return r; 3849f022ddfSJerome Glisse } 3859f022ddfSJerome Glisse } 3869f022ddfSJerome Glisse /* Reset gpu before posting otherwise ATOM will enter infinite loop */ 387a2d07b74SJerome Glisse if (radeon_asic_reset(rdev)) { 3889f022ddfSJerome Glisse dev_warn(rdev->dev, 3899f022ddfSJerome Glisse "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n", 3909f022ddfSJerome Glisse RREG32(R_000E40_RBBM_STATUS), 3919f022ddfSJerome Glisse RREG32(R_0007C0_CP_STAT)); 3929f022ddfSJerome Glisse } 3939f022ddfSJerome Glisse /* check if cards are posted or not */ 39472542d77SDave Airlie if (radeon_boot_test_post_card(rdev) == false) 39572542d77SDave Airlie return -EINVAL; 39672542d77SDave Airlie 3979f022ddfSJerome Glisse /* Initialize clocks */ 3989f022ddfSJerome Glisse radeon_get_clock_info(rdev->ddev); 399d594e46aSJerome Glisse /* initialize AGP */ 400d594e46aSJerome Glisse if (rdev->flags & RADEON_IS_AGP) { 401d594e46aSJerome Glisse r = radeon_agp_init(rdev); 4029f022ddfSJerome Glisse if (r) { 403d594e46aSJerome Glisse radeon_agp_disable(rdev); 4049f022ddfSJerome Glisse } 405d594e46aSJerome Glisse } 406d594e46aSJerome Glisse /* initialize memory controller */ 407d594e46aSJerome Glisse r300_mc_init(rdev); 4089f022ddfSJerome Glisse r420_debugfs(rdev); 4099f022ddfSJerome Glisse /* Fence driver */ 41030eb77f4SJerome Glisse r = radeon_fence_driver_init(rdev); 4119f022ddfSJerome Glisse if (r) { 4129f022ddfSJerome Glisse return r; 4139f022ddfSJerome Glisse } 4149f022ddfSJerome Glisse r = radeon_irq_kms_init(rdev); 4159f022ddfSJerome Glisse if (r) { 4169f022ddfSJerome Glisse return r; 4179f022ddfSJerome Glisse } 4189f022ddfSJerome Glisse /* Memory manager */ 4194c788679SJerome Glisse r = radeon_bo_init(rdev); 4209f022ddfSJerome Glisse if (r) { 4219f022ddfSJerome Glisse return r; 4229f022ddfSJerome Glisse } 42317e15b0cSDave Airlie if (rdev->family == CHIP_R420) 42417e15b0cSDave Airlie r100_enable_bm(rdev); 42517e15b0cSDave Airlie 4264aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) { 4274aac0473SJerome Glisse r = rv370_pcie_gart_init(rdev); 4284aac0473SJerome Glisse if (r) 4294aac0473SJerome Glisse return r; 4304aac0473SJerome Glisse } 4314aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) { 4324aac0473SJerome Glisse r = r100_pci_gart_init(rdev); 4334aac0473SJerome Glisse if (r) 4344aac0473SJerome Glisse return r; 4354aac0473SJerome Glisse } 436804c7559SAlex Deucher r420_set_reg_safe(rdev); 437*b15ba512SJerome Glisse 438*b15ba512SJerome Glisse r = radeon_ib_pool_init(rdev); 439733289c2SJerome Glisse rdev->accel_working = true; 440*b15ba512SJerome Glisse if (r) { 441*b15ba512SJerome Glisse dev_err(rdev->dev, "IB initialization failed (%d).\n", r); 442*b15ba512SJerome Glisse rdev->accel_working = false; 443*b15ba512SJerome Glisse } 444*b15ba512SJerome Glisse 445fc30b8efSDave Airlie r = r420_startup(rdev); 4469f022ddfSJerome Glisse if (r) { 4479f022ddfSJerome Glisse /* Somethings want wront with the accel init stop accel */ 4489f022ddfSJerome Glisse dev_err(rdev->dev, "Disabling GPU acceleration\n"); 4499f022ddfSJerome Glisse r100_cp_fini(rdev); 450724c80e1SAlex Deucher radeon_wb_fini(rdev); 4519f022ddfSJerome Glisse r100_ib_fini(rdev); 452655efd3dSJerome Glisse radeon_irq_kms_fini(rdev); 4534aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCIE) 4544aac0473SJerome Glisse rv370_pcie_gart_fini(rdev); 4554aac0473SJerome Glisse if (rdev->flags & RADEON_IS_PCI) 4564aac0473SJerome Glisse r100_pci_gart_fini(rdev); 4579f022ddfSJerome Glisse radeon_agp_fini(rdev); 458733289c2SJerome Glisse rdev->accel_working = false; 4599f022ddfSJerome Glisse } 4609f022ddfSJerome Glisse return 0; 4619f022ddfSJerome Glisse } 462771fe6b9SJerome Glisse 463771fe6b9SJerome Glisse /* 464771fe6b9SJerome Glisse * Debugfs info 465771fe6b9SJerome Glisse */ 466771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 467771fe6b9SJerome Glisse static int r420_debugfs_pipes_info(struct seq_file *m, void *data) 468771fe6b9SJerome Glisse { 469771fe6b9SJerome Glisse struct drm_info_node *node = (struct drm_info_node *) m->private; 470771fe6b9SJerome Glisse struct drm_device *dev = node->minor->dev; 471771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 472771fe6b9SJerome Glisse uint32_t tmp; 473771fe6b9SJerome Glisse 474771fe6b9SJerome Glisse tmp = RREG32(R400_GB_PIPE_SELECT); 475771fe6b9SJerome Glisse seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp); 476771fe6b9SJerome Glisse tmp = RREG32(R300_GB_TILE_CONFIG); 477771fe6b9SJerome Glisse seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp); 478771fe6b9SJerome Glisse tmp = RREG32(R300_DST_PIPE_CONFIG); 479771fe6b9SJerome Glisse seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp); 480771fe6b9SJerome Glisse return 0; 481771fe6b9SJerome Glisse } 482771fe6b9SJerome Glisse 483771fe6b9SJerome Glisse static struct drm_info_list r420_pipes_info_list[] = { 484771fe6b9SJerome Glisse {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL}, 485771fe6b9SJerome Glisse }; 486771fe6b9SJerome Glisse #endif 487771fe6b9SJerome Glisse 488771fe6b9SJerome Glisse int r420_debugfs_pipes_info_init(struct radeon_device *rdev) 489771fe6b9SJerome Glisse { 490771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS) 491771fe6b9SJerome Glisse return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1); 492771fe6b9SJerome Glisse #else 493771fe6b9SJerome Glisse return 0; 494771fe6b9SJerome Glisse #endif 495771fe6b9SJerome Glisse } 496