summaryrefslogtreecommitdiff
path: root/util/superiotool/superiotool.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2007-09-19 01:55:35 +0000
committerUwe Hermann <uwe@hermann-uwe.de>2007-09-19 01:55:35 +0000
commit3acf31e4eaa0f143cd8af10f5ce99523ddc53a03 (patch)
tree1698c59c50c3291bed158fb47b0ebbe729b0b7b8 /util/superiotool/superiotool.c
parent3ef9b740dea1044713b667829cb9c4e2a48785b0 (diff)
downloadcoreboot-3acf31e4eaa0f143cd8af10f5ce99523ddc53a03.tar.xz
Further code simplifications and improvements.
Add command line option handling code. The following options are defined at the moment: -d|--dump Dump Super I/O registers. -V|--verbose Verbose mode. -v|--version Show the superiotool version. -h|--help Show a short help text. Per default (no options) we just probe for a Super I/O and print its vendor, name, ID, version, and config port. Example: $ ./superiotool Found SMSC FDC37N769 Super I/O (id=0x28, rev=0x01) at port=0x03f0 $ ./superiotool -d Found SMSC FDC37N769 Super I/O (id=0x28, rev=0x01) at port=0x03f0 idx 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f val 20 90 80 f4 00 00 ff 00 00 00 40 00 0e 28 01 00 00 00 00 00 02 00 01 03 00 00 00 00 00 00 80 00 00 00 00 00 00 ba 00 00 03 00 00 23 03 03 00 00 def 28 9c 88 70 00 00 ff 00 00 00 00 00 02 28 NA 00 00 80 RR RR NA NA NA 03 RR RR RR RR RR RR 80 00 3c RR RR 00 00 00 00 00 00 00 RR 00 00 03 00 00 $ ./superiotool -s ./superiotool: invalid option -- s $ ./superiotool -h Usage: superiotool [-d] [-V] [-v] [-h] $ ./superiotool -v superiotool 0.1 Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2788 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/superiotool/superiotool.c')
-rw-r--r--util/superiotool/superiotool.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/util/superiotool/superiotool.c b/util/superiotool/superiotool.c
index fd49c309ee..de512486e6 100644
--- a/util/superiotool/superiotool.c
+++ b/util/superiotool/superiotool.c
@@ -22,6 +22,9 @@
#include "superiotool.h"
+/* Command line options. */
+int dump = 0, verbose = 0;
+
uint8_t regval(uint16_t port, uint8_t reg)
{
outb(reg, port);
@@ -34,6 +37,24 @@ void regwrite(uint16_t port, uint8_t reg, uint8_t val)
outb(val, port + 1);
}
+const char *get_superio_name(const struct superio_registers reg_table[],
+ uint16_t id)
+{
+ int i;
+
+ for (i = 0; /* Nothing */; i++) {
+ if (reg_table[i].superio_id == EOT)
+ break;
+
+ if ((uint16_t)reg_table[i].superio_id != id)
+ continue;
+
+ return reg_table[i].name;
+ }
+
+ return "<unknown>";
+}
+
void dump_superio(const char *vendor, const struct superio_registers reg_table[],
uint16_t port, uint16_t id)
{
@@ -53,7 +74,6 @@ void dump_superio(const char *vendor, const struct superio_registers reg_table[]
if (reg_table[i].ldn[j].ldn == EOT)
break;
- printf("%s %s\n", vendor, reg_table[i].name);
nodump = 0;
if (reg_table[i].ldn[j].ldn != NOLDN) {
@@ -98,9 +118,51 @@ void dump_superio(const char *vendor, const struct superio_registers reg_table[]
}
}
+void no_superio_found(uint16_t port) {
+ if (!verbose)
+ return;
+
+ if (inb(port) == 0xff)
+ printf("No Super I/O chip found at 0x%04x\n", port);
+ else
+ printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+}
+
int main(int argc, char *argv[])
{
- int i, j;
+ int i, j, opt, option_index;
+
+ const static struct option long_options[] = {
+ {"dump", no_argument, NULL, 'd'},
+ {"verbose", no_argument, NULL, 'V'},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, "dVvh",
+ long_options, &option_index)) != EOF) {
+ switch (opt) {
+ case 'd':
+ dump = 1;
+ break;
+ case 'V':
+ verbose = 1;
+ break;
+ case 'v':
+ printf("superiotool %s\n", SUPERIOTOOL_VERSION);
+ exit(0);
+ break;
+ case 'h':
+ printf("Usage: superiotool [-d] [-V] [-v] [-h]\n");
+ exit(0);
+ break;
+ default:
+ /* Unknown option. */
+ exit(1);
+ break;
+ }
+ }
if (iopl(3) < 0) {
perror("iopl");