Commit 3a1fc38e authored by Dave Airlie's avatar Dave Airlie
parent 37205891
...@@ -44,16 +44,22 @@ ...@@ -44,16 +44,22 @@
*/ */
struct ttm_range_manager { struct ttm_range_manager {
struct ttm_mem_type_manager manager;
struct drm_mm mm; struct drm_mm mm;
spinlock_t lock; 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, static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
struct ttm_buffer_object *bo, struct ttm_buffer_object *bo,
const struct ttm_place *place, const struct ttm_place *place,
struct ttm_mem_reg *mem) 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 *mm = &rman->mm;
struct drm_mm_node *node; struct drm_mm_node *node;
enum drm_mm_insert_mode mode; enum drm_mm_insert_mode mode;
...@@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man, ...@@ -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, static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
struct ttm_mem_reg *mem) 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) { if (mem->mm_node) {
spin_lock(&rman->lock); spin_lock(&rman->lock);
...@@ -113,25 +119,26 @@ int ttm_range_man_init(struct ttm_bo_device *bdev, ...@@ -113,25 +119,26 @@ int ttm_range_man_init(struct ttm_bo_device *bdev,
bool use_tt, bool use_tt,
unsigned long p_size) 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; 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); rman = kzalloc(sizeof(*rman), GFP_KERNEL);
if (!rman) if (!rman)
return -ENOMEM; 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; man->func = &ttm_bo_manager_func;
ttm_mem_type_manager_init(bdev, man, p_size); ttm_mem_type_manager_init(bdev, man, p_size);
drm_mm_init(&rman->mm, 0, p_size); drm_mm_init(&rman->mm, 0, p_size);
spin_lock_init(&rman->lock); spin_lock_init(&rman->lock);
man->priv = rman;
ttm_set_driver_manager(bdev, type, &rman->manager);
ttm_mem_type_manager_set_used(man, true); ttm_mem_type_manager_set_used(man, true);
return 0; return 0;
} }
...@@ -141,7 +148,7 @@ int ttm_range_man_fini(struct ttm_bo_device *bdev, ...@@ -141,7 +148,7 @@ int ttm_range_man_fini(struct ttm_bo_device *bdev,
unsigned type) unsigned type)
{ {
struct ttm_mem_type_manager *man = ttm_manager_type(bdev, 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; struct drm_mm *mm = &rman->mm;
int ret; int ret;
...@@ -155,10 +162,10 @@ int ttm_range_man_fini(struct ttm_bo_device *bdev, ...@@ -155,10 +162,10 @@ int ttm_range_man_fini(struct ttm_bo_device *bdev,
drm_mm_clean(mm); drm_mm_clean(mm);
drm_mm_takedown(mm); drm_mm_takedown(mm);
spin_unlock(&rman->lock); spin_unlock(&rman->lock);
kfree(rman);
man->priv = NULL;
ttm_mem_type_manager_cleanup(man); ttm_mem_type_manager_cleanup(man);
ttm_set_driver_manager(bdev, type, NULL);
kfree(rman);
return 0; return 0;
} }
EXPORT_SYMBOL(ttm_range_man_fini); EXPORT_SYMBOL(ttm_range_man_fini);
...@@ -166,7 +173,7 @@ EXPORT_SYMBOL(ttm_range_man_fini); ...@@ -166,7 +173,7 @@ EXPORT_SYMBOL(ttm_range_man_fini);
static void ttm_bo_man_debug(struct ttm_mem_type_manager *man, static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
struct drm_printer *printer) 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); spin_lock(&rman->lock);
drm_mm_print(&rman->mm, printer); drm_mm_print(&rman->mm, printer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment