[PATCH 44/81] drm/i915: Refactor property handling in atomic code

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Wed Dec 12 08:16:11 PST 2012


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Move the property code around a bit to make it easier to move it out to
the drm core later.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 drivers/gpu/drm/i915/intel_atomic.c |  423 ++++++++++++++++++++---------------
 drivers/gpu/drm/i915/intel_drv.h    |    3 +
 include/drm/drm_crtc.h              |   12 +
 3 files changed, 252 insertions(+), 186 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_atomic.c b/drivers/gpu/drm/i915/intel_atomic.c
index 41fd0d5..0e37cf5 100644
--- a/drivers/gpu/drm/i915/intel_atomic.c
+++ b/drivers/gpu/drm/i915/intel_atomic.c
@@ -1473,87 +1473,6 @@ static int intel_atomic_check(struct drm_device *dev, void *state)
 	return 0;
 }
 
-static void update_plane_props(struct drm_plane *plane)
-{
-	struct drm_mode_object *obj = &plane->base;
-
-	drm_object_property_set_value(obj, prop_src_x, plane->src_x);
-	drm_object_property_set_value(obj, prop_src_y, plane->src_y);
-	drm_object_property_set_value(obj, prop_src_w, plane->src_w);
-	drm_object_property_set_value(obj, prop_src_h, plane->src_h);
-
-	drm_object_property_set_value(obj, prop_crtc_x, plane->crtc_x);
-	drm_object_property_set_value(obj, prop_crtc_y, plane->crtc_y);
-	drm_object_property_set_value(obj, prop_crtc_w, plane->crtc_w);
-	drm_object_property_set_value(obj, prop_crtc_h, plane->crtc_h);
-
-	drm_object_property_set_value(obj, prop_fb_id, plane->fb ? plane->fb->base.id : 0);
-	drm_object_property_set_value(obj, prop_crtc_id, plane->crtc ? plane->crtc->base.id : 0);
-}
-
-static int update_prop_connector_ids(struct drm_crtc *crtc)
-{
-	struct drm_device *dev = crtc->dev;
-	struct drm_connector *connector;
-	uint64_t value = 0;
-	int i = 0;
-	uint32_t connector_ids[dev->mode_config.num_connector];
-
-	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
-		if (connector->encoder && connector->encoder->crtc == crtc)
-			connector_ids[i++] = connector->base.id;
-	}
-
-	if (i) {
-		drm_property_blob_replace_data(crtc->connector_ids_blob,
-					       i * sizeof connector_ids[0], connector_ids);
-		value = crtc->connector_ids_blob->base.id;
-	} else
-		drm_property_blob_replace_data(crtc->connector_ids_blob, 0, NULL);
-
-	drm_object_property_set_value(&crtc->base, prop_connector_ids, value);
-
-	return 0;
-}
-
-static int update_prop_mode(struct drm_crtc *crtc)
-{
-	uint64_t value = 0;
-
-	if (crtc->enabled) {
-		struct drm_mode_modeinfo umode;
-
-		drm_crtc_convert_to_umode(&umode, &crtc->mode);
-		drm_property_blob_replace_data(crtc->mode_blob, sizeof umode, &umode);
-		value = crtc->mode_blob->base.id;
-	} else
-		drm_property_blob_replace_data(crtc->mode_blob, 0, NULL);
-
-	drm_object_property_set_value(&crtc->base, prop_mode, value);
-
-	return 0;
-}
-
-static void update_crtc_props(struct drm_crtc *crtc)
-{
-	struct drm_mode_object *obj = &crtc->base;
-	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
-	drm_object_property_set_value(obj, prop_src_x, crtc->x);
-	drm_object_property_set_value(obj, prop_src_y, crtc->y);
-
-	drm_object_property_set_value(obj, prop_fb_id, crtc->fb ? crtc->fb->base.id : 0);
-
-	drm_object_property_set_value(obj, prop_cursor_id, intel_crtc->cursor_handle);
-	drm_object_property_set_value(obj, prop_cursor_x, intel_crtc->cursor_x);
-	drm_object_property_set_value(obj, prop_cursor_y, intel_crtc->cursor_y);
-	drm_object_property_set_value(obj, prop_cursor_w, intel_crtc->cursor_width);
-	drm_object_property_set_value(obj, prop_cursor_h, intel_crtc->cursor_height);
-
-	update_prop_mode(crtc);
-	update_prop_connector_ids(crtc);
-}
-
 static void update_props(struct drm_device *dev,
 			 struct intel_atomic_state *s)
 {
@@ -1565,7 +1484,7 @@ static void update_props(struct drm_device *dev,
 		if (!st->fb_dirty && !st->mode_dirty)
 			continue;
 
-		update_crtc_props(st->crtc);
+		intel_crtc_update_properties(st->crtc);
 	}
 
 	for (i = 0; i < dev->mode_config.num_plane; i++) {
@@ -1574,7 +1493,7 @@ static void update_props(struct drm_device *dev,
 		if (!st->dirty)
 			continue;
 
-		update_plane_props(st->plane);
+		drm_plane_update_properties(st->plane);
 	}
 }
 
@@ -1829,32 +1748,6 @@ static const struct drm_atomic_funcs intel_atomic_funcs = {
 	.end = intel_atomic_end,
 };
 
-static struct {
-	struct drm_property **prop;
-	const char *name;
-	uint64_t min;
-	uint64_t max;
-} props[] = {
-	{ &prop_src_x, "SRC_X", 0, UINT_MAX },
-	{ &prop_src_y, "SRC_Y", 0, UINT_MAX },
-	{ &prop_src_w, "SRC_W", 0, UINT_MAX },
-	{ &prop_src_h, "SRC_H", 0, UINT_MAX },
-
-	{ &prop_crtc_x, "CRTC_X", INT_MIN, INT_MAX },
-	{ &prop_crtc_y, "CRTC_Y", INT_MIN, INT_MAX },
-	{ &prop_crtc_w, "CRTC_W", 0, INT_MAX },
-	{ &prop_crtc_h, "CRTC_H", 0, INT_MAX },
-
-	{ &prop_fb_id, "FB_ID", 0, UINT_MAX },
-	{ &prop_crtc_id, "CRTC_ID", 0, UINT_MAX },
-
-	{ &prop_cursor_id, "CURSOR_ID", 0, UINT_MAX },
-	{ &prop_cursor_w, "CURSOR_W", 0, UINT_MAX },
-	{ &prop_cursor_h, "CURSOR_H", 0, UINT_MAX },
-	{ &prop_cursor_x, "CURSOR_X", INT_MIN, INT_MAX },
-	{ &prop_cursor_y, "CURSOR_Y", INT_MIN, INT_MAX },
-};
-
 static void intel_flip_init(struct drm_device *dev);
 static void intel_flip_fini(struct drm_device *dev);
 
@@ -1862,71 +1755,25 @@ int intel_atomic_init(struct drm_device *dev)
 {
 	struct drm_crtc *crtc;
 	struct drm_plane *plane;
-	int ret = -ENOMEM;
-	unsigned int i;
+	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(props); i++) {
-		*props[i].prop =
-			drm_property_create_range(dev, 0, props[i].name,
-						  props[i].min, props[i].max);
-		if (!*props[i].prop)
-			goto out;
-	}
-
-	/* FIXME create special object ID list property type? */
-	prop_connector_ids = drm_property_create(dev, DRM_MODE_PROP_BLOB, "CONNECTOR_IDS", 0);
-	if (!prop_connector_ids)
-		goto out;
-
-	prop_mode = drm_property_create(dev, DRM_MODE_PROP_BLOB, "MODE", 0);
-	if (!prop_mode)
+	ret = drm_mode_create_properties(dev);
+	if (ret)
 		goto out;
 
 	list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
-		struct drm_mode_object *obj = &plane->base;
-
-		drm_object_attach_property(obj, prop_src_x, 0);
-		drm_object_attach_property(obj, prop_src_y, 0);
-		drm_object_attach_property(obj, prop_src_w, 0);
-		drm_object_attach_property(obj, prop_src_h, 0);
-
-		drm_object_attach_property(obj, prop_crtc_x, 0);
-		drm_object_attach_property(obj, prop_crtc_y, 0);
-		drm_object_attach_property(obj, prop_crtc_w, 0);
-		drm_object_attach_property(obj, prop_crtc_h, 0);
-
-		drm_object_attach_property(obj, prop_fb_id, 0);
-		drm_object_attach_property(obj, prop_crtc_id, 0);
-
-		update_plane_props(plane);
+		drm_plane_attach_properties(plane);
+		drm_plane_update_properties(plane);
 	}
 
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		struct drm_mode_object *obj = &crtc->base;
+		intel_crtc_attach_properties(crtc);
 
