linux/include/drm/drm_buddy.h

/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2021 Intel Corporation
 */

#ifndef __DRM_BUDDY_H__
#define __DRM_BUDDY_H__

#include <linux/bitops.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/sched.h>

#include <drm/drm_print.h>

#define range_overflows(start, size, max)

#define DRM_BUDDY_RANGE_ALLOCATION
#define DRM_BUDDY_TOPDOWN_ALLOCATION
#define DRM_BUDDY_CONTIGUOUS_ALLOCATION
#define DRM_BUDDY_CLEAR_ALLOCATION
#define DRM_BUDDY_CLEARED

struct drm_buddy_block {};

/* Order-zero must be at least SZ_4K */
#define DRM_BUDDY_MAX_ORDER

/*
 * Binary Buddy System.
 *
 * Locking should be handled by the user, a simple mutex around
 * drm_buddy_alloc* and drm_buddy_free* should suffice.
 */
struct drm_buddy {};

static inline u64
drm_buddy_block_offset(struct drm_buddy_block *block)
{}

static inline unsigned int
drm_buddy_block_order(struct drm_buddy_block *block)
{}

static inline unsigned int
drm_buddy_block_state(struct drm_buddy_block *block)
{}

static inline bool
drm_buddy_block_is_allocated(struct drm_buddy_block *block)
{}

static inline bool
drm_buddy_block_is_clear(struct drm_buddy_block *block)
{}

static inline bool
drm_buddy_block_is_free(struct drm_buddy_block *block)
{}

static inline bool
drm_buddy_block_is_split(struct drm_buddy_block *block)
{}

static inline u64
drm_buddy_block_size(struct drm_buddy *mm,
		     struct drm_buddy_block *block)
{}

int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size);

void drm_buddy_fini(struct drm_buddy *mm);

struct drm_buddy_block *
drm_get_buddy(struct drm_buddy_block *block);

int drm_buddy_alloc_blocks(struct drm_buddy *mm,
			   u64 start, u64 end, u64 size,
			   u64 min_page_size,
			   struct list_head *blocks,
			   unsigned long flags);

int drm_buddy_block_trim(struct drm_buddy *mm,
			 u64 new_size,
			 struct list_head *blocks);

void drm_buddy_free_block(struct drm_buddy *mm, struct drm_buddy_block *block);

void drm_buddy_free_list(struct drm_buddy *mm,
			 struct list_head *objects,
			 unsigned int flags);

void drm_buddy_print(struct drm_buddy *mm, struct drm_printer *p);
void drm_buddy_block_print(struct drm_buddy *mm,
			   struct drm_buddy_block *block,
			   struct drm_printer *p);
#endif