Skip to contentSkip to conversation

drm: add atomic state logging and debugfs

PATCH In review Rob Clark 5 participants 20 messages Oct 14, 2016 – Oct 24, 2016 3 messages not in the archive

Subsystems (8)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

cover drm: add atomic state logging and debugfs

Bit more spiffed out version of the RFC. Now with Sean's suggestion to add vfuncs in plane/crtc/connector funcs for drivers that subclass the various state structs. Plus Ville's suggestion about helper macros for printing mode/rect structs (and alignment with how drm_rect printed the integer and fixed-point rects). Plus addition of connector state and debugfs.

Rob Clark (6):
drm: helper macros to print composite types
drm: add helper for printing to log or seq_file
drm: add helpers to go from plane state to drm_rect drm/atomic: add new drm_debug bit to dump atomic state before commit drm/atomic: add debugfs file to dump out atomic state drm/msm/mdp5: add atomic_print_state support

 drivers/gpu/drm/Makefile                    |   3 +-
 drivers/gpu/drm/drm_atomic.c                | 133 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_debugfs.c               |   9 ++
 drivers/gpu/drm/drm_modes.c                 |   8 +-
 drivers/gpu/drm/drm_print.c                 |  54 +++++++++++
 drivers/gpu/drm/drm_rect.c                  |  11 +--
 drivers/gpu/drm/drm_simple_kms_helper.c     |  14 +--
 drivers/gpu/drm/i915/intel_atomic_plane.c   |  10 +--
 drivers/gpu/drm/mediatek/mtk_drm_plane.c    |  15 +---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h     |  12 +++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   |  18 +++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c |  10 +--
 include/drm/drmP.h                          |  22 +++++
 include/drm/drm_atomic.h                    |   4 +
 include/drm/drm_crtc.h                      |  61 +++++++++++++
 include/drm/drm_print.h                     |  62 +++++++++++++
 16 files changed, 387 insertions(+), 59 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
author
#2 lore raw

PATCH 1/6 drm: helper macros to print composite types

In reply to a message not in the archive

I'll want to print things in a similar way in a later patch. This will make it easier.

TODO drm_rect_debug_print() doesn't have many call sites, and is kind of unnecessary now. Should we just drop it?

---
 drivers/gpu/drm/drm_modes.c |  8 +-------
 drivers/gpu/drm/drm_rect.c  | 11 ++---------
 include/drm/drmP.h          | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_modes.c +1 -7
