Skip to content

Commit

Permalink
drm/ttm: add back a reference to the bdev to the res manager
Browse files Browse the repository at this point in the history
It is simply a lot cleaner to have this around instead of adding
the device throughout the call chain.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20220124122514.1832-3-christian.koenig@amd.com
  • Loading branch information
Christian König committed Jan 26, 2022
1 parent de3688e commit 3f268ef
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
man->use_tt = true;
man->func = &amdgpu_gtt_mgr_func;

ttm_resource_manager_init(man, gtt_size >> PAGE_SHIFT);
ttm_resource_manager_init(man, &adev->mman.bdev,
gtt_size >> PAGE_SHIFT);

start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/amd/amdgpu/amdgpu_preempt_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int amdgpu_preempt_mgr_init(struct amdgpu_device *adev)
man->use_tt = true;
man->func = &amdgpu_preempt_mgr_func;

ttm_resource_manager_init(man, (1 << 30));
ttm_resource_manager_init(man, &adev->mman.bdev, (1 << 30));

atomic64_set(&mgr->used, 0);

Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
struct ttm_resource_manager *man = &mgr->manager;

ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
ttm_resource_manager_init(man, &adev->mman.bdev,
adev->gmc.real_vram_size >> PAGE_SHIFT);

man->func = &amdgpu_vram_mgr_func;

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int i915_ttm_buddy_man_init(struct ttm_device *bdev,
man = &bman->manager;
man->use_tt = use_tt;
man->func = &i915_ttm_buddy_manager_func;
ttm_resource_manager_init(man, bman->mm.size >> PAGE_SHIFT);
ttm_resource_manager_init(man, bdev, bman->mm.size >> PAGE_SHIFT);

ttm_resource_manager_set_used(man, true);
ttm_set_driver_manager(bdev, type, man);
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/nouveau/nouveau_ttm.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)

man->func = &nouveau_vram_manager;

ttm_resource_manager_init(man,
ttm_resource_manager_init(man, &drm->ttm.bdev,
drm->gem.vram_available >> PAGE_SHIFT);
ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
ttm_resource_manager_set_used(man, true);
Expand Down Expand Up @@ -211,7 +211,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)

man->func = func;
man->use_tt = true;
ttm_resource_manager_init(man, size_pages);
ttm_resource_manager_init(man, &drm->ttm.bdev, size_pages);
ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
ttm_resource_manager_set_used(man, true);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/ttm/ttm_range_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int ttm_range_man_init_nocheck(struct ttm_device *bdev,

man->func = &ttm_range_manager_func;

ttm_resource_manager_init(man, p_size);
ttm_resource_manager_init(man, bdev, p_size);

drm_mm_init(&rman->mm, 0, p_size);
spin_lock_init(&rman->lock);
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/ttm/ttm_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ EXPORT_SYMBOL(ttm_resource_compat);
* ttm_resource_manager_init
*
* @man: memory manager object to init
* @bdev: ttm device this manager belongs to
* @p_size: size managed area in pages.
*
* Initialise core parts of a manager object.
*/
void ttm_resource_manager_init(struct ttm_resource_manager *man,
struct ttm_device *bdev,
unsigned long p_size)
{
unsigned i;

spin_lock_init(&man->move_lock);
man->bdev = bdev;
man->size = p_size;

for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/ttm/ttm_sys_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ttm_sys_man_init(struct ttm_device *bdev)
man->use_tt = true;
man->func = &ttm_sys_manager_func;

ttm_resource_manager_init(man, 0);
ttm_resource_manager_init(man, bdev, 0);
ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, man);
ttm_resource_manager_set_used(man, true);
}
2 changes: 1 addition & 1 deletion drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)

man->func = &vmw_gmrid_manager_func;
man->use_tt = true;
ttm_resource_manager_init(man, 0);
ttm_resource_manager_init(man, &dev_priv->bdev, 0);
spin_lock_init(&gman->lock);
gman->used_gmr_pages = 0;
ida_init(&gman->gmr_ida);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/vmwgfx/vmwgfx_system_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int vmw_sys_man_init(struct vmw_private *dev_priv)
man->use_tt = true;
man->func = &vmw_sys_manager_func;

ttm_resource_manager_init(man, 0);
ttm_resource_manager_init(man, bdev, 0);
ttm_set_driver_manager(bdev, VMW_PL_SYSTEM, man);
ttm_resource_manager_set_used(man, true);
return 0;
Expand Down
16 changes: 9 additions & 7 deletions include/drm/ttm/ttm_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ struct ttm_resource_manager_func {
* @use_type: The memory type is enabled.
* @use_tt: If a TT object should be used for the backing store.
* @size: Size of the managed region.
* @bdev: ttm device this manager belongs to
* @func: structure pointer implementing the range manager. See above
* @move_lock: lock for move fence
* static information. bdev::driver::io_mem_free is never used.
* @lru: The lru list for this memory type.
* @move: The fence of the last pipelined move operation.
* @lru: The lru list for this memory type.
*
* This structure is used to identify and manage memory types for a device.
*/
Expand All @@ -119,20 +119,21 @@ struct ttm_resource_manager {
*/
bool use_type;
bool use_tt;
struct ttm_device *bdev;
uint64_t size;
const struct ttm_resource_manager_func *func;
spinlock_t move_lock;

/*
* Protected by the global->lru_lock.
* Protected by @move_lock.
*/

struct list_head lru[TTM_MAX_BO_PRIORITY];
struct dma_fence *move;

/*
* Protected by @move_lock.
* Protected by the global->lru_lock.
*/
struct dma_fence *move;

struct list_head lru[TTM_MAX_BO_PRIORITY];
};

/**
Expand Down Expand Up @@ -272,6 +273,7 @@ bool ttm_resource_compat(struct ttm_resource *res,
struct ttm_placement *placement);

void ttm_resource_manager_init(struct ttm_resource_manager *man,
struct ttm_device *bdev,
unsigned long p_size);

int ttm_resource_manager_evict_all(struct ttm_device *bdev,
Expand Down

0 comments on commit 3f268ef

Please sign in to comment.