Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +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. |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com> |
Uwe Hermann | bd26392 | 2007-09-01 19:42:42 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de> |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 6 | * Copyright (C) 2007 Carl-Daniel Hailfinger |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 7 | * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com> |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +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 | |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 24 | #include "superiotool.h" |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 25 | |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 26 | /* Command line options. */ |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 27 | int dump = 0, verbose = 0, extra_dump = 0; |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 28 | |
Uwe Hermann | e9d4616 | 2007-10-07 20:01:23 +0000 | [diff] [blame] | 29 | /* Global flag which indicates whether a chip was detected at all. */ |
| 30 | int chip_found = 0; |
| 31 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 32 | uint8_t regval(uint16_t port, uint8_t reg) |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 33 | { |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 34 | outb(reg, port); |
Carl-Daniel Hailfinger | b1786c2 | 2007-08-28 10:43:57 +0000 | [diff] [blame] | 35 | return inb(port + 1); |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 38 | void regwrite(uint16_t port, uint8_t reg, uint8_t val) |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 39 | { |
Carl-Daniel Hailfinger | 7a7890a | 2007-08-27 07:28:28 +0000 | [diff] [blame] | 40 | outb(reg, port); |
Carl-Daniel Hailfinger | b1786c2 | 2007-08-28 10:43:57 +0000 | [diff] [blame] | 41 | outb(val, port + 1); |
Carl-Daniel Hailfinger | 7a7890a | 2007-08-27 07:28:28 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Uwe Hermann | b4db220 | 2007-09-20 23:37:56 +0000 | [diff] [blame] | 44 | void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port) |
| 45 | { |
| 46 | outb(0x87, port); |
| 47 | outb(0x87, port); |
| 48 | } |
| 49 | |
| 50 | void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port) |
| 51 | { |
| 52 | outb(0xaa, port); /* Fintek, Winbond */ |
| 53 | regwrite(port, 0x02, 0x02); /* ITE */ |
| 54 | } |
| 55 | |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 56 | int superio_unknown(const struct superio_registers reg_table[], uint16_t id) |
| 57 | { |
| 58 | return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9); |
| 59 | } |
| 60 | |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 61 | const char *get_superio_name(const struct superio_registers reg_table[], |
| 62 | uint16_t id) |
| 63 | { |
| 64 | int i; |
| 65 | |
| 66 | for (i = 0; /* Nothing */; i++) { |
| 67 | if (reg_table[i].superio_id == EOT) |
| 68 | break; |
| 69 | |
| 70 | if ((uint16_t)reg_table[i].superio_id != id) |
| 71 | continue; |
| 72 | |
| 73 | return reg_table[i].name; |
| 74 | } |
| 75 | |
| 76 | return "<unknown>"; |
| 77 | } |
| 78 | |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 79 | static void dump_regs(const struct superio_registers reg_table[], |
| 80 | int i, int j, uint16_t port) |
| 81 | { |
Ward Vandewege | 2ee78d8 | 2007-09-24 22:02:31 +0000 | [diff] [blame] | 82 | int k; |
| 83 | const int *idx; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 84 | |
| 85 | if (reg_table[i].ldn[j].ldn != NOLDN) { |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 86 | printf("LDN 0x%02x", reg_table[i].ldn[j].ldn); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 87 | if (reg_table[i].ldn[j].name != NULL) |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 88 | printf(" (%s)", reg_table[i].ldn[j].name); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 89 | regwrite(port, 0x07, reg_table[i].ldn[j].ldn); |
| 90 | } else { |
| 91 | printf("Register dump:"); |
| 92 | } |
| 93 | |
| 94 | idx = reg_table[i].ldn[j].idx; |
| 95 | |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 96 | printf("\nidx"); |
| 97 | for (k = 0; idx[k] != EOT; k++) { |
| 98 | if (k && !(k % 8)) |
| 99 | putchar(' '); |
| 100 | printf(" %02x", idx[k]); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 103 | printf("\nval"); |
| 104 | for (k = 0; idx[k] != EOT; k++) { |
| 105 | if (k && !(k % 8)) |
| 106 | putchar(' '); |
| 107 | printf(" %02x", regval(port, idx[k])); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 110 | printf("\ndef"); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 111 | idx = reg_table[i].ldn[j].def; |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 112 | for (k = 0; idx[k] != EOT; k++) { |
| 113 | if (k && !(k % 8)) |
| 114 | putchar(' '); |
| 115 | if (idx[k] == NANA) |
| 116 | printf(" NA"); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 117 | else if (idx[k] == RSVD) |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 118 | printf(" RR"); |
Uwe Hermann | 59b99d9 | 2007-11-29 02:43:50 +0000 | [diff] [blame] | 119 | else if (idx[k] == MISC) |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 120 | printf(" MM"); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 121 | else |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 122 | printf(" %02x", idx[k]); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 123 | } |
| 124 | printf("\n"); |
| 125 | } |
| 126 | |
| 127 | void dump_superio(const char *vendor, |
| 128 | const struct superio_registers reg_table[], |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 129 | uint16_t port, uint16_t id) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 130 | { |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 131 | int i, j, no_dump_available = 1; |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 132 | |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 133 | if (!dump) |
| 134 | return; |
| 135 | |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 136 | for (i = 0; /* Nothing */; i++) { |
| 137 | if (reg_table[i].superio_id == EOT) |
| 138 | break; |
| 139 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 140 | if ((uint16_t)reg_table[i].superio_id != id) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 141 | continue; |
| 142 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 143 | for (j = 0; /* Nothing */; j++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 144 | if (reg_table[i].ldn[j].ldn == EOT) |
| 145 | break; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 146 | no_dump_available = 0; |
| 147 | dump_regs(reg_table, i, j, port); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 148 | } |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 149 | |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 150 | if (no_dump_available) |
| 151 | printf("No dump available for this Super I/O\n"); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 155 | void probing_for(const char *vendor, const char *info, uint16_t port) |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 156 | { |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 157 | if (!verbose) |
| 158 | return; |
| 159 | |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 160 | /* Yes, there's no space between '%s' and 'at'! */ |
Uwe Hermann | eec5ff4 | 2008-03-01 18:49:39 +0000 | [diff] [blame] | 161 | printf("Probing for %s Super I/O %sat 0x%x...\n", vendor, info, port); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 164 | /** Print a list of all supported chips from the given vendor. */ |
| 165 | void print_vendor_chips(const char *vendor, |
| 166 | const struct superio_registers reg_table[]) |
| 167 | { |
| 168 | int i; |
| 169 | |
| 170 | for (i = 0; reg_table[i].superio_id != EOT; i++) { |
| 171 | printf("%s %s", vendor, reg_table[i].name); |
| 172 | |
| 173 | /* Unless the ldn is empty, assume this chip has a dump. */ |
| 174 | if (reg_table[i].ldn[0].ldn != EOT) |
| 175 | printf(" (dump available)"); |
| 176 | |
| 177 | printf("\n"); |
| 178 | } |
| 179 | |
| 180 | /* If we printed any chips for this vendor, put in a blank line. */ |
| 181 | if (i != 0) |
| 182 | printf("\n"); |
| 183 | } |
| 184 | |
| 185 | /** Print a list of all chips supported by superiotool. */ |
| 186 | void print_list_of_supported_chips(void) |
| 187 | { |
| 188 | int i; |
| 189 | |
| 190 | printf("Supported Super I/O chips:\n\n"); |
| 191 | |
| 192 | for (i = 0; i < ARRAY_SIZE(vendor_print_functions); i++) |
| 193 | vendor_print_functions[i].print_list(); |
| 194 | |
| 195 | printf("See <http://coreboot.org/Superiotool#Supported_devices> " |
| 196 | "for more information.\n"); |
| 197 | } |
| 198 | |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 199 | static void print_version(void) |
| 200 | { |
Ulf Jordan | 39a5bf7 | 2007-10-13 18:06:12 +0000 | [diff] [blame] | 201 | printf("superiotool r%s\n", SUPERIOTOOL_VERSION); |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 204 | int main(int argc, char *argv[]) |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 205 | { |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 206 | int i, j, opt, option_index; |
| 207 | |
Uwe Hermann | 246be7d | 2007-10-31 22:22:11 +0000 | [diff] [blame] | 208 | static const struct option long_options[] = { |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 209 | {"dump", no_argument, NULL, 'd'}, |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 210 | {"extra-dump", no_argument, NULL, 'e'}, |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 211 | {"list-supported", no_argument, NULL, 'l'}, |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 212 | {"verbose", no_argument, NULL, 'V'}, |
| 213 | {"version", no_argument, NULL, 'v'}, |
| 214 | {"help", no_argument, NULL, 'h'}, |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 215 | {0, 0, 0, 0} |
| 216 | }; |
| 217 | |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 218 | while ((opt = getopt_long(argc, argv, "delVvh", |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 219 | long_options, &option_index)) != EOF) { |
| 220 | switch (opt) { |
| 221 | case 'd': |
| 222 | dump = 1; |
| 223 | break; |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 224 | case 'e': |
| 225 | extra_dump = 1; |
| 226 | break; |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 227 | case 'l': |
| 228 | print_list_of_supported_chips(); |
| 229 | exit(0); |
| 230 | break; |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 231 | case 'V': |
| 232 | verbose = 1; |
| 233 | break; |
| 234 | case 'v': |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 235 | print_version(); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 236 | exit(0); |
| 237 | break; |
| 238 | case 'h': |
Uwe Hermann | e474956 | 2007-09-19 16:26:18 +0000 | [diff] [blame] | 239 | printf(USAGE); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 240 | exit(0); |
| 241 | break; |
| 242 | default: |
| 243 | /* Unknown option. */ |
| 244 | exit(1); |
| 245 | break; |
| 246 | } |
| 247 | } |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 248 | |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 249 | if (iopl(3) < 0) { |
| 250 | perror("iopl"); |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 251 | printf("Superiotool must be run as root.\n"); |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 252 | exit(1); |
| 253 | } |
| 254 | |
Uwe Hermann | d937b52 | 2007-10-17 23:42:02 +0000 | [diff] [blame] | 255 | print_version(); |
| 256 | |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 257 | for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) { |
| 258 | for (j = 0; superio_ports_table[i].ports[j] != EOT; j++) |
| 259 | superio_ports_table[i].probe_idregs( |
| 260 | superio_ports_table[i].ports[j]); |
| 261 | } |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 262 | |
Uwe Hermann | e9d4616 | 2007-10-07 20:01:23 +0000 | [diff] [blame] | 263 | if (!chip_found) |
| 264 | printf("No Super I/O found\n"); |
| 265 | |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 266 | return 0; |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 267 | } |