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