blob: 0b6807d9d7dc92053543ff0f83f5000b0f68a013 [file] [log] [blame]
Wolfgang Denk4646d2a2006-05-30 15:56:48 +02001/**
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
Wolfgang Denkc57eadc2013-07-28 22:12:47 +020020 * SPDX-License-Identifier: BSD-3-Clause
Wolfgang Denk4646d2a2006-05-30 15:56:48 +020021 * @par
22 * -- End of Copyright Notice --
23*/
24
25#include "IxOsal.h"
26#include "IxVersionId.h"
27#include "IxFeatureCtrl.h"
28
29/* Macro to read from the Feature Control Register */
30#define IX_FEATURE_CTRL_READ(result) \
31do { \
32ixFeatureCtrlExpMap(); \
33(result) = IX_OSAL_READ_LONG(ixFeatureCtrlRegister); \
34} while (0)
35
36/* Macro to write to the Feature Control Register */
37#define IX_FEATURE_CTRL_WRITE(value) \
38do { \
39ixFeatureCtrlExpMap(); \
40IX_OSAL_WRITE_LONG(ixFeatureCtrlRegister, (value)); \
41} while (0)
42
43/*
44 * This is the offset of the feature register relative to the base of the
45 * Expansion Bus Controller MMR.
46 */
47#define IX_FEATURE_CTRL_REG_OFFSET (0x00000028)
48
49
50/* Boolean to mark the fact that the EXP_CONFIG address space was mapped */
York Sun4a598092013-04-01 11:29:11 -070051PRIVATE BOOL ixFeatureCtrlExpCfgRegionMapped = false;
Wolfgang Denk4646d2a2006-05-30 15:56:48 +020052
53/* Pointer holding the virtual address of the Feature Control Register */
54PRIVATE VUINT32 *ixFeatureCtrlRegister = NULL;
55
56/* Place holder to store the software configuration */
57PRIVATE BOOL swConfiguration[IX_FEATURECTRL_SWCONFIG_MAX];
58
59/* Flag to control swConfiguration[] is initialized once */
York Sun4a598092013-04-01 11:29:11 -070060PRIVATE BOOL swConfigurationFlag = false ;
Wolfgang Denk4646d2a2006-05-30 15:56:48 +020061
62/* Array containing component mask values */
63#ifdef __ixp42X
64UINT32 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
88};
89#elif defined (__ixp46X)
90UINT32 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)
115};
116#endif /* __ixp42X */
117
118/**
119 * Forward declaration
120 */
121PRIVATE
122void ixFeatureCtrlExpMap(void);
123
124PRIVATE
125void ixFeatureCtrlSwConfigurationInit(void);
126
127/**
128 * Function to map EXP_CONFIG space
129 */
130PRIVATE
131void ixFeatureCtrlExpMap(void)
132{
133 UINT32 expCfgBaseAddress = 0;
134
135 /* If the EXP Configuration space has already been mapped then
136 * return */
York Sun4a598092013-04-01 11:29:11 -0700137 if (ixFeatureCtrlExpCfgRegionMapped == true)
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200138 {
139 return;
140 }
141
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));
146
147 /* Assert that the mapping operation succeeded */
148 IX_OSAL_ASSERT(expCfgBaseAddress);
149
150 /* Set the address of the Feature register */
151 ixFeatureCtrlRegister =
152 (VUINT32 *) (expCfgBaseAddress + IX_FEATURE_CTRL_REG_OFFSET);
153
154 /* Mark the fact that the EXP_CONFIG space has already been mapped */
York Sun4a598092013-04-01 11:29:11 -0700155 ixFeatureCtrlExpCfgRegionMapped = true;
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200156}
157
158/**
159 * Function definition: ixFeatureCtrlSwConfigurationInit
160 * This function will only initialize software configuration once.
161 */
162PRIVATE void ixFeatureCtrlSwConfigurationInit(void)
163{
164 UINT32 i;
York Sun4a598092013-04-01 11:29:11 -0700165 if (false == swConfigurationFlag)
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200166 {
167 for (i=0; i<IX_FEATURECTRL_SWCONFIG_MAX ; i++)
168 {
169 /* By default, all software configuration are enabled */
York Sun4a598092013-04-01 11:29:11 -0700170 swConfiguration[i]= true ;
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200171 }
172 /*Make sure this function only initializes swConfiguration[] once*/
York Sun4a598092013-04-01 11:29:11 -0700173 swConfigurationFlag = true ;
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200174 }
175}
176
177/**
178 * Function definition: ixFeatureCtrlRead
179 */
180IxFeatureCtrlReg
181ixFeatureCtrlRead (void)
182{
183 IxFeatureCtrlReg result;
184
185#if CPU!=SIMSPARCSOLARIS
186 /* Read the feature control register */
187 IX_FEATURE_CTRL_READ(result);
188 return result;
189#else
190 /* Return an invalid value for VxWorks simulation */
191 result = 0xFFFFFFFF;
192 return result;
193#endif
194}
195
196/**
197 * Function definition: ixFeatureCtrlWrite
198 */
199void
200ixFeatureCtrlWrite (IxFeatureCtrlReg expUnitReg)
201{
202#if CPU!=SIMSPARCSOLARIS
203 /* Write value to feature control register */
204 IX_FEATURE_CTRL_WRITE(expUnitReg);
205#endif
206}
207
208
209/**
210 * Function definition: ixFeatureCtrlHwCapabilityRead
211 */
212IxFeatureCtrlReg
213ixFeatureCtrlHwCapabilityRead (void)
214{
215 IxFeatureCtrlReg currentReg, hwCapability;
216
217 /* Capture a copy of feature control register */
218 currentReg = ixFeatureCtrlRead();
219
220 /* Try to enable all hardware components.
221 * Only software disable hardware can be enabled again */
222 ixFeatureCtrlWrite(0);
223
224 /* Read feature control register to know the hardware capability. */
225 hwCapability = ixFeatureCtrlRead();
226
227 /* Restore initial feature control value */
228 ixFeatureCtrlWrite(currentReg);
229
230 /* return Hardware Capability */
231 return hwCapability;
232}
233
234
235/**
236 * Function definition: ixFeatureCtrlComponentCheck
237 */
238IX_STATUS
239ixFeatureCtrlComponentCheck (IxFeatureCtrlComponentType componentType)
240{
241 IxFeatureCtrlReg expUnitReg;
242 UINT32 mask = 0;
243
244 /* Lookup mask of component */
245 mask=componentMask[componentType];
246
247 /* Check if mask is available or not */
248 if(IX_FEATURECTRL_COMPONENT_NOT_AVAILABLE == mask)
249 {
250 return IX_FEATURE_CTRL_COMPONENT_DISABLED;
251 }
252
253 if(IX_FEATURECTRL_COMPONENT_ALWAYS_AVAILABLE == mask)
254 {
255 return IX_FEATURE_CTRL_COMPONENT_ENABLED;
256 }
257
258 /* Read feature control register to know current hardware capability. */
259 expUnitReg = ixFeatureCtrlRead();
260
261 /* For example: To check for Hashing Coprocessor (bit-2)
262 * expUniteg = 0x0010
263 * ~expUnitReg = 0x1101
264 * componentType = 0x0100
265 * ~expUnitReg & componentType = 0x0100 (Not zero)
266 */
267
268 /*
269 * Inverse the bit value because available component is 0 in value
270 */
271 expUnitReg = ~expUnitReg ;
272
273 if (expUnitReg & mask)
274 {
275 return (IX_FEATURE_CTRL_COMPONENT_ENABLED);
276 }
277 else
278 {
279 return (IX_FEATURE_CTRL_COMPONENT_DISABLED);
280 }
281}
282
283
284/**
285 * Function definition: ixFeatureCtrlProductIdRead
286 */
287IxFeatureCtrlProductId
288ixFeatureCtrlProductIdRead ()
289{
290#if CPU!=SIMSPARCSOLARIS
291 IxFeatureCtrlProductId pdId = 0 ;
292
293 /* Use ARM instruction to move register0 from coprocessor to ARM register */
294
295#ifndef __wince
Peter Tyser745e27e2009-04-20 11:09:05 -0500296 __asm__("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(pdId) :);
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200297#else
298
299#ifndef IN_KERNEL
300 BOOL mode;
301#endif
302 extern IxFeatureCtrlProductId AsmixFeatureCtrlProductIdRead();
303
304#ifndef IN_KERNEL
York Sun4a598092013-04-01 11:29:11 -0700305 mode = SetKMode(true);
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200306#endif
307 pdId = AsmixFeatureCtrlProductIdRead();
308#ifndef IN_KERNEL
309 SetKMode(mode);
310#endif
311
312#endif
313 return (pdId);
314#else
315 /* Return an invalid value for VxWorks simulation */
316 return 0xffffffff;
317#endif
318}
319
320/**
321 * Function definition: ixFeatureCtrlDeviceRead
322 */
323IxFeatureCtrlDeviceId
324ixFeatureCtrlDeviceRead ()
325{
326 return ((ixFeatureCtrlProductIdRead() >> IX_FEATURE_CTRL_DEVICE_TYPE_OFFSET)
327 & IX_FEATURE_CTRL_DEVICE_TYPE_MASK);
328} /* End function ixFeatureCtrlDeviceRead */
329
330
331/**
332 * Function definition: ixFeatureCtrlSwConfigurationCheck
333 */
334IX_STATUS
335ixFeatureCtrlSwConfigurationCheck (IxFeatureCtrlSwConfig swConfigType)
336{
337 if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
338 {
339 ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
340 IX_OSAL_LOG_DEV_STDOUT,
341 "FeatureCtrl: Invalid software configuraiton input.\n",
342 0, 0, 0, 0, 0, 0);
343
344 return IX_FEATURE_CTRL_SWCONFIG_DISABLED;
345 }
346
347 /* The function will only initialize once. */
348 ixFeatureCtrlSwConfigurationInit();
349
350 /* Check and return software configuration */
York Sun4a598092013-04-01 11:29:11 -0700351 return ((swConfiguration[(UINT32)swConfigType] == true) ? IX_FEATURE_CTRL_SWCONFIG_ENABLED: IX_FEATURE_CTRL_SWCONFIG_DISABLED);
Wolfgang Denk4646d2a2006-05-30 15:56:48 +0200352}
353
354/**
355 * Function definition: ixFeatureCtrlSwConfigurationWrite
356 */
357void
358ixFeatureCtrlSwConfigurationWrite (IxFeatureCtrlSwConfig swConfigType, BOOL enabled)
359{
360 if (swConfigType >= IX_FEATURECTRL_SWCONFIG_MAX)
361 {
362 ixOsalLog(IX_OSAL_LOG_LVL_WARNING,
363 IX_OSAL_LOG_DEV_STDOUT,
364 "FeatureCtrl: Invalid software configuraiton input.\n",
365 0, 0, 0, 0, 0, 0);
366
367 return;
368 }
369
370 /* The function will only initialize once. */
371 ixFeatureCtrlSwConfigurationInit();
372
373 /* Write software configuration */
374 swConfiguration[(UINT32)swConfigType]=enabled ;
375}
376
377/**
378 * Function definition: ixFeatureCtrlIxp400SwVersionShow
379 */
380void
381ixFeatureCtrlIxp400SwVersionShow (void)
382{
383 printf ("\nIXP400 Software Release %s %s\n\n", IX_VERSION_ID, IX_VERSION_INTERNAL_ID);
384
385}
386
387/**
388 * Function definition: ixFeatureCtrlSoftwareBuildGet
389 */
390IxFeatureCtrlBuildDevice
391ixFeatureCtrlSoftwareBuildGet (void)
392{
393 #ifdef __ixp42X
394 return IX_FEATURE_CTRL_SW_BUILD_IXP42X;
395 #else
396 return IX_FEATURE_CTRL_SW_BUILD_IXP46X;
397 #endif
398}