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