2 * This file is part of the superiotool 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
7 * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "superiotool.h"
26 #if defined(__FreeBSD__)
31 /* Command line options. */
32 int dump = 0, verbose = 0, extra_dump = 0;
34 /* Global flag which indicates whether a chip was detected at all. */
37 uint8_t regval(uint16_t port, uint8_t reg)
40 return INB(port + ((port == 0x3bd) ? 2 : 1)); /* 0x3bd is special. */
43 void regwrite(uint16_t port, uint8_t reg, uint8_t val)
49 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port)
55 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port)
57 OUTB(0xaa, port); /* Fintek, Winbond */
58 regwrite(port, 0x02, 0x02); /* ITE */
61 void enter_conf_mode_fintek_7777(uint16_t port)
67 void exit_conf_mode_fintek_7777(uint16_t port)
69 OUTB(0xaa, port); /* Fintek */
72 int superio_unknown(const struct superio_registers reg_table[], uint16_t id)
74 return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9);
78 const char *get_superio_name(const struct superio_registers reg_table[],
83 for (i = 0; /* Nothing */; i++) {
84 if (reg_table[i].superio_id == EOT)
87 if ((uint16_t)reg_table[i].superio_id != id)
90 return reg_table[i].name;
96 static void dump_regs(const struct superio_registers reg_table[],
97 int i, int j, uint16_t port, uint8_t ldn_sel)
102 if (reg_table[i].ldn[j].ldn != NOLDN) {
103 printf("LDN 0x%02x", reg_table[i].ldn[j].ldn);
104 if (reg_table[i].ldn[j].name != NULL)
105 printf(" (%s)", reg_table[i].ldn[j].name);
106 regwrite(port, ldn_sel, reg_table[i].ldn[j].ldn);
108 if (reg_table[i].ldn[j].name == NULL)
109 printf("Register dump:");
111 printf("(%s)", reg_table[i].ldn[j].name);
114 idx = reg_table[i].ldn[j].idx;
117 for (k = 0; idx[k] != EOT; k++) {
120 printf(" %02x", idx[k]);
124 for (k = 0; idx[k] != EOT; k++) {
127 printf(" %02x", regval(port, idx[k]));
131 idx = reg_table[i].ldn[j].def;
132 for (k = 0; idx[k] != EOT; k++) {
137 else if (idx[k] == RSVD)
139 else if (idx[k] == MISC)
142 printf(" %02x", idx[k]);
147 void dump_superio(const char *vendor,
148 const struct superio_registers reg_table[],
149 uint16_t port, uint16_t id, uint8_t ldn_sel)
151 int i, j, no_dump_available = 1;
156 for (i = 0; /* Nothing */; i++) {
157 if (reg_table[i].superio_id == EOT)
160 if ((uint16_t)reg_table[i].superio_id != id)
163 for (j = 0; /* Nothing */; j++) {
164 if (reg_table[i].ldn[j].ldn == EOT)
166 no_dump_available = 0;
167 dump_regs(reg_table, i, j, port, ldn_sel);
170 if (no_dump_available)
171 printf("No dump available for this Super I/O\n");
175 void dump_io(uint16_t iobase, uint16_t length)
179 printf("Dumping %d I/O mapped registers at base 0x%04x:\n",
181 for (i = 0; i < length; i++)
184 for (i = 0; i < length; i++)
185 printf("%02x ", INB(iobase + i));
189 void probing_for(const char *vendor, const char *info, uint16_t port)
194 /* Yes, there's no space between '%s' and 'at'! */
195 printf("Probing for %s Super I/O %sat 0x%x...\n", vendor, info, port);
198 /** Print a list of all supported chips from the given vendor. */
199 void print_vendor_chips(const char *vendor,
200 const struct superio_registers reg_table[])
204 for (i = 0; reg_table[i].superio_id != EOT; i++) {
205 printf("%s %s", vendor, reg_table[i].name);
207 /* Unless the ldn is empty, assume this chip has a dump. */
208 if (reg_table[i].ldn[0].ldn != EOT)
209 printf(" (dump available)");
214 /* If we printed any chips for this vendor, put in a blank line. */
219 /** Print a list of all chips supported by superiotool. */
220 void print_list_of_supported_chips(void)
224 printf("Supported Super I/O chips:\n\n");
226 for (i = 0; i < ARRAY_SIZE(vendor_print_functions); i++)
227 vendor_print_functions[i].print_list();
229 printf("See <http://coreboot.org/Superiotool#Supported_devices> "
230 "for more information.\n");
233 static void print_version(void)
235 printf("superiotool r%s\n", SUPERIOTOOL_VERSION);
238 int main(int argc, char *argv[])
240 int i, j, opt, option_index;
241 #if defined(__FreeBSD__)
245 static const struct option long_options[] = {
246 {"dump", no_argument, NULL, 'd'},
247 {"extra-dump", no_argument, NULL, 'e'},
248 {"list-supported", no_argument, NULL, 'l'},
249 {"verbose", no_argument, NULL, 'V'},
250 {"version", no_argument, NULL, 'v'},
251 {"help", no_argument, NULL, 'h'},
255 while ((opt = getopt_long(argc, argv, "delVvh",
256 long_options, &option_index)) != EOF) {
265 print_list_of_supported_chips();
281 /* Unknown option. */
287 #if defined(__FreeBSD__)
288 if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
294 printf("Superiotool must be run as root.\n");
301 /* Do some basic libpci init. */
307 for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) {
308 for (j = 0; superio_ports_table[i].ports[j] != EOT; j++)
309 superio_ports_table[i].probe_idregs(
310 superio_ports_table[i].ports[j]);
314 printf("No Super I/O found\n");
316 #if defined(__FreeBSD__)