IxFeatureCtrl.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. * SPDX-License-Identifier: BSD-3-Clause
  21. * @par
  22. * -- End of Copyright Notice --
  23. */
  24. #include "IxOsal.h"
  25. #include "IxVersionId.h"
  26. #include "IxFeatureCtrl.h"
  27. /* Macro to read from the Feature Control Register */
  28. #define IX_FEATURE_CTRL_READ(result) \
  29. do { \
  30. ixFeatureCtrlExpMap(); \
  31. (result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \
  32. } while (0)
  33. /* Macro to write to the Feature Control Register */
  34. #define IX_FEATURE_CTRL_WRITE(value) \
  35. do { \
  36. ixFeatureCtrlExpMap(); \
  37. IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \
  38. } while (0)
  39. /*
  40. * This is the offset of the feature register relative to the base of the
  41. * Expansion Bus Controller MMR.
  42. */
  43. #define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
  44. /* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
  45. PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = false;
  46. /* Pointer holding the virtual address of the Feature Control Register */
  47. PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL;
  48. /* Place holder to store the software configuration */
  49. PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX];
  50. /* Flag to control swConfiguration[] is initialized once */
  51. PRIVATE BOOL swConfigurationFlag = false ;
  52. /* Array containing component mask values */
  53. #ifdef __ixp42X
  54. UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
  55. (0x1<<IX_FEATURECTRL_RCOMP),
  56. (0x1<<IX_FEATURECTRL_USB),
  57. (0x1<<IX_FEATURECTRL_HASH),
  58. (0x1<<IX_FEATURECTRL_AES),
  59. (0x1<<IX_FEATURECTRL_DES),
  60. (0x1<<IX_FEATURECTRL_HDLC),
  61. (0x1<<IX_FEATURECTRL_AAL),
  62. (0x1<<IX_FEATURECTRL_HSS),
  63. (0x1<<IX_FEATURECTRL_UTOPIA),
  64. (0x1<<IX_FEATURECTRL_ETH0),
  65. (0x1<<IX_FEATURECTRL_ETH1),
  66. (0x1<<IX_FEATURECTRL_NPEA),
  67. (0x1<<IX_FEATURECTRL_NPEB),
  68. (0x1<<IX_FEATURECTRL_NPEC),
  69. (0x1<<IX_FEATURECTRL_PCI),
  70. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  71. (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
  72. (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2),
  73. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  74. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  75. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  76. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
  77. IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
  78. };
  79. #elif defined (__ixp46X)
  80. UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
  81. (0x1<<IX_FEATURECTRL_RCOMP),
  82. (0x1<<IX_FEATURECTRL_USB),
  83. (0x1<<IX_FEATURECTRL_HASH),
  84. (0x1<<IX_FEATURECTRL_AES),
  85. (0x1<<IX_FEATURECTRL_DES),
  86. (0x1<<IX_FEATURECTRL_HDLC),
  87. IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE, /* AAL component is always on */
  88. (0x1<<IX_FEATURECTRL_HSS),
  89. (0x1<<IX_FEATURECTRL_UTOPIA),
  90. (0x1<<IX_FEATURECTRL_ETH0),
  91. (0x1<<IX_FEATURECTRL_ETH1),
  92. (0x1<<IX_FEATURECTRL_NPEA),
  93. (0x1<<IX_FEATURECTRL_NPEB),
  94. (0x1<<IX_FEATURECTRL_NPEC),
  95. (0x1<<IX_FEATURECTRL_PCI),
  96. (0x1<<IX_FEATURECTRL_ECC_TIMESYNC),
  97. (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
  98. (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2), /* NOT TO BE USED */
  99. (0x1<<IX_FEATURECTRL_USB_HOST_CONTROLLER),
  100. (0x1<<IX_FEATURECTRL_NPEA_ETH),
  101. (0x1<<IX_FEATURECTRL_NPEB_ETH),
  102. (0x1<<IX_FEATURECTRL_RSA),
  103. (0x3<<IX_FEATURECTRL_XSCALE_MAX_FREQ),
  104. (0x1<<IX_FEATURECTRL_XSCALE_MAX_FREQ_BIT2)
  105. };
  106. #endif /* __ixp42X */
  107. /**
  108. * Forward declaration
  109. */
  110. PRIVATE
  111. void ixFeatureCtrlExpMap(void);
  112. PRIVATE
  113. void ixFeatureCtrlSwConfigurationInit(void);
  114. /**
  115. * Function to map EXP_CONFIG space
  116. */
  117. PRIVATE
  118. void ixFeatureCtrlExpMap(void)
  119. {
  120. UINT32 expCfgBaseAddress = 0;
  121. /* If the EXP Configuration space has already been mapped then
  122. * return */
  123. if (ixFeatureCtrlExpCfgRegionMapped == true)
  124. {
  125. return;
  126. }
  127. /* Map (get virtual address) for the EXP_CONFIG space */
  128. expCfgBaseAddress = (UINT32)
  129. (IX_OSAL_MEM_MAP(IX_OSAL_IXP400_EXP_BUS_REGS_PHYS_BASE,
  130. IX_OSAL_IXP400_EXP_REG_MAP_SIZE));
  131. /* Assert that the mapping operation succeeded */
  132. IX_OSAL_ASSERT(expCfgBaseAddress);
  133. /* Set the address of the Feature register */
  134. ixFeatureCtrlRegister =
  135. (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET);
  136. /* Mark the fact that the EXP_CONFIG space has already been mapped */
  137. ixFeatureCtrlExpCfgRegionMapped = true;
  138. }
  139. /**
  140. * Function definition: ixFeatureCtrlSwConfigurationInit
  141. * This function will only initialize software configuration once.
  142. */
  143. PRIVATE void ixFeatureCtrlSwConfigurationInit(void)
  144. {
  145. UINT32 i;
  146. if (false == swConfigurationFlag)
  147. {
  148. for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++)
  149. {
  150. /* By default, all software configuration are enabled */
  151. swConfiguration[i]= true ;
  152. }
  153. /*Make sure this function only initializes swConfiguration[] once*/
  154. swConfigurationFlag = true ;
  155. }
  156. }
  157. /**
  158. * Function definition: ixFeatureCtrlRead
  159. */
  160. IxFeatureCtrlReg
  161. ixFeatureCtrlRead (void)
  162. {
  163. IxFeatureCtrlReg result;
  164. #if CPU!=SIMSPARCSOLARIS
  165. /* Read the feature control register */
  166. IX_FEATURE_CTRL_READ(result);
  167. return result;
  168. #else
  169. /* Return an invalid value for VxWorks simulation */
  170. result = 0xFFFFFFFF;
  171. return result;
  172. #endif
  173. }
  174. /**
  175. * Function definition: ixFeatureCtrlWrite
  176. */
  177. void
  178. ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg)
  179. {
  180. #if CPU!=SIMSPARCSOLARIS
  181. /* Write value to feature control register */
  182. IX_FEATURE_CTRL_WRITE(expUnitReg);
  183. #endif
  184. }
  185. /**
  186. * Function definition: ixFeatureCtrlHwCapabilityRead
  187. */
  188. IxFeatureCtrlReg
  189. ixFeatureCtrlHwCapabilityRead (void)
  190. {
  191. IxFeatureCtrlReg currentReg, hwCapability;
  192. /* Capture a copy of feature control register */
  193. currentReg = ixFeatureCtrlRead();
  194. /* Try to enable all hardware components.
  195. * Only software disable hardware can be enabled again */
  196. ixFeatureCtrlWrite(0);
  197. /* Read feature control register to know the hardware capability. */
  198. hwCapability = ixFeatureCtrlRead();
  199. /* Restore initial feature control value */
  200. ixFeatureCtrlWrite(currentReg);
  201. /* return Hardware Capability */
  202. return hwCapability;
  203. }
  204. /**
  205. * Function definition: ixFeatureCtrlComponentCheck
  206. */
  207. IX_STATUS
  208. ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType)
  209. {
  210. IxFeatureCtrlReg expUnitReg;
  211. UINT32 mask = 0;
  212. /* Lookup mask of component */
  213. mask=componentMask[componentType];
  214. /* Check if mask is available or not */
  215. if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask)
  216. {
  217. return IX_FEATURE_CTRL_COMPONENT_DISABLED;
  218. }
  219. if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask)
  220. {
  221. return IX_FEATURE_CTRL_COMPONENT_ENABLED;
  222. }
  223. /* Read feature control register to know current hardware capability. */
  224. expUnitReg = ixFeatureCtrlRead();
  225. /* For example: To check for Hashing Coprocessor (bit-2)
  226. * expUniteg = 0x0010
  227. * ~expUnitReg = 0x1101
  228. * componentType = 0x0100
  229. * ~expUnitReg & componentType = 0x0100 (Not zero)
  230. */
  231. /*
  232. * Inverse the bit value because available component is 0 in value
  233. */
  234. expUnitReg = ~expUnitReg ;
  235. if (expUnitReg & mask)
  236. {
  237. return (IX_FEATURE_CTRL_COMPONENT_ENABLED);
  238. }
  239. else
  240. {
  241. return (IX_FEATURE_CTRL_COMPONENT_DISABLED);
  242. }
  243. }
  244. /**
  245. * Function definition: ixFeatureCtrlProductIdRead
  246. */
  247. IxFeatureCtrlProductId
  248. ixFeatureCtrlProductIdRead ()
  249. {
  250. #if CPU!=SIMSPARCSOLARIS
  251. IxFeatureCtrlProductId pdId = 0 ;
  252. /* Use ARM instruction to move register0 from coprocessor to ARM register */
  253. #ifndef __wince
  254. __asm__("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :);
  255. #else
  256. #ifndef IN_KERNEL
  257. BOOL mode;
  258. #endif
  259. extern IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead();
  260. #ifndef IN_KERNEL
  261. mode = SetKMode(true);
  262. #endif
  263. pdId = AsmixFeatureCtrlProductIdRead();
  264. #ifndef IN_KERNEL
  265. SetKMode(mode);
  266. #endif
  267. #endif
  268. return (pdId);
  269. #else
  270. /* Return an invalid value for VxWorks simulation */
  271. return 0xffffffff;
  272. #endif
  273. }
  274. /**
  275. * Function definition: ixFeatureCtrlDeviceRead
  276. */
  277. IxFeatureCtrlDeviceId
  278. ixFeatureCtrlDeviceRead ()
  279. {
  280. return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET)
  281. & IX_FEATURE_CTRL_DEVICE_TYPE_MASK);
  282. } /* End function ixFeatureCtrlDeviceRead */
  283. /**
  284. * Function definition: ixFeatureCtrlSwConfigurationCheck
  285. */
  286. IX_STATUS
  287. ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType)
  288. {
  289. if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
  290. {
  291. ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
  292. IX_OSAL_LOG_DEV_STDOUT,
  293. "FeatureCtrl: Invalid software configuraiton input.\n",
  294. 0, 0, 0, 0, 0, 0);
  295. return IX_FEATURE_CTRL_SWCONFIG_DISABLED;
  296. }
  297. /* The function will only initialize once. */
  298. ixFeatureCtrlSwConfigurationInit();
  299. /* Check and return software configuration */
  300. return ((swConfiguration[(UINT32)swConfigType] == true) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED);
  301. }
  302. /**
  303. * Function definition: ixFeatureCtrlSwConfigurationWrite
  304. */
  305. void
  306. ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled)
  307. {
  308. if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
  309. {
  310. ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
  311. IX_OSAL_LOG_DEV_STDOUT,
  312. "FeatureCtrl: Invalid software configuraiton input.\n",
  313. 0, 0, 0, 0, 0, 0);
  314. return;
  315. }
  316. /* The function will only initialize once. */
  317. ixFeatureCtrlSwConfigurationInit();
  318. /* Write software configuration */
  319. swConfiguration[(UINT32)swConfigType]=enabled ;
  320. }
  321. /**
  322. * Function definition: ixFeatureCtrlIxp400SwVersionShow
  323. */
  324. void
  325. ixFeatureCtrlIxp400SwVersionShow (void)
  326. {
  327. printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID);
  328. }
  329. /**
  330. * Function definition: ixFeatureCtrlSoftwareBuildGet
  331. */
  332. IxFeatureCtrlBuildDevice
  333. ixFeatureCtrlSoftwareBuildGet (void)
  334. {
  335. #ifdef __ixp42X
  336. return IX_FEATURE_CTRL_SW_BUILD_IXP42X;
  337. #else
  338. return IX_FEATURE_CTRL_SW_BUILD_IXP46X;
  339. #endif
  340. }