1450N/A/*
1450N/A * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A/*
1450N/A * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
1450N/A */
1450N/A
1450N/A/**************************************************************************
1450N/A *
1450N/A * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX. USA.
1450N/A * All Rights Reserved.
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the
1450N/A * "Software"), to deal in the Software without restriction, including
1450N/A * without limitation the rights to use, copy, modify, merge, publish,
1450N/A * distribute, sub license, and/or sell copies of the Software, and to
1450N/A * permit persons to whom the Software is furnished to do so, subject to
1450N/A * the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the
1450N/A * next paragraph) shall be included in all copies or substantial portions
1450N/A * of the Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1450N/A * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
1450N/A * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1450N/A * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1450N/A * USE OR OTHER DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A *
1450N/A **************************************************************************/
1450N/A/*
1450N/A * Authors:
1450N/A * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
1450N/A */
1450N/A
1450N/A#ifndef _DRM_MM_H_
1450N/A#define _DRM_MM_H_
1450N/A
1450N/A/*
1450N/A * Generic range manager structs
1450N/A */
1450N/A
1450N/Astruct drm_mm_node {
1450N/A struct list_head node_list;
1450N/A struct list_head hole_stack;
1450N/A unsigned hole_follows;
1450N/A unsigned scanned_block;
1450N/A unsigned scanned_prev_free;
1450N/A unsigned scanned_next_free;
1450N/A unsigned scanned_preceeds_hole;
1450N/A unsigned allocated;
1450N/A unsigned long color;
1450N/A unsigned long start;
1450N/A unsigned long size;
1450N/A struct drm_mm *mm;
1450N/A};
1450N/A
1450N/Astruct drm_mm {
1450N/A /* List of free memory blocks, most recently freed ordered. */
1450N/A struct list_head hole_stack;
1450N/A /* head_node.node_list is the list of all memory nodes, ordered
1450N/A * according to the (increasing) start address of the memory node. */
1450N/A struct drm_mm_node head_node;
1450N/A struct list_head unused_nodes;
1450N/A int num_unused;
1450N/A spinlock_t unused_lock;
1450N/A unsigned int scan_check_range : 1;
1450N/A unsigned scan_alignment;
1450N/A unsigned long scan_color;
1450N/A unsigned long scan_size;
1450N/A unsigned long scan_hit_start;
1450N/A unsigned long scan_hit_end;
1450N/A unsigned scanned_blocks;
1450N/A unsigned long scan_start;
1450N/A unsigned long scan_end;
1450N/A struct drm_mm_node *prev_scanned_node;
1450N/A
1450N/A void (*color_adjust)(struct drm_mm_node *node, unsigned long color,
1450N/A unsigned long *start, unsigned long *end);
1450N/A};
1450N/A
1450N/Astatic inline bool drm_mm_node_allocated(struct drm_mm_node *node)
1450N/A{
1450N/A return node->allocated;
1450N/A}
1450N/A
1450N/Aextern bool drm_mm_initialized(struct drm_mm *mm);
1450N/Aextern unsigned long __drm_mm_hole_node_start(struct drm_mm_node *hole_node);
1450N/Aextern unsigned long drm_mm_hole_node_start(struct drm_mm_node *hole_node);
1450N/Aextern unsigned long __drm_mm_hole_node_end(struct drm_mm_node *hole_node);
1450N/Aextern unsigned long drm_mm_hole_node_end(struct drm_mm_node *hole_node);
1450N/A#define drm_mm_for_each_node(entry, type, mm) list_for_each_entry(entry, type, \
1450N/A &(mm)->head_node.node_list, \
1450N/A node_list)
1450N/A#define drm_mm_for_each_scanned_node_reverse(entry, n, mm) \
1450N/A for (entry = (mm)->prev_scanned_node, \
1450N/A next = entry ? list_entry(entry->node_list.next, \
1450N/A struct drm_mm_node, node_list) : NULL; \
1450N/A entry != NULL; entry = next, \
1450N/A next = entry ? list_entry(entry->node_list.next, \
1450N/A struct drm_mm_node, node_list) : NULL) \
1450N/A
1450N/A/* Note that we need to unroll list_for_each_entry in order to inline
1450N/A * setting hole_start and hole_end on each iteration and keep the
1450N/A * macro sane.
1450N/A */
1450N/A#define drm_mm_for_each_hole(entry, mm, hole_start, hole_end) \
1450N/A for (entry = list_entry((mm)->hole_stack.next, struct drm_mm_node, hole_stack); \
1450N/A (entry) && (&entry->hole_stack != &(mm)->hole_stack ? \
1450N/A hole_start = drm_mm_hole_node_start(entry), \
1450N/A hole_end = drm_mm_hole_node_end(entry), \
1450N/A 1 : 0); \
1450N/A entry = list_entry(entry->hole_stack.next, struct drm_mm_node, hole_stack))
1450N/A
1450N/A/*
1450N/A * Basic range manager support (drm_mm.c)
1450N/A */
1450N/Aextern struct drm_mm_node *drm_mm_create_block(struct drm_mm *mm,
1450N/A unsigned long start,
1450N/A unsigned long size,
1450N/A bool atomic);
1450N/Aextern struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A int atomic);
1450N/Aextern struct drm_mm_node *drm_mm_get_block_range_generic(
1450N/A struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A unsigned long start,
1450N/A unsigned long end,
1450N/A int atomic);
1450N/Aextern struct drm_mm_node *drm_mm_get_block(struct drm_mm_node *parent,
1450N/A unsigned long size,
1450N/A unsigned alignment);
1450N/A
1450N/Aextern struct drm_mm_node *drm_mm_get_block_atomic(struct drm_mm_node *parent,
1450N/A unsigned long size,
1450N/A unsigned alignment);
1450N/A
1450N/Aextern struct drm_mm_node *drm_mm_get_block_range(
1450N/A struct drm_mm_node *parent,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long start,
1450N/A unsigned long end);
1450N/A
1450N/Aextern struct drm_mm_node *drm_mm_get_block_atomic_range(
1450N/A struct drm_mm_node *parent,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long start,
1450N/A unsigned long end);
1450N/A
1450N/Aextern int drm_mm_insert_node(struct drm_mm *mm,
1450N/A struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment);
1450N/Aextern int drm_mm_insert_node_in_range(struct drm_mm *mm,
1450N/A struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long start,
1450N/A unsigned long end);
1450N/Aextern int drm_mm_insert_node_generic(struct drm_mm *mm,
1450N/A struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color);
1450N/Aextern int drm_mm_insert_node_in_range_generic(struct drm_mm *mm,
1450N/A struct drm_mm_node *node,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A unsigned long start,
1450N/A unsigned long end);
1450N/Aextern void drm_mm_put_block(struct drm_mm_node *cur);
1450N/Aextern void drm_mm_remove_node(struct drm_mm_node *node);
1450N/Aextern void drm_mm_replace_node(struct drm_mm_node *old, struct drm_mm_node *new);
1450N/Aextern struct drm_mm_node *drm_mm_search_free_generic(const struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A bool best_match);
1450N/Aextern struct drm_mm_node *drm_mm_search_free_in_range_generic(
1450N/A const struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A unsigned long start,
1450N/A unsigned long end,
1450N/A bool best_match);
1450N/Aextern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A bool best_match);
1450N/Aextern struct drm_mm_node *drm_mm_search_free_in_range(
1450N/A const struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long start,
1450N/A unsigned long end,
1450N/A bool best_match);
1450N/Aextern void drm_mm_init(struct drm_mm *mm,
1450N/A unsigned long start,
1450N/A unsigned long size);
1450N/Aextern void drm_mm_takedown(struct drm_mm *mm);
1450N/Aextern int drm_mm_clean(struct drm_mm *mm);
1450N/Aextern int drm_mm_pre_get(struct drm_mm *mm);
1450N/Astatic inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
1450N/A{
1450N/A return block->mm;
1450N/A}
1450N/A
1450N/Avoid drm_mm_init_scan(struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color);
1450N/Avoid drm_mm_init_scan_with_range(struct drm_mm *mm,
1450N/A unsigned long size,
1450N/A unsigned alignment,
1450N/A unsigned long color,
1450N/A unsigned long start,
1450N/A unsigned long end);
1450N/Aint drm_mm_scan_add_block(struct drm_mm_node *node);
1450N/Aint drm_mm_scan_remove_block(struct drm_mm_node *node);
1450N/A
1450N/Aextern void drm_mm_debug_table(struct drm_mm *mm, const char *prefix);
1450N/A#ifdef CONFIG_DEBUG_FS
1450N/Aint drm_mm_dump_table(struct seq_file *m, struct drm_mm *mm);
1450N/A#endif
1450N/A
1450N/A#endif /* _DRM_MM_H_ */