All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: intel-gfx@lists.freedesktop.org
Subject: [intel-gpu-tools] [PATCH 3/3] intel-gpu-tools: update reg_write to use ioctl interface
Date: Tue,  5 Apr 2011 12:33:37 -0700	[thread overview]
Message-ID: <1302032017-1771-4-git-send-email-ben@bwidawsk.net> (raw)
In-Reply-To: <1302032017-1771-1-git-send-email-ben@bwidawsk.net>

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 --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;
 }
-- 
1.7.3.4

      parent reply	other threads:[~2011-04-05 19:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05 19:33 read/write ioctl usage in intel-gpu-tools, for review Ben Widawsky
2011-04-05 19:33 ` [intel-gpu-tools] [PATCH 1/3] intel-gpu-tools add ioctl interface usage Ben Widawsky
2011-04-06 18:38   ` Kenneth Graunke
2011-04-05 19:33 ` [intel-gpu-tools] [PATCH 2/3] intel-gpu-tools update reg_read to use ioctls Ben Widawsky
2011-04-05 19:33 ` Ben Widawsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302032017-1771-4-git-send-email-ben@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.