18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2008 Red Hat Inc.
38c2ecf20Sopenharmony_ci * Copyright 2009 Jerome Glisse.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
68c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
78c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
88c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
98c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
108c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
138c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
198c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
208c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
218c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Authors:
248c2ecf20Sopenharmony_ci *    Dave Airlie
258c2ecf20Sopenharmony_ci *    Jerome Glisse <glisse@freedesktop.org>
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include <linux/pci.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#include <drm/drm_agpsupport.h>
318c2ecf20Sopenharmony_ci#include <drm/drm_device.h>
328c2ecf20Sopenharmony_ci#include <drm/radeon_drm.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include "radeon.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_AGP)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct radeon_agpmode_quirk {
398c2ecf20Sopenharmony_ci	u32 hostbridge_vendor;
408c2ecf20Sopenharmony_ci	u32 hostbridge_device;
418c2ecf20Sopenharmony_ci	u32 chip_vendor;
428c2ecf20Sopenharmony_ci	u32 chip_device;
438c2ecf20Sopenharmony_ci	u32 subsys_vendor;
448c2ecf20Sopenharmony_ci	u32 subsys_device;
458c2ecf20Sopenharmony_ci	u32 default_mode;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic struct radeon_agpmode_quirk radeon_agpmode_quirk_list[] = {
498c2ecf20Sopenharmony_ci	/* Intel E7505 Memory Controller Hub / RV350 AR [Radeon 9600XT] Needs AGPMode 4 (deb #515326) */
508c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x2550, PCI_VENDOR_ID_ATI, 0x4152, 0x1458, 0x4038, 4},
518c2ecf20Sopenharmony_ci	/* Intel 82865G/PE/P DRAM Controller/Host-Hub / Mobility 9800 Needs AGPMode 4 (deb #462590) */
528c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x2570, PCI_VENDOR_ID_ATI, 0x4a4e, PCI_VENDOR_ID_DELL, 0x5106, 4},
538c2ecf20Sopenharmony_ci	/* Intel 82865G/PE/P DRAM Controller/Host-Hub / RV280 [Radeon 9200 SE] Needs AGPMode 4 (lp #300304) */
548c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x2570, PCI_VENDOR_ID_ATI, 0x5964,
558c2ecf20Sopenharmony_ci		0x148c, 0x2073, 4},
568c2ecf20Sopenharmony_ci	/* Intel 82855PM Processor to I/O Controller / Mobility M6 LY Needs AGPMode 1 (deb #467235) */
578c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c59,
588c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x052f, 1},
598c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #195051) */
608c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4e50,
618c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x0550, 1},
628c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / RV250/M9 GL [Mobility FireGL 9000/Radeon 9000] needs AGPMode 1 (Thinkpad T40p) */
638c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c66,
648c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x054d, 1},
658c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / Mobility M7 needs AGPMode 1 */
668c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c57,
678c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x0530, 1},
688c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / FireGL Mobility T2 RV350 Needs AGPMode 2 (fdo #20647) */
698c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4e54,
708c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x054f, 2},
718c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / Mobility M9+ / VaioPCG-V505DX Needs AGPMode 2 (fdo #17928) */
728c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x5c61,
738c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_SONY, 0x816b, 2},
748c2ecf20Sopenharmony_ci	/* Intel 82855PM Processor to I/O Controller / Mobility M9+ Needs AGPMode 8 (phoronix forum) */
758c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x5c61,
768c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_SONY, 0x8195, 8},
778c2ecf20Sopenharmony_ci	/* Intel 82830 830 Chipset Host Bridge / Mobility M6 LY Needs AGPMode 2 (fdo #17360)*/
788c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3575, PCI_VENDOR_ID_ATI, 0x4c59,
798c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_DELL, 0x00e3, 2},
808c2ecf20Sopenharmony_ci	/* Intel 82852/82855 host bridge / Mobility FireGL 9000 RV250 Needs AGPMode 1 (lp #296617) */
818c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4c66,
828c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_DELL, 0x0149, 1},
838c2ecf20Sopenharmony_ci	/* Intel 82855PM host bridge / Mobility FireGL 9000 RV250 Needs AGPMode 1 for suspend/resume */
848c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c66,
858c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_IBM, 0x0531, 1},
868c2ecf20Sopenharmony_ci	/* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (deb #467460) */
878c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
888c2ecf20Sopenharmony_ci		0x1025, 0x0061, 1},
898c2ecf20Sopenharmony_ci	/* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #203007) */
908c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
918c2ecf20Sopenharmony_ci		0x1025, 0x0064, 1},
928c2ecf20Sopenharmony_ci	/* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #141551) */
938c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
948c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_ASUSTEK, 0x1942, 1},
958c2ecf20Sopenharmony_ci	/* Intel 82852/82855 host bridge / Mobility 9600/9700 Needs AGPMode 1 (deb #510208) */
968c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
978c2ecf20Sopenharmony_ci		0x10cf, 0x127f, 1},
988c2ecf20Sopenharmony_ci	/* ASRock K7VT4A+ AGP 8x / ATI Radeon 9250 AGP Needs AGPMode 4 (lp #133192) */
998c2ecf20Sopenharmony_ci	{ 0x1849, 0x3189, PCI_VENDOR_ID_ATI, 0x5960,
1008c2ecf20Sopenharmony_ci		0x1787, 0x5960, 4},
1018c2ecf20Sopenharmony_ci	/* VIA K8M800 Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 4 (fdo #12544) */
1028c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x0204, PCI_VENDOR_ID_ATI, 0x5960,
1038c2ecf20Sopenharmony_ci		0x17af, 0x2020, 4},
1048c2ecf20Sopenharmony_ci	/* VIA KT880 Host Bridge / RV350 [Radeon 9550] Needs AGPMode 4 (fdo #19981) */
1058c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x0269, PCI_VENDOR_ID_ATI, 0x4153,
1068c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_ASUSTEK, 0x003c, 4},
1078c2ecf20Sopenharmony_ci	/* VIA VT8363 Host Bridge / R200 QL [Radeon 8500] Needs AGPMode 2 (lp #141551) */
1088c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x0305, PCI_VENDOR_ID_ATI, 0x514c,
1098c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_ATI, 0x013a, 2},
1108c2ecf20Sopenharmony_ci	/* VIA VT82C693A Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 2 (deb #515512) */
1118c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_ATI, 0x5960,
1128c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_ASUSTEK, 0x004c, 2},
1138c2ecf20Sopenharmony_ci	/* VIA VT82C693A Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 2 */
1148c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_ATI, 0x5960,
1158c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_ASUSTEK, 0x0054, 2},
1168c2ecf20Sopenharmony_ci	/* VIA VT8377 Host Bridge / R200 QM [Radeon 9100] Needs AGPMode 4 (deb #461144) */
1178c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x514d,
1188c2ecf20Sopenharmony_ci		0x174b, 0x7149, 4},
1198c2ecf20Sopenharmony_ci	/* VIA VT8377 Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 4 (lp #312693) */
1208c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x5960,
1218c2ecf20Sopenharmony_ci		0x1462, 0x0380, 4},
1228c2ecf20Sopenharmony_ci	/* VIA VT8377 Host Bridge / RV280 Needs AGPMode 4 (ati ML) */
1238c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x5964,
1248c2ecf20Sopenharmony_ci		0x148c, 0x2073, 4},
1258c2ecf20Sopenharmony_ci	/* ATI Host Bridge / RV280 [M9+] Needs AGPMode 1 (phoronix forum) */
1268c2ecf20Sopenharmony_ci	{ PCI_VENDOR_ID_ATI, 0xcbb2, PCI_VENDOR_ID_ATI, 0x5c61,
1278c2ecf20Sopenharmony_ci		PCI_VENDOR_ID_SONY, 0x8175, 1},
1288c2ecf20Sopenharmony_ci	{ 0, 0, 0, 0, 0, 0, 0 },
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci#endif
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ciint radeon_agp_init(struct radeon_device *rdev)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_AGP)
1358c2ecf20Sopenharmony_ci	struct radeon_agpmode_quirk *p = radeon_agpmode_quirk_list;
1368c2ecf20Sopenharmony_ci	struct drm_agp_mode mode;
1378c2ecf20Sopenharmony_ci	struct drm_agp_info info;
1388c2ecf20Sopenharmony_ci	uint32_t agp_status;
1398c2ecf20Sopenharmony_ci	int default_mode;
1408c2ecf20Sopenharmony_ci	bool is_v3;
1418c2ecf20Sopenharmony_ci	int ret;
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	/* Acquire AGP. */
1448c2ecf20Sopenharmony_ci	ret = drm_agp_acquire(rdev->ddev);
1458c2ecf20Sopenharmony_ci	if (ret) {
1468c2ecf20Sopenharmony_ci		DRM_ERROR("Unable to acquire AGP: %d\n", ret);
1478c2ecf20Sopenharmony_ci		return ret;
1488c2ecf20Sopenharmony_ci	}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	ret = drm_agp_info(rdev->ddev, &info);
1518c2ecf20Sopenharmony_ci	if (ret) {
1528c2ecf20Sopenharmony_ci		drm_agp_release(rdev->ddev);
1538c2ecf20Sopenharmony_ci		DRM_ERROR("Unable to get AGP info: %d\n", ret);
1548c2ecf20Sopenharmony_ci		return ret;
1558c2ecf20Sopenharmony_ci	}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	if (rdev->ddev->agp->agp_info.aper_size < 32) {
1588c2ecf20Sopenharmony_ci		drm_agp_release(rdev->ddev);
1598c2ecf20Sopenharmony_ci		dev_warn(rdev->dev, "AGP aperture too small (%zuM) "
1608c2ecf20Sopenharmony_ci			"need at least 32M, disabling AGP\n",
1618c2ecf20Sopenharmony_ci			rdev->ddev->agp->agp_info.aper_size);
1628c2ecf20Sopenharmony_ci		return -EINVAL;
1638c2ecf20Sopenharmony_ci	}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	mode.mode = info.mode;
1668c2ecf20Sopenharmony_ci	/* chips with the agp to pcie bridge don't have the AGP_STATUS register
1678c2ecf20Sopenharmony_ci	 * Just use the whatever mode the host sets up.
1688c2ecf20Sopenharmony_ci	 */
1698c2ecf20Sopenharmony_ci	if (rdev->family <= CHIP_RV350)
1708c2ecf20Sopenharmony_ci		agp_status = (RREG32(RADEON_AGP_STATUS) | RADEON_AGPv3_MODE) & mode.mode;
1718c2ecf20Sopenharmony_ci	else
1728c2ecf20Sopenharmony_ci		agp_status = mode.mode;
1738c2ecf20Sopenharmony_ci	is_v3 = !!(agp_status & RADEON_AGPv3_MODE);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (is_v3) {
1768c2ecf20Sopenharmony_ci		default_mode = (agp_status & RADEON_AGPv3_8X_MODE) ? 8 : 4;
1778c2ecf20Sopenharmony_ci	} else {
1788c2ecf20Sopenharmony_ci		if (agp_status & RADEON_AGP_4X_MODE) {
1798c2ecf20Sopenharmony_ci			default_mode = 4;
1808c2ecf20Sopenharmony_ci		} else if (agp_status & RADEON_AGP_2X_MODE) {
1818c2ecf20Sopenharmony_ci			default_mode = 2;
1828c2ecf20Sopenharmony_ci		} else {
1838c2ecf20Sopenharmony_ci			default_mode = 1;
1848c2ecf20Sopenharmony_ci		}
1858c2ecf20Sopenharmony_ci	}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	/* Apply AGPMode Quirks */
1888c2ecf20Sopenharmony_ci	while (p && p->chip_device != 0) {
1898c2ecf20Sopenharmony_ci		if (info.id_vendor == p->hostbridge_vendor &&
1908c2ecf20Sopenharmony_ci		    info.id_device == p->hostbridge_device &&
1918c2ecf20Sopenharmony_ci		    rdev->pdev->vendor == p->chip_vendor &&
1928c2ecf20Sopenharmony_ci		    rdev->pdev->device == p->chip_device &&
1938c2ecf20Sopenharmony_ci		    rdev->pdev->subsystem_vendor == p->subsys_vendor &&
1948c2ecf20Sopenharmony_ci		    rdev->pdev->subsystem_device == p->subsys_device) {
1958c2ecf20Sopenharmony_ci			default_mode = p->default_mode;
1968c2ecf20Sopenharmony_ci		}
1978c2ecf20Sopenharmony_ci		++p;
1988c2ecf20Sopenharmony_ci	}
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (radeon_agpmode > 0) {
2018c2ecf20Sopenharmony_ci		if ((radeon_agpmode < (is_v3 ? 4 : 1)) ||
2028c2ecf20Sopenharmony_ci		    (radeon_agpmode > (is_v3 ? 8 : 4)) ||
2038c2ecf20Sopenharmony_ci		    (radeon_agpmode & (radeon_agpmode - 1))) {
2048c2ecf20Sopenharmony_ci			DRM_ERROR("Illegal AGP Mode: %d (valid %s), leaving at %d\n",
2058c2ecf20Sopenharmony_ci				  radeon_agpmode, is_v3 ? "4, 8" : "1, 2, 4",
2068c2ecf20Sopenharmony_ci				  default_mode);
2078c2ecf20Sopenharmony_ci			radeon_agpmode = default_mode;
2088c2ecf20Sopenharmony_ci		} else {
2098c2ecf20Sopenharmony_ci			DRM_INFO("AGP mode requested: %d\n", radeon_agpmode);
2108c2ecf20Sopenharmony_ci		}
2118c2ecf20Sopenharmony_ci	} else {
2128c2ecf20Sopenharmony_ci		radeon_agpmode = default_mode;
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	mode.mode &= ~RADEON_AGP_MODE_MASK;
2168c2ecf20Sopenharmony_ci	if (is_v3) {
2178c2ecf20Sopenharmony_ci		switch (radeon_agpmode) {
2188c2ecf20Sopenharmony_ci		case 8:
2198c2ecf20Sopenharmony_ci			mode.mode |= RADEON_AGPv3_8X_MODE;
2208c2ecf20Sopenharmony_ci			break;
2218c2ecf20Sopenharmony_ci		case 4:
2228c2ecf20Sopenharmony_ci		default:
2238c2ecf20Sopenharmony_ci			mode.mode |= RADEON_AGPv3_4X_MODE;
2248c2ecf20Sopenharmony_ci			break;
2258c2ecf20Sopenharmony_ci		}
2268c2ecf20Sopenharmony_ci	} else {
2278c2ecf20Sopenharmony_ci		switch (radeon_agpmode) {
2288c2ecf20Sopenharmony_ci		case 4:
2298c2ecf20Sopenharmony_ci			mode.mode |= RADEON_AGP_4X_MODE;
2308c2ecf20Sopenharmony_ci			break;
2318c2ecf20Sopenharmony_ci		case 2:
2328c2ecf20Sopenharmony_ci			mode.mode |= RADEON_AGP_2X_MODE;
2338c2ecf20Sopenharmony_ci			break;
2348c2ecf20Sopenharmony_ci		case 1:
2358c2ecf20Sopenharmony_ci		default:
2368c2ecf20Sopenharmony_ci			mode.mode |= RADEON_AGP_1X_MODE;
2378c2ecf20Sopenharmony_ci			break;
2388c2ecf20Sopenharmony_ci		}
2398c2ecf20Sopenharmony_ci	}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	mode.mode &= ~RADEON_AGP_FW_MODE; /* disable fw */
2428c2ecf20Sopenharmony_ci	ret = drm_agp_enable(rdev->ddev, mode);
2438c2ecf20Sopenharmony_ci	if (ret) {
2448c2ecf20Sopenharmony_ci		DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode);
2458c2ecf20Sopenharmony_ci		drm_agp_release(rdev->ddev);
2468c2ecf20Sopenharmony_ci		return ret;
2478c2ecf20Sopenharmony_ci	}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	rdev->mc.agp_base = rdev->ddev->agp->agp_info.aper_base;
2508c2ecf20Sopenharmony_ci	rdev->mc.gtt_size = rdev->ddev->agp->agp_info.aper_size << 20;
2518c2ecf20Sopenharmony_ci	rdev->mc.gtt_start = rdev->mc.agp_base;
2528c2ecf20Sopenharmony_ci	rdev->mc.gtt_end = rdev->mc.gtt_start + rdev->mc.gtt_size - 1;
2538c2ecf20Sopenharmony_ci	dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n",
2548c2ecf20Sopenharmony_ci		rdev->mc.gtt_size >> 20, rdev->mc.gtt_start, rdev->mc.gtt_end);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	/* workaround some hw issues */
2578c2ecf20Sopenharmony_ci	if (rdev->family < CHIP_R200) {
2588c2ecf20Sopenharmony_ci		WREG32(RADEON_AGP_CNTL, RREG32(RADEON_AGP_CNTL) | 0x000e0000);
2598c2ecf20Sopenharmony_ci	}
2608c2ecf20Sopenharmony_ci	return 0;
2618c2ecf20Sopenharmony_ci#else
2628c2ecf20Sopenharmony_ci	return 0;
2638c2ecf20Sopenharmony_ci#endif
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_civoid radeon_agp_resume(struct radeon_device *rdev)
2678c2ecf20Sopenharmony_ci{
2688c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_AGP)
2698c2ecf20Sopenharmony_ci	int r;
2708c2ecf20Sopenharmony_ci	if (rdev->flags & RADEON_IS_AGP) {
2718c2ecf20Sopenharmony_ci		r = radeon_agp_init(rdev);
2728c2ecf20Sopenharmony_ci		if (r)
2738c2ecf20Sopenharmony_ci			dev_warn(rdev->dev, "radeon AGP reinit failed\n");
2748c2ecf20Sopenharmony_ci	}
2758c2ecf20Sopenharmony_ci#endif
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_civoid radeon_agp_fini(struct radeon_device *rdev)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_AGP)
2818c2ecf20Sopenharmony_ci	if (rdev->ddev->agp && rdev->ddev->agp->acquired) {
2828c2ecf20Sopenharmony_ci		drm_agp_release(rdev->ddev);
2838c2ecf20Sopenharmony_ci	}
2848c2ecf20Sopenharmony_ci#endif
2858c2ecf20Sopenharmony_ci}
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_civoid radeon_agp_suspend(struct radeon_device *rdev)
2888c2ecf20Sopenharmony_ci{
2898c2ecf20Sopenharmony_ci	radeon_agp_fini(rdev);
2908c2ecf20Sopenharmony_ci}
291