Commit 72c8c97b authored by Andrey Grodzovsky's avatar Andrey Grodzovsky

drm/amdgpu: Split amdgpu_device_fini into early and late

Some of the stuff in amdgpu_device_fini such as HW interrupts
disable and pending fences finilization must be done right away on
pci_remove while most of the stuff which relates to finilizing and
releasing driver data structures can be kept until
drm_driver.release hook is called, i.e. when the last device
reference is dropped.

v4: Change functions prefix early->hw and late->sw
Signed-off-by: default avatarAndrey Grodzovsky <andrey.grodzovsky@amd.com>
Acked-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210512142648.666476-3-andrey.grodzovsky@amd.com
parent 267d51d7
...@@ -1099,7 +1099,9 @@ static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_device *bdev) ...@@ -1099,7 +1099,9 @@ static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_device *bdev)
int amdgpu_device_init(struct amdgpu_device *adev, int amdgpu_device_init(struct amdgpu_device *adev,
uint32_t flags); uint32_t flags);
void amdgpu_device_fini(struct amdgpu_device *adev); void amdgpu_device_fini_hw(struct amdgpu_device *adev);
void amdgpu_device_fini_sw(struct amdgpu_device *adev);
int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos, void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos,
...@@ -1319,6 +1321,8 @@ void amdgpu_driver_lastclose_kms(struct drm_device *dev); ...@@ -1319,6 +1321,8 @@ void amdgpu_driver_lastclose_kms(struct drm_device *dev);
int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
void amdgpu_driver_postclose_kms(struct drm_device *dev, void amdgpu_driver_postclose_kms(struct drm_device *dev,
struct drm_file *file_priv); struct drm_file *file_priv);
void amdgpu_driver_release_kms(struct drm_device *dev);
int amdgpu_device_ip_suspend(struct amdgpu_device *adev); int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
int amdgpu_device_suspend(struct drm_device *dev, bool fbcon); int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
int amdgpu_device_resume(struct drm_device *dev, bool fbcon); int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
......
...@@ -3646,15 +3646,13 @@ int amdgpu_device_init(struct amdgpu_device *adev, ...@@ -3646,15 +3646,13 @@ int amdgpu_device_init(struct amdgpu_device *adev,
* Tear down the driver info (all asics). * Tear down the driver info (all asics).
* Called at driver shutdown. * Called at driver shutdown.
*/ */
void amdgpu_device_fini(struct amdgpu_device *adev) void amdgpu_device_fini_hw(struct amdgpu_device *adev)
{ {
dev_info(adev->dev, "amdgpu: finishing device.\n"); dev_info(adev->dev, "amdgpu: finishing device.\n");
flush_delayed_work(&adev->delayed_init_work); flush_delayed_work(&adev->delayed_init_work);
ttm_bo_lock_delayed_workqueue(&adev->mman.bdev); ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
adev->shutdown = true; adev->shutdown = true;
kfree(adev->pci_state);
/* make sure IB test finished before entering exclusive mode /* make sure IB test finished before entering exclusive mode
* to avoid preemption on IB test * to avoid preemption on IB test
* */ * */
...@@ -3671,11 +3669,24 @@ void amdgpu_device_fini(struct amdgpu_device *adev) ...@@ -3671,11 +3669,24 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
else else
drm_atomic_helper_shutdown(adev_to_drm(adev)); drm_atomic_helper_shutdown(adev_to_drm(adev));
} }
amdgpu_fence_driver_fini(adev); amdgpu_fence_driver_fini_hw(adev);
if (adev->pm_sysfs_en) if (adev->pm_sysfs_en)
amdgpu_pm_sysfs_fini(adev); amdgpu_pm_sysfs_fini(adev);
if (adev->ucode_sysfs_en)
amdgpu_ucode_sysfs_fini(adev);
sysfs_remove_files(&adev->dev->kobj, amdgpu_dev_attributes);
amdgpu_fbdev_fini(adev); amdgpu_fbdev_fini(adev);
amdgpu_irq_fini_hw(adev);
}
void amdgpu_device_fini_sw(struct amdgpu_device *adev)
{
amdgpu_device_ip_fini(adev); amdgpu_device_ip_fini(adev);
amdgpu_fence_driver_fini_sw(adev);
release_firmware(adev->firmware.gpu_info_fw); release_firmware(adev->firmware.gpu_info_fw);
adev->firmware.gpu_info_fw = NULL; adev->firmware.gpu_info_fw = NULL;
adev->accel_working = false; adev->accel_working = false;
...@@ -3701,14 +3712,13 @@ void amdgpu_device_fini(struct amdgpu_device *adev) ...@@ -3701,14 +3712,13 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
adev->rmmio = NULL; adev->rmmio = NULL;
amdgpu_device_doorbell_fini(adev); amdgpu_device_doorbell_fini(adev);
if (adev->ucode_sysfs_en)
amdgpu_ucode_sysfs_fini(adev);
sysfs_remove_files(&adev->dev->kobj, amdgpu_dev_attributes);
if (IS_ENABLED(CONFIG_PERF_EVENTS)) if (IS_ENABLED(CONFIG_PERF_EVENTS))
amdgpu_pmu_fini(adev); amdgpu_pmu_fini(adev);
if (adev->mman.discovery_bin) if (adev->mman.discovery_bin)
amdgpu_discovery_fini(adev); amdgpu_discovery_fini(adev);
kfree(adev->pci_state);
} }
......
...@@ -1311,14 +1311,10 @@ amdgpu_pci_remove(struct pci_dev *pdev) ...@@ -1311,14 +1311,10 @@ amdgpu_pci_remove(struct pci_dev *pdev)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct drm_device *dev = pci_get_drvdata(pdev);
#ifdef MODULE
if (THIS_MODULE->state != MODULE_STATE_GOING)
#endif
DRM_ERROR("Hotplug removal is not supported\n");
drm_dev_unplug(dev); drm_dev_unplug(dev);
amdgpu_driver_unload_kms(dev); amdgpu_driver_unload_kms(dev);
pci_disable_device(pdev); pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
} }
static void static void
...@@ -1751,6 +1747,7 @@ static const struct drm_driver amdgpu_kms_driver = { ...@@ -1751,6 +1747,7 @@ static const struct drm_driver amdgpu_kms_driver = {
.dumb_create = amdgpu_mode_dumb_create, .dumb_create = amdgpu_mode_dumb_create,
.dumb_map_offset = amdgpu_mode_dumb_mmap, .dumb_map_offset = amdgpu_mode_dumb_mmap,
.fops = &amdgpu_driver_kms_fops, .fops = &amdgpu_driver_kms_fops,
.release = &amdgpu_driver_release_kms,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
......
...@@ -523,7 +523,7 @@ int amdgpu_fence_driver_init(struct amdgpu_device *adev) ...@@ -523,7 +523,7 @@ int amdgpu_fence_driver_init(struct amdgpu_device *adev)
* *
* Tear down the fence driver for all possible rings (all asics). * Tear down the fence driver for all possible rings (all asics).
*/ */
void amdgpu_fence_driver_fini(struct amdgpu_device *adev) void amdgpu_fence_driver_fini_hw(struct amdgpu_device *adev)
{ {
unsigned i, j; unsigned i, j;
int r; int r;
...@@ -545,6 +545,19 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev) ...@@ -545,6 +545,19 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev)
ring->fence_drv.irq_type); ring->fence_drv.irq_type);
del_timer_sync(&ring->fence_drv.fallback_timer); del_timer_sync(&ring->fence_drv.fallback_timer);
}
}
void amdgpu_fence_driver_fini_sw(struct amdgpu_device *adev)
{
unsigned int i, j;
for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
struct amdgpu_ring *ring = adev->rings[i];
if (!ring || !ring->fence_drv.initialized)
continue;
for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j) for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
dma_fence_put(ring->fence_drv.fences[j]); dma_fence_put(ring->fence_drv.fences[j]);
kfree(ring->fence_drv.fences); kfree(ring->fence_drv.fences);
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <drm/drm_irq.h> #include <drm/drm_irq.h>
#include <drm/drm_vblank.h> #include <drm/drm_vblank.h>
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_drv.h>
#include "amdgpu.h" #include "amdgpu.h"
#include "amdgpu_ih.h" #include "amdgpu_ih.h"
#include "atom.h" #include "atom.h"
...@@ -348,6 +349,20 @@ int amdgpu_irq_init(struct amdgpu_device *adev) ...@@ -348,6 +349,20 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
return 0; return 0;
} }
void amdgpu_irq_fini_hw(struct amdgpu_device *adev)
{
if (adev->irq.installed) {
drm_irq_uninstall(&adev->ddev);
adev->irq.installed = false;
if (adev->irq.msi_enabled)
pci_free_irq_vectors(adev->pdev);
if (!amdgpu_device_has_dc_support(adev))
flush_work(&adev->hotplug_work);
}
}
/** /**
* amdgpu_irq_fini - shut down interrupt handling * amdgpu_irq_fini - shut down interrupt handling
* *
...@@ -357,19 +372,10 @@ int amdgpu_irq_init(struct amdgpu_device *adev) ...@@ -357,19 +372,10 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
* functionality, shuts down vblank, hotplug and reset interrupt handling, * functionality, shuts down vblank, hotplug and reset interrupt handling,
* turns off interrupts from all sources (all ASICs). * turns off interrupts from all sources (all ASICs).
*/ */
void amdgpu_irq_fini(struct amdgpu_device *adev) void amdgpu_irq_fini_sw(struct amdgpu_device *adev)
{ {
unsigned i, j; unsigned i, j;
if (adev->irq.installed) {
drm_irq_uninstall(adev_to_drm(adev));
adev->irq.installed = false;
if (adev->irq.msi_enabled)
pci_free_irq_vectors(adev->pdev);
if (!amdgpu_device_has_dc_support(adev))
flush_work(&adev->hotplug_work);
}
for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) { for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
if (!adev->irq.client[i].sources) if (!adev->irq.client[i].sources)
continue; continue;
......
...@@ -103,7 +103,8 @@ void amdgpu_irq_disable_all(struct amdgpu_device *adev); ...@@ -103,7 +103,8 @@ void amdgpu_irq_disable_all(struct amdgpu_device *adev);
irqreturn_t amdgpu_irq_handler(int irq, void *arg); irqreturn_t amdgpu_irq_handler(int irq, void *arg);
int amdgpu_irq_init(struct amdgpu_device *adev); int amdgpu_irq_init(struct amdgpu_device *adev);
void amdgpu_irq_fini(struct amdgpu_device *adev); void amdgpu_irq_fini_sw(struct amdgpu_device *adev);
void amdgpu_irq_fini_hw(struct amdgpu_device *adev);
int amdgpu_irq_add_id(struct amdgpu_device *adev, int amdgpu_irq_add_id(struct amdgpu_device *adev,
unsigned client_id, unsigned src_id, unsigned client_id, unsigned src_id,
struct amdgpu_irq_src *source); struct amdgpu_irq_src *source);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "amdgpu.h" #include "amdgpu.h"
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_drv.h>
#include "amdgpu_uvd.h" #include "amdgpu_uvd.h"
#include "amdgpu_vce.h" #include "amdgpu_vce.h"
#include "atom.h" #include "atom.h"
...@@ -92,7 +93,7 @@ void amdgpu_driver_unload_kms(struct drm_device *dev) ...@@ -92,7 +93,7 @@ void amdgpu_driver_unload_kms(struct drm_device *dev)
} }
amdgpu_acpi_fini(adev); amdgpu_acpi_fini(adev);
amdgpu_device_fini(adev); amdgpu_device_fini_hw(adev);
} }
void amdgpu_register_gpu_instance(struct amdgpu_device *adev) void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
...@@ -1219,6 +1220,15 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, ...@@ -1219,6 +1220,15 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
pm_runtime_put_autosuspend(dev->dev); pm_runtime_put_autosuspend(dev->dev);
} }
void amdgpu_driver_release_kms(struct drm_device *dev)
{
struct amdgpu_device *adev = drm_to_adev(dev);
amdgpu_device_fini_sw(adev);
pci_set_drvdata(adev->pdev, NULL);
}
/* /*
* VBlank related functions. * VBlank related functions.
*/ */
......
...@@ -2331,6 +2331,7 @@ int amdgpu_ras_pre_fini(struct amdgpu_device *adev) ...@@ -2331,6 +2331,7 @@ int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
if (!adev->ras_features || !con) if (!adev->ras_features || !con)
return 0; return 0;
/* Need disable ras on all IPs here before ip [hw/sw]fini */ /* Need disable ras on all IPs here before ip [hw/sw]fini */
amdgpu_ras_disable_all_features(adev, 0); amdgpu_ras_disable_all_features(adev, 0);
amdgpu_ras_recovery_fini(adev); amdgpu_ras_recovery_fini(adev);
......
...@@ -107,7 +107,8 @@ struct amdgpu_fence_driver { ...@@ -107,7 +107,8 @@ struct amdgpu_fence_driver {
}; };
int amdgpu_fence_driver_init(struct amdgpu_device *adev); int amdgpu_fence_driver_init(struct amdgpu_device *adev);
void amdgpu_fence_driver_fini(struct amdgpu_device *adev); void amdgpu_fence_driver_fini_hw(struct amdgpu_device *adev);
void amdgpu_fence_driver_fini_sw(struct amdgpu_device *adev);
void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring); void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
......
...@@ -309,7 +309,7 @@ static int cik_ih_sw_fini(void *handle) ...@@ -309,7 +309,7 @@ static int cik_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih); amdgpu_ih_ring_fini(adev, &adev->irq.ih);
amdgpu_irq_remove_domain(adev); amdgpu_irq_remove_domain(adev);
......
...@@ -301,7 +301,7 @@ static int cz_ih_sw_fini(void *handle) ...@@ -301,7 +301,7 @@ static int cz_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih); amdgpu_ih_ring_fini(adev, &adev->irq.ih);
amdgpu_irq_remove_domain(adev); amdgpu_irq_remove_domain(adev);
......
...@@ -300,7 +300,7 @@ static int iceland_ih_sw_fini(void *handle) ...@@ -300,7 +300,7 @@ static int iceland_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih); amdgpu_ih_ring_fini(adev, &adev->irq.ih);
amdgpu_irq_remove_domain(adev); amdgpu_irq_remove_domain(adev);
......
...@@ -569,7 +569,7 @@ static int navi10_ih_sw_fini(void *handle) ...@@ -569,7 +569,7 @@ static int navi10_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft); amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft);
amdgpu_ih_ring_fini(adev, &adev->irq.ih2); amdgpu_ih_ring_fini(adev, &adev->irq.ih2);
amdgpu_ih_ring_fini(adev, &adev->irq.ih1); amdgpu_ih_ring_fini(adev, &adev->irq.ih1);
......
...@@ -175,7 +175,7 @@ static int si_ih_sw_fini(void *handle) ...@@ -175,7 +175,7 @@ static int si_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih); amdgpu_ih_ring_fini(adev, &adev->irq.ih);
return 0; return 0;
......
...@@ -312,7 +312,7 @@ static int tonga_ih_sw_fini(void *handle) ...@@ -312,7 +312,7 @@ static int tonga_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih); amdgpu_ih_ring_fini(adev, &adev->irq.ih);
amdgpu_irq_remove_domain(adev); amdgpu_irq_remove_domain(adev);
......
...@@ -513,7 +513,7 @@ static int vega10_ih_sw_fini(void *handle) ...@@ -513,7 +513,7 @@ static int vega10_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft); amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft);
amdgpu_ih_ring_fini(adev, &adev->irq.ih2); amdgpu_ih_ring_fini(adev, &adev->irq.ih2);
amdgpu_ih_ring_fini(adev, &adev->irq.ih1); amdgpu_ih_ring_fini(adev, &adev->irq.ih1);
......
...@@ -565,7 +565,7 @@ static int vega20_ih_sw_fini(void *handle) ...@@ -565,7 +565,7 @@ static int vega20_ih_sw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
amdgpu_irq_fini(adev); amdgpu_irq_fini_sw(adev);
amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft); amdgpu_ih_ring_fini(adev, &adev->irq.ih_soft);
amdgpu_ih_ring_fini(adev, &adev->irq.ih2); amdgpu_ih_ring_fini(adev, &adev->irq.ih2);
amdgpu_ih_ring_fini(adev, &adev->irq.ih1); amdgpu_ih_ring_fini(adev, &adev->irq.ih1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment