From cf241e872fc203b59e8ff4b4eae6a6c2511d3747 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Fri, 7 May 2021 20:57:06 +0200 Subject: drm/radeon: Move AGP helpers into radeon driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Radeon calls DRMs core AGP helpers. These helpers are only required by legacy drivers. Reimplement the code in radeon to uncouple radeon from the legacy code. Signed-off-by: Thomas Zimmermann Reviewed-by: Alex Deucher Acked-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20210507185709.22797-2-tzimmermann@suse.de --- drivers/gpu/drm/radeon/radeon.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/gpu/drm/radeon/radeon.h') diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 42281fce552e..4f9e8dc460be 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -1110,6 +1110,14 @@ typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p, /* * AGP */ +#if IS_ENABLED(CONFIG_AGP) +struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev); +#else +static inline struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev) +{ + return NULL; +} +#endif int radeon_agp_init(struct radeon_device *rdev); void radeon_agp_resume(struct radeon_device *rdev); void radeon_agp_suspend(struct radeon_device *rdev); -- cgit v1.2.3 From 43359786a51e7fa7d89a45908de0ecee2d1dafa6 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Fri, 7 May 2021 20:57:07 +0200 Subject: drm/radeon: Move AGP data structures into radeon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the AGP code already duplicated, move over the AGP structures from the legacy code base in to radeon. The AGP data structures that are required by radeon are now declared within the driver. The AGP instance is stored in struct radeon_device.agp. Signed-off-by: Thomas Zimmermann Reviewed-by: Alex Deucher Acked-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20210507185709.22797-3-tzimmermann@suse.de --- drivers/gpu/drm/radeon/radeon.h | 38 ++++++++++++++++++-- drivers/gpu/drm/radeon/radeon_agp.c | 70 ++++++++++++++++++------------------- drivers/gpu/drm/radeon/radeon_drv.c | 13 ------- drivers/gpu/drm/radeon/radeon_kms.c | 18 +++++++--- drivers/gpu/drm/radeon/radeon_ttm.c | 6 ++-- 5 files changed, 86 insertions(+), 59 deletions(-) (limited to 'drivers/gpu/drm/radeon/radeon.h') diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 4f9e8dc460be..80d7637f0c27 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -60,6 +60,7 @@ * are considered as fatal) */ +#include #include #include #include @@ -1110,10 +1111,42 @@ typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p, /* * AGP */ + +struct radeon_agp_mode { + unsigned long mode; /**< AGP mode */ +}; + +struct radeon_agp_info { + int agp_version_major; + int agp_version_minor; + unsigned long mode; + unsigned long aperture_base; /* physical address */ + unsigned long aperture_size; /* bytes */ + unsigned long memory_allowed; /* bytes */ + unsigned long memory_used; + + /* PCI information */ + unsigned short id_vendor; + unsigned short id_device; +}; + +struct radeon_agp_head { + struct agp_kern_info agp_info; + struct list_head memory; + unsigned long mode; + struct agp_bridge_data *bridge; + int enabled; + int acquired; + unsigned long base; + int agp_mtrr; + int cant_use_aperture; + unsigned long page_mask; +}; + #if IS_ENABLED(CONFIG_AGP) -struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev); +struct radeon_agp_head *radeon_agp_head_init(struct drm_device *dev); #else -static inline struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev) +static inline struct radeon_agp_head *radeon_agp_head_init(struct drm_device *dev) { return NULL; } @@ -2310,6 +2343,7 @@ struct radeon_device { #ifdef __alpha__ struct pci_controller *hose; #endif + struct radeon_agp_head *agp; struct rw_semaphore exclusive_lock; /* ASIC */ union radeon_asic_config config; diff --git a/drivers/gpu/drm/radeon/radeon_agp.c b/drivers/gpu/drm/radeon/radeon_agp.c index 398be13c8e2b..d124600b5f58 100644 --- a/drivers/gpu/drm/radeon/radeon_agp.c +++ b/drivers/gpu/drm/radeon/radeon_agp.c @@ -27,7 +27,6 @@ #include -#include #include #include @@ -128,10 +127,10 @@ static struct radeon_agpmode_quirk radeon_agpmode_quirk_list[] = { { 0, 0, 0, 0, 0, 0, 0 }, }; -struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev) +struct radeon_agp_head *radeon_agp_head_init(struct drm_device *dev) { struct pci_dev *pdev = to_pci_dev(dev->dev); - struct drm_agp_head *head = NULL; + struct radeon_agp_head *head = NULL; head = kzalloc(sizeof(*head), GFP_KERNEL); if (!head) @@ -160,49 +159,50 @@ struct drm_agp_head *radeon_agp_head_init(struct drm_device *dev) return head; } -static int radeon_agp_head_acquire(struct drm_device *dev) +static int radeon_agp_head_acquire(struct radeon_device *rdev) { + struct drm_device *dev = rdev->ddev; struct pci_dev *pdev = to_pci_dev(dev->dev); - if (!dev->agp) + if (!rdev->agp) return -ENODEV; - if (dev->agp->acquired) + if (rdev->agp->acquired) return -EBUSY; - dev->agp->bridge = agp_backend_acquire(pdev); - if (!dev->agp->bridge) + rdev->agp->bridge = agp_backend_acquire(pdev); + if (!rdev->agp->bridge) return -ENODEV; - dev->agp->acquired = 1; + rdev->agp->acquired = 1; return 0; } -static int radeon_agp_head_release(struct drm_device *dev) +static int radeon_agp_head_release(struct radeon_device *rdev) { - if (!dev->agp || !dev->agp->acquired) + if (!rdev->agp || !rdev->agp->acquired) return -EINVAL; - agp_backend_release(dev->agp->bridge); - dev->agp->acquired = 0; + agp_backend_release(rdev->agp->bridge); + rdev->agp->acquired = 0; return 0; } -static int radeon_agp_head_enable(struct drm_device *dev, struct drm_agp_mode mode) +static int radeon_agp_head_enable(struct radeon_device *rdev, struct radeon_agp_mode mode) { - if (!dev->agp || !dev->agp->acquired) + if (!rdev->agp || !rdev->agp->acquired) return -EINVAL; - dev->agp->mode = mode.mode; - agp_enable(dev->agp->bridge, mode.mode); - dev->agp->enabled = 1; + rdev->agp->mode = mode.mode; + agp_enable(rdev->agp->bridge, mode.mode); + rdev->agp->enabled = 1; return 0; } -static int radeon_agp_head_info(struct drm_device *dev, struct drm_agp_info *info) +static int radeon_agp_head_info(struct radeon_device *rdev, struct radeon_agp_info *info) { struct agp_kern_info *kern; - if (!dev->agp || !dev->agp->acquired) + if (!rdev->agp || !rdev->agp->acquired) return -EINVAL; - kern = &dev->agp->agp_info; + kern = &rdev->agp->agp_info; info->agp_version_major = kern->version.major; info->agp_version_minor = kern->version.minor; info->mode = kern->mode; @@ -221,32 +221,32 @@ int radeon_agp_init(struct radeon_device *rdev) { #if IS_ENABLED(CONFIG_AGP) struct radeon_agpmode_quirk *p = radeon_agpmode_quirk_list; - struct drm_agp_mode mode; - struct drm_agp_info info; + struct radeon_agp_mode mode; + struct radeon_agp_info info; uint32_t agp_status; int default_mode; bool is_v3; int ret; /* Acquire AGP. */ - ret = radeon_agp_head_acquire(rdev->ddev); + ret = radeon_agp_head_acquire(rdev); if (ret) { DRM_ERROR("Unable to acquire AGP: %d\n", ret); return ret; } - ret = radeon_agp_head_info(rdev->ddev, &info); + ret = radeon_agp_head_info(rdev, &info); if (ret) { - radeon_agp_head_release(rdev->ddev); + radeon_agp_head_release(rdev); DRM_ERROR("Unable to get AGP info: %d\n", ret); return ret; } - if (rdev->ddev->agp->agp_info.aper_size < 32) { - radeon_agp_head_release(rdev->ddev); + if (rdev->agp->agp_info.aper_size < 32) { + radeon_agp_head_release(rdev); dev_warn(rdev->dev, "AGP aperture too small (%zuM) " "need at least 32M, disabling AGP\n", - rdev->ddev->agp->agp_info.aper_size); + rdev->agp->agp_info.aper_size); return -EINVAL; } @@ -327,15 +327,15 @@ int radeon_agp_init(struct radeon_device *rdev) } mode.mode &= ~RADEON_AGP_FW_MODE; /* disable fw */ - ret = radeon_agp_head_enable(rdev->ddev, mode); + ret = radeon_agp_head_enable(rdev, mode); if (ret) { DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode); - radeon_agp_head_release(rdev->ddev); + radeon_agp_head_release(rdev); return ret; } - rdev->mc.agp_base = rdev->ddev->agp->agp_info.aper_base; - rdev->mc.gtt_size = rdev->ddev->agp->agp_info.aper_size << 20; + rdev->mc.agp_base = rdev->agp->agp_info.aper_base; + rdev->mc.gtt_size = rdev->agp->agp_info.aper_size << 20; rdev->mc.gtt_start = rdev->mc.agp_base; rdev->mc.gtt_end = rdev->mc.gtt_start + rdev->mc.gtt_size - 1; dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n", @@ -366,8 +366,8 @@ void radeon_agp_resume(struct radeon_device *rdev) void radeon_agp_fini(struct radeon_device *rdev) { #if IS_ENABLED(CONFIG_AGP) - if (rdev->ddev->agp && rdev->ddev->agp->acquired) { - radeon_agp_head_release(rdev->ddev); + if (rdev->agp && rdev->agp->acquired) { + radeon_agp_head_release(rdev); } #endif } diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c index 7a9cd590d0de..31d3dd0e5258 100644 --- a/drivers/gpu/drm/radeon/radeon_drv.c +++ b/drivers/gpu/drm/radeon/radeon_drv.c @@ -39,7 +39,6 @@ #include #include -#include #include #include #include @@ -345,15 +344,6 @@ static int radeon_pci_probe(struct pci_dev *pdev, pci_set_drvdata(pdev, dev); - if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) - dev->agp = radeon_agp_head_init(dev); - if (dev->agp) { - dev->agp->agp_mtrr = arch_phys_wc_add( - dev->agp->agp_info.aper_base, - dev->agp->agp_info.aper_size * - 1024 * 1024); - } - ret = drm_dev_register(dev, ent->driver_data); if (ret) goto err_agp; @@ -361,9 +351,6 @@ static int radeon_pci_probe(struct pci_dev *pdev, return 0; err_agp: - if (dev->agp) - arch_phys_wc_del(dev->agp->agp_mtrr); - kfree(dev->agp); pci_disable_device(pdev); err_free: drm_dev_put(dev); diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c index 58876bb4ef2a..0473583dcdac 100644 --- a/drivers/gpu/drm/radeon/radeon_kms.c +++ b/drivers/gpu/drm/radeon/radeon_kms.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -80,10 +79,10 @@ void radeon_driver_unload_kms(struct drm_device *dev) radeon_modeset_fini(rdev); radeon_device_fini(rdev); - if (dev->agp) - arch_phys_wc_del(dev->agp->agp_mtrr); - kfree(dev->agp); - dev->agp = NULL; + if (rdev->agp) + arch_phys_wc_del(rdev->agp->agp_mtrr); + kfree(rdev->agp); + rdev->agp = NULL; done_free: kfree(rdev); @@ -119,6 +118,15 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) rdev->hose = pdev->sysdata; #endif + if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) + rdev->agp = radeon_agp_head_init(rdev->ddev); + if (rdev->agp) { + rdev->agp->agp_mtrr = arch_phys_wc_add( + rdev->agp->agp_info.aper_base, + rdev->agp->agp_info.aper_size * + 1024 * 1024); + } + /* update BUS flag */ if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) { flags |= RADEON_IS_AGP; diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 380b3007fd0b..3361d11769a2 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -38,7 +38,6 @@ #include #include -#include #include #include #include @@ -291,7 +290,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resourc /* RADEON_IS_AGP is set only if AGP is active */ mem->bus.offset = (mem->start << PAGE_SHIFT) + rdev->mc.agp_base; - mem->bus.is_iomem = !rdev->ddev->agp->cant_use_aperture; + mem->bus.is_iomem = !rdev->agp->cant_use_aperture; mem->bus.caching = ttm_write_combined; } #endif @@ -513,8 +512,7 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo, struct radeon_device *rdev = radeon_get_rdev(bo->bdev); if (rdev->flags & RADEON_IS_AGP) { - return ttm_agp_tt_create(bo, rdev->ddev->agp->bridge, - page_flags); + return ttm_agp_tt_create(bo, rdev->agp->bridge, page_flags); } #endif rbo = container_of(bo, struct radeon_bo, tbo); -- cgit v1.2.3