18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2008 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci * Copyright 2008 Red Hat Inc.
48c2ecf20Sopenharmony_ci * Copyright 2009 Jerome Glisse.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
88c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
98c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
108c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
118c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
148c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
178c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
188c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
198c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
208c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
218c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
228c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * Authors: Dave Airlie
258c2ecf20Sopenharmony_ci *          Alex Deucher
268c2ecf20Sopenharmony_ci *          Jerome Glisse
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/pci.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include "atom.h"
328c2ecf20Sopenharmony_ci#include "radeon.h"
338c2ecf20Sopenharmony_ci#include "radeon_asic.h"
348c2ecf20Sopenharmony_ci#include "radeon_audio.h"
358c2ecf20Sopenharmony_ci#include "rs690d.h"
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciint rs690_mc_wait_for_idle(struct radeon_device *rdev)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	unsigned i;
408c2ecf20Sopenharmony_ci	uint32_t tmp;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->usec_timeout; i++) {
438c2ecf20Sopenharmony_ci		/* read MC_STATUS */
448c2ecf20Sopenharmony_ci		tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
458c2ecf20Sopenharmony_ci		if (G_000090_MC_SYSTEM_IDLE(tmp))
468c2ecf20Sopenharmony_ci			return 0;
478c2ecf20Sopenharmony_ci		udelay(1);
488c2ecf20Sopenharmony_ci	}
498c2ecf20Sopenharmony_ci	return -1;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic void rs690_gpu_init(struct radeon_device *rdev)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	/* FIXME: is this correct ? */
558c2ecf20Sopenharmony_ci	r420_pipes_init(rdev);
568c2ecf20Sopenharmony_ci	if (rs690_mc_wait_for_idle(rdev)) {
578c2ecf20Sopenharmony_ci		pr_warn("Failed to wait MC idle while programming pipes. Bad things might happen.\n");
588c2ecf20Sopenharmony_ci	}
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciunion igp_info {
628c2ecf20Sopenharmony_ci	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
638c2ecf20Sopenharmony_ci	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_civoid rs690_pm_info(struct radeon_device *rdev)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
698c2ecf20Sopenharmony_ci	union igp_info *info;
708c2ecf20Sopenharmony_ci	uint16_t data_offset;
718c2ecf20Sopenharmony_ci	uint8_t frev, crev;
728c2ecf20Sopenharmony_ci	fixed20_12 tmp;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
758c2ecf20Sopenharmony_ci				   &frev, &crev, &data_offset)) {
768c2ecf20Sopenharmony_ci		info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci		/* Get various system informations from bios */
798c2ecf20Sopenharmony_ci		switch (crev) {
808c2ecf20Sopenharmony_ci		case 1:
818c2ecf20Sopenharmony_ci			tmp.full = dfixed_const(100);
828c2ecf20Sopenharmony_ci			rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info.ulBootUpMemoryClock));
838c2ecf20Sopenharmony_ci			rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
848c2ecf20Sopenharmony_ci			if (le16_to_cpu(info->info.usK8MemoryClock))
858c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
868c2ecf20Sopenharmony_ci			else if (rdev->clock.default_mclk) {
878c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
888c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
898c2ecf20Sopenharmony_ci			} else
908c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(400);
918c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_clk.full = dfixed_const(le16_to_cpu(info->info.usFSBClock));
928c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_width.full = dfixed_const(info->info.ucHTLinkWidth);
938c2ecf20Sopenharmony_ci			break;
948c2ecf20Sopenharmony_ci		case 2:
958c2ecf20Sopenharmony_ci			tmp.full = dfixed_const(100);
968c2ecf20Sopenharmony_ci			rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpSidePortClock));
978c2ecf20Sopenharmony_ci			rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
988c2ecf20Sopenharmony_ci			if (le32_to_cpu(info->info_v2.ulBootUpUMAClock))
998c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpUMAClock));
1008c2ecf20Sopenharmony_ci			else if (rdev->clock.default_mclk)
1018c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
1028c2ecf20Sopenharmony_ci			else
1038c2ecf20Sopenharmony_ci				rdev->pm.igp_system_mclk.full = dfixed_const(66700);
1048c2ecf20Sopenharmony_ci			rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
1058c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_clk.full = dfixed_const(le32_to_cpu(info->info_v2.ulHTLinkFreq));
1068c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_clk.full = dfixed_div(rdev->pm.igp_ht_link_clk, tmp);
1078c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_width.full = dfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
1088c2ecf20Sopenharmony_ci			break;
1098c2ecf20Sopenharmony_ci		default:
1108c2ecf20Sopenharmony_ci			/* We assume the slower possible clock ie worst case */
1118c2ecf20Sopenharmony_ci			rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
1128c2ecf20Sopenharmony_ci			rdev->pm.igp_system_mclk.full = dfixed_const(200);
1138c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
1148c2ecf20Sopenharmony_ci			rdev->pm.igp_ht_link_width.full = dfixed_const(8);
1158c2ecf20Sopenharmony_ci			DRM_ERROR("No integrated system info for your GPU, using safe default\n");
1168c2ecf20Sopenharmony_ci			break;
1178c2ecf20Sopenharmony_ci		}
1188c2ecf20Sopenharmony_ci	} else {
1198c2ecf20Sopenharmony_ci		/* We assume the slower possible clock ie worst case */
1208c2ecf20Sopenharmony_ci		rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
1218c2ecf20Sopenharmony_ci		rdev->pm.igp_system_mclk.full = dfixed_const(200);
1228c2ecf20Sopenharmony_ci		rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
1238c2ecf20Sopenharmony_ci		rdev->pm.igp_ht_link_width.full = dfixed_const(8);
1248c2ecf20Sopenharmony_ci		DRM_ERROR("No integrated system info for your GPU, using safe default\n");
1258c2ecf20Sopenharmony_ci	}
1268c2ecf20Sopenharmony_ci	/* Compute various bandwidth */
1278c2ecf20Sopenharmony_ci	/* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4  */
1288c2ecf20Sopenharmony_ci	tmp.full = dfixed_const(4);
1298c2ecf20Sopenharmony_ci	rdev->pm.k8_bandwidth.full = dfixed_mul(rdev->pm.igp_system_mclk, tmp);
1308c2ecf20Sopenharmony_ci	/* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
1318c2ecf20Sopenharmony_ci	 *              = ht_clk * ht_width / 5
1328c2ecf20Sopenharmony_ci	 */
1338c2ecf20Sopenharmony_ci	tmp.full = dfixed_const(5);
1348c2ecf20Sopenharmony_ci	rdev->pm.ht_bandwidth.full = dfixed_mul(rdev->pm.igp_ht_link_clk,
1358c2ecf20Sopenharmony_ci						rdev->pm.igp_ht_link_width);
1368c2ecf20Sopenharmony_ci	rdev->pm.ht_bandwidth.full = dfixed_div(rdev->pm.ht_bandwidth, tmp);
1378c2ecf20Sopenharmony_ci	if (tmp.full < rdev->pm.max_bandwidth.full) {
1388c2ecf20Sopenharmony_ci		/* HT link is a limiting factor */
1398c2ecf20Sopenharmony_ci		rdev->pm.max_bandwidth.full = tmp.full;
1408c2ecf20Sopenharmony_ci	}
1418c2ecf20Sopenharmony_ci	/* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
1428c2ecf20Sopenharmony_ci	 *                    = (sideport_clk * 14) / 10
1438c2ecf20Sopenharmony_ci	 */
1448c2ecf20Sopenharmony_ci	tmp.full = dfixed_const(14);
1458c2ecf20Sopenharmony_ci	rdev->pm.sideport_bandwidth.full = dfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
1468c2ecf20Sopenharmony_ci	tmp.full = dfixed_const(10);
1478c2ecf20Sopenharmony_ci	rdev->pm.sideport_bandwidth.full = dfixed_div(rdev->pm.sideport_bandwidth, tmp);
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic void rs690_mc_init(struct radeon_device *rdev)
1518c2ecf20Sopenharmony_ci{
1528c2ecf20Sopenharmony_ci	u64 base;
1538c2ecf20Sopenharmony_ci	uint32_t h_addr, l_addr;
1548c2ecf20Sopenharmony_ci	unsigned long long k8_addr;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	rs400_gart_adjust_size(rdev);
1578c2ecf20Sopenharmony_ci	rdev->mc.vram_is_ddr = true;
1588c2ecf20Sopenharmony_ci	rdev->mc.vram_width = 128;
1598c2ecf20Sopenharmony_ci	rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
1608c2ecf20Sopenharmony_ci	rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
1618c2ecf20Sopenharmony_ci	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1628c2ecf20Sopenharmony_ci	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
1638c2ecf20Sopenharmony_ci	rdev->mc.visible_vram_size = rdev->mc.aper_size;
1648c2ecf20Sopenharmony_ci	base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
1658c2ecf20Sopenharmony_ci	base = G_000100_MC_FB_START(base) << 16;
1668c2ecf20Sopenharmony_ci	rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
1678c2ecf20Sopenharmony_ci	/* Some boards seem to be configured for 128MB of sideport memory,
1688c2ecf20Sopenharmony_ci	 * but really only have 64MB.  Just skip the sideport and use
1698c2ecf20Sopenharmony_ci	 * UMA memory.
1708c2ecf20Sopenharmony_ci	 */
1718c2ecf20Sopenharmony_ci	if (rdev->mc.igp_sideport_enabled &&
1728c2ecf20Sopenharmony_ci	    (rdev->mc.real_vram_size == (384 * 1024 * 1024))) {
1738c2ecf20Sopenharmony_ci		base += 128 * 1024 * 1024;
1748c2ecf20Sopenharmony_ci		rdev->mc.real_vram_size -= 128 * 1024 * 1024;
1758c2ecf20Sopenharmony_ci		rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
1768c2ecf20Sopenharmony_ci	}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	/* Use K8 direct mapping for fast fb access. */
1798c2ecf20Sopenharmony_ci	rdev->fastfb_working = false;
1808c2ecf20Sopenharmony_ci	h_addr = G_00005F_K8_ADDR_EXT(RREG32_MC(R_00005F_MC_MISC_UMA_CNTL));
1818c2ecf20Sopenharmony_ci	l_addr = RREG32_MC(R_00001E_K8_FB_LOCATION);
1828c2ecf20Sopenharmony_ci	k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
1838c2ecf20Sopenharmony_ci#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
1848c2ecf20Sopenharmony_ci	if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
1858c2ecf20Sopenharmony_ci#endif
1868c2ecf20Sopenharmony_ci	{
1878c2ecf20Sopenharmony_ci		/* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
1888c2ecf20Sopenharmony_ci		 * memory is present.
1898c2ecf20Sopenharmony_ci		 */
1908c2ecf20Sopenharmony_ci		if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
1918c2ecf20Sopenharmony_ci			DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
1928c2ecf20Sopenharmony_ci					(unsigned long long)rdev->mc.aper_base, k8_addr);
1938c2ecf20Sopenharmony_ci			rdev->mc.aper_base = (resource_size_t)k8_addr;
1948c2ecf20Sopenharmony_ci			rdev->fastfb_working = true;
1958c2ecf20Sopenharmony_ci		}
1968c2ecf20Sopenharmony_ci	}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	rs690_pm_info(rdev);
1998c2ecf20Sopenharmony_ci	radeon_vram_location(rdev, &rdev->mc, base);
2008c2ecf20Sopenharmony_ci	rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
2018c2ecf20Sopenharmony_ci	radeon_gtt_location(rdev, &rdev->mc);
2028c2ecf20Sopenharmony_ci	radeon_update_bandwidth_info(rdev);
2038c2ecf20Sopenharmony_ci}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_civoid rs690_line_buffer_adjust(struct radeon_device *rdev,
2068c2ecf20Sopenharmony_ci			      struct drm_display_mode *mode1,
2078c2ecf20Sopenharmony_ci			      struct drm_display_mode *mode2)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	u32 tmp;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	/* Guess line buffer size to be 8192 pixels */
2128c2ecf20Sopenharmony_ci	u32 lb_size = 8192;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	/*
2158c2ecf20Sopenharmony_ci	 * Line Buffer Setup
2168c2ecf20Sopenharmony_ci	 * There is a single line buffer shared by both display controllers.
2178c2ecf20Sopenharmony_ci	 * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
2188c2ecf20Sopenharmony_ci	 * the display controllers.  The paritioning can either be done
2198c2ecf20Sopenharmony_ci	 * manually or via one of four preset allocations specified in bits 1:0:
2208c2ecf20Sopenharmony_ci	 *  0 - line buffer is divided in half and shared between crtc
2218c2ecf20Sopenharmony_ci	 *  1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
2228c2ecf20Sopenharmony_ci	 *  2 - D1 gets the whole buffer
2238c2ecf20Sopenharmony_ci	 *  3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
2248c2ecf20Sopenharmony_ci	 * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
2258c2ecf20Sopenharmony_ci	 * allocation mode. In manual allocation mode, D1 always starts at 0,
2268c2ecf20Sopenharmony_ci	 * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
2278c2ecf20Sopenharmony_ci	 */
2288c2ecf20Sopenharmony_ci	tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
2298c2ecf20Sopenharmony_ci	tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
2308c2ecf20Sopenharmony_ci	/* auto */
2318c2ecf20Sopenharmony_ci	if (mode1 && mode2) {
2328c2ecf20Sopenharmony_ci		if (mode1->hdisplay > mode2->hdisplay) {
2338c2ecf20Sopenharmony_ci			if (mode1->hdisplay > 2560)
2348c2ecf20Sopenharmony_ci				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
2358c2ecf20Sopenharmony_ci			else
2368c2ecf20Sopenharmony_ci				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
2378c2ecf20Sopenharmony_ci		} else if (mode2->hdisplay > mode1->hdisplay) {
2388c2ecf20Sopenharmony_ci			if (mode2->hdisplay > 2560)
2398c2ecf20Sopenharmony_ci				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
2408c2ecf20Sopenharmony_ci			else
2418c2ecf20Sopenharmony_ci				tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
2428c2ecf20Sopenharmony_ci		} else
2438c2ecf20Sopenharmony_ci			tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
2448c2ecf20Sopenharmony_ci	} else if (mode1) {
2458c2ecf20Sopenharmony_ci		tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
2468c2ecf20Sopenharmony_ci	} else if (mode2) {
2478c2ecf20Sopenharmony_ci		tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
2488c2ecf20Sopenharmony_ci	}
2498c2ecf20Sopenharmony_ci	WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	/* Save number of lines the linebuffer leads before the scanout */
2528c2ecf20Sopenharmony_ci	if (mode1)
2538c2ecf20Sopenharmony_ci		rdev->mode_info.crtcs[0]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode1->crtc_hdisplay);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	if (mode2)
2568c2ecf20Sopenharmony_ci		rdev->mode_info.crtcs[1]->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode2->crtc_hdisplay);
2578c2ecf20Sopenharmony_ci}
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistruct rs690_watermark {
2608c2ecf20Sopenharmony_ci	u32        lb_request_fifo_depth;
2618c2ecf20Sopenharmony_ci	fixed20_12 num_line_pair;
2628c2ecf20Sopenharmony_ci	fixed20_12 estimated_width;
2638c2ecf20Sopenharmony_ci	fixed20_12 worst_case_latency;
2648c2ecf20Sopenharmony_ci	fixed20_12 consumption_rate;
2658c2ecf20Sopenharmony_ci	fixed20_12 active_time;
2668c2ecf20Sopenharmony_ci	fixed20_12 dbpp;
2678c2ecf20Sopenharmony_ci	fixed20_12 priority_mark_max;
2688c2ecf20Sopenharmony_ci	fixed20_12 priority_mark;
2698c2ecf20Sopenharmony_ci	fixed20_12 sclk;
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistatic void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
2738c2ecf20Sopenharmony_ci					 struct radeon_crtc *crtc,
2748c2ecf20Sopenharmony_ci					 struct rs690_watermark *wm,
2758c2ecf20Sopenharmony_ci					 bool low)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	struct drm_display_mode *mode = &crtc->base.mode;
2788c2ecf20Sopenharmony_ci	fixed20_12 a, b, c;
2798c2ecf20Sopenharmony_ci	fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
2808c2ecf20Sopenharmony_ci	fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
2818c2ecf20Sopenharmony_ci	fixed20_12 sclk, core_bandwidth, max_bandwidth;
2828c2ecf20Sopenharmony_ci	u32 selected_sclk;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci	if (!crtc->base.enabled) {
2858c2ecf20Sopenharmony_ci		/* FIXME: wouldn't it better to set priority mark to maximum */
2868c2ecf20Sopenharmony_ci		wm->lb_request_fifo_depth = 4;
2878c2ecf20Sopenharmony_ci		return;
2888c2ecf20Sopenharmony_ci	}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	if (((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) &&
2918c2ecf20Sopenharmony_ci	    (rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
2928c2ecf20Sopenharmony_ci		selected_sclk = radeon_dpm_get_sclk(rdev, low);
2938c2ecf20Sopenharmony_ci	else
2948c2ecf20Sopenharmony_ci		selected_sclk = rdev->pm.current_sclk;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	/* sclk in Mhz */
2978c2ecf20Sopenharmony_ci	a.full = dfixed_const(100);
2988c2ecf20Sopenharmony_ci	sclk.full = dfixed_const(selected_sclk);
2998c2ecf20Sopenharmony_ci	sclk.full = dfixed_div(sclk, a);
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	/* core_bandwidth = sclk(Mhz) * 16 */
3028c2ecf20Sopenharmony_ci	a.full = dfixed_const(16);
3038c2ecf20Sopenharmony_ci	core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	if (crtc->vsc.full > dfixed_const(2))
3068c2ecf20Sopenharmony_ci		wm->num_line_pair.full = dfixed_const(2);
3078c2ecf20Sopenharmony_ci	else
3088c2ecf20Sopenharmony_ci		wm->num_line_pair.full = dfixed_const(1);
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	b.full = dfixed_const(mode->crtc_hdisplay);
3118c2ecf20Sopenharmony_ci	c.full = dfixed_const(256);
3128c2ecf20Sopenharmony_ci	a.full = dfixed_div(b, c);
3138c2ecf20Sopenharmony_ci	request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
3148c2ecf20Sopenharmony_ci	request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
3158c2ecf20Sopenharmony_ci	if (a.full < dfixed_const(4)) {
3168c2ecf20Sopenharmony_ci		wm->lb_request_fifo_depth = 4;
3178c2ecf20Sopenharmony_ci	} else {
3188c2ecf20Sopenharmony_ci		wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
3198c2ecf20Sopenharmony_ci	}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	/* Determine consumption rate
3228c2ecf20Sopenharmony_ci	 *  pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
3238c2ecf20Sopenharmony_ci	 *  vtaps = number of vertical taps,
3248c2ecf20Sopenharmony_ci	 *  vsc = vertical scaling ratio, defined as source/destination
3258c2ecf20Sopenharmony_ci	 *  hsc = horizontal scaling ration, defined as source/destination
3268c2ecf20Sopenharmony_ci	 */
3278c2ecf20Sopenharmony_ci	a.full = dfixed_const(mode->clock);
3288c2ecf20Sopenharmony_ci	b.full = dfixed_const(1000);
3298c2ecf20Sopenharmony_ci	a.full = dfixed_div(a, b);
3308c2ecf20Sopenharmony_ci	pclk.full = dfixed_div(b, a);
3318c2ecf20Sopenharmony_ci	if (crtc->rmx_type != RMX_OFF) {
3328c2ecf20Sopenharmony_ci		b.full = dfixed_const(2);
3338c2ecf20Sopenharmony_ci		if (crtc->vsc.full > b.full)
3348c2ecf20Sopenharmony_ci			b.full = crtc->vsc.full;
3358c2ecf20Sopenharmony_ci		b.full = dfixed_mul(b, crtc->hsc);
3368c2ecf20Sopenharmony_ci		c.full = dfixed_const(2);
3378c2ecf20Sopenharmony_ci		b.full = dfixed_div(b, c);
3388c2ecf20Sopenharmony_ci		consumption_time.full = dfixed_div(pclk, b);
3398c2ecf20Sopenharmony_ci	} else {
3408c2ecf20Sopenharmony_ci		consumption_time.full = pclk.full;
3418c2ecf20Sopenharmony_ci	}
3428c2ecf20Sopenharmony_ci	a.full = dfixed_const(1);
3438c2ecf20Sopenharmony_ci	wm->consumption_rate.full = dfixed_div(a, consumption_time);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	/* Determine line time
3478c2ecf20Sopenharmony_ci	 *  LineTime = total time for one line of displayhtotal
3488c2ecf20Sopenharmony_ci	 *  LineTime = total number of horizontal pixels
3498c2ecf20Sopenharmony_ci	 *  pclk = pixel clock period(ns)
3508c2ecf20Sopenharmony_ci	 */
3518c2ecf20Sopenharmony_ci	a.full = dfixed_const(crtc->base.mode.crtc_htotal);
3528c2ecf20Sopenharmony_ci	line_time.full = dfixed_mul(a, pclk);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	/* Determine active time
3558c2ecf20Sopenharmony_ci	 *  ActiveTime = time of active region of display within one line,
3568c2ecf20Sopenharmony_ci	 *  hactive = total number of horizontal active pixels
3578c2ecf20Sopenharmony_ci	 *  htotal = total number of horizontal pixels
3588c2ecf20Sopenharmony_ci	 */
3598c2ecf20Sopenharmony_ci	a.full = dfixed_const(crtc->base.mode.crtc_htotal);
3608c2ecf20Sopenharmony_ci	b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
3618c2ecf20Sopenharmony_ci	wm->active_time.full = dfixed_mul(line_time, b);
3628c2ecf20Sopenharmony_ci	wm->active_time.full = dfixed_div(wm->active_time, a);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	/* Maximun bandwidth is the minimun bandwidth of all component */
3658c2ecf20Sopenharmony_ci	max_bandwidth = core_bandwidth;
3668c2ecf20Sopenharmony_ci	if (rdev->mc.igp_sideport_enabled) {
3678c2ecf20Sopenharmony_ci		if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
3688c2ecf20Sopenharmony_ci			rdev->pm.sideport_bandwidth.full)
3698c2ecf20Sopenharmony_ci			max_bandwidth = rdev->pm.sideport_bandwidth;
3708c2ecf20Sopenharmony_ci		read_delay_latency.full = dfixed_const(370 * 800);
3718c2ecf20Sopenharmony_ci		a.full = dfixed_const(1000);
3728c2ecf20Sopenharmony_ci		b.full = dfixed_div(rdev->pm.igp_sideport_mclk, a);
3738c2ecf20Sopenharmony_ci		read_delay_latency.full = dfixed_div(read_delay_latency, b);
3748c2ecf20Sopenharmony_ci		read_delay_latency.full = dfixed_mul(read_delay_latency, a);
3758c2ecf20Sopenharmony_ci	} else {
3768c2ecf20Sopenharmony_ci		if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
3778c2ecf20Sopenharmony_ci			rdev->pm.k8_bandwidth.full)
3788c2ecf20Sopenharmony_ci			max_bandwidth = rdev->pm.k8_bandwidth;
3798c2ecf20Sopenharmony_ci		if (max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
3808c2ecf20Sopenharmony_ci			rdev->pm.ht_bandwidth.full)
3818c2ecf20Sopenharmony_ci			max_bandwidth = rdev->pm.ht_bandwidth;
3828c2ecf20Sopenharmony_ci		read_delay_latency.full = dfixed_const(5000);
3838c2ecf20Sopenharmony_ci	}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	/* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
3868c2ecf20Sopenharmony_ci	a.full = dfixed_const(16);
3878c2ecf20Sopenharmony_ci	sclk.full = dfixed_mul(max_bandwidth, a);
3888c2ecf20Sopenharmony_ci	a.full = dfixed_const(1000);
3898c2ecf20Sopenharmony_ci	sclk.full = dfixed_div(a, sclk);
3908c2ecf20Sopenharmony_ci	/* Determine chunk time
3918c2ecf20Sopenharmony_ci	 * ChunkTime = the time it takes the DCP to send one chunk of data
3928c2ecf20Sopenharmony_ci	 * to the LB which consists of pipeline delay and inter chunk gap
3938c2ecf20Sopenharmony_ci	 * sclk = system clock(ns)
3948c2ecf20Sopenharmony_ci	 */
3958c2ecf20Sopenharmony_ci	a.full = dfixed_const(256 * 13);
3968c2ecf20Sopenharmony_ci	chunk_time.full = dfixed_mul(sclk, a);
3978c2ecf20Sopenharmony_ci	a.full = dfixed_const(10);
3988c2ecf20Sopenharmony_ci	chunk_time.full = dfixed_div(chunk_time, a);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	/* Determine the worst case latency
4018c2ecf20Sopenharmony_ci	 * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
4028c2ecf20Sopenharmony_ci	 * WorstCaseLatency = worst case time from urgent to when the MC starts
4038c2ecf20Sopenharmony_ci	 *                    to return data
4048c2ecf20Sopenharmony_ci	 * READ_DELAY_IDLE_MAX = constant of 1us
4058c2ecf20Sopenharmony_ci	 * ChunkTime = time it takes the DCP to send one chunk of data to the LB
4068c2ecf20Sopenharmony_ci	 *             which consists of pipeline delay and inter chunk gap
4078c2ecf20Sopenharmony_ci	 */
4088c2ecf20Sopenharmony_ci	if (dfixed_trunc(wm->num_line_pair) > 1) {
4098c2ecf20Sopenharmony_ci		a.full = dfixed_const(3);
4108c2ecf20Sopenharmony_ci		wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
4118c2ecf20Sopenharmony_ci		wm->worst_case_latency.full += read_delay_latency.full;
4128c2ecf20Sopenharmony_ci	} else {
4138c2ecf20Sopenharmony_ci		a.full = dfixed_const(2);
4148c2ecf20Sopenharmony_ci		wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
4158c2ecf20Sopenharmony_ci		wm->worst_case_latency.full += read_delay_latency.full;
4168c2ecf20Sopenharmony_ci	}
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	/* Determine the tolerable latency
4198c2ecf20Sopenharmony_ci	 * TolerableLatency = Any given request has only 1 line time
4208c2ecf20Sopenharmony_ci	 *                    for the data to be returned
4218c2ecf20Sopenharmony_ci	 * LBRequestFifoDepth = Number of chunk requests the LB can
4228c2ecf20Sopenharmony_ci	 *                      put into the request FIFO for a display
4238c2ecf20Sopenharmony_ci	 *  LineTime = total time for one line of display
4248c2ecf20Sopenharmony_ci	 *  ChunkTime = the time it takes the DCP to send one chunk
4258c2ecf20Sopenharmony_ci	 *              of data to the LB which consists of
4268c2ecf20Sopenharmony_ci	 *  pipeline delay and inter chunk gap
4278c2ecf20Sopenharmony_ci	 */
4288c2ecf20Sopenharmony_ci	if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
4298c2ecf20Sopenharmony_ci		tolerable_latency.full = line_time.full;
4308c2ecf20Sopenharmony_ci	} else {
4318c2ecf20Sopenharmony_ci		tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
4328c2ecf20Sopenharmony_ci		tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
4338c2ecf20Sopenharmony_ci		tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
4348c2ecf20Sopenharmony_ci		tolerable_latency.full = line_time.full - tolerable_latency.full;
4358c2ecf20Sopenharmony_ci	}
4368c2ecf20Sopenharmony_ci	/* We assume worst case 32bits (4 bytes) */
4378c2ecf20Sopenharmony_ci	wm->dbpp.full = dfixed_const(4 * 8);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	/* Determine the maximum priority mark
4408c2ecf20Sopenharmony_ci	 *  width = viewport width in pixels
4418c2ecf20Sopenharmony_ci	 */
4428c2ecf20Sopenharmony_ci	a.full = dfixed_const(16);
4438c2ecf20Sopenharmony_ci	wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
4448c2ecf20Sopenharmony_ci	wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
4458c2ecf20Sopenharmony_ci	wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	/* Determine estimated width */
4488c2ecf20Sopenharmony_ci	estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
4498c2ecf20Sopenharmony_ci	estimated_width.full = dfixed_div(estimated_width, consumption_time);
4508c2ecf20Sopenharmony_ci	if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
4518c2ecf20Sopenharmony_ci		wm->priority_mark.full = dfixed_const(10);
4528c2ecf20Sopenharmony_ci	} else {
4538c2ecf20Sopenharmony_ci		a.full = dfixed_const(16);
4548c2ecf20Sopenharmony_ci		wm->priority_mark.full = dfixed_div(estimated_width, a);
4558c2ecf20Sopenharmony_ci		wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
4568c2ecf20Sopenharmony_ci		wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
4578c2ecf20Sopenharmony_ci	}
4588c2ecf20Sopenharmony_ci}
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_cistatic void rs690_compute_mode_priority(struct radeon_device *rdev,
4618c2ecf20Sopenharmony_ci					struct rs690_watermark *wm0,
4628c2ecf20Sopenharmony_ci					struct rs690_watermark *wm1,
4638c2ecf20Sopenharmony_ci					struct drm_display_mode *mode0,
4648c2ecf20Sopenharmony_ci					struct drm_display_mode *mode1,
4658c2ecf20Sopenharmony_ci					u32 *d1mode_priority_a_cnt,
4668c2ecf20Sopenharmony_ci					u32 *d2mode_priority_a_cnt)
4678c2ecf20Sopenharmony_ci{
4688c2ecf20Sopenharmony_ci	fixed20_12 priority_mark02, priority_mark12, fill_rate;
4698c2ecf20Sopenharmony_ci	fixed20_12 a, b;
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	*d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
4728c2ecf20Sopenharmony_ci	*d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	if (mode0 && mode1) {
4758c2ecf20Sopenharmony_ci		if (dfixed_trunc(wm0->dbpp) > 64)
4768c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
4778c2ecf20Sopenharmony_ci		else
4788c2ecf20Sopenharmony_ci			a.full = wm0->num_line_pair.full;
4798c2ecf20Sopenharmony_ci		if (dfixed_trunc(wm1->dbpp) > 64)
4808c2ecf20Sopenharmony_ci			b.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
4818c2ecf20Sopenharmony_ci		else
4828c2ecf20Sopenharmony_ci			b.full = wm1->num_line_pair.full;
4838c2ecf20Sopenharmony_ci		a.full += b.full;
4848c2ecf20Sopenharmony_ci		fill_rate.full = dfixed_div(wm0->sclk, a);
4858c2ecf20Sopenharmony_ci		if (wm0->consumption_rate.full > fill_rate.full) {
4868c2ecf20Sopenharmony_ci			b.full = wm0->consumption_rate.full - fill_rate.full;
4878c2ecf20Sopenharmony_ci			b.full = dfixed_mul(b, wm0->active_time);
4888c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->worst_case_latency,
4898c2ecf20Sopenharmony_ci						wm0->consumption_rate);
4908c2ecf20Sopenharmony_ci			a.full = a.full + b.full;
4918c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
4928c2ecf20Sopenharmony_ci			priority_mark02.full = dfixed_div(a, b);
4938c2ecf20Sopenharmony_ci		} else {
4948c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->worst_case_latency,
4958c2ecf20Sopenharmony_ci						wm0->consumption_rate);
4968c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
4978c2ecf20Sopenharmony_ci			priority_mark02.full = dfixed_div(a, b);
4988c2ecf20Sopenharmony_ci		}
4998c2ecf20Sopenharmony_ci		if (wm1->consumption_rate.full > fill_rate.full) {
5008c2ecf20Sopenharmony_ci			b.full = wm1->consumption_rate.full - fill_rate.full;
5018c2ecf20Sopenharmony_ci			b.full = dfixed_mul(b, wm1->active_time);
5028c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm1->worst_case_latency,
5038c2ecf20Sopenharmony_ci						wm1->consumption_rate);
5048c2ecf20Sopenharmony_ci			a.full = a.full + b.full;
5058c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5068c2ecf20Sopenharmony_ci			priority_mark12.full = dfixed_div(a, b);
5078c2ecf20Sopenharmony_ci		} else {
5088c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm1->worst_case_latency,
5098c2ecf20Sopenharmony_ci						wm1->consumption_rate);
5108c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5118c2ecf20Sopenharmony_ci			priority_mark12.full = dfixed_div(a, b);
5128c2ecf20Sopenharmony_ci		}
5138c2ecf20Sopenharmony_ci		if (wm0->priority_mark.full > priority_mark02.full)
5148c2ecf20Sopenharmony_ci			priority_mark02.full = wm0->priority_mark.full;
5158c2ecf20Sopenharmony_ci		if (wm0->priority_mark_max.full > priority_mark02.full)
5168c2ecf20Sopenharmony_ci			priority_mark02.full = wm0->priority_mark_max.full;
5178c2ecf20Sopenharmony_ci		if (wm1->priority_mark.full > priority_mark12.full)
5188c2ecf20Sopenharmony_ci			priority_mark12.full = wm1->priority_mark.full;
5198c2ecf20Sopenharmony_ci		if (wm1->priority_mark_max.full > priority_mark12.full)
5208c2ecf20Sopenharmony_ci			priority_mark12.full = wm1->priority_mark_max.full;
5218c2ecf20Sopenharmony_ci		*d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
5228c2ecf20Sopenharmony_ci		*d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
5238c2ecf20Sopenharmony_ci		if (rdev->disp_priority == 2) {
5248c2ecf20Sopenharmony_ci			*d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
5258c2ecf20Sopenharmony_ci			*d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
5268c2ecf20Sopenharmony_ci		}
5278c2ecf20Sopenharmony_ci	} else if (mode0) {
5288c2ecf20Sopenharmony_ci		if (dfixed_trunc(wm0->dbpp) > 64)
5298c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
5308c2ecf20Sopenharmony_ci		else
5318c2ecf20Sopenharmony_ci			a.full = wm0->num_line_pair.full;
5328c2ecf20Sopenharmony_ci		fill_rate.full = dfixed_div(wm0->sclk, a);
5338c2ecf20Sopenharmony_ci		if (wm0->consumption_rate.full > fill_rate.full) {
5348c2ecf20Sopenharmony_ci			b.full = wm0->consumption_rate.full - fill_rate.full;
5358c2ecf20Sopenharmony_ci			b.full = dfixed_mul(b, wm0->active_time);
5368c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->worst_case_latency,
5378c2ecf20Sopenharmony_ci						wm0->consumption_rate);
5388c2ecf20Sopenharmony_ci			a.full = a.full + b.full;
5398c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5408c2ecf20Sopenharmony_ci			priority_mark02.full = dfixed_div(a, b);
5418c2ecf20Sopenharmony_ci		} else {
5428c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm0->worst_case_latency,
5438c2ecf20Sopenharmony_ci						wm0->consumption_rate);
5448c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5458c2ecf20Sopenharmony_ci			priority_mark02.full = dfixed_div(a, b);
5468c2ecf20Sopenharmony_ci		}
5478c2ecf20Sopenharmony_ci		if (wm0->priority_mark.full > priority_mark02.full)
5488c2ecf20Sopenharmony_ci			priority_mark02.full = wm0->priority_mark.full;
5498c2ecf20Sopenharmony_ci		if (wm0->priority_mark_max.full > priority_mark02.full)
5508c2ecf20Sopenharmony_ci			priority_mark02.full = wm0->priority_mark_max.full;
5518c2ecf20Sopenharmony_ci		*d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
5528c2ecf20Sopenharmony_ci		if (rdev->disp_priority == 2)
5538c2ecf20Sopenharmony_ci			*d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
5548c2ecf20Sopenharmony_ci	} else if (mode1) {
5558c2ecf20Sopenharmony_ci		if (dfixed_trunc(wm1->dbpp) > 64)
5568c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
5578c2ecf20Sopenharmony_ci		else
5588c2ecf20Sopenharmony_ci			a.full = wm1->num_line_pair.full;
5598c2ecf20Sopenharmony_ci		fill_rate.full = dfixed_div(wm1->sclk, a);
5608c2ecf20Sopenharmony_ci		if (wm1->consumption_rate.full > fill_rate.full) {
5618c2ecf20Sopenharmony_ci			b.full = wm1->consumption_rate.full - fill_rate.full;
5628c2ecf20Sopenharmony_ci			b.full = dfixed_mul(b, wm1->active_time);
5638c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm1->worst_case_latency,
5648c2ecf20Sopenharmony_ci						wm1->consumption_rate);
5658c2ecf20Sopenharmony_ci			a.full = a.full + b.full;
5668c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5678c2ecf20Sopenharmony_ci			priority_mark12.full = dfixed_div(a, b);
5688c2ecf20Sopenharmony_ci		} else {
5698c2ecf20Sopenharmony_ci			a.full = dfixed_mul(wm1->worst_case_latency,
5708c2ecf20Sopenharmony_ci						wm1->consumption_rate);
5718c2ecf20Sopenharmony_ci			b.full = dfixed_const(16 * 1000);
5728c2ecf20Sopenharmony_ci			priority_mark12.full = dfixed_div(a, b);
5738c2ecf20Sopenharmony_ci		}
5748c2ecf20Sopenharmony_ci		if (wm1->priority_mark.full > priority_mark12.full)
5758c2ecf20Sopenharmony_ci			priority_mark12.full = wm1->priority_mark.full;
5768c2ecf20Sopenharmony_ci		if (wm1->priority_mark_max.full > priority_mark12.full)
5778c2ecf20Sopenharmony_ci			priority_mark12.full = wm1->priority_mark_max.full;
5788c2ecf20Sopenharmony_ci		*d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
5798c2ecf20Sopenharmony_ci		if (rdev->disp_priority == 2)
5808c2ecf20Sopenharmony_ci			*d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
5818c2ecf20Sopenharmony_ci	}
5828c2ecf20Sopenharmony_ci}
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_civoid rs690_bandwidth_update(struct radeon_device *rdev)
5858c2ecf20Sopenharmony_ci{
5868c2ecf20Sopenharmony_ci	struct drm_display_mode *mode0 = NULL;
5878c2ecf20Sopenharmony_ci	struct drm_display_mode *mode1 = NULL;
5888c2ecf20Sopenharmony_ci	struct rs690_watermark wm0_high, wm0_low;
5898c2ecf20Sopenharmony_ci	struct rs690_watermark wm1_high, wm1_low;
5908c2ecf20Sopenharmony_ci	u32 tmp;
5918c2ecf20Sopenharmony_ci	u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt;
5928c2ecf20Sopenharmony_ci	u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt;
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	if (!rdev->mode_info.mode_config_initialized)
5958c2ecf20Sopenharmony_ci		return;
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	radeon_update_display_priority(rdev);
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	if (rdev->mode_info.crtcs[0]->base.enabled)
6008c2ecf20Sopenharmony_ci		mode0 = &rdev->mode_info.crtcs[0]->base.mode;
6018c2ecf20Sopenharmony_ci	if (rdev->mode_info.crtcs[1]->base.enabled)
6028c2ecf20Sopenharmony_ci		mode1 = &rdev->mode_info.crtcs[1]->base.mode;
6038c2ecf20Sopenharmony_ci	/*
6048c2ecf20Sopenharmony_ci	 * Set display0/1 priority up in the memory controller for
6058c2ecf20Sopenharmony_ci	 * modes if the user specifies HIGH for displaypriority
6068c2ecf20Sopenharmony_ci	 * option.
6078c2ecf20Sopenharmony_ci	 */
6088c2ecf20Sopenharmony_ci	if ((rdev->disp_priority == 2) &&
6098c2ecf20Sopenharmony_ci	    ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
6108c2ecf20Sopenharmony_ci		tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
6118c2ecf20Sopenharmony_ci		tmp &= C_000104_MC_DISP0R_INIT_LAT;
6128c2ecf20Sopenharmony_ci		tmp &= C_000104_MC_DISP1R_INIT_LAT;
6138c2ecf20Sopenharmony_ci		if (mode0)
6148c2ecf20Sopenharmony_ci			tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
6158c2ecf20Sopenharmony_ci		if (mode1)
6168c2ecf20Sopenharmony_ci			tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
6178c2ecf20Sopenharmony_ci		WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
6188c2ecf20Sopenharmony_ci	}
6198c2ecf20Sopenharmony_ci	rs690_line_buffer_adjust(rdev, mode0, mode1);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
6228c2ecf20Sopenharmony_ci		WREG32(R_006C9C_DCP_CONTROL, 0);
6238c2ecf20Sopenharmony_ci	if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
6248c2ecf20Sopenharmony_ci		WREG32(R_006C9C_DCP_CONTROL, 2);
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_high, false);
6278c2ecf20Sopenharmony_ci	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_high, false);
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_low, true);
6308c2ecf20Sopenharmony_ci	rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_low, true);
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci	tmp = (wm0_high.lb_request_fifo_depth - 1);
6338c2ecf20Sopenharmony_ci	tmp |= (wm1_high.lb_request_fifo_depth - 1) << 16;
6348c2ecf20Sopenharmony_ci	WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci	rs690_compute_mode_priority(rdev,
6378c2ecf20Sopenharmony_ci				    &wm0_high, &wm1_high,
6388c2ecf20Sopenharmony_ci				    mode0, mode1,
6398c2ecf20Sopenharmony_ci				    &d1mode_priority_a_cnt, &d2mode_priority_a_cnt);
6408c2ecf20Sopenharmony_ci	rs690_compute_mode_priority(rdev,
6418c2ecf20Sopenharmony_ci				    &wm0_low, &wm1_low,
6428c2ecf20Sopenharmony_ci				    mode0, mode1,
6438c2ecf20Sopenharmony_ci				    &d1mode_priority_b_cnt, &d2mode_priority_b_cnt);
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci	WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
6468c2ecf20Sopenharmony_ci	WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_b_cnt);
6478c2ecf20Sopenharmony_ci	WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
6488c2ecf20Sopenharmony_ci	WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_b_cnt);
6498c2ecf20Sopenharmony_ci}
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ciuint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
6528c2ecf20Sopenharmony_ci{
6538c2ecf20Sopenharmony_ci	unsigned long flags;
6548c2ecf20Sopenharmony_ci	uint32_t r;
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->mc_idx_lock, flags);
6578c2ecf20Sopenharmony_ci	WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
6588c2ecf20Sopenharmony_ci	r = RREG32(R_00007C_MC_DATA);
6598c2ecf20Sopenharmony_ci	WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
6608c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
6618c2ecf20Sopenharmony_ci	return r;
6628c2ecf20Sopenharmony_ci}
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_civoid rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
6658c2ecf20Sopenharmony_ci{
6668c2ecf20Sopenharmony_ci	unsigned long flags;
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rdev->mc_idx_lock, flags);
6698c2ecf20Sopenharmony_ci	WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
6708c2ecf20Sopenharmony_ci		S_000078_MC_IND_WR_EN(1));
6718c2ecf20Sopenharmony_ci	WREG32(R_00007C_MC_DATA, v);
6728c2ecf20Sopenharmony_ci	WREG32(R_000078_MC_INDEX, 0x7F);
6738c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
6748c2ecf20Sopenharmony_ci}
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_cistatic void rs690_mc_program(struct radeon_device *rdev)
6778c2ecf20Sopenharmony_ci{
6788c2ecf20Sopenharmony_ci	struct rv515_mc_save save;
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	/* Stops all mc clients */
6818c2ecf20Sopenharmony_ci	rv515_mc_stop(rdev, &save);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	/* Wait for mc idle */
6848c2ecf20Sopenharmony_ci	if (rs690_mc_wait_for_idle(rdev))
6858c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
6868c2ecf20Sopenharmony_ci	/* Program MC, should be a 32bits limited address space */
6878c2ecf20Sopenharmony_ci	WREG32_MC(R_000100_MCCFG_FB_LOCATION,
6888c2ecf20Sopenharmony_ci			S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
6898c2ecf20Sopenharmony_ci			S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
6908c2ecf20Sopenharmony_ci	WREG32(R_000134_HDP_FB_LOCATION,
6918c2ecf20Sopenharmony_ci		S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_ci	rv515_mc_resume(rdev, &save);
6948c2ecf20Sopenharmony_ci}
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_cistatic int rs690_startup(struct radeon_device *rdev)
6978c2ecf20Sopenharmony_ci{
6988c2ecf20Sopenharmony_ci	int r;
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci	rs690_mc_program(rdev);
7018c2ecf20Sopenharmony_ci	/* Resume clock */
7028c2ecf20Sopenharmony_ci	rv515_clock_startup(rdev);
7038c2ecf20Sopenharmony_ci	/* Initialize GPU configuration (# pipes, ...) */
7048c2ecf20Sopenharmony_ci	rs690_gpu_init(rdev);
7058c2ecf20Sopenharmony_ci	/* Initialize GART (initialize after TTM so we can allocate
7068c2ecf20Sopenharmony_ci	 * memory through TTM but finalize after TTM) */
7078c2ecf20Sopenharmony_ci	r = rs400_gart_enable(rdev);
7088c2ecf20Sopenharmony_ci	if (r)
7098c2ecf20Sopenharmony_ci		return r;
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	/* allocate wb buffer */
7128c2ecf20Sopenharmony_ci	r = radeon_wb_init(rdev);
7138c2ecf20Sopenharmony_ci	if (r)
7148c2ecf20Sopenharmony_ci		return r;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
7178c2ecf20Sopenharmony_ci	if (r) {
7188c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
7198c2ecf20Sopenharmony_ci		return r;
7208c2ecf20Sopenharmony_ci	}
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	/* Enable IRQ */
7238c2ecf20Sopenharmony_ci	if (!rdev->irq.installed) {
7248c2ecf20Sopenharmony_ci		r = radeon_irq_kms_init(rdev);
7258c2ecf20Sopenharmony_ci		if (r)
7268c2ecf20Sopenharmony_ci			return r;
7278c2ecf20Sopenharmony_ci	}
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	rs600_irq_set(rdev);
7308c2ecf20Sopenharmony_ci	rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
7318c2ecf20Sopenharmony_ci	/* 1M ring buffer */
7328c2ecf20Sopenharmony_ci	r = r100_cp_init(rdev, 1024 * 1024);
7338c2ecf20Sopenharmony_ci	if (r) {
7348c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
7358c2ecf20Sopenharmony_ci		return r;
7368c2ecf20Sopenharmony_ci	}
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci	r = radeon_ib_pool_init(rdev);
7398c2ecf20Sopenharmony_ci	if (r) {
7408c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
7418c2ecf20Sopenharmony_ci		return r;
7428c2ecf20Sopenharmony_ci	}
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	r = radeon_audio_init(rdev);
7458c2ecf20Sopenharmony_ci	if (r) {
7468c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing audio\n");
7478c2ecf20Sopenharmony_ci		return r;
7488c2ecf20Sopenharmony_ci	}
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	return 0;
7518c2ecf20Sopenharmony_ci}
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ciint rs690_resume(struct radeon_device *rdev)
7548c2ecf20Sopenharmony_ci{
7558c2ecf20Sopenharmony_ci	int r;
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	/* Make sur GART are not working */
7588c2ecf20Sopenharmony_ci	rs400_gart_disable(rdev);
7598c2ecf20Sopenharmony_ci	/* Resume clock before doing reset */
7608c2ecf20Sopenharmony_ci	rv515_clock_startup(rdev);
7618c2ecf20Sopenharmony_ci	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
7628c2ecf20Sopenharmony_ci	if (radeon_asic_reset(rdev)) {
7638c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
7648c2ecf20Sopenharmony_ci			RREG32(R_000E40_RBBM_STATUS),
7658c2ecf20Sopenharmony_ci			RREG32(R_0007C0_CP_STAT));
7668c2ecf20Sopenharmony_ci	}
7678c2ecf20Sopenharmony_ci	/* post */
7688c2ecf20Sopenharmony_ci	atom_asic_init(rdev->mode_info.atom_context);
7698c2ecf20Sopenharmony_ci	/* Resume clock after posting */
7708c2ecf20Sopenharmony_ci	rv515_clock_startup(rdev);
7718c2ecf20Sopenharmony_ci	/* Initialize surface registers */
7728c2ecf20Sopenharmony_ci	radeon_surface_init(rdev);
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	rdev->accel_working = true;
7758c2ecf20Sopenharmony_ci	r = rs690_startup(rdev);
7768c2ecf20Sopenharmony_ci	if (r) {
7778c2ecf20Sopenharmony_ci		rdev->accel_working = false;
7788c2ecf20Sopenharmony_ci	}
7798c2ecf20Sopenharmony_ci	return r;
7808c2ecf20Sopenharmony_ci}
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ciint rs690_suspend(struct radeon_device *rdev)
7838c2ecf20Sopenharmony_ci{
7848c2ecf20Sopenharmony_ci	radeon_pm_suspend(rdev);
7858c2ecf20Sopenharmony_ci	radeon_audio_fini(rdev);
7868c2ecf20Sopenharmony_ci	r100_cp_disable(rdev);
7878c2ecf20Sopenharmony_ci	radeon_wb_disable(rdev);
7888c2ecf20Sopenharmony_ci	rs600_irq_disable(rdev);
7898c2ecf20Sopenharmony_ci	rs400_gart_disable(rdev);
7908c2ecf20Sopenharmony_ci	return 0;
7918c2ecf20Sopenharmony_ci}
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_civoid rs690_fini(struct radeon_device *rdev)
7948c2ecf20Sopenharmony_ci{
7958c2ecf20Sopenharmony_ci	radeon_pm_fini(rdev);
7968c2ecf20Sopenharmony_ci	radeon_audio_fini(rdev);
7978c2ecf20Sopenharmony_ci	r100_cp_fini(rdev);
7988c2ecf20Sopenharmony_ci	radeon_wb_fini(rdev);
7998c2ecf20Sopenharmony_ci	radeon_ib_pool_fini(rdev);
8008c2ecf20Sopenharmony_ci	radeon_gem_fini(rdev);
8018c2ecf20Sopenharmony_ci	rs400_gart_fini(rdev);
8028c2ecf20Sopenharmony_ci	radeon_irq_kms_fini(rdev);
8038c2ecf20Sopenharmony_ci	radeon_fence_driver_fini(rdev);
8048c2ecf20Sopenharmony_ci	radeon_bo_fini(rdev);
8058c2ecf20Sopenharmony_ci	radeon_atombios_fini(rdev);
8068c2ecf20Sopenharmony_ci	kfree(rdev->bios);
8078c2ecf20Sopenharmony_ci	rdev->bios = NULL;
8088c2ecf20Sopenharmony_ci}
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ciint rs690_init(struct radeon_device *rdev)
8118c2ecf20Sopenharmony_ci{
8128c2ecf20Sopenharmony_ci	int r;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	/* Disable VGA */
8158c2ecf20Sopenharmony_ci	rv515_vga_render_disable(rdev);
8168c2ecf20Sopenharmony_ci	/* Initialize scratch registers */
8178c2ecf20Sopenharmony_ci	radeon_scratch_init(rdev);
8188c2ecf20Sopenharmony_ci	/* Initialize surface registers */
8198c2ecf20Sopenharmony_ci	radeon_surface_init(rdev);
8208c2ecf20Sopenharmony_ci	/* restore some register to sane defaults */
8218c2ecf20Sopenharmony_ci	r100_restore_sanity(rdev);
8228c2ecf20Sopenharmony_ci	/* TODO: disable VGA need to use VGA request */
8238c2ecf20Sopenharmony_ci	/* BIOS*/
8248c2ecf20Sopenharmony_ci	if (!radeon_get_bios(rdev)) {
8258c2ecf20Sopenharmony_ci		if (ASIC_IS_AVIVO(rdev))
8268c2ecf20Sopenharmony_ci			return -EINVAL;
8278c2ecf20Sopenharmony_ci	}
8288c2ecf20Sopenharmony_ci	if (rdev->is_atom_bios) {
8298c2ecf20Sopenharmony_ci		r = radeon_atombios_init(rdev);
8308c2ecf20Sopenharmony_ci		if (r)
8318c2ecf20Sopenharmony_ci			return r;
8328c2ecf20Sopenharmony_ci	} else {
8338c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
8348c2ecf20Sopenharmony_ci		return -EINVAL;
8358c2ecf20Sopenharmony_ci	}
8368c2ecf20Sopenharmony_ci	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
8378c2ecf20Sopenharmony_ci	if (radeon_asic_reset(rdev)) {
8388c2ecf20Sopenharmony_ci		dev_warn(rdev->dev,
8398c2ecf20Sopenharmony_ci			"GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
8408c2ecf20Sopenharmony_ci			RREG32(R_000E40_RBBM_STATUS),
8418c2ecf20Sopenharmony_ci			RREG32(R_0007C0_CP_STAT));
8428c2ecf20Sopenharmony_ci	}
8438c2ecf20Sopenharmony_ci	/* check if cards are posted or not */
8448c2ecf20Sopenharmony_ci	if (radeon_boot_test_post_card(rdev) == false)
8458c2ecf20Sopenharmony_ci		return -EINVAL;
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	/* Initialize clocks */
8488c2ecf20Sopenharmony_ci	radeon_get_clock_info(rdev->ddev);
8498c2ecf20Sopenharmony_ci	/* initialize memory controller */
8508c2ecf20Sopenharmony_ci	rs690_mc_init(rdev);
8518c2ecf20Sopenharmony_ci	rv515_debugfs(rdev);
8528c2ecf20Sopenharmony_ci	/* Fence driver */
8538c2ecf20Sopenharmony_ci	r = radeon_fence_driver_init(rdev);
8548c2ecf20Sopenharmony_ci	if (r)
8558c2ecf20Sopenharmony_ci		return r;
8568c2ecf20Sopenharmony_ci	/* Memory manager */
8578c2ecf20Sopenharmony_ci	r = radeon_bo_init(rdev);
8588c2ecf20Sopenharmony_ci	if (r)
8598c2ecf20Sopenharmony_ci		return r;
8608c2ecf20Sopenharmony_ci	r = rs400_gart_init(rdev);
8618c2ecf20Sopenharmony_ci	if (r)
8628c2ecf20Sopenharmony_ci		return r;
8638c2ecf20Sopenharmony_ci	rs600_set_safe_registers(rdev);
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_ci	/* Initialize power management */
8668c2ecf20Sopenharmony_ci	radeon_pm_init(rdev);
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci	rdev->accel_working = true;
8698c2ecf20Sopenharmony_ci	r = rs690_startup(rdev);
8708c2ecf20Sopenharmony_ci	if (r) {
8718c2ecf20Sopenharmony_ci		/* Somethings want wront with the accel init stop accel */
8728c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "Disabling GPU acceleration\n");
8738c2ecf20Sopenharmony_ci		r100_cp_fini(rdev);
8748c2ecf20Sopenharmony_ci		radeon_wb_fini(rdev);
8758c2ecf20Sopenharmony_ci		radeon_ib_pool_fini(rdev);
8768c2ecf20Sopenharmony_ci		rs400_gart_fini(rdev);
8778c2ecf20Sopenharmony_ci		radeon_irq_kms_fini(rdev);
8788c2ecf20Sopenharmony_ci		rdev->accel_working = false;
8798c2ecf20Sopenharmony_ci	}
8808c2ecf20Sopenharmony_ci	return 0;
8818c2ecf20Sopenharmony_ci}
882