-		drm_object_attach_property(obj, prop_src_x, 0);
-		drm_object_attach_property(obj, prop_src_y, 0);
+		ret = drm_crtc_create_blobs(crtc);
+		if (ret)
+			goto destroy_props;
 
-		drm_object_attach_property(obj, prop_fb_id, 0);
-		drm_object_attach_property(obj, prop_mode, 0);
-		drm_object_attach_property(obj, prop_connector_ids, 0);
-
-		drm_object_attach_property(obj, prop_cursor_id, 0);
-		drm_object_attach_property(obj, prop_cursor_x, 0);
-		drm_object_attach_property(obj, prop_cursor_y, 0);
-		drm_object_attach_property(obj, prop_cursor_w, 0);
-		drm_object_attach_property(obj, prop_cursor_h, 0);
-
-		crtc->mode_blob = drm_property_create_blob(dev, 0, sizeof(struct drm_mode_modeinfo), NULL);
-		if (!crtc->mode_blob)
-			goto out;
-
-		crtc->connector_ids_blob = drm_property_create_blob(dev, 0,
-								    dev->mode_config.num_connector * sizeof(uint32_t), NULL);
-		if (!crtc->connector_ids_blob)
-			goto out;
-
-		update_crtc_props(crtc);
+		intel_crtc_update_properties(crtc);
 	}
 
 	dev->driver->atomic_funcs = &intel_atomic_funcs;
