drm/amdgpu: Fix a redundant kfree
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_drv.c
index 126e747..9799501 100644 (file)
@@ -26,6 +26,7 @@
 #include <drm/drm_drv.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_vblank.h>
+#include <drm/drm_managed.h>
 #include "amdgpu_drv.h"
 
 #include <drm/drm_pciids.h>
  * - 3.36.0 - Allow reading more status registers on si/cik
  * - 3.37.0 - L2 is invalidated before SDMA IBs, needed for correctness
  * - 3.38.0 - Add AMDGPU_IB_FLAG_EMIT_MEM_SYNC
+ * - 3.39.0 - DMABUF implicit sync does a full pipeline sync
+ * - 3.40.0 - Add AMDGPU_IDS_FLAGS_TMZ
  */
 #define KMS_DRIVER_MAJOR       3
-#define KMS_DRIVER_MINOR       38
+#define KMS_DRIVER_MINOR       40
 #define KMS_DRIVER_PATCHLEVEL  0
 
 int amdgpu_vram_limit = 0;
@@ -148,12 +151,15 @@ int amdgpu_mes = 0;
 int amdgpu_noretry;
 int amdgpu_force_asic_type = -1;
 int amdgpu_tmz = 0;
+int amdgpu_reset_method = -1; /* auto */
+int amdgpu_num_kcq = -1;
 
 struct amdgpu_mgpu_info mgpu_info = {
        .mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
 };
 int amdgpu_ras_enable = -1;
 uint amdgpu_ras_mask = 0xffffffff;
+int amdgpu_bad_page_threshold = -1;
 
 /**
  * DOC: vramlimit (int)
@@ -674,11 +680,14 @@ MODULE_PARM_DESC(debug_largebar,
  * Ignore CRAT table during KFD initialization. By default, KFD uses the ACPI CRAT
  * table to get information about AMD APUs. This option can serve as a workaround on
  * systems with a broken CRAT table.
+ *
+ * Default is auto (according to asic type, iommu_v2, and crat table, to decide
+ * whehter use CRAT)
  */
 int ignore_crat;
 module_param(ignore_crat, int, 0444);
 MODULE_PARM_DESC(ignore_crat,
-       "Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");
+       "Ignore CRAT table during KFD initialization (0 = auto (default), 1 = ignore CRAT)");
 
 /**
  * DOC: halt_if_hws_hang (int)
@@ -705,6 +714,23 @@ MODULE_PARM_DESC(hws_gws_support, "Assume MEC2 FW supports GWS barriers (false =
 int queue_preemption_timeout_ms = 9000;
 module_param(queue_preemption_timeout_ms, int, 0644);
 MODULE_PARM_DESC(queue_preemption_timeout_ms, "queue preemption timeout in ms (1 = Minimum, 9000 = default)");
+
+/**
+ * DOC: debug_evictions(bool)
+ * Enable extra debug messages to help determine the cause of evictions
+ */
+bool debug_evictions;
+module_param(debug_evictions, bool, 0644);
+MODULE_PARM_DESC(debug_evictions, "enable eviction debug messages (false = default)");
+
+/**
+ * DOC: no_system_mem_limit(bool)
+ * Disable system memory limit, to support multiple process shared memory
+ */
+bool no_system_mem_limit;
+module_param(no_system_mem_limit, bool, 0644);
+MODULE_PARM_DESC(no_system_mem_limit, "disable system memory limit (false = default)");
+
 #endif
 
 /**
@@ -748,6 +774,26 @@ module_param_named(abmlevel, amdgpu_dm_abm_level, uint, 0444);
 MODULE_PARM_DESC(tmz, "Enable TMZ feature (-1 = auto, 0 = off (default), 1 = on)");
 module_param_named(tmz, amdgpu_tmz, int, 0444);
 
+/**
+ * DOC: reset_method (int)
+ * GPU reset method (-1 = auto (default), 0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)
+ */
+MODULE_PARM_DESC(reset_method, "GPU reset method (-1 = auto (default), 0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)");
+module_param_named(reset_method, amdgpu_reset_method, int, 0444);
+
+/**
+ * DOC: bad_page_threshold (int)
+ * Bad page threshold is to specify the threshold value of faulty pages
+ * detected by RAS ECC, that may result in GPU entering bad status if total
+ * faulty pages by ECC exceed threshold value and leave it for user's further
+ * check.
+ */
+MODULE_PARM_DESC(bad_page_threshold, "Bad page threshold(-1 = auto(default value), 0 = disable bad page retirement)");
+module_param_named(bad_page_threshold, amdgpu_bad_page_threshold, int, 0444);
+
+MODULE_PARM_DESC(num_kcq, "number of kernel compute queue user want to setup (8 if set to greater than 8 or less than 0, only affect gfx 8+)");
+module_param_named(num_kcq, amdgpu_num_kcq, int, 0444);
+
 static const struct pci_device_id pciidlist[] = {
 #ifdef  CONFIG_DRM_AMDGPU_SI
        {0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
@@ -1040,7 +1086,7 @@ static struct drm_driver kms_driver;
 static int amdgpu_pci_probe(struct pci_dev *pdev,
                            const struct pci_device_id *ent)
 {
-       struct drm_device *dev;
+       struct drm_device *ddev;
        struct amdgpu_device *adev;
        unsigned long flags = ent->driver_data;
        int ret, retry = 0;
@@ -1096,34 +1142,44 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
        if (ret)
                return ret;
 
-       dev = drm_dev_alloc(&kms_driver, &pdev->dev);
-       if (IS_ERR(dev))
-               return PTR_ERR(dev);
+       adev = kzalloc(sizeof(*adev), GFP_KERNEL);
+       if (!adev)
+               return -ENOMEM;
+
+       adev->dev  = &pdev->dev;
+       adev->pdev = pdev;
+       ddev = adev_to_drm(adev);
+       ret = drm_dev_init(ddev, &kms_driver, &pdev->dev);
+       if (ret)
+               goto err_free;
+
+       drmm_add_final_kfree(ddev, adev);
 
        if (!supports_atomic)
-               dev->driver_features &= ~DRIVER_ATOMIC;
+               ddev->driver_features &= ~DRIVER_ATOMIC;
 
        ret = pci_enable_device(pdev);
        if (ret)
                goto err_free;
 
-       dev->pdev = pdev;
-
-       pci_set_drvdata(pdev, dev);
+       ddev->pdev = pdev;
+       pci_set_drvdata(pdev, ddev);
 
-       amdgpu_driver_load_kms(dev, ent->driver_data);
+       ret = amdgpu_driver_load_kms(adev, ent->driver_data);
+       if (ret)
+               goto err_pci;
 
 retry_init:
-       ret = drm_dev_register(dev, ent->driver_data);
+       ret = drm_dev_register(ddev, ent->driver_data);
        if (ret == -EAGAIN && ++retry <= 3) {
                DRM_INFO("retry init %d\n", retry);
                /* Don't request EX mode too frequently which is attacking */
                msleep(5000);
                goto retry_init;
-       } else if (ret)
+       } else if (ret) {
                goto err_pci;
+       }
 
-       adev = dev->dev_private;
        ret = amdgpu_debugfs_init(adev);
        if (ret)
                DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
@@ -1133,7 +1189,7 @@ retry_init:
 err_pci:
        pci_disable_device(pdev);
 err_free:
-       drm_dev_put(dev);
+       drm_dev_put(ddev);
        return ret;
 }
 
@@ -1157,7 +1213,7 @@ static void
 amdgpu_pci_shutdown(struct pci_dev *pdev)
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
-       struct amdgpu_device *adev = dev->dev_private;
+       struct amdgpu_device *adev = drm_to_adev(dev);
 
        if (amdgpu_ras_intr_triggered())
                return;
@@ -1167,7 +1223,8 @@ amdgpu_pci_shutdown(struct pci_dev *pdev)
         * unfortunately we can't detect certain
         * hypervisors so just do this all the time.
         */
-       adev->mp1_state = PP_MP1_STATE_UNLOAD;
+       if (!amdgpu_passthrough(adev))
+               adev->mp1_state = PP_MP1_STATE_UNLOAD;
        amdgpu_device_ip_suspend(adev);
        adev->mp1_state = PP_MP1_STATE_NONE;
 }
