Skip to contentSkip to conversation

drm/fourcc: Add macros to determine the modifier vendor

PATCH In review Thierry Reding 2 participants 5 messages Jun 10, 2021 – Aug 16, 2021

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

PATCH 1/3 drm/fourcc: Add macros to determine the modifier vendor

From: Thierry Reding <[email protected]>

When working with framebuffer modifiers, it can be useful to extract the vendor identifier or check a modifier against a given vendor identifier. Add one macro that extracts the vendor identifier and a helper to check a modifier against a given vendor identifier.

---
 include/uapi/drm/drm_fourcc.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/drm/drm_fourcc.h +6 -0
index f7156322aba5..36771d8ffc4a 100644
@@ -373,6 +373,12 @@ extern "C" {
 
 #define DRM_FORMAT_RESERVED	      ((1ULL << 56) - 1)
 
+#define fourcc_mod_get_vendor(modifier) \
+	(((modifier) >> 56) & 0xff)
+
+#define fourcc_mod_is_vendor(modifier, vendor) \
+	(fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_## vendor)
+
 #define fourcc_mod_code(vendor, val) \
 	((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
 
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/3 drm/arm: malidp: Use fourcc_mod_is_vendor() helper

From: Thierry Reding <[email protected]>

Rather than open-coding the vendor extraction operation, use the newly introduced helper macro.

---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_planes.c +1 -1
index 8c2ab3d653b7..0562bdaac00c 100644
@@ -165,7 +165,7 @@ bool malidp_format_mod_supported(struct drm_device *drm,
 		return !malidp_hw_format_is_afbc_only(format);
 	}
 
-	if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_ARM) {
+	if (!fourcc_mod_is_vendor(modifier, ARM)) {
 		DRM_ERROR("Unknown modifier (not Arm)\n");
 		return false;
 	}
Signature · 1 line
2.31.1
#2 lore raw

PATCH 3/3 drm/tegra: Use fourcc_mod_is_vendor() helper

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Rather than open-coding the vendor extraction operation, use the newly introduced helper macro.

---
 drivers/gpu/drm/tegra/fb.c    | 2 +-
 drivers/gpu/drm/tegra/plane.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/fb.c +1 -1
index cae8b8cbe9dd..c04dda8353fd 100644
@@ -44,7 +44,7 @@ int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
 {
 	uint64_t modifier = framebuffer->modifier;
 
-	if ((modifier >> 56) == DRM_FORMAT_MOD_VENDOR_NVIDIA) {
+	if (fourcc_mod_is_vendor(modifier, NVIDIA)) {
 		if ((modifier & DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT) == 0)
 			tiling->sector_layout = TEGRA_BO_SECTOR_LAYOUT_TEGRA;
 		else
drivers/gpu/drm/tegra/plane.c +1 -1
index 2e65b4075ce6..f7496425fa83 100644
@@ -109,7 +109,7 @@ static bool tegra_plane_format_mod_supported(struct drm_plane *plane,
 		return true;
 
 	/* check for the sector layout bit */
-	if ((modifier >> 56) == DRM_FORMAT_MOD_VENDOR_NVIDIA) {
+	if (fourcc_mod_is_vendor(modifier, NVIDIA)) {
 		if (modifier & DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT) {
 			if (!tegra_plane_supports_sector_layout(plane))
 				return false;
Signature · 1 line
2.31.1
Reviewed-by on v1 3/3
#3 lore raw

Re: [PATCH 3/3] drm/tegra: Use fourcc_mod_is_vendor() helper

Quoted 6 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Rather than open-coding the vendor extraction operation, use the newly introduced helper macro.

Quoted 34 lines
---
 drivers/gpu/drm/tegra/fb.c    | 2 +-
 drivers/gpu/drm/tegra/plane.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/fb.c +1 -1
index cae8b8cbe9dd..c04dda8353fd 100644
@@ -44,7 +44,7 @@ int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
 {
 	uint64_t modifier = framebuffer->modifier;
 
-	if ((modifier >> 56) == DRM_FORMAT_MOD_VENDOR_NVIDIA) {
+	if (fourcc_mod_is_vendor(modifier, NVIDIA)) {
 		if ((modifier & DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT) == 0)
 			tiling->sector_layout = TEGRA_BO_SECTOR_LAYOUT_TEGRA;
 		else
drivers/gpu/drm/tegra/plane.c +1 -1
index 2e65b4075ce6..f7496425fa83 100644
@@ -109,7 +109,7 @@ static bool tegra_plane_format_mod_supported(struct drm_plane *plane,
 		return true;
 
 	/* check for the sector layout bit */
-	if ((modifier >> 56) == DRM_FORMAT_MOD_VENDOR_NVIDIA) {
+	if (fourcc_mod_is_vendor(modifier, NVIDIA)) {
 		if (modifier & DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT) {
 			if (!tegra_plane_supports_sector_layout(plane))
 				return false;
Signature · 1 line
2.31.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw
In reply to Thierry Reding
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When working with framebuffer modifiers, it can be useful to extract the vendor identifier or check a modifier against a given vendor identifier. Add one macro that extracts the vendor identifier and a helper to check a modifier against a given vendor identifier.

Quoted 6 lines
---
 include/uapi/drm/drm_fourcc.h | 6 ++++++
 1 file changed, 6 insertions(+)

Sorry for this taking so long, I've finally applied this to drm-misc-next.

Thierry