@@ -1935,12 +1782,9 @@ int intel_atomic_init(struct drm_device *dev)
 
 	return 0;
 
+ destroy_props:
+	drm_mode_destroy_properties(dev);
  out:
-	drm_property_destroy(dev, prop_mode);
-	drm_property_destroy(dev, prop_connector_ids);
-
-	while (i--)
-		drm_property_destroy(dev, *props[i].prop);
 
 	return ret;
 }
@@ -1952,24 +1796,10 @@ void intel_atomic_fini(struct drm_device *dev)
 	intel_flip_fini(dev);
 
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		drm_property_destroy_blob(dev, crtc->mode_blob);
-		drm_property_destroy_blob(dev, crtc->connector_ids_blob);
+		drm_crtc_destroy_blobs(crtc);
 	}
 
-	drm_property_destroy(dev, prop_connector_ids);
-	drm_property_destroy(dev, prop_mode);
-	drm_property_destroy(dev, prop_crtc_id);
-	drm_property_destroy(dev, prop_fb_id);
-
-	drm_property_destroy(dev, prop_crtc_h);
-	drm_property_destroy(dev, prop_crtc_w);
-	drm_property_destroy(dev, prop_crtc_y);
-	drm_property_destroy(dev, prop_crtc_x);
-
-	drm_property_destroy(dev, prop_src_h);
-	drm_property_destroy(dev, prop_src_w);
-	drm_property_destroy(dev, prop_src_y);
-	drm_property_destroy(dev, prop_src_x);
+	drm_mode_destroy_properties(dev);
 }
 
 enum {
@@ -2464,3 +2294,224 @@ void intel_atomic_clear_flips(struct drm_crtc *crtc)
 			drm_flip_helper_clear(&intel_plane->flip_helper);
 	}
 }
