2 * This file is part of the LinuxBIOS project.
4 * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
5 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6 * Copyright (C) 2007 Carl-Daniel Hailfinger
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "superiotool.h"
25 /* Command line options. */
26 int dump = 0, verbose = 0;
28 uint8_t regval(uint16_t port, uint8_t reg)
34 void regwrite(uint16_t port, uint8_t reg, uint8_t val)
40 int superio_unknown(const struct superio_registers reg_table[], uint16_t id)
42 return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9);
45 const char *get_superio_name(const struct superio_registers reg_table[],
50 for (i = 0; /* Nothing */; i++) {
51 if (reg_table[i].superio_id == EOT)
54 if ((uint16_t)reg_table[i].superio_id != id)
57 return reg_table[i].name;
63 void dump_superio(const char *vendor, const struct superio_registers reg_table[],
64 uint16_t port, uint16_t id)
72 for (i = 0; /* Nothing */; i++) {
73 if (reg_table[i].superio_id == EOT)
76 if ((uint16_t)reg_table[i].superio_id != id)
81 for (j = 0; /* Nothing */; j++) {
82 if (reg_table[i].ldn[j].ldn == EOT)
87 if (reg_table[i].ldn[j].ldn != NOLDN) {
88 printf("Switching to LDN 0x%02x\n",
89 reg_table[i].ldn[j].ldn);
90 regwrite(port, 0x07, reg_table[i].ldn[j].ldn);
93 idx = reg_table[i].ldn[j].idx;
96 for (k = 0; /* Nothing */; k++) {
99 printf("%02x ", idx[k]);
103 for (k = 0; /* Nothing */; k++) {
106 printf("%02x ", regval(port, idx[k]));
110 idx = reg_table[i].ldn[j].def;
111 for (k = 0; /* Nothing */; k++) {
114 else if (idx[k] == NANA)
116 else if (idx[k] == RSVD)
118 else if (idx[k] == MISC) /* TODO */
121 printf("%02x ", idx[k]);
127 printf("No dump for %s %s\n", vendor, reg_table[i].name);
131 void no_superio_found(uint16_t port) {
135 if (inb(port) == 0xff)
136 printf("No Super I/O chip found at 0x%04x\n", port);
138 printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
141 int main(int argc, char *argv[])
143 int i, j, opt, option_index;
145 const static struct option long_options[] = {
146 {"dump", no_argument, NULL, 'd'},
147 {"verbose", no_argument, NULL, 'V'},
148 {"version", no_argument, NULL, 'v'},
149 {"help", no_argument, NULL, 'h'},
153 while ((opt = getopt_long(argc, argv, "dVvh",
154 long_options, &option_index)) != EOF) {
163 printf("superiotool %s\n", SUPERIOTOOL_VERSION);
171 /* Unknown option. */
179 printf("Superiotool must be run as root.\n");
183 for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) {
184 for (j = 0; superio_ports_table[i].ports[j] != EOT; j++)
185 superio_ports_table[i].probe_idregs(
186 superio_ports_table[i].ports[j]);