blob: e18c6c4c1e99f44ae0f5f7b908232c11dfc6ec98 [file] [log] [blame]
Wolfgang Denk4646d2a2006-05-30 15:56:48 +02001/**
2 * @file IxOsalOsServices.c (linux)
3 *
4 * @brief Implementation for Irq, Mem, sleep.
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 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the Intel Corporation nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * @par
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * @par
43 * -- End of Copyright Notice --
44 */
45
46#include <config.h>
47#include <common.h>
48#include "IxOsal.h"
49#include <IxEthAcc.h>
50#include <IxEthDB.h>
51#include <IxNpeDl.h>
52#include <IxQMgr.h>
53#include <IxNpeMh.h>
54
55static char *traceHeaders[] = {
56 "",
57 "[fatal] ",
58 "[error] ",
59 "[warning] ",
60 "[message] ",
61 "[debug1] ",
62 "[debug2] ",
63 "[debug3] ",
64 "[all]"
65};
66
67/* by default trace all but debug message */
68PRIVATE int ixOsalCurrLogLevel = IX_OSAL_LOG_LVL_MESSAGE;
69
70/**************************************
71 * Irq services
72 *************************************/
73
74PUBLIC IX_STATUS
75ixOsalIrqBind (UINT32 vector, IxOsalVoidFnVoidPtr routine, void *parameter)
76{
77 return IX_FAIL;
78}
79
80PUBLIC IX_STATUS
81ixOsalIrqUnbind (UINT32 vector)
82{
83 return IX_FAIL;
84}
85
86PUBLIC UINT32
87ixOsalIrqLock ()
88{
89 return 0;
90}
91
92/* Enable interrupts and task scheduling,
93 * input parameter: irqEnable status returned
94 * by ixOsalIrqLock().
95 */
96PUBLIC void
97ixOsalIrqUnlock (UINT32 lockKey)
98{
99}
100
101PUBLIC UINT32
102ixOsalIrqLevelSet (UINT32 level)
103{
104 return IX_FAIL;
105}
106
107PUBLIC void
108ixOsalIrqEnable (UINT32 irqLevel)
109{
110}
111
112PUBLIC void
113ixOsalIrqDisable (UINT32 irqLevel)
114{
115}
116
117/*********************
118 * Log function
119 *********************/
120
121INT32
122ixOsalLog (IxOsalLogLevel level,
123 IxOsalLogDevice device,
124 char *format, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
125{
126 /*
127 * Return -1 for custom display devices
128 */
129 if ((device != IX_OSAL_LOG_DEV_STDOUT)
130 && (device != IX_OSAL_LOG_DEV_STDERR))
131 {
132 debug("ixOsalLog: only IX_OSAL_LOG_DEV_STDOUT and IX_OSAL_LOG_DEV_STDERR are supported \n");
133 return (IX_OSAL_LOG_ERROR);
134 }
135
136 if (level <= ixOsalCurrLogLevel && level != IX_OSAL_LOG_LVL_NONE)
137 {
138#if 0 /* sr: U-Boots printf or debug doesn't return a length */
139 int headerByteCount = (level == IX_OSAL_LOG_LVL_USER) ? 0 : diag_printf(traceHeaders[level - 1]);
140
141 return headerByteCount + diag_printf (format, arg1, arg2, arg3, arg4, arg5, arg6);
142#else
143 int headerByteCount = (level == IX_OSAL_LOG_LVL_USER) ? 0 : strlen(traceHeaders[level - 1]);
144
145 return headerByteCount + strlen(format);
146#endif
147 }
148 else
149 {
150 /*
151 * Return error
152 */
153 return (IX_OSAL_LOG_ERROR);
154 }
155}
156
157PUBLIC UINT32
158ixOsalLogLevelSet (UINT32 level)
159{
160 UINT32 oldLevel;
161
162 /*
163 * Check value first
164 */
165 if ((level < IX_OSAL_LOG_LVL_NONE) || (level > IX_OSAL_LOG_LVL_ALL))
166 {
167 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
168 IX_OSAL_LOG_DEV_STDOUT,
169 "ixOsalLogLevelSet: Log Level is between %d and%d \n",
170 IX_OSAL_LOG_LVL_NONE, IX_OSAL_LOG_LVL_ALL, 0, 0, 0, 0);
171 return IX_OSAL_LOG_LVL_NONE;
172 }
173 oldLevel = ixOsalCurrLogLevel;
174
175 ixOsalCurrLogLevel = level;
176
177 return oldLevel;
178}
179
180/**************************************
181 * Task services
182 *************************************/
183
184PUBLIC void
185ixOsalBusySleep (UINT32 microseconds)
186{
187 udelay(microseconds);
188}
189
190PUBLIC void
191ixOsalSleep (UINT32 milliseconds)
192{
193 if (milliseconds != 0) {
194#if 1
195 /*
196 * sr: We poll while we wait because interrupts are off in U-Boot
197 * and CSR expects messages, etc to be dispatched while sleeping.
198 */
199 int i;
200 IxQMgrDispatcherFuncPtr qDispatcherFunc;
201
202 ixQMgrDispatcherLoopGet(&qDispatcherFunc);
203
204 while (milliseconds--) {
205 for (i = 1; i <= 2; i++)
206 ixNpeMhMessagesReceive(i);
207 (*qDispatcherFunc)(IX_QMGR_QUELOW_GROUP);
208
209 udelay(1000);
210 }
211#endif
212 }
213}
214
215/**************************************
216 * Memory functions
217 *************************************/
218
219void *
220ixOsalMemAlloc (UINT32 size)
221{
222 return (void *)0;
223}
224
225void
226ixOsalMemFree (void *ptr)
227{
228}
229
230/*
231 * Copy count bytes from src to dest ,
232 * returns pointer to the dest mem zone.
233 */
234void *
235ixOsalMemCopy (void *dest, void *src, UINT32 count)
236{
237 IX_OSAL_ASSERT (dest != NULL);
238 IX_OSAL_ASSERT (src != NULL);
239 return (memcpy (dest, src, count));
240}
241
242/*
243 * Fills a memory zone with a given constant byte,
244 * returns pointer to the memory zone.
245 */
246void *
247ixOsalMemSet (void *ptr, UINT8 filler, UINT32 count)
248{
249 IX_OSAL_ASSERT (ptr != NULL);
250 return (memset (ptr, filler, count));
251}