DRM from FreeBSD current, tested for r600
[dragonfly.git] / sys / dev / drm / drm_linux_list.h
blobe5a478a28f5b5be91b69f5aa560dc6c0b8b3b042
1 /* drm_linux_list.h -- linux list functions for the BSDs.
2 * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
3 */
4 /*-
5 * Copyright 2003 Eric Anholt
6 * All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
27 * Authors:
28 * Eric Anholt <anholt@FreeBSD.org>
32 #include <sys/cdefs.h>
34 #ifndef _DRM_LINUX_LIST_H_
35 #define _DRM_LINUX_LIST_H_
37 struct list_head {
38 struct list_head *next, *prev;
41 #define list_entry(ptr, type, member) container_of(ptr,type,member)
42 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
44 static __inline__ void
45 INIT_LIST_HEAD(struct list_head *head) {
46 (head)->next = head;
47 (head)->prev = head;
50 static __inline__ int
51 list_empty(struct list_head *head) {
52 return (head)->next == head;
55 static __inline__ void
56 list_add(struct list_head *new, struct list_head *head) {
57 (head)->next->prev = new;
58 (new)->next = (head)->next;
59 (new)->prev = head;
60 (head)->next = new;
63 static __inline__ void
64 list_add_tail(struct list_head *entry, struct list_head *head) {
65 (entry)->prev = (head)->prev;
66 (entry)->next = head;
67 (head)->prev->next = entry;
68 (head)->prev = entry;
71 static __inline__ void
72 list_del(struct list_head *entry) {
73 (entry)->next->prev = (entry)->prev;
74 (entry)->prev->next = (entry)->next;
77 static __inline__ void
78 list_del_init(struct list_head *entry) {
79 (entry)->next->prev = (entry)->prev;
80 (entry)->prev->next = (entry)->next;
81 INIT_LIST_HEAD(entry);
84 #define list_for_each(entry, head) \
85 for (entry = (head)->next; entry != head; entry = (entry)->next)
87 #define list_for_each_prev(entry, head) \
88 for (entry = (head)->prev; entry != (head); \
89 entry = entry->prev)
91 #define list_for_each_safe(entry, temp, head) \
92 for (entry = (head)->next, temp = (entry)->next; \
93 entry != head; \
94 entry = temp, temp = entry->next)
96 /**
97 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
98 * @pos: the type * to use as a loop cursor.
99 * @n: another type * to use as temporary storage
100 * @head: the head for your list.
101 * @member: the name of the list_struct within the struct.
103 #define list_for_each_entry_safe(pos, n, head, member) \
104 for (pos = list_entry((head)->next, __typeof(*pos), member), \
105 n = list_entry(pos->member.next, __typeof(*pos), member); \
106 &pos->member != (head); \
107 pos = n, n = list_entry(n->member.next, __typeof(*n), member))
109 #endif /* _DRM_LINUX_LIST_H_ */