]> Git Repo - linux.git/blobdiff - drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
Merge tag 'linux-watchdog-6.14-rc1' of git://www.linux-watchdog.org/linux-watchdog
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_object.c
index 4e6d218839f9ffff273711b25b1f0748bbb93bb5..96f4b8904e9a6a651cab30e6ac60e086ea2442ac 100644 (file)
@@ -373,14 +373,14 @@ EXPORT_SYMBOL(amdgpu_bo_create_kernel);
  * 0 on success, negative error code otherwise.
  */
 int amdgpu_bo_create_isp_user(struct amdgpu_device *adev,
-                          struct dma_buf *dbuf, u32 domain, struct amdgpu_bo **bo,
+                          struct dma_buf *dma_buf, u32 domain, struct amdgpu_bo **bo,
                           u64 *gpu_addr)
 
 {
        struct drm_gem_object *gem_obj;
        int r;
 
-       gem_obj = amdgpu_gem_prime_import(&adev->ddev, dbuf);
+       gem_obj = amdgpu_gem_prime_import(&adev->ddev, dma_buf);
        *bo = gem_to_amdgpu_bo(gem_obj);
        if (!(*bo)) {
                dev_err(adev->dev, "failed to get valid isp user bo\n");
@@ -1251,7 +1251,6 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
                           bool evict,
                           struct ttm_resource *new_mem)
 {
-       struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
        struct ttm_resource *old_mem = bo->resource;
        struct amdgpu_bo *abo;
 
@@ -1259,7 +1258,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
                return;
 
        abo = ttm_to_amdgpu_bo(bo);
-       amdgpu_vm_bo_invalidate(adev, abo, evict);
+       amdgpu_vm_bo_move(abo, new_mem, evict);
 
        amdgpu_bo_kunmap(abo);
 
@@ -1272,75 +1271,6 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
                             old_mem ? old_mem->mem_type : -1);
 }
 
-void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
-                         struct amdgpu_mem_stats *stats,
-                         unsigned int sz)
-{
-       const unsigned int domain_to_pl[] = {
-               [ilog2(AMDGPU_GEM_DOMAIN_CPU)]      = TTM_PL_SYSTEM,
-               [ilog2(AMDGPU_GEM_DOMAIN_GTT)]      = TTM_PL_TT,
-               [ilog2(AMDGPU_GEM_DOMAIN_VRAM)]     = TTM_PL_VRAM,
-               [ilog2(AMDGPU_GEM_DOMAIN_GDS)]      = AMDGPU_PL_GDS,
-               [ilog2(AMDGPU_GEM_DOMAIN_GWS)]      = AMDGPU_PL_GWS,
-               [ilog2(AMDGPU_GEM_DOMAIN_OA)]       = AMDGPU_PL_OA,
-               [ilog2(AMDGPU_GEM_DOMAIN_DOORBELL)] = AMDGPU_PL_DOORBELL,
-       };
-       struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-       struct ttm_resource *res = bo->tbo.resource;
-       struct drm_gem_object *obj = &bo->tbo.base;
-       uint64_t size = amdgpu_bo_size(bo);
-       unsigned int type;
-
-       if (!res) {
-               /*
-                * If no backing store use one of the preferred domain for basic
-                * stats. We take the MSB since that should give a reasonable
-                * view.
-                */
-               BUILD_BUG_ON(TTM_PL_VRAM < TTM_PL_TT ||
-                            TTM_PL_VRAM < TTM_PL_SYSTEM);
-               type = fls(bo->preferred_domains & AMDGPU_GEM_DOMAIN_MASK);
-               if (!type)
-                       return;
-               type--;
-               if (drm_WARN_ON_ONCE(&adev->ddev,
-                                    type >= ARRAY_SIZE(domain_to_pl)))
-                       return;
-               type = domain_to_pl[type];
-       } else {
-               type = res->mem_type;
-       }
-
-       if (drm_WARN_ON_ONCE(&adev->ddev, type >= sz))
-               return;
-
-       /* DRM stats common fields: */
-
-       if (drm_gem_object_is_shared_for_memory_stats(obj))
-               stats[type].drm.shared += size;
-       else
-               stats[type].drm.private += size;
-
-       if (res) {
-               stats[type].drm.resident += size;
-
-               if (!dma_resv_test_signaled(obj->resv, DMA_RESV_USAGE_BOOKKEEP))
-                       stats[type].drm.active += size;
-               else if (bo->flags & AMDGPU_GEM_CREATE_DISCARDABLE)
-                       stats[type].drm.purgeable += size;
-       }
-
-       /* amdgpu specific stats: */
-
-       if (bo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) {
-               stats[TTM_PL_VRAM].requested += size;
-               if (type != TTM_PL_VRAM)
-                       stats[TTM_PL_VRAM].evicted += size;
-       } else if (bo->preferred_domains & AMDGPU_GEM_DOMAIN_GTT) {
-               stats[TTM_PL_TT].requested += size;
-       }
-}
-
 /**
  * amdgpu_bo_release_notify - notification about a BO being released
  * @bo: pointer to a buffer object
@@ -1555,6 +1485,45 @@ u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
        return amdgpu_gmc_sign_extend(offset);
 }
 
+/**
+ * amdgpu_bo_mem_stats_placement - bo placement for memory accounting
+ * @bo:        the buffer object we should look at
+ *
+ * BO can have multiple preferred placements, to avoid double counting we want
+ * to file it under a single placement for memory stats.
+ * Luckily, if we take the highest set bit in preferred_domains the result is
+ * quite sensible.
+ *
+ * Returns:
+ * Which of the placements should the BO be accounted under.
+ */
+uint32_t amdgpu_bo_mem_stats_placement(struct amdgpu_bo *bo)
+{
+       uint32_t domain = bo->preferred_domains & AMDGPU_GEM_DOMAIN_MASK;
+
+       if (!domain)
+               return TTM_PL_SYSTEM;
+
+       switch (rounddown_pow_of_two(domain)) {
+       case AMDGPU_GEM_DOMAIN_CPU:
+               return TTM_PL_SYSTEM;
+       case AMDGPU_GEM_DOMAIN_GTT:
+               return TTM_PL_TT;
+       case AMDGPU_GEM_DOMAIN_VRAM:
+               return TTM_PL_VRAM;
+       case AMDGPU_GEM_DOMAIN_GDS:
+               return AMDGPU_PL_GDS;
+       case AMDGPU_GEM_DOMAIN_GWS:
+               return AMDGPU_PL_GWS;
+       case AMDGPU_GEM_DOMAIN_OA:
+               return AMDGPU_PL_OA;
+       case AMDGPU_GEM_DOMAIN_DOORBELL:
+               return AMDGPU_PL_DOORBELL;
+       default:
+               return TTM_PL_SYSTEM;
+       }
+}
+
 /**
  * amdgpu_bo_get_preferred_domain - get preferred domain
  * @adev: amdgpu device object
This page took 0.037188 seconds and 4 git commands to generate.