Skip to contentSkip to conversation

intel_reg_dumper: Add a single register decode mode

PATCH In review Damien Lespiau 3 participants 6 messages Sep 3, 2012 – Sep 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 intel_reg_dumper: Add a single register decode mode

From: Damien Lespiau <[email protected]>

Quoted 1 line

From time to time, one would like to decode a register value that have

been captured at a certain point in time (and say printed out with a printk). intel_reg_dumper has all the knowledge to do that and this patch adds a way to ask it to decode a value.

Example usage:

$ ./tools/intel_reg_dumper PCH_PP_CONTROL 0xabcd0002
       PCH_PP_CONTROL: 0xabcd0002 (blacklight disabled, power...

v2: friendlier invocation (Chris Wilson)
v3: remove unecessary casts and use strcasecmp (Jani Nikula)

---
 tools/intel_reg_dumper.c |   97 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 84 insertions(+), 13 deletions(-)
tools/intel_reg_dumper.c +84 -13
index 7564cae..cc68985 100644
@@ -1911,26 +1911,31 @@ static struct reg_debug i945gm_mi_regs[] = {
 	DEFINEREG(ECOSKPD),
 };
 
+static void
+_intel_dump_reg(struct reg_debug *reg, uint32_t val)
+{
+	char debug[1024];
+
+	if (reg->debug_output != NULL) {
+		reg->debug_output(debug, sizeof(debug), reg->reg, val);
+		printf("%30.30s: 0x%08x (%s)\n",
+		       reg->name, val, debug);
+	} else {
+		printf("%30.30s: 0x%08x\n", reg->name, val);
+	}
+}
+
 #define intel_dump_regs(regs) _intel_dump_regs(regs, ARRAY_SIZE(regs))
 
 static void
 _intel_dump_regs(struct reg_debug *regs, int count)
 {
-	char debug[1024];
 	int i;
 
 	for (i = 0; i < count; i++) {
 		uint32_t val = INREG(regs[i].reg);
 
-		if (regs[i].debug_output != NULL) {
-			regs[i].debug_output(debug, sizeof(debug), regs[i].reg, val);
-			printf("%30.30s: 0x%08x (%s)\n",
-			       regs[i].name,
-			       (unsigned int)val, debug);
-		} else {
-			printf("%30.30s: 0x%08x\n", regs[i].name,
-			       (unsigned int)val);
-		}
+		_intel_dump_reg(&regs[i], val);
 	}
 }
 
@@ -1964,6 +1969,54 @@ static struct reg_debug gen6_rp_debug_regs[] = {
 	DEFINEREG(GEN6_PMINTRMSK),
 };
 
+#define DECLARE_REGS(r)	{ .regs = r, .count = ARRAY_SIZE(r) }
+static struct {
+	struct reg_debug *regs;
+	int count;
+} known_registers[] = {
+	DECLARE_REGS(ironlake_debug_regs),
+	DECLARE_REGS(i945gm_mi_regs),
+	DECLARE_REGS(intel_debug_regs),
+	DECLARE_REGS(gen6_rp_debug_regs),
+	DECLARE_REGS(haswell_debug_regs)
+};
+#undef DECLARE_REGS
+
+static struct reg_debug *
+find_register_by_name(struct reg_debug *regs, int count,
+		      const char *name)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		if (strcasecmp(name, regs[i].name) == 0)
+			return &regs[i];
+
+	return NULL;
+}
+
+static void
+decode_register(const char *name, uint32_t val)
+{
+	int i;
+	struct reg_debug *reg = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(known_registers); i++) {
+		reg = find_register_by_name(known_registers[i].regs,
+					    known_registers[i].count,
+					    name);
+		if (reg)
+			break;
+	}
+
+	if (!reg) {
+		fprintf(stderr, "Unknown register: %s\n", name);
+		return;
+	}
+
+	_intel_dump_reg(reg, val);
+}
+
 static void
 intel_dump_other_regs(void)
 {
@@ -2172,6 +2225,7 @@ intel_dump_other_regs(void)
 static void print_usage(void)
 {
 	printf("Usage: intel_reg_dumper [options] [file]\n"
+	       "       intel_reg_dumper [options] register value\n"
 	       "Options:\n"
 	       "  -d id   when a dump file is used, use 'id' as device id (in "
 	       "hex)\n"
@@ -2181,8 +2235,9 @@ static void print_usage(void)
 int main(int argc, char** argv)
 {
 	struct pci_device *pci_dev;
-	int opt;
-	char *file = NULL;
+	int opt, n_args;
+	char *file = NULL, *reg_name = NULL;
+	uint32_t reg_val;
 
 	while ((opt = getopt(argc, argv, "d:h")) != -1) {
 		switch (opt) {
@@ -2197,8 +2252,24 @@ int main(int argc, char** argv)
 			return 1;
 		}
 	}
-	if (optind < argc)
+
+	n_args = argc - optind;
+	if (n_args == 1) {
 		file = argv[optind];
+	} else if (n_args == 2) {
+		reg_name = argv[optind];
+		reg_val = strtoul(argv[optind + 1], NULL, 0);
+	} else if (n_args) {
+		print_usage();
+		return 1;
+	}
+
+	/* the tool operates in "single" mode, decode a single register given
+	 * on the command line: intel_reg_dumper PCH_PP_CONTROL 0xabcd0002 */
+	if (reg_name) {
+		decode_register(reg_name, reg_val);
+		return 0;
+	}
 
 	if (file) {
 		intel_map_file(file);
Signature · 1 line
1.7.7.5
#1 lore raw

PATCH 2/4 intel_reg_dumper: Also decode registers given by address

From: Damien Lespiau <[email protected]>

One can now give an address instead of a register name to decode a single register.

---
 tools/intel_reg_dumper.c |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)
tools/intel_reg_dumper.c +30 -1
index cc68985..5bc47b6 100644
@@ -1996,7 +1996,7 @@ find_register_by_name(struct reg_debug *regs, int count,
 }
 
 static void
-decode_register(const char *name, uint32_t val)
+decode_register_name(const char *name, uint32_t val)
 {
 	int i;
 	struct reg_debug *reg = NULL;
@@ -2018,6 +2018,35 @@ decode_register(const char *name, uint32_t val)
 }
 
 static void
+decode_register_address(int address, uint32_t val)
+{
+	int i, j;
+
+	for (i = 0; i < ARRAY_SIZE(known_registers); i++) {
+		struct reg_debug *regs = known_registers[i].regs;
+
+		for (j = 0; j < known_registers[i].count; j++)
+			if (regs[j].reg == address)
+				_intel_dump_reg(&regs[j], val);
+	}
+}
+
+static void
+decode_register(const char *name, uint32_t val)
+{
+	long int address;
+	char *end;
+
+	address = strtoul(name, &end, 0);
+
+	/* found a register address */
+	if (address && *end == '\0')
+		decode_register_address(address, val);
+	else
+		decode_register_name(name, val);
+}
+
+static void
 intel_dump_other_regs(void)
 {
 	int i;
Signature · 1 line
1.7.7.5
#2 lore raw

PATCH 3/4 intel_reg_dumper: Allow partial register names on the command line

In reply to Damien Lespiau

From: Damien Lespiau <[email protected]>

Let people give just a part of the register name. Handy when not remembering the exact name or if the register is defined with a different name than the one in the spec being looked at.

---
 tools/intel_reg_dumper.c |   41 ++++++++++++++++-------------------------
 1 files changed, 16 insertions(+), 25 deletions(-)
tools/intel_reg_dumper.c +16 -25
index 5bc47b6..0b40f58 100644
@@ -26,6 +26,7 @@
  */
 
 #define _GNU_SOURCE
+#include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -1982,39 +1983,29 @@ static struct {
 };
 #undef DECLARE_REGS
 
-static struct reg_debug *
-find_register_by_name(struct reg_debug *regs, int count,
-		      const char *name)
+static void
+str_to_upper(char *str)
 {
-	int i;
-
-	for (i = 0; i < count; i++)
-		if (strcasecmp(name, regs[i].name) == 0)
-			return &regs[i];
-
-	return NULL;
+	while(*str) {
+		*str = toupper(*str);
+		str++;
+	}
 }
 
 static void
-decode_register_name(const char *name, uint32_t val)
+decode_register_name(char *name, uint32_t val)
 {
-	int i;
-	struct reg_debug *reg = NULL;
+	int i, j;
+
+	str_to_upper(name);
 
 	for (i = 0; i < ARRAY_SIZE(known_registers); i++) {
-		reg = find_register_by_name(known_registers[i].regs,
-					    known_registers[i].count,
-					    name);
-		if (reg)
-			break;
-	}
+		struct reg_debug *regs = known_registers[i].regs;
 
-	if (!reg) {
-		fprintf(stderr, "Unknown register: %s\n", name);
-		return;
+		for (j = 0; j < known_registers[i].count; j++)
+			if (strstr(regs[j].name, name))
+				_intel_dump_reg(&regs[j], val);
 	}
-
-	_intel_dump_reg(reg, val);
 }
 
 static void
@@ -2032,7 +2023,7 @@ decode_register_address(int address, uint32_t val)
 }
 
 static void
-decode_register(const char *name, uint32_t val)
+decode_register(char *name, uint32_t val)
 {
 	long int address;
 	char *end;
Signature · 1 line
1.7.7.5
#3 lore raw

PATCH 4/4 intel_reg_dumper: Add more information when dumping single registers

In reply to Damien Lespiau

From: Damien Lespiau <[email protected]>

Now that we can dump registers giving a partial name, adding more information about the dumped registers seems useful.

---
 tools/intel_reg_dumper.c |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)
tools/intel_reg_dumper.c +28 -8
index 0b40f58..f04702c 100644
@@ -27,6 +27,7 @@
 
 #define _GNU_SOURCE
 #include <ctype.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -1970,20 +1971,37 @@ static struct reg_debug gen6_rp_debug_regs[] = {
 	DEFINEREG(GEN6_PMINTRMSK),
 };
 
-#define DECLARE_REGS(r)	{ .regs = r, .count = ARRAY_SIZE(r) }
+#define DECLARE_REGS(d,r)	\
+	{ .description = d, .regs = r, .count = ARRAY_SIZE(r) }
 static struct {
+	const char *description;
 	struct reg_debug *regs;
 	int count;
 } known_registers[] = {
-	DECLARE_REGS(ironlake_debug_regs),
-	DECLARE_REGS(i945gm_mi_regs),
-	DECLARE_REGS(intel_debug_regs),
-	DECLARE_REGS(gen6_rp_debug_regs),
-	DECLARE_REGS(haswell_debug_regs)
+	DECLARE_REGS("Gen5",   ironlake_debug_regs),
+	DECLARE_REGS("i945GM", i945gm_mi_regs),
+	DECLARE_REGS("Gen2",   intel_debug_regs),
+	DECLARE_REGS("Gen6",   gen6_rp_debug_regs),
+	DECLARE_REGS("Gen7.5", haswell_debug_regs)
 };
 #undef DECLARE_REGS
 
 static void
+dump_reg(struct reg_debug *reg, uint32_t val, const char *prefix)
+{
+	char debug[1024];
+
+	if (reg->debug_output != NULL) {
+		reg->debug_output(debug, sizeof(debug), reg->reg, val);
+		printf("%s: %s (0x%x): 0x%08x (%s)\n",
+		       prefix, reg->name, reg->reg, val, debug);
+	} else {
+		printf("%s: %s (0x%x): 0x%08x\n",
+		       prefix, reg->name, reg->reg, val);
+	}
+}
+
+static void
 str_to_upper(char *str)
 {
 	while(*str) {
@@ -2004,7 +2022,8 @@ decode_register_name(char *name, uint32_t val)
 
 		for (j = 0; j < known_registers[i].count; j++)
 			if (strstr(regs[j].name, name))
-				_intel_dump_reg(&regs[j], val);
+				dump_reg(&regs[j], val,
+					 known_registers[i].description);
 	}
 }
 
@@ -2018,7 +2037,8 @@ decode_register_address(int address, uint32_t val)
 
 		for (j = 0; j < known_registers[i].count; j++)
 			if (regs[j].reg == address)
-				_intel_dump_reg(&regs[j], val);
+				dump_reg(&regs[j], val,
+					 known_registers[i].description);
 	}
 }
 
