Message ID | f650fe1ed3e3bb74760426fa7461c3b028d661fb.1733392101.git.jani.nikula@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | drm: add drm_printer based hex dumper and use it | expand |
Hi Jani, On Thu, Dec 05, 2024 at 11:49:33AM +0200, Jani Nikula wrote: > Add a helper to print a hex dump to a struct drm_printer. There's no > fancy formatting stuff, just 16 space-separated bytes per line, with an > optional prefix. > > Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Thanks, Andi
On Thu, 05 Dec 2024, Jani Nikula <jani.nikula@intel.com> wrote: > Add a helper to print a hex dump to a struct drm_printer. There's no > fancy formatting stuff, just 16 space-separated bytes per line, with an > optional prefix. drm-misc maintainers, ack for merging this via drm-intel-next? BR, Jani. > > Signed-off-by: Jani Nikula <jani.nikula@intel.com> > --- > drivers/gpu/drm/drm_print.c | 23 +++++++++++++++++++++++ > include/drm/drm_print.h | 2 ++ > 2 files changed, 25 insertions(+) > > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c > index 08cfea04e22b..79517bd4418f 100644 > --- a/drivers/gpu/drm/drm_print.c > +++ b/drivers/gpu/drm/drm_print.c > @@ -390,3 +390,26 @@ void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset) > } > } > EXPORT_SYMBOL(drm_print_regset32); > + > +/** > + * drm_print_hex_dump - print a hex dump to a &drm_printer stream > + * @p: The &drm_printer > + * @prefix: Prefix for each line, may be NULL for no prefix > + * @buf: Buffer to dump > + * @len: Length of buffer > + * > + * Print hex dump to &drm_printer, with 16 space-separated hex bytes per line, > + * optionally with a prefix on each line. No separator is added after prefix. > + */ > +void drm_print_hex_dump(struct drm_printer *p, const char *prefix, > + const u8 *buf, size_t len) > +{ > + int i; > + > + for (i = 0; i < len; i += 16) { > + int bytes_per_line = min(16, len - i); > + > + drm_printf(p, "%s%*ph\n", prefix ?: "", bytes_per_line, buf + i); > + } > +} > +EXPORT_SYMBOL(drm_print_hex_dump); > diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h > index b3906dc04388..f77fe1531cf8 100644 > --- a/include/drm/drm_print.h > +++ b/include/drm/drm_print.h > @@ -199,6 +199,8 @@ 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 long value, > const char * const bits[], unsigned int nbits); > +void drm_print_hex_dump(struct drm_printer *p, const char *prefix, > + const u8 *buf, size_t len); > > __printf(2, 0) > /**
On Thu, 05 Dec 2024, Andi Shyti <andi.shyti@linux.intel.com> wrote: > Hi Jani, > > On Thu, Dec 05, 2024 at 11:49:33AM +0200, Jani Nikula wrote: >> Add a helper to print a hex dump to a struct drm_printer. There's no >> fancy formatting stuff, just 16 space-separated bytes per line, with an >> optional prefix. >> >> Signed-off-by: Jani Nikula <jani.nikula@intel.com> > > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Thanks for the review, pushed the series to drm-intel-next with Thomas' IRC ack on patch 1. BR, Jani. > > Thanks, > Andi
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index 08cfea04e22b..79517bd4418f 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -390,3 +390,26 @@ void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset) } } EXPORT_SYMBOL(drm_print_regset32); + +/** + * drm_print_hex_dump - print a hex dump to a &drm_printer stream + * @p: The &drm_printer + * @prefix: Prefix for each line, may be NULL for no prefix + * @buf: Buffer to dump + * @len: Length of buffer + * + * Print hex dump to &drm_printer, with 16 space-separated hex bytes per line, + * optionally with a prefix on each line. No separator is added after prefix. + */ +void drm_print_hex_dump(struct drm_printer *p, const char *prefix, + const u8 *buf, size_t len) +{ + int i; + + for (i = 0; i < len; i += 16) { + int bytes_per_line = min(16, len - i); + + drm_printf(p, "%s%*ph\n", prefix ?: "", bytes_per_line, buf + i); + } +} +EXPORT_SYMBOL(drm_print_hex_dump); diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index b3906dc04388..f77fe1531cf8 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -199,6 +199,8 @@ 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 long value, const char * const bits[], unsigned int nbits); +void drm_print_hex_dump(struct drm_printer *p, const char *prefix, + const u8 *buf, size_t len); __printf(2, 0) /**
Add a helper to print a hex dump to a struct drm_printer. There's no fancy formatting stuff, just 16 space-separated bytes per line, with an optional prefix. Signed-off-by: Jani Nikula <jani.nikula@intel.com> --- drivers/gpu/drm/drm_print.c | 23 +++++++++++++++++++++++ include/drm/drm_print.h | 2 ++ 2 files changed, 25 insertions(+)