]> Git Repo - linux.git/blobdiff - drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
Merge drm/drm-next into drm-misc-next
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_object.c
index 19c1384a133f259e659546d7f39331c7f405fa67..b7a2070d90af2332e1164e4aca4c84633f20fe8a 100644 (file)
@@ -71,12 +71,12 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
        }
        amdgpu_bo_unref(&bo->parent);
 
-       if (bo->tbo.type == ttm_bo_type_device) {
+       if (bo->tbo.type != ttm_bo_type_kernel) {
                ubo = to_amdgpu_bo_user(bo);
                kfree(ubo->metadata);
        }
 
-       kfree(bo);
+       kvfree(bo);
 }
 
 /**
@@ -133,7 +133,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
        if (domain & AMDGPU_GEM_DOMAIN_GTT) {
                places[c].fpfn = 0;
                places[c].lpfn = 0;
-               places[c].mem_type = TTM_PL_TT;
+               places[c].mem_type =
+                       abo->flags & AMDGPU_GEM_CREATE_PREEMPTIBLE ?
+                       AMDGPU_PL_PREEMPT : TTM_PL_TT;
                places[c].flags = 0;
                c++;
        }
@@ -539,7 +541,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
        BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo));
 
        *bo_ptr = NULL;
-       bo = kzalloc(bp->bo_ptr_size, GFP_KERNEL);
+       bo = kvzalloc(bp->bo_ptr_size, GFP_KERNEL);
        if (bo == NULL)
                return -ENOMEM;
        drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size);
@@ -612,35 +614,6 @@ fail_unreserve:
        return r;
 }
 
-int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-                           unsigned long size,
-                           struct amdgpu_bo *bo)
-{
-       struct amdgpu_bo_param bp;
-       int r;
-
-       if (bo->shadow)
-               return 0;
-
-       memset(&bp, 0, sizeof(bp));
-       bp.size = size;
-       bp.domain = AMDGPU_GEM_DOMAIN_GTT;
-       bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-       bp.type = ttm_bo_type_kernel;
-       bp.resv = bo->tbo.base.resv;
-       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
-
-       r = amdgpu_bo_create(adev, &bp, &bo->shadow);
-       if (!r) {
-               bo->shadow->parent = amdgpu_bo_ref(bo);
-               mutex_lock(&adev->shadow_list_lock);
-               list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
-               mutex_unlock(&adev->shadow_list_lock);
-       }
-
-       return r;
-}
-
 /**
  * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
  * @adev: amdgpu device object
@@ -668,6 +641,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
        *ubo_ptr = to_amdgpu_bo_user(bo_ptr);
        return r;
 }
+
+/**
+ * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @vmbo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be for GPUVM.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_vm(struct amdgpu_device *adev,
+                       struct amdgpu_bo_param *bp,
+                       struct amdgpu_bo_vm **vmbo_ptr)
+{
+       struct amdgpu_bo *bo_ptr;
+       int r;
+
+       /* bo_ptr_size will be determined by the caller and it depends on
+        * num of amdgpu_vm_pt entries.
+        */
+       BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
+       r = amdgpu_bo_create(adev, bp, &bo_ptr);
+       if (r)
+               return r;
+
+       *vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
+       return r;
+}
+
 /**
  * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
  * @bo: pointer to the buffer object
@@ -702,6 +707,22 @@ retry:
        return r;
 }
 
+/**
+ * amdgpu_bo_add_to_shadow_list - add a BO to the shadow list
+ *
+ * @bo: BO that will be inserted into the shadow list
+ *
+ * Insert a BO to the shadow list.
+ */
+void amdgpu_bo_add_to_shadow_list(struct amdgpu_bo *bo)
+{
+       struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+
+       mutex_lock(&adev->shadow_list_lock);
+       list_add_tail(&bo->shadow_list, &adev->shadow_list);
+       mutex_unlock(&adev->shadow_list_lock);
+}
+
 /**
  * amdgpu_bo_restore_shadow - restore an &amdgpu_bo shadow
  *
@@ -756,8 +777,8 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
                return 0;
        }
 
-       r = dma_resv_wait_timeout_rcu(bo->tbo.base.resv, false, false,
-                                               MAX_SCHEDULE_TIMEOUT);
+       r = dma_resv_wait_timeout(bo->tbo.base.resv, false, false,
+                                 MAX_SCHEDULE_TIMEOUT);
        if (r < 0)
                return r;
 
@@ -1191,6 +1212,9 @@ int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
 
        BUG_ON(bo->tbo.type == ttm_bo_type_kernel);
        ubo = to_amdgpu_bo_user(bo);
+       if (metadata_size)
+               *metadata_size = ubo->metadata_size;
+
        if (buffer) {
                if (buffer_size < ubo->metadata_size)
                        return -EINVAL;
@@ -1199,8 +1223,6 @@ int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
                        memcpy(buffer, ubo->metadata, ubo->metadata_size);
        }
 
-       if (metadata_size)
-               *metadata_size = ubo->metadata_size;
        if (flags)
                *flags = ubo->metadata_flags;
 
This page took 0.044888 seconds and 4 git commands to generate.