Signature · 1 line
1.7.7.5
#4 lore raw
In reply to Damien Lespiau
Quoted 6 lines · Damien Lespiau

From: Damien Lespiau <[email protected]>

From time to time, one would like to decode a register value that have been captured at a certain point in time (and say printed out with a printk). intel_reg_dumper has all the knowledge to do that and this patch adds a way to ask it to decode a value.

Without further bikeshedding: the series reviewed, briefly tested, and liked by me.

Jani.

Quoted 168 lines

Example usage:

$ ./tools/intel_reg_dumper PCH_PP_CONTROL 0xabcd0002
       PCH_PP_CONTROL: 0xabcd0002 (blacklight disabled, power...

v2: friendlier invocation (Chris Wilson)
v3: remove unecessary casts and use strcasecmp (Jani Nikula)

---
 tools/intel_reg_dumper.c |   97 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 84 insertions(+), 13 deletions(-)
tools/intel_reg_dumper.c +84 -13
index 7564cae..cc68985 100644
@@ -1911,26 +1911,31 @@ static struct reg_debug i945gm_mi_regs[] = {
 	DEFINEREG(ECOSKPD),
 };
 
+static void
+_intel_dump_reg(struct reg_debug *reg, uint32_t val)
+{
+	char debug[1024];
+
+	if (reg->debug_output != NULL) {
+		reg->debug_output(debug, sizeof(debug), reg->reg, val);
+		printf("%30.30s: 0x%08x (%s)\n",
+		       reg->name, val, debug);
+	} else {
+		printf("%30.30s: 0x%08x\n", reg->name, val);
+	}
+}
+
 #define intel_dump_regs(regs) _intel_dump_regs(regs, ARRAY_SIZE(regs))
 
 static void
 _intel_dump_regs(struct reg_debug *regs, int count)
 {
-	char debug[1024];
 	int i;
 
 	for (i = 0; i < count; i++) {
 		uint32_t val = INREG(regs[i].reg);
 
-		if (regs[i].debug_output != NULL) {
-			regs[i].debug_output(debug, sizeof(debug), regs[i].reg, val);
-			printf("%30.30s: 0x%08x (%s)\n",
-			       regs[i].name,
-			       (unsigned int)val, debug);
-		} else {
-			printf("%30.30s: 0x%08x\n", regs[i].name,
-			       (unsigned int)val);
-		}
+		_intel_dump_reg(&regs[i], val);
 	}
 }
 
@@ -1964,6 +1969,54 @@ static struct reg_debug gen6_rp_debug_regs[] = {
 	DEFINEREG(GEN6_PMINTRMSK),
 };
 
+#define DECLARE_REGS(r)	{ .regs = r, .count = ARRAY_SIZE(r) }
+static struct {
+	struct reg_debug *regs;
+	int count;
+} known_registers[] = {
+	DECLARE_REGS(ironlake_debug_regs),
+	DECLARE_REGS(i945gm_mi_regs),
+	DECLARE_REGS(intel_debug_regs),
+	DECLARE_REGS(gen6_rp_debug_regs),
+	DECLARE_REGS(haswell_debug_regs)
+};
+#undef DECLARE_REGS
+
+static struct reg_debug *
+find_register_by_name(struct reg_debug *regs, int count,
+		      const char *name)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		if (strcasecmp(name, regs[i].name) == 0)
+			return &regs[i];
+
+	return NULL;
+}
+
+static void
+decode_register(const char *name, uint32_t val)
+{
+	int i;
+	struct reg_debug *reg = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(known_registers); i++) {
+		reg = find_register_by_name(known_registers[i].regs,
+					    known_registers[i].count,
+					    name);
+		if (reg)
+			break;
+	}
+
+	if (!reg) {
+		fprintf(stderr, "Unknown register: %s\n", name);
+		return;
+	}
+
+	_intel_dump_reg(reg, val);
+}
+
 static void
 intel_dump_other_regs(void)
 {
@@ -2172,6 +2225,7 @@ intel_dump_other_regs(void)
 static void print_usage(void)
 {
 	printf("Usage: intel_reg_dumper [options] [file]\n"
+	       "       intel_reg_dumper [options] register value\n"
 	       "Options:\n"
 	       "  -d id   when a dump file is used, use 'id' as device id (in "
 	       "hex)\n"
@@ -2181,8 +2235,9 @@ static void print_usage(void)
 int main(int argc, char** argv)
 {
 	struct pci_device *pci_dev;
-	int opt;
-	char *file = NULL;
+	int opt, n_args;
+	char *file = NULL, *reg_name = NULL;
+	uint32_t reg_val;
 
 	while ((opt = getopt(argc, argv, "d:h")) != -1) {
 		switch (opt) {
@@ -2197,8 +2252,24 @@ int main(int argc, char** argv)
 			return 1;
 		}
 	}
-	if (optind < argc)
+
+	n_args = argc - optind;
+	if (n_args == 1) {
 		file = argv[optind];
+	} else if (n_args == 2) {
+		reg_name = argv[optind];
+		reg_val = strtoul(argv[optind + 1], NULL, 0);
+	} else if (n_args) {
+		print_usage();
+		return 1;
+	}
+
+	/* the tool operates in "single" mode, decode a single register given
+	 * on the command line: intel_reg_dumper PCH_PP_CONTROL 0xabcd0002 */
+	if (reg_name) {
+		decode_register(reg_name, reg_val);
+		return 0;
+	}
 
 	if (file) {
 		intel_map_file(file);
Signature · 6 lines
1.7.7.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw
Quoted 10 lines · Jani Nikula
Quoted 6 lines · Damien Lespiau

From: Damien Lespiau <[email protected]>

From time to time, one would like to decode a register value that have been captured at a certain point in time (and say printed out with a printk). intel_reg_dumper has all the knowledge to do that and this patch adds a way to ask it to decode a value.

Without further bikeshedding: the series reviewed, briefly tested, and liked by me.

Now also applied, thanks.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48