xref: /linux/drivers/gpu/drm/radeon/r420.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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  */
28c182615fSSam Ravnborg 
2933d5ae6cSJani Nikula #include <linux/debugfs.h>
302ef79416SThomas Zimmermann #include <linux/pci.h>
31771fe6b9SJerome Glisse #include <linux/seq_file.h>
325a0e3ad6STejun Heo #include <linux/slab.h>
33c182615fSSam Ravnborg 
34c182615fSSam Ravnborg #include <drm/drm_device.h>
35c182615fSSam Ravnborg #include <drm/drm_file.h>
36c182615fSSam Ravnborg 
379f022ddfSJerome Glisse #include "atom.h"
3862cdc0c2SCorbin Simpson #include "r100d.h"
39804c7559SAlex Deucher #include "r420_reg_safe.h"
40c182615fSSam Ravnborg #include "r420d.h"
41c182615fSSam Ravnborg #include "radeon.h"
42c182615fSSam Ravnborg #include "radeon_asic.h"
43c182615fSSam Ravnborg #include "radeon_reg.h"
44804c7559SAlex Deucher 
r420_pm_init_profile(struct radeon_device * rdev)45ce8f5370SAlex Deucher void r420_pm_init_profile(struct radeon_device *rdev)
46ce8f5370SAlex Deucher {
47ce8f5370SAlex Deucher 	/* default */
48ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
49ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
50ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
51ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
52ce8f5370SAlex Deucher 	/* low sh */
53ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
54c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
55ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
56ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
57c9e75b21SAlex Deucher 	/* mid sh */
58c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
59c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
60c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
61c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
62ce8f5370SAlex Deucher 	/* high sh */
63ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
64ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
65ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
66ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
67ce8f5370SAlex Deucher 	/* low mh */
68ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
69ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
70ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
71ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
72c9e75b21SAlex Deucher 	/* mid mh */
73c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
74c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
75c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
76c9e75b21SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
77ce8f5370SAlex Deucher 	/* high mh */
78ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
79ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
80ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
81ce8f5370SAlex Deucher 	rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
82ce8f5370SAlex Deucher }
83ce8f5370SAlex Deucher 
r420_set_reg_safe(struct radeon_device * rdev)84804c7559SAlex Deucher static void r420_set_reg_safe(struct radeon_device *rdev)
85804c7559SAlex Deucher {
86804c7559SAlex Deucher 	rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
87804c7559SAlex Deucher 	rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm);
88804c7559SAlex Deucher }
89771fe6b9SJerome Glisse 
r420_pipes_init(struct radeon_device * rdev)90771fe6b9SJerome Glisse void r420_pipes_init(struct radeon_device *rdev)
91771fe6b9SJerome Glisse {
92771fe6b9SJerome Glisse 	unsigned tmp;
93771fe6b9SJerome Glisse 	unsigned gb_pipe_select;
94771fe6b9SJerome Glisse 	unsigned num_pipes;
95771fe6b9SJerome Glisse 
96771fe6b9SJerome Glisse 	/* GA_ENHANCE workaround TCL deadlock issue */
974612dc97SAlex Deucher 	WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
984612dc97SAlex Deucher 	       (1 << 2) | (1 << 3));
9918a4cd2eSDave Airlie 	/* add idle wait as per freedesktop.org bug 24041 */
10018a4cd2eSDave Airlie 	if (r100_gui_wait_for_idle(rdev)) {
1017ca85295SJoe Perches 		pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
10218a4cd2eSDave Airlie 	}
103771fe6b9SJerome Glisse 	/* get max number of pipes */
104d75ee3beSAlex Deucher 	gb_pipe_select = RREG32(R400_GB_PIPE_SELECT);
105771fe6b9SJerome Glisse 	num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
10694f7bf64STormod Volden 
10794f7bf64STormod Volden 	/* SE chips have 1 pipe */
10894f7bf64STormod Volden 	if ((rdev->pdev->device == 0x5e4c) ||
10994f7bf64STormod Volden 	    (rdev->pdev->device == 0x5e4f))
11094f7bf64STormod Volden 		num_pipes = 1;
11194f7bf64STormod Volden 
112771fe6b9SJerome Glisse 	rdev->num_gb_pipes = num_pipes;
113771fe6b9SJerome Glisse 	tmp = 0;
114771fe6b9SJerome Glisse 	switch (num_pipes) {
115771fe6b9SJerome Glisse 	default:
116771fe6b9SJerome Glisse 		/* force to 1 pipe */
117771fe6b9SJerome Glisse 		num_pipes = 1;
118df561f66SGustavo A. R. Silva 		fallthrough;
119771fe6b9SJerome Glisse 	case 1:
120771fe6b9SJerome Glisse 		tmp = (0 << 1);
121771fe6b9SJerome Glisse 		break;
122771fe6b9SJerome Glisse 	case 2:
123771fe6b9SJerome Glisse 		tmp = (3 << 1);
124771fe6b9SJerome Glisse 		break;
125771fe6b9SJerome Glisse 	case 3:
126771fe6b9SJerome Glisse 		tmp = (6 << 1);
127771fe6b9SJerome Glisse 		break;
128771fe6b9SJerome Glisse 	case 4:
129771fe6b9SJerome Glisse 		tmp = (7 << 1);
130771fe6b9SJerome Glisse 		break;
131771fe6b9SJerome Glisse 	}
1324612dc97SAlex Deucher 	WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
133771fe6b9SJerome Glisse 	/* Sub pixel 1/12 so we can have 4K rendering according to doc */
1344612dc97SAlex Deucher 	tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
1354612dc97SAlex Deucher 	WREG32(R300_GB_TILE_CONFIG, tmp);
136771fe6b9SJerome Glisse 	if (r100_gui_wait_for_idle(rdev)) {
1377ca85295SJoe Perches 		pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
138771fe6b9SJerome Glisse 	}
139771fe6b9SJerome Glisse 
1404612dc97SAlex Deucher 	tmp = RREG32(R300_DST_PIPE_CONFIG);
1414612dc97SAlex Deucher 	WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
142771fe6b9SJerome Glisse 
143771fe6b9SJerome Glisse 	WREG32(R300_RB2D_DSTCACHE_MODE,
144771fe6b9SJerome Glisse 	       RREG32(R300_RB2D_DSTCACHE_MODE) |
145771fe6b9SJerome Glisse 	       R300_DC_AUTOFLUSH_ENABLE |
146771fe6b9SJerome Glisse 	       R300_DC_DC_DISABLE_IGNORE_PE);
147771fe6b9SJerome Glisse 
148771fe6b9SJerome Glisse 	if (r100_gui_wait_for_idle(rdev)) {
1497ca85295SJoe Perches 		pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
150771fe6b9SJerome Glisse 	}
151f779b3e5SAlex Deucher 
152f779b3e5SAlex Deucher 	if (rdev->family == CHIP_RV530) {
153f779b3e5SAlex Deucher 		tmp = RREG32(RV530_GB_PIPE_SELECT2);
154f779b3e5SAlex Deucher 		if ((tmp & 3) == 3)
155f779b3e5SAlex Deucher 			rdev->num_z_pipes = 2;
156f779b3e5SAlex Deucher 		else
157f779b3e5SAlex Deucher 			rdev->num_z_pipes = 1;
158f779b3e5SAlex Deucher 	} else
159f779b3e5SAlex Deucher 		rdev->num_z_pipes = 1;
160f779b3e5SAlex Deucher 
161f779b3e5SAlex Deucher 	DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
162f779b3e5SAlex Deucher 		 rdev->num_gb_pipes, rdev->num_z_pipes);
163771fe6b9SJerome Glisse }
164771fe6b9SJerome Glisse 
r420_mc_rreg(struct radeon_device * rdev,u32 reg)1659f022ddfSJerome Glisse u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
166771fe6b9SJerome Glisse {
1670a5b7b0bSAlex Deucher 	unsigned long flags;
1689f022ddfSJerome Glisse 	u32 r;
1699f022ddfSJerome Glisse 
1700a5b7b0bSAlex Deucher 	spin_lock_irqsave(&rdev->mc_idx_lock, flags);
1719f022ddfSJerome Glisse 	WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
1729f022ddfSJerome Glisse 	r = RREG32(R_0001FC_MC_IND_DATA);
1730a5b7b0bSAlex Deucher 	spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
1749f022ddfSJerome Glisse 	return r;
1759f022ddfSJerome Glisse }
1769f022ddfSJerome Glisse 
r420_mc_wreg(struct radeon_device * rdev,u32 reg,u32 v)1779f022ddfSJerome Glisse void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1789f022ddfSJerome Glisse {
1790a5b7b0bSAlex Deucher 	unsigned long flags;
1800a5b7b0bSAlex Deucher 
1810a5b7b0bSAlex Deucher 	spin_lock_irqsave(&rdev->mc_idx_lock, flags);
1829f022ddfSJerome Glisse 	WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
1839f022ddfSJerome Glisse 		S_0001F8_MC_IND_WR_EN(1));
1849f022ddfSJerome Glisse 	WREG32(R_0001FC_MC_IND_DATA, v);
1850a5b7b0bSAlex Deucher 	spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
1869f022ddfSJerome Glisse }
1879f022ddfSJerome Glisse 
r420_debugfs(struct radeon_device * rdev)1889f022ddfSJerome Glisse static void r420_debugfs(struct radeon_device *rdev)
1899f022ddfSJerome Glisse {
1905b54d679SNirmoy Das 	r100_debugfs_rbbm_init(rdev);
1915b54d679SNirmoy Das 	r420_debugfs_pipes_info_init(rdev);
1929f022ddfSJerome Glisse }
1939f022ddfSJerome Glisse 
r420_clock_resume(struct radeon_device * rdev)1949f022ddfSJerome Glisse static void r420_clock_resume(struct radeon_device *rdev)
1959f022ddfSJerome Glisse {
1969f022ddfSJerome Glisse 	u32 sclk_cntl;
197ca6ffc64SJerome Glisse 
198ca6ffc64SJerome Glisse 	if (radeon_dynclks != -1 && radeon_dynclks)
199ca6ffc64SJerome Glisse 		radeon_atom_set_clock_gating(rdev, 1);
2009f022ddfSJerome Glisse 	sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
2019f022ddfSJerome Glisse 	sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
2029f022ddfSJerome Glisse 	if (rdev->family == CHIP_R420)
2039f022ddfSJerome Glisse 		sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
2049f022ddfSJerome Glisse 	WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
2059f022ddfSJerome Glisse }
2069f022ddfSJerome Glisse 
r420_cp_errata_init(struct radeon_device * rdev)20762cdc0c2SCorbin Simpson static void r420_cp_errata_init(struct radeon_device *rdev)
20862cdc0c2SCorbin Simpson {
209c346fb74SPan Bian 	int r;
210e32eb50dSChristian König 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2117b1f2485SChristian König 
21262cdc0c2SCorbin Simpson 	/* RV410 and R420 can lock up if CP DMA to host memory happens
21362cdc0c2SCorbin Simpson 	 * while the 2D engine is busy.
21462cdc0c2SCorbin Simpson 	 *
21562cdc0c2SCorbin Simpson 	 * The proper workaround is to queue a RESYNC at the beginning
21662cdc0c2SCorbin Simpson 	 * of the CP init, apparently.
21762cdc0c2SCorbin Simpson 	 */
21862cdc0c2SCorbin Simpson 	radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
219c346fb74SPan Bian 	r = radeon_ring_lock(rdev, ring, 8);
220c346fb74SPan Bian 	WARN_ON(r);
221e32eb50dSChristian König 	radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1));
222e32eb50dSChristian König 	radeon_ring_write(ring, rdev->config.r300.resync_scratch);
223e32eb50dSChristian König 	radeon_ring_write(ring, 0xDEADBEEF);
2241538a9e0SMichel Dänzer 	radeon_ring_unlock_commit(rdev, ring, false);
22562cdc0c2SCorbin Simpson }
22662cdc0c2SCorbin Simpson 
r420_cp_errata_fini(struct radeon_device * rdev)22762cdc0c2SCorbin Simpson static void r420_cp_errata_fini(struct radeon_device *rdev)
22862cdc0c2SCorbin Simpson {
229c346fb74SPan Bian 	int r;
230e32eb50dSChristian König 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2317b1f2485SChristian König 
23262cdc0c2SCorbin Simpson 	/* Catch the RESYNC we dispatched all the way back,
23362cdc0c2SCorbin Simpson 	 * at the very beginning of the CP init.
23462cdc0c2SCorbin Simpson 	 */
235c346fb74SPan Bian 	r = radeon_ring_lock(rdev, ring, 8);
236c346fb74SPan Bian 	WARN_ON(r);
237e32eb50dSChristian König 	radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
238e32eb50dSChristian König 	radeon_ring_write(ring, R300_RB3D_DC_FINISH);
2391538a9e0SMichel Dänzer 	radeon_ring_unlock_commit(rdev, ring, false);
24062cdc0c2SCorbin Simpson 	radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
24162cdc0c2SCorbin Simpson }
24262cdc0c2SCorbin Simpson 
r420_startup(struct radeon_device * rdev)243fc30b8efSDave Airlie static int r420_startup(struct radeon_device *rdev)
2449f022ddfSJerome Glisse {
2459f022ddfSJerome Glisse 	int r;
2469f022ddfSJerome Glisse 
24792cde00cSAlex Deucher 	/* set common regs */
24892cde00cSAlex Deucher 	r100_set_common_regs(rdev);
24992cde00cSAlex Deucher 	/* program mc */
2509f022ddfSJerome Glisse 	r300_mc_program(rdev);
251ca6ffc64SJerome Glisse 	/* Resume clock */
252ca6ffc64SJerome Glisse 	r420_clock_resume(rdev);
2539f022ddfSJerome Glisse 	/* Initialize GART (initialize after TTM so we can allocate
2549f022ddfSJerome Glisse 	 * memory through TTM but finalize after TTM) */
2554aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCIE) {
2564aac0473SJerome Glisse 		r = rv370_pcie_gart_enable(rdev);
2574aac0473SJerome Glisse 		if (r)
2584aac0473SJerome Glisse 			return r;
2594aac0473SJerome Glisse 	}
2604aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCI) {
2614aac0473SJerome Glisse 		r = r100_pci_gart_enable(rdev);
2624aac0473SJerome Glisse 		if (r)
2639f022ddfSJerome Glisse 			return r;
2649f022ddfSJerome Glisse 	}
265771fe6b9SJerome Glisse 	r420_pipes_init(rdev);
266724c80e1SAlex Deucher 
267724c80e1SAlex Deucher 	/* allocate wb buffer */
268724c80e1SAlex Deucher 	r = radeon_wb_init(rdev);
269724c80e1SAlex Deucher 	if (r)
270724c80e1SAlex Deucher 		return r;
271724c80e1SAlex Deucher 
27230eb77f4SJerome Glisse 	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
27330eb77f4SJerome Glisse 	if (r) {
27430eb77f4SJerome Glisse 		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
27530eb77f4SJerome Glisse 		return r;
27630eb77f4SJerome Glisse 	}
27730eb77f4SJerome Glisse 
2789f022ddfSJerome Glisse 	/* Enable IRQ */
279e49f3959SAdis Hamzić 	if (!rdev->irq.installed) {
280e49f3959SAdis Hamzić 		r = radeon_irq_kms_init(rdev);
281e49f3959SAdis Hamzić 		if (r)
282e49f3959SAdis Hamzić 			return r;
283e49f3959SAdis Hamzić 	}
284e49f3959SAdis Hamzić 
2859f022ddfSJerome Glisse 	r100_irq_set(rdev);
286cafe6609SJerome Glisse 	rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
2879f022ddfSJerome Glisse 	/* 1M ring buffer */
2889f022ddfSJerome Glisse 	r = r100_cp_init(rdev, 1024 * 1024);
2899f022ddfSJerome Glisse 	if (r) {
290ec4f2ac4SPaul Bolle 		dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
2919f022ddfSJerome Glisse 		return r;
292771fe6b9SJerome Glisse 	}
29362cdc0c2SCorbin Simpson 	r420_cp_errata_init(rdev);
294b15ba512SJerome Glisse 
2952898c348SChristian König 	r = radeon_ib_pool_init(rdev);
2962898c348SChristian König 	if (r) {
2972898c348SChristian König 		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
298b15ba512SJerome Glisse 		return r;
2992898c348SChristian König 	}
300b15ba512SJerome Glisse 
3019f022ddfSJerome Glisse 	return 0;
302771fe6b9SJerome Glisse }
303771fe6b9SJerome Glisse 
r420_resume(struct radeon_device * rdev)304fc30b8efSDave Airlie int r420_resume(struct radeon_device *rdev)
305fc30b8efSDave Airlie {
3066b7746e8SJerome Glisse 	int r;
3076b7746e8SJerome Glisse 
308fc30b8efSDave Airlie 	/* Make sur GART are not working */
309fc30b8efSDave Airlie 	if (rdev->flags & RADEON_IS_PCIE)
310fc30b8efSDave Airlie 		rv370_pcie_gart_disable(rdev);
311fc30b8efSDave Airlie 	if (rdev->flags & RADEON_IS_PCI)
312fc30b8efSDave Airlie 		r100_pci_gart_disable(rdev);
313fc30b8efSDave Airlie 	/* Resume clock before doing reset */
314fc30b8efSDave Airlie 	r420_clock_resume(rdev);
315fc30b8efSDave Airlie 	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
316a2d07b74SJerome Glisse 	if (radeon_asic_reset(rdev)) {
317fc30b8efSDave Airlie 		dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
318fc30b8efSDave Airlie 			RREG32(R_000E40_RBBM_STATUS),
319fc30b8efSDave Airlie 			RREG32(R_0007C0_CP_STAT));
320fc30b8efSDave Airlie 	}
321fc30b8efSDave Airlie 	/* check if cards are posted or not */
322fc30b8efSDave Airlie 	if (rdev->is_atom_bios) {
323fc30b8efSDave Airlie 		atom_asic_init(rdev->mode_info.atom_context);
324fc30b8efSDave Airlie 	} else {
325*fb1b5e1dSWu Hoi Pok 		radeon_combios_asic_init(rdev_to_drm(rdev));
326fc30b8efSDave Airlie 	}
327fc30b8efSDave Airlie 	/* Resume clock after posting */
328fc30b8efSDave Airlie 	r420_clock_resume(rdev);
329550e2d92SDave Airlie 	/* Initialize surface registers */
330550e2d92SDave Airlie 	radeon_surface_init(rdev);
331b15ba512SJerome Glisse 
332b15ba512SJerome Glisse 	rdev->accel_working = true;
3336b7746e8SJerome Glisse 	r = r420_startup(rdev);
3346b7746e8SJerome Glisse 	if (r) {
3356b7746e8SJerome Glisse 		rdev->accel_working = false;
3366b7746e8SJerome Glisse 	}
3376b7746e8SJerome Glisse 	return r;
338fc30b8efSDave Airlie }
339fc30b8efSDave Airlie 
r420_suspend(struct radeon_device * rdev)3409f022ddfSJerome Glisse int r420_suspend(struct radeon_device *rdev)
341771fe6b9SJerome Glisse {
3426c7bcceaSAlex Deucher 	radeon_pm_suspend(rdev);
34362cdc0c2SCorbin Simpson 	r420_cp_errata_fini(rdev);
3449f022ddfSJerome Glisse 	r100_cp_disable(rdev);
345724c80e1SAlex Deucher 	radeon_wb_disable(rdev);
3469f022ddfSJerome Glisse 	r100_irq_disable(rdev);
3474aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCIE)
3484aac0473SJerome Glisse 		rv370_pcie_gart_disable(rdev);
3494aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCI)
3504aac0473SJerome Glisse 		r100_pci_gart_disable(rdev);
3519f022ddfSJerome Glisse 	return 0;
352771fe6b9SJerome Glisse }
353771fe6b9SJerome Glisse 
r420_fini(struct radeon_device * rdev)3549f022ddfSJerome Glisse void r420_fini(struct radeon_device *rdev)
3559f022ddfSJerome Glisse {
3566c7bcceaSAlex Deucher 	radeon_pm_fini(rdev);
3579f022ddfSJerome Glisse 	r100_cp_fini(rdev);
358724c80e1SAlex Deucher 	radeon_wb_fini(rdev);
3592898c348SChristian König 	radeon_ib_pool_fini(rdev);
3609f022ddfSJerome Glisse 	radeon_gem_fini(rdev);
3614aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCIE)
3624aac0473SJerome Glisse 		rv370_pcie_gart_fini(rdev);
3634aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCI)
3644aac0473SJerome Glisse 		r100_pci_gart_fini(rdev);
3659f022ddfSJerome Glisse 	radeon_agp_fini(rdev);
3669f022ddfSJerome Glisse 	radeon_irq_kms_fini(rdev);
3679f022ddfSJerome Glisse 	radeon_fence_driver_fini(rdev);
3684c788679SJerome Glisse 	radeon_bo_fini(rdev);
3699f022ddfSJerome Glisse 	if (rdev->is_atom_bios) {
3709f022ddfSJerome Glisse 		radeon_atombios_fini(rdev);
3719f022ddfSJerome Glisse 	} else {
3729f022ddfSJerome Glisse 		radeon_combios_fini(rdev);
3739f022ddfSJerome Glisse 	}
3749f022ddfSJerome Glisse 	kfree(rdev->bios);
3759f022ddfSJerome Glisse 	rdev->bios = NULL;
3769f022ddfSJerome Glisse }
3779f022ddfSJerome Glisse 
r420_init(struct radeon_device * rdev)3789f022ddfSJerome Glisse int r420_init(struct radeon_device *rdev)
3799f022ddfSJerome Glisse {
3809f022ddfSJerome Glisse 	int r;
3819f022ddfSJerome Glisse 
3829f022ddfSJerome Glisse 	/* Initialize scratch registers */
3839f022ddfSJerome Glisse 	radeon_scratch_init(rdev);
3849f022ddfSJerome Glisse 	/* Initialize surface registers */
3859f022ddfSJerome Glisse 	radeon_surface_init(rdev);
3869f022ddfSJerome Glisse 	/* TODO: disable VGA need to use VGA request */
3874c712e6cSDave Airlie 	/* restore some register to sane defaults */
3884c712e6cSDave Airlie 	r100_restore_sanity(rdev);
3899f022ddfSJerome Glisse 	/* BIOS*/
3909f022ddfSJerome Glisse 	if (!radeon_get_bios(rdev)) {
3919f022ddfSJerome Glisse 		if (ASIC_IS_AVIVO(rdev))
3929f022ddfSJerome Glisse 			return -EINVAL;
3939f022ddfSJerome Glisse 	}
3949f022ddfSJerome Glisse 	if (rdev->is_atom_bios) {
3959f022ddfSJerome Glisse 		r = radeon_atombios_init(rdev);
3969f022ddfSJerome Glisse 		if (r) {
3979f022ddfSJerome Glisse 			return r;
3989f022ddfSJerome Glisse 		}
3999f022ddfSJerome Glisse 	} else {
4009f022ddfSJerome Glisse 		r = radeon_combios_init(rdev);
4019f022ddfSJerome Glisse 		if (r) {
4029f022ddfSJerome Glisse 			return r;
4039f022ddfSJerome Glisse 		}
4049f022ddfSJerome Glisse 	}
4059f022ddfSJerome Glisse 	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
406a2d07b74SJerome Glisse 	if (radeon_asic_reset(rdev)) {
4079f022ddfSJerome Glisse 		dev_warn(rdev->dev,
4089f022ddfSJerome Glisse 			"GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
4099f022ddfSJerome Glisse 			RREG32(R_000E40_RBBM_STATUS),
4109f022ddfSJerome Glisse 			RREG32(R_0007C0_CP_STAT));
4119f022ddfSJerome Glisse 	}
4129f022ddfSJerome Glisse 	/* check if cards are posted or not */
41372542d77SDave Airlie 	if (radeon_boot_test_post_card(rdev) == false)
41472542d77SDave Airlie 		return -EINVAL;
41572542d77SDave Airlie 
4169f022ddfSJerome Glisse 	/* Initialize clocks */
417*fb1b5e1dSWu Hoi Pok 	radeon_get_clock_info(rdev_to_drm(rdev));
418d594e46aSJerome Glisse 	/* initialize AGP */
419d594e46aSJerome Glisse 	if (rdev->flags & RADEON_IS_AGP) {
420d594e46aSJerome Glisse 		r = radeon_agp_init(rdev);
4219f022ddfSJerome Glisse 		if (r) {
422d594e46aSJerome Glisse 			radeon_agp_disable(rdev);
4239f022ddfSJerome Glisse 		}
424d594e46aSJerome Glisse 	}
425d594e46aSJerome Glisse 	/* initialize memory controller */
426d594e46aSJerome Glisse 	r300_mc_init(rdev);
4279f022ddfSJerome Glisse 	r420_debugfs(rdev);
4289f022ddfSJerome Glisse 	/* Fence driver */
429519424d7SBernard Zhao 	radeon_fence_driver_init(rdev);
4309f022ddfSJerome Glisse 	/* Memory manager */
4314c788679SJerome Glisse 	r = radeon_bo_init(rdev);
4329f022ddfSJerome Glisse 	if (r) {
4339f022ddfSJerome Glisse 		return r;
4349f022ddfSJerome Glisse 	}
43517e15b0cSDave Airlie 	if (rdev->family == CHIP_R420)
43617e15b0cSDave Airlie 		r100_enable_bm(rdev);
43717e15b0cSDave Airlie 
4384aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCIE) {
4394aac0473SJerome Glisse 		r = rv370_pcie_gart_init(rdev);
4404aac0473SJerome Glisse 		if (r)
4414aac0473SJerome Glisse 			return r;
4424aac0473SJerome Glisse 	}
4434aac0473SJerome Glisse 	if (rdev->flags & RADEON_IS_PCI) {
4444aac0473SJerome Glisse 		r = r100_pci_gart_init(rdev);
4454aac0473SJerome Glisse 		if (r)
4464aac0473SJerome Glisse 			return r;
4474aac0473SJerome Glisse 	}
448804c7559SAlex Deucher 	r420_set_reg_safe(rdev);
449b15ba512SJerome Glisse 
4506c7bcceaSAlex Deucher 	/* Initialize power management */
4516c7bcceaSAlex Deucher 	radeon_pm_init(rdev);
4526c7bcceaSAlex Deucher 
453733289c2SJerome Glisse 	rdev->accel_working = true;
454fc30b8efSDave Airlie 	r = r420_startup(rdev);
4559f022ddfSJerome Glisse 	if (r) {
4569f022ddfSJerome Glisse 		/* Somethings want wront with the accel init stop accel */
4579f022ddfSJerome Glisse 		dev_err(rdev->dev, "Disabling GPU acceleration\n");
4589f022ddfSJerome Glisse 		r100_cp_fini(rdev);
459724c80e1SAlex Deucher 		radeon_wb_fini(rdev);
4602898c348SChristian König 		radeon_ib_pool_fini(rdev);
461655efd3dSJerome Glisse 		radeon_irq_kms_fini(rdev);
4624aac0473SJerome Glisse 		if (rdev->flags & RADEON_IS_PCIE)
4634aac0473SJerome Glisse 			rv370_pcie_gart_fini(rdev);
4644aac0473SJerome Glisse 		if (rdev->flags & RADEON_IS_PCI)
4654aac0473SJerome Glisse 			r100_pci_gart_fini(rdev);
4669f022ddfSJerome Glisse 		radeon_agp_fini(rdev);
467733289c2SJerome Glisse 		rdev->accel_working = false;
4689f022ddfSJerome Glisse 	}
4699f022ddfSJerome Glisse 	return 0;
4709f022ddfSJerome Glisse }
471771fe6b9SJerome Glisse 
472771fe6b9SJerome Glisse /*
473771fe6b9SJerome Glisse  * Debugfs info
474771fe6b9SJerome Glisse  */
475771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS)
r420_debugfs_pipes_info_show(struct seq_file * m,void * unused)4765b54d679SNirmoy Das static int r420_debugfs_pipes_info_show(struct seq_file *m, void *unused)
477771fe6b9SJerome Glisse {
4786091ede9SSu Hui 	struct radeon_device *rdev = m->private;
479771fe6b9SJerome Glisse 	uint32_t tmp;
480771fe6b9SJerome Glisse 
481771fe6b9SJerome Glisse 	tmp = RREG32(R400_GB_PIPE_SELECT);
482771fe6b9SJerome Glisse 	seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
483771fe6b9SJerome Glisse 	tmp = RREG32(R300_GB_TILE_CONFIG);
484771fe6b9SJerome Glisse 	seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
485771fe6b9SJerome Glisse 	tmp = RREG32(R300_DST_PIPE_CONFIG);
486771fe6b9SJerome Glisse 	seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
487771fe6b9SJerome Glisse 	return 0;
488771fe6b9SJerome Glisse }
489771fe6b9SJerome Glisse 
4905b54d679SNirmoy Das DEFINE_SHOW_ATTRIBUTE(r420_debugfs_pipes_info);
491771fe6b9SJerome Glisse #endif
492771fe6b9SJerome Glisse 
r420_debugfs_pipes_info_init(struct radeon_device * rdev)4935b54d679SNirmoy Das void r420_debugfs_pipes_info_init(struct radeon_device *rdev)
494771fe6b9SJerome Glisse {
495771fe6b9SJerome Glisse #if defined(CONFIG_DEBUG_FS)
496*fb1b5e1dSWu Hoi Pok 	struct dentry *root = rdev_to_drm(rdev)->primary->debugfs_root;
4975b54d679SNirmoy Das 
4985b54d679SNirmoy Das 	debugfs_create_file("r420_pipes_info", 0444, root, rdev,
4995b54d679SNirmoy Das 			    &r420_debugfs_pipes_info_fops);
500771fe6b9SJerome Glisse #endif
501771fe6b9SJerome Glisse }
502