Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 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 | |
| 49 | #include "IxOsal.h" |
| 50 | #include "IxVersionId.h" |
| 51 | #include "IxFeatureCtrl.h" |
| 52 | |
| 53 | /* Macro to read from the Feature Control Register */ |
| 54 | #define IX_FEATURE_CTRL_READ(result) \ |
| 55 | do { \ |
| 56 | ixFeatureCtrlExpMap(); \ |
| 57 | (result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \ |
| 58 | } while (0) |
| 59 | |
| 60 | /* Macro to write to the Feature Control Register */ |
| 61 | #define IX_FEATURE_CTRL_WRITE(value) \ |
| 62 | do { \ |
| 63 | ixFeatureCtrlExpMap(); \ |
| 64 | IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \ |
| 65 | } while (0) |
| 66 | |
| 67 | /* |
| 68 | * This is the offset of the feature register relative to the base of the |
| 69 | * Expansion Bus Controller MMR. |
| 70 | */ |
| 71 | #define IX_FEATURE_CTRL_REG_OFFSET (0x00000028) |
| 72 | |
| 73 | |
| 74 | /* Boolean to mark the fact that the EXP_CONFIG address space was mapped */ |
| 75 | PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = FALSE; |
| 76 | |
| 77 | /* Pointer holding the virtual address of the Feature Control Register */ |
| 78 | PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL; |
| 79 | |
| 80 | /* Place holder to store the software configuration */ |
| 81 | PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX]; |
| 82 | |
| 83 | /* Flag to control swConfiguration[] is initialized once */ |
| 84 | PRIVATE BOOL swConfigurationFlag = FALSE ; |
| 85 | |
| 86 | /* Array containing component mask values */ |
| 87 | #ifdef __ixp42X |
| 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 |
| 112 | }; |
| 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) |
| 139 | }; |
| 140 | #endif /* __ixp42X */ |
| 141 | |
| 142 | /** |
| 143 | * Forward declaration |
| 144 | */ |
| 145 | PRIVATE |
| 146 | void ixFeatureCtrlExpMap(void); |
| 147 | |
| 148 | PRIVATE |
| 149 | void ixFeatureCtrlSwConfigurationInit(void); |
| 150 | |
| 151 | /** |
| 152 | * Function to map EXP_CONFIG space |
| 153 | */ |
| 154 | PRIVATE |
| 155 | void ixFeatureCtrlExpMap(void) |
| 156 | { |
| 157 | UINT32 expCfgBaseAddress = 0; |
| 158 | |
| 159 | /* If the EXP Configuration space has already been mapped then |
| 160 | * return */ |
| 161 | if (ixFeatureCtrlExpCfgRegionMapped == TRUE) |
| 162 | { |
| 163 | return; |
| 164 | } |
| 165 | |
| 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)); |
| 170 | |
| 171 | /* Assert that the mapping operation succeeded */ |
| 172 | IX_OSAL_ASSERT(expCfgBaseAddress); |
| 173 | |
| 174 | /* Set the address of the Feature register */ |
| 175 | ixFeatureCtrlRegister = |
| 176 | (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET); |
| 177 | |
| 178 | /* Mark the fact that the EXP_CONFIG space has already been mapped */ |
| 179 | ixFeatureCtrlExpCfgRegionMapped = TRUE; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Function definition: ixFeatureCtrlSwConfigurationInit |
| 184 | * This function will only initialize software configuration once. |
| 185 | */ |
| 186 | PRIVATE void ixFeatureCtrlSwConfigurationInit(void) |
| 187 | { |
| 188 | UINT32 i; |
| 189 | if (FALSE == swConfigurationFlag) |
| 190 | { |
| 191 | for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++) |
| 192 | { |
| 193 | /* By default, all software configuration are enabled */ |
| 194 | swConfiguration[i]= TRUE ; |
| 195 | } |
| 196 | /*Make sure this function only initializes swConfiguration[] once*/ |
| 197 | swConfigurationFlag = TRUE ; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Function definition: ixFeatureCtrlRead |
| 203 | */ |
| 204 | IxFeatureCtrlReg |
| 205 | ixFeatureCtrlRead (void) |
| 206 | { |
| 207 | IxFeatureCtrlReg result; |
| 208 | |
| 209 | #if CPU!=SIMSPARCSOLARIS |
| 210 | /* Read the feature control register */ |
| 211 | IX_FEATURE_CTRL_READ(result); |
| 212 | return result; |
| 213 | #else |
| 214 | /* Return an invalid value for VxWorks simulation */ |
| 215 | result = 0xFFFFFFFF; |
| 216 | return result; |
| 217 | #endif |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Function definition: ixFeatureCtrlWrite |
| 222 | */ |
| 223 | void |
| 224 | ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg) |
| 225 | { |
| 226 | #if CPU!=SIMSPARCSOLARIS |
| 227 | /* Write value to feature control register */ |
| 228 | IX_FEATURE_CTRL_WRITE(expUnitReg); |
| 229 | #endif |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /** |
| 234 | * Function definition: ixFeatureCtrlHwCapabilityRead |
| 235 | */ |
| 236 | IxFeatureCtrlReg |
| 237 | ixFeatureCtrlHwCapabilityRead (void) |
| 238 | { |
| 239 | IxFeatureCtrlReg currentReg, hwCapability; |
| 240 | |
| 241 | /* Capture a copy of feature control register */ |
| 242 | currentReg = ixFeatureCtrlRead(); |
| 243 | |
| 244 | /* Try to enable all hardware components. |
| 245 | * Only software disable hardware can be enabled again */ |
| 246 | ixFeatureCtrlWrite(0); |
| 247 | |
| 248 | /* Read feature control register to know the hardware capability. */ |
| 249 | hwCapability = ixFeatureCtrlRead(); |
| 250 | |
| 251 | /* Restore initial feature control value */ |
| 252 | ixFeatureCtrlWrite(currentReg); |
| 253 | |
| 254 | /* return Hardware Capability */ |
| 255 | return hwCapability; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /** |
| 260 | * Function definition: ixFeatureCtrlComponentCheck |
| 261 | */ |
| 262 | IX_STATUS |
| 263 | ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType) |
| 264 | { |
| 265 | IxFeatureCtrlReg expUnitReg; |
| 266 | UINT32 mask = 0; |
| 267 | |
| 268 | /* Lookup mask of component */ |
| 269 | mask=componentMask[componentType]; |
| 270 | |
| 271 | /* Check if mask is available or not */ |
| 272 | if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask) |
| 273 | { |
| 274 | return IX_FEATURE_CTRL_COMPONENT_DISABLED; |
| 275 | } |
| 276 | |
| 277 | if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask) |
| 278 | { |
| 279 | return IX_FEATURE_CTRL_COMPONENT_ENABLED; |
| 280 | } |
| 281 | |
| 282 | /* Read feature control register to know current hardware capability. */ |
| 283 | expUnitReg = ixFeatureCtrlRead(); |
| 284 | |
| 285 | /* For example: To check for Hashing Coprocessor (bit-2) |
| 286 | * expUniteg = 0x0010 |
| 287 | * ~expUnitReg = 0x1101 |
| 288 | * componentType = 0x0100 |
| 289 | * ~expUnitReg & componentType = 0x0100 (Not zero) |
| 290 | */ |
| 291 | |
| 292 | /* |
| 293 | * Inverse the bit value because available component is 0 in value |
| 294 | */ |
| 295 | expUnitReg = ~expUnitReg ; |
| 296 | |
| 297 | if (expUnitReg & mask) |
| 298 | { |
| 299 | return (IX_FEATURE_CTRL_COMPONENT_ENABLED); |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | return (IX_FEATURE_CTRL_COMPONENT_DISABLED); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | |
| 308 | /** |
| 309 | * Function definition: ixFeatureCtrlProductIdRead |
| 310 | */ |
| 311 | IxFeatureCtrlProductId |
| 312 | ixFeatureCtrlProductIdRead () |
| 313 | { |
| 314 | #if CPU!=SIMSPARCSOLARIS |
| 315 | IxFeatureCtrlProductId pdId = 0 ; |
| 316 | |
| 317 | /* Use ARM instruction to move register0 from coprocessor to ARM register */ |
| 318 | |
| 319 | #ifndef __wince |
| 320 | __asm("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :); |
| 321 | #else |
| 322 | |
| 323 | #ifndef IN_KERNEL |
| 324 | BOOL mode; |
| 325 | #endif |
| 326 | extern IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead(); |
| 327 | |
| 328 | #ifndef IN_KERNEL |
| 329 | mode = SetKMode(TRUE); |
| 330 | #endif |
| 331 | pdId = AsmixFeatureCtrlProductIdRead(); |
| 332 | #ifndef IN_KERNEL |
| 333 | SetKMode(mode); |
| 334 | #endif |
| 335 | |
| 336 | #endif |
| 337 | return (pdId); |
| 338 | #else |
| 339 | /* Return an invalid value for VxWorks simulation */ |
| 340 | return 0xffffffff; |
| 341 | #endif |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Function definition: ixFeatureCtrlDeviceRead |
| 346 | */ |
| 347 | IxFeatureCtrlDeviceId |
| 348 | ixFeatureCtrlDeviceRead () |
| 349 | { |
| 350 | return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET) |
| 351 | & IX_FEATURE_CTRL_DEVICE_TYPE_MASK); |
| 352 | } /* End function ixFeatureCtrlDeviceRead */ |
| 353 | |
| 354 | |
| 355 | /** |
| 356 | * Function definition: ixFeatureCtrlSwConfigurationCheck |
| 357 | */ |
| 358 | IX_STATUS |
| 359 | ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType) |
| 360 | { |
| 361 | if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX) |
| 362 | { |
| 363 | ixOsalLog(IX_OSAL_LOG_LVL_WARNING, |
| 364 | IX_OSAL_LOG_DEV_STDOUT, |
| 365 | "FeatureCtrl: Invalid software configuraiton input.\n", |
| 366 | 0, 0, 0, 0, 0, 0); |
| 367 | |
| 368 | return IX_FEATURE_CTRL_SWCONFIG_DISABLED; |
| 369 | } |
| 370 | |
| 371 | /* The function will only initialize once. */ |
| 372 | ixFeatureCtrlSwConfigurationInit(); |
| 373 | |
| 374 | /* Check and return software configuration */ |
| 375 | return ((swConfiguration[(UINT32)swConfigType] == TRUE) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Function definition: ixFeatureCtrlSwConfigurationWrite |
| 380 | */ |
| 381 | void |
| 382 | ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled) |
| 383 | { |
| 384 | if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX) |
| 385 | { |
| 386 | ixOsalLog(IX_OSAL_LOG_LVL_WARNING, |
| 387 | IX_OSAL_LOG_DEV_STDOUT, |
| 388 | "FeatureCtrl: Invalid software configuraiton input.\n", |
| 389 | 0, 0, 0, 0, 0, 0); |
| 390 | |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | /* The function will only initialize once. */ |
| 395 | ixFeatureCtrlSwConfigurationInit(); |
| 396 | |
| 397 | /* Write software configuration */ |
| 398 | swConfiguration[(UINT32)swConfigType]=enabled ; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Function definition: ixFeatureCtrlIxp400SwVersionShow |
| 403 | */ |
| 404 | void |
| 405 | ixFeatureCtrlIxp400SwVersionShow (void) |
| 406 | { |
| 407 | printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID); |
| 408 | |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Function definition: ixFeatureCtrlSoftwareBuildGet |
| 413 | */ |
| 414 | IxFeatureCtrlBuildDevice |
| 415 | ixFeatureCtrlSoftwareBuildGet (void) |
| 416 | { |
| 417 | #ifdef __ixp42X |
| 418 | return IX_FEATURE_CTRL_SW_BUILD_IXP42X; |
| 419 | #else |
| 420 | return IX_FEATURE_CTRL_SW_BUILD_IXP46X; |
| 421 | #endif |
| 422 | } |