Skip to contentSkip to conversation

drm/tegra: Sanitize format modifiers

PATCH In review Thierry Reding 2 participants 4 messages Jan 12, 2018 – Jan 26, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover drm/tegra: Sanitize format modifiers

From: Thierry Reding <[email protected]>

These UABI changes have now been merged into drm-next, so synchronize the libdrm headers and fixup the format modifiers in modetest.

Thierry

Thierry Reding (2):
drm/fourcc: Fix fourcc_mod_code() definition
drm/tegra: Sanitize format modifiers

 include/drm/drm_fourcc.h  | 38 ++++++++++++++++++++------------------
 tests/modetest/modetest.c | 28 ++++++++++++++--------------
 2 files changed, 34 insertions(+), 32 deletions(-)
Signature · 6 lines
2.15.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/2 drm/fourcc: Fix fourcc_mod_code() definition

From: Thierry Reding <[email protected]>

Avoid compiler warnings when the val parameter is an expression.

---
 include/drm/drm_fourcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/drm/drm_fourcc.h +1 -1
index 3ad838d3f93f..a76ed8f9e383 100644
@@ -188,7 +188,7 @@ extern "C" {
 #define DRM_FORMAT_RESERVED	      ((1ULL << 56) - 1)
 
 #define fourcc_mod_code(vendor, val) \
-	((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | (val & 0x00ffffffffffffffULL))
+	((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
 
 /*
  * Format Modifier tokens:
Signature · 6 lines
2.15.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/2 drm/tegra: Sanitize format modifiers

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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.

---
 include/drm/drm_fourcc.h  | 36 +++++++++++++++++++-----------------
 tests/modetest/modetest.c | 28 ++++++++++++++--------------
 2 files changed, 33 insertions(+), 31 deletions(-)
include/drm/drm_fourcc.h +19 -17
index a76ed8f9e383..e04613d30a13 100644
@@ -178,7 +178,7 @@ extern "C" {
 #define DRM_FORMAT_MOD_VENDOR_NONE    0
 #define DRM_FORMAT_MOD_VENDOR_INTEL   0x01
 #define DRM_FORMAT_MOD_VENDOR_AMD     0x02
-#define DRM_FORMAT_MOD_VENDOR_NV      0x03
+#define DRM_FORMAT_MOD_VENDOR_NVIDIA  0x03
 #define DRM_FORMAT_MOD_VENDOR_SAMSUNG 0x04
 #define DRM_FORMAT_MOD_VENDOR_QCOM    0x05
 #define DRM_FORMAT_MOD_VENDOR_VIVANTE 0x06
@@ -338,29 +338,17 @@ extern "C" {
  */
 #define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4)
 
-/* NVIDIA Tegra frame buffer modifiers */
-
-/*
- * Some modifiers take parameters, for example the number of vertical GOBs in
- * a block. Reserve the lower 32 bits for parameters
- */
-#define __fourcc_mod_tegra_mode_shift 32
-#define fourcc_mod_tegra_code(val, params) \
-	fourcc_mod_code(NV, ((((__u64)val) << __fourcc_mod_tegra_mode_shift) | params))
-#define fourcc_mod_tegra_mod(m) \
-	(m & ~((1ULL << __fourcc_mod_tegra_mode_shift) - 1))
-#define fourcc_mod_tegra_param(m) \
-	(m & ((1ULL << __fourcc_mod_tegra_mode_shift) - 1))
+/* NVIDIA frame buffer modifiers */
 
 /*
  * Tegra Tiled Layout, used by Tegra 2, 3 and 4.
  *
  * Pixels are arranged in simple tiles of 16 x 16 bytes.
  */
-#define NV_FORMAT_MOD_TEGRA_TILED fourcc_mod_tegra_code(1, 0)
+#define DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED fourcc_mod_code(NVIDIA, 1)
 
 /*
- * Tegra 16Bx2 Block Linear layout, used by TK1/TX1
+ * 16Bx2 Block Linear layout, used by desktop GPUs, and Tegra K1 and later
  *
  * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked
  * vertically by a power of 2 (1 to 32 GOBs) to form a block.
@@ -380,7 +368,21 @@ extern "C" {
  * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
  * in full detail.
  */
-#define NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(v) fourcc_mod_tegra_code(2, v)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(v) \
+	fourcc_mod_code(NVIDIA, 0x10 | ((v) & 0xf))
+
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB \
+	fourcc_mod_code(NVIDIA, 0x10)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB \
+	fourcc_mod_code(NVIDIA, 0x11)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB \
+	fourcc_mod_code(NVIDIA, 0x12)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB \
+	fourcc_mod_code(NVIDIA, 0x13)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB \
+	fourcc_mod_code(NVIDIA, 0x14)
+#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB \
+	fourcc_mod_code(NVIDIA, 0x15)
 
 /*
  * Broadcom VC4 "T" format
tests/modetest/modetest.c +14 -14
index 62d933272423..701547f4b648 100644
@@ -278,20 +278,20 @@ static const char *modifier_to_string(uint64_t modifier)
 		return "VIVANTE_SPLIT_TILED";
 	case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED:
 		return "VIVANTE_SPLIT_SUPER_TILED";
-	case NV_FORMAT_MOD_TEGRA_TILED:
-		return "MOD_TEGRA_TILED";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(0):
-		return "MOD_TEGRA_16BX2_BLOCK(0)";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(1):
-		return "MOD_TEGRA_16BX2_BLOCK(1)";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(2):
-		return "MOD_TEGRA_16BX2_BLOCK(2)";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(3):
-		return "MOD_TEGRA_16BX2_BLOCK(3)";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(4):
-		return "MOD_TEGRA_16BX2_BLOCK(4)";
-	case NV_FORMAT_MOD_TEGRA_16BX2_BLOCK(5):
-		return "MOD_TEGRA_16BX2_BLOCK(5)";
+	case DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED:
+		return "NVIDIA_TEGRA_TILED";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0):
+		return "NVIDIA_16BX2_BLOCK(0)";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1):
+		return "NVIDIA_16BX2_BLOCK(1)";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2):
+		return "NVIDIA_16BX2_BLOCK(2)";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3):
+		return "NVIDIA_16BX2_BLOCK(3)";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4):
+		return "NVIDIA_16BX2_BLOCK(4)";
+	case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5):
+		return "NVIDIA_16BX2_BLOCK(5)";
 	case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED:
 		return "MOD_BROADCOM_VC4_T_TILED";
 	default:
Signature · 6 lines
2.15.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Acked-by on the v1 series
#3 lore raw
In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

From: Thierry Reding <[email protected]>

These UABI changes have now been merged into drm-next, so synchronize the libdrm headers and fixup the format modifiers in modetest.

Hi Thierry,

I haven't checked the diff in detail, but on quick look it seems fine.

Please a add reference to branch/sha1, that these are based on, in the commit message of the respective patches. With that the series is

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel