blob: 02a4809bca9f262a7c0ed8d9493da285ff572f4d [file] [log] [blame]
zw161486e92e3a82007-05-09 19:58:49 -07001/*
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
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +08008 * Copyright (c) 2009, Intel Corporation.
zw161486e92e3a82007-05-09 19:58:49 -07009 * 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
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080035/*
36 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
37 * Use is subject to license terms.
38 */
zw161486e92e3a82007-05-09 19:58:49 -070039
40#ifndef _DRM_LINUX_LIST_H_
41#define _DRM_LINUX_LIST_H_
42
43struct list_head {
44 struct list_head *next, *prev;
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080045 caddr_t contain_ptr;
zw161486e92e3a82007-05-09 19:58:49 -070046};
47
48/* Cheat, assume the list_head is at the start of the struct */
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080049#define list_entry(entry, type, member) (type *)(uintptr_t)(entry->contain_ptr)
zw161486e92e3a82007-05-09 19:58:49 -070050
51#define INIT_LIST_HEAD(head) { \
52 (head)->next = head; \
53 (head)->prev = head; \
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080054 (head)->contain_ptr = (caddr_t)head; \
zw161486e92e3a82007-05-09 19:58:49 -070055}
56
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080057#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) { \
zw161486e92e3a82007-05-09 19:58:49 -070066 (entry)->prev = (head)->prev; \
67 (entry)->next = head; \
68 (head)->prev->next = entry; \
69 (head)->prev = entry; \
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080070 (entry)->contain_ptr = con_ptr; \
zw161486e92e3a82007-05-09 19:58:49 -070071}
72
73#define list_del(entry) { \
74 (entry)->next->prev = (entry)->prev; \
75 (entry)->prev->next = (entry)->next; \
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080076 (entry)->contain_ptr = NULL; \
zw161486e92e3a82007-05-09 19:58:49 -070077}
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; \
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080084 entry != head; \
zw161486e92e3a82007-05-09 19:58:49 -070085 entry = temp, temp = temp->next)
86
miao chen - Sun Microsystems - Beijing China0035d212009-12-05 13:25:40 +080087#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
zw161486e92e3a82007-05-09 19:58:49 -070099#endif /* _DRM_LINUX_LIST_H_ */