1 /*
2 * drm_linux_list.h -- linux list functions for the BSDs.
3 * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
4 */
5 /*
6 * -
7 * Copyright 2003 Eric Anholt
8 * Copyright (c) 2009, Intel Corporation.
9 * All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 *
30 * Authors:
31 * Eric Anholt <anholt@FreeBSD.org>
32 *
33 */
34
35 /*
36 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
37 * Use is subject to license terms.
38 */
39
40 #ifndef _DRM_LINUX_LIST_H_
41 #define _DRM_LINUX_LIST_H_
42
43 struct list_head {
44 struct list_head *next, *prev;
45 caddr_t contain_ptr;
46 };
47
48 /* Cheat, assume the list_head is at the start of the struct */
49 #define list_entry(entry, type, member) (type *)(uintptr_t)(entry->contain_ptr)
50
51 #define INIT_LIST_HEAD(head) { \
52 (head)->next = head; \
53 (head)->prev = head; \
54 (head)->contain_ptr = (caddr_t)head; \
55 }
56
57 #define list_add(entry, head, con_ptr) { \
58 (head)->next->prev = entry; \
59 (entry)->next = (head)->next; \
60 (entry)->prev = head; \
61 (head)->next = entry; \
62 (entry)->contain_ptr = con_ptr; \
63 }
64
65 #define list_add_tail(entry, head, con_ptr) { \
66 (entry)->prev = (head)->prev; \
67 (entry)->next = head; \
68 (head)->prev->next = entry; \
69 (head)->prev = entry; \
70 (entry)->contain_ptr = con_ptr; \
71 }
72
73 #define list_del(entry) { \
74 (entry)->next->prev = (entry)->prev; \
75 (entry)->prev->next = (entry)->next; \
76 (entry)->contain_ptr = NULL; \
77 }
78
79 #define list_for_each(entry, head) \
80 for (entry = (head)->next; entry != head; entry = (entry)->next)
81
82 #define list_for_each_safe(entry, temp, head) \
83 for (entry = (head)->next, temp = (entry)->next; \
84 entry != head; \
85 entry = temp, temp = temp->next)
86
87 #define list_del_init(entry) { \
88 list_del(entry); \
89 INIT_LIST_HEAD(entry); \
90 }
91
92 #define list_move_tail(entry, head, con_ptr) { \
93 list_del(entry); \
94 list_add_tail(entry, head, con_ptr); \
95 }
96
97 #define list_empty(head) ((head)->next == head)
98
99 #endif /* _DRM_LINUX_LIST_H_ */