tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_osk_list.h
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 /**
12  * @file mali_osk_list.h
13  * Implementation of the OS abstraction layer for the kernel device driver
14  */
15
16 #ifndef __MALI_OSK_LIST_H__
17 #define __MALI_OSK_LIST_H__
18
19 #include "mali_kernel_common.h"
20
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif
25
26 MALI_STATIC_INLINE void __mali_osk_list_add(_mali_osk_list_t *new_entry, _mali_osk_list_t *prev, _mali_osk_list_t *next)
27 {
28     next->prev = new_entry;
29     new_entry->next = next;
30     new_entry->prev = prev;
31     prev->next = new_entry;
32 }
33
34 MALI_STATIC_INLINE void __mali_osk_list_del(_mali_osk_list_t *prev, _mali_osk_list_t *next)
35 {
36     next->prev = prev;
37     prev->next = next;
38 }
39
40 /** @addtogroup _mali_osk_list
41  * @{ */
42
43 /** Reference implementations of Doubly-linked Circular Lists are provided.
44  * There is often no need to re-implement these.
45  *
46  * @note The implementation may differ subtly from any lists the OS provides.
47  * For this reason, these lists should not be mixed with OS-specific lists
48  * inside the OSK/UKK implementation. */
49
50 /** @brief Initialize a list element.
51  *
52  * All list elements must be initialized before use.
53  *
54  * Do not use on any list element that is present in a list without using
55  * _mali_osk_list_del first, otherwise this will break the list.
56  *
57  * @param list the list element to initialize
58  */
59 MALI_STATIC_INLINE void _mali_osk_list_init( _mali_osk_list_t *list )
60 {
61     list->next = list;
62     list->prev = list;
63 }
64
65 /** @brief Insert a single list element after an entry in a list
66  *
67  * As an example, if this is inserted to the head of a list, then this becomes
68  * the first element of the list.
69  *
70  * Do not use to move list elements from one list to another, as it will break
71  * the originating list.
72  *
73  *
74  * @param newlist the list element to insert
75  * @param list the list in which to insert. The new element will be the next
76  * entry in this list
77  */
78 MALI_STATIC_INLINE void _mali_osk_list_add( _mali_osk_list_t *new_entry, _mali_osk_list_t *list )
79 {
80     __mali_osk_list_add(new_entry, list, list->next);
81 }
82
83 /** @brief Insert a single list element before an entry in a list
84  *
85  * As an example, if this is inserted to the head of a list, then this becomes
86  * the last element of the list.
87  *
88  * Do not use to move list elements from one list to another, as it will break
89  * the originating list.
90  *
91  * @param newlist the list element to insert
92  * @param list the list in which to insert. The new element will be the previous
93  * entry in this list
94  */
95 MALI_STATIC_INLINE void _mali_osk_list_addtail( _mali_osk_list_t *new_entry, _mali_osk_list_t *list )
96 {
97     __mali_osk_list_add(new_entry, list->prev, list);
98 }
99
100 /** @brief Remove a single element from a list
101  *
102  * The element will no longer be present in the list. The removed list element
103  * will be uninitialized, and so should not be traversed. It must be
104  * initialized before further use.
105  *
106  * @param list the list element to remove.
107  */
108 MALI_STATIC_INLINE void _mali_osk_list_del( _mali_osk_list_t *list )
109 {
110     __mali_osk_list_del(list->prev, list->next);
111 }
112
113 /** @brief Remove a single element from a list, and re-initialize it
114  *
115  * The element will no longer be present in the list. The removed list element
116  * will initialized, and so can be used as normal.
117  *
118  * @param list the list element to remove and initialize.
119  */
120 MALI_STATIC_INLINE void _mali_osk_list_delinit( _mali_osk_list_t *list )
121 {
122     __mali_osk_list_del(list->prev, list->next);
123     _mali_osk_list_init(list);
124 }
125
126 /** @brief Determine whether a list is empty.
127  *
128  * An empty list is one that contains a single element that points to itself.
129  *
130  * @param list the list to check.
131  * @return non-zero if the list is empty, and zero otherwise.
132  */
133 MALI_STATIC_INLINE mali_bool _mali_osk_list_empty( _mali_osk_list_t *list )
134 {
135     return list->next == list;
136 }
137
138 /** @brief Move a list element from one list to another.
139  *
140  * The list element must be initialized.
141  *
142  * As an example, moving a list item to the head of a new list causes this item
143  * to be the first element in the new list.
144  *
145  * @param move the list element to move
146  * @param list the new list into which the element will be inserted, as the next
147  * element in the list.
148  */
149 MALI_STATIC_INLINE void _mali_osk_list_move( _mali_osk_list_t *move_entry, _mali_osk_list_t *list )
150 {
151     __mali_osk_list_del(move_entry->prev, move_entry->next);
152     _mali_osk_list_add(move_entry, list);
153 }
154
155 /** @brief Move an entire list
156  *
157  * The list element must be initialized.
158  *
159  * Allows you to move a list from one list head to another list head
160  *
161  * @param old_list The existing list head
162  * @param new_list The new list head (must be an empty list)
163  */
164 MALI_STATIC_INLINE void _mali_osk_list_move_list( _mali_osk_list_t *old_list, _mali_osk_list_t *new_list )
165 {
166         MALI_DEBUG_ASSERT(_mali_osk_list_empty(new_list));
167         if (!_mali_osk_list_empty(old_list))
168         {
169                 new_list->next = old_list->next;
170                 new_list->prev = old_list->prev;
171                 new_list->next->prev = new_list;
172                 new_list->prev->next = new_list;
173                 old_list->next = old_list;
174                 old_list->prev = old_list;
175         }
176 }
177 /** @} */ /* end group _mali_osk_list */
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* __MALI_OSK_LIST_H__ */