Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | afe8309 | 2007-09-28 15:45:43 +0000 | [diff] [blame] | 2 | * This file is part of the superiotool project. |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007-2010 Uwe Hermann <uwe@hermann-uwe.de> |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com> |
Stefan Reinauer | e95eb61 | 2009-09-01 09:57:55 +0000 | [diff] [blame] | 7 | * Copyright (C) 2008-2009 coresystems GmbH |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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 |
| 22 | */ |
| 23 | |
| 24 | #ifndef SUPERIOTOOL_H |
| 25 | #define SUPERIOTOOL_H |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 29 | #include <stdint.h> |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 30 | #include <string.h> |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 31 | #include <getopt.h> |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 32 | #if defined(__GLIBC__) |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 33 | #include <sys/io.h> |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 34 | #endif |
Stefan Reinauer | e95eb61 | 2009-09-01 09:57:55 +0000 | [diff] [blame] | 35 | #if (defined(__MACH__) && defined(__APPLE__)) |
| 36 | /* DirectIO is available here: http://www.coresystems.de/en/directio */ |
| 37 | #include <DirectIO/darwinio.h> |
| 38 | #endif |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 39 | |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 40 | #ifdef PCI_SUPPORT |
| 41 | #include <pci/pci.h> |
| 42 | #endif |
| 43 | |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 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); }) |
| 53 | #else |
| 54 | #define OUTB outb |
| 55 | #define OUTW outw |
| 56 | #define OUTL outl |
| 57 | #define INB inb |
| 58 | #define INW inw |
| 59 | #define INL inl |
| 60 | #endif |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 61 | |
Uwe Hermann | eec5ff4 | 2008-03-01 18:49:39 +0000 | [diff] [blame] | 62 | #define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\ |
Uwe Hermann | 74b29b9 | 2007-11-17 17:13:52 +0000 | [diff] [blame] | 63 | -d | --dump Dump Super I/O register contents\n\ |
Uwe Hermann | eec5ff4 | 2008-03-01 18:49:39 +0000 | [diff] [blame] | 64 | -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\ |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 65 | -l | --list-supported Show the list of supported Super I/O chips\n\ |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 66 | -V | --verbose Verbose mode\n\ |
| 67 | -v | --version Show the superiotool version\n\ |
Uwe Hermann | 969a9f6 | 2008-03-17 13:43:48 +0000 | [diff] [blame] | 68 | -h | --help Show a short help text\n\n" |
| 69 | |
| 70 | #define USAGE_INFO "\ |
Uwe Hermann | e474956 | 2007-09-19 16:26:18 +0000 | [diff] [blame] | 71 | Per default (no options) superiotool will just probe for a Super I/O\n\ |
Uwe Hermann | afe8309 | 2007-09-28 15:45:43 +0000 | [diff] [blame] | 72 | and print its vendor, name, ID, revision, and config port.\n" |
Uwe Hermann | e474956 | 2007-09-19 16:26:18 +0000 | [diff] [blame] | 73 | |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 74 | #define NOTFOUND " Failed. Returned data: " |
| 75 | |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 76 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 77 | |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 78 | #define EOT -1 /* End Of Table */ |
| 79 | #define NOLDN -2 /* NO LDN needed */ |
| 80 | #define NANA -3 /* Not Available */ |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 81 | #define RSVD -4 /* Reserved */ |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 82 | #define MISC -5 /* Needs special comment in output */ |
Tom Sylla | 92af509 | 2008-06-07 11:36:30 +0000 | [diff] [blame] | 83 | #define MAXLDN 0x14 /* Biggest LDN */ |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 84 | #define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */ |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 85 | #define MAXNUMIDX 170 /* Maximum number of indices */ |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 86 | #define IDXSIZE (MAXNUMIDX + 1) |
Uwe Hermann | 14f304a | 2007-10-08 01:11:11 +0000 | [diff] [blame] | 87 | #define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */ |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 88 | |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 89 | /* Select registers for various components. */ |
| 90 | #define LDN_SEL 0x07 /* LDN select register */ |
| 91 | #define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */ |
| 92 | |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 93 | /* Command line parameters. */ |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 94 | extern int dump, verbose, extra_dump; |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 95 | |
Uwe Hermann | e9d4616 | 2007-10-07 20:01:23 +0000 | [diff] [blame] | 96 | extern int chip_found; |
| 97 | |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 98 | struct superio_registers { |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 99 | int32_t superio_id; /* Signed, as we need EOT. */ |
Uwe Hermann | 42cccdf | 2008-03-29 01:35:21 +0000 | [diff] [blame] | 100 | const char *name; /* Super I/O name */ |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 101 | struct { |
Uwe Hermann | 42cccdf | 2008-03-29 01:35:21 +0000 | [diff] [blame] | 102 | int8_t ldn; |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 103 | const char *name; /* LDN name */ |
Uwe Hermann | 42cccdf | 2008-03-29 01:35:21 +0000 | [diff] [blame] | 104 | int16_t idx[IDXSIZE]; |
| 105 | int16_t def[IDXSIZE]; |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 106 | } ldn[LDNSIZE]; |
| 107 | }; |
| 108 | |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 109 | /* pci.c */ |
| 110 | #ifdef PCI_SUPPORT |
| 111 | extern struct pci_access *pacc; |
| 112 | struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device); |
| 113 | #endif |
| 114 | |
Uwe Hermann | 4cb7e71 | 2007-09-16 18:17:44 +0000 | [diff] [blame] | 115 | /* superiotool.c */ |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 116 | uint8_t regval(uint16_t port, uint8_t reg); |
| 117 | void regwrite(uint16_t port, uint8_t reg, uint8_t val); |
Uwe Hermann | b4db220 | 2007-09-20 23:37:56 +0000 | [diff] [blame] | 118 | void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port); |
| 119 | void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port); |
Stefan Reinauer | e7b7ae2 | 2010-08-17 08:24:01 +0000 | [diff] [blame] | 120 | void enter_conf_mode_fintek_7777(uint16_t port); |
| 121 | void exit_conf_mode_fintek_7777(uint16_t port); |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 122 | int superio_unknown(const struct superio_registers reg_table[], uint16_t id); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 123 | const char *get_superio_name(const struct superio_registers reg_table[], |
| 124 | uint16_t id); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 125 | void dump_superio(const char *name, const struct superio_registers reg_table[], |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 126 | uint16_t port, uint16_t id, uint8_t ldn_sel); |
Stefan Reinauer | 6df0c62 | 2009-03-11 14:48:20 +0000 | [diff] [blame] | 127 | void dump_io(uint16_t iobase, uint16_t length); |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 128 | void probing_for(const char *vendor, const char *info, uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 129 | void print_vendor_chips(const char *vendor, |
| 130 | const struct superio_registers reg_table[]); |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 131 | |
Uwe Hermann | 945045b | 2007-09-28 15:39:10 +0000 | [diff] [blame] | 132 | /* ali.c */ |
| 133 | void probe_idregs_ali(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 134 | void print_ali_chips(void); |
Uwe Hermann | 945045b | 2007-09-28 15:39:10 +0000 | [diff] [blame] | 135 | |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 136 | /* fintek.c */ |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 137 | void probe_idregs_fintek(uint16_t port); |
Stefan Reinauer | e7b7ae2 | 2010-08-17 08:24:01 +0000 | [diff] [blame] | 138 | void probe_idregs_fintek_alternative(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 139 | void print_fintek_chips(void); |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 140 | |
| 141 | /* ite.c */ |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 142 | void probe_idregs_ite(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 143 | void print_ite_chips(void); |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 144 | |
| 145 | /* nsc.c */ |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 146 | void probe_idregs_nsc(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 147 | void print_nsc_chips(void); |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 148 | |
David Hendricks | e1822d9 | 2010-07-22 22:56:44 +0000 | [diff] [blame] | 149 | /* nuvoton.c */ |
| 150 | void probe_idregs_nuvoton(uint16_t port); |
| 151 | void print_nuvoton_chips(void); |
| 152 | |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 153 | /* smsc.c */ |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 154 | void probe_idregs_smsc(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 155 | void print_smsc_chips(void); |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 156 | |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 157 | /* winbond.c */ |
| 158 | void probe_idregs_winbond(uint16_t port); |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 159 | void print_winbond_chips(void); |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 160 | |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 161 | /* via.c */ |
| 162 | #ifdef PCI_SUPPORT |
| 163 | void probe_idregs_via(uint16_t port); |
| 164 | void print_via_chips(void); |
| 165 | #endif |
| 166 | |
Uwe Hermann | c3da366 | 2007-09-26 16:14:16 +0000 | [diff] [blame] | 167 | /** Table of which config ports to probe for each Super I/O family. */ |
Uwe Hermann | 246be7d | 2007-10-31 22:22:11 +0000 | [diff] [blame] | 168 | static const struct { |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 169 | void (*probe_idregs) (uint16_t port); |
| 170 | int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */ |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 171 | } superio_ports_table[] = { |
Uwe Hermann | 945045b | 2007-09-28 15:39:10 +0000 | [diff] [blame] | 172 | {probe_idregs_ali, {0x3f0, 0x370, EOT}}, |
Uwe Hermann | 0f86732 | 2007-09-24 01:40:09 +0000 | [diff] [blame] | 173 | {probe_idregs_fintek, {0x2e, 0x4e, EOT}}, |
Stefan Reinauer | e7b7ae2 | 2010-08-17 08:24:01 +0000 | [diff] [blame] | 174 | {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}}, |
Urja Rannikko | 38204a2 | 2008-10-23 23:33:18 +0000 | [diff] [blame] | 175 | /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */ |
Anders Juel Jensen | 3d0ff91 | 2010-08-22 19:40:58 +0000 | [diff] [blame^] | 176 | {probe_idregs_ite, {0x25e, 0x2e, 0x4e, 0x370, EOT}}, |
Uwe Hermann | c7d29013 | 2008-05-14 22:56:47 +0000 | [diff] [blame] | 177 | {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, EOT}}, |
David Hendricks | e1822d9 | 2010-07-22 22:56:44 +0000 | [diff] [blame] | 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}}, |
Uwe Hermann | 14f304a | 2007-10-08 01:11:11 +0000 | [diff] [blame] | 181 | {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}}, |
Uwe Hermann | c3da366 | 2007-09-26 16:14:16 +0000 | [diff] [blame] | 182 | {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}}, |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 183 | #ifdef PCI_SUPPORT |
| 184 | {probe_idregs_via, {0x3f0, EOT}}, |
| 185 | #endif |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 186 | }; |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 187 | |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 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[] = { |
| 192 | {print_ali_chips}, |
| 193 | {print_fintek_chips}, |
| 194 | {print_ite_chips}, |
| 195 | {print_nsc_chips}, |
David Hendricks | e1822d9 | 2010-07-22 22:56:44 +0000 | [diff] [blame] | 196 | {print_nuvoton_chips}, |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 197 | {print_smsc_chips}, |
| 198 | {print_winbond_chips}, |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 199 | #ifdef PCI_SUPPORT |
| 200 | {print_via_chips}, |
| 201 | #endif |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 204 | #endif |