index fc5040a..77b0301 100644
@@ -49,13 +49,7 @@
  */
 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode)
 {
-	DRM_DEBUG_KMS("Modeline %d:\"%s\" %d %d %d %d %d %d %d %d %d %d "
-			"0x%x 0x%x\n",
-		mode->base.id, mode->name, mode->vrefresh, mode->clock,
-		mode->hdisplay, mode->hsync_start,
-		mode->hsync_end, mode->htotal,
-		mode->vdisplay, mode->vsync_start,
-		mode->vsync_end, mode->vtotal, mode->type, mode->flags);
+	DRM_DEBUG_KMS("Modeline " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
 }
 EXPORT_SYMBOL(drm_mode_debug_printmodeline);
 
drivers/gpu/drm/drm_rect.c +2 -9
index a8e2c86..d451112 100644
@@ -281,17 +281,10 @@ EXPORT_SYMBOL(drm_rect_calc_vscale_relaxed);
  */
 void drm_rect_debug_print(const char *prefix, const struct drm_rect *r, bool fixed_point)
 {
-	int w = drm_rect_width(r);
-	int h = drm_rect_height(r);
-
 	if (fixed_point)
-		DRM_DEBUG_KMS("%s%d.%06ux%d.%06u%+d.%06u%+d.%06u\n", prefix,
-			      w >> 16, ((w & 0xffff) * 15625) >> 10,
-			      h >> 16, ((h & 0xffff) * 15625) >> 10,
-			      r->x1 >> 16, ((r->x1 & 0xffff) * 15625) >> 10,
-			      r->y1 >> 16, ((r->y1 & 0xffff) * 15625) >> 10);
+		DRM_DEBUG_KMS("%s" DRM_RECT_FP_FMT "\n", prefix, DRM_RECT_FP_ARG(r));
 	else
-		DRM_DEBUG_KMS("%s%dx%d%+d%+d\n", prefix, w, h, r->x1, r->y1);
+		DRM_DEBUG_KMS("%s" DRM_RECT_FMT "\n", prefix, DRM_RECT_ARG(r));
 }
 EXPORT_SYMBOL(drm_rect_debug_print);
 
include/drm/drmP.h +21 -0
index 28d341a..7ffaa35 100644
@@ -231,6 +231,27 @@ void drm_err(const char *format, ...);
 			drm_ut_debug_printk(__func__, fmt, ##args);	\
 	} while (0)
 
+/* Format strings and argument splitters to simplify printing
+ * various "complex" objects
+ */
+#define DRM_MODE_FMT    "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
+#define DRM_MODE_ARG(m) \
+	(m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
+	(m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
+	(m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
+	(m)->type, (m)->flags
+
+#define DRM_RECT_FMT    "%dx%d%+d%+d"
+#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
+
+/* for rect's in fixed-point format: */
+#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
+#define DRM_RECT_FP_ARG(r) \
+		drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
+		drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
+		(r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
+		(r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
+
 /*@}*/
 
 /***********************************************************************/
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
author
#4 lore raw

PATCH 2/6 drm: add helper for printing to log or seq_file

In reply to a message not in the archive

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
 		drm_info.o drm_debugfs.o drm_encoder_slave.o \
 		drm_trace_points.o drm_global.o drm_prime.o \
 		drm_rect.o drm_vma_manager.o drm_flip_work.o \
-		drm_modeset_lock.o drm_atomic.o drm_bridge.o
+		drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+		drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +54 -0

54 lines not on this page · raw message

include/drm/drm_print.h new file +62 -0

62 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
author
#12 lore raw

PATCH 3/6 drm: add helpers to go from plane state to drm_rect

In reply to a message not in the archive
---
 drivers/gpu/drm/drm_simple_kms_helper.c     | 14 ++------------
 drivers/gpu/drm/i915/intel_atomic_plane.c   | 10 ++--------
 drivers/gpu/drm/mediatek/mtk_drm_plane.c    | 15 ++-------------
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 10 ++--------
 include/drm/drm_crtc.h                      | 24 ++++++++++++++++++++++++
 5 files changed, 32 insertions(+), 41 deletions(-)
drivers/gpu/drm/drm_simple_kms_helper.c +2 -12
index 0db36d2..9834fc5 100644
@@ -73,18 +73,8 @@ static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = {
 static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
 					struct drm_plane_state *plane_state)
 {
-	struct drm_rect src = {
-		.x1 = plane_state->src_x,
-		.y1 = plane_state->src_y,
-		.x2 = plane_state->src_x + plane_state->src_w,
-		.y2 = plane_state->src_y + plane_state->src_h,
-	};
-	struct drm_rect dest = {
-		.x1 = plane_state->crtc_x,
-		.y1 = plane_state->crtc_y,
-		.x2 = plane_state->crtc_x + plane_state->crtc_w,
-		.y2 = plane_state->crtc_y + plane_state->crtc_h,
-	};
+	struct drm_rect src = drm_plane_state_src(plane_state);
+	struct drm_rect dest = drm_plane_state_dest(plane_state);
 	struct drm_rect clip = { 0 };
 	struct drm_simple_display_pipe *pipe;
 	struct drm_crtc_state *crtc_state;
drivers/gpu/drm/i915/intel_atomic_plane.c +2 -8
index 7de7721..6682e9b 100644
@@ -139,14 +139,8 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
 	 * we want to keep another copy internal to our driver that we can
 	 * clip/modify ourselves.
 	 */
-	intel_state->src.x1 = state->src_x;
-	intel_state->src.y1 = state->src_y;
-	intel_state->src.x2 = state->src_x + state->src_w;
-	intel_state->src.y2 = state->src_y + state->src_h;
-	intel_state->dst.x1 = state->crtc_x;
-	intel_state->dst.y1 = state->crtc_y;
-	intel_state->dst.x2 = state->crtc_x + state->crtc_w;
-	intel_state->dst.y2 = state->crtc_y + state->crtc_h;
+	intel_state->src = drm_plane_state_src(state);
+	intel_state->dst = drm_plane_state_dest(state);
 
 	/* Clip all planes to CRTC size, or 0x0 if CRTC is disabled */
 	intel_state->clip.x1 = 0;
drivers/gpu/drm/mediatek/mtk_drm_plane.c +2 -13
index 3995765..2749e74 100644
@@ -135,19 +135,8 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
 	struct drm_framebuffer *fb = state->fb;
 	struct drm_crtc_state *crtc_state;
 	bool visible;
-	struct drm_rect dest = {
-		.x1 = state->crtc_x,
-		.y1 = state->crtc_y,
-		.x2 = state->crtc_x + state->crtc_w,
-		.y2 = state->crtc_y + state->crtc_h,
-	};
-	struct drm_rect src = {
-		/* 16.16 fixed point */
-		.x1 = state->src_x,
-		.y1 = state->src_y,
-		.x2 = state->src_x + state->src_w,
-		.y2 = state->src_y + state->src_h,
-	};
+	struct drm_rect dest = drm_plane_state_dest(state);
+	struct drm_rect src  = drm_plane_state_src(state);  /* 16.16 fixed point */
 	struct drm_rect clip = { 0, };
 
 	if (!fb)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +2 -8
index 6255e5b..31384ca 100644
@@ -610,14 +610,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
 	if (WARN_ON(!crtc_state))
 		return -EINVAL;
 
-	src->x1 = state->src_x;
-	src->y1 = state->src_y;
-	src->x2 = state->src_x + state->src_w;
-	src->y2 = state->src_y + state->src_h;
-	dest->x1 = state->crtc_x;
-	dest->y1 = state->crtc_y;
-	dest->x2 = state->crtc_x + state->crtc_w;
-	dest->y2 = state->crtc_y + state->crtc_h;
+	*src  = drm_plane_state_src(state);
+	*dest = drm_plane_state_dest(state);
 
 	clip.x1 = 0;
 	clip.y1 = 0;
include/drm/drm_crtc.h +24 -0
index b7d67cc..856fdf8 100644
@@ -36,6 +36,7 @@
 #include <uapi/drm/drm_mode.h>
 #include <uapi/drm/drm_fourcc.h>
 #include <drm/drm_modeset_lock.h>
+#include <drm/drm_rect.h>
 
 struct drm_device;
 struct drm_mode_set;
@@ -1395,6 +1396,29 @@ struct drm_plane_state {
 	struct drm_atomic_state *state;
 };
 
+static inline struct drm_rect
+drm_plane_state_src(const struct drm_plane_state *state)
+{
+	struct drm_rect src = {
+		.x1 = state->src_x,
+		.y1 = state->src_y,
+		.x2 = state->src_x + state->src_w,
+		.y2 = state->src_y + state->src_h,
+	};
+	return src;
+}
+
+static inline struct drm_rect
+drm_plane_state_dest(const struct drm_plane_state *state)
+{
+	struct drm_rect dest = {
+		.x1 = state->crtc_x,
+		.y1 = state->crtc_y,
+		.x2 = state->crtc_x + state->crtc_w,
+		.y2 = state->crtc_y + state->crtc_h,
+	};
+	return dest;
+}
 
 /**
  * struct drm_plane_funcs - driver plane control functions
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
#19 lore raw

PATCH 4/6 drm/atomic: add new drm_debug bit to dump atomic state before commit

In reply to Rob Clark
---
 drivers/gpu/drm/drm_atomic.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h           |  1 +
 include/drm/drm_crtc.h       | 37 ++++++++++++++++++
 3 files changed, 131 insertions(+)
drivers/gpu/drm/drm_atomic.c +93 -0
index 7ebf375..3cc3cb5 100644
@@ -30,6 +30,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_mode.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_print.h>
 #include <linux/sync_file.h>
 
 #include "drm_crtc_internal.h"
@@ -608,6 +609,28 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
 	return 0;
 }
 
+static void drm_atomic_crtc_print_state(struct drm_print *p,
+		const struct drm_crtc_state *state)
+{
+	struct drm_crtc *crtc = state->crtc;
+
+	drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name);
+	drm_printf(p, "\tenable=%d\n", state->enable);
+	drm_printf(p, "\tactive=%d\n", state->active);
+	drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
+	drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
+	drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
+	drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
+	drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
+	drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
+	drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
+	drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
+	drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
+
+	if (crtc->funcs->atomic_print_state)
+		crtc->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_get_plane_state - get plane state
  * @state: global atomic state object
@@ -895,6 +918,38 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
 	return 0;
 }
 
+static void drm_atomic_plane_print_state(struct drm_print *p,
+		const struct drm_plane_state *state)
+{
+	struct drm_plane *plane = state->plane;
+	struct drm_rect src  = drm_plane_state_src(state);
+	struct drm_rect dest = drm_plane_state_dest(state);
+
+	drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name);
+	drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
+	drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
+	if (state->fb) {
+		struct drm_framebuffer *fb = state->fb;
+		int i, n = drm_format_num_planes(fb->pixel_format);
+
+		drm_printf(p, "\t\tformat=%s\n",
+				drm_get_format_name(fb->pixel_format));
+		drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
+		drm_printf(p, "\t\tlayers:\n");
+		for (i = 0; i < n; i++) {
+			drm_printf(p, "\t\t\tpitch[%d]=%u\n", i, fb->pitches[i]);
+			drm_printf(p, "\t\t\toffset[%d]=%u\n", i, fb->offsets[i]);
+			drm_printf(p, "\t\t\tmodifier[%d]=0x%llx\n", i, fb->modifier[i]);
+		}
+	}
+	drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest));
+	drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src));
+	drm_printf(p, "\trotation=%x\n", state->rotation);
+
+	if (plane->funcs->atomic_print_state)
+		plane->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_get_connector_state - get connector state
  * @state: global atomic state object
@@ -1010,6 +1065,18 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_atomic_connector_set_property);
 
+static void drm_atomic_connector_print_state(struct drm_print *p,
+		const struct drm_connector_state *state)
+{
+	struct drm_connector *connector = state->connector;
+
+	drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name);
+	drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
+
+	if (connector->funcs->atomic_print_state)
+		connector->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_connector_get_property - get property value from connector state
  * @connector: the drm connector to set a property on
@@ -1475,6 +1542,29 @@ int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
 }
 EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
 
+static void drm_atomic_print_state(const struct drm_atomic_state *state)
+{
+	struct drm_print p = drm_print_info();
+	struct drm_plane *plane;
+	struct drm_plane_state *plane_state;
+	struct drm_crtc *crtc;
+	struct drm_crtc_state *crtc_state;
+	struct drm_connector *connector;
+	struct drm_connector_state *connector_state;
+	int i;
+
+	DRM_DEBUG_ATOMIC("checking %p\n", state);
+
+	for_each_plane_in_state(state, plane, plane_state, i)
+		drm_atomic_plane_print_state(&p, plane_state);
+
+	for_each_crtc_in_state(state, crtc, crtc_state, i)
+		drm_atomic_crtc_print_state(&p, crtc_state);
+
+	for_each_connector_in_state(state, connector, connector_state, i)
+		drm_atomic_connector_print_state(&p, connector_state);
+}
+
 /*
  * The big monstor ioctl
  */
@@ -1987,6 +2077,9 @@ retry:
 		 */
 		ret = drm_atomic_check_only(state);
 	} else {
+		if (unlikely(drm_debug & DRM_UT_STATE))
+			drm_atomic_print_state(state);
+
 		if (arg->flags & DRM_MODE_ATOMIC_OUT_FENCE)
 			install_out_fence(state, arg->count_out_fences,
 					  fence_state);
include/drm/drmP.h +1 -0
index 7ffaa35..642d5da 100644
@@ -133,6 +133,7 @@ struct dma_buf_attachment;
 #define DRM_UT_PRIME		0x08
 #define DRM_UT_ATOMIC		0x10
 #define DRM_UT_VBL		0x20
+#define DRM_UT_STATE		0x40
 
 extern __printf(2, 3)
 void drm_ut_debug_printk(const char *function_name,
include/drm/drm_crtc.h +37 -0
index 856fdf8..d74d47a 100644
@@ -44,6 +44,7 @@ struct drm_framebuffer;
 struct drm_object_properties;
 struct drm_file;
 struct drm_clip_rect;
+struct drm_print;
 struct device_node;
 struct fence;
 struct edid;
@@ -707,6 +708,18 @@ struct drm_crtc_funcs {
 				   const struct drm_crtc_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_crtc_state, it should implement
+	 * this optional hook for printing state.
+	 *
+	 * Do not call this directly, use drm_atomic_crtc_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_crtc_state *state);
 };
 
 /**
@@ -1132,6 +1145,18 @@ struct drm_connector_funcs {
 				   const struct drm_connector_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_connector_state, it should
+	 * implement this optional hook for printing state.
+	 *
+	 * Do not call this directly, use drm_atomic_connector_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_connector_state *state);
 };
 
 /**
@@ -1623,6 +1648,18 @@ struct drm_plane_funcs {
 				   const struct drm_plane_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_plane_state, it should implement
+	 * this optional hook for printing state.
+	 *
+	 * Do not call this directly, use drm_atomic_plane_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_plane_state *state);
 };
 
 enum drm_plane_type {
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#14 lore raw

PATCH 5/6 drm/atomic: add debugfs file to dump out atomic state

In reply to a message not in the archive
---
 drivers/gpu/drm/drm_atomic.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_debugfs.c |  9 +++++++++
 include/drm/drm_atomic.h      |  4 ++++
 3 files changed, 53 insertions(+)
drivers/gpu/drm/drm_atomic.c +40 -0
index 3cc3cb5..117d429 100644
@@ -1565,6 +1565,46 @@ static void drm_atomic_print_state(const struct drm_atomic_state *state)
 		drm_atomic_connector_print_state(&p, connector_state);
 }
 
+#ifdef CONFIG_DEBUG_FS
+static int drm_state_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = (struct drm_info_node *) m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_mode_config *config = &dev->mode_config;
+	struct drm_plane *plane;
+	struct drm_crtc *crtc;
+	struct drm_connector *connector;
+	struct drm_print p = drm_print_seq_file(m);
+
+	drm_modeset_lock_all(dev);
+
+	list_for_each_entry(plane, &config->plane_list, head)
+		drm_atomic_plane_print_state(&p, plane->state);
+
+	list_for_each_entry(crtc, &config->crtc_list, head)
+		drm_atomic_crtc_print_state(&p, crtc->state);
+
+	list_for_each_entry(connector, &config->connector_list, head)
+		drm_atomic_connector_print_state(&p, connector->state);
+
+	drm_modeset_unlock_all(dev);
+
+	return 0;
+}
+
+/* any use in debugfs files to dump individual planes/crtc/etc? */
+static const struct drm_info_list drm_atomic_debugfs_list[] = {
+	{"state", drm_state_info, 0},
+};
+
+int drm_atomic_debugfs_init(struct drm_minor *minor)
+{
+	return drm_debugfs_create_files(drm_atomic_debugfs_list,
+			ARRAY_SIZE(drm_atomic_debugfs_list),
+			minor->debugfs_root, minor);
+}
+#endif
+
 /*
  * The big monstor ioctl
  */
drivers/gpu/drm/drm_debugfs.c +9 -0
index fa10cef..d8945a9 100644
@@ -36,6 +36,7 @@
 #include <linux/export.h>
 #include <drm/drmP.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_atomic.h>
 #include "drm_internal.h"
 
 #if defined(CONFIG_DEBUG_FS)
@@ -163,6 +164,14 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		return ret;
 	}
 
+	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
+		ret = drm_atomic_debugfs_init(minor);
+		if (ret) {
+			DRM_ERROR("Failed to create atomic debugfs files\n");
+			return ret;
+		}
+	}
+
 	if (dev->driver->debugfs_init) {
 		ret = dev->driver->debugfs_init(minor);
 		if (ret) {
include/drm/drm_atomic.h +4 -0
index 856a9c8..68422f6 100644
@@ -181,6 +181,10 @@ int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
 
+#ifdef CONFIG_DEBUG_FS
+int drm_atomic_debugfs_init(struct drm_minor *minor);
+#endif
+
 #define for_each_connector_in_state(__state, connector, connector_state, __i) \
 	for ((__i) = 0;							\
 	     (__i) < (__state)->num_connector &&				\
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
author
#16 lore raw

PATCH 6/6 drm/msm/mdp5: add atomic_print_state support

In reply to a message not in the archive

We subclass drm_plane_state, so add mdp5_plane_atomic_print_state() to dump out our own driver specific plane state.

---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h   | 12 ++++++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c | 18 +++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h +12 -0
index e4b3fb3..3502711 100644
@@ -120,6 +120,18 @@ static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
 	return msm_readl(mdp5_kms->mmio + reg);
 }
 
+static inline const char *stage2name(enum mdp_mixer_stage_id stage)
+{
+	static const char *names[] = {
+#define NAME(n) [n] = #n
+		NAME(STAGE_UNUSED), NAME(STAGE_BASE),
+		NAME(STAGE0), NAME(STAGE1), NAME(STAGE2),
+		NAME(STAGE3), NAME(STAGE4), NAME(STAGE6),
+#undef NAME
+	};
+	return names[stage];
+}
+
 static inline const char *pipe2name(enum mdp5_pipe pipe)
 {
 	static const char *names[] = {
drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c +17 -1
index b6f1fc66..9f99b4d 100644
@@ -16,6 +16,7 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <drm/drm_print.h>
 #include "mdp5_kms.h"
 
 struct mdp5_plane {
@@ -187,6 +188,20 @@ done:
 #undef SET_PROPERTY
 }
 
+static void
+mdp5_plane_atomic_print_state(struct drm_print *p,
+		const struct drm_plane_state *state)
+{
+	struct mdp5_plane_state *pstate = to_mdp5_plane_state(state);
+
+	drm_printf(p, "\tpremultiplied=%u\n", pstate->premultiplied);
+	drm_printf(p, "\tzpos=%u\n", pstate->zpos);
+	drm_printf(p, "\talpha=%u\n", pstate->alpha);
+	drm_printf(p, "\tstage=%s\n", stage2name(pstate->stage));
+	drm_printf(p, "\tmode_changed=%u\n", pstate->mode_changed);
+	drm_printf(p, "\tpending=%u\n", pstate->pending);
+}
+
 static void mdp5_plane_reset(struct drm_plane *plane)
 {
 	struct mdp5_plane_state *mdp5_state;
@@ -250,6 +265,7 @@ static const struct drm_plane_funcs mdp5_plane_funcs = {
 		.reset = mdp5_plane_reset,
 		.atomic_duplicate_state = mdp5_plane_duplicate_state,
 		.atomic_destroy_state = mdp5_plane_destroy_state,
+		.atomic_print_state = mdp5_plane_atomic_print_state,
 };
 
 static int mdp5_plane_prepare_fb(struct drm_plane *plane,
@@ -907,7 +923,7 @@ struct drm_plane *mdp5_plane_init(struct drm_device *dev,
 	type = private_plane ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY;
 	ret = drm_universal_plane_init(dev, plane, 0xff, &mdp5_plane_funcs,
 				 mdp5_plane->formats, mdp5_plane->nformats,
-				 type, NULL);
+				 type, "%s", mdp5_plane->name);
 	if (ret)
 		goto fail;
 
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
#22 lore raw
In reply to Rob Clark
Quoted 6 lines · Rob Clark

Bit more spiffed out version of the RFC. Now with Sean's suggestion to add vfuncs in plane/crtc/connector funcs for drivers that subclass the various state structs. Plus Ville's suggestion about helper macros for printing mode/rect structs (and alignment with how drm_rect printed the integer and fixed-point rects). Plus addition of connector state and debugfs.

and jfyi, full state dump now looks like this:

--------
plane[24]: RGB0

    crtc=crtc-0
    fb=52
        format=XB24 little-endian (0x34324258)
        size=2048x1152
        layers:
            pitch[0]=8192
            offset[0]=0
            modifier[0]=0x0
    crtc-pos=2048x1152+0+0
    src-pos=2048.000000x1152.000000+0.000000+0.000000
    rotation=0
    premultiplied=0
    zpos=1
    alpha=255
    stage=STAGE_BASE
    mode_changed=0
    pending=0
plane[29]: RGB1
    crtc=(null)
    fb=0
    crtc-pos=0x0+0+0
    src-pos=0.000000x0.000000+0.000000+0.000000
    rotation=0
    premultiplied=0
    zpos=1
    alpha=255
    stage=STAGE_UNUSED
    mode_changed=0
    pending=0
plane[31]: VIG0
    crtc=(null)
    fb=0
    crtc-pos=0x0+0+0
    src-pos=0.000000x0.000000+0.000000+0.000000
    rotation=0
    premultiplied=0
    zpos=4
    alpha=255
    stage=STAGE_UNUSED
    mode_changed=0
    pending=0
plane[32]: DMA0
    crtc=(null)
    fb=0
    crtc-pos=0x0+0+0
    src-pos=0.000000x0.000000+0.000000+0.000000
    rotation=0
    premultiplied=0
    zpos=5
    alpha=255
    stage=STAGE_UNUSED
    mode_changed=0
    pending=0
crtc[28]: crtc-0
    enable=1
    active=1
    planes_changed=1
    mode_changed=0
    active_changed=0
    connectors_changed=0
    color_mgmt_changed=0
    plane_mask=1
    connector_mask=1
    encoder_mask=1
    mode: 0:"2048x1152" 60 156750 2048 2096 2128 2208 1152 1155 1160
1185 0x48 0x9
crtc[30]: crtc-1
    enable=0
    active=0
    planes_changed=0
    mode_changed=0
    active_changed=0
    connectors_changed=0
    color_mgmt_changed=0
    plane_mask=0
    connector_mask=0
    encoder_mask=0
    mode: 0:"" 0 0 0 0 0 0 0 0 0 0 0x0 0x0
connector[35]: HDMI-A-1
    crtc=crtc-0

--------

I've added fb parameters, which was another suggestion

BR,
-R

Quoted 28 lines

Rob Clark (6):
drm: helper macros to print composite types
drm: add helper for printing to log or seq_file
drm: add helpers to go from plane state to drm_rect drm/atomic: add new drm_debug bit to dump atomic state before commit drm/atomic: add debugfs file to dump out atomic state drm/msm/mdp5: add atomic_print_state support

 drivers/gpu/drm/Makefile                    |   3 +-
 drivers/gpu/drm/drm_atomic.c                | 133 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_debugfs.c               |   9 ++
 drivers/gpu/drm/drm_modes.c                 |   8 +-
 drivers/gpu/drm/drm_print.c                 |  54 +++++++++++
 drivers/gpu/drm/drm_rect.c                  |  11 +--
 drivers/gpu/drm/drm_simple_kms_helper.c     |  14 +--
 drivers/gpu/drm/i915/intel_atomic_plane.c   |  10 +--
 drivers/gpu/drm/mediatek/mtk_drm_plane.c    |  15 +---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h     |  12 +++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   |  18 +++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c |  10 +--
 include/drm/drmP.h                          |  22 +++++
 include/drm/drm_atomic.h                    |   4 +
 include/drm/drm_crtc.h                      |  61 +++++++++++++
 include/drm/drm_print.h                     |  62 +++++++++++++
 16 files changed, 387 insertions(+), 59 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
Quoted 3 lines

--
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw

Re: [PATCH 4/6] drm/atomic: add new drm_debug bit to dump atomic state before commit

In reply to Rob Clark
Quoted 1 line · Rob Clark

General comment: Some drivers (and I think this would be useful in general) also dump state into debugfs with seq_file. And we have a bunch of other places where unfortunately we duplicate dumping functions between dmesg and seq_file (e.g. drm_mm.c).

Fancy idea: Could we create a seq_file that dumps to dmesg and so reuse one for all? Before we have to add atomic_print_state and atomic_dump_state for dmesg vs. seq_file variations ...

One kerneldoc nit below.

Quoted 25 lines
include/drm/drmP.h +1 -0
index 7ffaa35..642d5da 100644
@@ -133,6 +133,7 @@ struct dma_buf_attachment;
 #define DRM_UT_PRIME		0x08
 #define DRM_UT_ATOMIC		0x10
 #define DRM_UT_VBL		0x20
+#define DRM_UT_STATE		0x40
 
 extern __printf(2, 3)
 void drm_ut_debug_printk(const char *function_name,
include/drm/drm_crtc.h +1 -0
index 856fdf8..d74d47a 100644
@@ -44,6 +44,7 @@ struct drm_framebuffer;
 struct drm_object_properties;
 struct drm_file;
 struct drm_clip_rect;
+struct drm_print;
 struct device_node;
 struct fence;
 struct edid;

include/drm/drm_crtc.h struct drm_crtc_funcs { · line 716

Quoted 9 lines
include/drm/drm_crtc.h +6 -0
@@ -707,6 +708,18 @@ struct drm_crtc_funcs {
 				   const struct drm_crtc_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_crtc_state, it should implement
+	 * this optional hook for printing state.

s/printing state/printing additional, driver-private state/ in all of these for clarification. Same below.
-Daniel

Quoted 50 lines
include/drm/drm_crtc.h +30 -0
+	 *
+	 * Do not call this directly, use drm_atomic_crtc_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_crtc_state *state);
 };
 
 /**
@@ -1132,6 +1145,18 @@ struct drm_connector_funcs {
 				   const struct drm_connector_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_connector_state, it should
+	 * implement this optional hook for printing state.
+	 *
+	 * Do not call this directly, use drm_atomic_connector_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_connector_state *state);
 };
 
 /**
@@ -1623,6 +1648,18 @@ struct drm_plane_funcs {
 				   const struct drm_plane_state *state,
 				   struct drm_property *property,
 				   uint64_t *val);
+
+	/**
+	 * @atomic_print_state:
+	 *
+	 * If driver subclasses struct &drm_plane_state, it should implement
+	 * this optional hook for printing state.
+	 *
+	 * Do not call this directly, use drm_atomic_plane_print_state()
+	 * instead.
+	 */
+	void (*atomic_print_state)(struct drm_print *p,
+				   const struct drm_plane_state *state);
 };
 
 enum drm_plane_type {
Signature · 1 line
2.7.4
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

In reply to Rob Clark
Quoted 4 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

Ok, maybe I should wait for coffee to kick in before commenting on patches ;-)

Two bits:
- kerneldoc for this pls, plus pulling into drm-internals.rst.
- Would be awesome to de-dupe the existing dumping code in drm_mm.c with this.

-Daniel

Quoted 153 lines
---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
 		drm_info.o drm_debugfs.o drm_encoder_slave.o \
 		drm_trace_points.o drm_global.o drm_prime.o \
 		drm_rect.o drm_vma_manager.o drm_flip_work.o \
-		drm_modeset_lock.o drm_atomic.o drm_bridge.o
+		drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+		drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +54 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+	seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{
+	const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+	char fmt[strlen(hdr) + strlen(f) + 1];
+
+	memcpy(fmt, hdr, strlen(hdr));
+	memcpy(fmt + strlen(hdr), f, strlen(f));
+	fmt[strlen(hdr) + strlen(f)] = 0;
+
+	vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+	va_list args;
+
+	va_start(args, f);
+	p->printfn(p, f, args);
+	va_end(args);
+}
include/drm/drm_print.h new file +62 -0
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */
+struct drm_print {
+	void (*printfn)(struct drm_print *p, const char *f, va_list args);
+	void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+	struct drm_print p = {
+		.printfn = __drm_printfn_seq_file,
+		.arg = f,
+	};
+	return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+	struct drm_print p = {
+		.printfn = __drm_printfn_info,
+	};
+	return p;
+}
+
+#endif /* DRM_PRINT_H_ */
Signature · 1 line
2.7.4
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

Quoted 6 lines · Daniel Vetter
Quoted 4 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

Quoted 7 lines

Ok, maybe I should wait for coffee to kick in before commenting on patches ;-)

Two bits:
- kerneldoc for this pls, plus pulling into drm-internals.rst.
- Would be awesome to de-dupe the existing dumping code in drm_mm.c with this.

I have a couple things in drm/msm that I want to de-dup.. and I guess most drivers probably do as well..

I'm toying with the idea to convert drm_info_list::show over to take a drm_print ptr instead of seq_file, then we could just re-use the debugfs fxns directly without having extra wrappers fxns.. question is best way to do that in a non-flag-day way..

BR,
-R

Quoted 152 lines

-Daniel

Quoted 150 lines
---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=      drm_auth.o drm_bufs.o drm_cache.o \
              drm_info.o drm_debugfs.o drm_encoder_slave.o \
              drm_trace_points.o drm_global.o drm_prime.o \
              drm_rect.o drm_vma_manager.o drm_flip_work.o \
-             drm_modeset_lock.o drm_atomic.o drm_bridge.o
+             drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+             drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +54 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+     seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{
+     const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+     char fmt[strlen(hdr) + strlen(f) + 1];
+
+     memcpy(fmt, hdr, strlen(hdr));
+     memcpy(fmt + strlen(hdr), f, strlen(f));
+     fmt[strlen(hdr) + strlen(f)] = 0;
+
+     vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+     va_list args;
+
+     va_start(args, f);
+     p->printfn(p, f, args);
+     va_end(args);
+}
include/drm/drm_print.h new file +62 -0
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */
+struct drm_print {
+     void (*printfn)(struct drm_print *p, const char *f, va_list args);
+     void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_seq_file,
+             .arg = f,
+     };
+     return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_info,
+     };
+     return p;
+}
+
+#endif /* DRM_PRINT_H_ */
Quoted 8 lines
Quoted 3 lines

--
2.7.4

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

Quoted 15 lines · Rob Clark
Quoted 6 lines · Daniel Vetter
Quoted 4 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

Quoted 7 lines

Ok, maybe I should wait for coffee to kick in before commenting on patches ;-)

Two bits:
- kerneldoc for this pls, plus pulling into drm-internals.rst.
- Would be awesome to de-dupe the existing dumping code in drm_mm.c with this.

Quoted 7 lines

I have a couple things in drm/msm that I want to de-dup.. and I guess most drivers probably do as well..

I'm toying with the idea to convert drm_info_list::show over to take a drm_print ptr instead of seq_file, then we could just re-use the debugfs fxns directly without having extra wrappers fxns.. question is best way to do that in a non-flag-day way..

One idea I had in the other reply is to create a seq_file which can dump to debugfs. Not sure how feasible that is ...
-Daniel

Quoted 164 lines

BR,
-R

Quoted 160 lines

-Daniel

Quoted 151 lines
---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=      drm_auth.o drm_bufs.o drm_cache.o \
              drm_info.o drm_debugfs.o drm_encoder_slave.o \
              drm_trace_points.o drm_global.o drm_prime.o \
              drm_rect.o drm_vma_manager.o drm_flip_work.o \
-             drm_modeset_lock.o drm_atomic.o drm_bridge.o
+             drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+             drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +54 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+     seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{
+     const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+     char fmt[strlen(hdr) + strlen(f) + 1];
+
+     memcpy(fmt, hdr, strlen(hdr));
+     memcpy(fmt + strlen(hdr), f, strlen(f));
+     fmt[strlen(hdr) + strlen(f)] = 0;
+
+     vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+     va_list args;
+
+     va_start(args, f);
+     p->printfn(p, f, args);
+     va_end(args);
+}
include/drm/drm_print.h new file +62 -1
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */
+struct drm_print {
+     void (*printfn)(struct drm_print *p, const char *f, va_list args);
+     void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_seq_file,
+             .arg = f,
+     };
+     return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_info,
+     };
+     return p;
+}
+
+#endif /* DRM_PRINT_H_ */
--
Quoted 2 lines

2.7.4

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

Quoted 19 lines · Daniel Vetter
Quoted 18 lines · Rob Clark
Quoted 6 lines · Daniel Vetter
Quoted 4 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

Quoted 7 lines

Ok, maybe I should wait for coffee to kick in before commenting on patches ;-)

Two bits:
- kerneldoc for this pls, plus pulling into drm-internals.rst.
- Would be awesome to de-dupe the existing dumping code in drm_mm.c with this.

I have a couple things in drm/msm that I want to de-dup.. and I guess most drivers probably do as well..

Quoted 7 lines
Quoted 4 lines

I'm toying with the idea to convert drm_info_list::show over to take a drm_print ptr instead of seq_file, then we could just re-use the debugfs fxns directly without having extra wrappers fxns.. question is best way to do that in a non-flag-day way..

One idea I had in the other reply is to create a seq_file which can dump to debugfs. Not sure how feasible that is ...

that was my first approach.. but seq_file carries a lot of baggage..

BR,
-R

Quoted 167 lines

-Daniel

Quoted 164 lines

BR,
-R

Quoted 160 lines

-Daniel

Quoted 151 lines
---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=      drm_auth.o drm_bufs.o drm_cache.o \
              drm_info.o drm_debugfs.o drm_encoder_slave.o \
              drm_trace_points.o drm_global.o drm_prime.o \
              drm_rect.o drm_vma_manager.o drm_flip_work.o \
-             drm_modeset_lock.o drm_atomic.o drm_bridge.o
+             drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+             drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +54 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+     seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{
+     const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+     char fmt[strlen(hdr) + strlen(f) + 1];
+
+     memcpy(fmt, hdr, strlen(hdr));
+     memcpy(fmt + strlen(hdr), f, strlen(f));
+     fmt[strlen(hdr) + strlen(f)] = 0;
+
+     vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+     va_list args;
+
+     va_start(args, f);
+     p->printfn(p, f, args);
+     va_end(args);
+}
include/drm/drm_print.h new file +62 -1
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */
+struct drm_print {
+     void (*printfn)(struct drm_print *p, const char *f, va_list args);
+     void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_seq_file,
+             .arg = f,
+     };
+     return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+     struct drm_print p = {
+             .printfn = __drm_printfn_info,
+     };
+     return p;
+}
+
+#endif /* DRM_PRINT_H_ */
--
Quoted 2 lines

2.7.4

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

Quoted 4 lines

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

In reply to a message not in the archive
Quoted 58 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=        drm_auth.o drm_bufs.o drm_cache.o \
                drm_info.o drm_debugfs.o drm_encoder_slave.o \
                drm_trace_points.o drm_global.o drm_prime.o \
                drm_rect.o drm_vma_manager.o drm_flip_work.o \
-               drm_modeset_lock.o drm_atomic.o drm_bridge.o
+               drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+               drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +26 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>

drivers/gpu/drm/drm_print.c line 36

Quoted 10 lines
drivers/gpu/drm/drm_print.c new file +10 -0
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+       seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{

I think you can re-use drm_printk here:

drm_printk(KERN_INFO, DRM_UT_NONE, f, args)

Quoted 58 lines
drivers/gpu/drm/drm_print.c new file +18 -0
+       const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+       char fmt[strlen(hdr) + strlen(f) + 1];
+
+       memcpy(fmt, hdr, strlen(hdr));
+       memcpy(fmt + strlen(hdr), f, strlen(f));
+       fmt[strlen(hdr) + strlen(f)] = 0;
+
+       vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+       va_list args;
+
+       va_start(args, f);
+       p->printfn(p, f, args);
+       va_end(args);
+}
include/drm/drm_print.h new file +34 -0
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */

include/drm/drm_print.h line 44

Quoted 10 lines
include/drm/drm_print.h new file +10 -0
+struct drm_print {
+       void (*printfn)(struct drm_print *p, const char *f, va_list args);
+       void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+

Is it worthwhile making _dev_ variants now?

Sean

Quoted 19 lines
include/drm/drm_print.h new file +18 -1
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+       struct drm_print p = {
+               .printfn = __drm_printfn_seq_file,
+               .arg = f,
+       };
+       return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+       struct drm_print p = {
+               .printfn = __drm_printfn_info,
+       };
+       return p;
+}
+
+#endif /* DRM_PRINT_H_ */
--
Quoted 2 lines

2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] drm: helper macros to print composite types

In reply to Rob Clark
Quoted 3 lines · Rob Clark

I'll want to print things in a similar way in a later patch. This will make it easier.

Quoted 3 lines

TODO drm_rect_debug_print() doesn't have many call sites, and is kind of unnecessary now. Should we just drop it?

yeah, seems like you could get the same info from the state dumps.

Quoted 83 lines
---
 drivers/gpu/drm/drm_modes.c |  8 +-------
 drivers/gpu/drm/drm_rect.c  | 11 ++---------
 include/drm/drmP.h          | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_modes.c +1 -7
index fc5040a..77b0301 100644
@@ -49,13 +49,7 @@
  */
 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode)
 {
-       DRM_DEBUG_KMS("Modeline %d:\"%s\" %d %d %d %d %d %d %d %d %d %d "
-                       "0x%x 0x%x\n",
-               mode->base.id, mode->name, mode->vrefresh, mode->clock,
-               mode->hdisplay, mode->hsync_start,
-               mode->hsync_end, mode->htotal,
-               mode->vdisplay, mode->vsync_start,
-               mode->vsync_end, mode->vtotal, mode->type, mode->flags);
+       DRM_DEBUG_KMS("Modeline " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
 }
 EXPORT_SYMBOL(drm_mode_debug_printmodeline);
 
drivers/gpu/drm/drm_rect.c +2 -9
index a8e2c86..d451112 100644
@@ -281,17 +281,10 @@ EXPORT_SYMBOL(drm_rect_calc_vscale_relaxed);
  */
 void drm_rect_debug_print(const char *prefix, const struct drm_rect *r, bool fixed_point)
 {
-       int w = drm_rect_width(r);
-       int h = drm_rect_height(r);
-
        if (fixed_point)
-               DRM_DEBUG_KMS("%s%d.%06ux%d.%06u%+d.%06u%+d.%06u\n", prefix,
-                             w >> 16, ((w & 0xffff) * 15625) >> 10,
-                             h >> 16, ((h & 0xffff) * 15625) >> 10,
-                             r->x1 >> 16, ((r->x1 & 0xffff) * 15625) >> 10,
-                             r->y1 >> 16, ((r->y1 & 0xffff) * 15625) >> 10);
+               DRM_DEBUG_KMS("%s" DRM_RECT_FP_FMT "\n", prefix, DRM_RECT_FP_ARG(r));
        else
-               DRM_DEBUG_KMS("%s%dx%d%+d%+d\n", prefix, w, h, r->x1, r->y1);
+               DRM_DEBUG_KMS("%s" DRM_RECT_FMT "\n", prefix, DRM_RECT_ARG(r));
 }
 EXPORT_SYMBOL(drm_rect_debug_print);
 
include/drm/drmP.h +21 -1
index 28d341a..7ffaa35 100644
@@ -231,6 +231,27 @@ void drm_err(const char *format, ...);
                        drm_ut_debug_printk(__func__, fmt, ##args);     \
        } while (0)
 
+/* Format strings and argument splitters to simplify printing
+ * various "complex" objects
+ */
+#define DRM_MODE_FMT    "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
+#define DRM_MODE_ARG(m) \
+       (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
+       (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
+       (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
+       (m)->type, (m)->flags
+
+#define DRM_RECT_FMT    "%dx%d%+d%+d"
+#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
+
+/* for rect's in fixed-point format: */
+#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
+#define DRM_RECT_FP_ARG(r) \
+               drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
+               drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
+               (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
+               (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
+
 /*@}*/
 
 /***********************************************************************/
--
Quoted 2 lines

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#18 lore raw

Re: [PATCH 6/6] drm/msm/mdp5: add atomic_print_state support

In reply to a message not in the archive
Quoted 3 lines · Rob Clark

We subclass drm_plane_state, so add mdp5_plane_atomic_print_state() to dump out our own driver specific plane state.

Quoted 80 lines
---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h   | 12 ++++++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c | 18 +++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h +12 -0
index e4b3fb3..3502711 100644
@@ -120,6 +120,18 @@ static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
        return msm_readl(mdp5_kms->mmio + reg);
 }
 
+static inline const char *stage2name(enum mdp_mixer_stage_id stage)
+{
+       static const char *names[] = {
+#define NAME(n) [n] = #n
+               NAME(STAGE_UNUSED), NAME(STAGE_BASE),
+               NAME(STAGE0), NAME(STAGE1), NAME(STAGE2),
+               NAME(STAGE3), NAME(STAGE4), NAME(STAGE6),
+#undef NAME
+       };
+       return names[stage];
+}
+
 static inline const char *pipe2name(enum mdp5_pipe pipe)
 {
        static const char *names[] = {
drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c +17 -2
index b6f1fc66..9f99b4d 100644
@@ -16,6 +16,7 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <drm/drm_print.h>
 #include "mdp5_kms.h"
 
 struct mdp5_plane {
@@ -187,6 +188,20 @@ done:
 #undef SET_PROPERTY
 }
 
+static void
+mdp5_plane_atomic_print_state(struct drm_print *p,
+               const struct drm_plane_state *state)
+{
+       struct mdp5_plane_state *pstate = to_mdp5_plane_state(state);
+
+       drm_printf(p, "\tpremultiplied=%u\n", pstate->premultiplied);
+       drm_printf(p, "\tzpos=%u\n", pstate->zpos);
+       drm_printf(p, "\talpha=%u\n", pstate->alpha);
+       drm_printf(p, "\tstage=%s\n", stage2name(pstate->stage));
+       drm_printf(p, "\tmode_changed=%u\n", pstate->mode_changed);
+       drm_printf(p, "\tpending=%u\n", pstate->pending);
+}
+
 static void mdp5_plane_reset(struct drm_plane *plane)
 {
        struct mdp5_plane_state *mdp5_state;
@@ -250,6 +265,7 @@ static const struct drm_plane_funcs mdp5_plane_funcs = {
                .reset = mdp5_plane_reset,
                .atomic_duplicate_state = mdp5_plane_duplicate_state,
                .atomic_destroy_state = mdp5_plane_destroy_state,
+               .atomic_print_state = mdp5_plane_atomic_print_state,
 };
 
 static int mdp5_plane_prepare_fb(struct drm_plane *plane,
@@ -907,7 +923,7 @@ struct drm_plane *mdp5_plane_init(struct drm_device *dev,
        type = private_plane ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY;
        ret = drm_universal_plane_init(dev, plane, 0xff, &mdp5_plane_funcs,
                                 mdp5_plane->formats, mdp5_plane->nformats,
-                                type, NULL);
+                                type, "%s", mdp5_plane->name);
        if (ret)
                goto fail;
 
--
Quoted 2 lines

2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

Reviewed-by on v1 3/6
#13 lore raw

Re: [PATCH 3/6] drm: add helpers to go from plane state to drm_rect

In reply to Rob Clark

On Fri, Oct 14, 2016 at 7:55 PM, Rob Clark <[email protected]> wrote:

Quoted 145 lines
---
 drivers/gpu/drm/drm_simple_kms_helper.c     | 14 ++------------
 drivers/gpu/drm/i915/intel_atomic_plane.c   | 10 ++--------
 drivers/gpu/drm/mediatek/mtk_drm_plane.c    | 15 ++-------------
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 10 ++--------
 include/drm/drm_crtc.h                      | 24 ++++++++++++++++++++++++
 5 files changed, 32 insertions(+), 41 deletions(-)
drivers/gpu/drm/drm_simple_kms_helper.c +2 -12
index 0db36d2..9834fc5 100644
@@ -73,18 +73,8 @@ static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = {
 static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
                                        struct drm_plane_state *plane_state)
 {
-       struct drm_rect src = {
-               .x1 = plane_state->src_x,
-               .y1 = plane_state->src_y,
-               .x2 = plane_state->src_x + plane_state->src_w,
-               .y2 = plane_state->src_y + plane_state->src_h,
-       };
-       struct drm_rect dest = {
-               .x1 = plane_state->crtc_x,
-               .y1 = plane_state->crtc_y,
-               .x2 = plane_state->crtc_x + plane_state->crtc_w,
-               .y2 = plane_state->crtc_y + plane_state->crtc_h,
-       };
+       struct drm_rect src = drm_plane_state_src(plane_state);
+       struct drm_rect dest = drm_plane_state_dest(plane_state);
        struct drm_rect clip = { 0 };
        struct drm_simple_display_pipe *pipe;
        struct drm_crtc_state *crtc_state;
drivers/gpu/drm/i915/intel_atomic_plane.c +2 -8
index 7de7721..6682e9b 100644
@@ -139,14 +139,8 @@ static int intel_plane_atomic_check(struct drm_plane *plane,
         * we want to keep another copy internal to our driver that we can
         * clip/modify ourselves.
         */
-       intel_state->src.x1 = state->src_x;
-       intel_state->src.y1 = state->src_y;
-       intel_state->src.x2 = state->src_x + state->src_w;
-       intel_state->src.y2 = state->src_y + state->src_h;
-       intel_state->dst.x1 = state->crtc_x;
-       intel_state->dst.y1 = state->crtc_y;
-       intel_state->dst.x2 = state->crtc_x + state->crtc_w;
-       intel_state->dst.y2 = state->crtc_y + state->crtc_h;
+       intel_state->src = drm_plane_state_src(state);
+       intel_state->dst = drm_plane_state_dest(state);
 
        /* Clip all planes to CRTC size, or 0x0 if CRTC is disabled */
        intel_state->clip.x1 = 0;
drivers/gpu/drm/mediatek/mtk_drm_plane.c +2 -13
index 3995765..2749e74 100644
@@ -135,19 +135,8 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
        struct drm_framebuffer *fb = state->fb;
        struct drm_crtc_state *crtc_state;
        bool visible;
-       struct drm_rect dest = {
-               .x1 = state->crtc_x,
-               .y1 = state->crtc_y,
-               .x2 = state->crtc_x + state->crtc_w,
-               .y2 = state->crtc_y + state->crtc_h,
-       };
-       struct drm_rect src = {
-               /* 16.16 fixed point */
-               .x1 = state->src_x,
-               .y1 = state->src_y,
-               .x2 = state->src_x + state->src_w,
-               .y2 = state->src_y + state->src_h,
-       };
+       struct drm_rect dest = drm_plane_state_dest(state);
+       struct drm_rect src  = drm_plane_state_src(state);  /* 16.16 fixed point */
        struct drm_rect clip = { 0, };
 
        if (!fb)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +2 -8
index 6255e5b..31384ca 100644
@@ -610,14 +610,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
        if (WARN_ON(!crtc_state))
                return -EINVAL;
 
-       src->x1 = state->src_x;
-       src->y1 = state->src_y;
-       src->x2 = state->src_x + state->src_w;
-       src->y2 = state->src_y + state->src_h;
-       dest->x1 = state->crtc_x;
-       dest->y1 = state->crtc_y;
-       dest->x2 = state->crtc_x + state->crtc_w;
-       dest->y2 = state->crtc_y + state->crtc_h;
+       *src  = drm_plane_state_src(state);
+       *dest = drm_plane_state_dest(state);
 
        clip.x1 = 0;
        clip.y1 = 0;
include/drm/drm_crtc.h +24 -1
index b7d67cc..856fdf8 100644
@@ -36,6 +36,7 @@
 #include <uapi/drm/drm_mode.h>
 #include <uapi/drm/drm_fourcc.h>
 #include <drm/drm_modeset_lock.h>
+#include <drm/drm_rect.h>
 
 struct drm_device;
 struct drm_mode_set;
@@ -1395,6 +1396,29 @@ struct drm_plane_state {
        struct drm_atomic_state *state;
 };
 
+static inline struct drm_rect
+drm_plane_state_src(const struct drm_plane_state *state)
+{
+       struct drm_rect src = {
+               .x1 = state->src_x,
+               .y1 = state->src_y,
+               .x2 = state->src_x + state->src_w,
+               .y2 = state->src_y + state->src_h,
+       };
+       return src;
+}
+
+static inline struct drm_rect
+drm_plane_state_dest(const struct drm_plane_state *state)
+{
+       struct drm_rect dest = {
+               .x1 = state->crtc_x,
+               .y1 = state->crtc_y,
+               .x2 = state->crtc_x + state->crtc_w,
+               .y2 = state->crtc_y + state->crtc_h,
+       };
+       return dest;
+}
 
 /**
  * struct drm_plane_funcs - driver plane control functions
--
Quoted 2 lines

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

Re: [PATCH 4/6] drm/atomic: add new drm_debug bit to dump atomic state before commit

In reply to Rob Clark

On Fri, Oct 14, 2016 at 7:55 PM, Rob Clark <[email protected]> wrote:

Could you add a commit message detailing what and when the state is dumped?

Quoted 173 lines
---
 drivers/gpu/drm/drm_atomic.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h           |  1 +
 include/drm/drm_crtc.h       | 37 ++++++++++++++++++
 3 files changed, 131 insertions(+)
drivers/gpu/drm/drm_atomic.c +93 -0
index 7ebf375..3cc3cb5 100644
@@ -30,6 +30,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_mode.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_print.h>
 #include <linux/sync_file.h>
 
 #include "drm_crtc_internal.h"
@@ -608,6 +609,28 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
        return 0;
 }
 
+static void drm_atomic_crtc_print_state(struct drm_print *p,
+               const struct drm_crtc_state *state)
+{
+       struct drm_crtc *crtc = state->crtc;
+
+       drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name);
+       drm_printf(p, "\tenable=%d\n", state->enable);
+       drm_printf(p, "\tactive=%d\n", state->active);
+       drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
+       drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
+       drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
+       drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
+       drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
+       drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
+       drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
+       drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
+       drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
+
+       if (crtc->funcs->atomic_print_state)
+               crtc->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_get_plane_state - get plane state
  * @state: global atomic state object
@@ -895,6 +918,38 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
        return 0;
 }
 
+static void drm_atomic_plane_print_state(struct drm_print *p,
+               const struct drm_plane_state *state)
+{
+       struct drm_plane *plane = state->plane;
+       struct drm_rect src  = drm_plane_state_src(state);
+       struct drm_rect dest = drm_plane_state_dest(state);
+
+       drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name);
+       drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
+       drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
+       if (state->fb) {
+               struct drm_framebuffer *fb = state->fb;
+               int i, n = drm_format_num_planes(fb->pixel_format);
+
+               drm_printf(p, "\t\tformat=%s\n",
+                               drm_get_format_name(fb->pixel_format));
+               drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
+               drm_printf(p, "\t\tlayers:\n");
+               for (i = 0; i < n; i++) {
+                       drm_printf(p, "\t\t\tpitch[%d]=%u\n", i, fb->pitches[i]);
+                       drm_printf(p, "\t\t\toffset[%d]=%u\n", i, fb->offsets[i]);
+                       drm_printf(p, "\t\t\tmodifier[%d]=0x%llx\n", i, fb->modifier[i]);
+               }
+       }
+       drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest));
+       drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src));
+       drm_printf(p, "\trotation=%x\n", state->rotation);
+
+       if (plane->funcs->atomic_print_state)
+               plane->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_get_connector_state - get connector state
  * @state: global atomic state object
@@ -1010,6 +1065,18 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_atomic_connector_set_property);
 
+static void drm_atomic_connector_print_state(struct drm_print *p,
+               const struct drm_connector_state *state)
+{
+       struct drm_connector *connector = state->connector;
+
+       drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name);
+       drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
+
+       if (connector->funcs->atomic_print_state)
+               connector->funcs->atomic_print_state(p, state);
+}
+
 /**
  * drm_atomic_connector_get_property - get property value from connector state
  * @connector: the drm connector to set a property on
@@ -1475,6 +1542,29 @@ int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
 }
 EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
 
+static void drm_atomic_print_state(const struct drm_atomic_state *state)
+{
+       struct drm_print p = drm_print_info();
+       struct drm_plane *plane;
+       struct drm_plane_state *plane_state;
+       struct drm_crtc *crtc;
+       struct drm_crtc_state *crtc_state;
+       struct drm_connector *connector;
+       struct drm_connector_state *connector_state;
+       int i;
+
+       DRM_DEBUG_ATOMIC("checking %p\n", state);
+
+       for_each_plane_in_state(state, plane, plane_state, i)
+               drm_atomic_plane_print_state(&p, plane_state);
+
+       for_each_crtc_in_state(state, crtc, crtc_state, i)
+               drm_atomic_crtc_print_state(&p, crtc_state);
+
+       for_each_connector_in_state(state, connector, connector_state, i)
+               drm_atomic_connector_print_state(&p, connector_state);
+}
+
 /*
  * The big monstor ioctl
  */
@@ -1987,6 +2077,9 @@ retry:
                 */
                ret = drm_atomic_check_only(state);
        } else {
+               if (unlikely(drm_debug & DRM_UT_STATE))
+                       drm_atomic_print_state(state);
+
                if (arg->flags & DRM_MODE_ATOMIC_OUT_FENCE)
                        install_out_fence(state, arg->count_out_fences,
                                          fence_state);
include/drm/drmP.h +1 -0
index 7ffaa35..642d5da 100644
@@ -133,6 +133,7 @@ struct dma_buf_attachment;
 #define DRM_UT_PRIME           0x08
 #define DRM_UT_ATOMIC          0x10
 #define DRM_UT_VBL             0x20
+#define DRM_UT_STATE           0x40
 
 extern __printf(2, 3)
 void drm_ut_debug_printk(const char *function_name,
include/drm/drm_crtc.h +1 -0
index 856fdf8..d74d47a 100644
@@ -44,6 +44,7 @@ struct drm_framebuffer;
 struct drm_object_properties;
 struct drm_file;
 struct drm_clip_rect;
+struct drm_print;
 struct device_node;
 struct fence;
 struct edid;
@@ -707,6 +708,18 @@ struct drm_crtc_funcs {
                                   const struct drm_crtc_state *state,
                                   struct drm_property *property,

include/drm/drm_crtc.h struct drm_crtc_funcs { · line 719

Quoted 10 lines
include/drm/drm_crtc.h +9 -0
                                   uint64_t *val);
+
+       /**
+        * @atomic_print_state:
+        *
+        * If driver subclasses struct &drm_crtc_state, it should implement
+        * this optional hook for printing state.
+        *
+        * Do not call this directly, use drm_atomic_crtc_print_state()
+        * instead.

These "Do not call this directory, use X instead" messages are somewhat misleading, since X is a static function in drm_atomic.c

Perhaps you should export drm_atomic_print_state?

Sean

Quoted 45 lines
include/drm/drm_crtc.h +27 -1
+        */
+       void (*atomic_print_state)(struct drm_print *p,
+                                  const struct drm_crtc_state *state);
 };
 
 /**
@@ -1132,6 +1145,18 @@ struct drm_connector_funcs {
                                   const struct drm_connector_state *state,
                                   struct drm_property *property,
                                   uint64_t *val);
+
+       /**
+        * @atomic_print_state:
+        *
+        * If driver subclasses struct &drm_connector_state, it should
+        * implement this optional hook for printing state.
+        *
+        * Do not call this directly, use drm_atomic_connector_print_state()
+        * instead.
+        */
+       void (*atomic_print_state)(struct drm_print *p,
+                                  const struct drm_connector_state *state);
 };
 
 /**
@@ -1623,6 +1648,18 @@ struct drm_plane_funcs {
                                   const struct drm_plane_state *state,
                                   struct drm_property *property,
                                   uint64_t *val);
+
+       /**
+        * @atomic_print_state:
+        *
+        * If driver subclasses struct &drm_plane_state, it should implement
+        * this optional hook for printing state.
+        *
+        * Do not call this directly, use drm_atomic_plane_print_state()
+        * instead.
+        */
+       void (*atomic_print_state)(struct drm_print *p,
+                                  const struct drm_plane_state *state);
 };
 
 enum drm_plane_type {
--
Quoted 2 lines

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 5/6
#15 lore raw

Re: [PATCH 5/6] drm/atomic: add debugfs file to dump out atomic state

In reply to Rob Clark

On Fri, Oct 14, 2016 at 7:55 PM, Rob Clark <[email protected]> wrote:

A short commit message detailing the change and info printed would probably be helpful.

Aside from that,

Quoted 101 lines
---
 drivers/gpu/drm/drm_atomic.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_debugfs.c |  9 +++++++++
 include/drm/drm_atomic.h      |  4 ++++
 3 files changed, 53 insertions(+)
drivers/gpu/drm/drm_atomic.c +40 -0
index 3cc3cb5..117d429 100644
@@ -1565,6 +1565,46 @@ static void drm_atomic_print_state(const struct drm_atomic_state *state)
                drm_atomic_connector_print_state(&p, connector_state);
 }
 
+#ifdef CONFIG_DEBUG_FS
+static int drm_state_info(struct seq_file *m, void *data)
+{
+       struct drm_info_node *node = (struct drm_info_node *) m->private;
+       struct drm_device *dev = node->minor->dev;
+       struct drm_mode_config *config = &dev->mode_config;
+       struct drm_plane *plane;
+       struct drm_crtc *crtc;
+       struct drm_connector *connector;
+       struct drm_print p = drm_print_seq_file(m);
+
+       drm_modeset_lock_all(dev);
+
+       list_for_each_entry(plane, &config->plane_list, head)
+               drm_atomic_plane_print_state(&p, plane->state);
+
+       list_for_each_entry(crtc, &config->crtc_list, head)
+               drm_atomic_crtc_print_state(&p, crtc->state);
+
+       list_for_each_entry(connector, &config->connector_list, head)
+               drm_atomic_connector_print_state(&p, connector->state);
+
+       drm_modeset_unlock_all(dev);
+
+       return 0;
+}
+
+/* any use in debugfs files to dump individual planes/crtc/etc? */
+static const struct drm_info_list drm_atomic_debugfs_list[] = {
+       {"state", drm_state_info, 0},
+};
+
+int drm_atomic_debugfs_init(struct drm_minor *minor)
+{
+       return drm_debugfs_create_files(drm_atomic_debugfs_list,
+                       ARRAY_SIZE(drm_atomic_debugfs_list),
+                       minor->debugfs_root, minor);
+}
+#endif
+
 /*
  * The big monstor ioctl
  */
drivers/gpu/drm/drm_debugfs.c +9 -0
index fa10cef..d8945a9 100644
@@ -36,6 +36,7 @@
 #include <linux/export.h>
 #include <drm/drmP.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_atomic.h>
 #include "drm_internal.h"
 
 #if defined(CONFIG_DEBUG_FS)
@@ -163,6 +164,14 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
                return ret;
        }
 
+       if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
+               ret = drm_atomic_debugfs_init(minor);
+               if (ret) {
+                       DRM_ERROR("Failed to create atomic debugfs files\n");
+                       return ret;
+               }
+       }
+
        if (dev->driver->debugfs_init) {
                ret = dev->driver->debugfs_init(minor);
                if (ret) {
include/drm/drm_atomic.h +4 -1
index 856a9c8..68422f6 100644
@@ -181,6 +181,10 @@ int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
 
+#ifdef CONFIG_DEBUG_FS
+int drm_atomic_debugfs_init(struct drm_minor *minor);
+#endif
+
 #define for_each_connector_in_state(__state, connector, connector_state, __i) \
        for ((__i) = 0;                                                 \
             (__i) < (__state)->num_connector &&                                \
--
Quoted 2 lines

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

Re: [PATCH 2/6] drm: add helper for printing to log or seq_file

In reply to Sean Paul
Quoted 72 lines · Sean Paul
Quoted 58 lines · Rob Clark

Sometimes it is nice not to duplicate equivalent printk() and seq_printf() code.

---
 drivers/gpu/drm/Makefile    |  3 ++-
 drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_print.h     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_print.c
 create mode 100644 include/drm/drm_print.h
drivers/gpu/drm/Makefile +2 -1
index e3dba6f..4894ebb 100644
@@ -12,7 +12,8 @@ drm-y       :=        drm_auth.o drm_bufs.o drm_cache.o \
                drm_info.o drm_debugfs.o drm_encoder_slave.o \
                drm_trace_points.o drm_global.o drm_prime.o \
                drm_rect.o drm_vma_manager.o drm_flip_work.o \
-               drm_modeset_lock.o drm_atomic.o drm_bridge.o
+               drm_modeset_lock.o drm_atomic.o drm_bridge.o \
+               drm_print.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_print.c new file +26 -0
new file mode 100644
index 0000000..ddcb437
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#include <linux/seq_file.h>

drivers/gpu/drm/drm_print.c line 36

Quoted 10 lines
drivers/gpu/drm/drm_print.c new file +10 -0
+#include <drm/drmP.h>
+#include <drm/drm_print.h>
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
+{
+       seq_vprintf(p->arg, f, args);
+}
+
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
+{

I think you can re-use drm_printk here:

Quoted 1 line

drm_printk(KERN_INFO, DRM_UT_NONE, f, args)

fwiw, I looked at drm_printk().. but kinda don't want the fxn name in the output. However the va_format trick is neat. I think I'll use that plus dev_printk().

BR,
-R

Quoted 88 lines
Quoted 59 lines
drivers/gpu/drm/drm_print.c new file +18 -0
+       const char *hdr = KERN_INFO "[" DRM_NAME "] ";
+       char fmt[strlen(hdr) + strlen(f) + 1];
+
+       memcpy(fmt, hdr, strlen(hdr));
+       memcpy(fmt + strlen(hdr), f, strlen(f));
+       fmt[strlen(hdr) + strlen(f)] = 0;
+
+       vprintk(fmt, args);
+}
+
+void drm_printf(struct drm_print *p, const char *f, ...)
+{
+       va_list args;
+
+       va_start(args, f);
+       p->printfn(p, f, args);
+       va_end(args);
+}
include/drm/drm_print.h new file +34 -0
new file mode 100644
index 0000000..f294a9a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rob Clark <[email protected]>
+ */
+
+#ifndef DRM_PRINT_H_
+#define DRM_PRINT_H_
+
+#include <stdarg.h>
+#include <linux/seq_file.h>
+
+/* A simple wrapper to abstract seq_file vs printk, so same logging code
+ * does not have to be duplicated.
+ */

include/drm/drm_print.h line 44

Quoted 10 lines
include/drm/drm_print.h new file +10 -0
+struct drm_print {
+       void (*printfn)(struct drm_print *p, const char *f, va_list args);
+       void *arg;
+};
+
+void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
+void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
+
+void drm_printf(struct drm_print *p, const char *f, ...);
+

Is it worthwhile making _dev_ variants now?

Sean

Quoted 13 lines
include/drm/drm_print.h new file +13 -0
+static inline struct drm_print drm_print_seq_file(struct seq_file *f)
+{
+       struct drm_print p = {
+               .printfn = __drm_printfn_seq_file,
+               .arg = f,
+       };
+       return p;
+}
+
+static inline struct drm_print drm_print_info(void)
+{
+       struct drm_print p = {
+               .printfn = __drm_printfn_info,
Quoted 8 lines
Quoted 8 lines
include/drm/drm_print.h new file +5 -1
+       };
+       return p;
+}
+
+#endif /* DRM_PRINT_H_ */
--

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel