2 * @file IxFeatureCtrl.c
4 * @author Intel Corporation
7 * @brief Feature Control Public API Implementation
11 * IXP400 SW Release version 2.0
13 * -- Copyright Notice --
16 * Copyright 2001-2005, Intel Corporation.
17 * All rights reserved.
20 * SPDX-License-Identifier: BSD-3-Clause
22 * -- End of Copyright Notice --
26 #include "IxVersionId.h"
27 #include "IxFeatureCtrl.h"
29 /* Macro to read from the Feature Control Register */
30 #define IX_FEATURE_CTRL_READ(result) \
32 ixFeatureCtrlExpMap(); \
33 (result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \
36 /* Macro to write to the Feature Control Register */
37 #define IX_FEATURE_CTRL_WRITE(value) \
39 ixFeatureCtrlExpMap(); \
40 IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \
44 * This is the offset of the feature register relative to the base of the
45 * Expansion Bus Controller MMR.
47 #define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
50 /* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
51 PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = false;
53 /* Pointer holding the virtual address of the Feature Control Register */
54 PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL;
56 /* Place holder to store the software configuration */
57 PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX];
59 /* Flag to control swConfiguration[] is initialized once */
60 PRIVATE BOOL swConfigurationFlag = false ;
62 /* Array containing component mask values */
64 UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
65 (0x1<<IX_FEATURECTRL_RCOMP),
66 (0x1<<IX_FEATURECTRL_USB),
67 (0x1<<IX_FEATURECTRL_HASH),
68 (0x1<<IX_FEATURECTRL_AES),
69 (0x1<<IX_FEATURECTRL_DES),
70 (0x1<<IX_FEATURECTRL_HDLC),
71 (0x1<<IX_FEATURECTRL_AAL),
72 (0x1<<IX_FEATURECTRL_HSS),
73 (0x1<<IX_FEATURECTRL_UTOPIA),
74 (0x1<<IX_FEATURECTRL_ETH0),
75 (0x1<<IX_FEATURECTRL_ETH1),
76 (0x1<<IX_FEATURECTRL_NPEA),
77 (0x1<<IX_FEATURECTRL_NPEB),
78 (0x1<<IX_FEATURECTRL_NPEC),
79 (0x1<<IX_FEATURECTRL_PCI),
80 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
81 (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
82 (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2),
83 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
84 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
85 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
86 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
87 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
89 #elif defined (__ixp46X)
90 UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
91 (0x1<<IX_FEATURECTRL_RCOMP),
92 (0x1<<IX_FEATURECTRL_USB),
93 (0x1<<IX_FEATURECTRL_HASH),
94 (0x1<<IX_FEATURECTRL_AES),
95 (0x1<<IX_FEATURECTRL_DES),
96 (0x1<<IX_FEATURECTRL_HDLC),
97 IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE, /* AAL component is always on */
98 (0x1<<IX_FEATURECTRL_HSS),
99 (0x1<<IX_FEATURECTRL_UTOPIA),
100 (0x1<<IX_FEATURECTRL_ETH0),
101 (0x1<<IX_FEATURECTRL_ETH1),
102 (0x1<<IX_FEATURECTRL_NPEA),
103 (0x1<<IX_FEATURECTRL_NPEB),
104 (0x1<<IX_FEATURECTRL_NPEC),
105 (0x1<<IX_FEATURECTRL_PCI),
106 (0x1<<IX_FEATURECTRL_ECC_TIMESYNC),
107 (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
108 (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2), /* NOT TO BE USED */
109 (0x1<<IX_FEATURECTRL_USB_HOST_CONTROLLER),
110 (0x1<<IX_FEATURECTRL_NPEA_ETH),
111 (0x1<<IX_FEATURECTRL_NPEB_ETH),
112 (0x1<<IX_FEATURECTRL_RSA),
113 (0x3<<IX_FEATURECTRL_XSCALE_MAX_FREQ),
114 (0x1<<IX_FEATURECTRL_XSCALE_MAX_FREQ_BIT2)
116 #endif /* __ixp42X */
119 * Forward declaration
122 void ixFeatureCtrlExpMap(void);
125 void ixFeatureCtrlSwConfigurationInit(void);
128 * Function to map EXP_CONFIG space
131 void ixFeatureCtrlExpMap(void)
133 UINT32 expCfgBaseAddress = 0;
135 /* If the EXP Configuration space has already been mapped then
137 if (ixFeatureCtrlExpCfgRegionMapped == true)
142 /* Map (get virtual address) for the EXP_CONFIG space */
143 expCfgBaseAddress = (UINT32)
144 (IX_OSAL_MEM_MAP(IX_OSAL_IXP400_EXP_BUS_REGS_PHYS_BASE,
145 IX_OSAL_IXP400_EXP_REG_MAP_SIZE));
147 /* Assert that the mapping operation succeeded */
148 IX_OSAL_ASSERT(expCfgBaseAddress);
150 /* Set the address of the Feature register */
151 ixFeatureCtrlRegister =
152 (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET);
154 /* Mark the fact that the EXP_CONFIG space has already been mapped */
155 ixFeatureCtrlExpCfgRegionMapped = true;
159 * Function definition: ixFeatureCtrlSwConfigurationInit
160 * This function will only initialize software configuration once.
162 PRIVATE void ixFeatureCtrlSwConfigurationInit(void)
165 if (false == swConfigurationFlag)
167 for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++)
169 /* By default, all software configuration are enabled */
170 swConfiguration[i]= true ;
172 /*Make sure this function only initializes swConfiguration[] once*/
173 swConfigurationFlag = true ;
178 * Function definition: ixFeatureCtrlRead
181 ixFeatureCtrlRead (void)
183 IxFeatureCtrlReg result;
185 #if CPU!=SIMSPARCSOLARIS
186 /* Read the feature control register */
187 IX_FEATURE_CTRL_READ(result);
190 /* Return an invalid value for VxWorks simulation */
197 * Function definition: ixFeatureCtrlWrite
200 ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg)
202 #if CPU!=SIMSPARCSOLARIS
203 /* Write value to feature control register */
204 IX_FEATURE_CTRL_WRITE(expUnitReg);
210 * Function definition: ixFeatureCtrlHwCapabilityRead
213 ixFeatureCtrlHwCapabilityRead (void)
215 IxFeatureCtrlReg currentReg, hwCapability;
217 /* Capture a copy of feature control register */
218 currentReg = ixFeatureCtrlRead();
220 /* Try to enable all hardware components.
221 * Only software disable hardware can be enabled again */
222 ixFeatureCtrlWrite(0);
224 /* Read feature control register to know the hardware capability. */
225 hwCapability = ixFeatureCtrlRead();
227 /* Restore initial feature control value */
228 ixFeatureCtrlWrite(currentReg);
230 /* return Hardware Capability */
236 * Function definition: ixFeatureCtrlComponentCheck
239 ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType)
241 IxFeatureCtrlReg expUnitReg;
244 /* Lookup mask of component */
245 mask=componentMask[componentType];
247 /* Check if mask is available or not */
248 if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask)
250 return IX_FEATURE_CTRL_COMPONENT_DISABLED;
253 if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask)
255 return IX_FEATURE_CTRL_COMPONENT_ENABLED;
258 /* Read feature control register to know current hardware capability. */
259 expUnitReg = ixFeatureCtrlRead();
261 /* For example: To check for Hashing Coprocessor (bit-2)
263 * ~expUnitReg = 0x1101
264 * componentType = 0x0100
265 * ~expUnitReg & componentType = 0x0100 (Not zero)
269 * Inverse the bit value because available component is 0 in value
271 expUnitReg = ~expUnitReg ;
273 if (expUnitReg & mask)
275 return (IX_FEATURE_CTRL_COMPONENT_ENABLED);
279 return (IX_FEATURE_CTRL_COMPONENT_DISABLED);
285 * Function definition: ixFeatureCtrlProductIdRead
287 IxFeatureCtrlProductId
288 ixFeatureCtrlProductIdRead ()
290 #if CPU!=SIMSPARCSOLARIS
291 IxFeatureCtrlProductId pdId = 0 ;
293 /* Use ARM instruction to move register0 from coprocessor to ARM register */
296 __asm__("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :);
302 extern IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead();
305 mode = SetKMode(true);
307 pdId = AsmixFeatureCtrlProductIdRead();
315 /* Return an invalid value for VxWorks simulation */
321 * Function definition: ixFeatureCtrlDeviceRead
323 IxFeatureCtrlDeviceId
324 ixFeatureCtrlDeviceRead ()
326 return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET)
327 & IX_FEATURE_CTRL_DEVICE_TYPE_MASK);
328 } /* End function ixFeatureCtrlDeviceRead */
332 * Function definition: ixFeatureCtrlSwConfigurationCheck
335 ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType)
337 if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
339 ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
340 IX_OSAL_LOG_DEV_STDOUT,
341 "FeatureCtrl: Invalid software configuraiton input.\n",
344 return IX_FEATURE_CTRL_SWCONFIG_DISABLED;
347 /* The function will only initialize once. */
348 ixFeatureCtrlSwConfigurationInit();
350 /* Check and return software configuration */
351 return ((swConfiguration[(UINT32)swConfigType] == true) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED);
355 * Function definition: ixFeatureCtrlSwConfigurationWrite
358 ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled)
360 if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
362 ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
363 IX_OSAL_LOG_DEV_STDOUT,
364 "FeatureCtrl: Invalid software configuraiton input.\n",
370 /* The function will only initialize once. */
371 ixFeatureCtrlSwConfigurationInit();
373 /* Write software configuration */
374 swConfiguration[(UINT32)swConfigType]=enabled ;
378 * Function definition: ixFeatureCtrlIxp400SwVersionShow
381 ixFeatureCtrlIxp400SwVersionShow (void)
383 printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID);
388 * Function definition: ixFeatureCtrlSoftwareBuildGet
390 IxFeatureCtrlBuildDevice
391 ixFeatureCtrlSoftwareBuildGet (void)
394 return IX_FEATURE_CTRL_SW_BUILD_IXP42X;
396 return IX_FEATURE_CTRL_SW_BUILD_IXP46X;