1450N/A/*
1450N/A * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A/*
1450N/A * drm_linux_list.h -- linux list functions for the BSDs.
1450N/A * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
1450N/A */
1450N/A/*
1450N/A * -
1450N/A * Copyright 2003 Eric Anholt
1450N/A * Copyright (c) 2009, 2012, Intel Corporation.
1450N/A * All Rights Reserved.
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1450N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1450N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1450N/A * OTHER DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Eric Anholt <anholt@FreeBSD.org>
1450N/A *
1450N/A */
1450N/A
1450N/A#ifndef _DRM_LINUX_LIST_H_
1450N/A#define _DRM_LINUX_LIST_H_
1450N/A
1450N/A#include <sys/types.h>
1450N/A#include <sys/param.h>
1450N/Astruct list_head {
1450N/A struct list_head *next, *prev;
1450N/A caddr_t contain_ptr;
1450N/A};
1450N/A
1450N/A/* Cheat, assume the list_head is at the start of the struct */
1450N/A#define container_of(ptr, type, member) \
1450N/A ((type *)(uintptr_t)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
1450N/A
1450N/A#define list_entry(ptr, type, member) \
1450N/A ptr ? ((type *)(uintptr_t)(ptr->contain_ptr)) : NULL
1450N/A
1450N/A#define list_first_entry(ptr, type, member) \
1450N/A list_entry((ptr)->next, type, member)
1450N/A
1450N/A#define list_empty(head) \
1450N/A ((head)->next == head)
1450N/A
1450N/A#define INIT_LIST_HEAD(head) \
1450N/Ado { \
1450N/A (head)->next = head; \
1450N/A (head)->prev = head; \
1450N/A (head)->contain_ptr = NULL; \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_add(ptr, head, entry) \
1450N/Ado { \
1450N/A struct list_head *n_node = (head)->next; \
1450N/A (ptr)->prev = head; \
1450N/A (ptr)->next = (head)->next; \
1450N/A n_node->prev = ptr; \
1450N/A (head)->next = ptr; \
1450N/A (ptr)->contain_ptr = entry; \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_add_tail(ptr, head, entry) \
1450N/Ado { \
1450N/A struct list_head *p_node = (head)->prev; \
1450N/A (ptr)->prev = (head)->prev; \
1450N/A (ptr)->next = head; \
1450N/A p_node->next = ptr; \
1450N/A (head)->prev = ptr; \
1450N/A (ptr)->contain_ptr = entry; \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_del(ptr) \
1450N/Ado { \
1450N/A struct list_head *n_node = (ptr)->next; \
1450N/A struct list_head *p_node = (ptr)->prev; \
1450N/A n_node->prev = (ptr)->prev; \
1450N/A p_node->next = (ptr)->next; \
1450N/A (ptr)->prev = NULL; \
1450N/A (ptr)->next = NULL; \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_del_init(ptr) \
1450N/Ado { \
1450N/A list_del(ptr); \
1450N/A INIT_LIST_HEAD(ptr); \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_move(ptr, head, entry) \
1450N/Ado { \
1450N/A list_del(ptr); \
1450N/A list_add(ptr, head, entry); \
1450N/A} while (*"\0")
1450N/A
1450N/A
1450N/A#define list_move_tail(ptr, head, entry) \
1450N/Ado { \
1450N/A list_del(ptr); \
1450N/A list_add_tail(ptr, head, entry); \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_splice(list, be, ne) \
1450N/Ado { \
1450N/A if (!list_empty(list)) { \
1450N/A struct list_head *first = (list)->next; \
1450N/A struct list_head *last = (list)->prev; \
1450N/A first->prev = be; \
1450N/A (be)->next = first; \
1450N/A last->next = ne; \
1450N/A (ne)->prev = last; \
1450N/A } \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_replace(old, new) \
1450N/Ado { \
1450N/A struct list_head *old_list = old; \
1450N/A struct list_head *new_list = new; \
1450N/A new_list->next = old_list->next; \
1450N/A new_list->next->prev = new_list; \
1450N/A new_list->prev = old_list->prev; \
1450N/A new_list->prev->next = new_list; \
1450N/A} while (*"\0")
1450N/A
1450N/A#define list_for_each(pos, head) \
1450N/A for (pos = (head)->next; pos != head; pos = (pos)->next)
1450N/A
1450N/A#define list_for_each_safe(pos, n, head) \
1450N/A for (pos = (head)->next, n = (pos)->next; \
1450N/A pos != head; \
1450N/A pos = n, n = n->next)
1450N/A
1450N/A#define list_for_each_entry(pos, type, head, member) \
1450N/A for (pos = list_entry((head)->next, type, member); pos; \
1450N/A pos = list_entry(pos->member.next, type, member))
1450N/A
1450N/A#define list_for_each_entry_safe(pos, n, type, head, member) \
1450N/A for (pos = list_entry((head)->next, type, member), \
1450N/A n = pos ? list_entry(pos->member.next, type, member) : pos; \
1450N/A pos; \
1450N/A pos = n, \
1450N/A n = list_entry((n ? n->member.next : (head)->next), type, member))
1450N/A
1450N/A#define list_for_each_entry_continue_reverse(pos, type, head, member) \
1450N/A for (pos = list_entry(pos->member.prev, type, member); \
1450N/A pos; \
1450N/A pos = list_entry(pos->member.prev, type, member))
1450N/A#endif /* _DRM_LINUX_LIST_H_ */