summaryrefslogtreecommitdiff
path: root/target/linux/generic/files/crypto/ocf/kirkwood/mvHal/common/mvStack.h
blob: e247e61c2d9de5c8ccfb4038f6a120262d8d61ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/******************************************************************************* 
*                   Copyright 2003, Marvell Semiconductor Israel LTD.          * 
* THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL.                      * 
* NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT  * 
* OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE        * 
* DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL.     * 
* THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED,       * 
* IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE.   * 
*                                                                              * 
* MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES, * 
* MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL    * 
* SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K.  * 
* (MJKK), MARVELL SEMICONDUCTOR ISRAEL LTD (MSIL).                             * 
********************************************************************************
* mvStack.h - Header File for :
*
* FILENAME:    $Workfile: mvStack.h $
* REVISION:    $Revision: 1.1 $
* LAST UPDATE: $Modtime:  $
*
* DESCRIPTION:
*     This file defines simple Stack (LIFO) functionality.
*
*******************************************************************************/

#ifndef __mvStack_h__
#define __mvStack_h__


/* includes */
#include "mvTypes.h"


/* defines  */


/* typedefs */
/* Data structure describes general purpose Stack */
typedef struct 
{
    int     stackIdx;
    int     numOfElements;
    MV_U32* stackElements;
} MV_STACK;

static INLINE MV_BOOL mvStackIsFull(void* stackHndl)
{	
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

    if(pStack->stackIdx == pStack->numOfElements)
        return MV_TRUE;

    return MV_FALSE;
}

static INLINE MV_BOOL mvStackIsEmpty(void* stackHndl)
{	
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

    if(pStack->stackIdx == 0)
        return MV_TRUE;

    return MV_FALSE;
}
/* Purpose: Push new element to stack
 * Inputs:
 *	- void* 	stackHndl 	- Stack handle as returned by "mvStackCreate()" function.
 *	- MV_U32	value		- New element.
 *
 * Return: MV_STATUS  	MV_FULL - Failure. Stack is full.
 *						MV_OK   - Success. Element is put to stack.
 */
static INLINE void mvStackPush(void* stackHndl, MV_U32 value)
{	
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

#ifdef MV_RT_DEBUG
    if(pStack->stackIdx == pStack->numOfElements)
    {
        mvOsPrintf("mvStackPush: Stack is FULL\n");
        return;
    }
#endif /* MV_RT_DEBUG */

    pStack->stackElements[pStack->stackIdx] = value;
    pStack->stackIdx++;
}

/* Purpose: Pop element from the top of stack and copy it to "pValue"
 * Inputs:
 *	- void* 	stackHndl 	- Stack handle as returned by "mvStackCreate()" function.
 *	- MV_U32	value		- Element in the top of stack.
 *
 * Return: MV_STATUS  	MV_EMPTY - Failure. Stack is empty.
 *						MV_OK    - Success. Element is removed from the stack and
 *									copied to pValue argument
 */
static INLINE MV_U32   mvStackPop(void* stackHndl)
{
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

#ifdef MV_RT_DEBUG
    if(pStack->stackIdx == 0)
    {
        mvOsPrintf("mvStackPop: Stack is EMPTY\n");
        return 0;
    }
#endif /* MV_RT_DEBUG */

    pStack->stackIdx--;
    return pStack->stackElements[pStack->stackIdx];
}

static INLINE int       mvStackIndex(void* stackHndl)
{
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

    return pStack->stackIdx;
}

static INLINE int       mvStackFreeElements(void* stackHndl)
{
    MV_STACK*   pStack = (MV_STACK*)stackHndl;

    return (pStack->numOfElements - pStack->stackIdx);
}

/* mvStack.h API list */

/* Create new Stack */
void*       mvStackCreate(int numOfElements);

/* Delete existing stack */
MV_STATUS   mvStackDelete(void* stackHndl);

/* Print status of the stack */
void        mvStackStatus(void* stackHndl, MV_BOOL isPrintElements);

#endif /* __mvStack_h__ */