125184Sjkh/*-
2113674Smtm * Copyright (c) 2005-2011 HighPoint Technologies, Inc.
3113674Smtm * All rights reserved.
4113674Smtm *
5113674Smtm * Redistribution and use in source and binary forms, with or without
6113674Smtm * modification, are permitted provided that the following conditions
7113674Smtm * are met:
8113674Smtm * 1. Redistributions of source code must retain the above copyright
9113674Smtm *    notice, this list of conditions and the following disclaimer.
10113674Smtm * 2. Redistributions in binary form must reproduce the above copyright
11113674Smtm *    notice, this list of conditions and the following disclaimer in the
12113674Smtm *    documentation and/or other materials provided with the distribution.
13113674Smtm *
14113674Smtm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15113674Smtm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16113674Smtm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17113674Smtm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18113674Smtm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19113674Smtm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20113674Smtm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21113674Smtm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22113674Smtm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23113674Smtm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24113674Smtm * SUCH DAMAGE.
2550472Speter *
2666830Sobrien * $FreeBSD: releng/10.3/sys/dev/hpt27xx/list.h 284879 2015-06-26 19:55:01Z delphij $
2725184Sjkh */
28113674Smtm
29113674Smtm#include <dev/hpt27xx/hpt27xx_config.h>
30113674Smtm
31113674Smtm#ifndef _HPT_LIST_H_
3225184Sjkh#define _HPT_LIST_H_
33113674Smtm
34113674Smtm#ifndef _LINUX_LIST_H
35113674Smtm
36113674Smtm#ifndef HPT_INLINE
37113674Smtm#define HPT_INLINE __inline
38113674Smtm#endif
39113674Smtm
40113674Smtmstruct list_head {
41113674Smtm	struct list_head *next, *prev;
42113674Smtm};
43113674Smtm
44113674Smtm#define INIT_LIST_HEAD(ptr) do { (ptr)->next = (ptr); (ptr)->prev = (ptr); } while (0)
45113674Smtm
46113674Smtmstatic HPT_INLINE void __list_add(struct list_head * _new, struct list_head * prev, struct list_head * next)
47113674Smtm{
4825184Sjkh	next->prev = _new;
49116029Smtm	_new->next = next;
50116029Smtm	_new->prev = prev;
51116029Smtm	prev->next = _new;
52116100Smtm}
53116029Smtm
54116029Smtmstatic HPT_INLINE void list_add(struct list_head *_new, struct list_head *head)
55116029Smtm{
56116029Smtm	__list_add(_new, head, head->next);
57116029Smtm}
58116029Smtm
59116029Smtmstatic HPT_INLINE void list_add_tail(struct list_head *_new, struct list_head *head)
60116029Smtm{
61116029Smtm	__list_add(_new, head->prev, head);
62116029Smtm}
63116029Smtm
64116029Smtmstatic HPT_INLINE void __list_del(struct list_head * prev, struct list_head * next)
65116029Smtm{
66116029Smtm	next->prev = prev;
67116029Smtm	prev->next = next;
68116029Smtm}
69116029Smtm
70116032Smtmstatic HPT_INLINE void list_del(struct list_head *entry)
71116032Smtm{
72116032Smtm	__list_del(entry->prev, entry->next);
73116029Smtm}
74116029Smtm
75116029Smtmstatic HPT_INLINE void list_del_init(struct list_head *entry)
76116029Smtm{
77116029Smtm	__list_del(entry->prev, entry->next);
78116029Smtm	INIT_LIST_HEAD(entry);
79116029Smtm}
80113674Smtm
81113674Smtmstatic HPT_INLINE int list_empty(struct list_head *head)
82113674Smtm{
83113674Smtm	HPT_ASSERT(!(head->next==head && head->prev!=head));
84113674Smtm	return head->next == head;
85113674Smtm}
86113674Smtm
87113674Smtmstatic HPT_INLINE void __list_splice(struct list_head *list,
88113674Smtm				 struct list_head *head)
89113674Smtm{
90113674Smtm	struct list_head *first = list->next;
91113674Smtm	struct list_head *last = list->prev;
92113674Smtm	struct list_head *at = head->next;
93113674Smtm
94113674Smtm	first->prev = head;
95113674Smtm	head->next = first;
96113674Smtm
97113674Smtm	last->next = at;
98113674Smtm	at->prev = last;
99113674Smtm}
100113674Smtm
101100280Sgordonstatic HPT_INLINE void list_splice(struct list_head *list, struct list_head *head)
102116029Smtm{
103116029Smtm	if (!list_empty(list))
104116029Smtm		__list_splice(list, head);
105116029Smtm}
106116029Smtm
107116029Smtmstatic HPT_INLINE void list_splice_init(struct list_head *list, struct list_head *head)
108116029Smtm{
109116029Smtm	if (!list_empty(list)) {
110116029Smtm		__list_splice(list, head);
111116029Smtm		INIT_LIST_HEAD(list);
112116029Smtm	}
113116029Smtm}
114116029Smtm
115116029Smtm#define list_entry(ptr, type, member) \
116116029Smtm	((type *)((char *)(ptr)-(HPT_UPTR)(&((type *)0)->member)))
117116029Smtm
118116029Smtm#define list_for_each(pos, head) \
119116029Smtm	for (pos = (head)->next; pos != (head); pos = pos->next)
120116029Smtm
121116029Smtm#define list_for_each_safe(pos, n, head) \
122116029Smtm	for (pos = (head)->next, n = pos->next; pos != (head); \
123116029Smtm		pos = n, n = pos->next)
124113674Smtm
125113674Smtm#define get_first_item(attached, type, member) \
126113674Smtm	((type *)((char *)((attached)->next)-(HPT_UPTR)(&((type *)0)->member)))
127113674Smtm
128113674Smtm#endif
129113674Smtm
130100280Sgordon#endif
131113674Smtm