From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Widawsky 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 Message-ID: <1302032017-1771-4-git-send-email-ben@bwidawsk.net> References: <1302032017-1771-1-git-send-email-ben@bwidawsk.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from cloud01.chad-versace.us (184-106-247-128.static.cloud-ips.com [184.106.247.128]) by gabe.freedesktop.org (Postfix) with ESMTP id CD2B99ED38 for ; Tue, 5 Apr 2011 12:33:46 -0700 (PDT) In-Reply-To: <1302032017-1771-1-git-send-email-ben@bwidawsk.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org we really need a global arg parser... :( Signed-off-by: Ben Widawsky --- 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 + * Ben Widawsky * */ @@ -31,26 +32,45 @@ #include #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", ®); - 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