[Intel-gfx] [intel-gpu-tools] [PATCH 3/3] intel-gpu-tools: update reg_write to use ioctl interface

Ben Widawsky ben at bwidawsk.net
Tue Apr 5 21:33:37 CEST 2011


we really need a global arg parser... :(

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

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 at gmail.com>
+ *    Ben Widawsky <ben at 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;
 }
-- 
1.7.3.4




More information about the Intel-gfx mailing list