XenevaOS
Loading...
Searching...
No Matches
drm_mm.h
Go to the documentation of this file.
1/**************************************************************************
2 *
3 * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX. USA.
4 * Copyright 2016 Intel Corporation
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 *
28 **************************************************************************/
29/*
30 * Authors:
31 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
32 */
33
34#ifndef _DRM_MM_H_
35#define _DRM_MM_H_
36
37/*
38 * Generic range manager structs
39 */
40#include <linux/bug.h>
41#include <linux/rbtree.h>
42#include <linux/limits.h>
43#include <linux/mm_types.h>
44#include <linux/list.h>
45#include <linux/spinlock.h>
46#include <linux/bitops.h> /* __ffs() and __set_bit() -- drm_mm.c:1887 and
47 * :478 spell both, and mainline's drm_mm.c
48 * gets them without naming this include: its
49 * slab.h/mm_types.h chain reaches bitops.h,
50 * where DCL's are slimmer and do not. Left to
51 * the caller it is an implicit declaration,
52 * which compiles as a warning and then fails
53 * to link. */
54#ifdef CONFIG_DRM_DEBUG_MM
55#include <linux/stackdepot.h>
56#endif
57#include <linux/types.h>
58
59struct drm_printer;
60
61#ifdef CONFIG_DRM_DEBUG_MM
62#define DRM_MM_BUG_ON(expr) BUG_ON(expr)
63#else
64#define DRM_MM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
65#endif
66
155
167 unsigned long color;
172 /* private: */
173 struct drm_mm *mm;
176 struct rb_node rb;
182 unsigned long flags;
183#define DRM_MM_NODE_ALLOCATED_BIT 0
184#define DRM_MM_NODE_SCANNED_BIT 1
185#ifdef CONFIG_DRM_DEBUG_MM
187#endif
188};
189
198struct drm_mm {
208 void (*color_adjust)(const struct drm_mm_node *node,
209 unsigned long color,
210 u64 *start, u64 *end);
211
212 /* private: */
213 /* List of all memory nodes that immediately precede a free hole. */
215 /* head_node.node_list is the list of all memory nodes, ordered
216 * according to the (increasing) start address of the memory node. */
218 /* Keep an interval_tree for fast lookup of drm_mm_nodes by address. */
222
223 unsigned long scan_active;
224};
225
252
266static inline bool drm_mm_node_allocated(const struct drm_mm_node *node)
267{
268 return test_bit(DRM_MM_NODE_ALLOCATED_BIT, &node->flags);
269}
270
284static inline bool drm_mm_initialized(const struct drm_mm *mm)
285{
286 return READ_ONCE(mm->hole_stack.next);
287}
288
301static inline bool drm_mm_hole_follows(const struct drm_mm_node *node)
302{
303 return node->hole_size;
304}
305
306static inline u64 __drm_mm_hole_node_start(const struct drm_mm_node *hole_node)
307{
308 return hole_node->start + hole_node->size;
309}
310
322static inline u64 drm_mm_hole_node_start(const struct drm_mm_node *hole_node)
323{
324 DRM_MM_BUG_ON(!drm_mm_hole_follows(hole_node));
325 return __drm_mm_hole_node_start(hole_node);
326}
327
328static inline u64 __drm_mm_hole_node_end(const struct drm_mm_node *hole_node)
329{
330 return list_next_entry(hole_node, node_list)->start;
331}
332
344static inline u64 drm_mm_hole_node_end(const struct drm_mm_node *hole_node)
345{
346 return __drm_mm_hole_node_end(hole_node);
347}
348
361#define drm_mm_nodes(mm) (&(mm)->head_node.node_list)
362
371#define drm_mm_for_each_node(entry, mm) \
372 list_for_each_entry(entry, drm_mm_nodes(mm), node_list)
373
383#define drm_mm_for_each_node_safe(entry, next, mm) \
384 list_for_each_entry_safe(entry, next, drm_mm_nodes(mm), node_list)
385
402#define drm_mm_for_each_hole(pos, mm, hole_start, hole_end) \
403 for (pos = list_first_entry(&(mm)->hole_stack, \
404 typeof(*pos), hole_stack); \
405 &pos->hole_stack != &(mm)->hole_stack ? \
406 hole_start = drm_mm_hole_node_start(pos), \
407 hole_end = hole_start + pos->hole_size, \
408 1 : 0; \
409 pos = list_next_entry(pos, hole_stack))
410
411/*
412 * Basic range manager support (drm_mm.c)
413 */
416 struct drm_mm_node *node,
417 u64 size,
418 u64 alignment,
419 unsigned long color,
420 u64 start,
421 u64 end,
423
441static inline int
442drm_mm_insert_node_generic(struct drm_mm *mm, struct drm_mm_node *node,
443 u64 size, u64 alignment,
444 unsigned long color,
446{
448 size, alignment, color,
449 0, U64_MAX, mode);
450}
451
466static inline int drm_mm_insert_node(struct drm_mm *mm,
467 struct drm_mm_node *node,
468 u64 size)
469{
470 return drm_mm_insert_node_generic(mm, node, size, 0, 0, 0);
471}
472
474void drm_mm_init(struct drm_mm *mm, u64 start, u64 size);
475void drm_mm_takedown(struct drm_mm *mm);
476
485static inline bool drm_mm_clean(const struct drm_mm *mm)
486{
487 return list_empty(drm_mm_nodes(mm));
488}
489
490struct drm_mm_node *
492
510#define drm_mm_for_each_node_in_range(node__, mm__, start__, end__) \
511 for (node__ = __drm_mm_interval_first((mm__), (start__), (end__)-1); \
512 node__->start < (end__); \
513 node__ = list_next_entry(node__, node_list))
514
516 struct drm_mm *mm,
517 u64 size, u64 alignment, unsigned long color,
518 u64 start, u64 end,
520
540static inline void drm_mm_scan_init(struct drm_mm_scan *scan,
541 struct drm_mm *mm,
542 u64 size,
543 u64 alignment,
544 unsigned long color,
546{
548 size, alignment, color,
549 0, U64_MAX, mode);
550}
551
553 struct drm_mm_node *node);
555 struct drm_mm_node *node);
557
558void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p);
559
560#endif
#define U64_MAX
Definition limits.h:25
#define list_next_entry(pos, member)
Definition list.h:27
#define BIT(nr)
Definition bitops.h:112
#define test_bit(nr, addr)
Definition bitops.h:124
size_t size
Definition drm_bridge.h:1299
void drm_mm_scan_init_with_range(struct drm_mm_scan *scan, struct drm_mm *mm, u64 size, u64 alignment, unsigned long color, u64 start, u64 end, enum drm_mm_insert_mode mode)
void drm_mm_takedown(struct drm_mm *mm)
#define drm_mm_nodes(mm)
Definition drm_mm.h:361
struct drm_mm_node * drm_mm_scan_color_evict(struct drm_mm_scan *scan)
#define DRM_MM_NODE_ALLOCATED_BIT
Definition drm_mm.h:183
bool drm_mm_scan_remove_block(struct drm_mm_scan *scan, struct drm_mm_node *node)
bool drm_mm_scan_add_block(struct drm_mm_scan *scan, struct drm_mm_node *node)
void drm_mm_remove_node(struct drm_mm_node *node)
drm_mm_insert_mode
Definition drm_mm.h:78
@ DRM_MM_INSERT_EVICT
Definition drm_mm.h:121
@ DRM_MM_INSERT_HIGH
Definition drm_mm.h:109
@ DRM_MM_INSERT_LOWEST
Definition drm_mm.h:153
@ DRM_MM_INSERT_BEST
Definition drm_mm.h:87
@ DRM_MM_INSERT_HIGHEST
Definition drm_mm.h:142
@ DRM_MM_INSERT_ONCE
Definition drm_mm.h:131
@ DRM_MM_INSERT_LOW
Definition drm_mm.h:97
struct drm_mm_node * __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last)
void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p)
int drm_mm_reserve_node(struct drm_mm *mm, struct drm_mm_node *node)
int drm_mm_insert_node_in_range(struct drm_mm *mm, struct drm_mm_node *node, u64 size, u64 alignment, unsigned long color, u64 start, u64 end, enum drm_mm_insert_mode mode)
void drm_mm_init(struct drm_mm *mm, u64 start, u64 size)
#define DRM_MM_BUG_ON(expr)
Definition drm_mm.h:64
void int node
Definition kthread.h:31
uint64_t u64
Definition kernel.h:17
#define READ_ONCE(x)
Definition kernel.h:605
char end[]
u32 depot_stack_handle_t
Definition stackdepot.h:15
Definition i_video.h:141
Definition drm_mm.h:165
struct list_head hole_stack
Definition drm_mm.h:175
u64 start
Definition drm_mm.h:169
struct rb_node rb_hole_size
Definition drm_mm.h:177
unsigned long color
Definition drm_mm.h:167
unsigned long flags
Definition drm_mm.h:182
struct rb_node rb
Definition drm_mm.h:176
u64 subtree_max_hole
Definition drm_mm.h:181
struct drm_mm * mm
Definition drm_mm.h:173
u64 hole_size
Definition drm_mm.h:180
u64 size
Definition drm_mm.h:171
struct rb_node rb_hole_addr
Definition drm_mm.h:178
struct list_head node_list
Definition drm_mm.h:174
u64 __subtree_last
Definition drm_mm.h:179
Definition drm_mm.h:235
u64 hit_start
Definition drm_mm.h:246
enum drm_mm_insert_mode mode
Definition drm_mm.h:250
u64 hit_end
Definition drm_mm.h:247
u64 range_start
Definition drm_mm.h:243
u64 alignment
Definition drm_mm.h:240
struct drm_mm * mm
Definition drm_mm.h:237
unsigned long color
Definition drm_mm.h:249
u64 size
Definition drm_mm.h:239
u64 remainder_mask
Definition drm_mm.h:241
u64 range_end
Definition drm_mm.h:244
Definition drm_mm.h:198
struct list_head hole_stack
Definition drm_mm.h:214
struct rb_root holes_addr
Definition drm_mm.h:221
struct drm_mm_node head_node
Definition drm_mm.h:217
void(* color_adjust)(const struct drm_mm_node *node, unsigned long color, u64 *start, u64 *end)
Definition drm_mm.h:208
struct rb_root_cached interval_tree
Definition drm_mm.h:219
unsigned long scan_active
Definition drm_mm.h:223
struct rb_root_cached holes_size
Definition drm_mm.h:220
Definition drm_print.h:181
Definition list.h:11
struct list_head * next
Definition list.h:12
Definition rbtree_types.h:21
Definition rbtree_types.h:48
Definition rbtree_types.h:34
#define mode(x)
TTY * last
Definition tty.cpp:48