minigbm: add buffer bandwidth compression flag to gbm device

Read MINIGBM_DEBUG env var when creating a gbm driver
Store value as a flag inside driver
Avoid allocating compressed buffers in the backends
when the flag disables compression

BUG=b:172215587

Change-Id: Idbd6f0aebc1782c1bf5921a6438310a87212d1f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2535658
Tested-by: Pilar Molina Lopez <pmolinalopez@google.com>
Commit-Queue: Pilar Molina Lopez <pmolinalopez@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@chromium.org>
diff --git a/drv.c b/drv.c
index 10e8f8d..233cce7 100644
--- a/drv.c
+++ b/drv.c
@@ -128,6 +128,10 @@
 	if (!drv)
 		return NULL;
 
+	char *minigbm_debug;
+	minigbm_debug = getenv("MINIGBM_DEBUG");
+	drv->compression = (minigbm_debug == NULL) || (strcmp(minigbm_debug, "nocompression") != 0);
+
 	drv->fd = fd;
 	drv->backend = drv_get_backend(fd);
 
diff --git a/drv_priv.h b/drv_priv.h
index d918b33..6ce7fa1 100644
--- a/drv_priv.h
+++ b/drv_priv.h
@@ -57,6 +57,7 @@
 	struct drv_array *mappings;
 	struct drv_array *combos;
 	pthread_mutex_t driver_lock;
+	bool compression;
 };
 
 struct backend {
diff --git a/i915.c b/i915.c
index 723d009..b45cbfe 100644
--- a/i915.c
+++ b/i915.c
@@ -353,6 +353,22 @@
 			modifier = I915_FORMAT_MOD_X_TILED;
 	}
 
+	/*
+	 * Skip I915_FORMAT_MOD_Y_TILED_CCS modifier if compression is disabled
+	 * Pick y tiled modifier if it has been passed in, otherwise use linear
+	 */
+	if (!bo->drv->compression && modifier == I915_FORMAT_MOD_Y_TILED_CCS) {
+		uint32_t i;
+		for (i = 0; modifiers && i < count; i++) {
+			if (modifiers[i] == I915_FORMAT_MOD_Y_TILED)
+				break;
+		}
+		if (i == count)
+			modifier = DRM_FORMAT_MOD_LINEAR;
+		else
+			modifier = I915_FORMAT_MOD_Y_TILED;
+	}
+
 	switch (modifier) {
 	case DRM_FORMAT_MOD_LINEAR:
 		bo->meta.tiling = I915_TILING_NONE;
diff --git a/msm.c b/msm.c
index 033dda5..acfc1ef 100644
--- a/msm.c
+++ b/msm.c
@@ -250,7 +250,7 @@
 
 	drv_modify_linear_combinations(drv);
 
-	if (should_avoid_ubwc())
+	if (should_avoid_ubwc() || !drv->compression)
 		return 0;
 
 	metadata.tiling = MSM_UBWC_TILING;
@@ -315,6 +315,9 @@
 	uint64_t modifier =
 	    drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order));
 
+	if (!bo->drv->compression && modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED)
+		modifier = DRM_FORMAT_MOD_LINEAR;
+
 	return msm_bo_create_for_modifier(bo, width, height, format, modifier);
 }
 
diff --git a/rockchip.c b/rockchip.c
index 9ef7962..30d9fbe 100644
--- a/rockchip.c
+++ b/rockchip.c
@@ -128,7 +128,8 @@
 		 */
 		bo->meta.total_size += w_mbs * h_mbs * 128;
 	} else if (width <= 2560 &&
-		   drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
+		   drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) &&
+		   bo->drv->compression) {
 		/* If the caller has decided they can use AFBC, always
 		 * pick that */
 		afbc_bo_from_format(bo, width, height, format);