IxOsalOsServices.c 5.8 KB

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