drm_mm.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 fl_entry;
  43. struct list_head ml_entry;
  44. int free;
  45. unsigned long start;
  46. unsigned long size;
  47. struct drm_mm *mm;
  48. void *private;
  49. };
  50. struct drm_mm {
  51. struct list_head fl_entry;
  52. struct list_head ml_entry;
  53. struct list_head unused_nodes;
  54. int num_unused;
  55. spinlock_t unused_lock;
  56. };
  57. /*
  58. * Basic range manager support (drm_mm.c)
  59. */
  60. extern struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node *node,
  61. unsigned long size,
  62. unsigned alignment,
  63. int atomic);
  64. extern struct drm_mm_node *drm_mm_get_block_range_generic(
  65. struct drm_mm_node *node,
  66. unsigned long size,
  67. unsigned alignment,
  68. unsigned long start,
  69. unsigned long end,
  70. int atomic);
  71. static inline struct drm_mm_node *drm_mm_get_block(struct drm_mm_node *parent,
  72. unsigned long size,
  73. unsigned alignment)
  74. {
  75. return drm_mm_get_block_generic(parent, size, alignment, 0);
  76. }
  77. static inline struct drm_mm_node *drm_mm_get_block_atomic(struct drm_mm_node *parent,
  78. unsigned long size,
  79. unsigned alignment)
  80. {
  81. return drm_mm_get_block_generic(parent, size, alignment, 1);
  82. }
  83. static inline struct drm_mm_node *drm_mm_get_block_range(
  84. struct drm_mm_node *parent,
  85. unsigned long size,
  86. unsigned alignment,
  87. unsigned long start,
  88. unsigned long end)
  89. {
  90. return drm_mm_get_block_range_generic(parent, size, alignment,
  91. start, end, 0);
  92. }
  93. static inline struct drm_mm_node *drm_mm_get_block_atomic_range(
  94. struct drm_mm_node *parent,
  95. unsigned long size,
  96. unsigned alignment,
  97. unsigned long start,
  98. unsigned long end)
  99. {
  100. return drm_mm_get_block_range_generic(parent, size, alignment,
  101. start, end, 1);
  102. }
  103. extern void drm_mm_put_block(struct drm_mm_node *cur);
  104. extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
  105. unsigned long size,
  106. unsigned alignment,
  107. int best_match);
  108. extern struct drm_mm_node *drm_mm_search_free_in_range(
  109. const struct drm_mm *mm,
  110. unsigned long size,
  111. unsigned alignment,
  112. unsigned long start,
  113. unsigned long end,
  114. int best_match);
  115. extern int drm_mm_init(struct drm_mm *mm, unsigned long start,
  116. unsigned long size);
  117. extern void drm_mm_takedown(struct drm_mm *mm);
  118. extern int drm_mm_clean(struct drm_mm *mm);
  119. extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
  120. extern int drm_mm_remove_space_from_tail(struct drm_mm *mm,
  121. unsigned long size);
  122. extern int drm_mm_add_space_to_tail(struct drm_mm *mm,
  123. unsigned long size, int atomic);
  124. extern int drm_mm_pre_get(struct drm_mm *mm);
  125. static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
  126. {
  127. return block->mm;
  128. }
  129. extern void drm_mm_debug_table(struct drm_mm *mm, const char *prefix);
  130. #ifdef CONFIG_DEBUG_FS
  131. int drm_mm_dump_table(struct seq_file *m, struct drm_mm *mm);
  132. #endif
  133. #endif