4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Declarations of list management control structures and definitions
7 * of inline list management functions.
9 * Copyright (C) 2008 Texas Instruments, Inc.
11 * This package is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <dspbridge/host_os.h>
24 #include <linux/list.h>
26 #define LST_IS_EMPTY(l) list_empty(&(l)->head)
29 struct list_head head;
33 * ======== lst_first ========
35 * Returns a pointer to the first element of the list, or NULL if the list
38 * lst: Pointer to list control structure.
40 * Pointer to first list element, or NULL.
46 static inline struct list_head *lst_first(struct lst_list *lst)
48 if (lst && !list_empty(&lst->head))
49 return lst->head.next;
54 * ======== lst_get_head ========
56 * Pops the head off the list and returns a pointer to it.
58 * If the list is empty, returns NULL.
59 * Else, removes the element at the head of the list, making the next
60 * element the head of the list.
61 * The head is removed by making the tail element of the list point its
62 * "next" pointer at the next element after the head, and by making the
63 * "prev" pointer of the next element after the head point at the tail
64 * element. So the next element after the head becomes the new head of
67 * lst: Pointer to list control structure of list whose head
68 * element is to be removed
70 * Pointer to element that was at the head of the list (success)
71 * NULL No elements in list
77 * Because the tail of the list points forward (its "next" pointer) to
78 * the head of the list, and the head of the list points backward (its
79 * "prev" pointer) to the tail of the list, this list is circular.
81 static inline struct list_head *lst_get_head(struct lst_list *lst)
83 struct list_head *elem_list;
85 if (!lst || list_empty(&lst->head))
88 elem_list = lst->head.next;
89 lst->head.next = elem_list->next;
90 elem_list->next->prev = &lst->head;
96 * ======== lst_init_elem ========
98 * Initializes a list element to default (cleared) values
101 * elem_list: Pointer to list element to be reset
107 * This function must not be called to "reset" an element in the middle
108 * of a list chain -- that would break the chain.
111 static inline void lst_init_elem(struct list_head *elem_list)
114 elem_list->next = NULL;
115 elem_list->prev = NULL;
120 * ======== lst_insert_before ========
122 * Insert the element before the existing element.
124 * lst: Pointer to list control structure.
125 * elem_list: Pointer to element in list to insert.
126 * elem_existing: Pointer to existing list element.
131 * - elem_list != NULL.
132 * - elem_existing != NULL.
135 static inline void lst_insert_before(struct lst_list *lst,
136 struct list_head *elem_list,
137 struct list_head *elem_existing)
139 if (lst && elem_list && elem_existing)
140 list_add_tail(elem_list, elem_existing);
144 * ======== lst_next ========
146 * Returns a pointer to the next element of the list, or NULL if the next
147 * element is the head of the list or the list is empty.
149 * lst: Pointer to list control structure.
150 * cur_elem: Pointer to element in list to remove.
152 * Pointer to list element, or NULL.
156 * - cur_elem != NULL.
159 static inline struct list_head *lst_next(struct lst_list *lst,
160 struct list_head *cur_elem)
162 if (lst && !list_empty(&lst->head) && cur_elem &&
163 (cur_elem->next != &lst->head))
164 return cur_elem->next;
169 * ======== lst_put_tail ========
171 * Adds the specified element to the tail of the list
173 * Sets new element's "prev" pointer to the address previously held by
174 * the head element's prev pointer. This is the previous tail member of
176 * Sets the new head's prev pointer to the address of the element.
177 * Sets next pointer of the previous tail member of the list to point to
178 * the new element (rather than the head, which it had been pointing at).
179 * Sets new element's next pointer to the address of the head element.
180 * Sets head's prev pointer to the address of the new element.
182 * lst: Pointer to list control structure to which *elem_list will be
184 * elem_list: Pointer to list element to be added
188 * *elem_list and *lst must both exist.
192 * Because the tail is always "just before" the head of the list (the
193 * tail's "next" pointer points at the head of the list, and the head's
194 * "prev" pointer points at the tail of the list), the list is circular.
196 static inline void lst_put_tail(struct lst_list *lst,
197 struct list_head *elem_list)
199 if (lst && elem_list)
200 list_add_tail(elem_list, &lst->head);
204 * ======== lst_remove_elem ========
206 * Removes (unlinks) the given element from the list, if the list is not
207 * empty. Does not free the list element.
209 * lst: Pointer to list control structure.
210 * cur_elem: Pointer to element in list to remove.
215 * - cur_elem != NULL.
218 static inline void lst_remove_elem(struct lst_list *lst,
219 struct list_head *cur_elem)
221 if (lst && !list_empty(&lst->head) && cur_elem)
222 list_del_init(cur_elem);