/* * 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>
*/
/* Figure out how big the string will be */
len = snprintf(NULL, 0, "%pV", vaf);
/* This is the easiest path, we've already advanced beyond the offset */ if (iterator->offset + len <= iterator->start) {
iterator->offset += len; return;
}
/* Then check if we can directly copy into the target buffer */ if ((iterator->offset >= iterator->start) && (len < iterator->remain)) {
ssize_t pos = iterator->offset - iterator->start;
if (iterator->data)
snprintf(((char *) iterator->data) + pos,
iterator->remain, "%pV", vaf);
iterator->offset += len;
iterator->remain -= len;
return;
}
/* * Finally, hit the slow path and make a temporary string to copy over * using _drm_puts_coredump
*/
buf = kmalloc(len + 1, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); if (!buf) return;
snprintf(buf, len + 1, "%pV", vaf);
__drm_puts_coredump(p, (constchar *) buf);
/** * drm_puts - print a const string to a &drm_printer stream * @p: the &drm printer * @str: const string * * Allow &drm_printer types that have a constant string * option to use it.
*/ void drm_puts(struct drm_printer *p, constchar *str)
{ if (p->puts)
p->puts(p, str); else
drm_printf(p, "%s", str);
}
EXPORT_SYMBOL(drm_puts);
/** * drm_printf - print to a &drm_printer stream * @p: the &drm_printer * @f: format string
*/ void drm_printf(struct drm_printer *p, constchar *f, ...)
{
va_list args;
/** * 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 * @value: field value. * @bits: Array with bit names. * @nbits: Size of bit names array.
*/ void drm_print_bits(struct drm_printer *p, unsignedlong value, constchar * const bits[], unsignedint nbits)
{ bool first = true; unsignedint i;
if (WARN_ON_ONCE(nbits > BITS_PER_TYPE(value)))
nbits = BITS_PER_TYPE(value);
for_each_set_bit(i, &value, nbits) { if (WARN_ON_ONCE(!bits[i])) continue;
drm_printf(p, "%s%s", first ? "" : ",",
bits[i]);
first = false;
} if (first)
drm_printf(p, "(none)");
}
EXPORT_SYMBOL(drm_print_bits);
/** * drm_print_regset32 - print the contents of registers to a * &drm_printer stream. * * @p: the &drm printer * @regset: the list of registers to print. * * Often in driver debug, it's useful to be able to either capture the * contents of registers in the steady state using debugfs or at * specific points during operation. This lets the driver have a * single list of registers for both.
*/ void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset)
{ int namelen = 0; int i;
for (i = 0; i < regset->nregs; i++)
namelen = max(namelen, (int)strlen(regset->regs[i].name));
for (i = 0; i < regset->nregs; i++) {
drm_printf(p, "%*s = 0x%08x\n",
namelen, regset->regs[i].name,
readl(regset->base + regset->regs[i].offset));
}
}
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, constchar *prefix, const u8 *buf, size_t len)
{ int i;
for (i = 0; i < len; i += 16) { int bytes_per_line = min(16, len - i);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.