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__) || defined(HAVE_TSERVER)
49 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 // Platform specific debug break defines
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
54 #define ADDR_DBG_BREAK()
55 #elif defined(__APPLE__)
56 #define ADDR_DBG_BREAK() { IOPanic("");}
58 #define ADDR_DBG_BREAK() { __debugbreak(); }
61 #define ADDR_DBG_BREAK()
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
65 ////////////////////////////////////////////////////////////////////////////////////////////////////
66 // Debug assertions used in AddrLib
67 ////////////////////////////////////////////////////////////////////////////////////////////////////
68 #if defined(_WIN32) && (_MSC_VER >= 1400)
69 #define ADDR_ANALYSIS_ASSUME(expr) __analysis_assume(expr)
71 #define ADDR_ANALYSIS_ASSUME(expr) do { } while (0)
75 #define ADDR_ASSERT(__e) \
77 ADDR_ANALYSIS_ASSUME(__e); \
78 if ( !((__e) ? TRUE : FALSE)) { ADDR_DBG_BREAK(); } \
80 #define ADDR_ASSERT_ALWAYS() ADDR_DBG_BREAK()
81 #define ADDR_UNHANDLED_CASE() ADDR_ASSERT(!"Unhandled case")
82 #define ADDR_NOT_IMPLEMENTED() ADDR_ASSERT(!"Not implemented");
84 #define ADDR_ASSERT(__e) ADDR_ANALYSIS_ASSUME(__e)
85 #define ADDR_ASSERT_ALWAYS()
86 #define ADDR_UNHANDLED_CASE()
87 #define ADDR_NOT_IMPLEMENTED()
89 ////////////////////////////////////////////////////////////////////////////////////////////////////
91 ////////////////////////////////////////////////////////////////////////////////////////////////////
92 // Debug print macro from legacy address library
93 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 #define ADDR_PRNT(a) Object::DebugPrint a
98 /// @brief Macro for reporting informational messages
101 /// This macro optionally prints an informational message to stdout.
102 /// The first parameter is a condition -- if it is true, nothing is done.
103 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
104 /// starting with a string. This is passed to printf() or an equivalent
105 /// in order to format the informational message. For example,
106 /// ADDR_INFO(0, ("test %d",3) ); prints out "test 3".
108 #define ADDR_INFO(cond, a) \
109 { if (!(cond)) { ADDR_PRNT(a); } }
112 /// @brief Macro for reporting error warning messages
115 /// This macro optionally prints an error warning message to stdout,
116 /// followed by the file name and line number where the macro was called.
117 /// The first parameter is a condition -- if it is true, nothing is done.
118 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
119 /// starting with a string. This is passed to printf() or an equivalent
120 /// in order to format the informational message. For example,
121 /// ADDR_WARN(0, ("test %d",3) ); prints out "test 3" followed by
122 /// a second line with the file name and line number.
124 #define ADDR_WARN(cond, a) \
127 ADDR_PRNT((" WARNING in file %s, line %d\n", __FILE__, __LINE__)); \
131 /// @brief Macro for reporting fatal error conditions
134 /// This macro optionally stops execution of the current routine
135 /// after printing an error warning message to stdout,
136 /// followed by the file name and line number where the macro was called.
137 /// The first parameter is a condition -- if it is true, nothing is done.
138 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
139 /// starting with a string. This is passed to printf() or an equivalent
140 /// in order to format the informational message. For example,
141 /// ADDR_EXIT(0, ("test %d",3) ); prints out "test 3" followed by
142 /// a second line with the file name and line number, then stops execution.
144 #define ADDR_EXIT(cond, a) \
146 { ADDR_PRNT(a); ADDR_DBG_BREAK();\
151 #define ADDRDPF 1 ? (void)0 : (void)
155 #define ADDR_DBG_BREAK()
157 #define ADDR_INFO(cond, a)
159 #define ADDR_WARN(cond, a)
161 #define ADDR_EXIT(cond, a)
164 ////////////////////////////////////////////////////////////////////////////////////////////////////
171 ////////////////////////////////////////////////////////////////////////////////////////////////////
173 ////////////////////////////////////////////////////////////////////////////////////////////////////
174 static const UINT_32 MicroTileWidth
= 8; ///< Micro tile width, for 1D and 2D tiling
175 static const UINT_32 MicroTileHeight
= 8; ///< Micro tile height, for 1D and 2D tiling
176 static const UINT_32 ThickTileThickness
= 4; ///< Micro tile thickness, for THICK modes
177 static const UINT_32 XThickTileThickness
= 8; ///< Extra thick tiling thickness
178 static const UINT_32 PowerSaveTileBytes
= 64; ///< Nuber of bytes per tile for power save 64
179 static const UINT_32 CmaskCacheBits
= 1024; ///< Number of bits for CMASK cache
180 static const UINT_32 CmaskElemBits
= 4; ///< Number of bits for CMASK element
181 static const UINT_32 HtileCacheBits
= 16384; ///< Number of bits for HTILE cache 512*32
183 static const UINT_32 MicroTilePixels
= MicroTileWidth
* MicroTileHeight
;
185 static const INT_32 TileIndexInvalid
= TILEINDEX_INVALID
;
186 static const INT_32 TileIndexLinearGeneral
= TILEINDEX_LINEAR_GENERAL
;
187 static const INT_32 TileIndexNoMacroIndex
= -3;
191 ////////////////////////////////////////////////////////////////////////////////////////////////////
193 ////////////////////////////////////////////////////////////////////////////////////////////////////
194 #define BITS_PER_BYTE 8
195 #define BITS_TO_BYTES(x) ( ((x) + (BITS_PER_BYTE-1)) / BITS_PER_BYTE )
196 #define BYTES_TO_BITS(x) ( (x) * BITS_PER_BYTE )
198 /// Helper macros to select a single bit from an int (undefined later in section)
199 #define _BIT(v,b) (((v) >> (b) ) & 1)
202 ****************************************************************************************************
203 * @brief Enums to identify AddrLib type
204 ****************************************************************************************************
216 ****************************************************************************************************
220 * Neutral enums that specifies chip family.
222 ****************************************************************************************************
226 ADDR_CHIP_FAMILY_IVLD
, ///< Invalid family
227 ADDR_CHIP_FAMILY_R6XX
,
228 ADDR_CHIP_FAMILY_R7XX
,
229 ADDR_CHIP_FAMILY_R8XX
,
237 ****************************************************************************************************
241 * This structure is used to set configuration flags.
242 ****************************************************************************************************
248 /// These flags are set up internally thru AddrLib::Create() based on ADDR_CREATE_FLAGS
249 UINT_32 optimalBankSwap
: 1; ///< New bank tiling for RV770 only
250 UINT_32 noCubeMipSlicesPad
: 1; ///< Disables faces padding for cubemap mipmaps
251 UINT_32 fillSizeFields
: 1; ///< If clients fill size fields in all input and
253 UINT_32 ignoreTileInfo
: 1; ///< Don't use tile info structure
254 UINT_32 useTileIndex
: 1; ///< Make tileIndex field in input valid
255 UINT_32 useCombinedSwizzle
: 1; ///< Use combined swizzle
256 UINT_32 checkLast2DLevel
: 1; ///< Check the last 2D mip sub level
257 UINT_32 useHtileSliceAlign
: 1; ///< Do htile single slice alignment
258 UINT_32 allowLargeThickTile
: 1; ///< Allow 64*thickness*bytesPerPixel > rowSize
259 UINT_32 disableLinearOpt
: 1; ///< Disallow tile modes to be optimized to linear
260 UINT_32 reserved
: 22; ///< Reserved bits for future use
266 ////////////////////////////////////////////////////////////////////////////////////////////////////
267 // Misc helper functions
268 ////////////////////////////////////////////////////////////////////////////////////////////////////
271 ****************************************************************************************************
275 * Xor the right-side numberOfBits bits of x.
276 ****************************************************************************************************
278 static inline UINT_32
XorReduce(
280 UINT_32 numberOfBits
)
283 UINT_32 result
= x
& 1;
285 for (i
=1; i
<numberOfBits
; i
++)
287 result
^= ((x
>>i
) & 1);
294 ****************************************************************************************************
298 * Check if the size (UINT_32) is pow 2
299 ****************************************************************************************************
301 static inline UINT_32
IsPow2(
302 UINT_32 dim
) ///< [in] dimension of miplevel
304 ADDR_ASSERT(dim
> 0);
305 return !(dim
& (dim
- 1));
309 ****************************************************************************************************
313 * Check if the size (UINT_64) is pow 2
314 ****************************************************************************************************
316 static inline UINT_64
IsPow2(
317 UINT_64 dim
) ///< [in] dimension of miplevel
319 ADDR_ASSERT(dim
> 0);
320 return !(dim
& (dim
- 1));
324 ****************************************************************************************************
328 * Align UINT_32 "x" to "align" alignment, "align" should be power of 2
329 ****************************************************************************************************
331 static inline UINT_32
PowTwoAlign(
336 // Assert that x is a power of two.
338 ADDR_ASSERT(IsPow2(align
));
339 return (x
+ (align
- 1)) & (~(align
- 1));
343 ****************************************************************************************************
347 * Align UINT_64 "x" to "align" alignment, "align" should be power of 2
348 ****************************************************************************************************
350 static inline UINT_64
PowTwoAlign(
355 // Assert that x is a power of two.
357 ADDR_ASSERT(IsPow2(align
));
358 return (x
+ (align
- 1)) & (~(align
- 1));
362 ****************************************************************************************************
366 * Get the min value between two unsigned values
367 ****************************************************************************************************
369 static inline UINT_32
Min(
373 return ((value1
< (value2
)) ? (value1
) : value2
);
377 ****************************************************************************************************
381 * Get the min value between two signed values
382 ****************************************************************************************************
384 static inline INT_32
Min(
388 return ((value1
< (value2
)) ? (value1
) : value2
);
392 ****************************************************************************************************
396 * Get the max value between two unsigned values
397 ****************************************************************************************************
399 static inline UINT_32
Max(
403 return ((value1
> (value2
)) ? (value1
) : value2
);
407 ****************************************************************************************************
411 * Get the max value between two signed values
412 ****************************************************************************************************
414 static inline INT_32
Max(
418 return ((value1
> (value2
)) ? (value1
) : value2
);
422 ****************************************************************************************************
426 * Compute the mipmap's next level dim size
427 ****************************************************************************************************
429 static inline UINT_32
NextPow2(
430 UINT_32 dim
) ///< [in] dimension of miplevel
436 if (dim
> 0x7fffffff)
438 ADDR_ASSERT_ALWAYS();
453 ****************************************************************************************************
457 * Compute log of base 2 no matter the target is power of 2 or not
458 ****************************************************************************************************
460 static inline UINT_32
Log2NonPow2(
461 UINT_32 x
) ///< [in] the value should calculate log based 2
476 ****************************************************************************************************
480 * Compute log of base 2
481 ****************************************************************************************************
483 static inline UINT_32
Log2(
484 UINT_32 x
) ///< [in] the value should calculate log based 2
486 // Assert that x is a power of two.
487 ADDR_ASSERT(IsPow2(x
));
489 return Log2NonPow2(x
);
493 ****************************************************************************************************
497 * Compute log of base 2 quickly (<= 16)
498 ****************************************************************************************************
500 static inline UINT_32
QLog2(
501 UINT_32 x
) ///< [in] the value should calculate log based 2
503 ADDR_ASSERT(x
<= 16);
525 ADDR_ASSERT_ALWAYS();
532 ****************************************************************************************************
536 * NULL pointer safe assignment
537 ****************************************************************************************************
539 static inline VOID
SafeAssign(
540 UINT_32
* pLVal
, ///< [in] Pointer to left val
541 UINT_32 rVal
) ///< [in] Right value
550 ****************************************************************************************************
554 * NULL pointer safe assignment for 64bit values
555 ****************************************************************************************************
557 static inline VOID
SafeAssign(
558 UINT_64
* pLVal
, ///< [in] Pointer to left val
559 UINT_64 rVal
) ///< [in] Right value
568 ****************************************************************************************************
572 * NULL pointer safe assignment for AddrTileMode
573 ****************************************************************************************************
575 static inline VOID
SafeAssign(
576 AddrTileMode
* pLVal
, ///< [in] Pointer to left val
577 AddrTileMode rVal
) ///< [in] Right value
586 ****************************************************************************************************
590 * Get channel initialization value
591 ****************************************************************************************************
593 static inline ADDR_CHANNEL_SETTING
InitChannel(
594 UINT_32 valid
, ///< [in] valid setting
595 UINT_32 channel
, ///< [in] channel setting
596 UINT_32 index
) ///< [in] index setting
598 ADDR_CHANNEL_SETTING t
;
608 #endif // __ADDR_COMMON_H__