drm/ttm: flip over the range manager to self allocated nodes
[linux-2.6-microblaze.git] / drivers / gpu / drm / ttm / ttm_resource.c
index 04f2eef..2a51ace 100644 (file)
 #include <drm/ttm/ttm_resource.h>
 #include <drm/ttm/ttm_bo_driver.h>
 
+void ttm_resource_init(struct ttm_buffer_object *bo,
+                       const struct ttm_place *place,
+                       struct ttm_resource *res)
+{
+       res->mm_node = NULL;
+       res->start = 0;
+       res->num_pages = PFN_UP(bo->base.size);
+       res->mem_type = place->mem_type;
+       res->placement = place->flags;
+       res->bus.addr = NULL;
+       res->bus.offset = 0;
+       res->bus.is_iomem = false;
+       res->bus.caching = ttm_cached;
+}
+EXPORT_SYMBOL(ttm_resource_init);
+
 int ttm_resource_alloc(struct ttm_buffer_object *bo,
                       const struct ttm_place *place,
-                      struct ttm_resource *res)
+                      struct ttm_resource **res_ptr)
 {
        struct ttm_resource_manager *man =
-               ttm_manager_type(bo->bdev, res->mem_type);
-
-       res->mm_node = NULL;
-       if (!man->func || !man->func->alloc)
-               return 0;
+               ttm_manager_type(bo->bdev, place->mem_type);
+       struct ttm_resource *res;
+       int r;
+
+       res = kmalloc(sizeof(*res), GFP_KERNEL);
+       if (!res)
+               return -ENOMEM;
+
+       ttm_resource_init(bo, place, res);
+       r = man->func->alloc(man, bo, place, res);
+       if (r) {
+               kfree(res);
+               return r;
+       }
 
-       return man->func->alloc(man, bo, place, res);
+       *res_ptr = res;
+       return 0;
 }
 
-void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource *res)
+void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
 {
-       struct ttm_resource_manager *man =
-               ttm_manager_type(bo->bdev, res->mem_type);
+       struct ttm_resource_manager *man;
 
-       if (man->func && man->func->free)
-               man->func->free(man, res);
+       if (!*res)
+               return;
 
-       res->mm_node = NULL;
-       res->mem_type = TTM_PL_SYSTEM;
+       man = ttm_manager_type(bo->bdev, (*res)->mem_type);
+       man->func->free(man, *res);
+       kfree(*res);
+       *res = NULL;
 }
 EXPORT_SYMBOL(ttm_resource_free);
 
@@ -139,7 +166,7 @@ void ttm_resource_manager_debug(struct ttm_resource_manager *man,
        drm_printf(p, "  use_type: %d\n", man->use_type);
        drm_printf(p, "  use_tt: %d\n", man->use_tt);
        drm_printf(p, "  size: %llu\n", man->size);
-       if (man->func && man->func->debug)
-               (*man->func->debug)(man, p);
+       if (man->func->debug)
+               man->func->debug(man, p);
 }
 EXPORT_SYMBOL(ttm_resource_manager_debug);