RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / services / shared / include / dllist.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          Double linked list header
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Double linked list interface
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #ifndef _DLLIST_
45 #define _DLLIST_
46
47 #include "img_types.h"
48
49 /*!
50         Pointer to a linked list node
51 */
52 typedef struct _DLLIST_NODE_    *PDLLIST_NODE;
53
54
55 /*!
56         Node in a linked list
57 */
58 /*
59  * Note: the following structure's size is architecture-dependent and
60  * clients may need to create a mirror the structure definition if it needs
61  * to be used in a structure shared between host and device. Consider such
62  * clients if any changes are made to this structure.
63  */ 
64 typedef struct _DLLIST_NODE_
65 {
66         struct _DLLIST_NODE_    *psPrevNode;
67         struct _DLLIST_NODE_    *psNextNode;
68 } DLLIST_NODE;
69
70
71 /*!
72         Static initialiser
73 */
74 #define DECLARE_DLLIST(n) \
75 DLLIST_NODE n = {&n, &n}
76
77
78 /*************************************************************************/ /*!
79 @Function       dllist_init
80
81 @Description    Initialize a new double linked list
82
83 @Input          psListHead              List head Node
84
85 */
86 /*****************************************************************************/
87 static INLINE
88 IMG_VOID dllist_init(PDLLIST_NODE psListHead)
89 {
90         psListHead->psPrevNode = psListHead;
91         psListHead->psNextNode = psListHead;
92 }
93
94
95 /*************************************************************************/ /*!
96 @Function       dllist_is_empty
97
98 @Description    Returns whether the list is empty
99
100 @Input          psListHead              List head Node
101
102 */
103 /*****************************************************************************/
104 static INLINE
105 IMG_BOOL dllist_is_empty(PDLLIST_NODE psListHead)
106 {
107         return ((psListHead->psPrevNode == psListHead) 
108                                 && (psListHead->psNextNode == psListHead));
109 }
110
111
112 /*************************************************************************/ /*!
113 @Function       dllist_add_to_head
114
115 @Description    Add psNewNode to head of list psListHead
116
117 @Input          psListHead             Head Node
118 @Input          psNewNode              New Node
119
120 */
121 /*****************************************************************************/
122 static INLINE
123 IMG_VOID dllist_add_to_head(PDLLIST_NODE psListHead, PDLLIST_NODE psNewNode)
124 {
125         PDLLIST_NODE psTmp;
126
127         psTmp = psListHead->psNextNode;
128
129         psListHead->psNextNode = psNewNode;
130         psNewNode->psNextNode = psTmp;
131
132         psTmp->psPrevNode = psNewNode;
133         psNewNode->psPrevNode = psListHead;
134 }
135
136
137 /*************************************************************************/ /*!
138 @Function       dllist_add_to_tail
139
140 @Description    Add psNewNode to tail of list psListHead
141
142 @Input          psListHead             Head Node
143 @Input          psNewNode              New Node
144
145 */
146 /*****************************************************************************/
147 static INLINE
148 IMG_VOID dllist_add_to_tail(PDLLIST_NODE psListHead, PDLLIST_NODE psNewNode)
149 {
150         PDLLIST_NODE psTmp;
151
152         psTmp = psListHead->psPrevNode;
153
154         psListHead->psPrevNode = psNewNode;
155         psNewNode->psPrevNode = psTmp;
156
157         psTmp->psNextNode = psNewNode;
158         psNewNode->psNextNode = psListHead;
159 }
160
161
162 /*************************************************************************/ /*!
163 @Function       dllist_node_is_in_list
164
165 @Description    Returns IMG_TRUE if psNode is in a list 
166
167 @Input          psNode             List node
168
169 */
170 /*****************************************************************************/
171 static INLINE
172 IMG_BOOL dllist_node_is_in_list(PDLLIST_NODE psNode)
173 {
174         return (psNode->psNextNode != 0);
175 }
176
177
178 /*************************************************************************/ /*!
179 @Function       dllist_get_next_node
180
181 @Description    Returns the list node after psListHead or IMG_NULL psListHead
182                                 is the only element in the list.
183
184 @Input          psListHead             List node to start the operation
185
186 */
187 /*****************************************************************************/
188 static INLINE
189 PDLLIST_NODE dllist_get_next_node(PDLLIST_NODE psListHead)
190 {
191         if (psListHead->psNextNode == psListHead)
192         {
193                 return IMG_NULL;
194         }
195         else
196         {
197                 return psListHead->psNextNode;
198         }
199
200
201
202 /*************************************************************************/ /*!
203 @Function       dllist_remove_node
204
205 @Description    Removes psListNode from the list where it currently belongs
206
207 @Input          psListNode             List node to be removed
208
209 */
210 /*****************************************************************************/
211 static INLINE
212 IMG_VOID dllist_remove_node(PDLLIST_NODE psListNode)
213 {
214         psListNode->psNextNode->psPrevNode = psListNode->psPrevNode;
215         psListNode->psPrevNode->psNextNode = psListNode->psNextNode;
216
217         /* Clear the node to show it's not on a list */
218         psListNode->psPrevNode = 0;
219         psListNode->psNextNode = 0;
220 }
221
222
223 /*!
224         Callback function called on each element of the list
225 */
226 typedef IMG_BOOL (*PFN_NODE_CALLBACK)(PDLLIST_NODE psNode, IMG_PVOID pvCallbackData);
227
228
229 /*************************************************************************/ /*!
230 @Function       dllist_foreach_node
231
232 @Description    Walk through all the nodes on the list until the 
233                                 end or a callback returns FALSE
234
235 @Input          psListHead                      List node to start the operation
236 @Input                  pfnCallBack                     PFN_NODE_CALLBACK function called on each element       
237 @Input                  pvCallbackData          Data passed to pfnCallBack alongside the current Node
238
239 */
240 /*****************************************************************************/
241 IMG_INTERNAL
242 IMG_VOID dllist_foreach_node(PDLLIST_NODE psListHead,
243                                                           PFN_NODE_CALLBACK pfnCallBack,
244                                                           IMG_PVOID pvCallbackData);
245
246
247 #endif  /* _DLLIST_ */
248