1 /*************************************************************************/ /*!
2 @File rgx_compact_bvnc.c
3 @Title BVNC compatibility check utilities
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description Utility functions used for packing BNC and V.
6 @License Dual MIT/GPLv2
8 The contents of this file are subject to the MIT license as set out below.
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
32 This License is also included in this distribution in the file called
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
44 #include "rgx_compat_bvnc.h"
45 #if defined(RGX_FIRMWARE)
46 #include "rgxfw_utils.h"
47 #elif !defined(RGX_BUILD_BINARY)
48 #include "pvr_debug.h"
51 #if defined(RGX_FIRMWARE)
52 #define PVR_COMPAT_ASSERT RGXFW_ASSERT
53 #elif !defined(RGX_BUILD_BINARY)
54 #define PVR_COMPAT_ASSERT PVR_ASSERT
57 #define PVR_COMPAT_ASSERT assert
60 /**************************************************************************//**
61 * C library strlen function.
62 *****************************************************************************/
63 static INLINE IMG_UINT32 OSStringLength(const IMG_CHAR* pszInput)
65 const IMG_CHAR* pszTemp = pszInput;
70 return (pszTemp - pszInput);
73 /**************************************************************************//**
74 * Utility function for packing BNC
75 *****************************************************************************/
76 static INLINE IMG_UINT64 rgx_bnc_pack(IMG_UINT32 ui32B, IMG_UINT32 ui32N,
80 * Test for input B, N and C exceeding max bit width.
82 PVR_COMPAT_ASSERT((ui32B & (~(RGX_BVNC_PACK_MASK_B >> RGX_BVNC_PACK_SHIFT_B))) == 0);
83 PVR_COMPAT_ASSERT((ui32N & (~(RGX_BVNC_PACK_MASK_N >> RGX_BVNC_PACK_SHIFT_N))) == 0);
84 PVR_COMPAT_ASSERT((ui32C & (~(RGX_BVNC_PACK_MASK_C >> RGX_BVNC_PACK_SHIFT_C))) == 0);
86 return (((IMG_UINT64)ui32B << RGX_BVNC_PACK_SHIFT_B) |
87 ((IMG_UINT64)ui32N << RGX_BVNC_PACK_SHIFT_N) |
88 ((IMG_UINT64)ui32C << RGX_BVNC_PACK_SHIFT_C));
91 /**************************************************************************//**
92 * Utility function for packing BNC and V to be used by compatibility check.
93 * BNC is packed into 48 bit format.
94 * If the array pointed to by pszV is a string that is shorter than
95 * ui32OutVMaxLen characters, null characters are appended to the copy in the
96 * array pointed to by pszOutV, until 'ui32OutVMaxLen' characters in all have
99 * @param: pui64OutBNC Output containing packed BNC.
100 * @param pszOutV Output containing version string.
101 * @param ui32OutVMaxLen Max characters that can be written to
102 pszOutV (excluding terminating null character)
103 * @param ui32B Input 'B' value
104 * @param pszV Input 'V' string
105 * @param ui32N Input 'N' value
106 * @param ui32C Input 'C' value
108 *****************************************************************************/
109 void rgx_bvnc_packed(IMG_UINT64 *pui64OutBNC, IMG_CHAR *pszOutV, IMG_UINT32 ui32OutVMaxLen,
110 IMG_UINT32 ui32B, IMG_CHAR *pszV, IMG_UINT32 ui32N, IMG_UINT32 ui32C)
112 *pui64OutBNC = rgx_bnc_pack(ui32B, ui32N, ui32C);
120 * Assert can fail for two reasons
121 * 1. Caller is passing invalid 'V' string or
122 * 2. Dest buffer does not have enough memory allocated for max 'V' size.
124 PVR_COMPAT_ASSERT(OSStringLength(pszV) <= ui32OutVMaxLen);
127 for (; ui32OutVMaxLen > 0 && *pszV != '\0'; --ui32OutVMaxLen)
129 /* When copying the V, omit any characters as these would cause
130 * the compatibility check against the V read from HW to fail
132 if (*pszV && (*pszV >= '0') && (*pszV <='9'))
134 *pszOutV++ = *pszV++;
146 }while(ui32OutVMaxLen-- > 0);
149 /**************************************************************************//**
150 * Utility function for packing BNC and V to be used by compatibility check.
151 * Input B,N and C is packed into 48 bit format.
152 * Input V is converted into string. If number of characters required to
153 * represent 16 bit wide version number is less than ui32OutVMaxLen, than null
154 * characters are appended to pszOutV, until ui32OutVMaxLen characters in all
157 * @param: pui64OutBNC Output containing packed BNC.
158 * @param pszOutV Output containing version string.
159 * @param ui32OutVMaxLen Max characters that can be written to
160 pszOutV (excluding terminating null character)
161 * @param ui32B Input 'B' value (16 bit wide)
162 * @param ui32V Input 'V' value (16 bit wide)
163 * @param ui32N Input 'N' value (16 bit wide)
164 * @param ui32C Input 'C' value (16 bit wide)
166 *****************************************************************************/
167 void rgx_bvnc_pack_hw(IMG_UINT64 *pui64OutBNC, IMG_CHAR *pszOutV, IMG_UINT32 ui32OutVMaxLen,
168 IMG_UINT32 ui32B, IMG_UINT32 ui32V, IMG_UINT32 ui32N, IMG_UINT32 ui32C)
171 * Allocate space for max digits required to represent 16 bit wide version
172 * number (including NULL terminating character).
175 IMG_CHAR *pszPointer = aszBuf;
177 *pui64OutBNC = rgx_bnc_pack(ui32B, ui32N, ui32C);
183 * Function only supports 16 bits wide version number.
185 PVR_COMPAT_ASSERT((ui32V & ~0xFFFF) == 0);
189 else if (ui32V > 999)
198 *pszPointer-- = '\0';
203 *pszPointer-- = (ui32V % 10) + '0';
207 for (pszPointer = aszBuf; ui32OutVMaxLen > 0 && *pszPointer != '\0'; --ui32OutVMaxLen)
208 *pszOutV++ = *pszPointer++;
211 * Append NULL characters.
216 }while(ui32OutVMaxLen-- > 0);