Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/tegra: Sanitize format modifiers

The existing format modifier definitions were merged prematurely, and
recent work has unveiled that the definitions are suboptimal in several
ways:

- The format specifiers, except for one, are not Tegra specific, but
the names don't reflect that.
- The number space is split into two, reserving 32 bits for some
"parameter" which most of the modifiers are not going to have.
- Symbolic names for the modifiers are not using the standard
DRM_FORMAT_MOD_* prefix, which makes them awkward to use.
- The vendor prefix NV is somewhat ambiguous.

Fortunately, nobody's started using these modifiers, so we can still fix
the above issues. Do so by using the standard prefix. Also, remove TEGRA
from the name of those modifiers that exist on NVIDIA GPUs as well. In
case of the block linear modifiers, make the "parameter" smaller (4
bits, though only 6 values are valid) and don't let that leak into any
of the other modifiers.

Finally, also use the more canonical NVIDIA instead of the ambiguous NV
prefix.

Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thierry Reding <treding@nvidia.com>

+48 -23
+29 -6
drivers/gpu/drm/tegra/fb.c
··· 54 54 struct tegra_fb *fb = to_tegra_fb(framebuffer); 55 55 uint64_t modifier = fb->base.modifier; 56 56 57 - switch (fourcc_mod_tegra_mod(modifier)) { 58 - case NV_FORMAT_MOD_TEGRA_TILED: 57 + switch (modifier) { 58 + case DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED: 59 59 tiling->mode = TEGRA_BO_TILING_MODE_TILED; 60 60 tiling->value = 0; 61 61 break; 62 62 63 - case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(0): 63 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0): 64 64 tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 65 - tiling->value = fourcc_mod_tegra_param(modifier); 66 - if (tiling->value > 5) 67 - return -EINVAL; 65 + tiling->value = 0; 66 + break; 67 + 68 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1): 69 + tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 70 + tiling->value = 1; 71 + break; 72 + 73 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2): 74 + tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 75 + tiling->value = 2; 76 + break; 77 + 78 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3): 79 + tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 80 + tiling->value = 3; 81 + break; 82 + 83 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4): 84 + tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 85 + tiling->value = 4; 86 + break; 87 + 88 + case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5): 89 + tiling->mode = TEGRA_BO_TILING_MODE_BLOCK; 90 + tiling->value = 5; 68 91 break; 69 92 70 93 default:
+19 -17
include/uapi/drm/drm_fourcc.h
··· 178 178 #define DRM_FORMAT_MOD_VENDOR_NONE 0 179 179 #define DRM_FORMAT_MOD_VENDOR_INTEL 0x01 180 180 #define DRM_FORMAT_MOD_VENDOR_AMD 0x02 181 - #define DRM_FORMAT_MOD_VENDOR_NV 0x03 181 + #define DRM_FORMAT_MOD_VENDOR_NVIDIA 0x03 182 182 #define DRM_FORMAT_MOD_VENDOR_SAMSUNG 0x04 183 183 #define DRM_FORMAT_MOD_VENDOR_QCOM 0x05 184 184 #define DRM_FORMAT_MOD_VENDOR_VIVANTE 0x06 ··· 338 338 */ 339 339 #define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4) 340 340 341 - /* NVIDIA Tegra frame buffer modifiers */ 342 - 343 - /* 344 - * Some modifiers take parameters, for example the number of vertical GOBs in 345 - * a block. Reserve the lower 32 bits for parameters 346 - */ 347 - #define __fourcc_mod_tegra_mode_shift 32 348 - #define fourcc_mod_tegra_code(val, params) \ 349 - fourcc_mod_code(NV, ((((__u64)val) << __fourcc_mod_tegra_mode_shift) | params)) 350 - #define fourcc_mod_tegra_mod(m) \ 351 - (m & ~((1ULL << __fourcc_mod_tegra_mode_shift) - 1)) 352 - #define fourcc_mod_tegra_param(m) \ 353 - (m & ((1ULL << __fourcc_mod_tegra_mode_shift) - 1)) 341 + /* NVIDIA frame buffer modifiers */ 354 342 355 343 /* 356 344 * Tegra Tiled Layout, used by Tegra 2, 3 and 4. 357 345 * 358 346 * Pixels are arranged in simple tiles of 16 x 16 bytes. 359 347 */ 360 - #define NV_FORMAT_MOD_TEGRA_TILED fourcc_mod_tegra_code(1, 0) 348 + #define DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED fourcc_mod_code(NVIDIA, 1) 361 349 362 350 /* 363 - * Tegra 16Bx2 Block Linear layout, used by TK1/TX1 351 + * 16Bx2 Block Linear layout, used by desktop GPUs, and Tegra K1 and later 364 352 * 365 353 * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked 366 354 * vertically by a power of 2 (1 to 32 GOBs) to form a block. ··· 368 380 * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format 369 381 * in full detail. 370 382 */ 371 - #define NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(v) fourcc_mod_tegra_code(2, v) 383 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(v) \ 384 + fourcc_mod_code(NVIDIA, 0x10 | ((v) & 0xf)) 385 + 386 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB \ 387 + fourcc_mod_code(NVIDIA, 0x10) 388 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB \ 389 + fourcc_mod_code(NVIDIA, 0x11) 390 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB \ 391 + fourcc_mod_code(NVIDIA, 0x12) 392 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB \ 393 + fourcc_mod_code(NVIDIA, 0x13) 394 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB \ 395 + fourcc_mod_code(NVIDIA, 0x14) 396 + #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB \ 397 + fourcc_mod_code(NVIDIA, 0x15) 372 398 373 399 /* 374 400 * Broadcom VC4 "T" format