New upstream version 18.02
[deb_dpdk.git] / drivers / bus / dpaa / include / dpaa_list.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017 NXP
4  *
5  */
6
7 #ifndef __DPAA_LIST_H
8 #define __DPAA_LIST_H
9
10 /****************/
11 /* Linked-lists */
12 /****************/
13
14 struct list_head {
15         struct list_head *prev;
16         struct list_head *next;
17 };
18
19 #define COMPAT_LIST_HEAD(n) \
20 struct list_head n = { \
21         .prev = &n, \
22         .next = &n \
23 }
24
25 #define INIT_LIST_HEAD(p) \
26 do { \
27         struct list_head *__p298 = (p); \
28         __p298->next = __p298; \
29         __p298->prev = __p298->next; \
30 } while (0)
31 #define list_entry(node, type, member) \
32         (type *)((void *)node - offsetof(type, member))
33 #define list_empty(p) \
34 ({ \
35         const struct list_head *__p298 = (p); \
36         ((__p298->next == __p298) && (__p298->prev == __p298)); \
37 })
38 #define list_add(p, l) \
39 do { \
40         struct list_head *__p298 = (p); \
41         struct list_head *__l298 = (l); \
42         __p298->next = __l298->next; \
43         __p298->prev = __l298; \
44         __l298->next->prev = __p298; \
45         __l298->next = __p298; \
46 } while (0)
47 #define list_add_tail(p, l) \
48 do { \
49         struct list_head *__p298 = (p); \
50         struct list_head *__l298 = (l); \
51         __p298->prev = __l298->prev; \
52         __p298->next = __l298; \
53         __l298->prev->next = __p298; \
54         __l298->prev = __p298; \
55 } while (0)
56 #define list_for_each(i, l)                             \
57         for (i = (l)->next; i != (l); i = i->next)
58 #define list_for_each_safe(i, j, l)                     \
59         for (i = (l)->next, j = i->next; i != (l);      \
60              i = j, j = i->next)
61 #define list_for_each_entry(i, l, name) \
62         for (i = list_entry((l)->next, typeof(*i), name); &i->name != (l); \
63                 i = list_entry(i->name.next, typeof(*i), name))
64 #define list_for_each_entry_safe(i, j, l, name) \
65         for (i = list_entry((l)->next, typeof(*i), name), \
66                 j = list_entry(i->name.next, typeof(*j), name); \
67                 &i->name != (l); \
68                 i = j, j = list_entry(j->name.next, typeof(*j), name))
69 #define list_del(i) \
70 do { \
71         (i)->next->prev = (i)->prev; \
72         (i)->prev->next = (i)->next; \
73 } while (0)
74
75 #endif /* __DPAA_LIST_H */