2 * Copyright © 2014 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 ***************************************************************************************************
30 * @brief Contains the helper function and constants
31 ***************************************************************************************************
34 #ifndef __ADDR_COMMON_H__
35 #define __ADDR_COMMON_H__
37 #include "addrinterface.h"
40 // ADDR_LNX_KERNEL_BUILD is for internal build
41 // Moved from addrinterface.h so __KERNEL__ is not needed any more
42 #if ADDR_LNX_KERNEL_BUILD // || (defined(__GNUC__) && defined(__KERNEL__))
43 #include "lnx_common_defs.h" // ported from cmmqs
44 #elif !defined(__APPLE__)
49 ///////////////////////////////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////////////////////////////////
52 static const UINT_32 MicroTileWidth
= 8; ///< Micro tile width, for 1D and 2D tiling
53 static const UINT_32 MicroTileHeight
= 8; ///< Micro tile height, for 1D and 2D tiling
54 static const UINT_32 ThickTileThickness
= 4; ///< Micro tile thickness, for THICK modes
55 static const UINT_32 XThickTileThickness
= 8; ///< Extra thick tiling thickness
56 static const UINT_32 PowerSaveTileBytes
= 64; ///< Nuber of bytes per tile for power save 64
57 static const UINT_32 CmaskCacheBits
= 1024; ///< Number of bits for CMASK cache
58 static const UINT_32 CmaskElemBits
= 4; ///< Number of bits for CMASK element
59 static const UINT_32 HtileCacheBits
= 16384; ///< Number of bits for HTILE cache 512*32
61 static const UINT_32 MicroTilePixels
= MicroTileWidth
* MicroTileHeight
;
63 static const INT_32 TileIndexInvalid
= TILEINDEX_INVALID
;
64 static const INT_32 TileIndexLinearGeneral
= TILEINDEX_LINEAR_GENERAL
;
65 static const INT_32 TileIndexNoMacroIndex
= -3;
67 ///////////////////////////////////////////////////////////////////////////////////////////////////
69 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 #define BITS_PER_BYTE 8
71 #define BITS_TO_BYTES(x) ( ((x) + (BITS_PER_BYTE-1)) / BITS_PER_BYTE )
72 #define BYTES_TO_BITS(x) ( (x) * BITS_PER_BYTE )
74 /// Helper macros to select a single bit from an int (undefined later in section)
75 #define _BIT(v,b) (((v) >> (b) ) & 1)
78 ***************************************************************************************************
79 * @brief Enums to identify AddrLib type
80 ***************************************************************************************************
92 ***************************************************************************************************
96 * Neutral enums that specifies chip family.
98 ***************************************************************************************************
102 ADDR_CHIP_FAMILY_IVLD
, ///< Invalid family
103 ADDR_CHIP_FAMILY_R6XX
,
104 ADDR_CHIP_FAMILY_R7XX
,
105 ADDR_CHIP_FAMILY_R8XX
,
113 ***************************************************************************************************
117 * This structure is used to set addr configuration flags.
118 ***************************************************************************************************
120 union ADDR_CONFIG_FLAGS
124 /// Clients do not need to set these flags except forceLinearAligned.
125 /// There flags are set up by AddrLib inside thru AddrInitGlobalParamsFromRegister
126 UINT_32 optimalBankSwap
: 1; ///< New bank tiling for RV770 only
127 UINT_32 noCubeMipSlicesPad
: 1; ///< Disables faces padding for cubemap mipmaps
128 UINT_32 fillSizeFields
: 1; ///< If clients fill size fields in all input and
130 UINT_32 ignoreTileInfo
: 1; ///< Don't use tile info structure
131 UINT_32 useTileIndex
: 1; ///< Make tileIndex field in input valid
132 UINT_32 useCombinedSwizzle
: 1; ///< Use combined swizzle
133 UINT_32 checkLast2DLevel
: 1; ///< Check the last 2D mip sub level
134 UINT_32 useHtileSliceAlign
: 1; ///< Do htile single slice alignment
135 UINT_32 degradeBaseLevel
: 1; ///< Degrade to 1D modes automatically for base level
136 UINT_32 allowLargeThickTile
: 1; ///< Allow 64*thickness*bytesPerPixel > rowSize
137 UINT_32 reserved
: 22; ///< Reserved bits for future use
143 ///////////////////////////////////////////////////////////////////////////////////////////////////
144 // Platform specific debug break defines
145 ///////////////////////////////////////////////////////////////////////////////////////////////////
147 #if defined(__GNUC__)
148 #define ADDR_DBG_BREAK()
149 #elif defined(__APPLE__)
150 #define ADDR_DBG_BREAK() { IOPanic("");}
152 #define ADDR_DBG_BREAK() { __debugbreak(); }
155 #define ADDR_DBG_BREAK()
157 ///////////////////////////////////////////////////////////////////////////////////////////////////
159 ///////////////////////////////////////////////////////////////////////////////////////////////////
160 // Debug assertions used in AddrLib
161 ///////////////////////////////////////////////////////////////////////////////////////////////////
163 #define ADDR_ASSERT(__e) if ( !((__e) ? TRUE : FALSE)) { ADDR_DBG_BREAK(); }
164 #define ADDR_ASSERT_ALWAYS() ADDR_DBG_BREAK()
165 #define ADDR_UNHANDLED_CASE() ADDR_ASSERT(!"Unhandled case")
166 #define ADDR_NOT_IMPLEMENTED() ADDR_ASSERT(!"Not implemented");
168 #define ADDR_ASSERT(__e)
169 #define ADDR_ASSERT_ALWAYS()
170 #define ADDR_UNHANDLED_CASE()
171 #define ADDR_NOT_IMPLEMENTED()
173 ///////////////////////////////////////////////////////////////////////////////////////////////////
175 ///////////////////////////////////////////////////////////////////////////////////////////////////
176 // Debug print macro from legacy address library
177 ///////////////////////////////////////////////////////////////////////////////////////////////////
180 #define ADDR_PRNT(a) AddrObject::DebugPrint a
182 /// @brief Macro for reporting informational messages
185 /// This macro optionally prints an informational message to stdout.
186 /// The first parameter is a condition -- if it is true, nothing is done.
187 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
188 /// starting with a string. This is passed to printf() or an equivalent
189 /// in order to format the informational message. For example,
190 /// ADDR_INFO(0, ("test %d",3) ); prints out "test 3".
192 #define ADDR_INFO(cond, a) \
193 { if (!(cond)) { ADDR_PRNT(a); } }
196 /// @brief Macro for reporting error warning messages
199 /// This macro optionally prints an error warning message to stdout,
200 /// followed by the file name and line number where the macro was called.
201 /// The first parameter is a condition -- if it is true, nothing is done.
202 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
203 /// starting with a string. This is passed to printf() or an equivalent
204 /// in order to format the informational message. For example,
205 /// ADDR_WARN(0, ("test %d",3) ); prints out "test 3" followed by
206 /// a second line with the file name and line number.
208 #define ADDR_WARN(cond, a) \
211 ADDR_PRNT((" WARNING in file %s, line %d\n", __FILE__, __LINE__)); \
215 /// @brief Macro for reporting fatal error conditions
218 /// This macro optionally stops execution of the current routine
219 /// after printing an error warning message to stdout,
220 /// followed by the file name and line number where the macro was called.
221 /// The first parameter is a condition -- if it is true, nothing is done.
222 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
223 /// starting with a string. This is passed to printf() or an equivalent
224 /// in order to format the informational message. For example,
225 /// ADDR_EXIT(0, ("test %d",3) ); prints out "test 3" followed by
226 /// a second line with the file name and line number, then stops execution.
228 #define ADDR_EXIT(cond, a) \
230 { ADDR_PRNT(a); ADDR_DBG_BREAK();\
235 #define ADDRDPF 1 ? (void)0 : (void)
239 #define ADDR_DBG_BREAK()
241 #define ADDR_INFO(cond, a)
243 #define ADDR_WARN(cond, a)
245 #define ADDR_EXIT(cond, a)
248 ///////////////////////////////////////////////////////////////////////////////////////////////////
250 ///////////////////////////////////////////////////////////////////////////////////////////////////
251 // Misc helper functions
252 ////////////////////////////////////////////////////////////////////////////////////////////////////
255 ***************************************************************************************************
259 * Xor the right-side numberOfBits bits of x.
260 ***************************************************************************************************
262 static inline UINT_32
XorReduce(
264 UINT_32 numberOfBits
)
267 UINT_32 result
= x
& 1;
269 for (i
=1; i
<numberOfBits
; i
++)
271 result
^= ((x
>>i
) & 1);
278 ***************************************************************************************************
282 * Check if the size (UINT_32) is pow 2
283 ***************************************************************************************************
285 static inline UINT_32
IsPow2(
286 UINT_32 dim
) ///< [in] dimension of miplevel
288 ADDR_ASSERT(dim
> 0);
289 return !(dim
& (dim
- 1));
293 ***************************************************************************************************
297 * Check if the size (UINT_64) is pow 2
298 ***************************************************************************************************
300 static inline UINT_64
IsPow2(
301 UINT_64 dim
) ///< [in] dimension of miplevel
303 ADDR_ASSERT(dim
> 0);
304 return !(dim
& (dim
- 1));
308 ***************************************************************************************************
312 * Align UINT_32 "x" to "align" alignment, "align" should be power of 2
313 ***************************************************************************************************
315 static inline UINT_32
PowTwoAlign(
320 // Assert that x is a power of two.
322 ADDR_ASSERT(IsPow2(align
));
323 return (x
+ (align
- 1)) & (~(align
- 1));
327 ***************************************************************************************************
331 * Align UINT_64 "x" to "align" alignment, "align" should be power of 2
332 ***************************************************************************************************
334 static inline UINT_64
PowTwoAlign(
339 // Assert that x is a power of two.
341 ADDR_ASSERT(IsPow2(align
));
342 return (x
+ (align
- 1)) & (~(align
- 1));
346 ***************************************************************************************************
350 * Get the min value between two unsigned values
351 ***************************************************************************************************
353 static inline UINT_32
Min(
357 return ((value1
< (value2
)) ? (value1
) : value2
);
361 ***************************************************************************************************
365 * Get the min value between two signed values
366 ***************************************************************************************************
368 static inline INT_32
Min(
372 return ((value1
< (value2
)) ? (value1
) : value2
);
376 ***************************************************************************************************
380 * Get the max value between two unsigned values
381 ***************************************************************************************************
383 static inline UINT_32
Max(
387 return ((value1
> (value2
)) ? (value1
) : value2
);
391 ***************************************************************************************************
395 * Get the max value between two signed values
396 ***************************************************************************************************
398 static inline INT_32
Max(
402 return ((value1
> (value2
)) ? (value1
) : value2
);
406 ***************************************************************************************************
410 * Compute the mipmap's next level dim size
411 ***************************************************************************************************
413 static inline UINT_32
NextPow2(
414 UINT_32 dim
) ///< [in] dimension of miplevel
420 if (dim
> 0x7fffffff)
422 ADDR_ASSERT_ALWAYS();
437 ***************************************************************************************************
441 * Compute log of base 2
442 ***************************************************************************************************
444 static inline UINT_32
Log2(
445 UINT_32 x
) ///< [in] the value should calculate log based 2
450 // Assert that x is a power of two.
452 ADDR_ASSERT(IsPow2(x
));
465 ***************************************************************************************************
469 * Compute log of base 2 quickly (<= 16)
470 ***************************************************************************************************
472 static inline UINT_32
QLog2(
473 UINT_32 x
) ///< [in] the value should calculate log based 2
475 ADDR_ASSERT(x
<= 16);
497 ADDR_ASSERT_ALWAYS();
504 ***************************************************************************************************
508 * NULL pointer safe assignment
509 ***************************************************************************************************
511 static inline VOID
SafeAssign(
512 UINT_32
* pLVal
, ///< [in] Pointer to left val
513 UINT_32 rVal
) ///< [in] Right value
522 ***************************************************************************************************
526 * NULL pointer safe assignment for 64bit values
527 ***************************************************************************************************
529 static inline VOID
SafeAssign(
530 UINT_64
* pLVal
, ///< [in] Pointer to left val
531 UINT_64 rVal
) ///< [in] Right value
540 ***************************************************************************************************
544 * NULL pointer safe assignment for AddrTileMode
545 ***************************************************************************************************
547 static inline VOID
SafeAssign(
548 AddrTileMode
* pLVal
, ///< [in] Pointer to left val
549 AddrTileMode rVal
) ///< [in] Right value
557 #endif // __ADDR_COMMON_H__