+
+static void drm_crtc_update_connector_ids_property(struct drm_crtc *crtc)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_connector *connector;
+	uint64_t value = 0;
+	int i = 0;
+	uint32_t connector_ids[dev->mode_config.num_connector];
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+		if (connector->encoder && connector->encoder->crtc == crtc)
+			connector_ids[i++] = connector->base.id;
+	}
+
+	if (i) {
+		drm_property_blob_replace_data(crtc->connector_ids_blob,
+					       i * sizeof connector_ids[0], connector_ids);
+		value = crtc->connector_ids_blob->base.id;
+	} else
+		drm_property_blob_replace_data(crtc->connector_ids_blob, 0, NULL);
+
+	drm_object_property_set_value(&crtc->base, prop_connector_ids, value);
+}
+
+static void drm_crtc_update_mode_property(struct drm_crtc *crtc)
+{
+	uint64_t value = 0;
+
+	if (crtc->enabled) {
+		struct drm_mode_modeinfo umode;
+
+		drm_crtc_convert_to_umode(&umode, &crtc->mode);
+		drm_property_blob_replace_data(crtc->mode_blob, sizeof umode, &umode);
+		value = crtc->mode_blob->base.id;
+	} else
+		drm_property_blob_replace_data(crtc->mode_blob, 0, NULL);
+
+	drm_object_property_set_value(&crtc->base, prop_mode, value);
+}
+
+void drm_crtc_update_properties(struct drm_crtc *crtc)
+{
+	struct drm_mode_object *obj = &crtc->base;
+
+	drm_object_property_set_value(obj, prop_src_x, crtc->x);
+	drm_object_property_set_value(obj, prop_src_y, crtc->y);
+	drm_object_property_set_value(obj, prop_fb_id, crtc->fb ? crtc->fb->base.id : 0);
+
+	drm_crtc_update_mode_property(crtc);
+	drm_crtc_update_connector_ids_property(crtc);
+}
+
+void intel_crtc_update_properties(struct drm_crtc *crtc)
+{
+	struct drm_mode_object *obj = &crtc->base;
+	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+
+	drm_crtc_update_properties(crtc);
+
+	drm_object_property_set_value(obj, prop_cursor_id, intel_crtc->cursor_handle);
+	drm_object_property_set_value(obj, prop_cursor_x, intel_crtc->cursor_x);
+	drm_object_property_set_value(obj, prop_cursor_y, intel_crtc->cursor_y);
+	drm_object_property_set_value(obj, prop_cursor_w, intel_crtc->cursor_width);
+	drm_object_property_set_value(obj, prop_cursor_h, intel_crtc->cursor_height);
+}
+
+void drm_plane_update_properties(struct drm_plane *plane)
+{
+	struct drm_mode_object *obj = &plane->base;
+
+	drm_object_property_set_value(obj, prop_src_x, plane->src_x);
+	drm_object_property_set_value(obj, prop_src_y, plane->src_y);
+	drm_object_property_set_value(obj, prop_src_w, plane->src_w);
+	drm_object_property_set_value(obj, prop_src_h, plane->src_h);
+
+	drm_object_property_set_value(obj, prop_crtc_x, plane->crtc_x);
+	drm_object_property_set_value(obj, prop_crtc_y, plane->crtc_y);
+	drm_object_property_set_value(obj, prop_crtc_w, plane->crtc_w);
+	drm_object_property_set_value(obj, prop_crtc_h, plane->crtc_h);
+
+	drm_object_property_set_value(obj, prop_fb_id, plane->fb ? plane->fb->base.id : 0);
+	drm_object_property_set_value(obj, prop_crtc_id, plane->crtc ? plane->crtc->base.id : 0);
+}
+
+int drm_crtc_create_blobs(struct drm_crtc *crtc)
+{
+	struct drm_device *dev = crtc->dev;
+
+	crtc->mode_blob = drm_property_create_blob(dev, 0, sizeof(struct drm_mode_modeinfo), NULL);
+	if (!crtc->mode_blob)
+		return -ENOMEM;
+
+	crtc->connector_ids_blob = drm_property_create_blob(dev, 0, dev->mode_config.num_connector * sizeof(uint32_t), NULL);
+	if (!crtc->connector_ids_blob)
+		return -ENOMEM;
+
+	return 0;
+}
+
+void drm_crtc_destroy_blobs(struct drm_crtc *crtc)
+{
+	struct drm_device *dev = crtc->dev;
+
+	drm_property_destroy_blob(dev, crtc->mode_blob);
+	drm_property_destroy_blob(dev, crtc->connector_ids_blob);
+}
+
+void drm_mode_destroy_properties(struct drm_device *dev)
+{
+	drm_property_destroy(dev, prop_connector_ids);
+	drm_property_destroy(dev, prop_mode);
+	drm_property_destroy(dev, prop_crtc_id);
+	drm_property_destroy(dev, prop_fb_id);
+
+	drm_property_destroy(dev, prop_crtc_h);
+	drm_property_destroy(dev, prop_crtc_w);
+	drm_property_destroy(dev, prop_crtc_y);
+	drm_property_destroy(dev, prop_crtc_x);
+
+	drm_property_destroy(dev, prop_src_h);
+	drm_property_destroy(dev, prop_src_w);
+	drm_property_destroy(dev, prop_src_y);
+	drm_property_destroy(dev, prop_src_x);
+}
+
+static struct {
+	struct drm_property **prop;
+	const char *name;
+	uint64_t min;
+	uint64_t max;
+} props[] = {
+	{ &prop_src_x, "SRC_X", 0, UINT_MAX },
+	{ &prop_src_y, "SRC_Y", 0, UINT_MAX },
+	{ &prop_src_w, "SRC_W", 0, UINT_MAX },
+	{ &prop_src_h, "SRC_H", 0, UINT_MAX },
+
+	{ &prop_crtc_x, "CRTC_X", INT_MIN, INT_MAX },
+	{ &prop_crtc_y, "CRTC_Y", INT_MIN, INT_MAX },
+	{ &prop_crtc_w, "CRTC_W", 0, INT_MAX },
+	{ &prop_crtc_h, "CRTC_H", 0, INT_MAX },
+
+	{ &prop_fb_id, "FB_ID", 0, UINT_MAX },
+	{ &prop_crtc_id, "CRTC_ID", 0, UINT_MAX },
+
+	{ &prop_cursor_id, "CURSOR_ID", 0, UINT_MAX },
+	{ &prop_cursor_w, "CURSOR_W", 0, UINT_MAX },
+	{ &prop_cursor_h, "CURSOR_H", 0, UINT_MAX },
+	{ &prop_cursor_x, "CURSOR_X", INT_MIN, INT_MAX },
+	{ &prop_cursor_y, "CURSOR_Y", INT_MIN, INT_MAX },
+};
+
+int drm_mode_create_properties(struct drm_device *dev)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(props); i++) {
+		*props[i].prop = drm_property_create_range(dev, 0, props[i].name, props[i].min, props[i].max);
+		if (!*props[i].prop)
+			goto out;
+	}
+
+	/* FIXME create special object ID list property type? */
+	prop_connector_ids = drm_property_create(dev, DRM_MODE_PROP_BLOB, "CONNECTOR_IDS", 0);
+	if (!prop_connector_ids)
+		goto out;
+
+	prop_mode = drm_property_create(dev, DRM_MODE_PROP_BLOB, "MODE", 0);
+	if (!prop_mode)
+		goto out;
+
+	return 0;
+
+ out:
+	drm_property_destroy(dev, prop_mode);
+	drm_property_destroy(dev, prop_connector_ids);
+
+	while (i--)
+		drm_property_destroy(dev, *props[i].prop);
+
+	return -ENOMEM; /* FIXME? */
+}
+
+void drm_plane_attach_properties(struct drm_plane *plane)
+{
+	struct drm_mode_object *obj = &plane->base;
+
+	drm_object_attach_property(obj, prop_src_x, 0);
+	drm_object_attach_property(obj, prop_src_y, 0);
+	drm_object_attach_property(obj, prop_src_w, 0);
+	drm_object_attach_property(obj, prop_src_h, 0);
+	drm_object_attach_property(obj, prop_crtc_x, 0);
+	drm_object_attach_property(obj, prop_crtc_y, 0);
+	drm_object_attach_property(obj, prop_crtc_w, 0);
+	drm_object_attach_property(obj, prop_crtc_h, 0);
+	drm_object_attach_property(obj, prop_fb_id, 0);
+	drm_object_attach_property(obj, prop_crtc_id, 0);
+}
+
+void drm_crtc_attach_properties(struct drm_crtc *crtc)
+{
+	struct drm_mode_object *obj = &crtc->base;
+
+	drm_object_attach_property(obj, prop_src_x, 0);
+	drm_object_attach_property(obj, prop_src_y, 0);
+	drm_object_attach_property(obj, prop_fb_id, 0);
+	drm_object_attach_property(obj, prop_mode, 0);
+	drm_object_attach_property(obj, prop_connector_ids, 0);
+}
+
+void intel_crtc_attach_properties(struct drm_crtc *crtc)
+{
+	struct drm_mode_object *obj = &crtc->base;
+
+	drm_crtc_attach_properties(crtc);
+
+	drm_object_attach_property(obj, prop_cursor_id, 0);
+	drm_object_attach_property(obj, prop_cursor_x, 0);
+	drm_object_attach_property(obj, prop_cursor_y, 0);
+	drm_object_attach_property(obj, prop_cursor_w, 0);
+	drm_object_attach_property(obj, prop_cursor_h, 0);
+}
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 5b0789f..1230c1b 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -734,4 +734,7 @@ extern void intel_atomic_clear_flips(struct drm_crtc *crtc);
 extern void intel_enable_primary(struct drm_crtc *crtc);
 extern void intel_disable_primary(struct drm_crtc *crtc);
 
+extern void intel_crtc_attach_properties(struct drm_crtc *crtc);
+extern void intel_crtc_update_properties(struct drm_crtc *crtc);
+
 #endif /* __INTEL_DRV_H__ */
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 897c110..74fb5a8 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1147,4 +1147,16 @@ struct drm_atomic_funcs {
 	void (*end)(struct drm_device *dev, void *state);
 };
 
+extern int drm_mode_create_properties(struct drm_device *dev);
+extern void drm_mode_destroy_properties(struct drm_device *dev);
+
+extern int drm_crtc_create_blobs(struct drm_crtc *crtc);
+extern void drm_crtc_destroy_blobs(struct drm_crtc *crtc);
+
+extern void drm_crtc_attach_properties(struct drm_crtc *crtc);
+extern void drm_plane_attach_properties(struct drm_plane *plane);
+
+extern void drm_crtc_update_properties(struct drm_crtc *crtc);
+extern void drm_plane_update_properties(struct drm_plane *plane);
+
 #endif /* __DRM_CRTC_H__ */
-- 
1.7.8.6



More information about the dri-devel mailing list