]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/npe/IxOsalOsSemaphore.c
doc: SPI: Add qspi test details on AM43xx
[karo-tx-uboot.git] / drivers / net / npe / IxOsalOsSemaphore.c
1 /**
2  * @file IxOsalOsSemaphore.c (eCos)
3  *
4  * @brief Implementation for semaphore and mutex.
5  *
6  *
7  * @par
8  * IXP400 SW Release version 1.5
9  *
10  * -- Copyright Notice --
11  *
12  * @par
13  * Copyright 2001-2005, Intel Corporation.
14  * All rights reserved.
15  *
16  * @par
17  * SPDX-License-Identifier:     BSD-3-Clause
18  * @par
19  * -- End of Copyright Notice --
20  */
21
22 #include "IxOsal.h"
23 #include "IxNpeMhReceive_p.h"
24
25 /* Define a large number */
26 #define IX_OSAL_MAX_LONG (0x7FFFFFFF)
27
28 /* Max timeout in MS, used to guard against possible overflow */
29 #define IX_OSAL_MAX_TIMEOUT_MS (IX_OSAL_MAX_LONG/HZ)
30
31
32 PUBLIC IX_STATUS
33 ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 start_value)
34 {
35     diag_printf("%s called\n", __FUNCTION__);
36     return IX_SUCCESS;
37 }
38
39 /**
40  * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked.
41  *              If the semaphore is 'full', it is taken and control is returned
42  *              to the caller. If the time indicated in 'timeout' is reached,
43  *              the thread will unblock and return an error indication. If the
44  *              timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block;
45  *              if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until
46  *              the semaphore is available.
47  *
48  *
49  */
50
51
52 PUBLIC IX_STATUS
53 ixOsalSemaphoreWait (IxOsalOsSemaphore * sid, INT32 timeout)
54 {
55     diag_printf("%s called\n", __FUNCTION__);
56     return IX_SUCCESS;
57 }
58
59 /*
60  * Attempt to get semaphore, return immediately,
61  * no error info because users expect some failures
62  * when using this API.
63  */
64 PUBLIC IX_STATUS
65 ixOsalSemaphoreTryWait (IxOsalSemaphore * sid)
66 {
67     diag_printf("%s called\n", __FUNCTION__);
68     return IX_FAIL;
69 }
70
71 /**
72  *
73  * DESCRIPTION: This function causes the next available thread in the pend queue
74  *              to be unblocked. If no thread is pending on this semaphore, the
75  *              semaphore becomes 'full'.
76  */
77 PUBLIC IX_STATUS
78 ixOsalSemaphorePost (IxOsalSemaphore * sid)
79 {
80     diag_printf("%s called\n", __FUNCTION__);
81     return IX_SUCCESS;
82 }
83
84 PUBLIC IX_STATUS
85 ixOsalSemaphoreGetValue (IxOsalSemaphore * sid, UINT32 * value)
86 {
87     diag_printf("%s called\n", __FUNCTION__);
88     return IX_FAIL;
89 }
90
91 PUBLIC IX_STATUS
92 ixOsalSemaphoreDestroy (IxOsalSemaphore * sid)
93 {
94     diag_printf("%s called\n", __FUNCTION__);
95     return IX_FAIL;
96 }
97
98 /****************************
99  *    Mutex
100  ****************************/
101
102 static void drv_mutex_init(IxOsalMutex *mutex)
103 {
104         *mutex = 0;
105 }
106
107 static void drv_mutex_destroy(IxOsalMutex *mutex)
108 {
109         *mutex = -1;
110 }
111
112 static int drv_mutex_trylock(IxOsalMutex *mutex)
113 {
114         int result = true;
115
116         if (*mutex == 1)
117                 result = false;
118
119         return result;
120 }
121
122 static void drv_mutex_unlock(IxOsalMutex *mutex)
123 {
124         if (*mutex == 1)
125                 printf("Trying to unlock unlocked mutex!");
126
127         *mutex = 0;
128 }
129
130 PUBLIC IX_STATUS
131 ixOsalMutexInit (IxOsalMutex * mutex)
132 {
133     drv_mutex_init(mutex);
134     return IX_SUCCESS;
135 }
136
137 PUBLIC IX_STATUS
138 ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout)
139 {
140     int tries;
141
142     if (timeout == IX_OSAL_WAIT_NONE) {
143         if (drv_mutex_trylock(mutex))
144             return IX_SUCCESS;
145         else
146             return IX_FAIL;
147     }
148
149     tries = (timeout * 1000) / 50;
150     while (1) {
151         if (drv_mutex_trylock(mutex))
152             return IX_SUCCESS;
153         if (timeout != IX_OSAL_WAIT_FOREVER && tries-- <= 0)
154             break;
155         udelay(50);
156     }
157     return IX_FAIL;
158 }
159
160 PUBLIC IX_STATUS
161 ixOsalMutexUnlock (IxOsalMutex * mutex)
162 {
163     drv_mutex_unlock(mutex);
164     return IX_SUCCESS;
165 }
166
167 /*
168  * Attempt to get mutex, return immediately,
169  * no error info because users expect some failures
170  * when using this API.
171  */
172 PUBLIC IX_STATUS
173 ixOsalMutexTryLock (IxOsalMutex * mutex)
174 {
175     if (drv_mutex_trylock(mutex))
176         return IX_SUCCESS;
177     return IX_FAIL;
178 }
179
180 PUBLIC IX_STATUS
181 ixOsalMutexDestroy (IxOsalMutex * mutex)
182 {
183     drv_mutex_destroy(mutex);
184     return IX_SUCCESS;
185 }
186
187 PUBLIC IX_STATUS
188 ixOsalFastMutexInit (IxOsalFastMutex * mutex)
189 {
190     return ixOsalMutexInit(mutex);
191 }
192
193 PUBLIC IX_STATUS ixOsalFastMutexTryLock(IxOsalFastMutex *mutex)
194 {
195     return ixOsalMutexTryLock(mutex);
196 }
197
198
199 PUBLIC IX_STATUS
200 ixOsalFastMutexUnlock (IxOsalFastMutex * mutex)
201 {
202     return ixOsalMutexUnlock(mutex);
203 }
204
205 PUBLIC IX_STATUS
206 ixOsalFastMutexDestroy (IxOsalFastMutex * mutex)
207 {
208     return ixOsalMutexDestroy(mutex);
209 }