@@ -1189,7 +1246,7 @@ static int amdgpu_pmops_resume(struct device *dev)
 static int amdgpu_pmops_freeze(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_dev->dev_private;
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
        int r;
 
        adev->in_hibernate = true;
@@ -1225,7 +1282,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct drm_device *drm_dev = pci_get_drvdata(pdev);
-       struct amdgpu_device *adev = drm_dev->dev_private;
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
        int ret, i;
 
        if (!adev->runpm) {
@@ -1276,7 +1333,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct drm_device *drm_dev = pci_get_drvdata(pdev);
-       struct amdgpu_device *adev = drm_dev->dev_private;
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
        int ret;
 
        if (!adev->runpm)
@@ -1312,7 +1369,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
 static int amdgpu_pmops_runtime_idle(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_dev->dev_private;
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
        /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
        int ret = 1;
 
@@ -1373,11 +1430,12 @@ long amdgpu_drm_ioctl(struct file *filp,
        dev = file_priv->minor->dev;
        ret = pm_runtime_get_sync(dev->dev);
        if (ret < 0)
-               return ret;
+               goto out;
 
        ret = drm_ioctl(filp, cmd, arg);
 
        pm_runtime_mark_last_busy(dev->dev);
+out:
        pm_runtime_put_autosuspend(dev->dev);
        return ret;
 }
@@ -1479,8 +1537,6 @@ static struct pci_driver amdgpu_kms_pci_driver = {
        .driver.pm = &amdgpu_pm_ops,
 };
 
-
-
 static int __init amdgpu_init(void)
 {
        int r;