lin
2025-08-21 57113df3a0e2be01232281fad9a5f2c060567981
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Copyright (c) 2008-2016 Allwinner Technology Co. Ltd.
* All rights reserved.
*
* File : ionAllocList.h
* Description :
* History :
*   Author  : xyliu <xyliu@allwinnertech.com>
*   Date    : 2016/04/13
*   Comment :
*
*
*/
 
#ifndef _ION_LIST_H
#define _ION_LIST_H
 
#define ion_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 
#define container_of(aw_ptr, type, member) ( { \
const typeof( ((type *)0)->member ) *__mptr = (aw_ptr); \
(type *)( (char *)__mptr - ion_offsetof(type,member) ); } )
 
static inline void aw_prefetch(const void *x) {(void)x;}
static inline void aw_prefetchw(const void *x) {(void)x;}
 
#define AW_LIST_LOCATION1  ((void *) 0x00100100)
#define AW_LIST_LOCATION2  ((void *) 0x00200200)
 
struct aw_mem_list_head {
struct aw_mem_list_head *aw_next, *aw_prev;
};
 
#define AW_MEM_LIST_HEAD_INIT(aw_name) { &(aw_name), &(aw_name) }
 
#define LIST_HEAD(aw_name) \
struct aw_mem_list_head aw_name = AW_MEM_LIST_HEAD_INIT(aw_name)
 
#define AW_MEM_INIT_LIST_HEAD(aw_ptr) do { \
(aw_ptr)->aw_next = (aw_ptr); (aw_ptr)->aw_prev = (aw_ptr); \
} while (0)
 
/*
 * Insert a new entry between two known consecutive entries.
 *
 * This is only for internal list manipulation where we know
 * the aw_prev/aw_next entries already!
 */
static inline void __aw_list_add(struct aw_mem_list_head *newList,
      struct aw_mem_list_head *aw_prev,
      struct aw_mem_list_head *aw_next)
{
    aw_next->aw_prev = newList;
    newList->aw_next = aw_next;
    newList->aw_prev = aw_prev;
    aw_prev->aw_next = newList;
}
 
/**
 * list_add - add a new entry
 * @new: new entry to be added
 * @head: list head to add it after
 *
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 */
static inline void aw_mem_list_add(struct aw_mem_list_head *newList, struct aw_mem_list_head *head)
{
    __aw_list_add(newList, head, head->aw_next);
}
 
/**
 * aw_mem_list_add_tail - add a new entry
 * @new: new entry to be added
 * @head: list head to add it before
 *
 * Insert a new entry before the specified head.
 * This is useful for implementing queues.
 */
static inline void aw_mem_list_add_tail(struct aw_mem_list_head *newList,
         struct aw_mem_list_head *head)
{
    __aw_list_add(newList, head->aw_prev, head);
}
 
static inline void __aw_mem_list_del(struct aw_mem_list_head * aw_prev,
        struct aw_mem_list_head * aw_next)
{
    aw_next->aw_prev = aw_prev;
    aw_prev->aw_next = aw_next;
}
 
static inline void aw_mem_list_del(struct aw_mem_list_head *entry)
{
    __aw_mem_list_del(entry->aw_prev, entry->aw_next);
    entry->aw_next = AW_LIST_LOCATION1;
    entry->aw_prev = AW_LIST_LOCATION2;
}
 
#define aw_mem_list_entry(aw_ptr, type, member) container_of(aw_ptr, type, member)
 
#define aw_mem_list_for_each_safe(aw_pos, aw_n, aw_head) \
for (aw_pos = (aw_head)->aw_next, aw_n = aw_pos->aw_next; aw_pos != (aw_head); \
aw_pos = aw_n, aw_n = aw_pos->aw_next)
 
#define aw_mem_list_for_each_entry(aw_pos, aw_head, member) \
for (aw_pos = aw_mem_list_entry((aw_head)->aw_next, typeof(*aw_pos), member); \
     aw_prefetch(aw_pos->member.aw_next), &aw_pos->member != (aw_head);  \
     aw_pos = aw_mem_list_entry(aw_pos->member.aw_next, typeof(*aw_pos), member))
 
 
/*
static inline void aw_mem_list_del_init(struct aw_mem_list_head *entry)
{
__aw_mem_list_del(entry->aw_prev, entry->aw_next);
AW_MEM_INIT_LIST_HEAD(entry);
}
 
static inline void list_move(struct aw_mem_list_head *list, struct aw_mem_list_head *head)
{
        __aw_mem_list_del(list->aw_prev, list->aw_next);
        aw_mem_list_add(list, head);
}
 
static inline void list_move_tail(struct aw_mem_list_head *list,
  struct aw_mem_list_head *head)
{
        __aw_mem_list_del(list->aw_prev, list->aw_next);
        aw_mem_list_add_tail(list, head);
}
 
static inline int list_empty(const struct aw_mem_list_head *head)
{
return head->aw_next == head;
}
 
static inline int list_empty_careful(const struct aw_mem_list_head *head)
{
struct aw_mem_list_head *aw_next = head->aw_next;
return (aw_next == head) && (aw_next == head->aw_prev);
}
 
static inline void __list_splice(struct aw_mem_list_head *list,
 struct aw_mem_list_head *head)
{
struct aw_mem_list_head *first = list->aw_next;
struct aw_mem_list_head *last = list->aw_prev;
struct aw_mem_list_head *at = head->aw_next;
 
first->aw_prev = head;
head->aw_next = first;
 
last->aw_next = at;
at->aw_prev = last;
}
*/
 
