diff options
author | Deepak Nibade <dnibade@nvidia.com> | 2017-02-10 07:00:41 -0500 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-03-31 14:34:24 -0400 |
commit | c8c1d02261521b5361a9a0daf28238740edc316d (patch) | |
tree | ed665657e6fcd51706682e7dc8f3563fc0192014 /drivers/gpu | |
parent | 5032125551dbd511303a3803c75bab8616e22918 (diff) |
gpu: nvgpu: implement own list APIs
Add nvgpu's own implementation of List APIs
This implementation is needed to remove nvgpu's
dependency on Linux specific list implementation
Define a list node as
struct nvgpu_list_node *node;
Define below common APIs:
nvgpu_init_list_node() - initialize list node
nvgpu_list_add() - add new node to list
nvgpu_list_add_tail() - add new node to end of list
nvgpu_list_del() - delete node from list
nvgpu_list_empty() - check if list is empty
Define below macros to simplify access to list:
nvgpu_list_entry() - convert list node to parent
nvgpu_list_next_entry() - find next entry in list
nvgpu_list_first_entry() - first entry in list
nvgpu_list_for_each_entry() - iterator for list
nvgpu_list_for_each_entry_safe() - deletion safe iterator
Jira NVGPU-13
Change-Id: Icb1d27857148e96b2c6dfa3c2bd50fcff9f896cf
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/1303024
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-by: Sami Kiminki <skiminki@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-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 */ | ||