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/firmware.h>
308c2ecf20Sopenharmony_ci#include <linux/pci.h>
318c2ecf20Sopenharmony_ci#include <linux/slab.h>
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#include <drm/drm_device.h>
348c2ecf20Sopenharmony_ci#include <drm/radeon_drm.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include "atom.h"
378c2ecf20Sopenharmony_ci#include "avivod.h"
388c2ecf20Sopenharmony_ci#include "radeon.h"
398c2ecf20Sopenharmony_ci#include "radeon_asic.h"
408c2ecf20Sopenharmony_ci#include "radeon_audio.h"
418c2ecf20Sopenharmony_ci#include "rv770d.h"
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define R700_PFP_UCODE_SIZE 848
448c2ecf20Sopenharmony_ci#define R700_PM4_UCODE_SIZE 1360
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic void rv770_gpu_init(struct radeon_device *rdev);
478c2ecf20Sopenharmony_civoid rv770_fini(struct radeon_device *rdev);
488c2ecf20Sopenharmony_cistatic void rv770_pcie_gen2_enable(struct radeon_device *rdev);
498c2ecf20Sopenharmony_ciint evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciint rv770_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
548c2ecf20Sopenharmony_ci	int r;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* RV740 uses evergreen uvd clk programming */
578c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV740)
588c2ecf20Sopenharmony_ci		return evergreen_set_uvd_clocks(rdev, vclk, dclk);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	/* bypass vclk and dclk with bclk */
618c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_2,
628c2ecf20Sopenharmony_ci		 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
638c2ecf20Sopenharmony_ci		 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	if (!vclk || !dclk) {
668c2ecf20Sopenharmony_ci		/* keep the Bypass mode, put PLL to sleep */
678c2ecf20Sopenharmony_ci		WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
688c2ecf20Sopenharmony_ci		return 0;
698c2ecf20Sopenharmony_ci	}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 50000, 160000,
728c2ecf20Sopenharmony_ci					  43663, 0x03FFFFFE, 1, 30, ~0,
738c2ecf20Sopenharmony_ci					  &fb_div, &vclk_div, &dclk_div);
748c2ecf20Sopenharmony_ci	if (r)
758c2ecf20Sopenharmony_ci		return r;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	fb_div |= 1;
788c2ecf20Sopenharmony_ci	vclk_div -= 1;
798c2ecf20Sopenharmony_ci	dclk_div -= 1;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/* set UPLL_FB_DIV to 0x50000 */
828c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(0x50000), ~UPLL_FB_DIV_MASK);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/* deassert UPLL_RESET and UPLL_SLEEP */
858c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~(UPLL_RESET_MASK | UPLL_SLEEP_MASK));
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/* assert BYPASS EN and FB_DIV[0] <- ??? why? */
888c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
898c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(1), ~UPLL_FB_DIV(1));
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
928c2ecf20Sopenharmony_ci	if (r)
938c2ecf20Sopenharmony_ci		return r;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	/* assert PLL_RESET */
968c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	/* set the required FB_DIV, REF_DIV, Post divder values */
998c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_REF_DIV(1), ~UPLL_REF_DIV_MASK);
1008c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_2,
1018c2ecf20Sopenharmony_ci		 UPLL_SW_HILEN(vclk_div >> 1) |
1028c2ecf20Sopenharmony_ci		 UPLL_SW_LOLEN((vclk_div >> 1) + (vclk_div & 1)) |
1038c2ecf20Sopenharmony_ci		 UPLL_SW_HILEN2(dclk_div >> 1) |
1048c2ecf20Sopenharmony_ci		 UPLL_SW_LOLEN2((dclk_div >> 1) + (dclk_div & 1)),
1058c2ecf20Sopenharmony_ci		 ~UPLL_SW_MASK);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div),
1088c2ecf20Sopenharmony_ci		 ~UPLL_FB_DIV_MASK);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* give the PLL some time to settle */
1118c2ecf20Sopenharmony_ci	mdelay(15);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/* deassert PLL_RESET */
1148c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	mdelay(15);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/* deassert BYPASS EN and FB_DIV[0] <- ??? why? */
1198c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
1208c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_3, 0, ~UPLL_FB_DIV(1));
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
1238c2ecf20Sopenharmony_ci	if (r)
1248c2ecf20Sopenharmony_ci		return r;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	/* switch VCLK and DCLK selection */
1278c2ecf20Sopenharmony_ci	WREG32_P(CG_UPLL_FUNC_CNTL_2,
1288c2ecf20Sopenharmony_ci		 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
1298c2ecf20Sopenharmony_ci		 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	mdelay(100);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	return 0;
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistatic const u32 r7xx_golden_registers[] =
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	0x8d00, 0xffffffff, 0x0e0e0074,
1398c2ecf20Sopenharmony_ci	0x8d04, 0xffffffff, 0x013a2b34,
1408c2ecf20Sopenharmony_ci	0x9508, 0xffffffff, 0x00000002,
1418c2ecf20Sopenharmony_ci	0x8b20, 0xffffffff, 0,
1428c2ecf20Sopenharmony_ci	0x88c4, 0xffffffff, 0x000000c2,
1438c2ecf20Sopenharmony_ci	0x28350, 0xffffffff, 0,
1448c2ecf20Sopenharmony_ci	0x9058, 0xffffffff, 0x0fffc40f,
1458c2ecf20Sopenharmony_ci	0x240c, 0xffffffff, 0x00000380,
1468c2ecf20Sopenharmony_ci	0x733c, 0xffffffff, 0x00000002,
1478c2ecf20Sopenharmony_ci	0x2650, 0x00040000, 0,
1488c2ecf20Sopenharmony_ci	0x20bc, 0x00040000, 0,
1498c2ecf20Sopenharmony_ci	0x7300, 0xffffffff, 0x001000f0
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic const u32 r7xx_golden_dyn_gpr_registers[] =
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	0x8db0, 0xffffffff, 0x98989898,
1558c2ecf20Sopenharmony_ci	0x8db4, 0xffffffff, 0x98989898,
1568c2ecf20Sopenharmony_ci	0x8db8, 0xffffffff, 0x98989898,
1578c2ecf20Sopenharmony_ci	0x8dbc, 0xffffffff, 0x98989898,
1588c2ecf20Sopenharmony_ci	0x8dc0, 0xffffffff, 0x98989898,
1598c2ecf20Sopenharmony_ci	0x8dc4, 0xffffffff, 0x98989898,
1608c2ecf20Sopenharmony_ci	0x8dc8, 0xffffffff, 0x98989898,
1618c2ecf20Sopenharmony_ci	0x8dcc, 0xffffffff, 0x98989898,
1628c2ecf20Sopenharmony_ci	0x88c4, 0xffffffff, 0x00000082
1638c2ecf20Sopenharmony_ci};
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic const u32 rv770_golden_registers[] =
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	0x562c, 0xffffffff, 0,
1688c2ecf20Sopenharmony_ci	0x3f90, 0xffffffff, 0,
1698c2ecf20Sopenharmony_ci	0x9148, 0xffffffff, 0,
1708c2ecf20Sopenharmony_ci	0x3f94, 0xffffffff, 0,
1718c2ecf20Sopenharmony_ci	0x914c, 0xffffffff, 0,
1728c2ecf20Sopenharmony_ci	0x9698, 0x18000000, 0x18000000
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic const u32 rv770ce_golden_registers[] =
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	0x562c, 0xffffffff, 0,
1788c2ecf20Sopenharmony_ci	0x3f90, 0xffffffff, 0x00cc0000,
1798c2ecf20Sopenharmony_ci	0x9148, 0xffffffff, 0x00cc0000,
1808c2ecf20Sopenharmony_ci	0x3f94, 0xffffffff, 0x00cc0000,
1818c2ecf20Sopenharmony_ci	0x914c, 0xffffffff, 0x00cc0000,
1828c2ecf20Sopenharmony_ci	0x9b7c, 0xffffffff, 0x00fa0000,
1838c2ecf20Sopenharmony_ci	0x3f8c, 0xffffffff, 0x00fa0000,
1848c2ecf20Sopenharmony_ci	0x9698, 0x18000000, 0x18000000
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic const u32 rv770_mgcg_init[] =
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	0x8bcc, 0xffffffff, 0x130300f9,
1908c2ecf20Sopenharmony_ci	0x5448, 0xffffffff, 0x100,
1918c2ecf20Sopenharmony_ci	0x55e4, 0xffffffff, 0x100,
1928c2ecf20Sopenharmony_ci	0x160c, 0xffffffff, 0x100,
1938c2ecf20Sopenharmony_ci	0x5644, 0xffffffff, 0x100,
1948c2ecf20Sopenharmony_ci	0xc164, 0xffffffff, 0x100,
1958c2ecf20Sopenharmony_ci	0x8a18, 0xffffffff, 0x100,
1968c2ecf20Sopenharmony_ci	0x897c, 0xffffffff, 0x8000100,
1978c2ecf20Sopenharmony_ci	0x8b28, 0xffffffff, 0x3c000100,
1988c2ecf20Sopenharmony_ci	0x9144, 0xffffffff, 0x100,
1998c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10000,
2008c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
2018c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10001,
2028c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
2038c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10002,
2048c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
2058c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10003,
2068c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
2078c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x0,
2088c2ecf20Sopenharmony_ci	0x9870, 0xffffffff, 0x100,
2098c2ecf20Sopenharmony_ci	0x8d58, 0xffffffff, 0x100,
2108c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x0,
2118c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2128c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x1,
2138c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2148c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x2,
2158c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2168c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x3,
2178c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2188c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x4,
2198c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2208c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x5,
2218c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2228c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x6,
2238c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2248c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x7,
2258c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2268c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x8,
2278c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2288c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x9,
2298c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
2308c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x8000,
2318c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x0,
2328c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2338c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x1,
2348c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2358c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x2,
2368c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2378c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x3,
2388c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2398c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x4,
2408c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2418c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x5,
2428c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2438c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x6,
2448c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2458c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x7,
2468c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2478c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x8,
2488c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2498c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x9,
2508c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
2518c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x8000,
2528c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x0,
2538c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2548c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x1,
2558c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2568c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x2,
2578c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2588c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x3,
2598c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2608c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x4,
2618c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2628c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x5,
2638c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2648c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x6,
2658c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2668c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x7,
2678c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2688c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x8,
2698c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2708c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x9,
2718c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
2728c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x80000000,
2738c2ecf20Sopenharmony_ci	0x9030, 0xffffffff, 0x100,
2748c2ecf20Sopenharmony_ci	0x9034, 0xffffffff, 0x100,
2758c2ecf20Sopenharmony_ci	0x9038, 0xffffffff, 0x100,
2768c2ecf20Sopenharmony_ci	0x903c, 0xffffffff, 0x100,
2778c2ecf20Sopenharmony_ci	0x9040, 0xffffffff, 0x100,
2788c2ecf20Sopenharmony_ci	0xa200, 0xffffffff, 0x100,
2798c2ecf20Sopenharmony_ci	0xa204, 0xffffffff, 0x100,
2808c2ecf20Sopenharmony_ci	0xa208, 0xffffffff, 0x100,
2818c2ecf20Sopenharmony_ci	0xa20c, 0xffffffff, 0x100,
2828c2ecf20Sopenharmony_ci	0x971c, 0xffffffff, 0x100,
2838c2ecf20Sopenharmony_ci	0x915c, 0xffffffff, 0x00020001,
2848c2ecf20Sopenharmony_ci	0x9160, 0xffffffff, 0x00040003,
2858c2ecf20Sopenharmony_ci	0x916c, 0xffffffff, 0x00060005,
2868c2ecf20Sopenharmony_ci	0x9170, 0xffffffff, 0x00080007,
2878c2ecf20Sopenharmony_ci	0x9174, 0xffffffff, 0x000a0009,
2888c2ecf20Sopenharmony_ci	0x9178, 0xffffffff, 0x000c000b,
2898c2ecf20Sopenharmony_ci	0x917c, 0xffffffff, 0x000e000d,
2908c2ecf20Sopenharmony_ci	0x9180, 0xffffffff, 0x0010000f,
2918c2ecf20Sopenharmony_ci	0x918c, 0xffffffff, 0x00120011,
2928c2ecf20Sopenharmony_ci	0x9190, 0xffffffff, 0x00140013,
2938c2ecf20Sopenharmony_ci	0x9194, 0xffffffff, 0x00020001,
2948c2ecf20Sopenharmony_ci	0x9198, 0xffffffff, 0x00040003,
2958c2ecf20Sopenharmony_ci	0x919c, 0xffffffff, 0x00060005,
2968c2ecf20Sopenharmony_ci	0x91a8, 0xffffffff, 0x00080007,
2978c2ecf20Sopenharmony_ci	0x91ac, 0xffffffff, 0x000a0009,
2988c2ecf20Sopenharmony_ci	0x91b0, 0xffffffff, 0x000c000b,
2998c2ecf20Sopenharmony_ci	0x91b4, 0xffffffff, 0x000e000d,
3008c2ecf20Sopenharmony_ci	0x91b8, 0xffffffff, 0x0010000f,
3018c2ecf20Sopenharmony_ci	0x91c4, 0xffffffff, 0x00120011,
3028c2ecf20Sopenharmony_ci	0x91c8, 0xffffffff, 0x00140013,
3038c2ecf20Sopenharmony_ci	0x91cc, 0xffffffff, 0x00020001,
3048c2ecf20Sopenharmony_ci	0x91d0, 0xffffffff, 0x00040003,
3058c2ecf20Sopenharmony_ci	0x91d4, 0xffffffff, 0x00060005,
3068c2ecf20Sopenharmony_ci	0x91e0, 0xffffffff, 0x00080007,
3078c2ecf20Sopenharmony_ci	0x91e4, 0xffffffff, 0x000a0009,
3088c2ecf20Sopenharmony_ci	0x91e8, 0xffffffff, 0x000c000b,
3098c2ecf20Sopenharmony_ci	0x91ec, 0xffffffff, 0x00020001,
3108c2ecf20Sopenharmony_ci	0x91f0, 0xffffffff, 0x00040003,
3118c2ecf20Sopenharmony_ci	0x91f4, 0xffffffff, 0x00060005,
3128c2ecf20Sopenharmony_ci	0x9200, 0xffffffff, 0x00080007,
3138c2ecf20Sopenharmony_ci	0x9204, 0xffffffff, 0x000a0009,
3148c2ecf20Sopenharmony_ci	0x9208, 0xffffffff, 0x000c000b,
3158c2ecf20Sopenharmony_ci	0x920c, 0xffffffff, 0x000e000d,
3168c2ecf20Sopenharmony_ci	0x9210, 0xffffffff, 0x0010000f,
3178c2ecf20Sopenharmony_ci	0x921c, 0xffffffff, 0x00120011,
3188c2ecf20Sopenharmony_ci	0x9220, 0xffffffff, 0x00140013,
3198c2ecf20Sopenharmony_ci	0x9224, 0xffffffff, 0x00020001,
3208c2ecf20Sopenharmony_ci	0x9228, 0xffffffff, 0x00040003,
3218c2ecf20Sopenharmony_ci	0x922c, 0xffffffff, 0x00060005,
3228c2ecf20Sopenharmony_ci	0x9238, 0xffffffff, 0x00080007,
3238c2ecf20Sopenharmony_ci	0x923c, 0xffffffff, 0x000a0009,
3248c2ecf20Sopenharmony_ci	0x9240, 0xffffffff, 0x000c000b,
3258c2ecf20Sopenharmony_ci	0x9244, 0xffffffff, 0x000e000d,
3268c2ecf20Sopenharmony_ci	0x9248, 0xffffffff, 0x0010000f,
3278c2ecf20Sopenharmony_ci	0x9254, 0xffffffff, 0x00120011,
3288c2ecf20Sopenharmony_ci	0x9258, 0xffffffff, 0x00140013,
3298c2ecf20Sopenharmony_ci	0x925c, 0xffffffff, 0x00020001,
3308c2ecf20Sopenharmony_ci	0x9260, 0xffffffff, 0x00040003,
3318c2ecf20Sopenharmony_ci	0x9264, 0xffffffff, 0x00060005,
3328c2ecf20Sopenharmony_ci	0x9270, 0xffffffff, 0x00080007,
3338c2ecf20Sopenharmony_ci	0x9274, 0xffffffff, 0x000a0009,
3348c2ecf20Sopenharmony_ci	0x9278, 0xffffffff, 0x000c000b,
3358c2ecf20Sopenharmony_ci	0x927c, 0xffffffff, 0x000e000d,
3368c2ecf20Sopenharmony_ci	0x9280, 0xffffffff, 0x0010000f,
3378c2ecf20Sopenharmony_ci	0x928c, 0xffffffff, 0x00120011,
3388c2ecf20Sopenharmony_ci	0x9290, 0xffffffff, 0x00140013,
3398c2ecf20Sopenharmony_ci	0x9294, 0xffffffff, 0x00020001,
3408c2ecf20Sopenharmony_ci	0x929c, 0xffffffff, 0x00040003,
3418c2ecf20Sopenharmony_ci	0x92a0, 0xffffffff, 0x00060005,
3428c2ecf20Sopenharmony_ci	0x92a4, 0xffffffff, 0x00080007
3438c2ecf20Sopenharmony_ci};
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cistatic const u32 rv710_golden_registers[] =
3468c2ecf20Sopenharmony_ci{
3478c2ecf20Sopenharmony_ci	0x3f90, 0x00ff0000, 0x00fc0000,
3488c2ecf20Sopenharmony_ci	0x9148, 0x00ff0000, 0x00fc0000,
3498c2ecf20Sopenharmony_ci	0x3f94, 0x00ff0000, 0x00fc0000,
3508c2ecf20Sopenharmony_ci	0x914c, 0x00ff0000, 0x00fc0000,
3518c2ecf20Sopenharmony_ci	0xb4c, 0x00000020, 0x00000020,
3528c2ecf20Sopenharmony_ci	0xa180, 0xffffffff, 0x00003f3f
3538c2ecf20Sopenharmony_ci};
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_cistatic const u32 rv710_mgcg_init[] =
3568c2ecf20Sopenharmony_ci{
3578c2ecf20Sopenharmony_ci	0x8bcc, 0xffffffff, 0x13030040,
3588c2ecf20Sopenharmony_ci	0x5448, 0xffffffff, 0x100,
3598c2ecf20Sopenharmony_ci	0x55e4, 0xffffffff, 0x100,
3608c2ecf20Sopenharmony_ci	0x160c, 0xffffffff, 0x100,
3618c2ecf20Sopenharmony_ci	0x5644, 0xffffffff, 0x100,
3628c2ecf20Sopenharmony_ci	0xc164, 0xffffffff, 0x100,
3638c2ecf20Sopenharmony_ci	0x8a18, 0xffffffff, 0x100,
3648c2ecf20Sopenharmony_ci	0x897c, 0xffffffff, 0x8000100,
3658c2ecf20Sopenharmony_ci	0x8b28, 0xffffffff, 0x3c000100,
3668c2ecf20Sopenharmony_ci	0x9144, 0xffffffff, 0x100,
3678c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10000,
3688c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
3698c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x0,
3708c2ecf20Sopenharmony_ci	0x9870, 0xffffffff, 0x100,
3718c2ecf20Sopenharmony_ci	0x8d58, 0xffffffff, 0x100,
3728c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x0,
3738c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
3748c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x1,
3758c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
3768c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x8000,
3778c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x0,
3788c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
3798c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x1,
3808c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
3818c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x8000,
3828c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x0,
3838c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
3848c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x1,
3858c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
3868c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x80000000,
3878c2ecf20Sopenharmony_ci	0x9030, 0xffffffff, 0x100,
3888c2ecf20Sopenharmony_ci	0x9034, 0xffffffff, 0x100,
3898c2ecf20Sopenharmony_ci	0x9038, 0xffffffff, 0x100,
3908c2ecf20Sopenharmony_ci	0x903c, 0xffffffff, 0x100,
3918c2ecf20Sopenharmony_ci	0x9040, 0xffffffff, 0x100,
3928c2ecf20Sopenharmony_ci	0xa200, 0xffffffff, 0x100,
3938c2ecf20Sopenharmony_ci	0xa204, 0xffffffff, 0x100,
3948c2ecf20Sopenharmony_ci	0xa208, 0xffffffff, 0x100,
3958c2ecf20Sopenharmony_ci	0xa20c, 0xffffffff, 0x100,
3968c2ecf20Sopenharmony_ci	0x971c, 0xffffffff, 0x100,
3978c2ecf20Sopenharmony_ci	0x915c, 0xffffffff, 0x00020001,
3988c2ecf20Sopenharmony_ci	0x9174, 0xffffffff, 0x00000003,
3998c2ecf20Sopenharmony_ci	0x9178, 0xffffffff, 0x00050001,
4008c2ecf20Sopenharmony_ci	0x917c, 0xffffffff, 0x00030002,
4018c2ecf20Sopenharmony_ci	0x918c, 0xffffffff, 0x00000004,
4028c2ecf20Sopenharmony_ci	0x9190, 0xffffffff, 0x00070006,
4038c2ecf20Sopenharmony_ci	0x9194, 0xffffffff, 0x00050001,
4048c2ecf20Sopenharmony_ci	0x9198, 0xffffffff, 0x00030002,
4058c2ecf20Sopenharmony_ci	0x91a8, 0xffffffff, 0x00000004,
4068c2ecf20Sopenharmony_ci	0x91ac, 0xffffffff, 0x00070006,
4078c2ecf20Sopenharmony_ci	0x91e8, 0xffffffff, 0x00000001,
4088c2ecf20Sopenharmony_ci	0x9294, 0xffffffff, 0x00000001,
4098c2ecf20Sopenharmony_ci	0x929c, 0xffffffff, 0x00000002,
4108c2ecf20Sopenharmony_ci	0x92a0, 0xffffffff, 0x00040003,
4118c2ecf20Sopenharmony_ci	0x9150, 0xffffffff, 0x4d940000
4128c2ecf20Sopenharmony_ci};
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic const u32 rv730_golden_registers[] =
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	0x3f90, 0x00ff0000, 0x00f00000,
4178c2ecf20Sopenharmony_ci	0x9148, 0x00ff0000, 0x00f00000,
4188c2ecf20Sopenharmony_ci	0x3f94, 0x00ff0000, 0x00f00000,
4198c2ecf20Sopenharmony_ci	0x914c, 0x00ff0000, 0x00f00000,
4208c2ecf20Sopenharmony_ci	0x900c, 0xffffffff, 0x003b033f,
4218c2ecf20Sopenharmony_ci	0xb4c, 0x00000020, 0x00000020,
4228c2ecf20Sopenharmony_ci	0xa180, 0xffffffff, 0x00003f3f
4238c2ecf20Sopenharmony_ci};
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic const u32 rv730_mgcg_init[] =
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	0x8bcc, 0xffffffff, 0x130300f9,
4288c2ecf20Sopenharmony_ci	0x5448, 0xffffffff, 0x100,
4298c2ecf20Sopenharmony_ci	0x55e4, 0xffffffff, 0x100,
4308c2ecf20Sopenharmony_ci	0x160c, 0xffffffff, 0x100,
4318c2ecf20Sopenharmony_ci	0x5644, 0xffffffff, 0x100,
4328c2ecf20Sopenharmony_ci	0xc164, 0xffffffff, 0x100,
4338c2ecf20Sopenharmony_ci	0x8a18, 0xffffffff, 0x100,
4348c2ecf20Sopenharmony_ci	0x897c, 0xffffffff, 0x8000100,
4358c2ecf20Sopenharmony_ci	0x8b28, 0xffffffff, 0x3c000100,
4368c2ecf20Sopenharmony_ci	0x9144, 0xffffffff, 0x100,
4378c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10000,
4388c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
4398c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10001,
4408c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
4418c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x0,
4428c2ecf20Sopenharmony_ci	0x9870, 0xffffffff, 0x100,
4438c2ecf20Sopenharmony_ci	0x8d58, 0xffffffff, 0x100,
4448c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x0,
4458c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4468c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x1,
4478c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4488c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x2,
4498c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4508c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x3,
4518c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4528c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x4,
4538c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4548c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x5,
4558c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4568c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x6,
4578c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4588c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x7,
4598c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
4608c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x8000,
4618c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x0,
4628c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4638c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x1,
4648c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4658c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x2,
4668c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4678c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x3,
4688c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4698c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x4,
4708c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4718c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x5,
4728c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4738c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x6,
4748c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4758c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x7,
4768c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
4778c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x8000,
4788c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x0,
4798c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4808c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x1,
4818c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4828c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x2,
4838c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4848c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x3,
4858c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4868c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x4,
4878c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4888c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x5,
4898c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4908c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x6,
4918c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4928c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x7,
4938c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
4948c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x80000000,
4958c2ecf20Sopenharmony_ci	0x9030, 0xffffffff, 0x100,
4968c2ecf20Sopenharmony_ci	0x9034, 0xffffffff, 0x100,
4978c2ecf20Sopenharmony_ci	0x9038, 0xffffffff, 0x100,
4988c2ecf20Sopenharmony_ci	0x903c, 0xffffffff, 0x100,
4998c2ecf20Sopenharmony_ci	0x9040, 0xffffffff, 0x100,
5008c2ecf20Sopenharmony_ci	0xa200, 0xffffffff, 0x100,
5018c2ecf20Sopenharmony_ci	0xa204, 0xffffffff, 0x100,
5028c2ecf20Sopenharmony_ci	0xa208, 0xffffffff, 0x100,
5038c2ecf20Sopenharmony_ci	0xa20c, 0xffffffff, 0x100,
5048c2ecf20Sopenharmony_ci	0x971c, 0xffffffff, 0x100,
5058c2ecf20Sopenharmony_ci	0x915c, 0xffffffff, 0x00020001,
5068c2ecf20Sopenharmony_ci	0x916c, 0xffffffff, 0x00040003,
5078c2ecf20Sopenharmony_ci	0x9170, 0xffffffff, 0x00000005,
5088c2ecf20Sopenharmony_ci	0x9178, 0xffffffff, 0x00050001,
5098c2ecf20Sopenharmony_ci	0x917c, 0xffffffff, 0x00030002,
5108c2ecf20Sopenharmony_ci	0x918c, 0xffffffff, 0x00000004,
5118c2ecf20Sopenharmony_ci	0x9190, 0xffffffff, 0x00070006,
5128c2ecf20Sopenharmony_ci	0x9194, 0xffffffff, 0x00050001,
5138c2ecf20Sopenharmony_ci	0x9198, 0xffffffff, 0x00030002,
5148c2ecf20Sopenharmony_ci	0x91a8, 0xffffffff, 0x00000004,
5158c2ecf20Sopenharmony_ci	0x91ac, 0xffffffff, 0x00070006,
5168c2ecf20Sopenharmony_ci	0x91b0, 0xffffffff, 0x00050001,
5178c2ecf20Sopenharmony_ci	0x91b4, 0xffffffff, 0x00030002,
5188c2ecf20Sopenharmony_ci	0x91c4, 0xffffffff, 0x00000004,
5198c2ecf20Sopenharmony_ci	0x91c8, 0xffffffff, 0x00070006,
5208c2ecf20Sopenharmony_ci	0x91cc, 0xffffffff, 0x00050001,
5218c2ecf20Sopenharmony_ci	0x91d0, 0xffffffff, 0x00030002,
5228c2ecf20Sopenharmony_ci	0x91e0, 0xffffffff, 0x00000004,
5238c2ecf20Sopenharmony_ci	0x91e4, 0xffffffff, 0x00070006,
5248c2ecf20Sopenharmony_ci	0x91e8, 0xffffffff, 0x00000001,
5258c2ecf20Sopenharmony_ci	0x91ec, 0xffffffff, 0x00050001,
5268c2ecf20Sopenharmony_ci	0x91f0, 0xffffffff, 0x00030002,
5278c2ecf20Sopenharmony_ci	0x9200, 0xffffffff, 0x00000004,
5288c2ecf20Sopenharmony_ci	0x9204, 0xffffffff, 0x00070006,
5298c2ecf20Sopenharmony_ci	0x9208, 0xffffffff, 0x00050001,
5308c2ecf20Sopenharmony_ci	0x920c, 0xffffffff, 0x00030002,
5318c2ecf20Sopenharmony_ci	0x921c, 0xffffffff, 0x00000004,
5328c2ecf20Sopenharmony_ci	0x9220, 0xffffffff, 0x00070006,
5338c2ecf20Sopenharmony_ci	0x9224, 0xffffffff, 0x00050001,
5348c2ecf20Sopenharmony_ci	0x9228, 0xffffffff, 0x00030002,
5358c2ecf20Sopenharmony_ci	0x9238, 0xffffffff, 0x00000004,
5368c2ecf20Sopenharmony_ci	0x923c, 0xffffffff, 0x00070006,
5378c2ecf20Sopenharmony_ci	0x9240, 0xffffffff, 0x00050001,
5388c2ecf20Sopenharmony_ci	0x9244, 0xffffffff, 0x00030002,
5398c2ecf20Sopenharmony_ci	0x9254, 0xffffffff, 0x00000004,
5408c2ecf20Sopenharmony_ci	0x9258, 0xffffffff, 0x00070006,
5418c2ecf20Sopenharmony_ci	0x9294, 0xffffffff, 0x00000001,
5428c2ecf20Sopenharmony_ci	0x929c, 0xffffffff, 0x00000002,
5438c2ecf20Sopenharmony_ci	0x92a0, 0xffffffff, 0x00040003,
5448c2ecf20Sopenharmony_ci	0x92a4, 0xffffffff, 0x00000005
5458c2ecf20Sopenharmony_ci};
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_cistatic const u32 rv740_golden_registers[] =
5488c2ecf20Sopenharmony_ci{
5498c2ecf20Sopenharmony_ci	0x88c4, 0xffffffff, 0x00000082,
5508c2ecf20Sopenharmony_ci	0x28a50, 0xfffffffc, 0x00000004,
5518c2ecf20Sopenharmony_ci	0x2650, 0x00040000, 0,
5528c2ecf20Sopenharmony_ci	0x20bc, 0x00040000, 0,
5538c2ecf20Sopenharmony_ci	0x733c, 0xffffffff, 0x00000002,
5548c2ecf20Sopenharmony_ci	0x7300, 0xffffffff, 0x001000f0,
5558c2ecf20Sopenharmony_ci	0x3f90, 0x00ff0000, 0,
5568c2ecf20Sopenharmony_ci	0x9148, 0x00ff0000, 0,
5578c2ecf20Sopenharmony_ci	0x3f94, 0x00ff0000, 0,
5588c2ecf20Sopenharmony_ci	0x914c, 0x00ff0000, 0,
5598c2ecf20Sopenharmony_ci	0x240c, 0xffffffff, 0x00000380,
5608c2ecf20Sopenharmony_ci	0x8a14, 0x00000007, 0x00000007,
5618c2ecf20Sopenharmony_ci	0x8b24, 0xffffffff, 0x00ff0fff,
5628c2ecf20Sopenharmony_ci	0x28a4c, 0xffffffff, 0x00004000,
5638c2ecf20Sopenharmony_ci	0xa180, 0xffffffff, 0x00003f3f,
5648c2ecf20Sopenharmony_ci	0x8d00, 0xffffffff, 0x0e0e003a,
5658c2ecf20Sopenharmony_ci	0x8d04, 0xffffffff, 0x013a0e2a,
5668c2ecf20Sopenharmony_ci	0x8c00, 0xffffffff, 0xe400000f,
5678c2ecf20Sopenharmony_ci	0x8db0, 0xffffffff, 0x98989898,
5688c2ecf20Sopenharmony_ci	0x8db4, 0xffffffff, 0x98989898,
5698c2ecf20Sopenharmony_ci	0x8db8, 0xffffffff, 0x98989898,
5708c2ecf20Sopenharmony_ci	0x8dbc, 0xffffffff, 0x98989898,
5718c2ecf20Sopenharmony_ci	0x8dc0, 0xffffffff, 0x98989898,
5728c2ecf20Sopenharmony_ci	0x8dc4, 0xffffffff, 0x98989898,
5738c2ecf20Sopenharmony_ci	0x8dc8, 0xffffffff, 0x98989898,
5748c2ecf20Sopenharmony_ci	0x8dcc, 0xffffffff, 0x98989898,
5758c2ecf20Sopenharmony_ci	0x9058, 0xffffffff, 0x0fffc40f,
5768c2ecf20Sopenharmony_ci	0x900c, 0xffffffff, 0x003b033f,
5778c2ecf20Sopenharmony_ci	0x28350, 0xffffffff, 0,
5788c2ecf20Sopenharmony_ci	0x8cf0, 0x1fffffff, 0x08e00420,
5798c2ecf20Sopenharmony_ci	0x9508, 0xffffffff, 0x00000002,
5808c2ecf20Sopenharmony_ci	0x88c4, 0xffffffff, 0x000000c2,
5818c2ecf20Sopenharmony_ci	0x9698, 0x18000000, 0x18000000
5828c2ecf20Sopenharmony_ci};
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_cistatic const u32 rv740_mgcg_init[] =
5858c2ecf20Sopenharmony_ci{
5868c2ecf20Sopenharmony_ci	0x8bcc, 0xffffffff, 0x13030100,
5878c2ecf20Sopenharmony_ci	0x5448, 0xffffffff, 0x100,
5888c2ecf20Sopenharmony_ci	0x55e4, 0xffffffff, 0x100,
5898c2ecf20Sopenharmony_ci	0x160c, 0xffffffff, 0x100,
5908c2ecf20Sopenharmony_ci	0x5644, 0xffffffff, 0x100,
5918c2ecf20Sopenharmony_ci	0xc164, 0xffffffff, 0x100,
5928c2ecf20Sopenharmony_ci	0x8a18, 0xffffffff, 0x100,
5938c2ecf20Sopenharmony_ci	0x897c, 0xffffffff, 0x100,
5948c2ecf20Sopenharmony_ci	0x8b28, 0xffffffff, 0x100,
5958c2ecf20Sopenharmony_ci	0x9144, 0xffffffff, 0x100,
5968c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10000,
5978c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
5988c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10001,
5998c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
6008c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10002,
6018c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
6028c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x10003,
6038c2ecf20Sopenharmony_ci	0x9a50, 0xffffffff, 0x100,
6048c2ecf20Sopenharmony_ci	0x9a1c, 0xffffffff, 0x0,
6058c2ecf20Sopenharmony_ci	0x9870, 0xffffffff, 0x100,
6068c2ecf20Sopenharmony_ci	0x8d58, 0xffffffff, 0x100,
6078c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x0,
6088c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6098c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x1,
6108c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6118c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x2,
6128c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6138c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x3,
6148c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6158c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x4,
6168c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6178c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x5,
6188c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6198c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x6,
6208c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6218c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x7,
6228c2ecf20Sopenharmony_ci	0x9510, 0xffffffff, 0x100,
6238c2ecf20Sopenharmony_ci	0x9500, 0xffffffff, 0x8000,
6248c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x0,
6258c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6268c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x1,
6278c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6288c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x2,
6298c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6308c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x3,
6318c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6328c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x4,
6338c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6348c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x5,
6358c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6368c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x6,
6378c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6388c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x7,
6398c2ecf20Sopenharmony_ci	0x949c, 0xffffffff, 0x100,
6408c2ecf20Sopenharmony_ci	0x9490, 0xffffffff, 0x8000,
6418c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x0,
6428c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6438c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x1,
6448c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6458c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x2,
6468c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6478c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x3,
6488c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6498c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x4,
6508c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6518c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x5,
6528c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6538c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x6,
6548c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6558c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x7,
6568c2ecf20Sopenharmony_ci	0x9654, 0xffffffff, 0x100,
6578c2ecf20Sopenharmony_ci	0x9604, 0xffffffff, 0x80000000,
6588c2ecf20Sopenharmony_ci	0x9030, 0xffffffff, 0x100,
6598c2ecf20Sopenharmony_ci	0x9034, 0xffffffff, 0x100,
6608c2ecf20Sopenharmony_ci	0x9038, 0xffffffff, 0x100,
6618c2ecf20Sopenharmony_ci	0x903c, 0xffffffff, 0x100,
6628c2ecf20Sopenharmony_ci	0x9040, 0xffffffff, 0x100,
6638c2ecf20Sopenharmony_ci	0xa200, 0xffffffff, 0x100,
6648c2ecf20Sopenharmony_ci	0xa204, 0xffffffff, 0x100,
6658c2ecf20Sopenharmony_ci	0xa208, 0xffffffff, 0x100,
6668c2ecf20Sopenharmony_ci	0xa20c, 0xffffffff, 0x100,
6678c2ecf20Sopenharmony_ci	0x971c, 0xffffffff, 0x100,
6688c2ecf20Sopenharmony_ci	0x915c, 0xffffffff, 0x00020001,
6698c2ecf20Sopenharmony_ci	0x9160, 0xffffffff, 0x00040003,
6708c2ecf20Sopenharmony_ci	0x916c, 0xffffffff, 0x00060005,
6718c2ecf20Sopenharmony_ci	0x9170, 0xffffffff, 0x00080007,
6728c2ecf20Sopenharmony_ci	0x9174, 0xffffffff, 0x000a0009,
6738c2ecf20Sopenharmony_ci	0x9178, 0xffffffff, 0x000c000b,
6748c2ecf20Sopenharmony_ci	0x917c, 0xffffffff, 0x000e000d,
6758c2ecf20Sopenharmony_ci	0x9180, 0xffffffff, 0x0010000f,
6768c2ecf20Sopenharmony_ci	0x918c, 0xffffffff, 0x00120011,
6778c2ecf20Sopenharmony_ci	0x9190, 0xffffffff, 0x00140013,
6788c2ecf20Sopenharmony_ci	0x9194, 0xffffffff, 0x00020001,
6798c2ecf20Sopenharmony_ci	0x9198, 0xffffffff, 0x00040003,
6808c2ecf20Sopenharmony_ci	0x919c, 0xffffffff, 0x00060005,
6818c2ecf20Sopenharmony_ci	0x91a8, 0xffffffff, 0x00080007,
6828c2ecf20Sopenharmony_ci	0x91ac, 0xffffffff, 0x000a0009,
6838c2ecf20Sopenharmony_ci	0x91b0, 0xffffffff, 0x000c000b,
6848c2ecf20Sopenharmony_ci	0x91b4, 0xffffffff, 0x000e000d,
6858c2ecf20Sopenharmony_ci	0x91b8, 0xffffffff, 0x0010000f,
6868c2ecf20Sopenharmony_ci	0x91c4, 0xffffffff, 0x00120011,
6878c2ecf20Sopenharmony_ci	0x91c8, 0xffffffff, 0x00140013,
6888c2ecf20Sopenharmony_ci	0x91cc, 0xffffffff, 0x00020001,
6898c2ecf20Sopenharmony_ci	0x91d0, 0xffffffff, 0x00040003,
6908c2ecf20Sopenharmony_ci	0x91d4, 0xffffffff, 0x00060005,
6918c2ecf20Sopenharmony_ci	0x91e0, 0xffffffff, 0x00080007,
6928c2ecf20Sopenharmony_ci	0x91e4, 0xffffffff, 0x000a0009,
6938c2ecf20Sopenharmony_ci	0x91e8, 0xffffffff, 0x000c000b,
6948c2ecf20Sopenharmony_ci	0x91ec, 0xffffffff, 0x00020001,
6958c2ecf20Sopenharmony_ci	0x91f0, 0xffffffff, 0x00040003,
6968c2ecf20Sopenharmony_ci	0x91f4, 0xffffffff, 0x00060005,
6978c2ecf20Sopenharmony_ci	0x9200, 0xffffffff, 0x00080007,
6988c2ecf20Sopenharmony_ci	0x9204, 0xffffffff, 0x000a0009,
6998c2ecf20Sopenharmony_ci	0x9208, 0xffffffff, 0x000c000b,
7008c2ecf20Sopenharmony_ci	0x920c, 0xffffffff, 0x000e000d,
7018c2ecf20Sopenharmony_ci	0x9210, 0xffffffff, 0x0010000f,
7028c2ecf20Sopenharmony_ci	0x921c, 0xffffffff, 0x00120011,
7038c2ecf20Sopenharmony_ci	0x9220, 0xffffffff, 0x00140013,
7048c2ecf20Sopenharmony_ci	0x9224, 0xffffffff, 0x00020001,
7058c2ecf20Sopenharmony_ci	0x9228, 0xffffffff, 0x00040003,
7068c2ecf20Sopenharmony_ci	0x922c, 0xffffffff, 0x00060005,
7078c2ecf20Sopenharmony_ci	0x9238, 0xffffffff, 0x00080007,
7088c2ecf20Sopenharmony_ci	0x923c, 0xffffffff, 0x000a0009,
7098c2ecf20Sopenharmony_ci	0x9240, 0xffffffff, 0x000c000b,
7108c2ecf20Sopenharmony_ci	0x9244, 0xffffffff, 0x000e000d,
7118c2ecf20Sopenharmony_ci	0x9248, 0xffffffff, 0x0010000f,
7128c2ecf20Sopenharmony_ci	0x9254, 0xffffffff, 0x00120011,
7138c2ecf20Sopenharmony_ci	0x9258, 0xffffffff, 0x00140013,
7148c2ecf20Sopenharmony_ci	0x9294, 0xffffffff, 0x00020001,
7158c2ecf20Sopenharmony_ci	0x929c, 0xffffffff, 0x00040003,
7168c2ecf20Sopenharmony_ci	0x92a0, 0xffffffff, 0x00060005,
7178c2ecf20Sopenharmony_ci	0x92a4, 0xffffffff, 0x00080007
7188c2ecf20Sopenharmony_ci};
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic void rv770_init_golden_registers(struct radeon_device *rdev)
7218c2ecf20Sopenharmony_ci{
7228c2ecf20Sopenharmony_ci	switch (rdev->family) {
7238c2ecf20Sopenharmony_ci	case CHIP_RV770:
7248c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7258c2ecf20Sopenharmony_ci						 r7xx_golden_registers,
7268c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_registers));
7278c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7288c2ecf20Sopenharmony_ci						 r7xx_golden_dyn_gpr_registers,
7298c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
7308c2ecf20Sopenharmony_ci		if (rdev->pdev->device == 0x994e)
7318c2ecf20Sopenharmony_ci			radeon_program_register_sequence(rdev,
7328c2ecf20Sopenharmony_ci							 rv770ce_golden_registers,
7338c2ecf20Sopenharmony_ci							 (const u32)ARRAY_SIZE(rv770ce_golden_registers));
7348c2ecf20Sopenharmony_ci		else
7358c2ecf20Sopenharmony_ci			radeon_program_register_sequence(rdev,
7368c2ecf20Sopenharmony_ci							 rv770_golden_registers,
7378c2ecf20Sopenharmony_ci							 (const u32)ARRAY_SIZE(rv770_golden_registers));
7388c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7398c2ecf20Sopenharmony_ci						 rv770_mgcg_init,
7408c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv770_mgcg_init));
7418c2ecf20Sopenharmony_ci		break;
7428c2ecf20Sopenharmony_ci	case CHIP_RV730:
7438c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7448c2ecf20Sopenharmony_ci						 r7xx_golden_registers,
7458c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_registers));
7468c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7478c2ecf20Sopenharmony_ci						 r7xx_golden_dyn_gpr_registers,
7488c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
7498c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7508c2ecf20Sopenharmony_ci						 rv730_golden_registers,
7518c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv730_golden_registers));
7528c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7538c2ecf20Sopenharmony_ci						 rv730_mgcg_init,
7548c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv730_mgcg_init));
7558c2ecf20Sopenharmony_ci		break;
7568c2ecf20Sopenharmony_ci	case CHIP_RV710:
7578c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7588c2ecf20Sopenharmony_ci						 r7xx_golden_registers,
7598c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_registers));
7608c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7618c2ecf20Sopenharmony_ci						 r7xx_golden_dyn_gpr_registers,
7628c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(r7xx_golden_dyn_gpr_registers));
7638c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7648c2ecf20Sopenharmony_ci						 rv710_golden_registers,
7658c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv710_golden_registers));
7668c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7678c2ecf20Sopenharmony_ci						 rv710_mgcg_init,
7688c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv710_mgcg_init));
7698c2ecf20Sopenharmony_ci		break;
7708c2ecf20Sopenharmony_ci	case CHIP_RV740:
7718c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7728c2ecf20Sopenharmony_ci						 rv740_golden_registers,
7738c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv740_golden_registers));
7748c2ecf20Sopenharmony_ci		radeon_program_register_sequence(rdev,
7758c2ecf20Sopenharmony_ci						 rv740_mgcg_init,
7768c2ecf20Sopenharmony_ci						 (const u32)ARRAY_SIZE(rv740_mgcg_init));
7778c2ecf20Sopenharmony_ci		break;
7788c2ecf20Sopenharmony_ci	default:
7798c2ecf20Sopenharmony_ci		break;
7808c2ecf20Sopenharmony_ci	}
7818c2ecf20Sopenharmony_ci}
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci#define PCIE_BUS_CLK                10000
7848c2ecf20Sopenharmony_ci#define TCLK                        (PCIE_BUS_CLK / 10)
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci/**
7878c2ecf20Sopenharmony_ci * rv770_get_xclk - get the xclk
7888c2ecf20Sopenharmony_ci *
7898c2ecf20Sopenharmony_ci * @rdev: radeon_device pointer
7908c2ecf20Sopenharmony_ci *
7918c2ecf20Sopenharmony_ci * Returns the reference clock used by the gfx engine
7928c2ecf20Sopenharmony_ci * (r7xx-cayman).
7938c2ecf20Sopenharmony_ci */
7948c2ecf20Sopenharmony_ciu32 rv770_get_xclk(struct radeon_device *rdev)
7958c2ecf20Sopenharmony_ci{
7968c2ecf20Sopenharmony_ci	u32 reference_clock = rdev->clock.spll.reference_freq;
7978c2ecf20Sopenharmony_ci	u32 tmp = RREG32(CG_CLKPIN_CNTL);
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci	if (tmp & MUX_TCLK_TO_XCLK)
8008c2ecf20Sopenharmony_ci		return TCLK;
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	if (tmp & XTALIN_DIVIDE)
8038c2ecf20Sopenharmony_ci		return reference_clock / 4;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	return reference_clock;
8068c2ecf20Sopenharmony_ci}
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_civoid rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base, bool async)
8098c2ecf20Sopenharmony_ci{
8108c2ecf20Sopenharmony_ci	struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
8118c2ecf20Sopenharmony_ci	u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
8128c2ecf20Sopenharmony_ci	int i;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	/* Lock the graphics update lock */
8158c2ecf20Sopenharmony_ci	tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
8168c2ecf20Sopenharmony_ci	WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	/* update the scanout addresses */
8198c2ecf20Sopenharmony_ci	WREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset,
8208c2ecf20Sopenharmony_ci	       async ? AVIVO_D1GRPH_SURFACE_UPDATE_H_RETRACE_EN : 0);
8218c2ecf20Sopenharmony_ci	if (radeon_crtc->crtc_id) {
8228c2ecf20Sopenharmony_ci		WREG32(D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
8238c2ecf20Sopenharmony_ci		WREG32(D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
8248c2ecf20Sopenharmony_ci	} else {
8258c2ecf20Sopenharmony_ci		WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
8268c2ecf20Sopenharmony_ci		WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
8278c2ecf20Sopenharmony_ci	}
8288c2ecf20Sopenharmony_ci	WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
8298c2ecf20Sopenharmony_ci	       (u32)crtc_base);
8308c2ecf20Sopenharmony_ci	WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
8318c2ecf20Sopenharmony_ci	       (u32)crtc_base);
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci	/* Wait for update_pending to go high. */
8348c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->usec_timeout; i++) {
8358c2ecf20Sopenharmony_ci		if (RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)
8368c2ecf20Sopenharmony_ci			break;
8378c2ecf20Sopenharmony_ci		udelay(1);
8388c2ecf20Sopenharmony_ci	}
8398c2ecf20Sopenharmony_ci	DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	/* Unlock the lock, so double-buffering can take place inside vblank */
8428c2ecf20Sopenharmony_ci	tmp &= ~AVIVO_D1GRPH_UPDATE_LOCK;
8438c2ecf20Sopenharmony_ci	WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
8448c2ecf20Sopenharmony_ci}
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_cibool rv770_page_flip_pending(struct radeon_device *rdev, int crtc_id)
8478c2ecf20Sopenharmony_ci{
8488c2ecf20Sopenharmony_ci	struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	/* Return current update_pending status: */
8518c2ecf20Sopenharmony_ci	return !!(RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) &
8528c2ecf20Sopenharmony_ci		AVIVO_D1GRPH_SURFACE_UPDATE_PENDING);
8538c2ecf20Sopenharmony_ci}
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci/* get temperature in millidegrees */
8568c2ecf20Sopenharmony_ciint rv770_get_temp(struct radeon_device *rdev)
8578c2ecf20Sopenharmony_ci{
8588c2ecf20Sopenharmony_ci	u32 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
8598c2ecf20Sopenharmony_ci		ASIC_T_SHIFT;
8608c2ecf20Sopenharmony_ci	int actual_temp;
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci	if (temp & 0x400)
8638c2ecf20Sopenharmony_ci		actual_temp = -256;
8648c2ecf20Sopenharmony_ci	else if (temp & 0x200)
8658c2ecf20Sopenharmony_ci		actual_temp = 255;
8668c2ecf20Sopenharmony_ci	else if (temp & 0x100) {
8678c2ecf20Sopenharmony_ci		actual_temp = temp & 0x1ff;
8688c2ecf20Sopenharmony_ci		actual_temp |= ~0x1ff;
8698c2ecf20Sopenharmony_ci	} else
8708c2ecf20Sopenharmony_ci		actual_temp = temp & 0xff;
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci	return (actual_temp * 1000) / 2;
8738c2ecf20Sopenharmony_ci}
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_civoid rv770_pm_misc(struct radeon_device *rdev)
8768c2ecf20Sopenharmony_ci{
8778c2ecf20Sopenharmony_ci	int req_ps_idx = rdev->pm.requested_power_state_index;
8788c2ecf20Sopenharmony_ci	int req_cm_idx = rdev->pm.requested_clock_mode_index;
8798c2ecf20Sopenharmony_ci	struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
8808c2ecf20Sopenharmony_ci	struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_ci	if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
8838c2ecf20Sopenharmony_ci		/* 0xff01 is a flag rather then an actual voltage */
8848c2ecf20Sopenharmony_ci		if (voltage->voltage == 0xff01)
8858c2ecf20Sopenharmony_ci			return;
8868c2ecf20Sopenharmony_ci		if (voltage->voltage != rdev->pm.current_vddc) {
8878c2ecf20Sopenharmony_ci			radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
8888c2ecf20Sopenharmony_ci			rdev->pm.current_vddc = voltage->voltage;
8898c2ecf20Sopenharmony_ci			DRM_DEBUG("Setting: v: %d\n", voltage->voltage);
8908c2ecf20Sopenharmony_ci		}
8918c2ecf20Sopenharmony_ci	}
8928c2ecf20Sopenharmony_ci}
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci/*
8958c2ecf20Sopenharmony_ci * GART
8968c2ecf20Sopenharmony_ci */
8978c2ecf20Sopenharmony_cistatic int rv770_pcie_gart_enable(struct radeon_device *rdev)
8988c2ecf20Sopenharmony_ci{
8998c2ecf20Sopenharmony_ci	u32 tmp;
9008c2ecf20Sopenharmony_ci	int r, i;
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	if (rdev->gart.robj == NULL) {
9038c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
9048c2ecf20Sopenharmony_ci		return -EINVAL;
9058c2ecf20Sopenharmony_ci	}
9068c2ecf20Sopenharmony_ci	r = radeon_gart_table_vram_pin(rdev);
9078c2ecf20Sopenharmony_ci	if (r)
9088c2ecf20Sopenharmony_ci		return r;
9098c2ecf20Sopenharmony_ci	/* Setup L2 cache */
9108c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
9118c2ecf20Sopenharmony_ci				ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
9128c2ecf20Sopenharmony_ci				EFFECTIVE_L2_QUEUE_SIZE(7));
9138c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL2, 0);
9148c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
9158c2ecf20Sopenharmony_ci	/* Setup TLB control */
9168c2ecf20Sopenharmony_ci	tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
9178c2ecf20Sopenharmony_ci		SYSTEM_ACCESS_MODE_NOT_IN_SYS |
9188c2ecf20Sopenharmony_ci		SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
9198c2ecf20Sopenharmony_ci		EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
9208c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
9218c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
9228c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
9238c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV740)
9248c2ecf20Sopenharmony_ci		WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
9258c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
9268c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
9278c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
9288c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
9298c2ecf20Sopenharmony_ci	WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
9308c2ecf20Sopenharmony_ci	WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
9318c2ecf20Sopenharmony_ci	WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
9328c2ecf20Sopenharmony_ci	WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
9338c2ecf20Sopenharmony_ci				RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
9348c2ecf20Sopenharmony_ci	WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
9358c2ecf20Sopenharmony_ci			(u32)(rdev->dummy_page.addr >> 12));
9368c2ecf20Sopenharmony_ci	for (i = 1; i < 7; i++)
9378c2ecf20Sopenharmony_ci		WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci	r600_pcie_gart_tlb_flush(rdev);
9408c2ecf20Sopenharmony_ci	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
9418c2ecf20Sopenharmony_ci		 (unsigned)(rdev->mc.gtt_size >> 20),
9428c2ecf20Sopenharmony_ci		 (unsigned long long)rdev->gart.table_addr);
9438c2ecf20Sopenharmony_ci	rdev->gart.ready = true;
9448c2ecf20Sopenharmony_ci	return 0;
9458c2ecf20Sopenharmony_ci}
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_cistatic void rv770_pcie_gart_disable(struct radeon_device *rdev)
9488c2ecf20Sopenharmony_ci{
9498c2ecf20Sopenharmony_ci	u32 tmp;
9508c2ecf20Sopenharmony_ci	int i;
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	/* Disable all tables */
9538c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++)
9548c2ecf20Sopenharmony_ci		WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	/* Setup L2 cache */
9578c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
9588c2ecf20Sopenharmony_ci				EFFECTIVE_L2_QUEUE_SIZE(7));
9598c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL2, 0);
9608c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
9618c2ecf20Sopenharmony_ci	/* Setup TLB control */
9628c2ecf20Sopenharmony_ci	tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
9638c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
9648c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
9658c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
9668c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
9678c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
9688c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
9698c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
9708c2ecf20Sopenharmony_ci	radeon_gart_table_vram_unpin(rdev);
9718c2ecf20Sopenharmony_ci}
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_cistatic void rv770_pcie_gart_fini(struct radeon_device *rdev)
9748c2ecf20Sopenharmony_ci{
9758c2ecf20Sopenharmony_ci	radeon_gart_fini(rdev);
9768c2ecf20Sopenharmony_ci	rv770_pcie_gart_disable(rdev);
9778c2ecf20Sopenharmony_ci	radeon_gart_table_vram_free(rdev);
9788c2ecf20Sopenharmony_ci}
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci
9818c2ecf20Sopenharmony_cistatic void rv770_agp_enable(struct radeon_device *rdev)
9828c2ecf20Sopenharmony_ci{
9838c2ecf20Sopenharmony_ci	u32 tmp;
9848c2ecf20Sopenharmony_ci	int i;
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_ci	/* Setup L2 cache */
9878c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
9888c2ecf20Sopenharmony_ci				ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
9898c2ecf20Sopenharmony_ci				EFFECTIVE_L2_QUEUE_SIZE(7));
9908c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL2, 0);
9918c2ecf20Sopenharmony_ci	WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
9928c2ecf20Sopenharmony_ci	/* Setup TLB control */
9938c2ecf20Sopenharmony_ci	tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
9948c2ecf20Sopenharmony_ci		SYSTEM_ACCESS_MODE_NOT_IN_SYS |
9958c2ecf20Sopenharmony_ci		SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
9968c2ecf20Sopenharmony_ci		EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
9978c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
9988c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
9998c2ecf20Sopenharmony_ci	WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
10008c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
10018c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
10028c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
10038c2ecf20Sopenharmony_ci	WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
10048c2ecf20Sopenharmony_ci	for (i = 0; i < 7; i++)
10058c2ecf20Sopenharmony_ci		WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
10068c2ecf20Sopenharmony_ci}
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_cistatic void rv770_mc_program(struct radeon_device *rdev)
10098c2ecf20Sopenharmony_ci{
10108c2ecf20Sopenharmony_ci	struct rv515_mc_save save;
10118c2ecf20Sopenharmony_ci	u32 tmp;
10128c2ecf20Sopenharmony_ci	int i, j;
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_ci	/* Initialize HDP */
10158c2ecf20Sopenharmony_ci	for (i = 0, j = 0; i < 32; i++, j += 0x18) {
10168c2ecf20Sopenharmony_ci		WREG32((0x2c14 + j), 0x00000000);
10178c2ecf20Sopenharmony_ci		WREG32((0x2c18 + j), 0x00000000);
10188c2ecf20Sopenharmony_ci		WREG32((0x2c1c + j), 0x00000000);
10198c2ecf20Sopenharmony_ci		WREG32((0x2c20 + j), 0x00000000);
10208c2ecf20Sopenharmony_ci		WREG32((0x2c24 + j), 0x00000000);
10218c2ecf20Sopenharmony_ci	}
10228c2ecf20Sopenharmony_ci	/* r7xx hw bug.  Read from HDP_DEBUG1 rather
10238c2ecf20Sopenharmony_ci	 * than writing to HDP_REG_COHERENCY_FLUSH_CNTL
10248c2ecf20Sopenharmony_ci	 */
10258c2ecf20Sopenharmony_ci	tmp = RREG32(HDP_DEBUG1);
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	rv515_mc_stop(rdev, &save);
10288c2ecf20Sopenharmony_ci	if (r600_mc_wait_for_idle(rdev)) {
10298c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
10308c2ecf20Sopenharmony_ci	}
10318c2ecf20Sopenharmony_ci	/* Lockout access through VGA aperture*/
10328c2ecf20Sopenharmony_ci	WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
10338c2ecf20Sopenharmony_ci	/* Update configuration */
10348c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
10358c2ecf20Sopenharmony_ci		if (rdev->mc.vram_start < rdev->mc.gtt_start) {
10368c2ecf20Sopenharmony_ci			/* VRAM before AGP */
10378c2ecf20Sopenharmony_ci			WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
10388c2ecf20Sopenharmony_ci				rdev->mc.vram_start >> 12);
10398c2ecf20Sopenharmony_ci			WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
10408c2ecf20Sopenharmony_ci				rdev->mc.gtt_end >> 12);
10418c2ecf20Sopenharmony_ci		} else {
10428c2ecf20Sopenharmony_ci			/* VRAM after AGP */
10438c2ecf20Sopenharmony_ci			WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
10448c2ecf20Sopenharmony_ci				rdev->mc.gtt_start >> 12);
10458c2ecf20Sopenharmony_ci			WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
10468c2ecf20Sopenharmony_ci				rdev->mc.vram_end >> 12);
10478c2ecf20Sopenharmony_ci		}
10488c2ecf20Sopenharmony_ci	} else {
10498c2ecf20Sopenharmony_ci		WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
10508c2ecf20Sopenharmony_ci			rdev->mc.vram_start >> 12);
10518c2ecf20Sopenharmony_ci		WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
10528c2ecf20Sopenharmony_ci			rdev->mc.vram_end >> 12);
10538c2ecf20Sopenharmony_ci	}
10548c2ecf20Sopenharmony_ci	WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
10558c2ecf20Sopenharmony_ci	tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
10568c2ecf20Sopenharmony_ci	tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
10578c2ecf20Sopenharmony_ci	WREG32(MC_VM_FB_LOCATION, tmp);
10588c2ecf20Sopenharmony_ci	WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
10598c2ecf20Sopenharmony_ci	WREG32(HDP_NONSURFACE_INFO, (2 << 7));
10608c2ecf20Sopenharmony_ci	WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
10618c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
10628c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
10638c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
10648c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
10658c2ecf20Sopenharmony_ci	} else {
10668c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_BASE, 0);
10678c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
10688c2ecf20Sopenharmony_ci		WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
10698c2ecf20Sopenharmony_ci	}
10708c2ecf20Sopenharmony_ci	if (r600_mc_wait_for_idle(rdev)) {
10718c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
10728c2ecf20Sopenharmony_ci	}
10738c2ecf20Sopenharmony_ci	rv515_mc_resume(rdev, &save);
10748c2ecf20Sopenharmony_ci	/* we need to own VRAM, so turn off the VGA renderer here
10758c2ecf20Sopenharmony_ci	 * to stop it overwriting our objects */
10768c2ecf20Sopenharmony_ci	rv515_vga_render_disable(rdev);
10778c2ecf20Sopenharmony_ci}
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci/*
10818c2ecf20Sopenharmony_ci * CP.
10828c2ecf20Sopenharmony_ci */
10838c2ecf20Sopenharmony_civoid r700_cp_stop(struct radeon_device *rdev)
10848c2ecf20Sopenharmony_ci{
10858c2ecf20Sopenharmony_ci	if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
10868c2ecf20Sopenharmony_ci		radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
10878c2ecf20Sopenharmony_ci	WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
10888c2ecf20Sopenharmony_ci	WREG32(SCRATCH_UMSK, 0);
10898c2ecf20Sopenharmony_ci	rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
10908c2ecf20Sopenharmony_ci}
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_cistatic int rv770_cp_load_microcode(struct radeon_device *rdev)
10938c2ecf20Sopenharmony_ci{
10948c2ecf20Sopenharmony_ci	const __be32 *fw_data;
10958c2ecf20Sopenharmony_ci	int i;
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_ci	if (!rdev->me_fw || !rdev->pfp_fw)
10988c2ecf20Sopenharmony_ci		return -EINVAL;
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci	r700_cp_stop(rdev);
11018c2ecf20Sopenharmony_ci	WREG32(CP_RB_CNTL,
11028c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
11038c2ecf20Sopenharmony_ci	       BUF_SWAP_32BIT |
11048c2ecf20Sopenharmony_ci#endif
11058c2ecf20Sopenharmony_ci	       RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_ci	/* Reset cp */
11088c2ecf20Sopenharmony_ci	WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
11098c2ecf20Sopenharmony_ci	RREG32(GRBM_SOFT_RESET);
11108c2ecf20Sopenharmony_ci	mdelay(15);
11118c2ecf20Sopenharmony_ci	WREG32(GRBM_SOFT_RESET, 0);
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	fw_data = (const __be32 *)rdev->pfp_fw->data;
11148c2ecf20Sopenharmony_ci	WREG32(CP_PFP_UCODE_ADDR, 0);
11158c2ecf20Sopenharmony_ci	for (i = 0; i < R700_PFP_UCODE_SIZE; i++)
11168c2ecf20Sopenharmony_ci		WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
11178c2ecf20Sopenharmony_ci	WREG32(CP_PFP_UCODE_ADDR, 0);
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	fw_data = (const __be32 *)rdev->me_fw->data;
11208c2ecf20Sopenharmony_ci	WREG32(CP_ME_RAM_WADDR, 0);
11218c2ecf20Sopenharmony_ci	for (i = 0; i < R700_PM4_UCODE_SIZE; i++)
11228c2ecf20Sopenharmony_ci		WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
11238c2ecf20Sopenharmony_ci
11248c2ecf20Sopenharmony_ci	WREG32(CP_PFP_UCODE_ADDR, 0);
11258c2ecf20Sopenharmony_ci	WREG32(CP_ME_RAM_WADDR, 0);
11268c2ecf20Sopenharmony_ci	WREG32(CP_ME_RAM_RADDR, 0);
11278c2ecf20Sopenharmony_ci	return 0;
11288c2ecf20Sopenharmony_ci}
11298c2ecf20Sopenharmony_ci
11308c2ecf20Sopenharmony_civoid r700_cp_fini(struct radeon_device *rdev)
11318c2ecf20Sopenharmony_ci{
11328c2ecf20Sopenharmony_ci	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
11338c2ecf20Sopenharmony_ci	r700_cp_stop(rdev);
11348c2ecf20Sopenharmony_ci	radeon_ring_fini(rdev, ring);
11358c2ecf20Sopenharmony_ci	radeon_scratch_free(rdev, ring->rptr_save_reg);
11368c2ecf20Sopenharmony_ci}
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_civoid rv770_set_clk_bypass_mode(struct radeon_device *rdev)
11398c2ecf20Sopenharmony_ci{
11408c2ecf20Sopenharmony_ci	u32 tmp, i;
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_IGP)
11438c2ecf20Sopenharmony_ci		return;
11448c2ecf20Sopenharmony_ci
11458c2ecf20Sopenharmony_ci	tmp = RREG32(CG_SPLL_FUNC_CNTL_2);
11468c2ecf20Sopenharmony_ci	tmp &= SCLK_MUX_SEL_MASK;
11478c2ecf20Sopenharmony_ci	tmp |= SCLK_MUX_SEL(1) | SCLK_MUX_UPDATE;
11488c2ecf20Sopenharmony_ci	WREG32(CG_SPLL_FUNC_CNTL_2, tmp);
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->usec_timeout; i++) {
11518c2ecf20Sopenharmony_ci		if (RREG32(CG_SPLL_STATUS) & SPLL_CHG_STATUS)
11528c2ecf20Sopenharmony_ci			break;
11538c2ecf20Sopenharmony_ci		udelay(1);
11548c2ecf20Sopenharmony_ci	}
11558c2ecf20Sopenharmony_ci
11568c2ecf20Sopenharmony_ci	tmp &= ~SCLK_MUX_UPDATE;
11578c2ecf20Sopenharmony_ci	WREG32(CG_SPLL_FUNC_CNTL_2, tmp);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	tmp = RREG32(MPLL_CNTL_MODE);
11608c2ecf20Sopenharmony_ci	if ((rdev->family == CHIP_RV710) || (rdev->family == CHIP_RV730))
11618c2ecf20Sopenharmony_ci		tmp &= ~RV730_MPLL_MCLK_SEL;
11628c2ecf20Sopenharmony_ci	else
11638c2ecf20Sopenharmony_ci		tmp &= ~MPLL_MCLK_SEL;
11648c2ecf20Sopenharmony_ci	WREG32(MPLL_CNTL_MODE, tmp);
11658c2ecf20Sopenharmony_ci}
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_ci/*
11688c2ecf20Sopenharmony_ci * Core functions
11698c2ecf20Sopenharmony_ci */
11708c2ecf20Sopenharmony_cistatic void rv770_gpu_init(struct radeon_device *rdev)
11718c2ecf20Sopenharmony_ci{
11728c2ecf20Sopenharmony_ci	int i, j, num_qd_pipes;
11738c2ecf20Sopenharmony_ci	u32 ta_aux_cntl;
11748c2ecf20Sopenharmony_ci	u32 sx_debug_1;
11758c2ecf20Sopenharmony_ci	u32 smx_dc_ctl0;
11768c2ecf20Sopenharmony_ci	u32 db_debug3;
11778c2ecf20Sopenharmony_ci	u32 num_gs_verts_per_thread;
11788c2ecf20Sopenharmony_ci	u32 vgt_gs_per_es;
11798c2ecf20Sopenharmony_ci	u32 gs_prim_buffer_depth = 0;
11808c2ecf20Sopenharmony_ci	u32 sq_ms_fifo_sizes;
11818c2ecf20Sopenharmony_ci	u32 sq_config;
11828c2ecf20Sopenharmony_ci	u32 sq_thread_resource_mgmt;
11838c2ecf20Sopenharmony_ci	u32 hdp_host_path_cntl;
11848c2ecf20Sopenharmony_ci	u32 sq_dyn_gpr_size_simd_ab_0;
11858c2ecf20Sopenharmony_ci	u32 gb_tiling_config = 0;
11868c2ecf20Sopenharmony_ci	u32 cc_gc_shader_pipe_config = 0;
11878c2ecf20Sopenharmony_ci	u32 mc_arb_ramcfg;
11888c2ecf20Sopenharmony_ci	u32 db_debug4, tmp;
11898c2ecf20Sopenharmony_ci	u32 inactive_pipes, shader_pipe_config;
11908c2ecf20Sopenharmony_ci	u32 disabled_rb_mask;
11918c2ecf20Sopenharmony_ci	unsigned active_number;
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci	/* setup chip specs */
11948c2ecf20Sopenharmony_ci	rdev->config.rv770.tiling_group_size = 256;
11958c2ecf20Sopenharmony_ci	switch (rdev->family) {
11968c2ecf20Sopenharmony_ci	case CHIP_RV770:
11978c2ecf20Sopenharmony_ci		rdev->config.rv770.max_pipes = 4;
11988c2ecf20Sopenharmony_ci		rdev->config.rv770.max_tile_pipes = 8;
11998c2ecf20Sopenharmony_ci		rdev->config.rv770.max_simds = 10;
12008c2ecf20Sopenharmony_ci		rdev->config.rv770.max_backends = 4;
12018c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gprs = 256;
12028c2ecf20Sopenharmony_ci		rdev->config.rv770.max_threads = 248;
12038c2ecf20Sopenharmony_ci		rdev->config.rv770.max_stack_entries = 512;
12048c2ecf20Sopenharmony_ci		rdev->config.rv770.max_hw_contexts = 8;
12058c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gs_threads = 16 * 2;
12068c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_size = 128;
12078c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_pos_size = 16;
12088c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_smx_size = 112;
12098c2ecf20Sopenharmony_ci		rdev->config.rv770.sq_num_cf_insts = 2;
12108c2ecf20Sopenharmony_ci
12118c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_num_of_sets = 7;
12128c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_prim_fifo_size = 0xF9;
12138c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
12148c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
12158c2ecf20Sopenharmony_ci		break;
12168c2ecf20Sopenharmony_ci	case CHIP_RV730:
12178c2ecf20Sopenharmony_ci		rdev->config.rv770.max_pipes = 2;
12188c2ecf20Sopenharmony_ci		rdev->config.rv770.max_tile_pipes = 4;
12198c2ecf20Sopenharmony_ci		rdev->config.rv770.max_simds = 8;
12208c2ecf20Sopenharmony_ci		rdev->config.rv770.max_backends = 2;
12218c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gprs = 128;
12228c2ecf20Sopenharmony_ci		rdev->config.rv770.max_threads = 248;
12238c2ecf20Sopenharmony_ci		rdev->config.rv770.max_stack_entries = 256;
12248c2ecf20Sopenharmony_ci		rdev->config.rv770.max_hw_contexts = 8;
12258c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gs_threads = 16 * 2;
12268c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_size = 256;
12278c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_pos_size = 32;
12288c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_smx_size = 224;
12298c2ecf20Sopenharmony_ci		rdev->config.rv770.sq_num_cf_insts = 2;
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_num_of_sets = 7;
12328c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_prim_fifo_size = 0xf9;
12338c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
12348c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
12358c2ecf20Sopenharmony_ci		if (rdev->config.rv770.sx_max_export_pos_size > 16) {
12368c2ecf20Sopenharmony_ci			rdev->config.rv770.sx_max_export_pos_size -= 16;
12378c2ecf20Sopenharmony_ci			rdev->config.rv770.sx_max_export_smx_size += 16;
12388c2ecf20Sopenharmony_ci		}
12398c2ecf20Sopenharmony_ci		break;
12408c2ecf20Sopenharmony_ci	case CHIP_RV710:
12418c2ecf20Sopenharmony_ci		rdev->config.rv770.max_pipes = 2;
12428c2ecf20Sopenharmony_ci		rdev->config.rv770.max_tile_pipes = 2;
12438c2ecf20Sopenharmony_ci		rdev->config.rv770.max_simds = 2;
12448c2ecf20Sopenharmony_ci		rdev->config.rv770.max_backends = 1;
12458c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gprs = 256;
12468c2ecf20Sopenharmony_ci		rdev->config.rv770.max_threads = 192;
12478c2ecf20Sopenharmony_ci		rdev->config.rv770.max_stack_entries = 256;
12488c2ecf20Sopenharmony_ci		rdev->config.rv770.max_hw_contexts = 4;
12498c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gs_threads = 8 * 2;
12508c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_size = 128;
12518c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_pos_size = 16;
12528c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_smx_size = 112;
12538c2ecf20Sopenharmony_ci		rdev->config.rv770.sq_num_cf_insts = 1;
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_num_of_sets = 7;
12568c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_prim_fifo_size = 0x40;
12578c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
12588c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
12598c2ecf20Sopenharmony_ci		break;
12608c2ecf20Sopenharmony_ci	case CHIP_RV740:
12618c2ecf20Sopenharmony_ci		rdev->config.rv770.max_pipes = 4;
12628c2ecf20Sopenharmony_ci		rdev->config.rv770.max_tile_pipes = 4;
12638c2ecf20Sopenharmony_ci		rdev->config.rv770.max_simds = 8;
12648c2ecf20Sopenharmony_ci		rdev->config.rv770.max_backends = 4;
12658c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gprs = 256;
12668c2ecf20Sopenharmony_ci		rdev->config.rv770.max_threads = 248;
12678c2ecf20Sopenharmony_ci		rdev->config.rv770.max_stack_entries = 512;
12688c2ecf20Sopenharmony_ci		rdev->config.rv770.max_hw_contexts = 8;
12698c2ecf20Sopenharmony_ci		rdev->config.rv770.max_gs_threads = 16 * 2;
12708c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_size = 256;
12718c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_pos_size = 32;
12728c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_max_export_smx_size = 224;
12738c2ecf20Sopenharmony_ci		rdev->config.rv770.sq_num_cf_insts = 2;
12748c2ecf20Sopenharmony_ci
12758c2ecf20Sopenharmony_ci		rdev->config.rv770.sx_num_of_sets = 7;
12768c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_prim_fifo_size = 0x100;
12778c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
12788c2ecf20Sopenharmony_ci		rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
12798c2ecf20Sopenharmony_ci
12808c2ecf20Sopenharmony_ci		if (rdev->config.rv770.sx_max_export_pos_size > 16) {
12818c2ecf20Sopenharmony_ci			rdev->config.rv770.sx_max_export_pos_size -= 16;
12828c2ecf20Sopenharmony_ci			rdev->config.rv770.sx_max_export_smx_size += 16;
12838c2ecf20Sopenharmony_ci		}
12848c2ecf20Sopenharmony_ci		break;
12858c2ecf20Sopenharmony_ci	default:
12868c2ecf20Sopenharmony_ci		break;
12878c2ecf20Sopenharmony_ci	}
12888c2ecf20Sopenharmony_ci
12898c2ecf20Sopenharmony_ci	/* Initialize HDP */
12908c2ecf20Sopenharmony_ci	j = 0;
12918c2ecf20Sopenharmony_ci	for (i = 0; i < 32; i++) {
12928c2ecf20Sopenharmony_ci		WREG32((0x2c14 + j), 0x00000000);
12938c2ecf20Sopenharmony_ci		WREG32((0x2c18 + j), 0x00000000);
12948c2ecf20Sopenharmony_ci		WREG32((0x2c1c + j), 0x00000000);
12958c2ecf20Sopenharmony_ci		WREG32((0x2c20 + j), 0x00000000);
12968c2ecf20Sopenharmony_ci		WREG32((0x2c24 + j), 0x00000000);
12978c2ecf20Sopenharmony_ci		j += 0x18;
12988c2ecf20Sopenharmony_ci	}
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_ci	WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
13018c2ecf20Sopenharmony_ci
13028c2ecf20Sopenharmony_ci	/* setup tiling, simd, pipe config */
13038c2ecf20Sopenharmony_ci	mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_ci	shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG);
13068c2ecf20Sopenharmony_ci	inactive_pipes = (shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT;
13078c2ecf20Sopenharmony_ci	for (i = 0, tmp = 1, active_number = 0; i < R7XX_MAX_PIPES; i++) {
13088c2ecf20Sopenharmony_ci		if (!(inactive_pipes & tmp)) {
13098c2ecf20Sopenharmony_ci			active_number++;
13108c2ecf20Sopenharmony_ci		}
13118c2ecf20Sopenharmony_ci		tmp <<= 1;
13128c2ecf20Sopenharmony_ci	}
13138c2ecf20Sopenharmony_ci	if (active_number == 1) {
13148c2ecf20Sopenharmony_ci		WREG32(SPI_CONFIG_CNTL, DISABLE_INTERP_1);
13158c2ecf20Sopenharmony_ci	} else {
13168c2ecf20Sopenharmony_ci		WREG32(SPI_CONFIG_CNTL, 0);
13178c2ecf20Sopenharmony_ci	}
13188c2ecf20Sopenharmony_ci
13198c2ecf20Sopenharmony_ci	cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
13208c2ecf20Sopenharmony_ci	tmp = rdev->config.rv770.max_simds -
13218c2ecf20Sopenharmony_ci		r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R7XX_MAX_SIMDS_MASK);
13228c2ecf20Sopenharmony_ci	rdev->config.rv770.active_simds = tmp;
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci	switch (rdev->config.rv770.max_tile_pipes) {
13258c2ecf20Sopenharmony_ci	case 1:
13268c2ecf20Sopenharmony_ci	default:
13278c2ecf20Sopenharmony_ci		gb_tiling_config = PIPE_TILING(0);
13288c2ecf20Sopenharmony_ci		break;
13298c2ecf20Sopenharmony_ci	case 2:
13308c2ecf20Sopenharmony_ci		gb_tiling_config = PIPE_TILING(1);
13318c2ecf20Sopenharmony_ci		break;
13328c2ecf20Sopenharmony_ci	case 4:
13338c2ecf20Sopenharmony_ci		gb_tiling_config = PIPE_TILING(2);
13348c2ecf20Sopenharmony_ci		break;
13358c2ecf20Sopenharmony_ci	case 8:
13368c2ecf20Sopenharmony_ci		gb_tiling_config = PIPE_TILING(3);
13378c2ecf20Sopenharmony_ci		break;
13388c2ecf20Sopenharmony_ci	}
13398c2ecf20Sopenharmony_ci	rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes;
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci	disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R7XX_MAX_BACKENDS_MASK;
13428c2ecf20Sopenharmony_ci	tmp = 0;
13438c2ecf20Sopenharmony_ci	for (i = 0; i < rdev->config.rv770.max_backends; i++)
13448c2ecf20Sopenharmony_ci		tmp |= (1 << i);
13458c2ecf20Sopenharmony_ci	/* if all the backends are disabled, fix it up here */
13468c2ecf20Sopenharmony_ci	if ((disabled_rb_mask & tmp) == tmp) {
13478c2ecf20Sopenharmony_ci		for (i = 0; i < rdev->config.rv770.max_backends; i++)
13488c2ecf20Sopenharmony_ci			disabled_rb_mask &= ~(1 << i);
13498c2ecf20Sopenharmony_ci	}
13508c2ecf20Sopenharmony_ci	tmp = (gb_tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
13518c2ecf20Sopenharmony_ci	tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.rv770.max_backends,
13528c2ecf20Sopenharmony_ci					R7XX_MAX_BACKENDS, disabled_rb_mask);
13538c2ecf20Sopenharmony_ci	gb_tiling_config |= tmp << 16;
13548c2ecf20Sopenharmony_ci	rdev->config.rv770.backend_map = tmp;
13558c2ecf20Sopenharmony_ci
13568c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV770)
13578c2ecf20Sopenharmony_ci		gb_tiling_config |= BANK_TILING(1);
13588c2ecf20Sopenharmony_ci	else {
13598c2ecf20Sopenharmony_ci		if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
13608c2ecf20Sopenharmony_ci			gb_tiling_config |= BANK_TILING(1);
13618c2ecf20Sopenharmony_ci		else
13628c2ecf20Sopenharmony_ci			gb_tiling_config |= BANK_TILING(0);
13638c2ecf20Sopenharmony_ci	}
13648c2ecf20Sopenharmony_ci	rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3);
13658c2ecf20Sopenharmony_ci	gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
13668c2ecf20Sopenharmony_ci	if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) {
13678c2ecf20Sopenharmony_ci		gb_tiling_config |= ROW_TILING(3);
13688c2ecf20Sopenharmony_ci		gb_tiling_config |= SAMPLE_SPLIT(3);
13698c2ecf20Sopenharmony_ci	} else {
13708c2ecf20Sopenharmony_ci		gb_tiling_config |=
13718c2ecf20Sopenharmony_ci			ROW_TILING(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
13728c2ecf20Sopenharmony_ci		gb_tiling_config |=
13738c2ecf20Sopenharmony_ci			SAMPLE_SPLIT(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
13748c2ecf20Sopenharmony_ci	}
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci	gb_tiling_config |= BANK_SWAPS(1);
13778c2ecf20Sopenharmony_ci	rdev->config.rv770.tile_config = gb_tiling_config;
13788c2ecf20Sopenharmony_ci
13798c2ecf20Sopenharmony_ci	WREG32(GB_TILING_CONFIG, gb_tiling_config);
13808c2ecf20Sopenharmony_ci	WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
13818c2ecf20Sopenharmony_ci	WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
13828c2ecf20Sopenharmony_ci	WREG32(DMA_TILING_CONFIG, (gb_tiling_config & 0xffff));
13838c2ecf20Sopenharmony_ci	WREG32(DMA_TILING_CONFIG2, (gb_tiling_config & 0xffff));
13848c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV730) {
13858c2ecf20Sopenharmony_ci		WREG32(UVD_UDEC_DB_TILING_CONFIG, (gb_tiling_config & 0xffff));
13868c2ecf20Sopenharmony_ci		WREG32(UVD_UDEC_DBW_TILING_CONFIG, (gb_tiling_config & 0xffff));
13878c2ecf20Sopenharmony_ci		WREG32(UVD_UDEC_TILING_CONFIG, (gb_tiling_config & 0xffff));
13888c2ecf20Sopenharmony_ci	}
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci	WREG32(CGTS_SYS_TCC_DISABLE, 0);
13918c2ecf20Sopenharmony_ci	WREG32(CGTS_TCC_DISABLE, 0);
13928c2ecf20Sopenharmony_ci	WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
13938c2ecf20Sopenharmony_ci	WREG32(CGTS_USER_TCC_DISABLE, 0);
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_ci
13968c2ecf20Sopenharmony_ci	num_qd_pipes = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
13978c2ecf20Sopenharmony_ci	WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK);
13988c2ecf20Sopenharmony_ci	WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK);
13998c2ecf20Sopenharmony_ci
14008c2ecf20Sopenharmony_ci	/* set HW defaults for 3D engine */
14018c2ecf20Sopenharmony_ci	WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
14028c2ecf20Sopenharmony_ci				     ROQ_IB2_START(0x2b)));
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci	WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
14058c2ecf20Sopenharmony_ci
14068c2ecf20Sopenharmony_ci	ta_aux_cntl = RREG32(TA_CNTL_AUX);
14078c2ecf20Sopenharmony_ci	WREG32(TA_CNTL_AUX, ta_aux_cntl | DISABLE_CUBE_ANISO);
14088c2ecf20Sopenharmony_ci
14098c2ecf20Sopenharmony_ci	sx_debug_1 = RREG32(SX_DEBUG_1);
14108c2ecf20Sopenharmony_ci	sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
14118c2ecf20Sopenharmony_ci	WREG32(SX_DEBUG_1, sx_debug_1);
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
14148c2ecf20Sopenharmony_ci	smx_dc_ctl0 &= ~CACHE_DEPTH(0x1ff);
14158c2ecf20Sopenharmony_ci	smx_dc_ctl0 |= CACHE_DEPTH((rdev->config.rv770.sx_num_of_sets * 64) - 1);
14168c2ecf20Sopenharmony_ci	WREG32(SMX_DC_CTL0, smx_dc_ctl0);
14178c2ecf20Sopenharmony_ci
14188c2ecf20Sopenharmony_ci	if (rdev->family != CHIP_RV740)
14198c2ecf20Sopenharmony_ci		WREG32(SMX_EVENT_CTL, (ES_FLUSH_CTL(4) |
14208c2ecf20Sopenharmony_ci				       GS_FLUSH_CTL(4) |
14218c2ecf20Sopenharmony_ci				       ACK_FLUSH_CTL(3) |
14228c2ecf20Sopenharmony_ci				       SYNC_FLUSH_CTL));
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci	if (rdev->family != CHIP_RV770)
14258c2ecf20Sopenharmony_ci		WREG32(SMX_SAR_CTL0, 0x00003f3f);
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci	db_debug3 = RREG32(DB_DEBUG3);
14288c2ecf20Sopenharmony_ci	db_debug3 &= ~DB_CLK_OFF_DELAY(0x1f);
14298c2ecf20Sopenharmony_ci	switch (rdev->family) {
14308c2ecf20Sopenharmony_ci	case CHIP_RV770:
14318c2ecf20Sopenharmony_ci	case CHIP_RV740:
14328c2ecf20Sopenharmony_ci		db_debug3 |= DB_CLK_OFF_DELAY(0x1f);
14338c2ecf20Sopenharmony_ci		break;
14348c2ecf20Sopenharmony_ci	case CHIP_RV710:
14358c2ecf20Sopenharmony_ci	case CHIP_RV730:
14368c2ecf20Sopenharmony_ci	default:
14378c2ecf20Sopenharmony_ci		db_debug3 |= DB_CLK_OFF_DELAY(2);
14388c2ecf20Sopenharmony_ci		break;
14398c2ecf20Sopenharmony_ci	}
14408c2ecf20Sopenharmony_ci	WREG32(DB_DEBUG3, db_debug3);
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	if (rdev->family != CHIP_RV770) {
14438c2ecf20Sopenharmony_ci		db_debug4 = RREG32(DB_DEBUG4);
14448c2ecf20Sopenharmony_ci		db_debug4 |= DISABLE_TILE_COVERED_FOR_PS_ITER;
14458c2ecf20Sopenharmony_ci		WREG32(DB_DEBUG4, db_debug4);
14468c2ecf20Sopenharmony_ci	}
14478c2ecf20Sopenharmony_ci
14488c2ecf20Sopenharmony_ci	WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.rv770.sx_max_export_size / 4) - 1) |
14498c2ecf20Sopenharmony_ci					POSITION_BUFFER_SIZE((rdev->config.rv770.sx_max_export_pos_size / 4) - 1) |
14508c2ecf20Sopenharmony_ci					SMX_BUFFER_SIZE((rdev->config.rv770.sx_max_export_smx_size / 4) - 1)));
14518c2ecf20Sopenharmony_ci
14528c2ecf20Sopenharmony_ci	WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.rv770.sc_prim_fifo_size) |
14538c2ecf20Sopenharmony_ci				 SC_HIZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_hiz_tile_fifo_size) |
14548c2ecf20Sopenharmony_ci				 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_earlyz_tile_fifo_fize)));
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
14578c2ecf20Sopenharmony_ci
14588c2ecf20Sopenharmony_ci	WREG32(VGT_NUM_INSTANCES, 1);
14598c2ecf20Sopenharmony_ci
14608c2ecf20Sopenharmony_ci	WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
14618c2ecf20Sopenharmony_ci
14628c2ecf20Sopenharmony_ci	WREG32(CP_PERFMON_CNTL, 0);
14638c2ecf20Sopenharmony_ci
14648c2ecf20Sopenharmony_ci	sq_ms_fifo_sizes = (CACHE_FIFO_SIZE(16 * rdev->config.rv770.sq_num_cf_insts) |
14658c2ecf20Sopenharmony_ci			    DONE_FIFO_HIWATER(0xe0) |
14668c2ecf20Sopenharmony_ci			    ALU_UPDATE_FIFO_HIWATER(0x8));
14678c2ecf20Sopenharmony_ci	switch (rdev->family) {
14688c2ecf20Sopenharmony_ci	case CHIP_RV770:
14698c2ecf20Sopenharmony_ci	case CHIP_RV730:
14708c2ecf20Sopenharmony_ci	case CHIP_RV710:
14718c2ecf20Sopenharmony_ci		sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x1);
14728c2ecf20Sopenharmony_ci		break;
14738c2ecf20Sopenharmony_ci	case CHIP_RV740:
14748c2ecf20Sopenharmony_ci	default:
14758c2ecf20Sopenharmony_ci		sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x4);
14768c2ecf20Sopenharmony_ci		break;
14778c2ecf20Sopenharmony_ci	}
14788c2ecf20Sopenharmony_ci	WREG32(SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci	/* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
14818c2ecf20Sopenharmony_ci	 * should be adjusted as needed by the 2D/3D drivers.  This just sets default values
14828c2ecf20Sopenharmony_ci	 */
14838c2ecf20Sopenharmony_ci	sq_config = RREG32(SQ_CONFIG);
14848c2ecf20Sopenharmony_ci	sq_config &= ~(PS_PRIO(3) |
14858c2ecf20Sopenharmony_ci		       VS_PRIO(3) |
14868c2ecf20Sopenharmony_ci		       GS_PRIO(3) |
14878c2ecf20Sopenharmony_ci		       ES_PRIO(3));
14888c2ecf20Sopenharmony_ci	sq_config |= (DX9_CONSTS |
14898c2ecf20Sopenharmony_ci		      VC_ENABLE |
14908c2ecf20Sopenharmony_ci		      EXPORT_SRC_C |
14918c2ecf20Sopenharmony_ci		      PS_PRIO(0) |
14928c2ecf20Sopenharmony_ci		      VS_PRIO(1) |
14938c2ecf20Sopenharmony_ci		      GS_PRIO(2) |
14948c2ecf20Sopenharmony_ci		      ES_PRIO(3));
14958c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV710)
14968c2ecf20Sopenharmony_ci		/* no vertex cache */
14978c2ecf20Sopenharmony_ci		sq_config &= ~VC_ENABLE;
14988c2ecf20Sopenharmony_ci
14998c2ecf20Sopenharmony_ci	WREG32(SQ_CONFIG, sq_config);
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci	WREG32(SQ_GPR_RESOURCE_MGMT_1,  (NUM_PS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
15028c2ecf20Sopenharmony_ci					 NUM_VS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
15038c2ecf20Sopenharmony_ci					 NUM_CLAUSE_TEMP_GPRS(((rdev->config.rv770.max_gprs * 24)/64)/2)));
15048c2ecf20Sopenharmony_ci
15058c2ecf20Sopenharmony_ci	WREG32(SQ_GPR_RESOURCE_MGMT_2,  (NUM_GS_GPRS((rdev->config.rv770.max_gprs * 7)/64) |
15068c2ecf20Sopenharmony_ci					 NUM_ES_GPRS((rdev->config.rv770.max_gprs * 7)/64)));
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_ci	sq_thread_resource_mgmt = (NUM_PS_THREADS((rdev->config.rv770.max_threads * 4)/8) |
15098c2ecf20Sopenharmony_ci				   NUM_VS_THREADS((rdev->config.rv770.max_threads * 2)/8) |
15108c2ecf20Sopenharmony_ci				   NUM_ES_THREADS((rdev->config.rv770.max_threads * 1)/8));
15118c2ecf20Sopenharmony_ci	if (((rdev->config.rv770.max_threads * 1) / 8) > rdev->config.rv770.max_gs_threads)
15128c2ecf20Sopenharmony_ci		sq_thread_resource_mgmt |= NUM_GS_THREADS(rdev->config.rv770.max_gs_threads);
15138c2ecf20Sopenharmony_ci	else
15148c2ecf20Sopenharmony_ci		sq_thread_resource_mgmt |= NUM_GS_THREADS((rdev->config.rv770.max_gs_threads * 1)/8);
15158c2ecf20Sopenharmony_ci	WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ci	WREG32(SQ_STACK_RESOURCE_MGMT_1, (NUM_PS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
15188c2ecf20Sopenharmony_ci						     NUM_VS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_ci	WREG32(SQ_STACK_RESOURCE_MGMT_2, (NUM_GS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
15218c2ecf20Sopenharmony_ci						     NUM_ES_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_ci	sq_dyn_gpr_size_simd_ab_0 = (SIMDA_RING0((rdev->config.rv770.max_gprs * 38)/64) |
15248c2ecf20Sopenharmony_ci				     SIMDA_RING1((rdev->config.rv770.max_gprs * 38)/64) |
15258c2ecf20Sopenharmony_ci				     SIMDB_RING0((rdev->config.rv770.max_gprs * 38)/64) |
15268c2ecf20Sopenharmony_ci				     SIMDB_RING1((rdev->config.rv770.max_gprs * 38)/64));
15278c2ecf20Sopenharmony_ci
15288c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0);
15298c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0);
15308c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0);
15318c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0);
15328c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0);
15338c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0);
15348c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0);
15358c2ecf20Sopenharmony_ci	WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0);
15368c2ecf20Sopenharmony_ci
15378c2ecf20Sopenharmony_ci	WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
15388c2ecf20Sopenharmony_ci					  FORCE_EOV_MAX_REZ_CNT(255)));
15398c2ecf20Sopenharmony_ci
15408c2ecf20Sopenharmony_ci	if (rdev->family == CHIP_RV710)
15418c2ecf20Sopenharmony_ci		WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(TC_ONLY) |
15428c2ecf20Sopenharmony_ci						AUTO_INVLD_EN(ES_AND_GS_AUTO)));
15438c2ecf20Sopenharmony_ci	else
15448c2ecf20Sopenharmony_ci		WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(VC_AND_TC) |
15458c2ecf20Sopenharmony_ci						AUTO_INVLD_EN(ES_AND_GS_AUTO)));
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_ci	switch (rdev->family) {
15488c2ecf20Sopenharmony_ci	case CHIP_RV770:
15498c2ecf20Sopenharmony_ci	case CHIP_RV730:
15508c2ecf20Sopenharmony_ci	case CHIP_RV740:
15518c2ecf20Sopenharmony_ci		gs_prim_buffer_depth = 384;
15528c2ecf20Sopenharmony_ci		break;
15538c2ecf20Sopenharmony_ci	case CHIP_RV710:
15548c2ecf20Sopenharmony_ci		gs_prim_buffer_depth = 128;
15558c2ecf20Sopenharmony_ci		break;
15568c2ecf20Sopenharmony_ci	default:
15578c2ecf20Sopenharmony_ci		break;
15588c2ecf20Sopenharmony_ci	}
15598c2ecf20Sopenharmony_ci
15608c2ecf20Sopenharmony_ci	num_gs_verts_per_thread = rdev->config.rv770.max_pipes * 16;
15618c2ecf20Sopenharmony_ci	vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
15628c2ecf20Sopenharmony_ci	/* Max value for this is 256 */
15638c2ecf20Sopenharmony_ci	if (vgt_gs_per_es > 256)
15648c2ecf20Sopenharmony_ci		vgt_gs_per_es = 256;
15658c2ecf20Sopenharmony_ci
15668c2ecf20Sopenharmony_ci	WREG32(VGT_ES_PER_GS, 128);
15678c2ecf20Sopenharmony_ci	WREG32(VGT_GS_PER_ES, vgt_gs_per_es);
15688c2ecf20Sopenharmony_ci	WREG32(VGT_GS_PER_VS, 2);
15698c2ecf20Sopenharmony_ci
15708c2ecf20Sopenharmony_ci	/* more default values. 2D/3D driver should adjust as needed */
15718c2ecf20Sopenharmony_ci	WREG32(VGT_GS_VERTEX_REUSE, 16);
15728c2ecf20Sopenharmony_ci	WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
15738c2ecf20Sopenharmony_ci	WREG32(VGT_STRMOUT_EN, 0);
15748c2ecf20Sopenharmony_ci	WREG32(SX_MISC, 0);
15758c2ecf20Sopenharmony_ci	WREG32(PA_SC_MODE_CNTL, 0);
15768c2ecf20Sopenharmony_ci	WREG32(PA_SC_EDGERULE, 0xaaaaaaaa);
15778c2ecf20Sopenharmony_ci	WREG32(PA_SC_AA_CONFIG, 0);
15788c2ecf20Sopenharmony_ci	WREG32(PA_SC_CLIPRECT_RULE, 0xffff);
15798c2ecf20Sopenharmony_ci	WREG32(PA_SC_LINE_STIPPLE, 0);
15808c2ecf20Sopenharmony_ci	WREG32(SPI_INPUT_Z, 0);
15818c2ecf20Sopenharmony_ci	WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
15828c2ecf20Sopenharmony_ci	WREG32(CB_COLOR7_FRAG, 0);
15838c2ecf20Sopenharmony_ci
15848c2ecf20Sopenharmony_ci	/* clear render buffer base addresses */
15858c2ecf20Sopenharmony_ci	WREG32(CB_COLOR0_BASE, 0);
15868c2ecf20Sopenharmony_ci	WREG32(CB_COLOR1_BASE, 0);
15878c2ecf20Sopenharmony_ci	WREG32(CB_COLOR2_BASE, 0);
15888c2ecf20Sopenharmony_ci	WREG32(CB_COLOR3_BASE, 0);
15898c2ecf20Sopenharmony_ci	WREG32(CB_COLOR4_BASE, 0);
15908c2ecf20Sopenharmony_ci	WREG32(CB_COLOR5_BASE, 0);
15918c2ecf20Sopenharmony_ci	WREG32(CB_COLOR6_BASE, 0);
15928c2ecf20Sopenharmony_ci	WREG32(CB_COLOR7_BASE, 0);
15938c2ecf20Sopenharmony_ci
15948c2ecf20Sopenharmony_ci	WREG32(TCP_CNTL, 0);
15958c2ecf20Sopenharmony_ci
15968c2ecf20Sopenharmony_ci	hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
15978c2ecf20Sopenharmony_ci	WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
15988c2ecf20Sopenharmony_ci
15998c2ecf20Sopenharmony_ci	WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
16028c2ecf20Sopenharmony_ci					  NUM_CLIP_SEQ(3)));
16038c2ecf20Sopenharmony_ci	WREG32(VC_ENHANCE, 0);
16048c2ecf20Sopenharmony_ci}
16058c2ecf20Sopenharmony_ci
16068c2ecf20Sopenharmony_civoid r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
16078c2ecf20Sopenharmony_ci{
16088c2ecf20Sopenharmony_ci	u64 size_bf, size_af;
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_ci	if (mc->mc_vram_size > 0xE0000000) {
16118c2ecf20Sopenharmony_ci		/* leave room for at least 512M GTT */
16128c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "limiting VRAM\n");
16138c2ecf20Sopenharmony_ci		mc->real_vram_size = 0xE0000000;
16148c2ecf20Sopenharmony_ci		mc->mc_vram_size = 0xE0000000;
16158c2ecf20Sopenharmony_ci	}
16168c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
16178c2ecf20Sopenharmony_ci		size_bf = mc->gtt_start;
16188c2ecf20Sopenharmony_ci		size_af = mc->mc_mask - mc->gtt_end;
16198c2ecf20Sopenharmony_ci		if (size_bf > size_af) {
16208c2ecf20Sopenharmony_ci			if (mc->mc_vram_size > size_bf) {
16218c2ecf20Sopenharmony_ci				dev_warn(rdev->dev, "limiting VRAM\n");
16228c2ecf20Sopenharmony_ci				mc->real_vram_size = size_bf;
16238c2ecf20Sopenharmony_ci				mc->mc_vram_size = size_bf;
16248c2ecf20Sopenharmony_ci			}
16258c2ecf20Sopenharmony_ci			mc->vram_start = mc->gtt_start - mc->mc_vram_size;
16268c2ecf20Sopenharmony_ci		} else {
16278c2ecf20Sopenharmony_ci			if (mc->mc_vram_size > size_af) {
16288c2ecf20Sopenharmony_ci				dev_warn(rdev->dev, "limiting VRAM\n");
16298c2ecf20Sopenharmony_ci				mc->real_vram_size = size_af;
16308c2ecf20Sopenharmony_ci				mc->mc_vram_size = size_af;
16318c2ecf20Sopenharmony_ci			}
16328c2ecf20Sopenharmony_ci			mc->vram_start = mc->gtt_end + 1;
16338c2ecf20Sopenharmony_ci		}
16348c2ecf20Sopenharmony_ci		mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
16358c2ecf20Sopenharmony_ci		dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
16368c2ecf20Sopenharmony_ci				mc->mc_vram_size >> 20, mc->vram_start,
16378c2ecf20Sopenharmony_ci				mc->vram_end, mc->real_vram_size >> 20);
16388c2ecf20Sopenharmony_ci	} else {
16398c2ecf20Sopenharmony_ci		radeon_vram_location(rdev, &rdev->mc, 0);
16408c2ecf20Sopenharmony_ci		rdev->mc.gtt_base_align = 0;
16418c2ecf20Sopenharmony_ci		radeon_gtt_location(rdev, mc);
16428c2ecf20Sopenharmony_ci	}
16438c2ecf20Sopenharmony_ci}
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_cistatic int rv770_mc_init(struct radeon_device *rdev)
16468c2ecf20Sopenharmony_ci{
16478c2ecf20Sopenharmony_ci	u32 tmp;
16488c2ecf20Sopenharmony_ci	int chansize, numchan;
16498c2ecf20Sopenharmony_ci
16508c2ecf20Sopenharmony_ci	/* Get VRAM informations */
16518c2ecf20Sopenharmony_ci	rdev->mc.vram_is_ddr = true;
16528c2ecf20Sopenharmony_ci	tmp = RREG32(MC_ARB_RAMCFG);
16538c2ecf20Sopenharmony_ci	if (tmp & CHANSIZE_OVERRIDE) {
16548c2ecf20Sopenharmony_ci		chansize = 16;
16558c2ecf20Sopenharmony_ci	} else if (tmp & CHANSIZE_MASK) {
16568c2ecf20Sopenharmony_ci		chansize = 64;
16578c2ecf20Sopenharmony_ci	} else {
16588c2ecf20Sopenharmony_ci		chansize = 32;
16598c2ecf20Sopenharmony_ci	}
16608c2ecf20Sopenharmony_ci	tmp = RREG32(MC_SHARED_CHMAP);
16618c2ecf20Sopenharmony_ci	switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
16628c2ecf20Sopenharmony_ci	case 0:
16638c2ecf20Sopenharmony_ci	default:
16648c2ecf20Sopenharmony_ci		numchan = 1;
16658c2ecf20Sopenharmony_ci		break;
16668c2ecf20Sopenharmony_ci	case 1:
16678c2ecf20Sopenharmony_ci		numchan = 2;
16688c2ecf20Sopenharmony_ci		break;
16698c2ecf20Sopenharmony_ci	case 2:
16708c2ecf20Sopenharmony_ci		numchan = 4;
16718c2ecf20Sopenharmony_ci		break;
16728c2ecf20Sopenharmony_ci	case 3:
16738c2ecf20Sopenharmony_ci		numchan = 8;
16748c2ecf20Sopenharmony_ci		break;
16758c2ecf20Sopenharmony_ci	}
16768c2ecf20Sopenharmony_ci	rdev->mc.vram_width = numchan * chansize;
16778c2ecf20Sopenharmony_ci	/* Could aper size report 0 ? */
16788c2ecf20Sopenharmony_ci	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
16798c2ecf20Sopenharmony_ci	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
16808c2ecf20Sopenharmony_ci	/* Setup GPU memory space */
16818c2ecf20Sopenharmony_ci	rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
16828c2ecf20Sopenharmony_ci	rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
16838c2ecf20Sopenharmony_ci	rdev->mc.visible_vram_size = rdev->mc.aper_size;
16848c2ecf20Sopenharmony_ci	r700_vram_gtt_location(rdev, &rdev->mc);
16858c2ecf20Sopenharmony_ci	radeon_update_bandwidth_info(rdev);
16868c2ecf20Sopenharmony_ci
16878c2ecf20Sopenharmony_ci	return 0;
16888c2ecf20Sopenharmony_ci}
16898c2ecf20Sopenharmony_ci
16908c2ecf20Sopenharmony_cistatic void rv770_uvd_init(struct radeon_device *rdev)
16918c2ecf20Sopenharmony_ci{
16928c2ecf20Sopenharmony_ci	int r;
16938c2ecf20Sopenharmony_ci
16948c2ecf20Sopenharmony_ci	if (!rdev->has_uvd)
16958c2ecf20Sopenharmony_ci		return;
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_ci	r = radeon_uvd_init(rdev);
16988c2ecf20Sopenharmony_ci	if (r) {
16998c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
17008c2ecf20Sopenharmony_ci		/*
17018c2ecf20Sopenharmony_ci		 * At this point rdev->uvd.vcpu_bo is NULL which trickles down
17028c2ecf20Sopenharmony_ci		 * to early fails uvd_v2_2_resume() and thus nothing happens
17038c2ecf20Sopenharmony_ci		 * there. So it is pointless to try to go through that code
17048c2ecf20Sopenharmony_ci		 * hence why we disable uvd here.
17058c2ecf20Sopenharmony_ci		 */
17068c2ecf20Sopenharmony_ci		rdev->has_uvd = false;
17078c2ecf20Sopenharmony_ci		return;
17088c2ecf20Sopenharmony_ci	}
17098c2ecf20Sopenharmony_ci	rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
17108c2ecf20Sopenharmony_ci	r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
17118c2ecf20Sopenharmony_ci}
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_cistatic void rv770_uvd_start(struct radeon_device *rdev)
17148c2ecf20Sopenharmony_ci{
17158c2ecf20Sopenharmony_ci	int r;
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci	if (!rdev->has_uvd)
17188c2ecf20Sopenharmony_ci		return;
17198c2ecf20Sopenharmony_ci
17208c2ecf20Sopenharmony_ci	r = uvd_v2_2_resume(rdev);
17218c2ecf20Sopenharmony_ci	if (r) {
17228c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
17238c2ecf20Sopenharmony_ci		goto error;
17248c2ecf20Sopenharmony_ci	}
17258c2ecf20Sopenharmony_ci	r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
17268c2ecf20Sopenharmony_ci	if (r) {
17278c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
17288c2ecf20Sopenharmony_ci		goto error;
17298c2ecf20Sopenharmony_ci	}
17308c2ecf20Sopenharmony_ci	return;
17318c2ecf20Sopenharmony_ci
17328c2ecf20Sopenharmony_cierror:
17338c2ecf20Sopenharmony_ci	rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
17348c2ecf20Sopenharmony_ci}
17358c2ecf20Sopenharmony_ci
17368c2ecf20Sopenharmony_cistatic void rv770_uvd_resume(struct radeon_device *rdev)
17378c2ecf20Sopenharmony_ci{
17388c2ecf20Sopenharmony_ci	struct radeon_ring *ring;
17398c2ecf20Sopenharmony_ci	int r;
17408c2ecf20Sopenharmony_ci
17418c2ecf20Sopenharmony_ci	if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
17428c2ecf20Sopenharmony_ci		return;
17438c2ecf20Sopenharmony_ci
17448c2ecf20Sopenharmony_ci	ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
17458c2ecf20Sopenharmony_ci	r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
17468c2ecf20Sopenharmony_ci	if (r) {
17478c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
17488c2ecf20Sopenharmony_ci		return;
17498c2ecf20Sopenharmony_ci	}
17508c2ecf20Sopenharmony_ci	r = uvd_v1_0_init(rdev);
17518c2ecf20Sopenharmony_ci	if (r) {
17528c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
17538c2ecf20Sopenharmony_ci		return;
17548c2ecf20Sopenharmony_ci	}
17558c2ecf20Sopenharmony_ci}
17568c2ecf20Sopenharmony_ci
17578c2ecf20Sopenharmony_cistatic int rv770_startup(struct radeon_device *rdev)
17588c2ecf20Sopenharmony_ci{
17598c2ecf20Sopenharmony_ci	struct radeon_ring *ring;
17608c2ecf20Sopenharmony_ci	int r;
17618c2ecf20Sopenharmony_ci
17628c2ecf20Sopenharmony_ci	/* enable pcie gen2 link */
17638c2ecf20Sopenharmony_ci	rv770_pcie_gen2_enable(rdev);
17648c2ecf20Sopenharmony_ci
17658c2ecf20Sopenharmony_ci	/* scratch needs to be initialized before MC */
17668c2ecf20Sopenharmony_ci	r = r600_vram_scratch_init(rdev);
17678c2ecf20Sopenharmony_ci	if (r)
17688c2ecf20Sopenharmony_ci		return r;
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci	rv770_mc_program(rdev);
17718c2ecf20Sopenharmony_ci
17728c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
17738c2ecf20Sopenharmony_ci		rv770_agp_enable(rdev);
17748c2ecf20Sopenharmony_ci	} else {
17758c2ecf20Sopenharmony_ci		r = rv770_pcie_gart_enable(rdev);
17768c2ecf20Sopenharmony_ci		if (r)
17778c2ecf20Sopenharmony_ci			return r;
17788c2ecf20Sopenharmony_ci	}
17798c2ecf20Sopenharmony_ci
17808c2ecf20Sopenharmony_ci	rv770_gpu_init(rdev);
17818c2ecf20Sopenharmony_ci
17828c2ecf20Sopenharmony_ci	/* allocate wb buffer */
17838c2ecf20Sopenharmony_ci	r = radeon_wb_init(rdev);
17848c2ecf20Sopenharmony_ci	if (r)
17858c2ecf20Sopenharmony_ci		return r;
17868c2ecf20Sopenharmony_ci
17878c2ecf20Sopenharmony_ci	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
17888c2ecf20Sopenharmony_ci	if (r) {
17898c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
17908c2ecf20Sopenharmony_ci		return r;
17918c2ecf20Sopenharmony_ci	}
17928c2ecf20Sopenharmony_ci
17938c2ecf20Sopenharmony_ci	r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
17948c2ecf20Sopenharmony_ci	if (r) {
17958c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
17968c2ecf20Sopenharmony_ci		return r;
17978c2ecf20Sopenharmony_ci	}
17988c2ecf20Sopenharmony_ci
17998c2ecf20Sopenharmony_ci	rv770_uvd_start(rdev);
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci	/* Enable IRQ */
18028c2ecf20Sopenharmony_ci	if (!rdev->irq.installed) {
18038c2ecf20Sopenharmony_ci		r = radeon_irq_kms_init(rdev);
18048c2ecf20Sopenharmony_ci		if (r)
18058c2ecf20Sopenharmony_ci			return r;
18068c2ecf20Sopenharmony_ci	}
18078c2ecf20Sopenharmony_ci
18088c2ecf20Sopenharmony_ci	r = r600_irq_init(rdev);
18098c2ecf20Sopenharmony_ci	if (r) {
18108c2ecf20Sopenharmony_ci		DRM_ERROR("radeon: IH init failed (%d).\n", r);
18118c2ecf20Sopenharmony_ci		radeon_irq_kms_fini(rdev);
18128c2ecf20Sopenharmony_ci		return r;
18138c2ecf20Sopenharmony_ci	}
18148c2ecf20Sopenharmony_ci	r600_irq_set(rdev);
18158c2ecf20Sopenharmony_ci
18168c2ecf20Sopenharmony_ci	ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
18178c2ecf20Sopenharmony_ci	r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
18188c2ecf20Sopenharmony_ci			     RADEON_CP_PACKET2);
18198c2ecf20Sopenharmony_ci	if (r)
18208c2ecf20Sopenharmony_ci		return r;
18218c2ecf20Sopenharmony_ci
18228c2ecf20Sopenharmony_ci	ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
18238c2ecf20Sopenharmony_ci	r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
18248c2ecf20Sopenharmony_ci			     DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
18258c2ecf20Sopenharmony_ci	if (r)
18268c2ecf20Sopenharmony_ci		return r;
18278c2ecf20Sopenharmony_ci
18288c2ecf20Sopenharmony_ci	r = rv770_cp_load_microcode(rdev);
18298c2ecf20Sopenharmony_ci	if (r)
18308c2ecf20Sopenharmony_ci		return r;
18318c2ecf20Sopenharmony_ci	r = r600_cp_resume(rdev);
18328c2ecf20Sopenharmony_ci	if (r)
18338c2ecf20Sopenharmony_ci		return r;
18348c2ecf20Sopenharmony_ci
18358c2ecf20Sopenharmony_ci	r = r600_dma_resume(rdev);
18368c2ecf20Sopenharmony_ci	if (r)
18378c2ecf20Sopenharmony_ci		return r;
18388c2ecf20Sopenharmony_ci
18398c2ecf20Sopenharmony_ci	rv770_uvd_resume(rdev);
18408c2ecf20Sopenharmony_ci
18418c2ecf20Sopenharmony_ci	r = radeon_ib_pool_init(rdev);
18428c2ecf20Sopenharmony_ci	if (r) {
18438c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
18448c2ecf20Sopenharmony_ci		return r;
18458c2ecf20Sopenharmony_ci	}
18468c2ecf20Sopenharmony_ci
18478c2ecf20Sopenharmony_ci	r = radeon_audio_init(rdev);
18488c2ecf20Sopenharmony_ci	if (r) {
18498c2ecf20Sopenharmony_ci		DRM_ERROR("radeon: audio init failed\n");
18508c2ecf20Sopenharmony_ci		return r;
18518c2ecf20Sopenharmony_ci	}
18528c2ecf20Sopenharmony_ci
18538c2ecf20Sopenharmony_ci	return 0;
18548c2ecf20Sopenharmony_ci}
18558c2ecf20Sopenharmony_ci
18568c2ecf20Sopenharmony_ciint rv770_resume(struct radeon_device *rdev)
18578c2ecf20Sopenharmony_ci{
18588c2ecf20Sopenharmony_ci	int r;
18598c2ecf20Sopenharmony_ci
18608c2ecf20Sopenharmony_ci	/* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
18618c2ecf20Sopenharmony_ci	 * posting will perform necessary task to bring back GPU into good
18628c2ecf20Sopenharmony_ci	 * shape.
18638c2ecf20Sopenharmony_ci	 */
18648c2ecf20Sopenharmony_ci	/* post card */
18658c2ecf20Sopenharmony_ci	atom_asic_init(rdev->mode_info.atom_context);
18668c2ecf20Sopenharmony_ci
18678c2ecf20Sopenharmony_ci	/* init golden registers */
18688c2ecf20Sopenharmony_ci	rv770_init_golden_registers(rdev);
18698c2ecf20Sopenharmony_ci
18708c2ecf20Sopenharmony_ci	if (rdev->pm.pm_method == PM_METHOD_DPM)
18718c2ecf20Sopenharmony_ci		radeon_pm_resume(rdev);
18728c2ecf20Sopenharmony_ci
18738c2ecf20Sopenharmony_ci	rdev->accel_working = true;
18748c2ecf20Sopenharmony_ci	r = rv770_startup(rdev);
18758c2ecf20Sopenharmony_ci	if (r) {
18768c2ecf20Sopenharmony_ci		DRM_ERROR("r600 startup failed on resume\n");
18778c2ecf20Sopenharmony_ci		rdev->accel_working = false;
18788c2ecf20Sopenharmony_ci		return r;
18798c2ecf20Sopenharmony_ci	}
18808c2ecf20Sopenharmony_ci
18818c2ecf20Sopenharmony_ci	return r;
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_ci}
18848c2ecf20Sopenharmony_ci
18858c2ecf20Sopenharmony_ciint rv770_suspend(struct radeon_device *rdev)
18868c2ecf20Sopenharmony_ci{
18878c2ecf20Sopenharmony_ci	radeon_pm_suspend(rdev);
18888c2ecf20Sopenharmony_ci	radeon_audio_fini(rdev);
18898c2ecf20Sopenharmony_ci	if (rdev->has_uvd) {
18908c2ecf20Sopenharmony_ci		uvd_v1_0_fini(rdev);
18918c2ecf20Sopenharmony_ci		radeon_uvd_suspend(rdev);
18928c2ecf20Sopenharmony_ci	}
18938c2ecf20Sopenharmony_ci	r700_cp_stop(rdev);
18948c2ecf20Sopenharmony_ci	r600_dma_stop(rdev);
18958c2ecf20Sopenharmony_ci	r600_irq_suspend(rdev);
18968c2ecf20Sopenharmony_ci	radeon_wb_disable(rdev);
18978c2ecf20Sopenharmony_ci	rv770_pcie_gart_disable(rdev);
18988c2ecf20Sopenharmony_ci
18998c2ecf20Sopenharmony_ci	return 0;
19008c2ecf20Sopenharmony_ci}
19018c2ecf20Sopenharmony_ci
19028c2ecf20Sopenharmony_ci/* Plan is to move initialization in that function and use
19038c2ecf20Sopenharmony_ci * helper function so that radeon_device_init pretty much
19048c2ecf20Sopenharmony_ci * do nothing more than calling asic specific function. This
19058c2ecf20Sopenharmony_ci * should also allow to remove a bunch of callback function
19068c2ecf20Sopenharmony_ci * like vram_info.
19078c2ecf20Sopenharmony_ci */
19088c2ecf20Sopenharmony_ciint rv770_init(struct radeon_device *rdev)
19098c2ecf20Sopenharmony_ci{
19108c2ecf20Sopenharmony_ci	int r;
19118c2ecf20Sopenharmony_ci
19128c2ecf20Sopenharmony_ci	/* Read BIOS */
19138c2ecf20Sopenharmony_ci	if (!radeon_get_bios(rdev)) {
19148c2ecf20Sopenharmony_ci		if (ASIC_IS_AVIVO(rdev))
19158c2ecf20Sopenharmony_ci			return -EINVAL;
19168c2ecf20Sopenharmony_ci	}
19178c2ecf20Sopenharmony_ci	/* Must be an ATOMBIOS */
19188c2ecf20Sopenharmony_ci	if (!rdev->is_atom_bios) {
19198c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
19208c2ecf20Sopenharmony_ci		return -EINVAL;
19218c2ecf20Sopenharmony_ci	}
19228c2ecf20Sopenharmony_ci	r = radeon_atombios_init(rdev);
19238c2ecf20Sopenharmony_ci	if (r)
19248c2ecf20Sopenharmony_ci		return r;
19258c2ecf20Sopenharmony_ci	/* Post card if necessary */
19268c2ecf20Sopenharmony_ci	if (!radeon_card_posted(rdev)) {
19278c2ecf20Sopenharmony_ci		if (!rdev->bios) {
19288c2ecf20Sopenharmony_ci			dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
19298c2ecf20Sopenharmony_ci			return -EINVAL;
19308c2ecf20Sopenharmony_ci		}
19318c2ecf20Sopenharmony_ci		DRM_INFO("GPU not posted. posting now...\n");
19328c2ecf20Sopenharmony_ci		atom_asic_init(rdev->mode_info.atom_context);
19338c2ecf20Sopenharmony_ci	}
19348c2ecf20Sopenharmony_ci	/* init golden registers */
19358c2ecf20Sopenharmony_ci	rv770_init_golden_registers(rdev);
19368c2ecf20Sopenharmony_ci	/* Initialize scratch registers */
19378c2ecf20Sopenharmony_ci	r600_scratch_init(rdev);
19388c2ecf20Sopenharmony_ci	/* Initialize surface registers */
19398c2ecf20Sopenharmony_ci	radeon_surface_init(rdev);
19408c2ecf20Sopenharmony_ci	/* Initialize clocks */
19418c2ecf20Sopenharmony_ci	radeon_get_clock_info(rdev->ddev);
19428c2ecf20Sopenharmony_ci	/* Fence driver */
19438c2ecf20Sopenharmony_ci	r = radeon_fence_driver_init(rdev);
19448c2ecf20Sopenharmony_ci	if (r)
19458c2ecf20Sopenharmony_ci		return r;
19468c2ecf20Sopenharmony_ci	/* initialize AGP */
19478c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
19488c2ecf20Sopenharmony_ci		r = radeon_agp_init(rdev);
19498c2ecf20Sopenharmony_ci		if (r)
19508c2ecf20Sopenharmony_ci			radeon_agp_disable(rdev);
19518c2ecf20Sopenharmony_ci	}
19528c2ecf20Sopenharmony_ci	r = rv770_mc_init(rdev);
19538c2ecf20Sopenharmony_ci	if (r)
19548c2ecf20Sopenharmony_ci		return r;
19558c2ecf20Sopenharmony_ci	/* Memory manager */
19568c2ecf20Sopenharmony_ci	r = radeon_bo_init(rdev);
19578c2ecf20Sopenharmony_ci	if (r)
19588c2ecf20Sopenharmony_ci		return r;
19598c2ecf20Sopenharmony_ci
19608c2ecf20Sopenharmony_ci	if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
19618c2ecf20Sopenharmony_ci		r = r600_init_microcode(rdev);
19628c2ecf20Sopenharmony_ci		if (r) {
19638c2ecf20Sopenharmony_ci			DRM_ERROR("Failed to load firmware!\n");
19648c2ecf20Sopenharmony_ci			return r;
19658c2ecf20Sopenharmony_ci		}
19668c2ecf20Sopenharmony_ci	}
19678c2ecf20Sopenharmony_ci
19688c2ecf20Sopenharmony_ci	/* Initialize power management */
19698c2ecf20Sopenharmony_ci	radeon_pm_init(rdev);
19708c2ecf20Sopenharmony_ci
19718c2ecf20Sopenharmony_ci	rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
19728c2ecf20Sopenharmony_ci	r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
19738c2ecf20Sopenharmony_ci
19748c2ecf20Sopenharmony_ci	rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
19758c2ecf20Sopenharmony_ci	r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
19768c2ecf20Sopenharmony_ci
19778c2ecf20Sopenharmony_ci	rv770_uvd_init(rdev);
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_ci	rdev->ih.ring_obj = NULL;
19808c2ecf20Sopenharmony_ci	r600_ih_ring_init(rdev, 64 * 1024);
19818c2ecf20Sopenharmony_ci
19828c2ecf20Sopenharmony_ci	r = r600_pcie_gart_init(rdev);
19838c2ecf20Sopenharmony_ci	if (r)
19848c2ecf20Sopenharmony_ci		return r;
19858c2ecf20Sopenharmony_ci
19868c2ecf20Sopenharmony_ci	rdev->accel_working = true;
19878c2ecf20Sopenharmony_ci	r = rv770_startup(rdev);
19888c2ecf20Sopenharmony_ci	if (r) {
19898c2ecf20Sopenharmony_ci		dev_err(rdev->dev, "disabling GPU acceleration\n");
19908c2ecf20Sopenharmony_ci		r700_cp_fini(rdev);
19918c2ecf20Sopenharmony_ci		r600_dma_fini(rdev);
19928c2ecf20Sopenharmony_ci		r600_irq_fini(rdev);
19938c2ecf20Sopenharmony_ci		radeon_wb_fini(rdev);
19948c2ecf20Sopenharmony_ci		radeon_ib_pool_fini(rdev);
19958c2ecf20Sopenharmony_ci		radeon_irq_kms_fini(rdev);
19968c2ecf20Sopenharmony_ci		rv770_pcie_gart_fini(rdev);
19978c2ecf20Sopenharmony_ci		rdev->accel_working = false;
19988c2ecf20Sopenharmony_ci	}
19998c2ecf20Sopenharmony_ci
20008c2ecf20Sopenharmony_ci	return 0;
20018c2ecf20Sopenharmony_ci}
20028c2ecf20Sopenharmony_ci
20038c2ecf20Sopenharmony_civoid rv770_fini(struct radeon_device *rdev)
20048c2ecf20Sopenharmony_ci{
20058c2ecf20Sopenharmony_ci	radeon_pm_fini(rdev);
20068c2ecf20Sopenharmony_ci	r700_cp_fini(rdev);
20078c2ecf20Sopenharmony_ci	r600_dma_fini(rdev);
20088c2ecf20Sopenharmony_ci	r600_irq_fini(rdev);
20098c2ecf20Sopenharmony_ci	radeon_wb_fini(rdev);
20108c2ecf20Sopenharmony_ci	radeon_ib_pool_fini(rdev);
20118c2ecf20Sopenharmony_ci	radeon_irq_kms_fini(rdev);
20128c2ecf20Sopenharmony_ci	uvd_v1_0_fini(rdev);
20138c2ecf20Sopenharmony_ci	radeon_uvd_fini(rdev);
20148c2ecf20Sopenharmony_ci	rv770_pcie_gart_fini(rdev);
20158c2ecf20Sopenharmony_ci	r600_vram_scratch_fini(rdev);
20168c2ecf20Sopenharmony_ci	radeon_gem_fini(rdev);
20178c2ecf20Sopenharmony_ci	radeon_fence_driver_fini(rdev);
20188c2ecf20Sopenharmony_ci	radeon_agp_fini(rdev);
20198c2ecf20Sopenharmony_ci	radeon_bo_fini(rdev);
20208c2ecf20Sopenharmony_ci	radeon_atombios_fini(rdev);
20218c2ecf20Sopenharmony_ci	kfree(rdev->bios);
20228c2ecf20Sopenharmony_ci	rdev->bios = NULL;
20238c2ecf20Sopenharmony_ci}
20248c2ecf20Sopenharmony_ci
20258c2ecf20Sopenharmony_cistatic void rv770_pcie_gen2_enable(struct radeon_device *rdev)
20268c2ecf20Sopenharmony_ci{
20278c2ecf20Sopenharmony_ci	u32 link_width_cntl, lanes, speed_cntl, tmp;
20288c2ecf20Sopenharmony_ci	u16 link_cntl2;
20298c2ecf20Sopenharmony_ci
20308c2ecf20Sopenharmony_ci	if (radeon_pcie_gen2 == 0)
20318c2ecf20Sopenharmony_ci		return;
20328c2ecf20Sopenharmony_ci
20338c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_IGP)
20348c2ecf20Sopenharmony_ci		return;
20358c2ecf20Sopenharmony_ci
20368c2ecf20Sopenharmony_ci	if (!(rdev->flags & RADEON_IS_PCIE))
20378c2ecf20Sopenharmony_ci		return;
20388c2ecf20Sopenharmony_ci
20398c2ecf20Sopenharmony_ci	/* x2 cards have a special sequence */
20408c2ecf20Sopenharmony_ci	if (ASIC_IS_X2(rdev))
20418c2ecf20Sopenharmony_ci		return;
20428c2ecf20Sopenharmony_ci
20438c2ecf20Sopenharmony_ci	if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
20448c2ecf20Sopenharmony_ci		(rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
20458c2ecf20Sopenharmony_ci		return;
20468c2ecf20Sopenharmony_ci
20478c2ecf20Sopenharmony_ci	DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
20488c2ecf20Sopenharmony_ci
20498c2ecf20Sopenharmony_ci	/* advertise upconfig capability */
20508c2ecf20Sopenharmony_ci	link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
20518c2ecf20Sopenharmony_ci	link_width_cntl &= ~LC_UPCONFIGURE_DIS;
20528c2ecf20Sopenharmony_ci	WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
20538c2ecf20Sopenharmony_ci	link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
20548c2ecf20Sopenharmony_ci	if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
20558c2ecf20Sopenharmony_ci		lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
20568c2ecf20Sopenharmony_ci		link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
20578c2ecf20Sopenharmony_ci				     LC_RECONFIG_ARC_MISSING_ESCAPE);
20588c2ecf20Sopenharmony_ci		link_width_cntl |= lanes | LC_RECONFIG_NOW |
20598c2ecf20Sopenharmony_ci			LC_RENEGOTIATE_EN | LC_UPCONFIGURE_SUPPORT;
20608c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
20618c2ecf20Sopenharmony_ci	} else {
20628c2ecf20Sopenharmony_ci		link_width_cntl |= LC_UPCONFIGURE_DIS;
20638c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
20648c2ecf20Sopenharmony_ci	}
20658c2ecf20Sopenharmony_ci
20668c2ecf20Sopenharmony_ci	speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
20678c2ecf20Sopenharmony_ci	if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
20688c2ecf20Sopenharmony_ci	    (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
20698c2ecf20Sopenharmony_ci
20708c2ecf20Sopenharmony_ci		tmp = RREG32(0x541c);
20718c2ecf20Sopenharmony_ci		WREG32(0x541c, tmp | 0x8);
20728c2ecf20Sopenharmony_ci		WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
20738c2ecf20Sopenharmony_ci		link_cntl2 = RREG16(0x4088);
20748c2ecf20Sopenharmony_ci		link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
20758c2ecf20Sopenharmony_ci		link_cntl2 |= 0x2;
20768c2ecf20Sopenharmony_ci		WREG16(0x4088, link_cntl2);
20778c2ecf20Sopenharmony_ci		WREG32(MM_CFGREGS_CNTL, 0);
20788c2ecf20Sopenharmony_ci
20798c2ecf20Sopenharmony_ci		speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
20808c2ecf20Sopenharmony_ci		speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
20818c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
20828c2ecf20Sopenharmony_ci
20838c2ecf20Sopenharmony_ci		speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
20848c2ecf20Sopenharmony_ci		speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
20858c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
20868c2ecf20Sopenharmony_ci
20878c2ecf20Sopenharmony_ci		speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
20888c2ecf20Sopenharmony_ci		speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
20898c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
20908c2ecf20Sopenharmony_ci
20918c2ecf20Sopenharmony_ci		speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
20928c2ecf20Sopenharmony_ci		speed_cntl |= LC_GEN2_EN_STRAP;
20938c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
20948c2ecf20Sopenharmony_ci
20958c2ecf20Sopenharmony_ci	} else {
20968c2ecf20Sopenharmony_ci		link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
20978c2ecf20Sopenharmony_ci		/* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
20988c2ecf20Sopenharmony_ci		if (1)
20998c2ecf20Sopenharmony_ci			link_width_cntl |= LC_UPCONFIGURE_DIS;
21008c2ecf20Sopenharmony_ci		else
21018c2ecf20Sopenharmony_ci			link_width_cntl &= ~LC_UPCONFIGURE_DIS;
21028c2ecf20Sopenharmony_ci		WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
21038c2ecf20Sopenharmony_ci	}
21048c2ecf20Sopenharmony_ci}
2105