/**
 * list_splice - join two lists
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 */
 
/*
static inline void list_splice(struct aw_mem_list_head *list, struct aw_mem_list_head *head)
{
if (!list_empty(list))
__list_splice(list, head);
}
*/
 
/**
 * list_splice_init - join two lists and reinitialise the emptied list.
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 *
 * The list at @list is reinitialised
 
static inline void list_splice_init(struct aw_mem_list_head *list,
    struct aw_mem_list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
AW_MEM_INIT_LIST_HEAD(list);
}
}
*/
 
//not use
/*
#define list_for_each(pos, head) \
for (pos = (head)->aw_next; prefetch(pos->aw_next), pos != (head); \
         pos = pos->aw_next)
 
#define __list_for_each(pos, head) \
for (pos = (head)->aw_next; pos != (head); pos = pos->aw_next)
 
#define list_for_each_prev(pos, head) \
for (pos = (head)->aw_prev; prefetch(pos->aw_prev), pos != (head); \
         pos = pos->aw_prev)
 
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->aw_prev, typeof(*pos), member); \
     prefetch(pos->member.aw_prev), &pos->member != (head);  \
     pos = list_entry(pos->member.aw_prev, typeof(*pos), member))
 
#define list_prepare_entry(pos, head, member) \
((pos) ? : list_entry(head, typeof(*pos), member))
 
#define list_for_each_entry_continue(pos, head, member)  \
for (pos = list_entry(pos->member.aw_next, typeof(*pos), member); \
     prefetch(pos->member.aw_next), &pos->member != (head); \
     pos = list_entry(pos->member.aw_next, typeof(*pos), member))
 
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->aw_next, typeof(*pos), member), \
n = list_entry(pos->member.aw_next, typeof(*pos), member); \
     &pos->member != (head);  \
     pos = n, n = list_entry(n->member.aw_next, typeof(*n), member))
 
//HASH LIST
struct hlist_head {
struct hlist_node *first;
};
 
struct hlist_node {
struct hlist_node *aw_next, **pprev;
};
 
#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
#define INIT_HLIST_HEAD(aw_ptr) ((aw_ptr)->first = NULL)
#define INIT_HLIST_NODE(aw_ptr) ((aw_ptr)->aw_next = NULL, (aw_ptr)->pprev = NULL)
 
static inline int hlist_unhashed(const struct hlist_node *h)
{
return !h->pprev;
}
 
static inline int hlist_empty(const struct hlist_head *h)
{
return !h->first;
}
 
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *aw_next = n->aw_next;
struct hlist_node **pprev = n->pprev;
*pprev = aw_next;
if (aw_next)
aw_next->pprev = pprev;
}
 
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->aw_next = AW_LIST_LOCATION1;
n->pprev = AW_LIST_LOCATION2;
}
 
static inline void hlist_del_init(struct hlist_node *n)
{
if (n->pprev)  {
__hlist_del(n);
INIT_HLIST_NODE(n);
}
}
 
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
struct hlist_node *first = h->first;
n->aw_next = first;
if (first)
first->pprev = &n->aw_next;
h->first = n;
n->pprev = &h->first;
}
*/
 
/* aw_next must be != NULL */
/*
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *aw_next)
{
n->pprev = aw_next->pprev;
n->aw_next = aw_next;
aw_next->pprev = &n->aw_next;
*(n->pprev) = n;
}
 
static inline void hlist_add_after(struct hlist_node *n,
struct hlist_node *aw_next)
{
aw_next->aw_next = n->aw_next;
n->aw_next = aw_next;
aw_next->pprev = &n->aw_next;
 
if(aw_next->aw_next)
aw_next->aw_next->pprev  = &aw_next->aw_next;
}
 
#define hlist_entry(aw_ptr, type, member) container_of(aw_ptr,type,member)
 
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos && ({ prefetch(pos->aw_next); 1; }); \
     pos = pos->aw_next)
 
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->aw_next; 1; }); \
     pos = n)
 
#define hlist_for_each_entry(tpos, pos, head, member)  \
for (pos = (head)->first;  \
     pos && ({ prefetch(pos->aw_next); 1;}) &&  \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
     pos = pos->aw_next)
 
#define hlist_for_each_entry_continue(tpos, pos, member)  \
for (pos = (pos)->aw_next;  \
     pos && ({ prefetch(pos->aw_next); 1;}) &&  \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
     pos = pos->aw_next)
 
#define hlist_for_each_entry_from(tpos, pos, member)  \
for (; pos && ({ prefetch(pos->aw_next); 1;}) &&  \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
     pos = pos->aw_next)
 
#define hlist_for_each_entry_safe(tpos, pos, n, head, member)   \
for (pos = (head)->first;  \
     pos && ({ n = pos->aw_next; 1; }) &&   \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
     pos = n)
*/
#endif