From: Daniel Vetter <daniel@ffwll.ch>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: dri-devel@lists.freedesktop.org,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <maxime.ripard@bootlin.com>,
Sean Paul <sean@poorly.run>, David Airlie <airlied@linux.ie>,
Daniel Vetter <daniel@ffwll.ch>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/6] drm: add drm_print_bits
Date: Tue, 3 Sep 2019 12:54:36 +0200 [thread overview]
Message-ID: <20190903105436.GU2112@phenom.ffwll.local> (raw)
In-Reply-To: <20190903101248.12879-2-kraxel@redhat.com>
On Tue, Sep 03, 2019 at 12:12:43PM +0200, Gerd Hoffmann wrote:
> New helper to print named bits of some value (think flags fields).
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> include/drm/drm_print.h | 3 +++
> drivers/gpu/drm/drm_print.c | 36 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
> index a5d6f2f3e430..8658c1da1c7d 100644
> --- a/include/drm/drm_print.h
> +++ b/include/drm/drm_print.h
> @@ -88,6 +88,9 @@ __printf(2, 3)
> void drm_printf(struct drm_printer *p, const char *f, ...);
> void drm_puts(struct drm_printer *p, const char *str);
> void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
> +void drm_print_bits(struct drm_printer *p, unsigned int indent,
> + const char *label, unsigned int value,
> + const char *bits[], unsigned int nbits);
>
> __printf(2, 0)
> /**
> diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> index a17c8a14dba4..7f7aba920f51 100644
> --- a/drivers/gpu/drm/drm_print.c
> +++ b/drivers/gpu/drm/drm_print.c
> @@ -179,6 +179,42 @@ void drm_printf(struct drm_printer *p, const char *f, ...)
> }
> EXPORT_SYMBOL(drm_printf);
>
> +/**
> + * drm_print_bits - print bits to a &drm_printer stream
> + *
> + * Print bits (in flag fields for example) in human readable form.
> + *
> + * @p: the &drm_printer
> + * @indent: Tab indentation level (max 5)
> + * @label: field label.
> + * @value: field value.
> + * @bits: Array with bit names.
> + * @nbits: bit name array size.
> + */
> +void drm_print_bits(struct drm_printer *p, unsigned int indent,
> + const char *label, unsigned int value,
> + const char *bits[], unsigned int nbits)
> +{
> + bool first = true;
> + unsigned int i;
> +
> + for (i = 0; i < nbits; i++) {
> + if (!(value & (1 << i)))
> + continue;
> + if (!bits[i])
I think this should be a WARN_ON, indicates a programming error?
> + continue;
> + if (first) {
> + first = false;
> + drm_printf_indent(p, indent, "%s=%s",
> + label, bits[i]);
Hm, to make this a bit more flexible to use I'd drop the label= printing
...
> + } else
> + drm_printf(p, ",%s", bits[i]);
> + }
> + if (!first)
> + drm_printf(p, "\n");
... and also the newline. Then you could also use this for bit-fields
which just a few bits. Also, should we print anything if no bit is set?
If you prefer the label= + \n then pls add that to the kerneldoc, that it
prints this as a line of its own.
-Daniel
> +}
> +EXPORT_SYMBOL(drm_print_bits);
> +
> void drm_dev_printk(const struct device *dev, const char *level,
> const char *format, ...)
> {
> --
> 2.18.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2019-09-03 10:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190903101248.12879-1-kraxel@redhat.com>
2019-09-03 10:12 ` Gerd Hoffmann
2019-09-03 10:54 ` Daniel Vetter [this message]
2019-09-03 10:12 ` [PATCH v2 2/6] drm/ttm: add drm gem ttm helpers, starting with drm_gem_ttm_print_info() Gerd Hoffmann
2019-09-03 10:56 ` Daniel Vetter
2019-09-03 10:12 ` [PATCH v2 3/6] drm/vram: use drm_gem_ttm_print_info Gerd Hoffmann
2019-09-03 10:58 ` Daniel Vetter
2019-09-03 10:12 ` [PATCH v2 4/6] drm/vram: add vram-mm debugfs file Gerd Hoffmann
2019-09-03 10:12 ` [PATCH v2 5/6] drm/qxl: use drm_gem_object_funcs callbacks Gerd Hoffmann
2019-09-03 10:12 ` [PATCH v2 6/6] drm/qxl: use drm_gem_ttm_print_info Gerd Hoffmann
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=20190903105436.GU2112@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=maxime.ripard@bootlin.com \
--cc=sean@poorly.run \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®