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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 14, 2016 at 07:55:49PM -0400, Rob Clark wrote:
> Sometimes it is nice not to duplicate equivalent printk() and
> seq_printf() code.
> 
> Signed-off-by: Rob Clark <robdclark@xxxxxxxxx>

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

> ---
>  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@xxxxxxxxx>
> + */
> +
> +#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@xxxxxxxxx>
> + */
> +
> +#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
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux