diff mbox

[intel-gpu-tools,3/3] intel-gpu-tools: update reg_write to use ioctl interface

Message ID 1302032017-1771-4-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
we really need a global arg parser... :(

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

Patch

diff --git a/tools/intel_reg_write.c b/tools/intel_reg_write.c
index c8af9bb..158f5f8 100644
--- a/tools/intel_reg_write.c
+++ b/tools/intel_reg_write.c
@@ -22,6 +22,7 @@ 
  *
  * Authors:
  *    Ben Gamari <bgamari.foss@gmail.com>
+ *    Ben Widawsky <ben@bwidawsk.net>
  *
  */
 
@@ -31,26 +32,45 @@ 
 #include <err.h>
 #include "intel_gpu_tools.h"
 
+static void usage(const char *app_name)
+{
+	printf("Usage: %s [-i] addr value\n", app_name);
+	printf("  -i: use IOCTL read/write driver interface.\n");
+	printf("  WARNING: This is dangerous to you and your system's health.\n");
+	printf("           Only for use in debugging.\n");
+	exit(1);
+}
+
 int main(int argc, char** argv)
 {
 	uint32_t reg, value;
-	volatile uint32_t *ptr;
+	int opt;
 
-	if (argc < 3) {
-		printf("Usage: %s addr value\n", argv[0]);
-		printf("  WARNING: This is dangerous to you and your system's health.\n");
-		printf("           Only for use in debugging.\n");
-		exit(1);
+	while ((opt = getopt(argc, argv, "ih?")) != -1) {
+		switch (opt) {
+		case 'i':
+			use_ioctl_mmio = 1;
+			break;
+		case 'h':
+		case '?':
+			usage(argv[0]);
+			exit(EXIT_FAILURE);
+		}
 	}
+	if (argc - optind != 2) {
+		usage(argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
+
+	reg = strtol(argv[optind], NULL, 0);
+	value = strtol(argv[optind + 1], NULL, 0);
 
 	intel_get_mmio(intel_get_pci_device());
-	sscanf(argv[1], "0x%x", &reg);
-	sscanf(argv[2], "0x%x", &value);
-	ptr = (volatile uint32_t *)((volatile char *)mmio + reg);
 
-	printf("Value before: 0x%X\n", *ptr);
-	*ptr = value;
-	printf("Value after: 0x%X\n", *ptr);
+	printf("Value before: 0x%X\n", INREG(reg));
+	OUTREG(reg, value);
+	printf("Value after: 0x%X\n", INREG(reg));
 
 	return 0;
 }