1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef SYM_MISC_H
28#define SYM_MISC_H
29
30
31
32
33typedef struct sym_quehead {
34 struct sym_quehead *flink;
35 struct sym_quehead *blink;
36} SYM_QUEHEAD;
37
38#define sym_que_init(ptr) do { \
39 (ptr)->flink = (ptr); (ptr)->blink = (ptr); \
40} while (0)
41
42static inline struct sym_quehead *sym_que_first(struct sym_quehead *head)
43{
44 return (head->flink == head) ? 0 : head->flink;
45}
46
47static inline struct sym_quehead *sym_que_last(struct sym_quehead *head)
48{
49 return (head->blink == head) ? 0 : head->blink;
50}
51
52static inline void __sym_que_add(struct sym_quehead * new,
53 struct sym_quehead * blink,
54 struct sym_quehead * flink)
55{
56 flink->blink = new;
57 new->flink = flink;
58 new->blink = blink;
59 blink->flink = new;
60}
61
62static inline void __sym_que_del(struct sym_quehead * blink,
63 struct sym_quehead * flink)
64{
65 flink->blink = blink;
66 blink->flink = flink;
67}
68
69static inline int sym_que_empty(struct sym_quehead *head)
70{
71 return head->flink == head;
72}
73
74static inline void sym_que_splice(struct sym_quehead *list,
75 struct sym_quehead *head)
76{
77 struct sym_quehead *first = list->flink;
78
79 if (first != list) {
80 struct sym_quehead *last = list->blink;
81 struct sym_quehead *at = head->flink;
82
83 first->blink = head;
84 head->flink = first;
85
86 last->flink = at;
87 at->blink = last;
88 }
89}
90
91static inline void sym_que_move(struct sym_quehead *orig,
92 struct sym_quehead *dest)
93{
94 struct sym_quehead *first, *last;
95
96 first = orig->flink;
97 if (first != orig) {
98 first->blink = dest;
99 dest->flink = first;
100 last = orig->blink;
101 last->flink = dest;
102 dest->blink = last;
103 orig->flink = orig;
104 orig->blink = orig;
105 } else {
106 dest->flink = dest;
107 dest->blink = dest;
108 }
109}
110
111#define sym_que_entry(ptr, type, member) container_of(ptr, type, member)
112
113#define sym_insque(new, pos) __sym_que_add(new, pos, (pos)->flink)
114
115#define sym_remque(el) __sym_que_del((el)->blink, (el)->flink)
116
117#define sym_insque_head(new, head) __sym_que_add(new, head, (head)->flink)
118
119static inline struct sym_quehead *sym_remque_head(struct sym_quehead *head)
120{
121 struct sym_quehead *elem = head->flink;
122
123 if (elem != head)
124 __sym_que_del(head, elem->flink);
125 else
126 elem = NULL;
127 return elem;
128}
129
130#define sym_insque_tail(new, head) __sym_que_add(new, (head)->blink, head)
131
132static inline struct sym_quehead *sym_remque_tail(struct sym_quehead *head)
133{
134 struct sym_quehead *elem = head->blink;
135
136 if (elem != head)
137 __sym_que_del(elem->blink, head);
138 else
139 elem = 0;
140 return elem;
141}
142
143
144
145
146#define FOR_EACH_QUEUED_ELEMENT(head, qp) \
147 for (qp = (head)->flink; qp != (head); qp = qp->flink)
148
149
150
151
152#define sym_qptr(p) ((struct sym_quehead *) (p))
153
154
155
156
157#define sym_set_bit(p, n) (((u32 *)(p))[(n)>>5] |= (1<<((n)&0x1f)))
158#define sym_clr_bit(p, n) (((u32 *)(p))[(n)>>5] &= ~(1<<((n)&0x1f)))
159#define sym_is_bit(p, n) (((u32 *)(p))[(n)>>5] & (1<<((n)&0x1f)))
160
161
162
163
164
165
166#define _U_(a,m) (a)<=(1<<m)?m:
167
168
169
170
171#define _LGRU16_(a) \
172( \
173 _U_(a, 0)_U_(a, 1)_U_(a, 2)_U_(a, 3)_U_(a, 4)_U_(a, 5)_U_(a, 6)_U_(a, 7) \
174 _U_(a, 8)_U_(a, 9)_U_(a,10)_U_(a,11)_U_(a,12)_U_(a,13)_U_(a,14)_U_(a,15) \
175 16)
176
177#endif
178