blob: a9aa36804b429e79bca289542cf838728b44013d [file] [log] [blame]
Wolfgang Denkba94a1b2006-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
Wolfgang Denkcb3761e2013-07-28 22:12:47 +020017 * SPDX-License-Identifier: BSD-3-Clause
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020018 * @par
19 * -- End of Copyright Notice --
20 */
21
22#include <config.h>
23#include <common.h>
24#include "IxOsal.h"
25#include <IxEthAcc.h>
26#include <IxEthDB.h>
27#include <IxNpeDl.h>
28#include <IxQMgr.h>
29#include <IxNpeMh.h>
30
31static char *traceHeaders[] = {
32 "",
33 "[fatal] ",
34 "[error] ",
35 "[warning] ",
36 "[message] ",
37 "[debug1] ",
38 "[debug2] ",
39 "[debug3] ",
40 "[all]"
41};
42
43/* by default trace all but debug message */
44PRIVATE int ixOsalCurrLogLevel = IX_OSAL_LOG_LVL_MESSAGE;
45
46/**************************************
47 * Irq services
48 *************************************/
49
50PUBLIC IX_STATUS
51ixOsalIrqBind (UINT32 vector, IxOsalVoidFnVoidPtr routine, void *parameter)
52{
53 return IX_FAIL;
54}
55
56PUBLIC IX_STATUS
57ixOsalIrqUnbind (UINT32 vector)
58{
59 return IX_FAIL;
60}
61
62PUBLIC UINT32
63ixOsalIrqLock ()
64{
65 return 0;
66}
67
68/* Enable interrupts and task scheduling,
69 * input parameter: irqEnable status returned
70 * by ixOsalIrqLock().
71 */
72PUBLIC void
73ixOsalIrqUnlock (UINT32 lockKey)
74{
75}
76
77PUBLIC UINT32
78ixOsalIrqLevelSet (UINT32 level)
79{
80 return IX_FAIL;
81}
82
83PUBLIC void
84ixOsalIrqEnable (UINT32 irqLevel)
85{
86}
87
88PUBLIC void
89ixOsalIrqDisable (UINT32 irqLevel)
90{
91}
92
93/*********************
94 * Log function
95 *********************/
96
97INT32
98ixOsalLog (IxOsalLogLevel level,
99 IxOsalLogDevice device,
100 char *format, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
101{
102 /*
103 * Return -1 for custom display devices
104 */
105 if ((device != IX_OSAL_LOG_DEV_STDOUT)
106 && (device != IX_OSAL_LOG_DEV_STDERR))
107 {
108 debug("ixOsalLog: only IX_OSAL_LOG_DEV_STDOUT and IX_OSAL_LOG_DEV_STDERR are supported \n");
109 return (IX_OSAL_LOG_ERROR);
110 }
111
112 if (level <= ixOsalCurrLogLevel && level != IX_OSAL_LOG_LVL_NONE)
113 {
114#if 0 /* sr: U-Boots printf or debug doesn't return a length */
115 int headerByteCount = (level == IX_OSAL_LOG_LVL_USER) ? 0 : diag_printf(traceHeaders[level - 1]);
116
117 return headerByteCount + diag_printf (format, arg1, arg2, arg3, arg4, arg5, arg6);
118#else
119 int headerByteCount = (level == IX_OSAL_LOG_LVL_USER) ? 0 : strlen(traceHeaders[level - 1]);
120
121 return headerByteCount + strlen(format);
122#endif
123 }
124 else
125 {
126 /*
127 * Return error
128 */
129 return (IX_OSAL_LOG_ERROR);
130 }
131}
132
133PUBLIC UINT32
134ixOsalLogLevelSet (UINT32 level)
135{
136 UINT32 oldLevel;
137
138 /*
139 * Check value first
140 */
141 if ((level < IX_OSAL_LOG_LVL_NONE) || (level > IX_OSAL_LOG_LVL_ALL))
142 {
143 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
144 IX_OSAL_LOG_DEV_STDOUT,
145 "ixOsalLogLevelSet: Log Level is between %d and%d \n",
146 IX_OSAL_LOG_LVL_NONE, IX_OSAL_LOG_LVL_ALL, 0, 0, 0, 0);
147 return IX_OSAL_LOG_LVL_NONE;
148 }
149 oldLevel = ixOsalCurrLogLevel;
150
151 ixOsalCurrLogLevel = level;
152
153 return oldLevel;
154}
155
156/**************************************
157 * Task services
158 *************************************/
159
160PUBLIC void
161ixOsalBusySleep (UINT32 microseconds)
162{
163 udelay(microseconds);
164}
165
166PUBLIC void
167ixOsalSleep (UINT32 milliseconds)
168{
169 if (milliseconds != 0) {
170#if 1
171 /*
172 * sr: We poll while we wait because interrupts are off in U-Boot
173 * and CSR expects messages, etc to be dispatched while sleeping.
174 */
175 int i;
176 IxQMgrDispatcherFuncPtr qDispatcherFunc;
177
178 ixQMgrDispatcherLoopGet(&qDispatcherFunc);
179
180 while (milliseconds--) {
181 for (i = 1; i <= 2; i++)
182 ixNpeMhMessagesReceive(i);
183 (*qDispatcherFunc)(IX_QMGR_QUELOW_GROUP);
184
185 udelay(1000);
186 }
187#endif
188 }
189}
190
191/**************************************
192 * Memory functions
193 *************************************/
194
195void *
196ixOsalMemAlloc (UINT32 size)
197{
198 return (void *)0;
199}
200
201void
202ixOsalMemFree (void *ptr)
203{
204}
205
206/*
207 * Copy count bytes from src to dest ,
208 * returns pointer to the dest mem zone.
209 */
210void *
211ixOsalMemCopy (void *dest, void *src, UINT32 count)
212{
213 IX_OSAL_ASSERT (dest != NULL);
214 IX_OSAL_ASSERT (src != NULL);
215 return (memcpy (dest, src, count));
216}
217
218/*
219 * Fills a memory zone with a given constant byte,
220 * returns pointer to the memory zone.
221 */
222void *
223ixOsalMemSet (void *ptr, UINT8 filler, UINT32 count)
224{
225 IX_OSAL_ASSERT (ptr != NULL);
226 return (memset (ptr, filler, count));
227}