drm_mm.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**************************************************************************
  2. *
  3. * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX. USA.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. *
  27. **************************************************************************/
  28. /*
  29. * Authors:
  30. * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
  31. */
  32. #ifndef _DRM_MM_H_
  33. #define _DRM_MM_H_
  34. /*
  35. * Generic range manager structs
  36. */
  37. #include <linux/list.h>
  38. #ifdef CONFIG_DEBUG_FS
  39. #include <linux/seq_file.h>
  40. #endif
  41. struct drm_mm_node {
  42. struct list_head node_list;
  43. struct list_head hole_stack;
  44. unsigned hole_follows : 1;
  45. unsigned scanned_block : 1;
  46. unsigned scanned_prev_free : 1;
  47. unsigned scanned_next_free : 1;
  48. unsigned scanned_preceeds_hole : 1;
  49. unsigned allocated : 1;
  50. unsigned long start;
  51. unsigned long size;
  52. struct drm_mm *mm;
  53. };
  54. struct drm_mm {
  55. /* List of all memory nodes that immediately precede a free hole. */
  56. struct list_head hole_stack;
  57. /* head_node.node_list is the list of all memory nodes, ordered
  58. * according to the (increasing) start address of the memory node. */
  59. struct drm_mm_node head_node;
  60. struct list_head unused_nodes;
  61. int num_unused;
  62. spinlock_t unused_lock;
  63. unsigned int scan_check_range : 1;
  64. unsigned scan_alignment;
  65. unsigned long scan_size;
  66. unsigned long scan_hit_start;
  67. unsigned scan_hit_size;
  68. unsigned scanned_blocks;
  69. unsigned long scan_start;
  70. unsigned long scan_end;
  71. struct drm_mm_node *prev_scanned_node;
  72. };
  73. static inline bool drm_mm_node_allocated(struct drm_mm_node *node)
  74. {
  75. return node->allocated;
  76. }
  77. static inline bool drm_mm_initialized(struct drm_mm *mm)
  78. {
  79. return mm->hole_stack.next;
  80. }
  81. #define drm_mm_for_each_node(entry, mm) list_for_each_entry(entry, \
  82. &(mm)->head_node.node_list, \
  83. node_list)
  84. #define drm_mm_for_each_scanned_node_reverse(entry, n, mm) \
  85. for (entry = (mm)->prev_scanned_node, \
  86. next = entry ? list_entry(entry->node_list.next, \
  87. struct drm_mm_node, node_list) : NULL; \
  88. entry != NULL; entry = next, \
  89. next = entry ? list_entry(entry->node_list.next, \
  90. struct drm_mm_node, node_list) : NULL) \
  91. /*
  92. * Basic range manager support (drm_mm.c)
  93. */
  94. extern struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *node,
  95. unsigned long size,
  96. unsigned alignment,
  97. int atomic);
  98. extern struct drm_mm_node *drm_mm_get_block_range_generic(
  99. struct drm_mm_node *node,
  100. unsigned long size,
  101. unsigned alignment,
  102. unsigned long start,
  103. unsigned long end,
  104. int atomic);
  105. static inline struct drm_mm_node *drm_mm_get_block(struct drm_mm_node *parent,
  106. unsigned long size,
  107. unsigned alignment)
  108. {
  109. return drm_mm_get_block_generic(parent, size, alignment, 0);
  110. }
  111. static inline struct drm_mm_node *drm_mm_get_block_atomic(struct drm_mm_node *parent,
  112. unsigned long size,
  113. unsigned alignment)
  114. {
  115. return drm_mm_get_block_generic(parent, size, alignment, 1);
  116. }
  117. static inline struct drm_mm_node *drm_mm_get_block_range(
  118. struct drm_mm_node *parent,
  119. unsigned long size,
  120. unsigned alignment,
  121. unsigned long start,
  122. unsigned long end)
  123. {
  124. return drm_mm_get_block_range_generic(parent, size, alignment,
  125. start, end, 0);
  126. }
  127. static inline struct drm_mm_node *drm_mm_get_block_atomic_range(
  128. struct drm_mm_node *parent,
  129. unsigned long size,
  130. unsigned alignment,
  131. unsigned long start,
  132. unsigned long end)
  133. {
  134. return drm_mm_get_block_range_generic(parent, size, alignment,
  135. start, end, 1);
  136. }
  137. extern int drm_mm_insert_node(struct drm_mm *mm, struct drm_mm_node *node,
  138. unsigned long size, unsigned alignment);
  139. extern int drm_mm_insert_node_in_range(struct drm_mm *mm,
  140. struct drm_mm_node *node,
  141. unsigned long size, unsigned alignment,
  142. unsigned long start, unsigned long end);
  143. extern void drm_mm_put_block(struct drm_mm_node *cur);
  144. extern void drm_mm_remove_node(struct drm_mm_node *node);
  145. extern void drm_mm_replace_node(struct drm_mm_node *old, struct drm_mm_node *new);
  146. extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
  147. unsigned long size,
  148. unsigned alignment,
  149. int best_match);
  150. extern struct drm_mm_node *drm_mm_search_free_in_range(
  151. const struct drm_mm *mm,
  152. unsigned long size,
  153. unsigned alignment,
  154. unsigned long start,
  155. unsigned long end,
  156. int best_match);
  157. extern int drm_mm_init(struct drm_mm *mm, unsigned long start,
  158. unsigned long size);
  159. extern void drm_mm_takedown(struct drm_mm *mm);
  160. extern int drm_mm_clean(struct drm_mm *mm);
  161. extern int drm_mm_pre_get(struct drm_mm *mm);
  162. static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
  163. {
  164. return block->mm;
  165. }
  166. void drm_mm_init_scan(struct drm_mm *mm, unsigned long size,
  167. unsigned alignment);
  168. void drm_mm_init_scan_with_range(struct drm_mm *mm, unsigned long size,
  169. unsigned alignment,
  170. unsigned long start,
  171. unsigned long end);
  172. int drm_mm_scan_add_block(struct drm_mm_node *node);
  173. int drm_mm_scan_remove_block(struct drm_mm_node *node);
  174. extern void drm_mm_debug_table(struct drm_mm *mm, const char *prefix);
  175. #ifdef CONFIG_DEBUG_FS
  176. int drm_mm_dump_table(struct seq_file *m, struct drm_mm *mm);
  177. #endif
  178. #endif