1 /* 2 * Copyright (c) 2020-2022, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file mhw_blt.h 24 //! \brief MHW interface for constructing commands for the BLT 25 //! 26 #ifndef __MHW_BLT_H__ 27 #define __MHW_BLT_H__ 28 29 #include "mos_os.h" 30 #include "mhw_utilities.h" 31 32 //! 33 //! \brief Fast copy blt parameters 34 //! 35 typedef struct _MHW_FAST_COPY_BLT_PARAM 36 { 37 uint32_t dwColorDepth; 38 uint32_t dwSrcPitch; 39 uint32_t dwDstPitch; 40 uint32_t dwSrcTop; 41 uint32_t dwSrcLeft; 42 uint32_t dwDstTop; 43 uint32_t dwDstBottom; 44 uint32_t dwDstLeft; 45 uint32_t dwDstRight; 46 uint32_t dwPlaneIndex; 47 uint32_t dwPlaneNum; 48 PMOS_RESOURCE pSrcOsResource; 49 PMOS_RESOURCE pDstOsResource; 50 }MHW_FAST_COPY_BLT_PARAM, *PMHW_FAST_COPY_BLT_PARAM; 51 52 //! 53 //! \brief Control surface copy blt parameters 54 //! 55 typedef struct _MHW_CTRL_SURF_COPY_BLT_PARAM 56 { 57 uint32_t dwSrcMemoryType; 58 uint32_t dwDstMemoryType; 59 uint32_t dwSizeofControlSurface; 60 PMOS_RESOURCE pSrcOsResource; 61 PMOS_RESOURCE pDstOsResource; 62 }MHW_CTRL_SURF_COPY_BLT_PARAM, *PMHW_CTRL_SURF_COPY_BLT_PARAM; 63 64 typedef enum BLT_TILE_TYPE_ENUM 65 { 66 BLT_TILED_X, 67 BLT_TILED_Y, 68 BLT_TILED_W, 69 BLT_NOT_TILED, 70 BLT_TILED_4, 71 BLT_TILED_64 72 }BLT_TILE_TYPE; 73 74 typedef enum _MHW_BLT_ENGINE_ADDRESS_SHIFT 75 { 76 MHW_BLT_ENGINE_STATE_BASE_ADDRESS_SHIFT = 0 77 } MHW_BLT_ENGINE_ADDRESS_SHIFT; 78 79 class mhw_blt_state 80 { 81 public: 82 // Internal Macros 83 #define __CODEGEN_MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b)) 84 #define __CODEGEN_BITFIELD(l, h) (h) - (l) + 1 85 #define __CODEGEN_OP_LENGTH_BIAS 2 86 #define __CODEGEN_OP_LENGTH(x) (uint32_t)((__CODEGEN_MAX(x, __CODEGEN_OP_LENGTH_BIAS)) - __CODEGEN_OP_LENGTH_BIAS) 87 GetOpLength(uint32_t uiLength)88 static uint32_t GetOpLength(uint32_t uiLength) { return __CODEGEN_OP_LENGTH(uiLength); } 89 90 //! 91 //! \brief XY_BLOCK_COPY_BLT 92 //! \details 93 //! XY_BLOCK_COPY_BLT instruction performs a color source copy where the 94 //! only operands involved are a color source and destination of the same 95 //! bit width. The source and destination surfaces CAN overlap, the hardware 96 //! handles this internally. This new blit command will happen in large 97 //! numbers, consecutively, possibly an entire batch will comprise only new 98 //! blit commands. Legacy commands and new blit command will not be 99 //! interspersed. If they are, they will be separated by implied HW flush: 100 //! Whenever there is a transition between this new Fast Blit command and 101 //! the Legacy Blit commands (2D BLT instructions other than 102 //! XY_BLOCK_COPY_BLT, XY_FAST_COPY_BLT, XY_FAST_COLOR_BLT), the HW will 103 //! impose an automatic flush BEFORE the execution (at the beginning) of the 104 //! next blitter command. The starting pixel of the blit operation for both 105 //! source and destination should be on a pixel boundary. 106 //! Note that when two sequential block copy blits have different source 107 //! surfaces, but their destinations refer to the same destination surfaces 108 //! and therefore destinations overlap it is imperative that a Flush be 109 //! inserted between the two blits. 110 //! 111 struct XY_BLOCK_COPY_BLT_CMD 112 { 113 union 114 { 115 struct 116 { 117 uint32_t DwordLength : __CODEGEN_BITFIELD( 0, 7) ; //!< DWORD_LENGTH 118 uint32_t Reserved8 : __CODEGEN_BITFIELD( 8, 18) ; //!< Reserved 119 uint32_t ColorDepth : __CODEGEN_BITFIELD(19, 21) ; //!< COLOR_DEPTH 120 uint32_t InstructionTargetOpcode : __CODEGEN_BITFIELD(22, 28) ; //!< INSTRUCTION_TARGETOPCODE 121 uint32_t Client : __CODEGEN_BITFIELD(29, 31) ; //!< CLIENT 122 }; 123 uint32_t Value; 124 } DW0; 125 union 126 { 127 struct 128 { 129 uint32_t DestinationPitch : __CODEGEN_BITFIELD( 0, 17) ; //!< Destination Pitch 130 uint32_t Reserved50 : __CODEGEN_BITFIELD(18, 20) ; //!< Reserved 131 uint32_t DestinationMocsValue : __CODEGEN_BITFIELD(21, 27) ; //!< Destination MOCS value 132 uint32_t Reserved60 : __CODEGEN_BITFIELD(28, 29) ; //!< Reserved 133 uint32_t DestinationTiling : __CODEGEN_BITFIELD(30, 31) ; //!< DESTINATION_TILING 134 }; 135 uint32_t Value; 136 } DW1; 137 union 138 { 139 struct 140 { 141 uint32_t DestinationX1CoordinateLeft : __CODEGEN_BITFIELD( 0, 15) ; //!< Destination X1 Coordinate (Left) 142 uint32_t DestinationY1CoordinateTop : __CODEGEN_BITFIELD(16, 31) ; //!< Destination Y1 Coordinate (Top) 143 }; 144 uint32_t Value; 145 } DW2; 146 union 147 { 148 struct 149 { 150 uint32_t DestinationX2CoordinateRight : __CODEGEN_BITFIELD( 0, 15) ; //!< Destination X2 Coordinate (Right) 151 uint32_t DestinationY2CoordinateBottom : __CODEGEN_BITFIELD(16, 31) ; //!< Destination Y2 Coordinate (Bottom) 152 }; 153 uint32_t Value; 154 } DW3; 155 union 156 { 157 struct 158 { 159 uint64_t DestinationBaseAddress ; //!< Destination Base Address 160 }; 161 uint32_t Value[2]; 162 } DW4_5; 163 union 164 { 165 struct 166 { 167 uint32_t DestinationXOffset : __CODEGEN_BITFIELD( 0, 13) ; //!< Destination X offset 168 uint32_t Reserved206 : __CODEGEN_BITFIELD(14, 15) ; //!< Reserved 169 uint32_t DestinationYOffset : __CODEGEN_BITFIELD(16, 29) ; //!< Destination Y offset 170 uint32_t Reserved222 : __CODEGEN_BITFIELD(30, 31) ; //!< Reserved 171 }; 172 uint32_t Value; 173 } DW6; 174 union 175 { 176 struct 177 { 178 uint32_t SourceX1CoordinateLeft : __CODEGEN_BITFIELD( 0, 15) ; //!< Source X1 Coordinate (Left) 179 uint32_t SourceY1CoordinateTop : __CODEGEN_BITFIELD(16, 31) ; //!< Source Y1 Coordinate (Top) 180 }; 181 uint32_t Value; 182 } DW7; 183 union 184 { 185 struct 186 { 187 uint32_t SourcePitch : __CODEGEN_BITFIELD( 0, 17) ; //!< Source Pitch 188 uint32_t Reserved274 : __CODEGEN_BITFIELD(18, 20) ; //!< Reserved 189 uint32_t SourceMocs : __CODEGEN_BITFIELD(21, 27) ; //!< Source MOCS 190 uint32_t Reserved284 : __CODEGEN_BITFIELD(28, 29) ; //!< Reserved 191 uint32_t SourceTiling : __CODEGEN_BITFIELD(30, 31) ; //!< SOURCE_TILING 192 }; 193 uint32_t Value; 194 } DW8; 195 union 196 { 197 struct 198 { 199 uint64_t SourceBaseAddress ; //!< Source Base Address 200 }; 201 uint32_t Value[2]; 202 } DW9_10; 203 union 204 { 205 struct 206 { 207 uint32_t SourceXOffset : __CODEGEN_BITFIELD( 0, 13) ; //!< Source X offset 208 uint32_t Reserved366 : __CODEGEN_BITFIELD(14, 15) ; //!< Reserved 209 uint32_t SourceYOffset : __CODEGEN_BITFIELD(16, 29) ; //!< Source Y offset 210 uint32_t Reserved382 : __CODEGEN_BITFIELD(30, 31) ; //!< Reserved 211 }; 212 uint32_t Value; 213 } DW11; 214 215 //! \name Local enumerations 216 217 //! \brief COLOR_DEPTH 218 //! \details 219 //! This field actually programs bits per pixel value for each pixel of 220 //! the surface. Reprogramming of these bits require explicit flushing of 221 //! Copy Engine. 222 enum COLOR_DEPTH 223 { 224 COLOR_DEPTH_8BITCOLOR = 0, //!< No additional details 225 COLOR_DEPTH_16BITCOLOR = 1, //!< No additional details 226 COLOR_DEPTH_32BITCOLOR = 2, //!< No additional details 227 COLOR_DEPTH_64BITCOLOR = 3, //!< No additional details 228 COLOR_DEPTH_96BITCOLOR_ONLYLINEARCASEISSUPPORTED = 4, //!< No additional details 229 COLOR_DEPTH_128BITCOLOR = 5, //!< No additional details 230 }; 231 232 enum INSTRUCTION_TARGETOPCODE 233 { 234 INSTRUCTION_TARGETOPCODE_INSTRUCTIONTARGETXYBLOCKCOPYBLT = 65, //!< No additional details 235 }; 236 237 enum CLIENT 238 { 239 CLIENT_2DPROCESSOR = 2, //!< No additional details 240 }; 241 242 //! \brief DESTINATION_TILING 243 //! \details 244 //! These bits indicate destination tiling method. 245 enum DESTINATION_TILING 246 { 247 DESTINATION_TILING_LINEAR = 0, //!< Linear mode (no tiling) 248 DESTINATION_TILING_YMAJOR = 1, //!< Y major tiling 249 }; 250 251 //! \brief SOURCE_TILING 252 //! \details 253 //! These bits indicate source tiling method. 254 enum SOURCE_TILING 255 { 256 SOURCE_TILING_LINEAR = 0, //!< Linear Tiling (tiking disabled) 257 SOURCE_TILING_YMAJOR = 1, //!< Y major tiling 258 }; 259 260 //! \name Initializations 261 262 //! \brief Explicit member initialization function 263 XY_BLOCK_COPY_BLT_CMD(); 264 265 static const size_t dwSize = 12; 266 static const size_t byteSize = 48; 267 }; 268 269 //! 270 //! \brief XY_FAST_COPY_BLT 271 //! \details 272 //! This BLT instruction performs a color source copy where the only 273 //! operands involved are a color source and destination of the same bit 274 //! width. The source and destination surfaces CANNOT overlap. The hardware 275 //! assumes this whenever this Fast_Copy command is given to it. For 276 //! overlapping Blits, use the traditional XY_SRC_COPY_BLT command (for 277 //! overlap determination, read the description given in the XY_SRC_COPY_BLT 278 //! command). Note that this command does not support Clipping operations. 279 //! This new blit command will happen in large numbers, consecutively, 280 //! possibly an entire batch will comprise only new blit commands Legacy 281 //! commands and new blit command will not be interspersed. If they are, 282 //! they will be separated by implied HW flush: Whenever there is a 283 //! transition between this new Fast Blit command and the Legacy Blit 284 //! commands (2D BLT instructions other than XY_BLOCK_COPY_BLT, 285 //! XY_FAST_COPY_BLT and XY_FAST_COLOR_BLT), the HW will impose an automatic 286 //! flush BEFORE the execution (at the beginning) of the next blitter 287 //! command. New blit command can use any combination of memory surface type 288 //! - linear, tiledX, tiledY, and the tiling information is conveyed as part 289 //! of the new Fast Copy command. The Fast Copy Blit supports the new 64KB 290 //! Tiling defined for SKL.The starting pixel of Fast Copy blit for both 291 //! source and destination should be on an OWord boundary. 292 //! Note that when two sequential fast copy blits have different source 293 //! surfaces, but their destinations refer to the same destination surfaces 294 //! and therefore destinations overlap it is imperative that a Flush be 295 //! inserted between the two blits. 296 //! 297 298 struct XY_FAST_COPY_BLT_CMD 299 { 300 union 301 { 302 struct 303 { 304 uint32_t DwordLength : __CODEGEN_BITFIELD( 0, 7) ; //!< DWORD_LENGTH 305 uint32_t Reserved8 : __CODEGEN_BITFIELD( 8, 12) ; //!< Reserved 306 uint32_t DestinationTilingMethod : __CODEGEN_BITFIELD(13, 14) ; //!< DESTINATION_TILING_METHOD 307 uint32_t Reserved15 : __CODEGEN_BITFIELD(15, 19) ; //!< Reserved 308 uint32_t SourceTilingMethod : __CODEGEN_BITFIELD(20, 21) ; //!< SOURCE_TILING_METHOD 309 uint32_t InstructionTargetOpcode : __CODEGEN_BITFIELD(22, 28) ; //!< INSTRUCTION_TARGETOPCODE 310 uint32_t Client : __CODEGEN_BITFIELD(29, 31) ; //!< CLIENT 311 }; 312 uint32_t Value; 313 } DW0; 314 union 315 { 316 struct 317 { 318 uint32_t DestinationPitch : __CODEGEN_BITFIELD( 0, 15) ; //!< Destination Pitch 319 uint32_t Reserved48 : __CODEGEN_BITFIELD(16, 23) ; //!< Reserved 320 uint32_t ColorDepth : __CODEGEN_BITFIELD(24, 26) ; //!< COLOR_DEPTH 321 uint32_t Reserved59 : __CODEGEN_BITFIELD(27, 29) ; //!< Reserved 322 uint32_t TileYTypeForDestination : __CODEGEN_BITFIELD(30, 30) ; //!< TILE_Y_TYPE_FOR_DESTINATION 323 uint32_t TileYTypeForSource : __CODEGEN_BITFIELD(31, 31) ; //!< TILE_Y_TYPE_FOR_SOURCE 324 }; 325 uint32_t Value; 326 } DW1; 327 union 328 { 329 struct 330 { 331 uint32_t DestinationX1CoordinateLeft : __CODEGEN_BITFIELD( 0, 15) ; //!< Destination X1 Coordinate (Left) 332 uint32_t DestinationY1CoordinateTop : __CODEGEN_BITFIELD(16, 31) ; //!< Destination Y1 Coordinate (Top) 333 }; 334 uint32_t Value; 335 } DW2; 336 union 337 { 338 struct 339 { 340 uint32_t DestinationX2CoordinateRight : __CODEGEN_BITFIELD( 0, 15) ; //!< Destination X2 Coordinate (Right) 341 uint32_t DestinationY2CoordinateBottom : __CODEGEN_BITFIELD(16, 31) ; //!< Destination Y2 Coordinate (Bottom) 342 }; 343 uint32_t Value; 344 } DW3; 345 union 346 { 347 struct 348 { 349 uint64_t DestinationBaseAddress ; //!< Destination Base Address 350 }; 351 uint32_t Value[2]; 352 } DW4_5; 353 union 354 { 355 struct 356 { 357 uint32_t SourceX1CoordinateLeft : __CODEGEN_BITFIELD( 0, 15) ; //!< Source X1 Coordinate (Left) 358 uint32_t SourceY1CoordinateTop : __CODEGEN_BITFIELD(16, 31) ; //!< Source Y1 Coordinate (Top) 359 }; 360 uint32_t Value; 361 } DW6; 362 union 363 { 364 struct 365 { 366 uint32_t SourcePitch : __CODEGEN_BITFIELD( 0, 15) ; //!< Source Pitch 367 uint32_t Reserved240 : __CODEGEN_BITFIELD(16, 31) ; //!< Reserved 368 }; 369 uint32_t Value; 370 } DW7; 371 union 372 { 373 struct 374 { 375 uint64_t SourceBaseAddress ; //!< Source Base Address 376 }; 377 uint32_t Value[2]; 378 } DW8_9; 379 380 //! \name Local enumerations 381 382 //! \brief DESTINATION_TILING_METHOD 383 //! \details 384 //! SW is required to flush the HW before changing the polarity of these 385 //! bits for subsequent blits. 386 enum DESTINATION_TILING_METHOD 387 { 388 DESTINATION_TILING_METHOD_LINEAR_TILINGDISABLED = 0, //!< No additional details 389 DESTINATION_TILING_METHOD_LEGACYTILE_X = 1, //!< No additional details 390 DESTINATION_TILING_METHOD_TILE_Y = 2, //!< Choosing between 'Legacy Tile-Y' or the 'New 4K Tile-YF' can be done in DWord 1, Bit[30]. 391 DESTINATION_TILING_METHOD_64KBTILING = 3, //!< No additional details 392 }; 393 394 //! \brief SOURCE_TILING_METHOD 395 //! \details 396 //! SW is required to flush the HW before changing the polarity of these 397 //! bits for subsequent blits. 398 enum SOURCE_TILING_METHOD 399 { 400 SOURCE_TILING_METHOD_LINEAR_TILINGDISABLED = 0, //!< No additional details 401 SOURCE_TILING_METHOD_LEGACYTILE_X = 1, //!< No additional details 402 SOURCE_TILING_METHOD_TILE_Y = 2, //!< Choosing between 'Legacy Tile-Y' or the 'New 4K Tile-YF' can be done in DWord 1, Bit[31]. 403 SOURCE_TILING_METHOD_64KBTILING = 3, //!< No additional details 404 }; 405 406 enum INSTRUCTION_TARGETOPCODE 407 { 408 INSTRUCTION_TARGETOPCODE_UNNAMED66 = 66, //!< No additional details 409 }; 410 411 enum CLIENT 412 { 413 CLIENT_2DPROCESSOR = 2, //!< No additional details 414 }; 415 416 enum COLOR_DEPTH 417 { 418 COLOR_DEPTH_8BITCOLOR = 0, //!< No additional details 419 COLOR_DEPTH_16BITCOLOR_565 = 1, //!< No additional details 420 COLOR_DEPTH_32BITCOLOR = 3, //!< No additional details 421 COLOR_DEPTH_64BITCOLOR_FOR64KBTILING = 4, //!< No additional details 422 COLOR_DEPTH_128BITCOLOR_FOR64KBTILING = 5, //!< No additional details 423 }; 424 425 //! \brief TILE_Y_TYPE_FOR_DESTINATION 426 //! \details 427 //! Destination being Tile-Y can be selected in DWord 0, Bit[14:13]. 428 enum TILE_Y_TYPE_FOR_DESTINATION 429 { 430 TILE_Y_TYPE_FOR_DESTINATION_NEW4KTILE_YF = 1, //!< No additional details 431 }; 432 433 //! \brief TILE_Y_TYPE_FOR_SOURCE 434 //! \details 435 //! Source being Tile-Y can be selected in DWord 0, Bit[21:20]. 436 enum TILE_Y_TYPE_FOR_SOURCE 437 { 438 TILE_Y_TYPE_FOR_SOURCE_NEW4KTILE_YF = 1, //!< No additional details 439 }; 440 441 //! \name Initializations 442 443 //! \brief Explicit member initialization function 444 XY_FAST_COPY_BLT_CMD(); 445 446 static const size_t dwSize = 10; 447 static const size_t byteSize = 40; 448 }; 449 450 ////////////////////////////////////////////////////////////////////////// 451 /// @brief BCS_SWCTRL 452 /// @details 453 /// 454 /// 455 struct BCS_SWCTRL_CMD 456 { 457 union 458 { 459 struct 460 { 461 /// DWORD 0 462 uint32_t TileYSource : __CODEGEN_BITFIELD(0, 0); ///< U1 463 uint32_t TileYDestination : __CODEGEN_BITFIELD(1, 1); ///< U1 464 uint32_t NotInvalidateBlitterCacheonBCSFlush : __CODEGEN_BITFIELD(2, 2); ///< U1 465 uint32_t ShrinkBlitterCache : __CODEGEN_BITFIELD(3, 3); ///< U1 466 uint32_t Reserved_4 : __CODEGEN_BITFIELD(4, 15); ///< U12 467 uint32_t TileYSourceMask : __CODEGEN_BITFIELD(16, 16); ///< U1 468 uint32_t TileYDestinationMask : __CODEGEN_BITFIELD(17, 17); ///< U1 469 uint32_t Mask : __CODEGEN_BITFIELD(18, 31); ///< U16 470 471 }; 472 uint32_t Value; 473 } DW0; 474 475 ////////////////////////////////////////////////////////////////////////// 476 /// @name LOCAL ENUMERATIONS 477 /// @{ 478 479 /// @brief 480 enum CONSTANTS_TYPE 481 { 482 COMMAND_LENGTH = 1, ///< 483 REGISTER_OFFSET = 0x22200, ///< 484 }; 485 //! \name Initializations 486 487 //! \brief Explicit member initialization function 488 BCS_SWCTRL_CMD(); 489 490 static const size_t dwSize = 1; 491 static const size_t byteSize = 4; 492 }; 493 494 struct BCS_SWCTRL_XE // just used for XE+ 495 { 496 union 497 { 498 struct 499 { 500 /// DWORD 0 501 uint32_t Tile4Source : __CODEGEN_BITFIELD(0, 0); ///< U1 502 uint32_t Tile4Destination : __CODEGEN_BITFIELD(1, 1); ///< U1 503 uint32_t SystemMemoryThrottleThreshold : __CODEGEN_BITFIELD(2, 15); ///< U14 504 uint32_t Mask : __CODEGEN_BITFIELD(16, 31); ///< U16 505 506 }; 507 uint32_t Value; 508 } DW0; 509 510 ////////////////////////////////////////////////////////////////////////// 511 /// @name LOCAL ENUMERATIONS 512 /// @{ 513 /// @brief U1 514 enum TILE_4_SOURCE 515 { 516 TILE_4_SOURCE_XMAJOR = 0, ///< 517 TILE_4_SOURCE_TILE4 = 1, ///< 518 }; 519 520 /// @brief U1 521 enum TILE_4_DESTINATION 522 { 523 TILE_4_DESTINATION_XMAJOR = 0, ///< 524 TILE_4_DESTINATION_TILE4 = 1, /// 525 }; 526 /// @brief 527 enum CONSTANTS_TYPE 528 { 529 COMMAND_LENGTH = 1, ///< 530 REGISTER_OFFSET = 0x22200, ///< 531 }; 532 //! \name Initializations 533 534 //! \brief Explicit member initialization function 535 BCS_SWCTRL_XE(); 536 537 static const size_t dwSize = 1; 538 static const size_t byteSize = 4; 539 }; 540 }; 541 542 #endif // __MHW_BLT_H__ 543