xref: /dflybsd-src/sys/dev/drm/radeon/rs690.c (revision a85cb24f18e3804e75ab8bcda7692564d0563317)
1926deccbSFrançois Tigeot /*
2926deccbSFrançois Tigeot  * Copyright 2008 Advanced Micro Devices, Inc.
3926deccbSFrançois Tigeot  * Copyright 2008 Red Hat Inc.
4926deccbSFrançois Tigeot  * Copyright 2009 Jerome Glisse.
5926deccbSFrançois Tigeot  *
6926deccbSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
7926deccbSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
8926deccbSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
9926deccbSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10926deccbSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
11926deccbSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
12926deccbSFrançois Tigeot  *
13926deccbSFrançois Tigeot  * The above copyright notice and this permission notice shall be included in
14926deccbSFrançois Tigeot  * all copies or substantial portions of the Software.
15926deccbSFrançois Tigeot  *
16926deccbSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17926deccbSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18926deccbSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19926deccbSFrançois Tigeot  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20926deccbSFrançois Tigeot  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21926deccbSFrançois Tigeot  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22926deccbSFrançois Tigeot  * OTHER DEALINGS IN THE SOFTWARE.
23926deccbSFrançois Tigeot  *
24926deccbSFrançois Tigeot  * Authors: Dave Airlie
25926deccbSFrançois Tigeot  *          Alex Deucher
26926deccbSFrançois Tigeot  *          Jerome Glisse
27926deccbSFrançois Tigeot  */
28926deccbSFrançois Tigeot #include <drm/drmP.h>
29926deccbSFrançois Tigeot #include "radeon.h"
30926deccbSFrançois Tigeot #include "radeon_asic.h"
31c59a5c48SFrançois Tigeot #include "radeon_audio.h"
32926deccbSFrançois Tigeot #include "atom.h"
33926deccbSFrançois Tigeot #include "rs690d.h"
34926deccbSFrançois Tigeot 
rs690_mc_wait_for_idle(struct radeon_device * rdev)35926deccbSFrançois Tigeot int rs690_mc_wait_for_idle(struct radeon_device *rdev)
36926deccbSFrançois Tigeot {
37926deccbSFrançois Tigeot 	unsigned i;
38926deccbSFrançois Tigeot 	uint32_t tmp;
39926deccbSFrançois Tigeot 
40926deccbSFrançois Tigeot 	for (i = 0; i < rdev->usec_timeout; i++) {
41926deccbSFrançois Tigeot 		/* read MC_STATUS */
42926deccbSFrançois Tigeot 		tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
43926deccbSFrançois Tigeot 		if (G_000090_MC_SYSTEM_IDLE(tmp))
44926deccbSFrançois Tigeot 			return 0;
45c4ef309bSzrj 		udelay(1);
46926deccbSFrançois Tigeot 	}
47926deccbSFrançois Tigeot 	return -1;
48926deccbSFrançois Tigeot }
49926deccbSFrançois Tigeot 
rs690_gpu_init(struct radeon_device * rdev)50926deccbSFrançois Tigeot static void rs690_gpu_init(struct radeon_device *rdev)
51926deccbSFrançois Tigeot {
52926deccbSFrançois Tigeot 	/* FIXME: is this correct ? */
53926deccbSFrançois Tigeot 	r420_pipes_init(rdev);
54926deccbSFrançois Tigeot 	if (rs690_mc_wait_for_idle(rdev)) {
55*a85cb24fSFrançois Tigeot 		pr_warn("Failed to wait MC idle while programming pipes. Bad things might happen.\n");
56926deccbSFrançois Tigeot 	}
57926deccbSFrançois Tigeot }
58926deccbSFrançois Tigeot 
59926deccbSFrançois Tigeot union igp_info {
60926deccbSFrançois Tigeot 	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
61926deccbSFrançois Tigeot 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
62926deccbSFrançois Tigeot };
63926deccbSFrançois Tigeot 
rs690_pm_info(struct radeon_device * rdev)64926deccbSFrançois Tigeot void rs690_pm_info(struct radeon_device *rdev)
65926deccbSFrançois Tigeot {
66926deccbSFrançois Tigeot 	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
67926deccbSFrançois Tigeot 	union igp_info *info;
68926deccbSFrançois Tigeot 	uint16_t data_offset;
69926deccbSFrançois Tigeot 	uint8_t frev, crev;
70926deccbSFrançois Tigeot 	fixed20_12 tmp;
71926deccbSFrançois Tigeot 
72926deccbSFrançois Tigeot 	if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
73926deccbSFrançois Tigeot 				   &frev, &crev, &data_offset)) {
74926deccbSFrançois Tigeot 		info = (union igp_info *)((uintptr_t)rdev->mode_info.atom_context->bios + data_offset);
75926deccbSFrançois Tigeot 
76926deccbSFrançois Tigeot 		/* Get various system informations from bios */
77926deccbSFrançois Tigeot 		switch (crev) {
78926deccbSFrançois Tigeot 		case 1:
79926deccbSFrançois Tigeot 			tmp.full = dfixed_const(100);
80926deccbSFrançois Tigeot 			rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info.ulBootUpMemoryClock));
81926deccbSFrançois Tigeot 			rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
82926deccbSFrançois Tigeot 			if (le16_to_cpu(info->info.usK8MemoryClock))
83926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
84926deccbSFrançois Tigeot 			else if (rdev->clock.default_mclk) {
85926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
86926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
87926deccbSFrançois Tigeot 			} else
88926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(400);
89926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_clk.full = dfixed_const(le16_to_cpu(info->info.usFSBClock));
90926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_width.full = dfixed_const(info->info.ucHTLinkWidth);
91926deccbSFrançois Tigeot 			break;
92926deccbSFrançois Tigeot 		case 2:
93926deccbSFrançois Tigeot 			tmp.full = dfixed_const(100);
94926deccbSFrançois Tigeot 			rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpSidePortClock));
95926deccbSFrançois Tigeot 			rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
96926deccbSFrançois Tigeot 			if (le32_to_cpu(info->info_v2.ulBootUpUMAClock))
97926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpUMAClock));
98926deccbSFrançois Tigeot 			else if (rdev->clock.default_mclk)
99926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
100926deccbSFrançois Tigeot 			else
101926deccbSFrançois Tigeot 				rdev->pm.igp_system_mclk.full = dfixed_const(66700);
102926deccbSFrançois Tigeot 			rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
103926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_clk.full = dfixed_const(le32_to_cpu(info->info_v2.ulHTLinkFreq));
104926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_clk.full = dfixed_div(rdev->pm.igp_ht_link_clk, tmp);
105926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_width.full = dfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
106926deccbSFrançois Tigeot 			break;
107926deccbSFrançois Tigeot 		default:
108926deccbSFrançois Tigeot 			/* We assume the slower possible clock ie worst case */
109926deccbSFrançois Tigeot 			rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
110926deccbSFrançois Tigeot 			rdev->pm.igp_system_mclk.full = dfixed_const(200);
111926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
112926deccbSFrançois Tigeot 			rdev->pm.igp_ht_link_width.full = dfixed_const(8);
113926deccbSFrançois Tigeot 			DRM_ERROR("No integrated system info for your GPU, using safe default\n");
114926deccbSFrançois Tigeot 			break;
115926deccbSFrançois Tigeot 		}
116926deccbSFrançois Tigeot 	} else {
117926deccbSFrançois Tigeot 		/* We assume the slower possible clock ie worst case */
118926deccbSFrançois Tigeot 		rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
119926deccbSFrançois Tigeot 		rdev->pm.igp_system_mclk.full = dfixed_const(200);
120926deccbSFrançois Tigeot 		rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
121926deccbSFrançois Tigeot 		rdev->pm.igp_ht_link_width.full = dfixed_const(8);
122926deccbSFrançois Tigeot 		DRM_ERROR("No integrated system info for your GPU, using safe default\n");
123926deccbSFrançois Tigeot 	}
124926deccbSFrançois Tigeot 	/* Compute various bandwidth */
125926deccbSFrançois Tigeot 	/* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4  */
126926deccbSFrançois Tigeot 	tmp.full = dfixed_const(4);
127926deccbSFrançois Tigeot 	rdev->pm.k8_bandwidth.full = dfixed_mul(rdev->pm.igp_system_mclk, tmp);
128926deccbSFrançois Tigeot 	/* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
129926deccbSFrançois Tigeot 	 *              = ht_clk * ht_width / 5
130926deccbSFrançois Tigeot 	 */
131926deccbSFrançois Tigeot 	tmp.full = dfixed_const(5);
132926deccbSFrançois Tigeot 	rdev->pm.ht_bandwidth.full = dfixed_mul(rdev->pm.igp_ht_link_clk,
133926deccbSFrançois Tigeot 						rdev->pm.igp_ht_link_width);
134926deccbSFrançois Tigeot 	rdev->pm.ht_bandwidth.full = dfixed_div(rdev->pm.ht_bandwidth, tmp);
135926deccbSFrançois Tigeot 	if (tmp.full < rdev->pm.max_bandwidth.full) {
136926deccbSFrançois Tigeot 		/* HT link is a limiting factor */
137926deccbSFrançois Tigeot 		rdev->pm.max_bandwidth.full = tmp.full;
138926deccbSFrançois Tigeot 	}
139926deccbSFrançois Tigeot 	/* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
140926deccbSFrançois Tigeot 	 *                    = (sideport_clk * 14) / 10
141926deccbSFrançois Tigeot 	 */
142926deccbSFrançois Tigeot 	tmp.full = dfixed_const(14);
143926deccbSFrançois Tigeot 	rdev->pm.sideport_bandwidth.full = dfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
144926deccbSFrançois Tigeot 	tmp.full = dfixed_const(10);
145926deccbSFrançois Tigeot 	rdev->pm.sideport_bandwidth.full = dfixed_div(rdev->pm.sideport_bandwidth, tmp);
146926deccbSFrançois Tigeot }
147926deccbSFrançois Tigeot 
rs690_mc_init(struct radeon_device * rdev)148926deccbSFrançois Tigeot static void rs690_mc_init(struct radeon_device *rdev)
149926deccbSFrançois Tigeot {
150926deccbSFrançois Tigeot 	u64 base;
151f43cf1b1SMichael Neumann 	uint32_t h_addr, l_addr;
152f43cf1b1SMichael Neumann 	unsigned long long k8_addr;
153926deccbSFrançois Tigeot 
154926deccbSFrançois Tigeot 	rs400_gart_adjust_size(rdev);
155926deccbSFrançois Tigeot 	rdev->mc.vram_is_ddr = true;
156926deccbSFrançois Tigeot 	rdev->mc.vram_width = 128;
157926deccbSFrançois Tigeot 	rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
158926deccbSFrançois Tigeot 	rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
1594a26d795SImre Vadasz 	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1604a26d795SImre Vadasz 	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
161926deccbSFrançois Tigeot 	rdev->mc.visible_vram_size = rdev->mc.aper_size;
162926deccbSFrançois Tigeot 	base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
163926deccbSFrançois Tigeot 	base = G_000100_MC_FB_START(base) << 16;
164926deccbSFrançois Tigeot 	rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
165c6f73aabSFrançois Tigeot 	/* Some boards seem to be configured for 128MB of sideport memory,
166c6f73aabSFrançois Tigeot 	 * but really only have 64MB.  Just skip the sideport and use
167c6f73aabSFrançois Tigeot 	 * UMA memory.
168c6f73aabSFrançois Tigeot 	 */
169c6f73aabSFrançois Tigeot 	if (rdev->mc.igp_sideport_enabled &&
170c6f73aabSFrançois Tigeot 	    (rdev->mc.real_vram_size == (384 * 1024 * 1024))) {
171c6f73aabSFrançois Tigeot 		base += 128 * 1024 * 1024;
172c6f73aabSFrançois Tigeot 		rdev->mc.real_vram_size -= 128 * 1024 * 1024;
173c6f73aabSFrançois Tigeot 		rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
174c6f73aabSFrançois Tigeot 	}
175f43cf1b1SMichael Neumann 
176f43cf1b1SMichael Neumann 	/* Use K8 direct mapping for fast fb access. */
177f43cf1b1SMichael Neumann 	rdev->fastfb_working = false;
178f43cf1b1SMichael Neumann 	h_addr = G_00005F_K8_ADDR_EXT(RREG32_MC(R_00005F_MC_MISC_UMA_CNTL));
179f43cf1b1SMichael Neumann 	l_addr = RREG32_MC(R_00001E_K8_FB_LOCATION);
180f43cf1b1SMichael Neumann 	k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
181f43cf1b1SMichael Neumann #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
182f43cf1b1SMichael Neumann 	if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
183f43cf1b1SMichael Neumann #endif
184f43cf1b1SMichael Neumann 	{
185f43cf1b1SMichael Neumann 		/* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
186f43cf1b1SMichael Neumann 		 * memory is present.
187f43cf1b1SMichael Neumann 		 */
188f43cf1b1SMichael Neumann 		if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
189f43cf1b1SMichael Neumann 			DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
190f43cf1b1SMichael Neumann 					(unsigned long long)rdev->mc.aper_base, k8_addr);
191f43cf1b1SMichael Neumann 			rdev->mc.aper_base = (resource_size_t)k8_addr;
192f43cf1b1SMichael Neumann 			rdev->fastfb_working = true;
193f43cf1b1SMichael Neumann 		}
194f43cf1b1SMichael Neumann 	}
195f43cf1b1SMichael Neumann 
196926deccbSFrançois Tigeot 	rs690_pm_info(rdev);
197926deccbSFrançois Tigeot 	radeon_vram_location(rdev, &rdev->mc, base);
198926deccbSFrançois Tigeot 	rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
199926deccbSFrançois Tigeot 	radeon_gtt_location(rdev, &rdev->mc);
200926deccbSFrançois Tigeot 	radeon_update_bandwidth_info(rdev);
201926deccbSFrançois Tigeot }
202926deccbSFrançois Tigeot 
rs690_line_buffer_adjust(struct radeon_device * rdev,struct drm_display_mode * mode1,struct drm_display_mode * mode2)203926deccbSFrançois Tigeot void rs690_line_buffer_adjust(struct radeon_device *rdev,
204926deccbSFrançois Tigeot 			      struct drm_display_mode *mode1,
205926deccbSFrançois Tigeot 			      struct drm_display_mode *mode2)
206926deccbSFrançois Tigeot {
207926deccbSFrançois Tigeot 	u32 tmp;
208926deccbSFrançois Tigeot 
209c59a5c48SFrançois Tigeot 	/* Guess line buffer size to be 8192 pixels */
210c59a5c48SFrançois Tigeot 	u32 lb_size = 8192;
211c59a5c48SFrançois Tigeot 
212926deccbSFrançois Tigeot 	/*
213926deccbSFrançois Tigeot 	 * Line Buffer Setup
214926deccbSFrançois Tigeot 	 * There is a single line buffer shared by both display controllers.
215926deccbSFrançois Tigeot 	 * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
216926deccbSFrançois Tigeot 	 * the display controllers.  The paritioning can either be done
217926deccbSFrançois Tigeot 	 * manually or via one of four preset allocations specified in bits 1:0:
218926deccbSFrançois Tigeot 	 *  0 - line buffer is divided in half and shared between crtc
219926deccbSFrançois Tigeot 	 *  1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
220926deccbSFrançois Tigeot 	 *  2 - D1 gets the whole buffer
221926deccbSFrançois Tigeot 	 *  3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
222926deccbSFrançois Tigeot 	 * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
223926deccbSFrançois Tigeot 	 * allocation mode. In manual allocation mode, D1 always starts at 0,
224926deccbSFrançois Tigeot 	 * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
225926deccbSFrançois Tigeot 	 */
226926deccbSFrançois Tigeot 	tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
227926deccbSFrançois Tigeot 	tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
228926deccbSFrançois Tigeot 	/* auto */
229926deccbSFrançois Tigeot 	if (mode1 && mode2) {
230926deccbSFrançois Tigeot 		if (mode1->hdisplay > mode2->hdisplay) {
231926deccbSFrançois Tigeot 			if (mode1->hdisplay > 2560)
232926deccbSFrançois Tigeot 				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
233926deccbSFrançois Tigeot 			else
234926deccbSFrançois Tigeot 				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
235926deccbSFrançois Tigeot 		} else if (mode2->hdisplay > mode1->hdisplay) {
236926deccbSFrançois Tigeot 			if (mode2->hdisplay > 2560)
237926deccbSFrançois Tigeot 				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
238926deccbSFrançois Tigeot 			else
239926deccbSFrançois Tigeot 				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
240926deccbSFrançois Tigeot 		} else
241926deccbSFrançois Tigeot 			tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
242926deccbSFrançois Tigeot 	} else if (mode1) {
243926deccbSFrançois Tigeot 		tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
244926deccbSFrançois Tigeot 	} else if (mode2) {
245926deccbSFrançois Tigeot 		tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
246926deccbSFrançois Tigeot 	}
247926deccbSFrançois Tigeot 	WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
248c59a5c48SFrançois Tigeot 
249c59a5c48SFrançois Tigeot 	/* Save number of lines the linebuffer leads before the scanout */
250c59a5c48SFrançois Tigeot 	if (mode1)
251c59a5c48SFrançois Tigeot 		rdev->mode_info.crtcs[0]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode1->crtc_hdisplay);
252c59a5c48SFrançois Tigeot 
253c59a5c48SFrançois Tigeot 	if (mode2)
254c59a5c48SFrançois Tigeot 		rdev->mode_info.crtcs[1]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode2->crtc_hdisplay);
255926deccbSFrançois Tigeot }
256926deccbSFrançois Tigeot 
257926deccbSFrançois Tigeot struct rs690_watermark {
258926deccbSFrançois Tigeot 	u32        lb_request_fifo_depth;
259926deccbSFrançois Tigeot 	fixed20_12 num_line_pair;
260926deccbSFrançois Tigeot 	fixed20_12 estimated_width;
261926deccbSFrançois Tigeot 	fixed20_12 worst_case_latency;
262926deccbSFrançois Tigeot 	fixed20_12 consumption_rate;
263926deccbSFrançois Tigeot 	fixed20_12 active_time;
264926deccbSFrançois Tigeot 	fixed20_12 dbpp;
265926deccbSFrançois Tigeot 	fixed20_12 priority_mark_max;
266926deccbSFrançois Tigeot 	fixed20_12 priority_mark;
267926deccbSFrançois Tigeot 	fixed20_12 sclk;
268926deccbSFrançois Tigeot };
269926deccbSFrançois Tigeot 
rs690_crtc_bandwidth_compute(struct radeon_device * rdev,struct radeon_crtc * crtc,struct rs690_watermark * wm,bool low)270926deccbSFrançois Tigeot static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
271926deccbSFrançois Tigeot 					 struct radeon_crtc *crtc,
27257e252bfSMichael Neumann 					 struct rs690_watermark *wm,
27357e252bfSMichael Neumann 					 bool low)
274926deccbSFrançois Tigeot {
275926deccbSFrançois Tigeot 	struct drm_display_mode *mode = &crtc->base.mode;
276926deccbSFrançois Tigeot 	fixed20_12 a, b, c;
277926deccbSFrançois Tigeot 	fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
278926deccbSFrançois Tigeot 	fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
27957e252bfSMichael Neumann 	fixed20_12 sclk, core_bandwidth, max_bandwidth;
28057e252bfSMichael Neumann 	u32 selected_sclk;
281926deccbSFrançois Tigeot 
28257e09377SMatthew Dillon 	bzero(wm, sizeof(*wm));	/* avoid gcc warning */
283926deccbSFrançois Tigeot 	if (!crtc->base.enabled) {
284926deccbSFrançois Tigeot 		/* FIXME: wouldn't it better to set priority mark to maximum */
285926deccbSFrançois Tigeot 		wm->lb_request_fifo_depth = 4;
286926deccbSFrançois Tigeot 		return;
287926deccbSFrançois Tigeot 	}
288926deccbSFrançois Tigeot 
28957e252bfSMichael Neumann 	if (((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) &&
29057e252bfSMichael Neumann 	    (rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
29157e252bfSMichael Neumann 		selected_sclk = radeon_dpm_get_sclk(rdev, low);
29257e252bfSMichael Neumann 	else
29357e252bfSMichael Neumann 		selected_sclk = rdev->pm.current_sclk;
29457e252bfSMichael Neumann 
29557e252bfSMichael Neumann 	/* sclk in Mhz */
29657e252bfSMichael Neumann 	a.full = dfixed_const(100);
29757e252bfSMichael Neumann 	sclk.full = dfixed_const(selected_sclk);
29857e252bfSMichael Neumann 	sclk.full = dfixed_div(sclk, a);
29957e252bfSMichael Neumann 
30057e252bfSMichael Neumann 	/* core_bandwidth = sclk(Mhz) * 16 */
30157e252bfSMichael Neumann 	a.full = dfixed_const(16);
30257e252bfSMichael Neumann 	core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
30357e252bfSMichael Neumann 
304926deccbSFrançois Tigeot 	if (crtc->vsc.full > dfixed_const(2))
305926deccbSFrançois Tigeot 		wm->num_line_pair.full = dfixed_const(2);
306926deccbSFrançois Tigeot 	else
307926deccbSFrançois Tigeot 		wm->num_line_pair.full = dfixed_const(1);
308926deccbSFrançois Tigeot 
309926deccbSFrançois Tigeot 	b.full = dfixed_const(mode->crtc_hdisplay);
310926deccbSFrançois Tigeot 	c.full = dfixed_const(256);
311926deccbSFrançois Tigeot 	a.full = dfixed_div(b, c);
312926deccbSFrançois Tigeot 	request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
313926deccbSFrançois Tigeot 	request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
314926deccbSFrançois Tigeot 	if (a.full < dfixed_const(4)) {
315926deccbSFrançois Tigeot 		wm->lb_request_fifo_depth = 4;
316926deccbSFrançois Tigeot 	} else {
317926deccbSFrançois Tigeot 		wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
318926deccbSFrançois Tigeot 	}
319926deccbSFrançois Tigeot 
320926deccbSFrançois Tigeot 	/* Determine consumption rate
321926deccbSFrançois Tigeot 	 *  pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
322926deccbSFrançois Tigeot 	 *  vtaps = number of vertical taps,
323926deccbSFrançois Tigeot 	 *  vsc = vertical scaling ratio, defined as source/destination
324926deccbSFrançois Tigeot 	 *  hsc = horizontal scaling ration, defined as source/destination
325926deccbSFrançois Tigeot 	 */
326926deccbSFrançois Tigeot 	a.full = dfixed_const(mode->clock);
327926deccbSFrançois Tigeot 	b.full = dfixed_const(1000);
328926deccbSFrançois Tigeot 	a.full = dfixed_div(a, b);
329926deccbSFrançois Tigeot 	pclk.full = dfixed_div(b, a);
330926deccbSFrançois Tigeot 	if (crtc->rmx_type != RMX_OFF) {
331926deccbSFrançois Tigeot 		b.full = dfixed_const(2);
332926deccbSFrançois Tigeot 		if (crtc->vsc.full > b.full)
333926deccbSFrançois Tigeot 			b.full = crtc->vsc.full;
334926deccbSFrançois Tigeot 		b.full = dfixed_mul(b, crtc->hsc);
335926deccbSFrançois Tigeot 		c.full = dfixed_const(2);
336926deccbSFrançois Tigeot 		b.full = dfixed_div(b, c);
337926deccbSFrançois Tigeot 		consumption_time.full = dfixed_div(pclk, b);
338926deccbSFrançois Tigeot 	} else {
339926deccbSFrançois Tigeot 		consumption_time.full = pclk.full;
340926deccbSFrançois Tigeot 	}
341926deccbSFrançois Tigeot 	a.full = dfixed_const(1);
342926deccbSFrançois Tigeot 	wm->consumption_rate.full = dfixed_div(a, consumption_time);
343926deccbSFrançois Tigeot 
344926deccbSFrançois Tigeot 
345926deccbSFrançois Tigeot 	/* Determine line time
346926deccbSFrançois Tigeot 	 *  LineTime = total time for one line of displayhtotal
347926deccbSFrançois Tigeot 	 *  LineTime = total number of horizontal pixels
348926deccbSFrançois Tigeot 	 *  pclk = pixel clock period(ns)
349926deccbSFrançois Tigeot 	 */
350926deccbSFrançois Tigeot 	a.full = dfixed_const(crtc->base.mode.crtc_htotal);
351926deccbSFrançois Tigeot 	line_time.full = dfixed_mul(a, pclk);
352926deccbSFrançois Tigeot 
353926deccbSFrançois Tigeot 	/* Determine active time
354926deccbSFrançois Tigeot 	 *  ActiveTime = time of active region of display within one line,
355926deccbSFrançois Tigeot 	 *  hactive = total number of horizontal active pixels
356926deccbSFrançois Tigeot 	 *  htotal = total number of horizontal pixels
357926deccbSFrançois Tigeot 	 */
358926deccbSFrançois Tigeot 	a.full = dfixed_const(crtc->base.mode.crtc_htotal);
359926deccbSFrançois Tigeot 	b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
360926deccbSFrançois Tigeot 	wm->active_time.full = dfixed_mul(line_time, b);
361926deccbSFrançois Tigeot 	wm->active_time.full = dfixed_div(wm->active_time, a);
362926deccbSFrançois Tigeot 
363926deccbSFrançois Tigeot 	/* Maximun bandwidth is the minimun bandwidth of all component */
36457e252bfSMichael Neumann 	max_bandwidth = core_bandwidth;
365926deccbSFrançois Tigeot 	if (rdev->mc.igp_sideport_enabled) {
36657e252bfSMichael Neumann 		if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
367926deccbSFrançois Tigeot 			rdev->pm.sideport_bandwidth.full)
36857e252bfSMichael Neumann 			max_bandwidth = rdev->pm.sideport_bandwidth;
369c6f73aabSFrançois Tigeot 		read_delay_latency.full = dfixed_const(370 * 800);
370c6f73aabSFrançois Tigeot 		a.full = dfixed_const(1000);
371c6f73aabSFrançois Tigeot 		b.full = dfixed_div(rdev->pm.igp_sideport_mclk, a);
372c6f73aabSFrançois Tigeot 		read_delay_latency.full = dfixed_div(read_delay_latency, b);
373c6f73aabSFrançois Tigeot 		read_delay_latency.full = dfixed_mul(read_delay_latency, a);
374926deccbSFrançois Tigeot 	} else {
37557e252bfSMichael Neumann 		if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
376926deccbSFrançois Tigeot 			rdev->pm.k8_bandwidth.full)
37757e252bfSMichael Neumann 			max_bandwidth = rdev->pm.k8_bandwidth;
37857e252bfSMichael Neumann 		if (max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
379926deccbSFrançois Tigeot 			rdev->pm.ht_bandwidth.full)
38057e252bfSMichael Neumann 			max_bandwidth = rdev->pm.ht_bandwidth;
381926deccbSFrançois Tigeot 		read_delay_latency.full = dfixed_const(5000);
382926deccbSFrançois Tigeot 	}
383926deccbSFrançois Tigeot 
384926deccbSFrançois Tigeot 	/* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
385926deccbSFrançois Tigeot 	a.full = dfixed_const(16);
38657e252bfSMichael Neumann 	sclk.full = dfixed_mul(max_bandwidth, a);
387926deccbSFrançois Tigeot 	a.full = dfixed_const(1000);
38857e252bfSMichael Neumann 	sclk.full = dfixed_div(a, sclk);
389926deccbSFrançois Tigeot 	/* Determine chunk time
390926deccbSFrançois Tigeot 	 * ChunkTime = the time it takes the DCP to send one chunk of data
391926deccbSFrançois Tigeot 	 * to the LB which consists of pipeline delay and inter chunk gap
392926deccbSFrançois Tigeot 	 * sclk = system clock(ns)
393926deccbSFrançois Tigeot 	 */
394926deccbSFrançois Tigeot 	a.full = dfixed_const(256 * 13);
39557e252bfSMichael Neumann 	chunk_time.full = dfixed_mul(sclk, a);
396926deccbSFrançois Tigeot 	a.full = dfixed_const(10);
397926deccbSFrançois Tigeot 	chunk_time.full = dfixed_div(chunk_time, a);
398926deccbSFrançois Tigeot 
399926deccbSFrançois Tigeot 	/* Determine the worst case latency
400926deccbSFrançois Tigeot 	 * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
401926deccbSFrançois Tigeot 	 * WorstCaseLatency = worst case time from urgent to when the MC starts
402926deccbSFrançois Tigeot 	 *                    to return data
403926deccbSFrançois Tigeot 	 * READ_DELAY_IDLE_MAX = constant of 1us
404926deccbSFrançois Tigeot 	 * ChunkTime = time it takes the DCP to send one chunk of data to the LB
405926deccbSFrançois Tigeot 	 *             which consists of pipeline delay and inter chunk gap
406926deccbSFrançois Tigeot 	 */
407926deccbSFrançois Tigeot 	if (dfixed_trunc(wm->num_line_pair) > 1) {
408926deccbSFrançois Tigeot 		a.full = dfixed_const(3);
409926deccbSFrançois Tigeot 		wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
410926deccbSFrançois Tigeot 		wm->worst_case_latency.full += read_delay_latency.full;
411926deccbSFrançois Tigeot 	} else {
412926deccbSFrançois Tigeot 		a.full = dfixed_const(2);
413926deccbSFrançois Tigeot 		wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
414926deccbSFrançois Tigeot 		wm->worst_case_latency.full += read_delay_latency.full;
415926deccbSFrançois Tigeot 	}
416926deccbSFrançois Tigeot 
417926deccbSFrançois Tigeot 	/* Determine the tolerable latency
418926deccbSFrançois Tigeot 	 * TolerableLatency = Any given request has only 1 line time
419926deccbSFrançois Tigeot 	 *                    for the data to be returned
420926deccbSFrançois Tigeot 	 * LBRequestFifoDepth = Number of chunk requests the LB can
421926deccbSFrançois Tigeot 	 *                      put into the request FIFO for a display
422926deccbSFrançois Tigeot 	 *  LineTime = total time for one line of display
423926deccbSFrançois Tigeot 	 *  ChunkTime = the time it takes the DCP to send one chunk
424926deccbSFrançois Tigeot 	 *              of data to the LB which consists of
425926deccbSFrançois Tigeot 	 *  pipeline delay and inter chunk gap
426926deccbSFrançois Tigeot 	 */
427926deccbSFrançois Tigeot 	if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
428926deccbSFrançois Tigeot 		tolerable_latency.full = line_time.full;
429926deccbSFrançois Tigeot 	} else {
430926deccbSFrançois Tigeot 		tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
431926deccbSFrançois Tigeot 		tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
432926deccbSFrançois Tigeot 		tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
433926deccbSFrançois Tigeot 		tolerable_latency.full = line_time.full - tolerable_latency.full;
434926deccbSFrançois Tigeot 	}
435926deccbSFrançois Tigeot 	/* We assume worst case 32bits (4 bytes) */
436926deccbSFrançois Tigeot 	wm->dbpp.full = dfixed_const(4 * 8);
437926deccbSFrançois Tigeot 
438926deccbSFrançois Tigeot 	/* Determine the maximum priority mark
439926deccbSFrançois Tigeot 	 *  width = viewport width in pixels
440926deccbSFrançois Tigeot 	 */
441926deccbSFrançois Tigeot 	a.full = dfixed_const(16);
442926deccbSFrançois Tigeot 	wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
443926deccbSFrançois Tigeot 	wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
444926deccbSFrançois Tigeot 	wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
445926deccbSFrançois Tigeot 
446926deccbSFrançois Tigeot 	/* Determine estimated width */
447926deccbSFrançois Tigeot 	estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
448926deccbSFrançois Tigeot 	estimated_width.full = dfixed_div(estimated_width, consumption_time);
449926deccbSFrançois Tigeot 	if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
450926deccbSFrançois Tigeot 		wm->priority_mark.full = dfixed_const(10);
451926deccbSFrançois Tigeot 	} else {
452926deccbSFrançois Tigeot 		a.full = dfixed_const(16);
453926deccbSFrançois Tigeot 		wm->priority_mark.full = dfixed_div(estimated_width, a);
454926deccbSFrançois Tigeot 		wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
455926deccbSFrançois Tigeot 		wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
456926deccbSFrançois Tigeot 	}
457926deccbSFrançois Tigeot }
458926deccbSFrançois Tigeot 
rs690_compute_mode_priority(struct radeon_device * rdev,struct rs690_watermark * wm0,struct rs690_watermark * wm1,struct drm_display_mode * mode0,struct drm_display_mode * mode1,u32 * d1mode_priority_a_cnt,u32 * d2mode_priority_a_cnt)45957e252bfSMichael Neumann static void rs690_compute_mode_priority(struct radeon_device *rdev,
46057e252bfSMichael Neumann 					struct rs690_watermark *wm0,
46157e252bfSMichael Neumann 					struct rs690_watermark *wm1,
46257e252bfSMichael Neumann 					struct drm_display_mode *mode0,
46357e252bfSMichael Neumann 					struct drm_display_mode *mode1,
46457e252bfSMichael Neumann 					u32 *d1mode_priority_a_cnt,
46557e252bfSMichael Neumann 					u32 *d2mode_priority_a_cnt)
46657e252bfSMichael Neumann {
46757e252bfSMichael Neumann 	fixed20_12 priority_mark02, priority_mark12, fill_rate;
46857e252bfSMichael Neumann 	fixed20_12 a, b;
46957e252bfSMichael Neumann 
47057e252bfSMichael Neumann 	*d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
47157e252bfSMichael Neumann 	*d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
47257e252bfSMichael Neumann 
47357e252bfSMichael Neumann 	if (mode0 && mode1) {
47457e252bfSMichael Neumann 		if (dfixed_trunc(wm0->dbpp) > 64)
47557e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
47657e252bfSMichael Neumann 		else
47757e252bfSMichael Neumann 			a.full = wm0->num_line_pair.full;
47857e252bfSMichael Neumann 		if (dfixed_trunc(wm1->dbpp) > 64)
47957e252bfSMichael Neumann 			b.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
48057e252bfSMichael Neumann 		else
48157e252bfSMichael Neumann 			b.full = wm1->num_line_pair.full;
48257e252bfSMichael Neumann 		a.full += b.full;
48357e252bfSMichael Neumann 		fill_rate.full = dfixed_div(wm0->sclk, a);
48457e252bfSMichael Neumann 		if (wm0->consumption_rate.full > fill_rate.full) {
48557e252bfSMichael Neumann 			b.full = wm0->consumption_rate.full - fill_rate.full;
48657e252bfSMichael Neumann 			b.full = dfixed_mul(b, wm0->active_time);
48757e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->worst_case_latency,
48857e252bfSMichael Neumann 						wm0->consumption_rate);
48957e252bfSMichael Neumann 			a.full = a.full + b.full;
49057e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
49157e252bfSMichael Neumann 			priority_mark02.full = dfixed_div(a, b);
49257e252bfSMichael Neumann 		} else {
49357e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->worst_case_latency,
49457e252bfSMichael Neumann 						wm0->consumption_rate);
49557e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
49657e252bfSMichael Neumann 			priority_mark02.full = dfixed_div(a, b);
49757e252bfSMichael Neumann 		}
49857e252bfSMichael Neumann 		if (wm1->consumption_rate.full > fill_rate.full) {
49957e252bfSMichael Neumann 			b.full = wm1->consumption_rate.full - fill_rate.full;
50057e252bfSMichael Neumann 			b.full = dfixed_mul(b, wm1->active_time);
50157e252bfSMichael Neumann 			a.full = dfixed_mul(wm1->worst_case_latency,
50257e252bfSMichael Neumann 						wm1->consumption_rate);
50357e252bfSMichael Neumann 			a.full = a.full + b.full;
50457e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
50557e252bfSMichael Neumann 			priority_mark12.full = dfixed_div(a, b);
50657e252bfSMichael Neumann 		} else {
50757e252bfSMichael Neumann 			a.full = dfixed_mul(wm1->worst_case_latency,
50857e252bfSMichael Neumann 						wm1->consumption_rate);
50957e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
51057e252bfSMichael Neumann 			priority_mark12.full = dfixed_div(a, b);
51157e252bfSMichael Neumann 		}
51257e252bfSMichael Neumann 		if (wm0->priority_mark.full > priority_mark02.full)
51357e252bfSMichael Neumann 			priority_mark02.full = wm0->priority_mark.full;
51457e252bfSMichael Neumann 		if (wm0->priority_mark_max.full > priority_mark02.full)
51557e252bfSMichael Neumann 			priority_mark02.full = wm0->priority_mark_max.full;
51657e252bfSMichael Neumann 		if (wm1->priority_mark.full > priority_mark12.full)
51757e252bfSMichael Neumann 			priority_mark12.full = wm1->priority_mark.full;
51857e252bfSMichael Neumann 		if (wm1->priority_mark_max.full > priority_mark12.full)
51957e252bfSMichael Neumann 			priority_mark12.full = wm1->priority_mark_max.full;
52057e252bfSMichael Neumann 		*d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
52157e252bfSMichael Neumann 		*d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
52257e252bfSMichael Neumann 		if (rdev->disp_priority == 2) {
52357e252bfSMichael Neumann 			*d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
52457e252bfSMichael Neumann 			*d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
52557e252bfSMichael Neumann 		}
52657e252bfSMichael Neumann 	} else if (mode0) {
52757e252bfSMichael Neumann 		if (dfixed_trunc(wm0->dbpp) > 64)
52857e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
52957e252bfSMichael Neumann 		else
53057e252bfSMichael Neumann 			a.full = wm0->num_line_pair.full;
53157e252bfSMichael Neumann 		fill_rate.full = dfixed_div(wm0->sclk, a);
53257e252bfSMichael Neumann 		if (wm0->consumption_rate.full > fill_rate.full) {
53357e252bfSMichael Neumann 			b.full = wm0->consumption_rate.full - fill_rate.full;
53457e252bfSMichael Neumann 			b.full = dfixed_mul(b, wm0->active_time);
53557e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->worst_case_latency,
53657e252bfSMichael Neumann 						wm0->consumption_rate);
53757e252bfSMichael Neumann 			a.full = a.full + b.full;
53857e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
53957e252bfSMichael Neumann 			priority_mark02.full = dfixed_div(a, b);
54057e252bfSMichael Neumann 		} else {
54157e252bfSMichael Neumann 			a.full = dfixed_mul(wm0->worst_case_latency,
54257e252bfSMichael Neumann 						wm0->consumption_rate);
54357e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
54457e252bfSMichael Neumann 			priority_mark02.full = dfixed_div(a, b);
54557e252bfSMichael Neumann 		}
54657e252bfSMichael Neumann 		if (wm0->priority_mark.full > priority_mark02.full)
54757e252bfSMichael Neumann 			priority_mark02.full = wm0->priority_mark.full;
54857e252bfSMichael Neumann 		if (wm0->priority_mark_max.full > priority_mark02.full)
54957e252bfSMichael Neumann 			priority_mark02.full = wm0->priority_mark_max.full;
55057e252bfSMichael Neumann 		*d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
55157e252bfSMichael Neumann 		if (rdev->disp_priority == 2)
55257e252bfSMichael Neumann 			*d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
55357e252bfSMichael Neumann 	} else if (mode1) {
55457e252bfSMichael Neumann 		if (dfixed_trunc(wm1->dbpp) > 64)
55557e252bfSMichael Neumann 			a.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
55657e252bfSMichael Neumann 		else
55757e252bfSMichael Neumann 			a.full = wm1->num_line_pair.full;
55857e252bfSMichael Neumann 		fill_rate.full = dfixed_div(wm1->sclk, a);
55957e252bfSMichael Neumann 		if (wm1->consumption_rate.full > fill_rate.full) {
56057e252bfSMichael Neumann 			b.full = wm1->consumption_rate.full - fill_rate.full;
56157e252bfSMichael Neumann 			b.full = dfixed_mul(b, wm1->active_time);
56257e252bfSMichael Neumann 			a.full = dfixed_mul(wm1->worst_case_latency,
56357e252bfSMichael Neumann 						wm1->consumption_rate);
56457e252bfSMichael Neumann 			a.full = a.full + b.full;
56557e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
56657e252bfSMichael Neumann 			priority_mark12.full = dfixed_div(a, b);
56757e252bfSMichael Neumann 		} else {
56857e252bfSMichael Neumann 			a.full = dfixed_mul(wm1->worst_case_latency,
56957e252bfSMichael Neumann 						wm1->consumption_rate);
57057e252bfSMichael Neumann 			b.full = dfixed_const(16 * 1000);
57157e252bfSMichael Neumann 			priority_mark12.full = dfixed_div(a, b);
57257e252bfSMichael Neumann 		}
57357e252bfSMichael Neumann 		if (wm1->priority_mark.full > priority_mark12.full)
57457e252bfSMichael Neumann 			priority_mark12.full = wm1->priority_mark.full;
57557e252bfSMichael Neumann 		if (wm1->priority_mark_max.full > priority_mark12.full)
57657e252bfSMichael Neumann 			priority_mark12.full = wm1->priority_mark_max.full;
57757e252bfSMichael Neumann 		*d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
57857e252bfSMichael Neumann 		if (rdev->disp_priority == 2)
57957e252bfSMichael Neumann 			*d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
58057e252bfSMichael Neumann 	}
58157e252bfSMichael Neumann }
58257e252bfSMichael Neumann 
rs690_bandwidth_update(struct radeon_device * rdev)583926deccbSFrançois Tigeot void rs690_bandwidth_update(struct radeon_device *rdev)
584926deccbSFrançois Tigeot {
585926deccbSFrançois Tigeot 	struct drm_display_mode *mode0 = NULL;
586926deccbSFrançois Tigeot 	struct drm_display_mode *mode1 = NULL;
58757e252bfSMichael Neumann 	struct rs690_watermark wm0_high, wm0_low;
58857e252bfSMichael Neumann 	struct rs690_watermark wm1_high, wm1_low;
589926deccbSFrançois Tigeot 	u32 tmp;
59057e252bfSMichael Neumann 	u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt;
59157e252bfSMichael Neumann 	u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt;
592926deccbSFrançois Tigeot 
593591d5043SFrançois Tigeot 	if (!rdev->mode_info.mode_config_initialized)
594591d5043SFrançois Tigeot 		return;
595591d5043SFrançois Tigeot 
596926deccbSFrançois Tigeot 	radeon_update_display_priority(rdev);
597926deccbSFrançois Tigeot 
598926deccbSFrançois Tigeot 	if (rdev->mode_info.crtcs[0]->base.enabled)
599926deccbSFrançois Tigeot 		mode0 = &rdev->mode_info.crtcs[0]->base.mode;
600926deccbSFrançois Tigeot 	if (rdev->mode_info.crtcs[1]->base.enabled)
601926deccbSFrançois Tigeot 		mode1 = &rdev->mode_info.crtcs[1]->base.mode;
602926deccbSFrançois Tigeot 	/*
603926deccbSFrançois Tigeot 	 * Set display0/1 priority up in the memory controller for
604926deccbSFrançois Tigeot 	 * modes if the user specifies HIGH for displaypriority
605926deccbSFrançois Tigeot 	 * option.
606926deccbSFrançois Tigeot 	 */
607926deccbSFrançois Tigeot 	if ((rdev->disp_priority == 2) &&
608926deccbSFrançois Tigeot 	    ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
609926deccbSFrançois Tigeot 		tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
610926deccbSFrançois Tigeot 		tmp &= C_000104_MC_DISP0R_INIT_LAT;
611926deccbSFrançois Tigeot 		tmp &= C_000104_MC_DISP1R_INIT_LAT;
612926deccbSFrançois Tigeot 		if (mode0)
613926deccbSFrançois Tigeot 			tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
614926deccbSFrançois Tigeot 		if (mode1)
615926deccbSFrançois Tigeot 			tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
616926deccbSFrançois Tigeot 		WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
617926deccbSFrançois Tigeot 	}
618926deccbSFrançois Tigeot 	rs690_line_buffer_adjust(rdev, mode0, mode1);
619926deccbSFrançois Tigeot 
620926deccbSFrançois Tigeot 	if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
621926deccbSFrançois Tigeot 		WREG32(R_006C9C_DCP_CONTROL, 0);
622926deccbSFrançois Tigeot 	if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
623926deccbSFrançois Tigeot 		WREG32(R_006C9C_DCP_CONTROL, 2);
624926deccbSFrançois Tigeot 
62557e252bfSMichael Neumann 	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_high, false);
62657e252bfSMichael Neumann 	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_high, false);
627926deccbSFrançois Tigeot 
62857e252bfSMichael Neumann 	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_low, true);
62957e252bfSMichael Neumann 	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_low, true);
63057e252bfSMichael Neumann 
63157e252bfSMichael Neumann 	tmp = (wm0_high.lb_request_fifo_depth - 1);
63257e252bfSMichael Neumann 	tmp |= (wm1_high.lb_request_fifo_depth - 1) << 16;
633926deccbSFrançois Tigeot 	WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
634926deccbSFrançois Tigeot 
63557e252bfSMichael Neumann 	rs690_compute_mode_priority(rdev,
63657e252bfSMichael Neumann 				    &wm0_high, &wm1_high,
63757e252bfSMichael Neumann 				    mode0, mode1,
63857e252bfSMichael Neumann 				    &d1mode_priority_a_cnt, &d2mode_priority_a_cnt);
63957e252bfSMichael Neumann 	rs690_compute_mode_priority(rdev,
64057e252bfSMichael Neumann 				    &wm0_low, &wm1_low,
64157e252bfSMichael Neumann 				    mode0, mode1,
64257e252bfSMichael Neumann 				    &d1mode_priority_b_cnt, &d2mode_priority_b_cnt);
643926deccbSFrançois Tigeot 
644926deccbSFrançois Tigeot 	WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
64557e252bfSMichael Neumann 	WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_b_cnt);
646926deccbSFrançois Tigeot 	WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
64757e252bfSMichael Neumann 	WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_b_cnt);
648926deccbSFrançois Tigeot }
649926deccbSFrançois Tigeot 
rs690_mc_rreg(struct radeon_device * rdev,uint32_t reg)650926deccbSFrançois Tigeot uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
651926deccbSFrançois Tigeot {
652926deccbSFrançois Tigeot 	uint32_t r;
653926deccbSFrançois Tigeot 
654ec5b6af4SFrançois Tigeot 	lockmgr(&rdev->mc_idx_lock, LK_EXCLUSIVE);
655926deccbSFrançois Tigeot 	WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
656926deccbSFrançois Tigeot 	r = RREG32(R_00007C_MC_DATA);
657926deccbSFrançois Tigeot 	WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
658ec5b6af4SFrançois Tigeot 	lockmgr(&rdev->mc_idx_lock, LK_RELEASE);
659926deccbSFrançois Tigeot 	return r;
660926deccbSFrançois Tigeot }
661926deccbSFrançois Tigeot 
rs690_mc_wreg(struct radeon_device * rdev,uint32_t reg,uint32_t v)662926deccbSFrançois Tigeot void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
663926deccbSFrançois Tigeot {
664ec5b6af4SFrançois Tigeot 	lockmgr(&rdev->mc_idx_lock, LK_EXCLUSIVE);
665926deccbSFrançois Tigeot 	WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
666926deccbSFrançois Tigeot 		S_000078_MC_IND_WR_EN(1));
667926deccbSFrançois Tigeot 	WREG32(R_00007C_MC_DATA, v);
668926deccbSFrançois Tigeot 	WREG32(R_000078_MC_INDEX, 0x7F);
669ec5b6af4SFrançois Tigeot 	lockmgr(&rdev->mc_idx_lock, LK_RELEASE);
670926deccbSFrançois Tigeot }
671926deccbSFrançois Tigeot 
rs690_mc_program(struct radeon_device * rdev)672926deccbSFrançois Tigeot static void rs690_mc_program(struct radeon_device *rdev)
673926deccbSFrançois Tigeot {
674926deccbSFrançois Tigeot 	struct rv515_mc_save save;
675926deccbSFrançois Tigeot 
676926deccbSFrançois Tigeot 	/* Stops all mc clients */
677926deccbSFrançois Tigeot 	rv515_mc_stop(rdev, &save);
678926deccbSFrançois Tigeot 
679926deccbSFrançois Tigeot 	/* Wait for mc idle */
680926deccbSFrançois Tigeot 	if (rs690_mc_wait_for_idle(rdev))
681926deccbSFrançois Tigeot 		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
682926deccbSFrançois Tigeot 	/* Program MC, should be a 32bits limited address space */
683926deccbSFrançois Tigeot 	WREG32_MC(R_000100_MCCFG_FB_LOCATION,
684926deccbSFrançois Tigeot 			S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
685926deccbSFrançois Tigeot 			S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
686926deccbSFrançois Tigeot 	WREG32(R_000134_HDP_FB_LOCATION,
687926deccbSFrançois Tigeot 		S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
688926deccbSFrançois Tigeot 
689926deccbSFrançois Tigeot 	rv515_mc_resume(rdev, &save);
690926deccbSFrançois Tigeot }
691926deccbSFrançois Tigeot 
rs690_startup(struct radeon_device * rdev)692926deccbSFrançois Tigeot static int rs690_startup(struct radeon_device *rdev)
693926deccbSFrançois Tigeot {
694926deccbSFrançois Tigeot 	int r;
695926deccbSFrançois Tigeot 
696926deccbSFrançois Tigeot 	rs690_mc_program(rdev);
697926deccbSFrançois Tigeot 	/* Resume clock */
698926deccbSFrançois Tigeot 	rv515_clock_startup(rdev);
699926deccbSFrançois Tigeot 	/* Initialize GPU configuration (# pipes, ...) */
700926deccbSFrançois Tigeot 	rs690_gpu_init(rdev);
701926deccbSFrançois Tigeot 	/* Initialize GART (initialize after TTM so we can allocate
702926deccbSFrançois Tigeot 	 * memory through TTM but finalize after TTM) */
703926deccbSFrançois Tigeot 	r = rs400_gart_enable(rdev);
704926deccbSFrançois Tigeot 	if (r)
705926deccbSFrançois Tigeot 		return r;
706926deccbSFrançois Tigeot 
707926deccbSFrançois Tigeot 	/* allocate wb buffer */
708926deccbSFrançois Tigeot 	r = radeon_wb_init(rdev);
709926deccbSFrançois Tigeot 	if (r)
710926deccbSFrançois Tigeot 		return r;
711926deccbSFrançois Tigeot 
712926deccbSFrançois Tigeot 	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
713926deccbSFrançois Tigeot 	if (r) {
714926deccbSFrançois Tigeot 		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
715926deccbSFrançois Tigeot 		return r;
716926deccbSFrançois Tigeot 	}
717926deccbSFrançois Tigeot 
718926deccbSFrançois Tigeot 	/* Enable IRQ */
719f43cf1b1SMichael Neumann 	if (!rdev->irq.installed) {
720f43cf1b1SMichael Neumann 		r = radeon_irq_kms_init(rdev);
721f43cf1b1SMichael Neumann 		if (r)
722f43cf1b1SMichael Neumann 			return r;
723f43cf1b1SMichael Neumann 	}
724f43cf1b1SMichael Neumann 
725926deccbSFrançois Tigeot 	rs600_irq_set(rdev);
726926deccbSFrançois Tigeot 	rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
727926deccbSFrançois Tigeot 	/* 1M ring buffer */
728926deccbSFrançois Tigeot 	r = r100_cp_init(rdev, 1024 * 1024);
729926deccbSFrançois Tigeot 	if (r) {
730926deccbSFrançois Tigeot 		dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
731926deccbSFrançois Tigeot 		return r;
732926deccbSFrançois Tigeot 	}
733926deccbSFrançois Tigeot 
734926deccbSFrançois Tigeot 	r = radeon_ib_pool_init(rdev);
735926deccbSFrançois Tigeot 	if (r) {
736926deccbSFrançois Tigeot 		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
737926deccbSFrançois Tigeot 		return r;
738926deccbSFrançois Tigeot 	}
739926deccbSFrançois Tigeot 
740c59a5c48SFrançois Tigeot 	r = radeon_audio_init(rdev);
741926deccbSFrançois Tigeot 	if (r) {
742926deccbSFrançois Tigeot 		dev_err(rdev->dev, "failed initializing audio\n");
743926deccbSFrançois Tigeot 		return r;
744926deccbSFrançois Tigeot 	}
745926deccbSFrançois Tigeot 
746926deccbSFrançois Tigeot 	return 0;
747926deccbSFrançois Tigeot }
748926deccbSFrançois Tigeot 
rs690_resume(struct radeon_device * rdev)749926deccbSFrançois Tigeot int rs690_resume(struct radeon_device *rdev)
750926deccbSFrançois Tigeot {
751926deccbSFrançois Tigeot 	int r;
752926deccbSFrançois Tigeot 
753926deccbSFrançois Tigeot 	/* Make sur GART are not working */
754926deccbSFrançois Tigeot 	rs400_gart_disable(rdev);
755926deccbSFrançois Tigeot 	/* Resume clock before doing reset */
756926deccbSFrançois Tigeot 	rv515_clock_startup(rdev);
757926deccbSFrançois Tigeot 	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
758926deccbSFrançois Tigeot 	if (radeon_asic_reset(rdev)) {
759926deccbSFrançois Tigeot 		dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
760926deccbSFrançois Tigeot 			RREG32(R_000E40_RBBM_STATUS),
761926deccbSFrançois Tigeot 			RREG32(R_0007C0_CP_STAT));
762926deccbSFrançois Tigeot 	}
763926deccbSFrançois Tigeot 	/* post */
764926deccbSFrançois Tigeot 	atom_asic_init(rdev->mode_info.atom_context);
765926deccbSFrançois Tigeot 	/* Resume clock after posting */
766926deccbSFrançois Tigeot 	rv515_clock_startup(rdev);
767926deccbSFrançois Tigeot 	/* Initialize surface registers */
768926deccbSFrançois Tigeot 	radeon_surface_init(rdev);
769926deccbSFrançois Tigeot 
770926deccbSFrançois Tigeot 	rdev->accel_working = true;
771926deccbSFrançois Tigeot 	r = rs690_startup(rdev);
772926deccbSFrançois Tigeot 	if (r) {
773926deccbSFrançois Tigeot 		rdev->accel_working = false;
774926deccbSFrançois Tigeot 	}
775926deccbSFrançois Tigeot 	return r;
776926deccbSFrançois Tigeot }
777926deccbSFrançois Tigeot 
rs690_suspend(struct radeon_device * rdev)778926deccbSFrançois Tigeot int rs690_suspend(struct radeon_device *rdev)
779926deccbSFrançois Tigeot {
780c6f73aabSFrançois Tigeot 	radeon_pm_suspend(rdev);
781c59a5c48SFrançois Tigeot 	radeon_audio_fini(rdev);
782926deccbSFrançois Tigeot 	r100_cp_disable(rdev);
783926deccbSFrançois Tigeot 	radeon_wb_disable(rdev);
784926deccbSFrançois Tigeot 	rs600_irq_disable(rdev);
785926deccbSFrançois Tigeot 	rs400_gart_disable(rdev);
786926deccbSFrançois Tigeot 	return 0;
787926deccbSFrançois Tigeot }
788926deccbSFrançois Tigeot 
rs690_fini(struct radeon_device * rdev)789926deccbSFrançois Tigeot void rs690_fini(struct radeon_device *rdev)
790926deccbSFrançois Tigeot {
791c6f73aabSFrançois Tigeot 	radeon_pm_fini(rdev);
792c59a5c48SFrançois Tigeot 	radeon_audio_fini(rdev);
793926deccbSFrançois Tigeot 	r100_cp_fini(rdev);
794926deccbSFrançois Tigeot 	radeon_wb_fini(rdev);
795926deccbSFrançois Tigeot 	radeon_ib_pool_fini(rdev);
796926deccbSFrançois Tigeot 	radeon_gem_fini(rdev);
797926deccbSFrançois Tigeot 	rs400_gart_fini(rdev);
798926deccbSFrançois Tigeot 	radeon_irq_kms_fini(rdev);
799926deccbSFrançois Tigeot 	radeon_fence_driver_fini(rdev);
800926deccbSFrançois Tigeot 	radeon_bo_fini(rdev);
801926deccbSFrançois Tigeot 	radeon_atombios_fini(rdev);
802c4ef309bSzrj 	kfree(rdev->bios);
803926deccbSFrançois Tigeot 	rdev->bios = NULL;
804926deccbSFrançois Tigeot }
805926deccbSFrançois Tigeot 
rs690_init(struct radeon_device * rdev)806926deccbSFrançois Tigeot int rs690_init(struct radeon_device *rdev)
807926deccbSFrançois Tigeot {
808926deccbSFrançois Tigeot 	int r;
809926deccbSFrançois Tigeot 
810926deccbSFrançois Tigeot 	/* Disable VGA */
811926deccbSFrançois Tigeot 	rv515_vga_render_disable(rdev);
812926deccbSFrançois Tigeot 	/* Initialize scratch registers */
813926deccbSFrançois Tigeot 	radeon_scratch_init(rdev);
814926deccbSFrançois Tigeot 	/* Initialize surface registers */
815926deccbSFrançois Tigeot 	radeon_surface_init(rdev);
816926deccbSFrançois Tigeot 	/* restore some register to sane defaults */
817926deccbSFrançois Tigeot 	r100_restore_sanity(rdev);
818926deccbSFrançois Tigeot 	/* TODO: disable VGA need to use VGA request */
819926deccbSFrançois Tigeot 	/* BIOS*/
820926deccbSFrançois Tigeot 	if (!radeon_get_bios(rdev)) {
821926deccbSFrançois Tigeot 		if (ASIC_IS_AVIVO(rdev))
822926deccbSFrançois Tigeot 			return -EINVAL;
823926deccbSFrançois Tigeot 	}
824926deccbSFrançois Tigeot 	if (rdev->is_atom_bios) {
825926deccbSFrançois Tigeot 		r = radeon_atombios_init(rdev);
826926deccbSFrançois Tigeot 		if (r)
827926deccbSFrançois Tigeot 			return r;
828926deccbSFrançois Tigeot 	} else {
829926deccbSFrançois Tigeot 		dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
830926deccbSFrançois Tigeot 		return -EINVAL;
831926deccbSFrançois Tigeot 	}
832926deccbSFrançois Tigeot 	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
833926deccbSFrançois Tigeot 	if (radeon_asic_reset(rdev)) {
834926deccbSFrançois Tigeot 		dev_warn(rdev->dev,
835926deccbSFrançois Tigeot 			"GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
836926deccbSFrançois Tigeot 			RREG32(R_000E40_RBBM_STATUS),
837926deccbSFrançois Tigeot 			RREG32(R_0007C0_CP_STAT));
838926deccbSFrançois Tigeot 	}
839926deccbSFrançois Tigeot 	/* check if cards are posted or not */
840926deccbSFrançois Tigeot 	if (radeon_boot_test_post_card(rdev) == false)
841926deccbSFrançois Tigeot 		return -EINVAL;
842926deccbSFrançois Tigeot 
843926deccbSFrançois Tigeot 	/* Initialize clocks */
844926deccbSFrançois Tigeot 	radeon_get_clock_info(rdev->ddev);
845926deccbSFrançois Tigeot 	/* initialize memory controller */
846926deccbSFrançois Tigeot 	rs690_mc_init(rdev);
847926deccbSFrançois Tigeot 	rv515_debugfs(rdev);
848926deccbSFrançois Tigeot 	/* Fence driver */
849926deccbSFrançois Tigeot 	r = radeon_fence_driver_init(rdev);
850926deccbSFrançois Tigeot 	if (r)
851926deccbSFrançois Tigeot 		return r;
852926deccbSFrançois Tigeot 	/* Memory manager */
853926deccbSFrançois Tigeot 	r = radeon_bo_init(rdev);
854926deccbSFrançois Tigeot 	if (r)
855926deccbSFrançois Tigeot 		return r;
856926deccbSFrançois Tigeot 	r = rs400_gart_init(rdev);
857926deccbSFrançois Tigeot 	if (r)
858926deccbSFrançois Tigeot 		return r;
859926deccbSFrançois Tigeot 	rs600_set_safe_registers(rdev);
860926deccbSFrançois Tigeot 
861c6f73aabSFrançois Tigeot 	/* Initialize power management */
862c6f73aabSFrançois Tigeot 	radeon_pm_init(rdev);
863c6f73aabSFrançois Tigeot 
864926deccbSFrançois Tigeot 	rdev->accel_working = true;
865926deccbSFrançois Tigeot 	r = rs690_startup(rdev);
866926deccbSFrançois Tigeot 	if (r) {
867926deccbSFrançois Tigeot 		/* Somethings want wront with the accel init stop accel */
868926deccbSFrançois Tigeot 		dev_err(rdev->dev, "Disabling GPU acceleration\n");
869926deccbSFrançois Tigeot 		r100_cp_fini(rdev);
870926deccbSFrançois Tigeot 		radeon_wb_fini(rdev);
871926deccbSFrançois Tigeot 		radeon_ib_pool_fini(rdev);
872926deccbSFrançois Tigeot 		rs400_gart_fini(rdev);
873926deccbSFrançois Tigeot 		radeon_irq_kms_fini(rdev);
874926deccbSFrançois Tigeot 		rdev->accel_working = false;
875926deccbSFrançois Tigeot 	}
876926deccbSFrançois Tigeot 	return 0;
877926deccbSFrançois Tigeot }
878