Message ID | 20200731040520.3701599-41-airlied@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ttm mem manager refactoring. | expand |
Am 31.07.20 um 06:05 schrieb Dave Airlie: > From: Dave Airlie <airlied@redhat.com> > > Signed-off-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/ttm/ttm_bo_manager.c | 32 +++++++++++++++++----------- > 1 file changed, 20 insertions(+), 12 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c > index 2f5fa44b6474..2782ccff9b66 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c > +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c > @@ -44,16 +44,22 @@ > */ > > struct ttm_range_manager { > + struct ttm_mem_type_manager manager; > struct drm_mm mm; > spinlock_t lock; > }; > > +static inline struct ttm_range_manager *to_range_manager(struct ttm_mem_type_manager *man) > +{ > + return container_of(man, struct ttm_range_manager, manager); > +} > + > static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, > struct ttm_buffer_object *bo, > const struct ttm_place *place, > struct ttm_mem_reg *mem) > { > - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; > + struct ttm_range_manager *rman = to_range_manager(man); > struct drm_mm *mm = &rman->mm; > struct drm_mm_node *node; > enum drm_mm_insert_mode mode; > @@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, > static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man, > struct ttm_mem_reg *mem) > { > - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; > + struct ttm_range_manager *rman = to_range_manager(man); > > if (mem->mm_node) { > spin_lock(&rman->lock); > @@ -113,25 +119,26 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev, > bool use_tt, > unsigned long p_size) > { > - struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type); > + struct ttm_mem_type_manager *man; > struct ttm_range_manager *rman; > > - man->available_caching = available_caching; > - man->default_caching = default_caching; > - man->use_tt = use_tt; > - > rman = kzalloc(sizeof(*rman), GFP_KERNEL); > if (!rman) > return -ENOMEM; > > + man = &rman->manager; > + man->available_caching = available_caching; > + man->default_caching = default_caching; > + man->use_tt = use_tt; > + > man->func = &ttm_bo_manager_func; > > ttm_bo_init_mm_base(bdev, man, p_size); > > drm_mm_init(&rman->mm, 0, p_size); > spin_lock_init(&rman->lock); > - man->priv = rman; > > + ttm_set_driver_manager(bdev, type, &rman->manager); > ttm_bo_use_mm(man); > return 0; > } > @@ -141,7 +148,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev, > unsigned type) > { > struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type); > - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; > + struct ttm_range_manager *rman = to_range_manager(man); > struct drm_mm *mm = &rman->mm; > int ret; > > @@ -155,10 +162,11 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev, > drm_mm_clean(mm); > drm_mm_takedown(mm); > spin_unlock(&rman->lock); > - kfree(rman); > - man->priv = NULL; > > ttm_bo_man_cleanup(man); > + ttm_set_driver_manager(bdev, type, NULL); > + kfree(rman); > + > return 0; > } > EXPORT_SYMBOL(ttm_bo_man_takedown); > @@ -166,7 +174,7 @@ EXPORT_SYMBOL(ttm_bo_man_takedown); > static void ttm_bo_man_debug(struct ttm_mem_type_manager *man, > struct drm_printer *printer) > { > - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; > + struct ttm_range_manager *rman = to_range_manager(man); > > spin_lock(&rman->lock); > drm_mm_print(&rman->mm, printer);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c index 2f5fa44b6474..2782ccff9b66 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c @@ -44,16 +44,22 @@ */ struct ttm_range_manager { + struct ttm_mem_type_manager manager; struct drm_mm mm; spinlock_t lock; }; +static inline struct ttm_range_manager *to_range_manager(struct ttm_mem_type_manager *man) +{ + return container_of(man, struct ttm_range_manager, manager); +} + static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, struct ttm_buffer_object *bo, const struct ttm_place *place, struct ttm_mem_reg *mem) { - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; + struct ttm_range_manager *rman = to_range_manager(man); struct drm_mm *mm = &rman->mm; struct drm_mm_node *node; enum drm_mm_insert_mode mode; @@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man, struct ttm_mem_reg *mem) { - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; + struct ttm_range_manager *rman = to_range_manager(man); if (mem->mm_node) { spin_lock(&rman->lock); @@ -113,25 +119,26 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev, bool use_tt, unsigned long p_size) { - struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type); + struct ttm_mem_type_manager *man; struct ttm_range_manager *rman; - man->available_caching = available_caching; - man->default_caching = default_caching; - man->use_tt = use_tt; - rman = kzalloc(sizeof(*rman), GFP_KERNEL); if (!rman) return -ENOMEM; + man = &rman->manager; + man->available_caching = available_caching; + man->default_caching = default_caching; + man->use_tt = use_tt; + man->func = &ttm_bo_manager_func; ttm_bo_init_mm_base(bdev, man, p_size); drm_mm_init(&rman->mm, 0, p_size); spin_lock_init(&rman->lock); - man->priv = rman; + ttm_set_driver_manager(bdev, type, &rman->manager); ttm_bo_use_mm(man); return 0; } @@ -141,7 +148,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev, unsigned type) { struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type); - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; + struct ttm_range_manager *rman = to_range_manager(man); struct drm_mm *mm = &rman->mm; int ret; @@ -155,10 +162,11 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev, drm_mm_clean(mm); drm_mm_takedown(mm); spin_unlock(&rman->lock); - kfree(rman); - man->priv = NULL; ttm_bo_man_cleanup(man); + ttm_set_driver_manager(bdev, type, NULL); + kfree(rman); + return 0; } EXPORT_SYMBOL(ttm_bo_man_takedown); @@ -166,7 +174,7 @@ EXPORT_SYMBOL(ttm_bo_man_takedown); static void ttm_bo_man_debug(struct ttm_mem_type_manager *man, struct drm_printer *printer) { - struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; + struct ttm_range_manager *rman = to_range_manager(man); spin_lock(&rman->lock); drm_mm_print(&rman->mm, printer);