2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
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.
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.
12 * @file mali_osk_list.h
13 * Implementation of the OS abstraction layer for the kernel device driver
16 #ifndef __MALI_OSK_LIST_H__
17 #define __MALI_OSK_LIST_H__
19 #include "mali_kernel_common.h"
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)
28 next->prev = new_entry;
29 new_entry->next = next;
30 new_entry->prev = prev;
31 prev->next = new_entry;
34 MALI_STATIC_INLINE void __mali_osk_list_del(_mali_osk_list_t *prev, _mali_osk_list_t *next)
40 /** @addtogroup _mali_osk_list
43 /** Reference implementations of Doubly-linked Circular Lists are provided.
44 * There is often no need to re-implement these.
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. */
50 /** @brief Initialize a list element.
52 * All list elements must be initialized before use.
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.
57 * @param list the list element to initialize
59 MALI_STATIC_INLINE void _mali_osk_list_init( _mali_osk_list_t *list )
65 /** @brief Insert a single list element after an entry in a list
67 * As an example, if this is inserted to the head of a list, then this becomes
68 * the first element of the list.
70 * Do not use to move list elements from one list to another, as it will break
71 * the originating list.
74 * @param newlist the list element to insert
75 * @param list the list in which to insert. The new element will be the next
78 MALI_STATIC_INLINE void _mali_osk_list_add( _mali_osk_list_t *new_entry, _mali_osk_list_t *list )
80 __mali_osk_list_add(new_entry, list, list->next);
83 /** @brief Insert a single list element before an entry in a list
85 * As an example, if this is inserted to the head of a list, then this becomes
86 * the last element of the list.
88 * Do not use to move list elements from one list to another, as it will break
89 * the originating list.
91 * @param newlist the list element to insert
92 * @param list the list in which to insert. The new element will be the previous
95 MALI_STATIC_INLINE void _mali_osk_list_addtail( _mali_osk_list_t *new_entry, _mali_osk_list_t *list )
97 __mali_osk_list_add(new_entry, list->prev, list);
100 /** @brief Remove a single element from a list
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.
106 * @param list the list element to remove.
108 MALI_STATIC_INLINE void _mali_osk_list_del( _mali_osk_list_t *list )
110 __mali_osk_list_del(list->prev, list->next);
113 /** @brief Remove a single element from a list, and re-initialize it
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.
118 * @param list the list element to remove and initialize.
120 MALI_STATIC_INLINE void _mali_osk_list_delinit( _mali_osk_list_t *list )
122 __mali_osk_list_del(list->prev, list->next);
123 _mali_osk_list_init(list);
126 /** @brief Determine whether a list is empty.
128 * An empty list is one that contains a single element that points to itself.
130 * @param list the list to check.
131 * @return non-zero if the list is empty, and zero otherwise.
133 MALI_STATIC_INLINE mali_bool _mali_osk_list_empty( _mali_osk_list_t *list )
135 return list->next == list;
138 /** @brief Move a list element from one list to another.
140 * The list element must be initialized.
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.
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.
149 MALI_STATIC_INLINE void _mali_osk_list_move( _mali_osk_list_t *move_entry, _mali_osk_list_t *list )
151 __mali_osk_list_del(move_entry->prev, move_entry->next);
152 _mali_osk_list_add(move_entry, list);
155 /** @brief Move an entire list
157 * The list element must be initialized.
159 * Allows you to move a list from one list head to another list head
161 * @param old_list The existing list head
162 * @param new_list The new list head (must be an empty list)
164 MALI_STATIC_INLINE void _mali_osk_list_move_list( _mali_osk_list_t *old_list, _mali_osk_list_t *new_list )
166 MALI_DEBUG_ASSERT(_mali_osk_list_empty(new_list));
167 if (!_mali_osk_list_empty(old_list))
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;
177 /** @} */ /* end group _mali_osk_list */
183 #endif /* __MALI_OSK_LIST_H__ */