Root/target/linux/generic/files/crypto/ocf/kirkwood/mvHal/common/mvStack.h

1/*******************************************************************************
2* Copyright 2003, Marvell Semiconductor Israel LTD. *
3* THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL. *
4* NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT *
5* OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE *
6* DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL. *
7* THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED, *
8* IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE. *
9* *
10* MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES, *
11* MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL *
12* SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K. *
13* (MJKK), MARVELL SEMICONDUCTOR ISRAEL LTD (MSIL). *
14********************************************************************************
15* mvStack.h - Header File for :
16*
17* FILENAME: $Workfile: mvStack.h $
18* REVISION: $Revision: 1.1 $
19* LAST UPDATE: $Modtime: $
20*
21* DESCRIPTION:
22* This file defines simple Stack (LIFO) functionality.
23*
24*******************************************************************************/
25
26#ifndef __mvStack_h__
27#define __mvStack_h__
28
29
30/* includes */
31#include "mvTypes.h"
32
33
34/* defines */
35
36
37/* typedefs */
38/* Data structure describes general purpose Stack */
39typedef struct
40{
41    int stackIdx;
42    int numOfElements;
43    MV_U32* stackElements;
44} MV_STACK;
45
46static INLINE MV_BOOL mvStackIsFull(void* stackHndl)
47{
48    MV_STACK* pStack = (MV_STACK*)stackHndl;
49
50    if(pStack->stackIdx == pStack->numOfElements)
51        return MV_TRUE;
52
53    return MV_FALSE;
54}
55
56static INLINE MV_BOOL mvStackIsEmpty(void* stackHndl)
57{
58    MV_STACK* pStack = (MV_STACK*)stackHndl;
59
60    if(pStack->stackIdx == 0)
61        return MV_TRUE;
62
63    return MV_FALSE;
64}
65/* Purpose: Push new element to stack
66 * Inputs:
67 * - void* stackHndl - Stack handle as returned by "mvStackCreate()" function.
68 * - MV_U32 value - New element.
69 *
70 * Return: MV_STATUS MV_FULL - Failure. Stack is full.
71 * MV_OK - Success. Element is put to stack.
72 */
73static INLINE void mvStackPush(void* stackHndl, MV_U32 value)
74{
75    MV_STACK* pStack = (MV_STACK*)stackHndl;
76
77#ifdef MV_RT_DEBUG
78    if(pStack->stackIdx == pStack->numOfElements)
79    {
80        mvOsPrintf("mvStackPush: Stack is FULL\n");
81        return;
82    }
83#endif /* MV_RT_DEBUG */
84
85    pStack->stackElements[pStack->stackIdx] = value;
86    pStack->stackIdx++;
87}
88
89/* Purpose: Pop element from the top of stack and copy it to "pValue"
90 * Inputs:
91 * - void* stackHndl - Stack handle as returned by "mvStackCreate()" function.
92 * - MV_U32 value - Element in the top of stack.
93 *
94 * Return: MV_STATUS MV_EMPTY - Failure. Stack is empty.
95 * MV_OK - Success. Element is removed from the stack and
96 * copied to pValue argument
97 */
98static INLINE MV_U32 mvStackPop(void* stackHndl)
99{
100    MV_STACK* pStack = (MV_STACK*)stackHndl;
101
102#ifdef MV_RT_DEBUG
103    if(pStack->stackIdx == 0)
104    {
105        mvOsPrintf("mvStackPop: Stack is EMPTY\n");
106        return 0;
107    }
108#endif /* MV_RT_DEBUG */
109
110    pStack->stackIdx--;
111    return pStack->stackElements[pStack->stackIdx];
112}
113
114static INLINE int mvStackIndex(void* stackHndl)
115{
116    MV_STACK* pStack = (MV_STACK*)stackHndl;
117
118    return pStack->stackIdx;
119}
120
121static INLINE int mvStackFreeElements(void* stackHndl)
122{
123    MV_STACK* pStack = (MV_STACK*)stackHndl;
124
125    return (pStack->numOfElements - pStack->stackIdx);
126}
127
128/* mvStack.h API list */
129
130/* Create new Stack */
131void* mvStackCreate(int numOfElements);
132
133/* Delete existing stack */
134MV_STATUS mvStackDelete(void* stackHndl);
135
136/* Print status of the stack */
137void mvStackStatus(void* stackHndl, MV_BOOL isPrintElements);
138
139#endif /* __mvStack_h__ */
140
141

Archive Download this file



interactive