Rev 4110 | Rev 6082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4110 | Rev 5056 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | #endif |
45 | #endif |
Line 46... | Line 46... | ||
46 | 46 | ||
47 | enum drm_mm_search_flags { |
47 | enum drm_mm_search_flags { |
48 | DRM_MM_SEARCH_DEFAULT = 0, |
48 | DRM_MM_SEARCH_DEFAULT = 0, |
- | 49 | DRM_MM_SEARCH_BEST = 1 << 0, |
|
49 | DRM_MM_SEARCH_BEST = 1 << 0, |
50 | DRM_MM_SEARCH_BELOW = 1 << 1, |
Line -... | Line 51... | ||
- | 51 | }; |
|
- | 52 | ||
- | 53 | enum drm_mm_allocator_flags { |
|
- | 54 | DRM_MM_CREATE_DEFAULT = 0, |
|
- | 55 | DRM_MM_CREATE_TOP = 1 << 0, |
|
- | 56 | }; |
|
- | 57 | ||
- | 58 | #define DRM_MM_BOTTOMUP DRM_MM_SEARCH_DEFAULT, DRM_MM_CREATE_DEFAULT |
|
50 | }; |
59 | #define DRM_MM_TOPDOWN DRM_MM_SEARCH_BELOW, DRM_MM_CREATE_TOP |
51 | 60 | ||
52 | struct drm_mm_node { |
61 | struct drm_mm_node { |
53 | struct list_head node_list; |
62 | struct list_head node_list; |
54 | struct list_head hole_stack; |
63 | struct list_head hole_stack; |
Line 83... | Line 92... | ||
83 | 92 | ||
84 | void (*color_adjust)(struct drm_mm_node *node, unsigned long color, |
93 | void (*color_adjust)(struct drm_mm_node *node, unsigned long color, |
85 | unsigned long *start, unsigned long *end); |
94 | unsigned long *start, unsigned long *end); |
Line -... | Line 95... | ||
- | 95 | }; |
|
- | 96 | ||
- | 97 | /** |
|
- | 98 | * drm_mm_node_allocated - checks whether a node is allocated |
|
- | 99 | * @node: drm_mm_node to check |
|
- | 100 | * |
|
- | 101 | * Drivers should use this helpers for proper encapusulation of drm_mm |
|
- | 102 | * internals. |
|
- | 103 | * |
|
- | 104 | * Returns: |
|
86 | }; |
105 | * True if the @node is allocated. |
87 | 106 | */ |
|
88 | static inline bool drm_mm_node_allocated(struct drm_mm_node *node) |
107 | static inline bool drm_mm_node_allocated(struct drm_mm_node *node) |
89 | { |
108 | { |
Line -... | Line 109... | ||
- | 109 | return node->allocated; |
|
- | 110 | } |
|
- | 111 | ||
- | 112 | /** |
|
- | 113 | * drm_mm_initialized - checks whether an allocator is initialized |
|
- | 114 | * @mm: drm_mm to check |
|
- | 115 | * |
|
- | 116 | * Drivers should use this helpers for proper encapusulation of drm_mm |
|
- | 117 | * internals. |
|
- | 118 | * |
|
90 | return node->allocated; |
119 | * Returns: |
91 | } |
120 | * True if the @mm is initialized. |
92 | 121 | */ |
|
93 | static inline bool drm_mm_initialized(struct drm_mm *mm) |
122 | static inline bool drm_mm_initialized(struct drm_mm *mm) |
Line 94... | Line 123... | ||
94 | { |
123 | { |
95 | return mm->hole_stack.next; |
124 | return mm->hole_stack.next; |
96 | } |
125 | } |
97 | 126 | ||
Line -... | Line 127... | ||
- | 127 | static inline unsigned long __drm_mm_hole_node_start(struct drm_mm_node *hole_node) |
|
- | 128 | { |
|
- | 129 | return hole_node->start + hole_node->size; |
|
- | 130 | } |
|
- | 131 | ||
- | 132 | /** |
|
- | 133 | * drm_mm_hole_node_start - computes the start of the hole following @node |
|
- | 134 | * @hole_node: drm_mm_node which implicitly tracks the following hole |
|
- | 135 | * |
|
- | 136 | * This is useful for driver-sepific debug dumpers. Otherwise drivers should not |
|
- | 137 | * inspect holes themselves. Drivers must check first whether a hole indeed |
|
98 | static inline unsigned long __drm_mm_hole_node_start(struct drm_mm_node *hole_node) |
138 | * follows by looking at node->hole_follows. |
99 | { |
139 | * |
100 | return hole_node->start + hole_node->size; |
140 | * Returns: |
101 | } |
141 | * Start of the subsequent hole. |
102 | 142 | */ |
|
Line 110... | Line 150... | ||
110 | { |
150 | { |
111 | return list_entry(hole_node->node_list.next, |
151 | return list_entry(hole_node->node_list.next, |
112 | struct drm_mm_node, node_list)->start; |
152 | struct drm_mm_node, node_list)->start; |
113 | } |
153 | } |
Line -... | Line 154... | ||
- | 154 | ||
- | 155 | /** |
|
- | 156 | * drm_mm_hole_node_end - computes the end of the hole following @node |
|
- | 157 | * @hole_node: drm_mm_node which implicitly tracks the following hole |
|
- | 158 | * |
|
- | 159 | * This is useful for driver-sepific debug dumpers. Otherwise drivers should not |
|
- | 160 | * inspect holes themselves. Drivers must check first whether a hole indeed |
|
- | 161 | * follows by looking at node->hole_follows. |
|
- | 162 | * |
|
- | 163 | * Returns: |
|
- | 164 | * End of the subsequent hole. |
|
114 | 165 | */ |
|
115 | static inline unsigned long drm_mm_hole_node_end(struct drm_mm_node *hole_node) |
166 | static inline unsigned long drm_mm_hole_node_end(struct drm_mm_node *hole_node) |
116 | { |
167 | { |
117 | return __drm_mm_hole_node_end(hole_node); |
168 | return __drm_mm_hole_node_end(hole_node); |
Line -... | Line 169... | ||
- | 169 | } |
|
- | 170 | ||
- | 171 | /** |
|
- | 172 | * drm_mm_for_each_node - iterator to walk over all allocated nodes |
|
- | 173 | * @entry: drm_mm_node structure to assign to in each iteration step |
|
- | 174 | * @mm: drm_mm allocator to walk |
|
- | 175 | * |
|
- | 176 | * This iterator walks over all nodes in the range allocator. It is implemented |
|
118 | } |
177 | * with list_for_each, so not save against removal of elements. |
119 | 178 | */ |
|
120 | #define drm_mm_for_each_node(entry, mm) list_for_each_entry(entry, \ |
179 | #define drm_mm_for_each_node(entry, mm) list_for_each_entry(entry, \ |
Line -... | Line 180... | ||
- | 180 | &(mm)->head_node.node_list, \ |
|
- | 181 | node_list) |
|
- | 182 | ||
- | 183 | /** |
|
- | 184 | * drm_mm_for_each_hole - iterator to walk over all holes |
|
- | 185 | * @entry: drm_mm_node used internally to track progress |
|
- | 186 | * @mm: drm_mm allocator to walk |
|
- | 187 | * @hole_start: ulong variable to assign the hole start to on each iteration |
|
- | 188 | * @hole_end: ulong variable to assign the hole end to on each iteration |
|
- | 189 | * |
|
- | 190 | * This iterator walks over all holes in the range allocator. It is implemented |
|
- | 191 | * with list_for_each, so not save against removal of elements. @entry is used |
|
- | 192 | * internally and will not reflect a real drm_mm_node for the very first hole. |
|
121 | &(mm)->head_node.node_list, \ |
193 | * Hence users of this iterator may not access it. |
122 | node_list) |
194 | * |
- | 195 | * Implementation Note: |
|
- | 196 | * We need to inline list_for_each_entry in order to be able to set hole_start |
|
123 | 197 | * and hole_end on each iteration while keeping the macro sane. |
|
124 | /* Note that we need to unroll list_for_each_entry in order to inline |
198 | * |
125 | * setting hole_start and hole_end on each iteration and keep the |
199 | * The __drm_mm_for_each_hole version is similar, but with added support for |
126 | * macro sane. |
200 | * going backwards. |
127 | */ |
201 | */ |
128 | #define drm_mm_for_each_hole(entry, mm, hole_start, hole_end) \ |
202 | #define drm_mm_for_each_hole(entry, mm, hole_start, hole_end) \ |
129 | for (entry = list_entry((mm)->hole_stack.next, struct drm_mm_node, hole_stack); \ |
203 | for (entry = list_entry((mm)->hole_stack.next, struct drm_mm_node, hole_stack); \ |
130 | &entry->hole_stack != &(mm)->hole_stack ? \ |
204 | &entry->hole_stack != &(mm)->hole_stack ? \ |
131 | hole_start = drm_mm_hole_node_start(entry), \ |
205 | hole_start = drm_mm_hole_node_start(entry), \ |
Line -... | Line 206... | ||
- | 206 | hole_end = drm_mm_hole_node_end(entry), \ |
|
- | 207 | 1 : 0; \ |
|
- | 208 | entry = list_entry(entry->hole_stack.next, struct drm_mm_node, hole_stack)) |
|
- | 209 | ||
- | 210 | #define __drm_mm_for_each_hole(entry, mm, hole_start, hole_end, backwards) \ |
|
- | 211 | for (entry = list_entry((backwards) ? (mm)->hole_stack.prev : (mm)->hole_stack.next, struct drm_mm_node, hole_stack); \ |
|
- | 212 | &entry->hole_stack != &(mm)->hole_stack ? \ |
|
- | 213 | hole_start = drm_mm_hole_node_start(entry), \ |
|
132 | hole_end = drm_mm_hole_node_end(entry), \ |
214 | hole_end = drm_mm_hole_node_end(entry), \ |
133 | 1 : 0; \ |
215 | 1 : 0; \ |
134 | entry = list_entry(entry->hole_stack.next, struct drm_mm_node, hole_stack)) |
216 | entry = list_entry((backwards) ? entry->hole_stack.prev : entry->hole_stack.next, struct drm_mm_node, hole_stack)) |
135 | 217 | ||
Line 136... | Line 218... | ||
136 | /* |
218 | /* |
137 | * Basic range manager support (drm_mm.c) |
219 | * Basic range manager support (drm_mm.c) |
138 | */ |
220 | */ |
139 | extern int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node); |
221 | int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node); |
140 | 222 | ||
141 | extern int drm_mm_insert_node_generic(struct drm_mm *mm, |
223 | int drm_mm_insert_node_generic(struct drm_mm *mm, |
- | 224 | struct drm_mm_node *node, |
|
- | 225 | unsigned long size, |
|
- | 226 | unsigned alignment, |
|
- | 227 | unsigned long color, |
|
- | 228 | enum drm_mm_search_flags sflags, |
|
- | 229 | enum drm_mm_allocator_flags aflags); |
|
- | 230 | /** |
|
- | 231 | * drm_mm_insert_node - search for space and insert @node |
|
- | 232 | * @mm: drm_mm to allocate from |
|
- | 233 | * @node: preallocate node to insert |
|
- | 234 | * @size: size of the allocation |
|
- | 235 | * @alignment: alignment of the allocation |
|
- | 236 | * @flags: flags to fine-tune the allocation |
|
- | 237 | * |
|
- | 238 | * This is a simplified version of drm_mm_insert_node_generic() with @color set |
|
- | 239 | * to 0. |
|
- | 240 | * |
|
142 | struct drm_mm_node *node, |
241 | * The preallocated node must be cleared to 0. |
143 | unsigned long size, |
242 | * |
144 | unsigned alignment, |
243 | * Returns: |
145 | unsigned long color, |
244 | * 0 on success, -ENOSPC if there's no suitable hole. |
146 | enum drm_mm_search_flags flags); |
245 | */ |
147 | static inline int drm_mm_insert_node(struct drm_mm *mm, |
246 | static inline int drm_mm_insert_node(struct drm_mm *mm, |
148 | struct drm_mm_node *node, |
247 | struct drm_mm_node *node, |
- | 248 | unsigned long size, |
|
149 | unsigned long size, |
249 | unsigned alignment, |
Line 150... | Line 250... | ||
150 | unsigned alignment, |
250 | enum drm_mm_search_flags flags) |
151 | enum drm_mm_search_flags flags) |
251 | { |
152 | { |
252 | return drm_mm_insert_node_generic(mm, node, size, alignment, 0, flags, |
153 | return drm_mm_insert_node_generic(mm, node, size, alignment, 0, flags); |
253 | DRM_MM_CREATE_DEFAULT); |
154 | } |
254 | } |
155 | 255 | ||
156 | extern int drm_mm_insert_node_in_range_generic(struct drm_mm *mm, |
256 | int drm_mm_insert_node_in_range_generic(struct drm_mm *mm, |
157 | struct drm_mm_node *node, |
257 | struct drm_mm_node *node, |
- | 258 | unsigned long size, |
|
- | 259 | unsigned alignment, |
|
- | 260 | unsigned long color, |
|
- | 261 | unsigned long start, |
|
- | 262 | unsigned long end, |
|
- | 263 | enum drm_mm_search_flags sflags, |
|
- | 264 | enum drm_mm_allocator_flags aflags); |
|
- | 265 | /** |
|
- | 266 | * drm_mm_insert_node_in_range - ranged search for space and insert @node |
|
- | 267 | * @mm: drm_mm to allocate from |
|
- | 268 | * @node: preallocate node to insert |
|
- | 269 | * @size: size of the allocation |
|
- | 270 | * @alignment: alignment of the allocation |
|
- | 271 | * @start: start of the allowed range for this node |
|
- | 272 | * @end: end of the allowed range for this node |
|
- | 273 | * @flags: flags to fine-tune the allocation |
|
- | 274 | * |
|
- | 275 | * This is a simplified version of drm_mm_insert_node_in_range_generic() with |
|
- | 276 | * @color set to 0. |
|
158 | unsigned long size, |
277 | * |
159 | unsigned alignment, |
278 | * The preallocated node must be cleared to 0. |
160 | unsigned long color, |
279 | * |
161 | unsigned long start, |
280 | * Returns: |
162 | unsigned long end, |
281 | * 0 on success, -ENOSPC if there's no suitable hole. |
163 | enum drm_mm_search_flags flags); |
282 | */ |
164 | static inline int drm_mm_insert_node_in_range(struct drm_mm *mm, |
283 | static inline int drm_mm_insert_node_in_range(struct drm_mm *mm, |
165 | struct drm_mm_node *node, |
284 | struct drm_mm_node *node, |
166 | unsigned long size, |
285 | unsigned long size, |
167 | unsigned alignment, |
286 | unsigned alignment, |
- | 287 | unsigned long start, |
|
168 | unsigned long start, |
288 | unsigned long end, |
Line 169... | Line 289... | ||
169 | unsigned long end, |
289 | enum drm_mm_search_flags flags) |
170 | enum drm_mm_search_flags flags) |
290 | { |
171 | { |
291 | return drm_mm_insert_node_in_range_generic(mm, node, size, alignment, |
172 | return drm_mm_insert_node_in_range_generic(mm, node, size, alignment, |
292 | 0, start, end, flags, |
173 | 0, start, end, flags); |
293 | DRM_MM_CREATE_DEFAULT); |
174 | } |
294 | } |
175 | 295 | ||
Line 176... | Line 296... | ||
176 | extern void drm_mm_remove_node(struct drm_mm_node *node); |
296 | void drm_mm_remove_node(struct drm_mm_node *node); |
177 | extern void drm_mm_replace_node(struct drm_mm_node *old, struct drm_mm_node *new); |
297 | void drm_mm_replace_node(struct drm_mm_node *old, struct drm_mm_node *new); |
178 | extern void drm_mm_init(struct drm_mm *mm, |
298 | void drm_mm_init(struct drm_mm *mm, |
179 | unsigned long start, |
299 | unsigned long start, |
Line 189... | Line 309... | ||
189 | unsigned long size, |
309 | unsigned long size, |
190 | unsigned alignment, |
310 | unsigned alignment, |
191 | unsigned long color, |
311 | unsigned long color, |
192 | unsigned long start, |
312 | unsigned long start, |
193 | unsigned long end); |
313 | unsigned long end); |
194 | int drm_mm_scan_add_block(struct drm_mm_node *node); |
314 | bool drm_mm_scan_add_block(struct drm_mm_node *node); |
195 | int drm_mm_scan_remove_block(struct drm_mm_node *node); |
315 | bool drm_mm_scan_remove_block(struct drm_mm_node *node); |
Line 196... | Line 316... | ||
196 | 316 | ||
197 | extern void drm_mm_debug_table(struct drm_mm *mm, const char *prefix); |
317 | void drm_mm_debug_table(struct drm_mm *mm, const char *prefix); |
198 | #ifdef CONFIG_DEBUG_FS |
318 | #ifdef CONFIG_DEBUG_FS |
199 | int drm_mm_dump_table(struct seq_file *m, struct drm_mm *mm); |
319 | int drm_mm_dump_table(struct seq_file *m, struct drm_mm *mm); |
Line 200... | Line 320... | ||
200 | #endif |
320 | #endif |