diff options
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/list.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/list.h b/drivers/gpu/nvgpu/include/nvgpu/list.h new file mode 100644 index 00000000..c8d2b37a --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/list.h | |||
@@ -0,0 +1,79 @@ | |||
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_LIST_H | ||
18 | #define NVGPU_LIST_H | ||
19 | |||
20 | struct nvgpu_list_node { | ||
21 | struct nvgpu_list_node *prev; | ||
22 | struct nvgpu_list_node *next; | ||
23 | }; | ||
24 | |||
25 | static inline void nvgpu_init_list_node(struct nvgpu_list_node *node) | ||
26 | { | ||
27 | node->prev = node; | ||
28 | node->next = node; | ||
29 | } | ||
30 | |||
31 | static inline void nvgpu_list_add(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head) | ||
32 | { | ||
33 | new_node->next = head->next; | ||
34 | new_node->next->prev = new_node; | ||
35 | new_node->prev = head; | ||
36 | head->next = new_node; | ||
37 | } | ||
38 | |||
39 | static inline void nvgpu_list_add_tail(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head) | ||
40 | { | ||
41 | new_node->prev = head->prev; | ||
42 | new_node->prev->next = new_node; | ||
43 | new_node->next = head; | ||
44 | head->prev = new_node; | ||
45 | } | ||
46 | |||
47 | static inline void nvgpu_list_del(struct nvgpu_list_node *node) | ||
48 | { | ||
49 | node->prev->next = node->next; | ||
50 | node->next->prev = node->prev; | ||
51 | nvgpu_init_list_node(node); | ||
52 | } | ||
53 | |||
54 | static inline int nvgpu_list_empty(struct nvgpu_list_node *head) | ||
55 | { | ||
56 | return head->next == head; | ||
57 | } | ||
58 | |||
59 | #define nvgpu_list_entry(ptr, type, member) \ | ||
60 | type ## _from_ ## member(ptr) | ||
61 | |||
62 | #define nvgpu_list_next_entry(pos, type, member) \ | ||
63 | nvgpu_list_entry((pos)->member.next, type, member) | ||
64 | |||
65 | #define nvgpu_list_first_entry(ptr, type, member) \ | ||
66 | nvgpu_list_entry((ptr)->next, type, member) | ||
67 | |||
68 | #define nvgpu_list_for_each_entry(pos, head, type, member) \ | ||
69 | for (pos = nvgpu_list_first_entry(head, type, member); \ | ||
70 | &pos->member != (head); \ | ||
71 | pos = nvgpu_list_next_entry(pos, type, member)) | ||
72 | |||
73 | #define nvgpu_list_for_each_entry_safe(pos, n, head, type, member) \ | ||
74 | for (pos = nvgpu_list_first_entry(head, type, member), \ | ||
75 | n = nvgpu_list_next_entry(pos, type, member); \ | ||
76 | &pos->member != (head); \ | ||
77 | pos = n, n = nvgpu_list_next_entry(n, type, member)) | ||
78 | |||
79 | #endif /* NVGPU_LIST_H */ | ||