drm: mm: extract node insert helper functions
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 18 Feb 2011 16:59:13 +0000 (17:59 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 23 Feb 2011 00:32:43 +0000 (10:32 +1000)
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_mm.c

index 4fa33e1283afad5008a74021a29a0b896a7b939f..fecb4063c018d5ac7d91e43ad71b4db4d7b07256 100644 (file)
@@ -115,24 +115,15 @@ static inline unsigned long drm_mm_hole_node_end(struct drm_mm_node *hole_node)
        return next_node->start;
 }
 
-struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *hole_node,
-                                            unsigned long size,
-                                            unsigned alignment,
-                                            int atomic)
+static void drm_mm_insert_helper(struct drm_mm_node *hole_node,
+                                struct drm_mm_node *node,
+                                unsigned long size, unsigned alignment)
 {
-
-       struct drm_mm_node *node;
        struct drm_mm *mm = hole_node->mm;
        unsigned long tmp = 0, wasted = 0;
        unsigned long hole_start = drm_mm_hole_node_start(hole_node);
        unsigned long hole_end = drm_mm_hole_node_end(hole_node);
 
-       BUG_ON(!hole_node->hole_follows);
-
-       node = drm_mm_kmalloc(mm, atomic);
-       if (unlikely(node == NULL))
-               return NULL;
-
        if (alignment)
                tmp = hole_start % alignment;
 
@@ -157,30 +148,37 @@ struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *hole_node,
        } else {
                node->hole_follows = 0;
        }
+}
+
+struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *hole_node,
+                                            unsigned long size,
+                                            unsigned alignment,
+                                            int atomic)
+{
+       struct drm_mm_node *node;
+
+       BUG_ON(!hole_node->hole_follows);
+
+       node = drm_mm_kmalloc(hole_node->mm, atomic);
+       if (unlikely(node == NULL))
+               return NULL;
+
+       drm_mm_insert_helper(hole_node, node, size, alignment);
 
        return node;
 }
 EXPORT_SYMBOL(drm_mm_get_block_generic);
 
-struct drm_mm_node *drm_mm_get_block_range_generic(struct drm_mm_node *hole_node,
-                                               unsigned long size,
-                                               unsigned alignment,
-                                               unsigned long start,
-                                               unsigned long end,
-                                               int atomic)
+static void drm_mm_insert_helper_range(struct drm_mm_node *hole_node,
+                                      struct drm_mm_node *node,
+                                      unsigned long size, unsigned alignment,
+                                      unsigned long start, unsigned long end)
 {
-       struct drm_mm_node *node;
        struct drm_mm *mm = hole_node->mm;
        unsigned long tmp = 0, wasted = 0;
        unsigned long hole_start = drm_mm_hole_node_start(hole_node);
        unsigned long hole_end = drm_mm_hole_node_end(hole_node);
 
-       BUG_ON(!hole_node->hole_follows);
-
-       node = drm_mm_kmalloc(mm, atomic);
-       if (unlikely(node == NULL))
-               return NULL;
-
        if (hole_start < start)
                wasted += start - hole_start;
        if (alignment)
@@ -210,6 +208,25 @@ struct drm_mm_node *drm_mm_get_block_range_generic(struct drm_mm_node *hole_node
        } else {
                node->hole_follows = 0;
        }
+}
+
+struct drm_mm_node *drm_mm_get_block_range_generic(struct drm_mm_node *hole_node,
+                                               unsigned long size,
+                                               unsigned alignment,
+                                               unsigned long start,
+                                               unsigned long end,
+                                               int atomic)
+{
+       struct drm_mm_node *node;
+
+       BUG_ON(!hole_node->hole_follows);
+
+       node = drm_mm_kmalloc(hole_node->mm, atomic);
+       if (unlikely(node == NULL))
+               return NULL;
+
+       drm_mm_insert_helper_range(hole_node, node, size, alignment,
+                                  start, end);
 
        return node;
 }