Use plane property for setting Exynos zpos

On older kernel versions there was an Exynos-specific ioctl
to set the plane Z position. More recent kernels have replaced
this with a property on the plane objects.

This patch attempts to use the property first, and falls back
to the old method if that fails.

Change-Id: I9b22c1b0eb128cee2f0e7c5907012a49592787e1
diff --git a/src/drmmode_exynos/drmmode_exynos.c b/src/drmmode_exynos/drmmode_exynos.c
index a5a98d2..0c2a895 100644
--- a/src/drmmode_exynos/drmmode_exynos.c
+++ b/src/drmmode_exynos/drmmode_exynos.c
@@ -48,12 +48,45 @@
 
 static int init_plane_for_cursor(int drm_fd, uint32_t plane_id)
 {
-	struct drm_exynos_plane_set_zpos data;
+	int res = -1;
+	drmModeObjectPropertiesPtr props;
+	props = drmModeObjectGetProperties(drm_fd, plane_id,
+			DRM_MODE_OBJECT_PLANE);
 
-	data.plane_id = plane_id;
-	data.zpos = 1;
+	if (props) {
+		int i;
 
-	return ioctl(drm_fd, DRM_IOCTL_EXYNOS_PLANE_SET_ZPOS, &data);
+		for (i = 0; i < props->count_props; i++) {
+			drmModePropertyPtr this_prop;
+			this_prop = drmModeGetProperty(drm_fd, props->props[i]);
+
+			if (this_prop) {
+				if (!strncmp(this_prop->name, "zpos",
+							DRM_PROP_NAME_LEN)) {
+					res = drmModeObjectSetProperty(drm_fd,
+							plane_id,
+							DRM_MODE_OBJECT_PLANE,
+							this_prop->prop_id,
+							1);
+					drmModeFreeProperty(this_prop);
+					break;
+				}
+				drmModeFreeProperty(this_prop);
+			}
+		}
+		drmModeFreeObjectProperties(props);
+	}
+
+	if (res) {
+		/* Try the old method */
+		struct drm_exynos_plane_set_zpos data;
+		data.plane_id = plane_id;
+		data.zpos = 1;
+
+		res = ioctl(drm_fd, DRM_IOCTL_EXYNOS_PLANE_SET_ZPOS, &data);
+	}
+
+	return res;
 }
 
 /* The cursor format is ARGB so the image can be copied straight over.