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 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
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.
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
46 * -- End of Copyright Notice --
50 #include "IxVersionId.h"
51 #include "IxFeatureCtrl.h"
53 /* Macro to read from the Feature Control Register */
54 #define IX_FEATURE_CTRL_READ(result) \
56 ixFeatureCtrlExpMap(); \
57 (result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \
60 /* Macro to write to the Feature Control Register */
61 #define IX_FEATURE_CTRL_WRITE(value) \
63 ixFeatureCtrlExpMap(); \
64 IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \
68 * This is the offset of the feature register relative to the base of the
69 * Expansion Bus Controller MMR.
71 #define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
74 /* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
75 PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped
= FALSE
;
77 /* Pointer holding the virtual address of the Feature Control Register */
78 PRIVATE VUINT32
*ixFeatureCtrlRegister
= NULL
;
80 /* Place holder to store the software configuration */
81 PRIVATE BOOL swConfiguration
[IX_FEATURECTRL_SWCONFIG_MAX
];
83 /* Flag to control swConfiguration[] is initialized once */
84 PRIVATE BOOL swConfigurationFlag
= FALSE
;
86 /* Array containing component mask values */
88 UINT32 componentMask
[IX_FEATURECTRL_MAX_COMPONENTS
] = {
89 (0x1<<IX_FEATURECTRL_RCOMP
),
90 (0x1<<IX_FEATURECTRL_USB
),
91 (0x1<<IX_FEATURECTRL_HASH
),
92 (0x1<<IX_FEATURECTRL_AES
),
93 (0x1<<IX_FEATURECTRL_DES
),
94 (0x1<<IX_FEATURECTRL_HDLC
),
95 (0x1<<IX_FEATURECTRL_AAL
),
96 (0x1<<IX_FEATURECTRL_HSS
),
97 (0x1<<IX_FEATURECTRL_UTOPIA
),
98 (0x1<<IX_FEATURECTRL_ETH0
),
99 (0x1<<IX_FEATURECTRL_ETH1
),
100 (0x1<<IX_FEATURECTRL_NPEA
),
101 (0x1<<IX_FEATURECTRL_NPEB
),
102 (0x1<<IX_FEATURECTRL_NPEC
),
103 (0x1<<IX_FEATURECTRL_PCI
),
104 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
,
105 (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT
),
106 (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2
),
107 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
,
108 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
,
109 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
,
110 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
,
111 IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
113 #elif defined (__ixp46X)
114 UINT32 componentMask
[IX_FEATURECTRL_MAX_COMPONENTS
] = {
115 (0x1<<IX_FEATURECTRL_RCOMP
),
116 (0x1<<IX_FEATURECTRL_USB
),
117 (0x1<<IX_FEATURECTRL_HASH
),
118 (0x1<<IX_FEATURECTRL_AES
),
119 (0x1<<IX_FEATURECTRL_DES
),
120 (0x1<<IX_FEATURECTRL_HDLC
),
121 IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE
, /* AAL component is always on */
122 (0x1<<IX_FEATURECTRL_HSS
),
123 (0x1<<IX_FEATURECTRL_UTOPIA
),
124 (0x1<<IX_FEATURECTRL_ETH0
),
125 (0x1<<IX_FEATURECTRL_ETH1
),
126 (0x1<<IX_FEATURECTRL_NPEA
),
127 (0x1<<IX_FEATURECTRL_NPEB
),
128 (0x1<<IX_FEATURECTRL_NPEC
),
129 (0x1<<IX_FEATURECTRL_PCI
),
130 (0x1<<IX_FEATURECTRL_ECC_TIMESYNC
),
131 (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT
),
132 (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2
), /* NOT TO BE USED */
133 (0x1<<IX_FEATURECTRL_USB_HOST_CONTROLLER
),
134 (0x1<<IX_FEATURECTRL_NPEA_ETH
),
135 (0x1<<IX_FEATURECTRL_NPEB_ETH
),
136 (0x1<<IX_FEATURECTRL_RSA
),
137 (0x3<<IX_FEATURECTRL_XSCALE_MAX_FREQ
),
138 (0x1<<IX_FEATURECTRL_XSCALE_MAX_FREQ_BIT2
)
140 #endif /* __ixp42X */
143 * Forward declaration
146 void ixFeatureCtrlExpMap(void);
149 void ixFeatureCtrlSwConfigurationInit(void);
152 * Function to map EXP_CONFIG space
155 void ixFeatureCtrlExpMap(void)
157 UINT32 expCfgBaseAddress
= 0;
159 /* If the EXP Configuration space has already been mapped then
161 if (ixFeatureCtrlExpCfgRegionMapped
== TRUE
)
166 /* Map (get virtual address) for the EXP_CONFIG space */
167 expCfgBaseAddress
= (UINT32
)
168 (IX_OSAL_MEM_MAP(IX_OSAL_IXP400_EXP_BUS_REGS_PHYS_BASE
,
169 IX_OSAL_IXP400_EXP_REG_MAP_SIZE
));
171 /* Assert that the mapping operation succeeded */
172 IX_OSAL_ASSERT(expCfgBaseAddress
);
174 /* Set the address of the Feature register */
175 ixFeatureCtrlRegister
=
176 (VUINT32
*) (expCfgBaseAddress
+ IX_FEATURE_CTRL_REG_OFFSET
);
178 /* Mark the fact that the EXP_CONFIG space has already been mapped */
179 ixFeatureCtrlExpCfgRegionMapped
= TRUE
;
183 * Function definition: ixFeatureCtrlSwConfigurationInit
184 * This function will only initialize software configuration once.
186 PRIVATE
void ixFeatureCtrlSwConfigurationInit(void)
189 if (FALSE
== swConfigurationFlag
)
191 for (i
=0; i
<IX_FEATURECTRL_SWCONFIG_MAX
; i
++)
193 /* By default, all software configuration are enabled */
194 swConfiguration
[i
]= TRUE
;
196 /*Make sure this function only initializes swConfiguration[] once*/
197 swConfigurationFlag
= TRUE
;
202 * Function definition: ixFeatureCtrlRead
205 ixFeatureCtrlRead (void)
207 IxFeatureCtrlReg result
;
209 #if CPU!=SIMSPARCSOLARIS
210 /* Read the feature control register */
211 IX_FEATURE_CTRL_READ(result
);
214 /* Return an invalid value for VxWorks simulation */
221 * Function definition: ixFeatureCtrlWrite
224 ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg
)
226 #if CPU!=SIMSPARCSOLARIS
227 /* Write value to feature control register */
228 IX_FEATURE_CTRL_WRITE(expUnitReg
);
234 * Function definition: ixFeatureCtrlHwCapabilityRead
237 ixFeatureCtrlHwCapabilityRead (void)
239 IxFeatureCtrlReg currentReg
, hwCapability
;
241 /* Capture a copy of feature control register */
242 currentReg
= ixFeatureCtrlRead();
244 /* Try to enable all hardware components.
245 * Only software disable hardware can be enabled again */
246 ixFeatureCtrlWrite(0);
248 /* Read feature control register to know the hardware capability. */
249 hwCapability
= ixFeatureCtrlRead();
251 /* Restore initial feature control value */
252 ixFeatureCtrlWrite(currentReg
);
254 /* return Hardware Capability */
260 * Function definition: ixFeatureCtrlComponentCheck
263 ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType
)
265 IxFeatureCtrlReg expUnitReg
;
268 /* Lookup mask of component */
269 mask
=componentMask
[componentType
];
271 /* Check if mask is available or not */
272 if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
== mask
)
274 return IX_FEATURE_CTRL_COMPONENT_DISABLED
;
277 if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE
== mask
)
279 return IX_FEATURE_CTRL_COMPONENT_ENABLED
;
282 /* Read feature control register to know current hardware capability. */
283 expUnitReg
= ixFeatureCtrlRead();
285 /* For example: To check for Hashing Coprocessor (bit-2)
287 * ~expUnitReg = 0x1101
288 * componentType = 0x0100
289 * ~expUnitReg & componentType = 0x0100 (Not zero)
293 * Inverse the bit value because available component is 0 in value
295 expUnitReg
= ~expUnitReg
;
297 if (expUnitReg
& mask
)
299 return (IX_FEATURE_CTRL_COMPONENT_ENABLED
);
303 return (IX_FEATURE_CTRL_COMPONENT_DISABLED
);
309 * Function definition: ixFeatureCtrlProductIdRead
311 IxFeatureCtrlProductId
312 ixFeatureCtrlProductIdRead ()
314 #if CPU!=SIMSPARCSOLARIS
315 IxFeatureCtrlProductId pdId
= 0 ;
317 /* Use ARM instruction to move register0 from coprocessor to ARM register */
320 __asm__("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId
) :);
326 extern IxFeatureCtrlProductId
AsmixFeatureCtrlProductIdRead();
329 mode
= SetKMode(TRUE
);
331 pdId
= AsmixFeatureCtrlProductIdRead();
339 /* Return an invalid value for VxWorks simulation */
345 * Function definition: ixFeatureCtrlDeviceRead
347 IxFeatureCtrlDeviceId
348 ixFeatureCtrlDeviceRead ()
350 return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET
)
351 & IX_FEATURE_CTRL_DEVICE_TYPE_MASK
);
352 } /* End function ixFeatureCtrlDeviceRead */
356 * Function definition: ixFeatureCtrlSwConfigurationCheck
359 ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType
)
361 if (swConfigType
>= IX_FEATURECTRL_SWCONFIG_MAX
)
363 ixOsalLog(IX_OSAL_LOG_LVL_WARNING
,
364 IX_OSAL_LOG_DEV_STDOUT
,
365 "FeatureCtrl: Invalid software configuraiton input.\n",
368 return IX_FEATURE_CTRL_SWCONFIG_DISABLED
;
371 /* The function will only initialize once. */
372 ixFeatureCtrlSwConfigurationInit();
374 /* Check and return software configuration */
375 return ((swConfiguration
[(UINT32
)swConfigType
] == TRUE
) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED
: IX_FEATURE_CTRL_SWCONFIG_DISABLED
);
379 * Function definition: ixFeatureCtrlSwConfigurationWrite
382 ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType
, BOOL enabled
)
384 if (swConfigType
>= IX_FEATURECTRL_SWCONFIG_MAX
)
386 ixOsalLog(IX_OSAL_LOG_LVL_WARNING
,
387 IX_OSAL_LOG_DEV_STDOUT
,
388 "FeatureCtrl: Invalid software configuraiton input.\n",
394 /* The function will only initialize once. */
395 ixFeatureCtrlSwConfigurationInit();
397 /* Write software configuration */
398 swConfiguration
[(UINT32
)swConfigType
]=enabled
;
402 * Function definition: ixFeatureCtrlIxp400SwVersionShow
405 ixFeatureCtrlIxp400SwVersionShow (void)
407 printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID
, IX_VERSION_INTERNAL_ID
);
412 * Function definition: ixFeatureCtrlSoftwareBuildGet
414 IxFeatureCtrlBuildDevice
415 ixFeatureCtrlSoftwareBuildGet (void)
418 return IX_FEATURE_CTRL_SW_BUILD_IXP42X
;
420 return IX_FEATURE_CTRL_SW_BUILD_IXP46X
;