6732e031320e4e757cbd38f00f3544364932227a
[dpdk.git] / drivers / net / bnxt / tf_core / stack.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5 #ifndef _STACK_H_
6 #define _STACK_H_
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stdbool.h>
11 #include <stdint.h>
12
13 /** Stack data structure
14  */
15 struct stack {
16         int max;         /**< Maximum number of entries */
17         int top;         /**< maximum value in stack */
18         uint32_t *items; /**< items in the stack */
19 };
20
21 /** Initialize stack of uint32_t elements
22  *
23  *  [in] num_entries
24  *    maximum number of elements in the stack
25  *
26  *  [in] items
27  *    pointer to items (must be sized to (uint32_t * num_entries)
28  *
29  *  s[in] st
30  *    pointer to the stack structure
31  *
32  *  return
33  *    0 for success
34  */
35 int stack_init(int num_entries,
36                uint32_t *items,
37                struct stack *st);
38
39 /** Return the address of the stack contents
40  *
41  *  [in] st
42  *    pointer to the stack
43  *
44  *  return
45  *    pointer to the stack contents
46  */
47 uint32_t *stack_items(struct stack *st);
48
49 /** Return the size of the stack
50  *
51  *  [in] st
52  *    pointer to the stack
53  *
54  *  return
55  *    number of elements
56  */
57 int32_t stack_size(struct stack *st);
58
59 /** Check if the stack is empty
60  *
61  * [in] st
62  *   pointer to the stack
63  *
64  * return
65  *   true or false
66  */
67 bool stack_is_empty(struct stack *st);
68
69 /** Check if the stack is full
70  *
71  * [in] st
72  *   pointer to the stack
73  *
74  * return
75  *   true or false
76  */
77 bool stack_is_full(struct stack *st);
78
79 /** Add  element x to  the stack
80  *
81  * [in] st
82  *   pointer to the stack
83  *
84  * [in] x
85  *   value to push on the stack
86  * return
87  *  0 for success
88  */
89 int stack_push(struct stack *st, uint32_t x);
90
91 /** Pop top element x from the stack and return
92  * in user provided location.
93  *
94  * [in] st
95  *   pointer to the stack
96  *
97  * [in, out] x
98  *  pointer to where the value popped will be written
99  *
100  * return
101  *  0 for success
102  */
103 int stack_pop(struct stack *st, uint32_t *x);
104
105 /** Dump stack information
106  *
107  * Warning: Don't use for large stacks due to prints
108  *
109  * [in] st
110  *   pointer to the stack
111  *
112  * return
113  *    none
114  */
115 void stack_dump(struct stack *st);
116
117 #endif /* _STACK_H_ */