diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2007-08-27 16:04:32 +0000 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2007-08-27 16:04:32 +0000 |
commit | 8181a0c905a591caef684a2d7487feedbec84c10 (patch) | |
tree | 3939183e8e73928d1b5dcfc97b40f33b6baa309b /firmware/export/linkedlist.h | |
parent | 9305c86f5b8fdfd60882428f884ba29bded8da78 (diff) | |
download | rockbox-8181a0c905a591caef684a2d7487feedbec84c10.tar.gz rockbox-8181a0c905a591caef684a2d7487feedbec84c10.zip |
Usb Stack: only setup packet handling, and not enabled by default as there is a lot to do.
* settings code is not fully ready -> changing device driver has no effect
* clean ups
* check copyriths
* find a way to detect IN transfers
* support for full and highspeed
* ...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14470 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/export/linkedlist.h')
-rw-r--r-- | firmware/export/linkedlist.h | 710 |
1 files changed, 710 insertions, 0 deletions
diff --git a/firmware/export/linkedlist.h b/firmware/export/linkedlist.h new file mode 100644 index 0000000000..299c2f2c85 --- /dev/null +++ b/firmware/export/linkedlist.h | |||
@@ -0,0 +1,710 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: adc.h 13174 2007-04-15 23:35:56Z amiconn $ | ||
9 | * | ||
10 | * Copyright (C) by Linux Kernel Developers | ||
11 | * | ||
12 | * Original source can be found in linux kernel: <kernel>/include/list.h | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _LINKED_LIST_H_ | ||
23 | #define _LINKED_LIST_H_ | ||
24 | |||
25 | #include <stddef.h> /* used for offsetof */ | ||
26 | |||
27 | static inline void prefetch(const void *x) { (void)x; } | ||
28 | |||
29 | /* | ||
30 | * Simple doubly linked list implementation. | ||
31 | * | ||
32 | * Some of the internal functions ("__xxx") are useful when | ||
33 | * manipulating whole lists rather than single entries, as | ||
34 | * sometimes we already know the next/prev entries and we can | ||
35 | * generate better code by using them directly rather than | ||
36 | * using the generic single-entry routines. | ||
37 | */ | ||
38 | |||
39 | /* TODO move this macro? */ | ||
40 | /* more about this macro: http://www.kroah.com/log/linux/container_of.html */ | ||
41 | #define container_of(ptr, type, member) ({ \ | ||
42 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | ||
43 | (type *)( (char *)__mptr - offsetof(type,member) );}) | ||
44 | |||
45 | /* | ||
46 | * These are non-NULL pointers that will result in page faults | ||
47 | * under normal circumstances, used to verify that nobody uses | ||
48 | * non-initialized list entries. | ||
49 | */ | ||
50 | #define LIST_POISON1 ((void *) 0x00100100) | ||
51 | #define LIST_POISON2 ((void *) 0x00200200) | ||
52 | |||
53 | struct list_head { | ||
54 | struct list_head *next, *prev; | ||
55 | }; | ||
56 | |||
57 | #define LIST_HEAD_INIT(name) { &(name), &(name) } | ||
58 | |||
59 | #define LIST_HEAD(name) \ | ||
60 | struct list_head name = LIST_HEAD_INIT(name) | ||
61 | |||
62 | static inline void INIT_LIST_HEAD(struct list_head *list) | ||
63 | { | ||
64 | list->next = list; | ||
65 | list->prev = list; | ||
66 | } | ||
67 | |||
68 | /* | ||
69 | * Insert a new entry between two known consecutive entries. | ||
70 | * | ||
71 | * This is only for internal list manipulation where we know | ||
72 | * the prev/next entries already! | ||
73 | */ | ||
74 | static inline void __list_add(struct list_head *new, | ||
75 | struct list_head *prev, | ||
76 | struct list_head *next) | ||
77 | { | ||
78 | next->prev = new; | ||
79 | new->next = next; | ||
80 | new->prev = prev; | ||
81 | prev->next = new; | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * list_add - add a new entry | ||
87 | * @new: new entry to be added | ||
88 | * @head: list head to add it after | ||
89 | * | ||
90 | * Insert a new entry after the specified head. | ||
91 | * This is good for implementing stacks. | ||
92 | */ | ||
93 | static inline void list_add(struct list_head *new, struct list_head *head) | ||
94 | { | ||
95 | __list_add(new, head, head->next); | ||
96 | } | ||
97 | |||
98 | |||
99 | /** | ||
100 | * list_add_tail - add a new entry | ||
101 | * @new: new entry to be added | ||
102 | * @head: list head to add it before | ||
103 | * | ||
104 | * Insert a new entry before the specified head. | ||
105 | * This is useful for implementing queues. | ||
106 | */ | ||
107 | static inline void list_add_tail(struct list_head *new, struct list_head *head) | ||
108 | { | ||
109 | __list_add(new, head->prev, head); | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * Delete a list entry by making the prev/next entries | ||
114 | * point to each other. | ||
115 | * | ||
116 | * This is only for internal list manipulation where we know | ||
117 | * the prev/next entries already! | ||
118 | */ | ||
119 | static inline void __list_del(struct list_head * prev, struct list_head * next) | ||
120 | { | ||
121 | next->prev = prev; | ||
122 | prev->next = next; | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * list_del - deletes entry from list. | ||
127 | * @entry: the element to delete from the list. | ||
128 | * Note: list_empty() on entry does not return true after this, the entry is | ||
129 | * in an undefined state. | ||
130 | */ | ||
131 | static inline void list_del(struct list_head *entry) | ||
132 | { | ||
133 | __list_del(entry->prev, entry->next); | ||
134 | entry->next = LIST_POISON1; | ||
135 | entry->prev = LIST_POISON2; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * list_replace - replace old entry by new one | ||
140 | * @old : the element to be replaced | ||
141 | * @new : the new element to insert | ||
142 | * | ||
143 | * If @old was empty, it will be overwritten. | ||
144 | */ | ||
145 | static inline void list_replace(struct list_head *old, | ||
146 | struct list_head *new) | ||
147 | { | ||
148 | new->next = old->next; | ||
149 | new->next->prev = new; | ||
150 | new->prev = old->prev; | ||
151 | new->prev->next = new; | ||
152 | } | ||
153 | |||
154 | static inline void list_replace_init(struct list_head *old, | ||
155 | struct list_head *new) | ||
156 | { | ||
157 | list_replace(old, new); | ||
158 | INIT_LIST_HEAD(old); | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * list_del_init - deletes entry from list and reinitialize it. | ||
163 | * @entry: the element to delete from the list. | ||
164 | */ | ||
165 | static inline void list_del_init(struct list_head *entry) | ||
166 | { | ||
167 | __list_del(entry->prev, entry->next); | ||
168 | INIT_LIST_HEAD(entry); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * list_move - delete from one list and add as another's head | ||
173 | * @list: the entry to move | ||
174 | * @head: the head that will precede our entry | ||
175 | */ | ||
176 | static inline void list_move(struct list_head *list, struct list_head *head) | ||
177 | { | ||
178 | __list_del(list->prev, list->next); | ||
179 | list_add(list, head); | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * list_move_tail - delete from one list and add as another's tail | ||
184 | * @list: the entry to move | ||
185 | * @head: the head that will follow our entry | ||
186 | */ | ||
187 | static inline void list_move_tail(struct list_head *list, | ||
188 | struct list_head *head) | ||
189 | { | ||
190 | __list_del(list->prev, list->next); | ||
191 | list_add_tail(list, head); | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * list_is_last - tests whether @list is the last entry in list @head | ||
196 | * @list: the entry to test | ||
197 | * @head: the head of the list | ||
198 | */ | ||
199 | static inline int list_is_last(const struct list_head *list, | ||
200 | const struct list_head *head) | ||
201 | { | ||
202 | return list->next == head; | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * list_empty - tests whether a list is empty | ||
207 | * @head: the list to test. | ||
208 | */ | ||
209 | static inline int list_empty(const struct list_head *head) | ||
210 | { | ||
211 | return head->next == head; | ||
212 | } | ||
213 | |||
214 | static inline void __list_splice(struct list_head *list, | ||
215 | struct list_head *head) | ||
216 | { | ||
217 | struct list_head *first = list->next; | ||
218 | struct list_head *last = list->prev; | ||
219 | struct list_head *at = head->next; | ||
220 | |||
221 | first->prev = head; | ||
222 | head->next = first; | ||
223 | |||
224 | last->next = at; | ||
225 | at->prev = last; | ||
226 | } | ||
227 | |||
228 | /** | ||
229 | * list_splice - join two lists | ||
230 | * @list: the new list to add. | ||
231 | * @head: the place to add it in the first list. | ||
232 | */ | ||
233 | static inline void list_splice(struct list_head *list, struct list_head *head) | ||
234 | { | ||
235 | if (!list_empty(list)) { | ||
236 | __list_splice(list, head); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * list_splice_init - join two lists and reinitialise the emptied list. | ||
242 | * @list: the new list to add. | ||
243 | * @head: the place to add it in the first list. | ||
244 | * | ||
245 | * The list at @list is reinitialised | ||
246 | */ | ||
247 | static inline void list_splice_init(struct list_head *list, | ||
248 | struct list_head *head) | ||
249 | { | ||
250 | if (!list_empty(list)) { | ||
251 | __list_splice(list, head); | ||
252 | INIT_LIST_HEAD(list); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | /** | ||
257 | * list_entry - get the struct for this entry | ||
258 | * @ptr: the &struct list_head pointer. | ||
259 | * @type: the type of the struct this is embedded in. | ||
260 | * @member: the name of the list_struct within the struct. | ||
261 | */ | ||
262 | #define list_entry(ptr, type, member) \ | ||
263 | container_of(ptr, type, member) | ||
264 | |||
265 | /** | ||
266 | * list_for_each - iterate over a list | ||
267 | * @pos: the &struct list_head to use as a loop cursor. | ||
268 | * @head: the head for your list. | ||
269 | */ | ||
270 | #define list_for_each(pos, head) \ | ||
271 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ | ||
272 | pos = pos->next) | ||
273 | |||
274 | /** | ||
275 | * __list_for_each - iterate over a list | ||
276 | * @pos: the &struct list_head to use as a loop cursor. | ||
277 | * @head: the head for your list. | ||
278 | * | ||
279 | * This variant differs from list_for_each() in that it's the | ||
280 | * simplest possible list iteration code, no prefetching is done. | ||
281 | * Use this for code that knows the list to be very short (empty | ||
282 | * or 1 entry) most of the time. | ||
283 | */ | ||
284 | #define __list_for_each(pos, head) \ | ||
285 | for (pos = (head)->next; pos != (head); pos = pos->next) | ||
286 | |||
287 | /** | ||
288 | * list_for_each_prev - iterate over a list backwards | ||
289 | * @pos: the &struct list_head to use as a loop cursor. | ||
290 | * @head: the head for your list. | ||
291 | */ | ||
292 | #define list_for_each_prev(pos, head) \ | ||
293 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ | ||
294 | pos = pos->prev) | ||
295 | |||
296 | /** | ||
297 | * list_for_each_entry - iterate over list of given type | ||
298 | * @pos: the type * to use as a loop cursor. | ||
299 | * @head: the head for your list. | ||
300 | * @member: the name of the list_struct within the struct. | ||
301 | */ | ||
302 | #define list_for_each_entry(pos, head, member) \ | ||
303 | for (pos = list_entry((head)->next, typeof(*pos), member); \ | ||
304 | prefetch(pos->member.next), &pos->member != (head); \ | ||
305 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
306 | |||
307 | /** | ||
308 | * list_for_each_entry_reverse - iterate backwards over list of given type. | ||
309 | * @pos: the type * to use as a loop cursor. | ||
310 | * @head: the head for your list. | ||
311 | * @member: the name of the list_struct within the struct. | ||
312 | */ | ||
313 | #define list_for_each_entry_reverse(pos, head, member) \ | ||
314 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ | ||
315 | prefetch(pos->member.prev), &pos->member != (head); \ | ||
316 | pos = list_entry(pos->member.prev, typeof(*pos), member)) | ||
317 | |||
318 | /** | ||
319 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() | ||
320 | * @pos: the type * to use as a start point | ||
321 | * @head: the head of the list | ||
322 | * @member: the name of the list_struct within the struct. | ||
323 | * | ||
324 | * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). | ||
325 | */ | ||
326 | #define list_prepare_entry(pos, head, member) \ | ||
327 | ((pos) ? : list_entry(head, typeof(*pos), member)) | ||
328 | |||
329 | /** | ||
330 | * list_for_each_entry_continue - continue iteration over list of given type | ||
331 | * @pos: the type * to use as a loop cursor. | ||
332 | * @head: the head for your list. | ||
333 | * @member: the name of the list_struct within the struct. | ||
334 | * | ||
335 | * Continue to iterate over list of given type, continuing after | ||
336 | * the current position. | ||
337 | */ | ||
338 | #define list_for_each_entry_continue(pos, head, member) \ | ||
339 | for (pos = list_entry(pos->member.next, typeof(*pos), member); \ | ||
340 | prefetch(pos->member.next), &pos->member != (head); \ | ||
341 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
342 | |||
343 | /** | ||
344 | * list_for_each_entry_from - iterate over list of given type from the current point | ||
345 | * @pos: the type * to use as a loop cursor. | ||
346 | * @head: the head for your list. | ||
347 | * @member: the name of the list_struct within the struct. | ||
348 | * | ||
349 | * Iterate over list of given type, continuing from current position. | ||
350 | */ | ||
351 | #define list_for_each_entry_from(pos, head, member) \ | ||
352 | for (; prefetch(pos->member.next), &pos->member != (head); \ | ||
353 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
354 | |||
355 | #endif /*_LINKED_LIST_H_*/ | ||
356 | /*************************************************************************** | ||
357 | * __________ __ ___. | ||
358 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
359 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
360 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
361 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
362 | * \/ \/ \/ \/ \/ | ||
363 | * $Id: adc.h 13174 2007-04-15 23:35:56Z amiconn $ | ||
364 | * | ||
365 | * Copyright (C) by Linux Kernel Developers | ||
366 | * | ||
367 | * Original source can be found in linux kernel: <kernel>/include/list.h | ||
368 | * | ||
369 | * All files in this archive are subject to the GNU General Public License. | ||
370 | * See the file COPYING in the source tree root for full license agreement. | ||
371 | * | ||
372 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
373 | * KIND, either express or implied. | ||
374 | * | ||
375 | ****************************************************************************/ | ||
376 | |||
377 | #ifndef _LINKED_LIST_H_ | ||
378 | #define _LINKED_LIST_H_ | ||
379 | |||
380 | #include <stddef.h> /* used for offsetof */ | ||
381 | |||
382 | static inline void prefetch(const void *x) { (void)x; } | ||
383 | |||
384 | /* | ||
385 | * Simple doubly linked list implementation. | ||
386 | * | ||
387 | * Some of the internal functions ("__xxx") are useful when | ||
388 | * manipulating whole lists rather than single entries, as | ||
389 | * sometimes we already know the next/prev entries and we can | ||
390 | * generate better code by using them directly rather than | ||
391 | * using the generic single-entry routines. | ||
392 | */ | ||
393 | |||
394 | /* TODO move this macro? */ | ||
395 | /* more about this macro: http://www.kroah.com/log/linux/container_of.html */ | ||
396 | #define container_of(ptr, type, member) ({ \ | ||
397 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | ||
398 | (type *)( (char *)__mptr - offsetof(type,member) );}) | ||
399 | |||
400 | /* | ||
401 | * These are non-NULL pointers that will result in page faults | ||
402 | * under normal circumstances, used to verify that nobody uses | ||
403 | * non-initialized list entries. | ||
404 | */ | ||
405 | #define LIST_POISON1 ((void *) 0x00100100) | ||
406 | #define LIST_POISON2 ((void *) 0x00200200) | ||
407 | |||
408 | struct list_head { | ||
409 | struct list_head *next, *prev; | ||
410 | }; | ||
411 | |||
412 | #define LIST_HEAD_INIT(name) { &(name), &(name) } | ||
413 | |||
414 | #define LIST_HEAD(name) \ | ||
415 | struct list_head name = LIST_HEAD_INIT(name) | ||
416 | |||
417 | static inline void INIT_LIST_HEAD(struct list_head *list) | ||
418 | { | ||
419 | list->next = list; | ||
420 | list->prev = list; | ||
421 | } | ||
422 | |||
423 | /* | ||
424 | * Insert a new entry between two known consecutive entries. | ||
425 | * | ||
426 | * This is only for internal list manipulation where we know | ||
427 | * the prev/next entries already! | ||
428 | */ | ||
429 | static inline void __list_add(struct list_head *new, | ||
430 | struct list_head *prev, | ||
431 | struct list_head *next) | ||
432 | { | ||
433 | next->prev = new; | ||
434 | new->next = next; | ||
435 | new->prev = prev; | ||
436 | prev->next = new; | ||
437 | } | ||
438 | |||
439 | |||
440 | /** | ||
441 | * list_add - add a new entry | ||
442 | * @new: new entry to be added | ||
443 | * @head: list head to add it after | ||
444 | * | ||
445 | * Insert a new entry after the specified head. | ||
446 | * This is good for implementing stacks. | ||
447 | */ | ||
448 | static inline void list_add(struct list_head *new, struct list_head *head) | ||
449 | { | ||
450 | __list_add(new, head, head->next); | ||
451 | } | ||
452 | |||
453 | |||
454 | /** | ||
455 | * list_add_tail - add a new entry | ||
456 | * @new: new entry to be added | ||
457 | * @head: list head to add it before | ||
458 | * | ||
459 | * Insert a new entry before the specified head. | ||
460 | * This is useful for implementing queues. | ||
461 | */ | ||
462 | static inline void list_add_tail(struct list_head *new, struct list_head *head) | ||
463 | { | ||
464 | __list_add(new, head->prev, head); | ||
465 | } | ||
466 | |||
467 | /* | ||
468 | * Delete a list entry by making the prev/next entries | ||
469 | * point to each other. | ||
470 | * | ||
471 | * This is only for internal list manipulation where we know | ||
472 | * the prev/next entries already! | ||
473 | */ | ||
474 | static inline void __list_del(struct list_head * prev, struct list_head * next) | ||
475 | { | ||
476 | next->prev = prev; | ||
477 | prev->next = next; | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * list_del - deletes entry from list. | ||
482 | * @entry: the element to delete from the list. | ||
483 | * Note: list_empty() on entry does not return true after this, the entry is | ||
484 | * in an undefined state. | ||
485 | */ | ||
486 | static inline void list_del(struct list_head *entry) | ||
487 | { | ||
488 | __list_del(entry->prev, entry->next); | ||
489 | entry->next = LIST_POISON1; | ||
490 | entry->prev = LIST_POISON2; | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * list_replace - replace old entry by new one | ||
495 | * @old : the element to be replaced | ||
496 | * @new : the new element to insert | ||
497 | * | ||
498 | * If @old was empty, it will be overwritten. | ||
499 | */ | ||
500 | static inline void list_replace(struct list_head *old, | ||
501 | struct list_head *new) | ||
502 | { | ||
503 | new->next = old->next; | ||
504 | new->next->prev = new; | ||
505 | new->prev = old->prev; | ||
506 | new->prev->next = new; | ||
507 | } | ||
508 | |||
509 | static inline void list_replace_init(struct list_head *old, | ||
510 | struct list_head *new) | ||
511 | { | ||
512 | list_replace(old, new); | ||
513 | INIT_LIST_HEAD(old); | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * list_del_init - deletes entry from list and reinitialize it. | ||
518 | * @entry: the element to delete from the list. | ||
519 | */ | ||
520 | static inline void list_del_init(struct list_head *entry) | ||
521 | { | ||
522 | __list_del(entry->prev, entry->next); | ||
523 | INIT_LIST_HEAD(entry); | ||
524 | } | ||
525 | |||
526 | /** | ||
527 | * list_move - delete from one list and add as another's head | ||
528 | * @list: the entry to move | ||
529 | * @head: the head that will precede our entry | ||
530 | */ | ||
531 | static inline void list_move(struct list_head *list, struct list_head *head) | ||
532 | { | ||
533 | __list_del(list->prev, list->next); | ||
534 | list_add(list, head); | ||
535 | } | ||
536 | |||
537 | /** | ||
538 | * list_move_tail - delete from one list and add as another's tail | ||
539 | * @list: the entry to move | ||
540 | * @head: the head that will follow our entry | ||
541 | */ | ||
542 | static inline void list_move_tail(struct list_head *list, | ||
543 | struct list_head *head) | ||
544 | { | ||
545 | __list_del(list->prev, list->next); | ||
546 | list_add_tail(list, head); | ||
547 | } | ||
548 | |||
549 | /** | ||
550 | * list_is_last - tests whether @list is the last entry in list @head | ||
551 | * @list: the entry to test | ||
552 | * @head: the head of the list | ||
553 | */ | ||
554 | static inline int list_is_last(const struct list_head *list, | ||
555 | const struct list_head *head) | ||
556 | { | ||
557 | return list->next == head; | ||
558 | } | ||
559 | |||
560 | /** | ||
561 | * list_empty - tests whether a list is empty | ||
562 | * @head: the list to test. | ||
563 | */ | ||
564 | static inline int list_empty(const struct list_head *head) | ||
565 | { | ||
566 | return head->next == head; | ||
567 | } | ||
568 | |||
569 | static inline void __list_splice(struct list_head *list, | ||
570 | struct list_head *head) | ||
571 | { | ||
572 | struct list_head *first = list->next; | ||
573 | struct list_head *last = list->prev; | ||
574 | struct list_head *at = head->next; | ||
575 | |||
576 | first->prev = head; | ||
577 | head->next = first; | ||
578 | |||
579 | last->next = at; | ||
580 | at->prev = last; | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * list_splice - join two lists | ||
585 | * @list: the new list to add. | ||
586 | * @head: the place to add it in the first list. | ||
587 | */ | ||
588 | static inline void list_splice(struct list_head *list, struct list_head *head) | ||
589 | { | ||
590 | if (!list_empty(list)) { | ||
591 | __list_splice(list, head); | ||
592 | } | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * list_splice_init - join two lists and reinitialise the emptied list. | ||
597 | * @list: the new list to add. | ||
598 | * @head: the place to add it in the first list. | ||
599 | * | ||
600 | * The list at @list is reinitialised | ||
601 | */ | ||
602 | static inline void list_splice_init(struct list_head *list, | ||
603 | struct list_head *head) | ||
604 | { | ||
605 | if (!list_empty(list)) { | ||
606 | __list_splice(list, head); | ||
607 | INIT_LIST_HEAD(list); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | /** | ||
612 | * list_entry - get the struct for this entry | ||
613 | * @ptr: the &struct list_head pointer. | ||
614 | * @type: the type of the struct this is embedded in. | ||
615 | * @member: the name of the list_struct within the struct. | ||
616 | */ | ||
617 | #define list_entry(ptr, type, member) \ | ||
618 | container_of(ptr, type, member) | ||
619 | |||
620 | /** | ||
621 | * list_for_each - iterate over a list | ||
622 | * @pos: the &struct list_head to use as a loop cursor. | ||
623 | * @head: the head for your list. | ||
624 | */ | ||
625 | #define list_for_each(pos, head) \ | ||
626 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ | ||
627 | pos = pos->next) | ||
628 | |||
629 | /** | ||
630 | * __list_for_each - iterate over a list | ||
631 | * @pos: the &struct list_head to use as a loop cursor. | ||
632 | * @head: the head for your list. | ||
633 | * | ||
634 | * This variant differs from list_for_each() in that it's the | ||
635 | * simplest possible list iteration code, no prefetching is done. | ||
636 | * Use this for code that knows the list to be very short (empty | ||
637 | * or 1 entry) most of the time. | ||
638 | */ | ||
639 | #define __list_for_each(pos, head) \ | ||
640 | for (pos = (head)->next; pos != (head); pos = pos->next) | ||
641 | |||
642 | /** | ||
643 | * list_for_each_prev - iterate over a list backwards | ||
644 | * @pos: the &struct list_head to use as a loop cursor. | ||
645 | * @head: the head for your list. | ||
646 | */ | ||
647 | #define list_for_each_prev(pos, head) \ | ||
648 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ | ||
649 | pos = pos->prev) | ||
650 | |||
651 | /** | ||
652 | * list_for_each_entry - iterate over list of given type | ||
653 | * @pos: the type * to use as a loop cursor. | ||
654 | * @head: the head for your list. | ||
655 | * @member: the name of the list_struct within the struct. | ||
656 | */ | ||
657 | #define list_for_each_entry(pos, head, member) \ | ||
658 | for (pos = list_entry((head)->next, typeof(*pos), member); \ | ||
659 | prefetch(pos->member.next), &pos->member != (head); \ | ||
660 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
661 | |||
662 | /** | ||
663 | * list_for_each_entry_reverse - iterate backwards over list of given type. | ||
664 | * @pos: the type * to use as a loop cursor. | ||
665 | * @head: the head for your list. | ||
666 | * @member: the name of the list_struct within the struct. | ||
667 | */ | ||
668 | #define list_for_each_entry_reverse(pos, head, member) \ | ||
669 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ | ||
670 | prefetch(pos->member.prev), &pos->member != (head); \ | ||
671 | pos = list_entry(pos->member.prev, typeof(*pos), member)) | ||
672 | |||
673 | /** | ||
674 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() | ||
675 | * @pos: the type * to use as a start point | ||
676 | * @head: the head of the list | ||
677 | * @member: the name of the list_struct within the struct. | ||
678 | * | ||
679 | * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). | ||
680 | */ | ||
681 | #define list_prepare_entry(pos, head, member) \ | ||
682 | ((pos) ? : list_entry(head, typeof(*pos), member)) | ||
683 | |||
684 | /** | ||
685 | * list_for_each_entry_continue - continue iteration over list of given type | ||
686 | * @pos: the type * to use as a loop cursor. | ||
687 | * @head: the head for your list. | ||
688 | * @member: the name of the list_struct within the struct. | ||
689 | * | ||
690 | * Continue to iterate over list of given type, continuing after | ||
691 | * the current position. | ||
692 | */ | ||
693 | #define list_for_each_entry_continue(pos, head, member) \ | ||
694 | for (pos = list_entry(pos->member.next, typeof(*pos), member); \ | ||
695 | prefetch(pos->member.next), &pos->member != (head); \ | ||
696 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
697 | |||
698 | /** | ||
699 | * list_for_each_entry_from - iterate over list of given type from the current point | ||
700 | * @pos: the type * to use as a loop cursor. | ||
701 | * @head: the head for your list. | ||
702 | * @member: the name of the list_struct within the struct. | ||
703 | * | ||
704 | * Iterate over list of given type, continuing from current position. | ||
705 | */ | ||
706 | #define list_for_each_entry_from(pos, head, member) \ | ||
707 | for (; prefetch(pos->member.next), &pos->member != (head); \ | ||
708 | pos = list_entry(pos->member.next, typeof(*pos), member)) | ||
709 | |||
710 | #endif /*_LINKED_LIST_H_*/ | ||