2 * This file is part of the superiotool project.
4 * Copyright (C) 2007 Carl-Daniel Hailfinger
5 * Copyright (C) 2007-2010 Uwe Hermann <uwe@hermann-uwe.de>
6 * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
7 * Copyright (C) 2008-2009 coresystems GmbH
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
32 #if defined(__GLIBC__)
35 #if (defined(__MACH__) && defined(__APPLE__))
36 /* DirectIO is available here: http://www.coresystems.de/en/directio */
37 #include <DirectIO/darwinio.h>
44 #if defined(__FreeBSD__)
45 #include <sys/types.h>
46 #include <machine/cpufunc.h>
47 #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
48 #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
49 #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
50 #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
51 #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
52 #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
62 #define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\
63 -d | --dump Dump Super I/O register contents\n\
64 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
65 -l | --list-supported Show the list of supported Super I/O chips\n\
66 -V | --verbose Verbose mode\n\
67 -v | --version Show the superiotool version\n\
68 -h | --help Show a short help text\n\n"
71 Per default (no options) superiotool will just probe for a Super I/O\n\
72 and print its vendor, name, ID, revision, and config port.\n"
74 #define NOTFOUND " Failed. Returned data: "
76 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
78 #define EOT -1 /* End Of Table */
79 #define NOLDN -2 /* NO LDN needed */
80 #define NANA -3 /* Not Available */
81 #define RSVD -4 /* Reserved */
82 #define MISC -5 /* Needs special comment in output */
83 #define MAXLDN 0x14 /* Biggest LDN */
84 #define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
85 #define MAXNUMIDX 170 /* Maximum number of indices */
86 #define IDXSIZE (MAXNUMIDX + 1)
87 #define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
89 /* Select registers for various components. */
90 #define LDN_SEL 0x07 /* LDN select register */
91 #define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
93 /* Command line parameters. */
94 extern int dump, verbose, extra_dump;
96 extern int chip_found;
98 struct superio_registers {
99 int32_t superio_id; /* Signed, as we need EOT. */
100 const char *name; /* Super I/O name */
103 const char *name; /* LDN name */
104 int16_t idx[IDXSIZE];
105 int16_t def[IDXSIZE];
111 extern struct pci_access *pacc;
112 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
116 uint8_t regval(uint16_t port, uint8_t reg);
117 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
118 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
119 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
120 void enter_conf_mode_fintek_7777(uint16_t port);
121 void exit_conf_mode_fintek_7777(uint16_t port);
122 int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
123 const char *get_superio_name(const struct superio_registers reg_table[],
125 void dump_superio(const char *name, const struct superio_registers reg_table[],
126 uint16_t port, uint16_t id, uint8_t ldn_sel);
127 void dump_io(uint16_t iobase, uint16_t length);
128 void probing_for(const char *vendor, const char *info, uint16_t port);
129 void print_vendor_chips(const char *vendor,
130 const struct superio_registers reg_table[]);
133 void probe_idregs_ali(uint16_t port);
134 void print_ali_chips(void);
137 void probe_idregs_fintek(uint16_t port);
138 void probe_idregs_fintek_alternative(uint16_t port);
139 void print_fintek_chips(void);
142 void probe_idregs_ite(uint16_t port);
143 void print_ite_chips(void);
146 void probe_idregs_nsc(uint16_t port);
147 void print_nsc_chips(void);
150 void probe_idregs_nuvoton(uint16_t port);
151 void print_nuvoton_chips(void);
154 void probe_idregs_smsc(uint16_t port);
155 void print_smsc_chips(void);
158 void probe_idregs_winbond(uint16_t port);
159 void print_winbond_chips(void);
163 void probe_idregs_via(uint16_t port);
164 void print_via_chips(void);
167 /** Table of which config ports to probe for each Super I/O family. */
168 static const struct {
169 void (*probe_idregs) (uint16_t port);
170 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
171 } superio_ports_table[] = {
172 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
173 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
174 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
175 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
176 {probe_idregs_ite, {0x25e, 0x2e, 0x4e, 0x370, EOT}},
177 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, EOT}},
178 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
179 * addition to the following hardware strapping options. */
180 {probe_idregs_nuvoton, {0x164e, 0x2e, EOT}},
181 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
182 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
184 {probe_idregs_via, {0x3f0, EOT}},
188 /** Table of functions to print out supported Super I/O chips. */
189 static const struct {
190 void (*print_list) (void);
191 } vendor_print_functions[] = {
193 {print_fintek_chips},
196 {print_nuvoton_chips},
198 {print_winbond_chips},