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