IxFeatureCtrl.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /**
  2. * @file IxFeatureCtrl.c
  3. *
  4. * @author Intel Corporation
  5. * @date 29-Jan-2003
  6. *
  7. * @brief Feature Control Public API Implementation
  8. *
  9. *
  10. * @par
  11. * IXP400 SW Release version 2.0
  12. *
  13. * -- Copyright Notice --
  14. *
  15. * @par
  16. * Copyright 2001-2005, Intel Corporation.
  17. * All rights reserved.
  18. *
  19. * @par
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. * 1. Redistributions of source code must retain the above copyright
  24. * notice, this list of conditions and the following disclaimer.
  25. * 2. Redistributions in binary form must reproduce the above copyright
  26. * notice, this list of conditions and the following disclaimer in the
  27. * documentation and/or other materials provided with the distribution.
  28. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  29. * may be used to endorse or promote products derived from this software
  30. * without specific prior written permission.
  31. *
  32. * @par
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  37. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  38. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  39. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  42. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  43. * SUCH DAMAGE.
  44. *
  45. * @par
  46. * -- End of Copyright Notice --
  47. */
  48. #include "IxOsal.h"
  49. #include "IxVersionId.h"
  50. #include "IxFeatureCtrl.h"
  51. /* Macro to read from the Feature Control Register */
  52. #define IX_FEATURE_CTRL_READ(result) \
  53. do { \
  54. ixFeatureCtrlExpMap(); \
  55. (result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \
  56. } while (0)
  57. /* Macro to write to the Feature Control Register */
  58. #define IX_FEATURE_CTRL_WRITE(value) \
  59. do { \
  60. ixFeatureCtrlExpMap(); \
  61. IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \
  62. } while (0)
  63. /*
  64. * This is the offset of the feature register relative to the base of the
  65. * Expansion Bus Controller MMR.
  66. */
  67. #define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
  68. /* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
  69. PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = FALSE;
  70. /* Pointer holding the virtual address of the Feature Control Register */
  71. PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL;
  72. /* Place holder to store the software configuration */
  73. PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX];
  74. /* Flag to control swConfiguration[] is initialized once */
  75. PRIVATE BOOL swConfigurationFlag = FALSE ;
  76. /* Array containing component mask values */
  77. #ifdef __ixp42X
  78. UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
  79. (0x1<<IX_FEATURECTRL_RCOMP),
  80. (0x1<<IX_FEATURECTRL_USB),
  81. (0x1<<IX_FEATURECTRL_HASH),
  82. (0x1<<IX_FEATURECTRL_AES),
  83. (0x1<<IX_FEATURECTRL_DES),
  84. (0x1<<IX_FEATURECTRL_HDLC),
  85. (0x1<<IX_FEATURECTRL_AAL),
  86. (0x1<<IX_FEATURECTRL_HSS),
  87. (0x1<<IX_FEATURECTRL_UTOPIA),
  88. (0x1<<IX_FEATURECTRL_ETH0),
  89. (0x1<<IX_FEATURECTRL_ETH1),
  90. (0x1<<IX_FEATURECTRL_NPEA),
  91. (0x1<<IX_FEATURECTRL_NPEB),
  92. (0x1<<IX_FEATURECTRL_NPEC),
  93. (0x1<<IX_FEATURECTRL_PCI),
  94. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  95. (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
  96. (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2),
  97. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  98. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  99. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  100. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  101. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
  102. };
  103. #elif defined (__ixp46X)
  104. UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
  105. (0x1<<IX_FEATURECTRL_RCOMP),
  106. (0x1<<IX_FEATURECTRL_USB),
  107. (0x1<<IX_FEATURECTRL_HASH),
  108. (0x1<<IX_FEATURECTRL_AES),
  109. (0x1<<IX_FEATURECTRL_DES),
  110. (0x1<<IX_FEATURECTRL_HDLC),
  111. IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE, /* AAL component is always on */
  112. (0x1<<IX_FEATURECTRL_HSS),
  113. (0x1<<IX_FEATURECTRL_UTOPIA),
  114. (0x1<<IX_FEATURECTRL_ETH0),
  115. (0x1<<IX_FEATURECTRL_ETH1),
  116. (0x1<<IX_FEATURECTRL_NPEA),
  117. (0x1<<IX_FEATURECTRL_NPEB),
  118. (0x1<<IX_FEATURECTRL_NPEC),
  119. (0x1<<IX_FEATURECTRL_PCI),
  120. (0x1<<IX_FEATURECTRL_ECC_TIMESYNC),
  121. (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
  122. (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2), /* NOT TO BE USED */
  123. (0x1<<IX_FEATURECTRL_USB_HOST_CONTROLLER),
  124. (0x1<<IX_FEATURECTRL_NPEA_ETH),
  125. (0x1<<IX_FEATURECTRL_NPEB_ETH),
  126. (0x1<<IX_FEATURECTRL_RSA),
  127. (0x3<<IX_FEATURECTRL_XSCALE_MAX_FREQ),
  128. (0x1<<IX_FEATURECTRL_XSCALE_MAX_FREQ_BIT2)
  129. };
  130. #endif /* __ixp42X */
  131. /**
  132. * Forward declaration
  133. */
  134. PRIVATE
  135. void ixFeatureCtrlExpMap(void);
  136. PRIVATE
  137. void ixFeatureCtrlSwConfigurationInit(void);
  138. /**
  139. * Function to map EXP_CONFIG space
  140. */
  141. PRIVATE
  142. void ixFeatureCtrlExpMap(void)
  143. {
  144. UINT32 expCfgBaseAddress = 0;
  145. /* If the EXP Configuration space has already been mapped then
  146. * return */
  147. if (ixFeatureCtrlExpCfgRegionMapped == TRUE)
  148. {
  149. return;
  150. }
  151. /* Map (get virtual address) for the EXP_CONFIG space */
  152. expCfgBaseAddress = (UINT32)
  153. (IX_OSAL_MEM_MAP(IX_OSAL_IXP400_EXP_BUS_REGS_PHYS_BASE,
  154. IX_OSAL_IXP400_EXP_REG_MAP_SIZE));
  155. /* Assert that the mapping operation succeeded */
  156. IX_OSAL_ASSERT(expCfgBaseAddress);
  157. /* Set the address of the Feature register */
  158. ixFeatureCtrlRegister =
  159. (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET);
  160. /* Mark the fact that the EXP_CONFIG space has already been mapped */
  161. ixFeatureCtrlExpCfgRegionMapped = TRUE;
  162. }
  163. /**
  164. * Function definition: ixFeatureCtrlSwConfigurationInit
  165. * This function will only initialize software configuration once.
  166. */
  167. PRIVATE void ixFeatureCtrlSwConfigurationInit(void)
  168. {
  169. UINT32 i;
  170. if (FALSE == swConfigurationFlag)
  171. {
  172. for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++)
  173. {
  174. /* By default, all software configuration are enabled */
  175. swConfiguration[i]= TRUE ;
  176. }
  177. /*Make sure this function only initializes swConfiguration[] once*/
  178. swConfigurationFlag = TRUE ;
  179. }
  180. }
  181. /**
  182. * Function definition: ixFeatureCtrlRead
  183. */
  184. IxFeatureCtrlReg
  185. ixFeatureCtrlRead (void)
  186. {
  187. IxFeatureCtrlReg result;
  188. #if CPU!=SIMSPARCSOLARIS
  189. /* Read the feature control register */
  190. IX_FEATURE_CTRL_READ(result);
  191. return result;
  192. #else
  193. /* Return an invalid value for VxWorks simulation */
  194. result = 0xFFFFFFFF;
  195. return result;
  196. #endif
  197. }
  198. /**
  199. * Function definition: ixFeatureCtrlWrite
  200. */
  201. void
  202. ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg)
  203. {
  204. #if CPU!=SIMSPARCSOLARIS
  205. /* Write value to feature control register */
  206. IX_FEATURE_CTRL_WRITE(expUnitReg);
  207. #endif
  208. }
  209. /**
  210. * Function definition: ixFeatureCtrlHwCapabilityRead
  211. */
  212. IxFeatureCtrlReg
  213. ixFeatureCtrlHwCapabilityRead (void)
  214. {
  215. IxFeatureCtrlReg currentReg, hwCapability;
  216. /* Capture a copy of feature control register */
  217. currentReg = ixFeatureCtrlRead();
  218. /* Try to enable all hardware components.
  219. * Only software disable hardware can be enabled again */
  220. ixFeatureCtrlWrite(0);
  221. /* Read feature control register to know the hardware capability. */
  222. hwCapability = ixFeatureCtrlRead();
  223. /* Restore initial feature control value */
  224. ixFeatureCtrlWrite(currentReg);
  225. /* return Hardware Capability */
  226. return hwCapability;
  227. }
  228. /**
  229. * Function definition: ixFeatureCtrlComponentCheck
  230. */
  231. IX_STATUS
  232. ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType)
  233. {
  234. IxFeatureCtrlReg expUnitReg;
  235. UINT32 mask = 0;
  236. /* Lookup mask of component */
  237. mask=componentMask[componentType];
  238. /* Check if mask is available or not */
  239. if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask)
  240. {
  241. return IX_FEATURE_CTRL_COMPONENT_DISABLED;
  242. }
  243. if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask)
  244. {
  245. return IX_FEATURE_CTRL_COMPONENT_ENABLED;
  246. }
  247. /* Read feature control register to know current hardware capability. */
  248. expUnitReg = ixFeatureCtrlRead();
  249. /* For example: To check for Hashing Coprocessor (bit-2)
  250. * expUniteg = 0x0010
  251. * ~expUnitReg = 0x1101
  252. * componentType = 0x0100
  253. * ~expUnitReg & componentType = 0x0100 (Not zero)
  254. */
  255. /*
  256. * Inverse the bit value because available component is 0 in value
  257. */
  258. expUnitReg = ~expUnitReg ;
  259. if (expUnitReg & mask)
  260. {
  261. return (IX_FEATURE_CTRL_COMPONENT_ENABLED);
  262. }
  263. else
  264. {
  265. return (IX_FEATURE_CTRL_COMPONENT_DISABLED);
  266. }
  267. }
  268. /**
  269. * Function definition: ixFeatureCtrlProductIdRead
  270. */
  271. IxFeatureCtrlProductId
  272. ixFeatureCtrlProductIdRead ()
  273. {
  274. #if CPU!=SIMSPARCSOLARIS
  275. IxFeatureCtrlProductId pdId = 0 ;
  276. /* Use ARM instruction to move register0 from coprocessor to ARM register */
  277. #ifndef __wince
  278. __asm("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :);
  279. #else
  280. #ifndef IN_KERNEL
  281. BOOL mode;
  282. #endif
  283. extern IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead();
  284. #ifndef IN_KERNEL
  285. mode = SetKMode(TRUE);
  286. #endif
  287. pdId = AsmixFeatureCtrlProductIdRead();
  288. #ifndef IN_KERNEL
  289. SetKMode(mode);
  290. #endif
  291. #endif
  292. return (pdId);
  293. #else
  294. /* Return an invalid value for VxWorks simulation */
  295. return 0xffffffff;
  296. #endif
  297. }
  298. /**
  299. * Function definition: ixFeatureCtrlDeviceRead
  300. */
  301. IxFeatureCtrlDeviceId
  302. ixFeatureCtrlDeviceRead ()
  303. {
  304. return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET)
  305. & IX_FEATURE_CTRL_DEVICE_TYPE_MASK);
  306. } /* End function ixFeatureCtrlDeviceRead */
  307. /**
  308. * Function definition: ixFeatureCtrlSwConfigurationCheck
  309. */
  310. IX_STATUS
  311. ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType)
  312. {
  313. if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
  314. {
  315. ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
  316. IX_OSAL_LOG_DEV_STDOUT,
  317. "FeatureCtrl: Invalid software configuraiton input.\n",
  318. 0, 0, 0, 0, 0, 0);
  319. return IX_FEATURE_CTRL_SWCONFIG_DISABLED;
  320. }
  321. /* The function will only initialize once. */
  322. ixFeatureCtrlSwConfigurationInit();
  323. /* Check and return software configuration */
  324. return ((swConfiguration[(UINT32)swConfigType] == TRUE) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED);
  325. }
  326. /**
  327. * Function definition: ixFeatureCtrlSwConfigurationWrite
  328. */
  329. void
  330. ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled)
  331. {
  332. if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
  333. {
  334. ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
  335. IX_OSAL_LOG_DEV_STDOUT,
  336. "FeatureCtrl: Invalid software configuraiton input.\n",
  337. 0, 0, 0, 0, 0, 0);
  338. return;
  339. }
  340. /* The function will only initialize once. */
  341. ixFeatureCtrlSwConfigurationInit();
  342. /* Write software configuration */
  343. swConfiguration[(UINT32)swConfigType]=enabled ;
  344. }
  345. /**
  346. * Function definition: ixFeatureCtrlIxp400SwVersionShow
  347. */
  348. void
  349. ixFeatureCtrlIxp400SwVersionShow (void)
  350. {
  351. printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID);
  352. }
  353. /**
  354. * Function definition: ixFeatureCtrlSoftwareBuildGet
  355. */
  356. IxFeatureCtrlBuildDevice
  357. ixFeatureCtrlSoftwareBuildGet (void)
  358. {
  359. #ifdef __ixp42X
  360. return IX_FEATURE_CTRL_SW_BUILD_IXP42X;
  361. #else
  362. return IX_FEATURE_CTRL_SW_BUILD_IXP46X;
  363. #endif
  364. }