1 /******************************************************************************
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
12 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
13 * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
14 * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
15 * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
16 * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
17 * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
18 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
19 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
20 * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
21 * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE.
25 * Xilinx hardware products are not intended for use in life support
26 * appliances, devices, or systems. Use in such applications is
27 * expressly prohibited.
30 * (c) Copyright 2002-2004 Xilinx Inc.
31 * All rights reserved.
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 675 Mass Ave, Cambridge, MA 02139, USA.
38 ******************************************************************************/
39 /*****************************************************************************
41 * This file contains the implementation of the XVersion component. This
42 * component represents a version ID. It is encapsulated within a component
43 * so that it's type and implementation can change without affecting users of
46 * The version is formatted as X.YYZ where X = 0 - 9, Y = 00 - 99, Z = a - z
47 * X is the major revision, YY is the minor revision, and Z is the
48 * compatability revision.
50 * Packed versions are also utilized for the configuration ROM such that
51 * memory is minimized. A packed version consumes only 16 bits and is
52 * formatted as follows.
55 * Revision Range Bit Positions
57 * Major Revision 0 - 9 Bits 15 - 12
58 * Minor Revision 0 - 99 Bits 11 - 5
59 * Compatability Revision a - z Bits 4 - 0
62 ******************************************************************************/
64 /***************************** Include Files *********************************/
66 #include "xbasic_types.h"
69 /************************** Constant Definitions *****************************/
71 /* the following constants define the masks and shift values to allow the
72 * revisions to be packed and unpacked, a packed version is packed into a 16
73 * bit value in the following format, XXXXYYYYYYYZZZZZ, where XXXX is the
74 * major revision, YYYYYYY is the minor revision, and ZZZZZ is the compatability
77 #define XVE_MAJOR_SHIFT_VALUE 12
78 #define XVE_MINOR_ONLY_MASK 0x0FE0
79 #define XVE_MINOR_SHIFT_VALUE 5
80 #define XVE_COMP_ONLY_MASK 0x001F
82 /* the following constants define the specific characters of a version string
83 * for each character of the revision, a version string is in the following
84 * format, "X.YYZ" where X is the major revision (0 - 9), YY is the minor
85 * revision (00 - 99), and Z is the compatability revision (a - z)
87 #define XVE_MAJOR_CHAR 0 /* major revision 0 - 9 */
88 #define XVE_MINOR_TENS_CHAR 2 /* minor revision tens 0 - 9 */
89 #define XVE_MINOR_ONES_CHAR 3 /* minor revision ones 0 - 9 */
90 #define XVE_COMP_CHAR 4 /* compatability revision a - z */
91 #define XVE_END_STRING_CHAR 5
93 /**************************** Type Definitions *******************************/
95 /***************** Macros (Inline Functions) Definitions *********************/
97 /************************** Function Prototypes ******************************/
99 static u32 IsVersionStringValid(s8 * StringPtr);
101 /*****************************************************************************
103 * Unpacks a packed version into the specified version. Versions are packed
104 * into the configuration ROM to reduce the amount storage. A packed version
105 * is a binary format as oppossed to a non-packed version which is implemented
108 * @param InstancePtr points to the version to unpack the packed version into.
109 * @param PackedVersion contains the packed version to unpack.
119 ******************************************************************************/
121 XVersion_UnPack(XVersion * InstancePtr, u16 PackedVersion)
123 /* not implemented yet since CROM related */
126 /*****************************************************************************
128 * Packs a version into the specified packed version. Versions are packed into
129 * the configuration ROM to reduce the amount storage.
131 * @param InstancePtr points to the version to pack.
132 * @param PackedVersionPtr points to the packed version which will receive
133 * the new packed version.
137 * A status, XST_SUCCESS, indicating the packing was accomplished
138 * successfully, or an error, XST_INVALID_VERSION, indicating the specified
139 * input version was not valid such that the pack did not occur
141 * The packed version pointed to by PackedVersionPtr is modified with the new
142 * packed version if the status indicates success.
148 ******************************************************************************/
150 XVersion_Pack(XVersion * InstancePtr, u16 * PackedVersionPtr)
152 /* not implemented yet since CROM related */
157 /*****************************************************************************
159 * Determines if two versions are equal.
161 * @param InstancePtr points to the first version to be compared.
162 * @param VersionPtr points to a second version to be compared.
166 * TRUE if the versions are equal, FALSE otherwise.
172 ******************************************************************************/
174 XVersion_IsEqual(XVersion * InstancePtr, XVersion * VersionPtr)
176 u8 *Version1 = (u8 *) InstancePtr;
177 u8 *Version2 = (u8 *) VersionPtr;
180 /* assert to verify input arguments */
182 XASSERT_NONVOID(InstancePtr != NULL);
183 XASSERT_NONVOID(VersionPtr != NULL);
185 /* check each byte of the versions to see if they are the same,
186 * return at any point a byte differs between them
188 for (Index = 0; Index < sizeof (XVersion); Index++) {
189 if (Version1[Index] != Version2[Index]) {
194 /* No byte was found to be different between the versions, so indicate
195 * the versions are equal
200 /*****************************************************************************
202 * Converts a version to a null terminated string.
204 * @param InstancePtr points to the version to convert.
205 * @param StringPtr points to the string which will be the result of the
206 * conversion. This does not need to point to a null terminated
207 * string as an input, but must point to storage which is an adequate
208 * amount to hold the result string.
212 * The null terminated string is inserted at the location pointed to by
213 * StringPtr if the status indicates success.
217 * It is necessary for the caller to have already allocated the storage to
218 * contain the string. The amount of memory necessary for the string is
219 * specified in the version header file.
221 ******************************************************************************/
223 XVersion_ToString(XVersion * InstancePtr, s8 * StringPtr)
225 /* assert to verify input arguments */
227 XASSERT_VOID(InstancePtr != NULL);
228 XASSERT_VOID(StringPtr != NULL);
230 /* since version is implemented as a string, just copy the specified
231 * input into the specified output
233 XVersion_Copy(InstancePtr, (XVersion *) StringPtr);
236 /*****************************************************************************
238 * Initializes a version from a null terminated string. Since the string may not
239 * be a format which is compatible with the version, an error could occur.
241 * @param InstancePtr points to the version which is to be initialized.
242 * @param StringPtr points to a null terminated string which will be
243 * converted to a version. The format of the string must match the
244 * version string format which is X.YYX where X = 0 - 9, YY = 00 - 99,
249 * A status, XST_SUCCESS, indicating the conversion was accomplished
250 * successfully, or XST_INVALID_VERSION indicating the version string format
257 ******************************************************************************/
259 XVersion_FromString(XVersion * InstancePtr, s8 * StringPtr)
261 /* assert to verify input arguments */
263 XASSERT_NONVOID(InstancePtr != NULL);
264 XASSERT_NONVOID(StringPtr != NULL);
266 /* if the version string specified is not valid, return an error */
268 if (!IsVersionStringValid(StringPtr)) {
269 return XST_INVALID_VERSION;
272 /* copy the specified string into the specified version and indicate the
273 * conversion was successful
275 XVersion_Copy((XVersion *) StringPtr, InstancePtr);
280 /*****************************************************************************
282 * Copies the contents of a version to another version.
284 * @param InstancePtr points to the version which is the source of data for
285 * the copy operation.
286 * @param VersionPtr points to another version which is the destination of
287 * the copy operation.
297 ******************************************************************************/
299 XVersion_Copy(XVersion * InstancePtr, XVersion * VersionPtr)
301 u8 *Source = (u8 *) InstancePtr;
302 u8 *Destination = (u8 *) VersionPtr;
305 /* assert to verify input arguments */
307 XASSERT_VOID(InstancePtr != NULL);
308 XASSERT_VOID(VersionPtr != NULL);
310 /* copy each byte of the source version to the destination version */
312 for (Index = 0; Index < sizeof (XVersion); Index++) {
313 Destination[Index] = Source[Index];
317 /*****************************************************************************
319 * Determines if the specified version is valid.
321 * @param StringPtr points to the string to be validated.
325 * TRUE if the version string is a valid format, FALSE otherwise.
331 ******************************************************************************/
333 IsVersionStringValid(s8 * StringPtr)
335 /* if the input string is not a valid format, "X.YYZ" where X = 0 - 9,
336 * YY = 00 - 99, and Z = a - z, then indicate it's not valid
338 if ((StringPtr[XVE_MAJOR_CHAR] < '0') ||
339 (StringPtr[XVE_MAJOR_CHAR] > '9') ||
340 (StringPtr[XVE_MINOR_TENS_CHAR] < '0') ||
341 (StringPtr[XVE_MINOR_TENS_CHAR] > '9') ||
342 (StringPtr[XVE_MINOR_ONES_CHAR] < '0') ||
343 (StringPtr[XVE_MINOR_ONES_CHAR] > '9') ||
344 (StringPtr[XVE_COMP_CHAR] < 'a') ||
345 (StringPtr[XVE_COMP_CHAR] > 'z')) {