drm_mm.h 4.4 KB

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