871e6121ec2231ee9da1a35a7db5ac0718490fe3
[deb_dpdk.git] / drivers / bus / dpaa / include / dpaa_list.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 NXP.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of NXP nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef __DPAA_LIST_H
34 #define __DPAA_LIST_H
35
36 /****************/
37 /* Linked-lists */
38 /****************/
39
40 struct list_head {
41         struct list_head *prev;
42         struct list_head *next;
43 };
44
45 #define COMPAT_LIST_HEAD(n) \
46 struct list_head n = { \
47         .prev = &n, \
48         .next = &n \
49 }
50
51 #define INIT_LIST_HEAD(p) \
52 do { \
53         struct list_head *__p298 = (p); \
54         __p298->next = __p298; \
55         __p298->prev = __p298->next; \
56 } while (0)
57 #define list_entry(node, type, member) \
58         (type *)((void *)node - offsetof(type, member))
59 #define list_empty(p) \
60 ({ \
61         const struct list_head *__p298 = (p); \
62         ((__p298->next == __p298) && (__p298->prev == __p298)); \
63 })
64 #define list_add(p, l) \
65 do { \
66         struct list_head *__p298 = (p); \
67         struct list_head *__l298 = (l); \
68         __p298->next = __l298->next; \
69         __p298->prev = __l298; \
70         __l298->next->prev = __p298; \
71         __l298->next = __p298; \
72 } while (0)
73 #define list_add_tail(p, l) \
74 do { \
75         struct list_head *__p298 = (p); \
76         struct list_head *__l298 = (l); \
77         __p298->prev = __l298->prev; \
78         __p298->next = __l298; \
79         __l298->prev->next = __p298; \
80         __l298->prev = __p298; \
81 } while (0)
82 #define list_for_each(i, l)                             \
83         for (i = (l)->next; i != (l); i = i->next)
84 #define list_for_each_safe(i, j, l)                     \
85         for (i = (l)->next, j = i->next; i != (l);      \
86              i = j, j = i->next)
87 #define list_for_each_entry(i, l, name) \
88         for (i = list_entry((l)->next, typeof(*i), name); &i->name != (l); \
89                 i = list_entry(i->name.next, typeof(*i), name))
90 #define list_for_each_entry_safe(i, j, l, name) \
91         for (i = list_entry((l)->next, typeof(*i), name), \
92                 j = list_entry(i->name.next, typeof(*j), name); \
93                 &i->name != (l); \
94                 i = j, j = list_entry(j->name.next, typeof(*j), name))
95 #define list_del(i) \
96 do { \
97         (i)->next->prev = (i)->prev; \
98         (i)->prev->next = (i)->next; \
99 } while (0)
100
101 #endif /* __DPAA_LIST_H */