diff options
author | Deepak Nibade <dnibade@nvidia.com> | 2017-03-30 05:10:09 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-04-06 13:57:22 -0400 |
commit | 6dda47a114d1ecbef4f5fa77e8100d795ee23ff1 (patch) | |
tree | 87c3fecc7e473dc669256fab16cbf0dba765a995 /drivers/gpu/nvgpu/include | |
parent | 335b3fa2fe89de3ae37d01a8e9605dc74554f777 (diff) |
gpu: nvgpu: add rbtree implementation
In order to remove nvgpu's dependency from Linux,
add nvgpu's own rbtree implementation
Define a rbtree node as
struct nvgpu_rbtree_node *node;
Add below APIs to support rbtree operations
nvgpu_rbtree_insert()
- insert a new node into tree
nvgpu_rbtree_unlink()
- remove a node from tree
nvgpu_rbtree_search()
- search a key in tree
nvgpu_rbtree_range_search()
- search a node with key falling in range
nvgpu_rbtree_less_than_search()
- search a node with key lesser than given key
nvgpu_rbtree_enum_start()
- start enumerating a tree
nvgpu_rbtree_enum_next()
- find next node in enumeration
Jira NVGPU-13
Change-Id: Idceb375dc20d9411799c92608b0264e59886bf68
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/1331537
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/rbtree.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/rbtree.h b/drivers/gpu/nvgpu/include/nvgpu/rbtree.h new file mode 100644 index 00000000..c29957c2 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/rbtree.h | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef __NVGPU_RBTREE_H__ | ||
18 | #define __NVGPU_RBTREE_H__ | ||
19 | |||
20 | #include <nvgpu/types.h> | ||
21 | |||
22 | struct nvgpu_rbtree_node { | ||
23 | u64 key_start; | ||
24 | u64 key_end; | ||
25 | |||
26 | bool is_red; /* !IsRed == IsBlack */ | ||
27 | |||
28 | struct nvgpu_rbtree_node *parent; | ||
29 | struct nvgpu_rbtree_node *left; | ||
30 | struct nvgpu_rbtree_node *right; | ||
31 | }; | ||
32 | |||
33 | /** | ||
34 | * nvgpu_rbtree_insert - insert a new node into rbtree | ||
35 | * | ||
36 | * @new_node Pointer to new node. | ||
37 | * @root Pointer to root of tree | ||
38 | * | ||
39 | * Nodes with duplicate key_start and overlapping ranges | ||
40 | * are not allowed | ||
41 | */ | ||
42 | void nvgpu_rbtree_insert(struct nvgpu_rbtree_node *new_node, | ||
43 | struct nvgpu_rbtree_node **root); | ||
44 | |||
45 | /** | ||
46 | * nvgpu_rbtree_unlink - delete a node from rbtree | ||
47 | * | ||
48 | * @node Pointer to node to be deleted | ||
49 | * @root Pointer to root of tree | ||
50 | */ | ||
51 | void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, | ||
52 | struct nvgpu_rbtree_node **root); | ||
53 | |||
54 | /** | ||
55 | * nvgpu_rbtree_search - search a given key in rbtree | ||
56 | * | ||
57 | * @key_start Key to be searched in rbtree | ||
58 | * @node Node pointer to be returned | ||
59 | * @root Pointer to root of tree | ||
60 | * | ||
61 | * This API will match given key against key_start of each node | ||
62 | * In case of a hit, node points to a node with given key | ||
63 | * In case of a miss, node is NULL | ||
64 | */ | ||
65 | void nvgpu_rbtree_search(u64 key_start, struct nvgpu_rbtree_node **node, | ||
66 | struct nvgpu_rbtree_node *root); | ||
67 | |||
68 | /** | ||
69 | * nvgpu_rbtree_range_search - search a node with key falling in range | ||
70 | * | ||
71 | * @key Key to be searched in rbtree | ||
72 | * @node Node pointer to be returned | ||
73 | * @root Pointer to root of tree | ||
74 | * | ||
75 | * This API will match given key and find a node where key value | ||
76 | * falls within range of {start, end} keys | ||
77 | * In case of a hit, node points to a node with given key | ||
78 | * In case of a miss, node is NULL | ||
79 | */ | ||
80 | void nvgpu_rbtree_range_search(u64 key, | ||
81 | struct nvgpu_rbtree_node **node, | ||
82 | struct nvgpu_rbtree_node *root); | ||
83 | |||
84 | /** | ||
85 | * nvgpu_rbtree_less_than_search - search a node with key lesser than given key | ||
86 | * | ||
87 | * @key_start Key to be searched in rbtree | ||
88 | * @node Node pointer to be returned | ||
89 | * @root Pointer to root of tree | ||
90 | * | ||
91 | * This API will match given key and find a node with highest | ||
92 | * key value lesser than given key | ||
93 | * In case of a hit, node points to a node with given key | ||
94 | * In case of a miss, node is NULL | ||
95 | */ | ||
96 | void nvgpu_rbtree_less_than_search(u64 key_start, | ||
97 | struct nvgpu_rbtree_node **node, | ||
98 | struct nvgpu_rbtree_node *root); | ||
99 | |||
100 | /** | ||
101 | * nvgpu_rbtree_enum_start - enumerate tree starting at the node with specified value | ||
102 | * | ||
103 | * @key_start Key value to begin enumeration from | ||
104 | * @node Pointer to first node in the tree | ||
105 | * @root Pointer to root of tree | ||
106 | * | ||
107 | * This API returns node pointer pointing to first node in the rbtree | ||
108 | */ | ||
109 | void nvgpu_rbtree_enum_start(u64 key_start, | ||
110 | struct nvgpu_rbtree_node **node, | ||
111 | struct nvgpu_rbtree_node *root); | ||
112 | |||
113 | /** | ||
114 | * nvgpu_rbtree_enum_next - find next node in enumeration | ||
115 | * | ||
116 | * @node Pointer to next node in the tree | ||
117 | * @root Pointer to root of tree | ||
118 | * | ||
119 | * This API returns node pointer pointing to next node in the rbtree | ||
120 | */ | ||
121 | void nvgpu_rbtree_enum_next(struct nvgpu_rbtree_node **node, | ||
122 | struct nvgpu_rbtree_node *root); | ||
123 | |||
124 | #endif /* __NVGPU_RBTREE_H__ */ | ||