source: SVN/cambria/redboot/packages/devs/eth/intel/npe/featureCtrl/current/src/IxFeatureCtrl.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 12.8 KB
Line 
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.3
12 *
13 * -- Copyright Notice --
14 *
15 * @par
16 * Copyright (c) 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 *
33 * @par
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
35 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 *
46 *
47 * @par
48 * -- End of Copyright Notice --
49*/
50
51#include "IxOsal.h"
52#include "IxVersionId.h"
53#include "IxFeatureCtrlMacros_p.h"
54#include "IxFeatureCtrl_sp.h"
55
56/*
57 * This is the offset of the feature register relative to the base of the
58 * Expansion Bus Controller MMR.
59 */
60#define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
61
62/* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
63PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = FALSE;
64
65/* Pointer holding the virtual address of the Feature Control Register */
66PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL;
67
68/* Place holder to store the software configuration */
69PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX];
70
71/* Flag to control swConfiguration[] is initialized once */
72PRIVATE BOOL swConfigurationFlag = FALSE ;
73
74/* Array containing component mask values */
75#if defined(__ixp42X)
76UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
77    (0x1<<IX_FEATURECTRL_RCOMP),
78    (0x1<<IX_FEATURECTRL_USB),
79    (0x1<<IX_FEATURECTRL_HASH),
80    (0x1<<IX_FEATURECTRL_AES),
81    (0x1<<IX_FEATURECTRL_DES),
82    (0x1<<IX_FEATURECTRL_HDLC),
83    (0x1<<IX_FEATURECTRL_AAL),
84    (0x1<<IX_FEATURECTRL_HSS),
85    (0x1<<IX_FEATURECTRL_UTOPIA),
86    (0x1<<IX_FEATURECTRL_ETH0),
87    (0x1<<IX_FEATURECTRL_ETH1),
88    (0x1<<IX_FEATURECTRL_NPEA),
89    (0x1<<IX_FEATURECTRL_NPEB),
90    (0x1<<IX_FEATURECTRL_NPEC),
91    (0x1<<IX_FEATURECTRL_PCI),
92    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
93    (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
94    (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2),
95    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
96    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
97    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
98    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
99    IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE
100};
101#endif /* __ixp42X */
102
103#if defined (__ixp46X)
104UINT32 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 /* __ixp46X */
131
132#if defined (__ixp43X)
133UINT32 componentMask[IX_FEATURECTRL_MAX_COMPONENTS] = {
134   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
135   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
136   (0x1<<IX_FEATURECTRL_HASH),
137   (0x1<<IX_FEATURECTRL_AES),
138   (0x1<<IX_FEATURECTRL_DES),
139   (0x1<<IX_FEATURECTRL_HDLC),
140   IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE, /* AAL component is always on */
141   (0x1<<IX_FEATURECTRL_HSS),
142   (0x1<<IX_FEATURECTRL_UTOPIA),
143   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
144   (0x1<<IX_FEATURECTRL_ETH1),
145   (0x1<<IX_FEATURECTRL_NPEA),
146   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
147   (0x1<<IX_FEATURECTRL_NPEC),
148   (0x1<<IX_FEATURECTRL_PCI),
149   (0x1<<IX_FEATURECTRL_ECC_TIMESYNC),
150   (0x3<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT),
151   (0x1<<IX_FEATURECTRL_UTOPIA_PHY_LIMIT_BIT2), /* NOT TO BE USED */
152   (0x1<<IX_FEATURECTRL_USB_HOST_CONTROLLER),
153   (0x1<<IX_FEATURECTRL_NPEA_ETH),
154   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
155   IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE,
156   (0x3<<IX_FEATURECTRL_XSCALE_MAX_FREQ),
157   (0x1<<IX_FEATURECTRL_XSCALE_MAX_FREQ_BIT2)
158};
159#endif /* __ixp43X */
160
161/**
162 * Forward declaration
163 */
164PRIVATE
165void ixFeatureCtrlExpMap(void);
166
167PRIVATE
168void ixFeatureCtrlSwConfigurationInit(void);
169
170UINT32 expCfgBaseAddress = 0;
171
172/**
173 * Function to map EXP_CONFIG space
174 */
175PRIVATE
176void ixFeatureCtrlExpMap(void)
177{
178
179    /* If the EXP Configuration space has already been mapped then
180     * return */
181    if (ixFeatureCtrlExpCfgRegionMapped == TRUE)
182    {
183        return;
184    }
185
186    /* Map (get virtual address) for the EXP_CONFIG space */
187    expCfgBaseAddress = (UINT32)
188        (IX_OSAL_MEM_MAP(IX_OSAL_IXP400_EXP_BUS_REGS_PHYS_BASE,
189                           IX_OSAL_IXP400_EXP_REG_MAP_SIZE));
190
191    /* Assert that the mapping operation succeeded */
192    IX_OSAL_ASSERT(expCfgBaseAddress);
193
194    /* Set the address of the Feature register */
195    ixFeatureCtrlRegister =
196        (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET);
197
198    /* Mark the fact that the EXP_CONFIG space has already been mapped */
199    ixFeatureCtrlExpCfgRegionMapped = TRUE;
200}
201
202/**
203 * Function definition: ixFeatureCtrlSwConfigurationInit
204 * This function will only initialize software configuration once.
205 */
206PRIVATE void ixFeatureCtrlSwConfigurationInit(void)
207{
208  UINT32 i;
209  if (FALSE == swConfigurationFlag)
210  {
211    for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++)
212    {
213        /* By default, all software configuration are enabled */
214        swConfiguration[i]= TRUE ;
215    }
216    /*Make sure this function only initializes swConfiguration[] once*/
217    swConfigurationFlag = TRUE ;
218  } 
219}
220
221/**
222 * Function definition: ixFeatureCtrlRead
223 */
224IxFeatureCtrlReg
225ixFeatureCtrlRead (void)
226{
227    IxFeatureCtrlReg result;
228    ixFeatureCtrlExpMap();
229    /*  Read the feature control register */
230    IX_FEATURE_CTRL_READ((UINT32)ixFeatureCtrlRegister, result);
231    return result;
232}
233
234/**
235 * Function definition: ixFeatureCtrlWrite
236 */
237void
238ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg)
239{
240  ixFeatureCtrlExpMap();
241    /* Write value to feature control register */
242    IX_FEATURE_CTRL_WRITE((UINT32)ixFeatureCtrlRegister, expUnitReg);
243}
244
245
246/**
247 * Function definition: ixFeatureCtrlHwCapabilityRead
248 */
249IxFeatureCtrlReg
250ixFeatureCtrlHwCapabilityRead (void)
251{ 
252  IxFeatureCtrlReg currentReg, hwCapability;
253 
254  /* Capture a copy of feature control register */
255  currentReg = ixFeatureCtrlRead(); 
256
257  /* Try to enable all hardware components.
258   * Only software disable hardware can be enabled again */
259  ixFeatureCtrlWrite(0);
260 
261  /* Read feature control register to know the hardware capability. */ 
262  hwCapability = ixFeatureCtrlRead();
263     
264  /* Restore initial feature control value */
265  ixFeatureCtrlWrite(currentReg);
266
267  /* return Hardware Capability */
268  return hwCapability; 
269}
270
271
272/**
273 * Function definition: ixFeatureCtrlComponentCheck
274 */
275IX_STATUS
276ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType)
277{
278  IxFeatureCtrlReg expUnitReg; 
279  UINT32 mask = 0;
280
281  /* Lookup mask of component */
282  mask=componentMask[componentType];
283
284  /* Check if mask is available or not */
285  if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask)
286  {
287      return IX_FEATURE_CTRL_COMPONENT_DISABLED;
288  }
289
290  if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask)
291  {
292      return IX_FEATURE_CTRL_COMPONENT_ENABLED;
293  }
294
295  /* Read feature control register to know current hardware capability. */ 
296  expUnitReg = ixFeatureCtrlRead();
297
298  /* For example: To check for Hashing Coprocessor (bit-2)
299   *                   expUniteg    = 0x0010
300   *                  ~expUnitReg   = 0x1101
301   *                  componentType = 0x0100
302   *    ~expUnitReg & componentType = 0x0100 (Not zero)                     
303   */
304 
305  /*
306   * Inverse the bit value because available component is 0 in value
307   */
308  expUnitReg = ~expUnitReg ;
309
310  if (expUnitReg & mask)
311  {
312     return (IX_FEATURE_CTRL_COMPONENT_ENABLED);
313  }   
314  else
315  { 
316     return (IX_FEATURE_CTRL_COMPONENT_DISABLED);
317  } 
318}
319
320
321#ifdef _DIAB_TOOL
322__asm  volatile IxFeatureCtrlProductId _ixFeatureCtrlAsmProductIdRead()
323{
324! "r0"
325    mrc p15, 0, r0, c0, c0, 0; /* return value is returned through register R0 */
326}
327#endif /* #ifdef _DIAB_TOOL */
328
329
330/**
331 * Function definition: ixFeatureCtrlProductIdRead
332 */
333IxFeatureCtrlProductId
334ixFeatureCtrlProductIdRead ()
335{
336#if ((CPU!=SIMSPARCSOLARIS) && (CPU!=SIMLINUX))
337  IxFeatureCtrlProductId  pdId = 0 ;
338   
339  /* Use ARM instruction to move register0 from coprocessor to ARM register */ 
340   
341#ifndef __wince
342#ifdef _DIAB_TOOL
343    pdId = _ixFeatureCtrlAsmProductIdRead();
344#else
345    __asm("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :); 
346#endif /* #ifdef _DIAB_TOOL */
347#else
348     
349#ifndef IN_KERNEL
350        BOOL  mode;
351#endif
352    extern  IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead();
353   
354#ifndef IN_KERNEL
355    mode = SetKMode(TRUE);
356#endif
357    pdId = AsmixFeatureCtrlProductIdRead();
358#ifndef IN_KERNEL
359    SetKMode(mode);
360#endif
361
362#endif
363#if defined(CYGHWR_HAL_ARM_XSCALE_CPU_IXP43x)
364    /* this makes IXP435 look like IXP465 instead of IXP425 */
365    pdId | (1 << IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET);
366#endif
367  return (((pdId&0xFFFFFFF0)+((pdId&IX_FEATURE_CTRL_SILICON_STEPPING_MASK)?1:0)));
368#else
369  /* Return an invalid value for VxWorks simulation */
370  return 0xffffffff;
371#endif
372}
373
374/**
375 * Function definition: ixFeatureCtrlDeviceRead
376 */
377IxFeatureCtrlDeviceId
378ixFeatureCtrlDeviceRead ()
379{
380  return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET) 
381             & IX_FEATURE_CTRL_DEVICE_TYPE_MASK);
382} /* End function ixFeatureCtrlDeviceRead */
383
384
385/**
386 * Function definition: ixFeatureCtrlSwConfigurationCheck
387 */
388IX_STATUS
389ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType)
390{
391  if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX) 
392  {
393     ixOsalLog(IX_OSAL_LOG_LVL_WARNING, 
394               IX_OSAL_LOG_DEV_STDOUT,
395               "FeatureCtrl: Invalid software configuration input.\n",
396               0, 0, 0, 0, 0, 0); 
397
398     return IX_FEATURE_CTRL_SWCONFIG_DISABLED;
399  }
400
401  /* The function will only initialize once. */
402  ixFeatureCtrlSwConfigurationInit();
403 
404  /* Check and return software configuration */
405  return  ((swConfiguration[(UINT32)swConfigType] == TRUE) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED);
406}
407
408/**
409 * Function definition: ixFeatureCtrlSwConfigurationWrite
410 */
411void
412ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled)
413{
414  if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX) 
415  {
416     ixOsalLog(IX_OSAL_LOG_LVL_WARNING, 
417               IX_OSAL_LOG_DEV_STDOUT,
418               "FeatureCtrl: Invalid software configuration input.\n",
419               0, 0, 0, 0, 0, 0); 
420
421     return;
422  }
423
424  /* The function will only initialize once. */
425  ixFeatureCtrlSwConfigurationInit();
426 
427  /* Write software configuration */
428  swConfiguration[(UINT32)swConfigType]=enabled ;
429}
430
431/**
432 * Function definition: ixFeatureCtrlIxp400SwVersionShow
433 */
434void
435ixFeatureCtrlSwVersionShow (void)
436{
437    printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID);
438
439}
440
441/**
442 * Function definition: ixFeatureCtrlSoftwareBuildGet
443 */
444IxFeatureCtrlBuildDevice
445ixFeatureCtrlSoftwareBuildGet (void)
446{
447#if defined(__ixp42X)
448    return IX_FEATURE_CTRL_SW_BUILD_IXP42X;
449#endif /* __ixp42X */
450
451#if defined (__ixp46X)
452    return IX_FEATURE_CTRL_SW_BUILD_IXP46X;
453#endif /* __ixp46X */
454
455#if defined (__ixp43X)
456    return IX_FEATURE_CTRL_SW_BUILD_IXP43X;
457#endif /* __ixp46X */
458}
Note: See TracBrowser for help on using the repository browser.