All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Clark <robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: "Archit Taneja" <architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	"Rob Clark" <robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Sean Paul" <seanpaul-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	"Daniel Vetter" <daniel-/w4YWyX8dFk@public.gmane.org>,
	freedreno-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	"Ville Syrjälä"
	<ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Subject: [PATCH 2/6] drm: add helper for printing to log or seq_file
Date: Fri, 14 Oct 2016 19:55:49 -0400	[thread overview]
Message-ID: <1476489353-16261-3-git-send-email-robdclark@gmail.com> (raw)
In-Reply-To: <1476489353-16261-1-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

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

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 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

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index e3dba6f..4894ebb 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -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
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
new file mode 100644
index 0000000..ddcb437
--- /dev/null
+++ b/drivers/gpu/drm/drm_print.c
@@ -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 <robdclark@gmail.com>
+ */
+
+#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);
+}
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
new file mode 100644
index 0000000..f294a9a
--- /dev/null
+++ b/include/drm/drm_print.h
@@ -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 <robdclark@gmail.com>
+ */
+
+#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_ */
-- 
2.7.4

_______________________________________________
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno

  parent reply	other threads:[~2016-10-14 23:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14 23:55 [PATCH 0/6] drm: add atomic state logging and debugfs Rob Clark
2016-10-14 23:55 ` [PATCH 4/6] drm/atomic: add new drm_debug bit to dump atomic state before commit Rob Clark
2016-10-17  6:31   ` Daniel Vetter
2016-10-17 17:00   ` Sean Paul
     [not found] ` <1476489353-16261-1-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-14 23:55   ` [PATCH 1/6] drm: helper macros to print composite types Rob Clark
2016-10-17 17:00     ` Sean Paul
2016-10-14 23:55   ` Rob Clark [this message]
2016-10-17  6:38     ` [PATCH 2/6] drm: add helper for printing to log or seq_file Daniel Vetter
2016-10-17 11:59       ` Rob Clark
2016-10-17 12:30         ` Daniel Vetter
2016-10-17 12:35           ` Rob Clark
     [not found]     ` <1476489353-16261-3-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-17 17:00       ` Sean Paul
2016-10-24 17:05         ` Rob Clark
2016-10-14 23:55   ` [PATCH 3/6] drm: add helpers to go from plane state to drm_rect Rob Clark
2016-10-17 17:00     ` Sean Paul
2016-10-14 23:55   ` [PATCH 5/6] drm/atomic: add debugfs file to dump out atomic state Rob Clark
2016-10-17 17:00     ` Sean Paul
2016-10-14 23:55   ` [PATCH 6/6] drm/msm/mdp5: add atomic_print_state support Rob Clark
     [not found]     ` <1476489353-16261-7-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-17 17:00       ` Sean Paul
2016-10-15  0:19 ` [PATCH 0/6] drm: add atomic state logging and debugfs Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476489353-16261-3-git-send-email-robdclark@gmail.com \
    --to=robdclark-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=daniel-/w4YWyX8dFk@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=freedreno-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=seanpaul-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.