IxOsalOsServices.c 4.4 KB

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