xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_list.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2020 Rockchip Electronics Co. Ltd.
4  *
5  * Author: Zorro Liu <zorro.liu@rock-chips.com>
6  */
7 
8 #ifndef _BUF_LIST_H_
9 #define _BUF_LIST_H_
10 
11 #define BUF_LIST_MAX_NUMBER 100
12 
13 typedef struct buf_list_s {
14 	/** number of elements */
15 	int nb_elt;
16 	/** list node */
17 	int **array_elements;
18 	int maxelements;
19 } buf_list_t;
20 
21 /** @brief initializes the list struct
22   *
23   * @param *li - pointer to list struct
24   * @returns 0 on success, 1 on error
25   */
26 int buf_list_init(buf_list_t **li, int maxelements);
27 
28 /** @brief uninitializes the list struct
29   *
30   * @param *li - the list
31   * @returns 0 on success, 1 on error
32   */
33 int buf_list_uninit(buf_list_t *li);
34 
35 /** @brief query if i'nth element exists
36   *
37   * @param *li - the list
38   * @param i   - position
39   * @returns 0 on success, 1 on error
40   */
41 int buf_list_eol(buf_list_t *li, int i);
42 
43 /** @brief return the element at position
44   *
45   * @param *li - the list
46   * @param pos - position
47   * @returns pointer to element on success, NULL on error.
48   */
49 int *buf_list_get(buf_list_t *li, int pos);
50 
51 /** @brief removes the element at position
52   *
53   * @param *li - the list
54   * @param pos - position
55   * @returns - on success, 1 on error
56   */
57 int buf_list_remove(buf_list_t *li, int pos);
58 
59 /** @brief adds the element at position
60   *
61   * @param *li - the list
62   * @param *el - element
63   * @param pos - position (-1 means the end)
64   * @returns - on success, 1 on error
65   */
66 int buf_list_add(buf_list_t *li, int *el, int pos);
67 
68 /** @brief search the node at list, with the given compare function
69   *
70   * @param *list    - the list
71   * @param *node    - node to be matched
72   * @param cmp_func - compare function. compare function must return -1, 0, 1
73 		for less than, equal to, and greater than
74   * @returns - on success, 1 on error
75   */
76 int *buf_list_find(buf_list_t *list, int *node, int (*cmp_func)(int *, int *));
77 
78 /** @brief return the position of node
79   *
80   * @param *list - the list
81   * @param *node - element
82   * @returns - position on success, -1 on error
83   */
84 int buf_list_get_pos(buf_list_t *list, int *node);
85 
86 /** @brief set the node element at a specified position
87   *
88   * @param *list - the list
89   * @param *el - element
90   * @pos pos - position
91   * @returns - 1 on success, -1 on error
92   */
93 int buf_list_set(buf_list_t *li, int *el, int pos);
94 
95 #endif
96