minigbm: Added YV12 for Mali platforms

Oak-cheets is using YV12 as it's Android flexible YUV format, so
we need to support it.  Additionally, we're trying to enable
YV12 on Mali with EXT_image_dma_buf_import.  Instead of having
redundant switch statements in every driver, let's add a helper
function to do this.

BUG=chrome-os-partner:54632, b/29059119, chromium:616275
TEST=Ran plane_test, graphics_Gbm on veyron_minnie

Change-Id: I4798225db809941367e58dde962576535b8d767c
Reviewed-on: https://chromium-review.googlesource.com/377884
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/helpers.c b/helpers.c
index b5eb732..14197e4 100644
--- a/helpers.c
+++ b/helpers.c
@@ -170,6 +170,43 @@
 	return stride;
 }
 
+/*
+ * This function fills in the buffer object given driver aligned dimensions
+ * and a format.  This function assumes there is just one kernel buffer per
+ * buffer object.
+ */
+int drv_bo_from_format(struct bo *bo, uint32_t width, uint32_t height,
+		       drv_format_t format)
+{
+
+	switch (format) {
+	case DRV_FORMAT_YVU420:
+		bo->strides[0] = drv_stride_from_format(format, width, 0);
+		bo->strides[1] = drv_stride_from_format(format, width, 1);
+		bo->strides[2] = drv_stride_from_format(format, width, 2);
+		bo->sizes[0] = height * bo->strides[0];
+		bo->sizes[1] = bo->sizes[2] = (height / 2) * bo->strides[1];
+		bo->offsets[0] = 0;
+		bo->offsets[1] = bo->sizes[0];
+		bo->offsets[2] = bo->offsets[1] + bo->sizes[1];
+		break;
+	case DRV_FORMAT_NV12:
+		bo->strides[0] = drv_stride_from_format(format, width, 0);
+		bo->strides[1] = drv_stride_from_format(format, width, 1);
+		bo->sizes[0] = height * bo->strides[0];
+		bo->sizes[1] = height * bo->strides[1] / 2;
+		bo->offsets[0] = 0;
+		bo->offsets[1] = height * bo->strides[0];
+		break;
+	default:
+		bo->strides[0] = drv_stride_from_format(format, width, 0);
+		bo->sizes[0] = height * bo->strides[0];
+		bo->offsets[0] = 0;
+	}
+
+	return 0;
+}
+
 int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
 		       uint32_t format, uint32_t flags)
 {