1 /* 2 ************************************************************************************************************************ 3 * 4 * Copyright (C) 2007-2022 Advanced Micro Devices, Inc. All rights reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE 23 * 24 ***********************************************************************************************************************/ 25 26 /** 27 **************************************************************************************************** 28 * @file siaddrlib.h 29 * @brief Contains the R800Lib class definition. 30 **************************************************************************************************** 31 */ 32 33 #ifndef __SI_ADDR_LIB_H__ 34 #define __SI_ADDR_LIB_H__ 35 36 #include "addrlib1.h" 37 #include "egbaddrlib.h" 38 39 namespace Addr 40 { 41 namespace V1 42 { 43 44 /** 45 **************************************************************************************************** 46 * @brief Describes the information in tile mode table 47 **************************************************************************************************** 48 */ 49 struct TileConfig 50 { 51 AddrTileMode mode; 52 AddrTileType type; 53 ADDR_TILEINFO info; 54 }; 55 56 /** 57 **************************************************************************************************** 58 * @brief SI specific settings structure. 59 **************************************************************************************************** 60 */ 61 struct SiChipSettings 62 { 63 UINT_32 isSouthernIsland : 1; 64 UINT_32 isTahiti : 1; 65 UINT_32 isPitCairn : 1; 66 UINT_32 isCapeVerde : 1; 67 // Oland/Hainan are of GFXIP 6.0, similar with SI 68 UINT_32 isOland : 1; 69 UINT_32 isHainan : 1; 70 71 // CI 72 UINT_32 isSeaIsland : 1; 73 UINT_32 isBonaire : 1; 74 UINT_32 isKaveri : 1; 75 UINT_32 isSpectre : 1; 76 UINT_32 isSpooky : 1; 77 UINT_32 isKalindi : 1; 78 UINT_32 isHawaii : 1; 79 80 // VI 81 UINT_32 isVolcanicIslands : 1; 82 UINT_32 isIceland : 1; 83 UINT_32 isTonga : 1; 84 UINT_32 isFiji : 1; 85 UINT_32 isPolaris10 : 1; 86 UINT_32 isPolaris11 : 1; 87 UINT_32 isPolaris12 : 1; 88 UINT_32 isVegaM : 1; 89 UINT_32 isCarrizo : 1; 90 }; 91 92 /** 93 **************************************************************************************************** 94 * @brief This class is the SI specific address library 95 * function set. 96 **************************************************************************************************** 97 */ 98 class SiLib : public EgBasedLib 99 { 100 public: 101 /// Creates SiLib object CreateObj(const Client * pClient)102 static Addr::Lib* CreateObj(const Client* pClient) 103 { 104 VOID* pMem = Object::ClientAlloc(sizeof(SiLib), pClient); 105 return (pMem != NULL) ? new (pMem) SiLib(pClient) : NULL; 106 } 107 108 protected: 109 SiLib(const Client* pClient); 110 virtual ~SiLib(); 111 112 // Hwl interface - defined in AddrLib1 113 virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfo( 114 const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, 115 ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const; 116 117 virtual ADDR_E_RETURNCODE HwlConvertTileInfoToHW( 118 const ADDR_CONVERT_TILEINFOTOHW_INPUT* pIn, 119 ADDR_CONVERT_TILEINFOTOHW_OUTPUT* pOut) const; 120 121 virtual UINT_64 HwlComputeXmaskAddrFromCoord( 122 UINT_32 pitch, UINT_32 height, UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 numSlices, 123 UINT_32 factor, BOOL_32 isLinear, BOOL_32 isWidth8, BOOL_32 isHeight8, 124 ADDR_TILEINFO* pTileInfo, UINT_32* pBitPosition) const; 125 126 virtual VOID HwlComputeXmaskCoordFromAddr( 127 UINT_64 addr, UINT_32 bitPosition, UINT_32 pitch, UINT_32 height, UINT_32 numSlices, 128 UINT_32 factor, BOOL_32 isLinear, BOOL_32 isWidth8, BOOL_32 isHeight8, 129 ADDR_TILEINFO* pTileInfo, UINT_32* pX, UINT_32* pY, UINT_32* pSlice) const; 130 131 virtual ADDR_E_RETURNCODE HwlGetTileIndex( 132 const ADDR_GET_TILEINDEX_INPUT* pIn, 133 ADDR_GET_TILEINDEX_OUTPUT* pOut) const; 134 135 virtual BOOL_32 HwlComputeMipLevel( 136 ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn) const; 137 138 virtual ChipFamily HwlConvertChipFamily( 139 UINT_32 uChipFamily, UINT_32 uChipRevision); 140 141 virtual BOOL_32 HwlInitGlobalParams( 142 const ADDR_CREATE_INPUT* pCreateIn); 143 144 virtual ADDR_E_RETURNCODE HwlSetupTileCfg( 145 UINT_32 bpp, INT_32 index, INT_32 macroModeIndex, 146 ADDR_TILEINFO* pInfo, AddrTileMode* pMode = 0, AddrTileType* pType = 0) const; 147 148 virtual VOID HwlComputeTileDataWidthAndHeightLinear( 149 UINT_32* pMacroWidth, UINT_32* pMacroHeight, 150 UINT_32 bpp, ADDR_TILEINFO* pTileInfo) const; 151 152 virtual UINT_64 HwlComputeHtileBytes( 153 UINT_32 pitch, UINT_32 height, UINT_32 bpp, 154 BOOL_32 isLinear, UINT_32 numSlices, UINT_64* pSliceBytes, UINT_32 baseAlign) const; 155 156 virtual ADDR_E_RETURNCODE ComputeBankEquation( 157 UINT_32 log2BytesPP, UINT_32 threshX, UINT_32 threshY, 158 ADDR_TILEINFO* pTileInfo, ADDR_EQUATION* pEquation) const; 159 160 virtual ADDR_E_RETURNCODE ComputePipeEquation( 161 UINT_32 log2BytesPP, UINT_32 threshX, UINT_32 threshY, 162 ADDR_TILEINFO* pTileInfo, ADDR_EQUATION* pEquation) const; 163 164 virtual UINT_32 ComputePipeFromCoord( 165 UINT_32 x, UINT_32 y, UINT_32 slice, 166 AddrTileMode tileMode, UINT_32 pipeSwizzle, BOOL_32 ignoreSE, 167 ADDR_TILEINFO* pTileInfo) const; 168 169 virtual UINT_32 HwlGetPipes(const ADDR_TILEINFO* pTileInfo) const; 170 171 /// Pre-handler of 3x pitch (96 bit) adjustment 172 virtual UINT_32 HwlPreHandleBaseLvl3xPitch( 173 const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, UINT_32 expPitch) const; 174 /// Post-handler of 3x pitch adjustment 175 virtual UINT_32 HwlPostHandleBaseLvl3xPitch( 176 const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, UINT_32 expPitch) const; 177 178 /// Dummy function to finalize the inheritance 179 virtual UINT_32 HwlComputeXmaskCoordYFrom8Pipe( 180 UINT_32 pipe, UINT_32 x) const; 181 182 // Sub-hwl interface - defined in EgBasedLib 183 virtual VOID HwlSetupTileInfo( 184 AddrTileMode tileMode, ADDR_SURFACE_FLAGS flags, 185 UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples, 186 ADDR_TILEINFO* inputTileInfo, ADDR_TILEINFO* outputTileInfo, 187 AddrTileType inTileType, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const; 188 189 virtual UINT_32 HwlGetPitchAlignmentMicroTiled( 190 AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples) const; 191 192 virtual UINT_64 HwlGetSizeAdjustmentMicroTiled( 193 UINT_32 thickness, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples, 194 UINT_32 baseAlign, UINT_32 pitchAlign, 195 UINT_32 *pPitch, UINT_32 *pHeight) const; 196 197 virtual VOID HwlCheckLastMacroTiledLvl( 198 const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const; 199 200 virtual BOOL_32 HwlTileInfoEqual( 201 const ADDR_TILEINFO* pLeft, const ADDR_TILEINFO* pRight) const; 202 203 virtual AddrTileMode HwlDegradeThickTileMode( 204 AddrTileMode baseTileMode, UINT_32 numSlices, UINT_32* pBytesPerTile) const; 205 206 virtual VOID HwlOverrideTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const; 207 208 virtual VOID HwlOptimizeTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const; 209 210 virtual VOID HwlSelectTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const; 211 212 /// Overwrite tile setting to PRT 213 virtual VOID HwlSetPrtTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const; 214 HwlSanityCheckMacroTiled(ADDR_TILEINFO * pTileInfo)215 virtual BOOL_32 HwlSanityCheckMacroTiled( 216 ADDR_TILEINFO* pTileInfo) const 217 { 218 return TRUE; 219 } 220 221 virtual UINT_32 HwlGetPitchAlignmentLinear(UINT_32 bpp, ADDR_SURFACE_FLAGS flags) const; 222 223 virtual UINT_64 HwlGetSizeAdjustmentLinear( 224 AddrTileMode tileMode, 225 UINT_32 bpp, UINT_32 numSamples, UINT_32 baseAlign, UINT_32 pitchAlign, 226 UINT_32 *pPitch, UINT_32 *pHeight, UINT_32 *pHeightAlign) const; 227 228 virtual VOID HwlComputeSurfaceCoord2DFromBankPipe( 229 AddrTileMode tileMode, UINT_32* pX, UINT_32* pY, UINT_32 slice, 230 UINT_32 bank, UINT_32 pipe, 231 UINT_32 bankSwizzle, UINT_32 pipeSwizzle, UINT_32 tileSlices, 232 BOOL_32 ignoreSE, 233 ADDR_TILEINFO* pTileInfo) const; 234 235 virtual UINT_32 HwlPreAdjustBank( 236 UINT_32 tileX, UINT_32 bank, ADDR_TILEINFO* pTileInfo) const; 237 238 virtual INT_32 HwlPostCheckTileIndex( 239 const ADDR_TILEINFO* pInfo, AddrTileMode mode, AddrTileType type, 240 INT curIndex = TileIndexInvalid) const; 241 242 virtual VOID HwlFmaskPreThunkSurfInfo( 243 const ADDR_COMPUTE_FMASK_INFO_INPUT* pFmaskIn, 244 const ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut, 245 ADDR_COMPUTE_SURFACE_INFO_INPUT* pSurfIn, 246 ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut) const; 247 248 virtual VOID HwlFmaskPostThunkSurfInfo( 249 const ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut, 250 ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut) const; 251 252 virtual UINT_32 HwlComputeFmaskBits( 253 const ADDR_COMPUTE_FMASK_INFO_INPUT* pIn, 254 UINT_32* pNumSamples) const; 255 HwlReduceBankWidthHeight(UINT_32 tileSize,UINT_32 bpp,ADDR_SURFACE_FLAGS flags,UINT_32 numSamples,UINT_32 bankHeightAlign,UINT_32 pipes,ADDR_TILEINFO * pTileInfo)256 virtual BOOL_32 HwlReduceBankWidthHeight( 257 UINT_32 tileSize, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples, 258 UINT_32 bankHeightAlign, UINT_32 pipes, 259 ADDR_TILEINFO* pTileInfo) const 260 { 261 return TRUE; 262 } 263 264 virtual UINT_32 HwlComputeMaxBaseAlignments() const; 265 266 virtual UINT_32 HwlComputeMaxMetaBaseAlignments() const; 267 268 virtual VOID HwlComputeSurfaceAlignmentsMacroTiled( 269 AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, 270 UINT_32 mipLevel, UINT_32 numSamples, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const; 271 272 // Get equation table pointer and number of equations HwlGetEquationTableInfo(const ADDR_EQUATION ** ppEquationTable)273 virtual UINT_32 HwlGetEquationTableInfo(const ADDR_EQUATION** ppEquationTable) const 274 { 275 *ppEquationTable = m_equationTable; 276 277 return m_numEquations; 278 } 279 280 // Check if it is supported for given bpp and tile config to generate an equation 281 BOOL_32 IsEquationSupported( 282 UINT_32 bpp, TileConfig tileConfig, INT_32 tileIndex, UINT_32 elementBytesLog2) const; 283 284 // Protected non-virtual functions 285 VOID ComputeTileCoordFromPipeAndElemIdx( 286 UINT_32 elemIdx, UINT_32 pipe, AddrPipeCfg pipeCfg, UINT_32 pitchInMacroTile, 287 UINT_32 x, UINT_32 y, UINT_32* pX, UINT_32* pY) const; 288 289 UINT_32 TileCoordToMaskElementIndex( 290 UINT_32 tx, UINT_32 ty, AddrPipeCfg pipeConfig, 291 UINT_32 *macroShift, UINT_32 *elemIdxBits) const; 292 293 BOOL_32 DecodeGbRegs( 294 const ADDR_REGISTER_VALUE* pRegValue); 295 296 const TileConfig* GetTileSetting( 297 UINT_32 index) const; 298 299 // Initialize equation table 300 VOID InitEquationTable(); 301 302 UINT_32 GetPipePerSurf(AddrPipeCfg pipeConfig) const; 303 304 static const UINT_32 TileTableSize = 32; 305 TileConfig m_tileTable[TileTableSize]; 306 UINT_32 m_noOfEntries; 307 308 // Max number of bpp (8bpp/16bpp/32bpp/64bpp/128bpp) 309 static const UINT_32 MaxNumElementBytes = 5; 310 311 static const BOOL_32 m_EquationSupport[TileTableSize][MaxNumElementBytes]; 312 313 // Prt tile mode index mask 314 static const UINT_32 SiPrtTileIndexMask = ((1 << 3) | (1 << 5) | (1 << 6) | (1 << 7) | 315 (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24) | 316 (1 << 25) | (1 << 30)); 317 318 // More than half slots in tile mode table can't support equation 319 static const UINT_32 EquationTableSize = (MaxNumElementBytes * TileTableSize) / 2; 320 // Equation table 321 ADDR_EQUATION m_equationTable[EquationTableSize]; 322 UINT_32 m_numMacroBits[EquationTableSize]; 323 UINT_32 m_blockWidth[EquationTableSize]; 324 UINT_32 m_blockHeight[EquationTableSize]; 325 UINT_32 m_blockSlices[EquationTableSize]; 326 // Number of equation entries in the table 327 UINT_32 m_numEquations; 328 // Equation lookup table according to bpp and tile index 329 UINT_32 m_equationLookupTable[MaxNumElementBytes][TileTableSize]; 330 331 UINT_32 m_uncompressDepthEqIndex; 332 333 SiChipSettings m_settings; 334 335 private: 336 337 VOID ReadGbTileMode(UINT_32 regValue, TileConfig* pCfg) const; 338 BOOL_32 InitTileSettingTable(const UINT_32 *pSetting, UINT_32 noOfEntries); 339 }; 340 341 } // V1 342 } // Addr 343 344 #endif 345 346