diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/bitmap_allocator_priv.h')
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/bitmap_allocator_priv.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator_priv.h b/drivers/gpu/nvgpu/common/mm/bitmap_allocator_priv.h new file mode 100644 index 00000000..1750447d --- /dev/null +++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator_priv.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #ifndef BITMAP_ALLOCATOR_PRIV_H | ||
24 | #define BITMAP_ALLOCATOR_PRIV_H | ||
25 | |||
26 | |||
27 | #include <nvgpu/rbtree.h> | ||
28 | #include <nvgpu/kmem.h> | ||
29 | |||
30 | struct nvgpu_allocator; | ||
31 | |||
32 | struct nvgpu_bitmap_allocator { | ||
33 | struct nvgpu_allocator *owner; | ||
34 | |||
35 | u64 base; /* Base address of the space. */ | ||
36 | u64 length; /* Length of the space. */ | ||
37 | u64 blk_size; /* Size that corresponds to 1 bit. */ | ||
38 | u64 blk_shift; /* Bit shift to divide by blk_size. */ | ||
39 | u64 num_bits; /* Number of allocatable bits. */ | ||
40 | u64 bit_offs; /* Offset of bitmap. */ | ||
41 | |||
42 | /* | ||
43 | * Optimization for making repeated allocations faster. Keep track of | ||
44 | * the next bit after the most recent allocation. This is where the next | ||
45 | * search will start from. This should make allocation faster in cases | ||
46 | * where lots of allocations get made one after another. It shouldn't | ||
47 | * have a negative impact on the case where the allocator is fragmented. | ||
48 | */ | ||
49 | u64 next_blk; | ||
50 | |||
51 | unsigned long *bitmap; /* The actual bitmap! */ | ||
52 | struct nvgpu_rbtree_node *allocs; /* Tree of outstanding allocations */ | ||
53 | |||
54 | struct nvgpu_kmem_cache *meta_data_cache; | ||
55 | |||
56 | u64 flags; | ||
57 | |||
58 | bool inited; | ||
59 | |||
60 | /* Statistics */ | ||
61 | u64 nr_allocs; | ||
62 | u64 nr_fixed_allocs; | ||
63 | u64 bytes_alloced; | ||
64 | u64 bytes_freed; | ||
65 | }; | ||
66 | |||
67 | struct nvgpu_bitmap_alloc { | ||
68 | u64 base; | ||
69 | u64 length; | ||
70 | struct nvgpu_rbtree_node alloc_entry; /* RB tree of allocations. */ | ||
71 | }; | ||
72 | |||
73 | static inline struct nvgpu_bitmap_alloc * | ||
74 | nvgpu_bitmap_alloc_from_rbtree_node(struct nvgpu_rbtree_node *node) | ||
75 | { | ||
76 | return (struct nvgpu_bitmap_alloc *) | ||
77 | ((uintptr_t)node - offsetof(struct nvgpu_bitmap_alloc, alloc_entry)); | ||
78 | }; | ||
79 | |||
80 | static inline struct nvgpu_bitmap_allocator *bitmap_allocator( | ||
81 | struct nvgpu_allocator *a) | ||
82 | { | ||
83 | return (struct nvgpu_bitmap_allocator *)(a)->priv; | ||
84 | } | ||
85 | |||
86 | |||
87 | #endif | ||