181966bceSXin LI /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4f29c86f1SXin LI * Copyright (c) 2005-2011 HighPoint Technologies, Inc.
581966bceSXin LI * All rights reserved.
681966bceSXin LI *
781966bceSXin LI * Redistribution and use in source and binary forms, with or without
881966bceSXin LI * modification, are permitted provided that the following conditions
981966bceSXin LI * are met:
1081966bceSXin LI * 1. Redistributions of source code must retain the above copyright
1181966bceSXin LI * notice, this list of conditions and the following disclaimer.
1281966bceSXin LI * 2. Redistributions in binary form must reproduce the above copyright
1381966bceSXin LI * notice, this list of conditions and the following disclaimer in the
1481966bceSXin LI * documentation and/or other materials provided with the distribution.
1581966bceSXin LI *
1681966bceSXin LI * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1781966bceSXin LI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1881966bceSXin LI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1981966bceSXin LI * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2081966bceSXin LI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2181966bceSXin LI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2281966bceSXin LI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2381966bceSXin LI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2481966bceSXin LI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2581966bceSXin LI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2681966bceSXin LI * SUCH DAMAGE.
2781966bceSXin LI */
2881966bceSXin LI
2981966bceSXin LI #include <dev/hpt27xx/hpt27xx_config.h>
3081966bceSXin LI
3181966bceSXin LI #ifndef _HPT_LIST_H_
3281966bceSXin LI #define _HPT_LIST_H_
3381966bceSXin LI
3481966bceSXin LI #ifndef _LINUX_LIST_H
3581966bceSXin LI
3681966bceSXin LI #ifndef HPT_INLINE
3781966bceSXin LI #define HPT_INLINE __inline
3881966bceSXin LI #endif
3981966bceSXin LI
4081966bceSXin LI struct list_head {
4181966bceSXin LI struct list_head *next, *prev;
4281966bceSXin LI };
4381966bceSXin LI
4481966bceSXin LI #define INIT_LIST_HEAD(ptr) do { (ptr)->next = (ptr); (ptr)->prev = (ptr); } while (0)
4581966bceSXin LI
__list_add(struct list_head * _new,struct list_head * prev,struct list_head * next)4681966bceSXin LI static HPT_INLINE void __list_add(struct list_head * _new, struct list_head * prev, struct list_head * next)
4781966bceSXin LI {
4881966bceSXin LI next->prev = _new;
4981966bceSXin LI _new->next = next;
5081966bceSXin LI _new->prev = prev;
5181966bceSXin LI prev->next = _new;
5281966bceSXin LI }
5381966bceSXin LI
list_add(struct list_head * _new,struct list_head * head)5481966bceSXin LI static HPT_INLINE void list_add(struct list_head *_new, struct list_head *head)
5581966bceSXin LI {
5681966bceSXin LI __list_add(_new, head, head->next);
5781966bceSXin LI }
5881966bceSXin LI
list_add_tail(struct list_head * _new,struct list_head * head)5981966bceSXin LI static HPT_INLINE void list_add_tail(struct list_head *_new, struct list_head *head)
6081966bceSXin LI {
6181966bceSXin LI __list_add(_new, head->prev, head);
6281966bceSXin LI }
6381966bceSXin LI
__list_del(struct list_head * prev,struct list_head * next)6481966bceSXin LI static HPT_INLINE void __list_del(struct list_head * prev, struct list_head * next)
6581966bceSXin LI {
6681966bceSXin LI next->prev = prev;
6781966bceSXin LI prev->next = next;
6881966bceSXin LI }
6981966bceSXin LI
list_del(struct list_head * entry)7081966bceSXin LI static HPT_INLINE void list_del(struct list_head *entry)
7181966bceSXin LI {
7281966bceSXin LI __list_del(entry->prev, entry->next);
7381966bceSXin LI }
7481966bceSXin LI
list_del_init(struct list_head * entry)7581966bceSXin LI static HPT_INLINE void list_del_init(struct list_head *entry)
7681966bceSXin LI {
7781966bceSXin LI __list_del(entry->prev, entry->next);
7881966bceSXin LI INIT_LIST_HEAD(entry);
7981966bceSXin LI }
8081966bceSXin LI
list_empty(struct list_head * head)8181966bceSXin LI static HPT_INLINE int list_empty(struct list_head *head)
8281966bceSXin LI {
8381966bceSXin LI HPT_ASSERT(!(head->next==head && head->prev!=head));
8481966bceSXin LI return head->next == head;
8581966bceSXin LI }
8681966bceSXin LI
__list_splice(struct list_head * list,struct list_head * head)8781966bceSXin LI static HPT_INLINE void __list_splice(struct list_head *list,
8881966bceSXin LI struct list_head *head)
8981966bceSXin LI {
9081966bceSXin LI struct list_head *first = list->next;
9181966bceSXin LI struct list_head *last = list->prev;
9281966bceSXin LI struct list_head *at = head->next;
9381966bceSXin LI
9481966bceSXin LI first->prev = head;
9581966bceSXin LI head->next = first;
9681966bceSXin LI
9781966bceSXin LI last->next = at;
9881966bceSXin LI at->prev = last;
9981966bceSXin LI }
10081966bceSXin LI
list_splice(struct list_head * list,struct list_head * head)10181966bceSXin LI static HPT_INLINE void list_splice(struct list_head *list, struct list_head *head)
10281966bceSXin LI {
10381966bceSXin LI if (!list_empty(list))
10481966bceSXin LI __list_splice(list, head);
10581966bceSXin LI }
10681966bceSXin LI
list_splice_init(struct list_head * list,struct list_head * head)10781966bceSXin LI static HPT_INLINE void list_splice_init(struct list_head *list, struct list_head *head)
10881966bceSXin LI {
10981966bceSXin LI if (!list_empty(list)) {
11081966bceSXin LI __list_splice(list, head);
11181966bceSXin LI INIT_LIST_HEAD(list);
11281966bceSXin LI }
11381966bceSXin LI }
11481966bceSXin LI
11581966bceSXin LI #define list_entry(ptr, type, member) \
11681966bceSXin LI ((type *)((char *)(ptr)-(HPT_UPTR)(&((type *)0)->member)))
11781966bceSXin LI
11881966bceSXin LI #define list_for_each(pos, head) \
11981966bceSXin LI for (pos = (head)->next; pos != (head); pos = pos->next)
12081966bceSXin LI
12181966bceSXin LI #define list_for_each_safe(pos, n, head) \
12281966bceSXin LI for (pos = (head)->next, n = pos->next; pos != (head); \
12381966bceSXin LI pos = n, n = pos->next)
12481966bceSXin LI
12581966bceSXin LI #define get_first_item(attached, type, member) \
12681966bceSXin LI ((type *)((char *)((attached)->next)-(HPT_UPTR)(&((type *)0)->member)))
12781966bceSXin LI
12881966bceSXin LI #endif
12981966bceSXin LI
13081966bceSXin LI #endif
131