summaryrefslogtreecommitdiff
path: root/lib/igt_debugfs.c
diff options
context:
space:
mode:
authorPaul Kocialkowski <paul.kocialkowski@linux.intel.com>2017-07-19 16:46:08 +0300
committerLyude <lyude@redhat.com>2017-07-19 12:04:56 -0400
commit34a54192e1fb25041d032d92da59d143afa67464 (patch)
tree201e489f9308d9d87072b68a4fe174568f69352a /lib/igt_debugfs.c
parentee31e0b539c63bb52137f0585605dad3a700a7c0 (diff)
lib/igt_debugfs: Add extended helper to format crc to string
This introduces a igt_crc_to_string_extended helper that allows formatting a crc to a string with a given delimiter and size to print per crc word. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@linux.intel.com> Reviewed-by: Lyude <lyude@redhat.com>
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r--lib/igt_debugfs.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index ef05dc77..2aa33586 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -348,28 +348,47 @@ bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b)
}
/**
- * igt_crc_to_string:
+ * igt_crc_to_string_extended:
* @crc: pipe CRC value to print
+ * @delimiter: The delimiter to use between crc words
+ * @crc_size: the number of bytes to print per crc word (either 4 or 2)
*
- * This function allocates a string and formats @crc into it.
+ * This function allocates a string and formats @crc into it, depending on
+ * @delimiter and @crc_size.
* The caller is responsible for freeing the string.
*
* This should only ever be used for diagnostic debug output.
*/
-char *igt_crc_to_string(igt_crc_t *crc)
+char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size)
{
int i;
char *buf = calloc(128, sizeof(char));
+ const char *format[2] = { "%08x%c", "%04x%c" };
if (!buf)
return NULL;
for (i = 0; i < crc->n_words; i++)
- sprintf(buf + strlen(buf), "%08x ", crc->crc[i]);
+ sprintf(buf + strlen(buf), format[crc_size == 2], crc->crc[i],
+ i == (crc->n_words - 1) ? '\0' : delimiter);
return buf;
}
+/**
+ * igt_crc_to_string:
+ * @crc: pipe CRC value to print
+ *
+ * This function allocates a string and formats @crc into it.
+ * The caller is responsible for freeing the string.
+ *
+ * This should only ever be used for diagnostic debug output.
+ */
+char *igt_crc_to_string(igt_crc_t *crc)
+{
+ return igt_crc_to_string_extended(crc, ' ', 4);
+}
+
#define MAX_CRC_ENTRIES 10
#define MAX_LINE_LEN (10 + 11 * MAX_CRC_ENTRIES + 1)