diff mbox

[intel-gpu-tools,2/3] intel-gpu-tools update reg_read to use ioctls

Message ID 1302032017-1771-3-git-send-email-ben@bwidawsk.net (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Widawsky April 5, 2011, 7:33 p.m. UTC
Redid the arg parsing as well as the register dumps to easily support
switching between ioctl, and non-ioctl usage.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 tools/intel_reg_read.c |   41 +++++++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/tools/intel_reg_read.c b/tools/intel_reg_read.c
index 0259924..d7c4962 100644
--- a/tools/intel_reg_read.c
+++ b/tools/intel_reg_read.c
@@ -22,7 +22,7 @@ 
  *
  * Authors:
  *	Zhenyu Wang <zhenyuw@linux.intel.com>
- *
+ *	Ben Widawsky <ben@bwidawsk.net>
  */
 
 #include <unistd.h>
@@ -30,32 +30,49 @@ 
 #include <stdio.h>
 #include <err.h>
 #include <string.h>
+#include <unistd.h>
 #include "intel_gpu_tools.h"
 
 static void dump_range(uint32_t start, uint32_t end)
 {
 	int i;
-
 	for (i = start; i < end; i += 4)
-		printf("0x%X : 0x%X\n", i,
-		       *(volatile uint32_t *)((volatile char*)mmio + i));
+		printf("0x%X : 0x%X\n", i, INREG(i));
+}
+
+static void usage(const char *app_name)
+{
+	printf("Usage: %s -i [-f | addr]\n", app_name);
+	printf("\t -i : use IOCTL read/write driver interface.\n");
+	printf("\t -f : read back full range of registers.\n");
+	printf("\t      WARNING! This could be danger to hang the machine!\n");
+	exit(1);
 }
 
 int main(int argc, char** argv)
 {
 	uint32_t reg;
+	int opt;
+	int do_range_dump = 0;
 
-	if (argc != 2) {
-		printf("Usage: %s [-f | addr]\n", argv[0]);
-		printf("\t -f : read back full range of registers.\n");
-		printf("\t      WARNING! This could be danger to hang the machine!\n");
-		printf("\t addr : in 0xXXXX format\n");
-		exit(1);
+	while ((opt = getopt(argc, argv, "ifh?")) != -1) {
+		switch (opt) {
+		case 'i':
+			use_ioctl_mmio = 1;
+			break;
+		case 'f':
+			do_range_dump = 1;
+			break;
+		case 'h':
+		case '?':
+			usage(argv[0]);
+			exit(EXIT_FAILURE);
+		}
 	}
 
 	intel_get_mmio(intel_get_pci_device());
 
-	if (!strcmp(argv[1], "-f")) {
+	if (do_range_dump) {
 		dump_range(0x00000, 0x00fff);   /* VGA registers */
 		dump_range(0x02000, 0x02fff);   /* instruction, memory, interrupt control registers */
 		dump_range(0x03000, 0x031ff);   /* FENCE and PPGTT control registers */
@@ -71,7 +88,7 @@  int main(int argc, char** argv)
 		dump_range(0x70000, 0x72fff);   /* display and cursor registers */
 		dump_range(0x73000, 0x73fff);   /* performance counters */
 	} else {
-		sscanf(argv[1], "0x%x", &reg);
+		reg = strtol(argv[optind], NULL, 0);
 		dump_range(reg, reg + 4);
 	}