#include "i915_buddy.h"
#include "i915_gem.h"
+#include "i915_globals.h"
#include "i915_utils.h"
+static struct i915_global_buddy {
+ struct i915_global base;
+ struct kmem_cache *slab_blocks;
+} global;
+
static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm,
struct i915_buddy_block *parent,
unsigned int order,
GEM_BUG_ON(order > I915_BUDDY_MAX_ORDER);
- block = kmem_cache_zalloc(mm->slab_blocks, GFP_KERNEL);
+ block = kmem_cache_zalloc(global.slab_blocks, GFP_KERNEL);
if (!block)
return NULL;
static void i915_block_free(struct i915_buddy_mm *mm,
struct i915_buddy_block *block)
{
- kmem_cache_free(mm->slab_blocks, block);
+ kmem_cache_free(global.slab_blocks, block);
}
static void mark_allocated(struct i915_buddy_block *block)
GEM_BUG_ON(mm->max_order > I915_BUDDY_MAX_ORDER);
- mm->slab_blocks = KMEM_CACHE(i915_buddy_block, SLAB_HWCACHE_ALIGN);
- if (!mm->slab_blocks)
- return -ENOMEM;
-
mm->free_list = kmalloc_array(mm->max_order + 1,
sizeof(struct list_head),
GFP_KERNEL);
if (!mm->free_list)
- goto out_destroy_slab;
+ return -ENOMEM;
for (i = 0; i <= mm->max_order; ++i)
INIT_LIST_HEAD(&mm->free_list[i]);
kfree(mm->roots);
out_free_list:
kfree(mm->free_list);
-out_destroy_slab:
- kmem_cache_destroy(mm->slab_blocks);
return -ENOMEM;
}
kfree(mm->roots);
kfree(mm->free_list);
- kmem_cache_destroy(mm->slab_blocks);
}
static int split_block(struct i915_buddy_mm *mm,
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
#include "selftests/i915_buddy.c"
#endif
+
+static void i915_global_buddy_exit(void)
+{
+ kmem_cache_destroy(global.slab_blocks);
+}
+
+static struct i915_global_buddy global = { {
+ .exit = i915_global_buddy_exit,
+} };
+
+int __init i915_global_buddy_init(void)
+{
+ global.slab_blocks = KMEM_CACHE(i915_buddy_block, 0);
+ if (!global.slab_blocks)
+ return -ENOMEM;
+
+ i915_global_register(&global.base);
+ return 0;
+}
#include <linux/workqueue.h>
#include "i915_active.h"
+#include "i915_buddy.h"
#include "gem/i915_gem_context.h"
#include "gem/i915_gem_object.h"
#include "i915_globals.h"
static __initconst int (* const initfn[])(void) = {
i915_global_active_init,
+ i915_global_buddy_init,
i915_global_context_init,
i915_global_gem_context_init,
i915_global_objects_init,