Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 2 | |
Uwe Hermann | 0120e1a | 2007-09-16 18:11:03 +0000 | [diff] [blame] | 3 | #include "superiotool.h" |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 4 | |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 5 | #if defined(__FreeBSD__) |
| 6 | #include <fcntl.h> |
| 7 | #include <unistd.h> |
| 8 | #endif |
| 9 | |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 10 | /* Command line options. */ |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 11 | int dump = 0, verbose = 0, extra_dump = 0, alternate_dump = 0; |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 12 | |
Uwe Hermann | e9d4616 | 2007-10-07 20:01:23 +0000 | [diff] [blame] | 13 | /* Global flag which indicates whether a chip was detected at all. */ |
| 14 | int chip_found = 0; |
| 15 | |
Guenter Roeck | a89da09 | 2012-06-29 12:23:50 -0700 | [diff] [blame] | 16 | static void set_bank(uint16_t port, uint8_t bank) |
| 17 | { |
| 18 | OUTB(0x4E, port); |
| 19 | OUTB(bank, port + 1); |
| 20 | } |
| 21 | |
| 22 | static uint8_t datareg(uint16_t port, uint8_t reg) |
| 23 | { |
| 24 | OUTB(reg, port); |
| 25 | return INB(port + 1); |
| 26 | } |
| 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 | { |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 30 | OUTB(reg, port); |
| 31 | return INB(port + ((port == 0x3bd) ? 2 : 1)); /* 0x3bd is special. */ |
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 | { |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 36 | OUTB(reg, port); |
| 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 | { |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 42 | OUTB(0x87, port); |
| 43 | OUTB(0x87, port); |
Uwe Hermann | b4db220 | 2007-09-20 23:37:56 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port) |
| 47 | { |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 48 | OUTB(0xaa, port); /* Fintek, Winbond */ |
Uwe Hermann | b4db220 | 2007-09-20 23:37:56 +0000 | [diff] [blame] | 49 | regwrite(port, 0x02, 0x02); /* ITE */ |
| 50 | } |
| 51 | |
Stefan Reinauer | e7b7ae2 | 2010-08-17 08:24:01 +0000 | [diff] [blame] | 52 | void enter_conf_mode_fintek_7777(uint16_t port) |
| 53 | { |
| 54 | OUTB(0x77, port); |
| 55 | OUTB(0x77, port); |
| 56 | } |
| 57 | |
| 58 | void exit_conf_mode_fintek_7777(uint16_t port) |
| 59 | { |
| 60 | OUTB(0xaa, port); /* Fintek */ |
| 61 | } |
| 62 | |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 63 | int superio_unknown(const struct superio_registers reg_table[], uint16_t id) |
| 64 | { |
| 65 | return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9); |
| 66 | } |
| 67 | |
Stefan Reinauer | e7b7ae2 | 2010-08-17 08:24:01 +0000 | [diff] [blame] | 68 | |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 69 | const char *get_superio_name(const struct superio_registers reg_table[], |
| 70 | uint16_t id) |
| 71 | { |
| 72 | int i; |
| 73 | |
| 74 | for (i = 0; /* Nothing */; i++) { |
| 75 | if (reg_table[i].superio_id == EOT) |
| 76 | break; |
| 77 | |
| 78 | if ((uint16_t)reg_table[i].superio_id != id) |
| 79 | continue; |
| 80 | |
| 81 | return reg_table[i].name; |
| 82 | } |
| 83 | |
| 84 | return "<unknown>"; |
| 85 | } |
| 86 | |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 87 | static void dump_regs(const struct superio_registers reg_table[], |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 88 | int i, int j, uint16_t port, uint8_t ldn_sel) |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 89 | { |
Ward Vandewege | 2ee78d8 | 2007-09-24 22:02:31 +0000 | [diff] [blame] | 90 | int k; |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 91 | const int16_t *idx, *def; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 92 | |
| 93 | if (reg_table[i].ldn[j].ldn != NOLDN) { |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 94 | printf("LDN 0x%02x", reg_table[i].ldn[j].ldn); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 95 | if (reg_table[i].ldn[j].name != NULL) |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 96 | printf(" (%s)", reg_table[i].ldn[j].name); |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 97 | regwrite(port, ldn_sel, reg_table[i].ldn[j].ldn); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 98 | } else { |
Anders Juel Jensen | 4fd7df9 | 2010-08-22 19:40:11 +0000 | [diff] [blame] | 99 | if (reg_table[i].ldn[j].name == NULL) |
| 100 | printf("Register dump:"); |
| 101 | else |
| 102 | printf("(%s)", reg_table[i].ldn[j].name); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | idx = reg_table[i].ldn[j].idx; |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 106 | def = reg_table[i].ldn[j].def; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 107 | |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 108 | if (alternate_dump) { |
| 109 | int skip_def = 0; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 110 | |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 111 | printf("\nidx val def\n"); |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 112 | |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 113 | for (k = 0; idx[k] != EOT; k++) { |
| 114 | printf("0x%02x: 0x%02x", idx[k], regval(port, idx[k])); |
| 115 | |
| 116 | if (skip_def || def[k] == EOT) { |
| 117 | skip_def = 1; |
| 118 | printf("\n"); |
| 119 | continue; |
| 120 | } |
| 121 | if (def[k] == NANA) |
| 122 | printf(" (NA)\n"); |
| 123 | else if (def[k] == RSVD) |
| 124 | printf(" (RR)\n"); |
| 125 | else if (def[k] == MISC) |
| 126 | printf(" (MM)\n"); |
| 127 | else |
| 128 | printf(" (0x%02x)\n", def[k]); |
| 129 | } |
| 130 | } else { |
| 131 | printf("\nidx"); |
| 132 | for (k = 0; idx[k] != EOT; k++) { |
| 133 | if (k && !(k % 8)) |
| 134 | putchar(' '); |
Frieder Ferlemann | a422c2d | 2007-11-13 09:09:33 +0000 | [diff] [blame] | 135 | printf(" %02x", idx[k]); |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | printf("\nval"); |
| 139 | for (k = 0; idx[k] != EOT; k++) { |
| 140 | if (k && !(k % 8)) |
| 141 | putchar(' '); |
| 142 | printf(" %02x", regval(port, idx[k])); |
| 143 | } |
| 144 | |
| 145 | printf("\ndef"); |
| 146 | for (k = 0; def[k] != EOT; k++) { |
| 147 | if (k && !(k % 8)) |
| 148 | putchar(' '); |
| 149 | if (def[k] == NANA) |
| 150 | printf(" NA"); |
| 151 | else if (def[k] == RSVD) |
| 152 | printf(" RR"); |
| 153 | else if (def[k] == MISC) |
| 154 | printf(" MM"); |
| 155 | else |
| 156 | printf(" %02x", def[k]); |
| 157 | } |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 158 | } |
| 159 | printf("\n"); |
| 160 | } |
| 161 | |
| 162 | void dump_superio(const char *vendor, |
| 163 | const struct superio_registers reg_table[], |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 164 | uint16_t port, uint16_t id, uint8_t ldn_sel) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 165 | { |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 166 | int i, j, no_dump_available = 1; |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 167 | |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 168 | if (!dump) |
| 169 | return; |
| 170 | |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 171 | for (i = 0; /* Nothing */; i++) { |
| 172 | if (reg_table[i].superio_id == EOT) |
| 173 | break; |
| 174 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 175 | if ((uint16_t)reg_table[i].superio_id != id) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 176 | continue; |
| 177 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 178 | for (j = 0; /* Nothing */; j++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 179 | if (reg_table[i].ldn[j].ldn == EOT) |
| 180 | break; |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 181 | no_dump_available = 0; |
Stefan Reinauer | 7a51e50 | 2008-12-01 14:18:57 +0000 | [diff] [blame] | 182 | dump_regs(reg_table, i, j, port, ldn_sel); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 183 | } |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 184 | |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 185 | if (no_dump_available) |
| 186 | printf("No dump available for this Super I/O\n"); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Stefan Reinauer | 6df0c62 | 2009-03-11 14:48:20 +0000 | [diff] [blame] | 190 | void dump_io(uint16_t iobase, uint16_t length) |
| 191 | { |
| 192 | uint16_t i; |
| 193 | |
Uwe Hermann | 83da8dc | 2009-03-25 17:38:40 +0000 | [diff] [blame] | 194 | printf("Dumping %d I/O mapped registers at base 0x%04x:\n", |
Stefan Reinauer | 6df0c62 | 2009-03-11 14:48:20 +0000 | [diff] [blame] | 195 | length, iobase); |
Uwe Hermann | 83da8dc | 2009-03-25 17:38:40 +0000 | [diff] [blame] | 196 | for (i = 0; i < length; i++) |
| 197 | printf("%02x ", i); |
Stefan Reinauer | 6df0c62 | 2009-03-11 14:48:20 +0000 | [diff] [blame] | 198 | printf("\n"); |
Uwe Hermann | 83da8dc | 2009-03-25 17:38:40 +0000 | [diff] [blame] | 199 | for (i = 0; i < length; i++) |
| 200 | printf("%02x ", INB(iobase + i)); |
Stefan Reinauer | 6df0c62 | 2009-03-11 14:48:20 +0000 | [diff] [blame] | 201 | printf("\n"); |
| 202 | } |
| 203 | |
Guenter Roeck | a89da09 | 2012-06-29 12:23:50 -0700 | [diff] [blame] | 204 | void dump_data(uint16_t iobase, int bank) |
| 205 | { |
| 206 | uint16_t i; |
| 207 | |
| 208 | printf("Bank %d:\n", bank); |
| 209 | printf(" "); |
| 210 | for (i = 0; i < 16; i++) |
| 211 | printf("%02x ", i); |
| 212 | set_bank(iobase, bank); |
| 213 | for (i = 0; i < 256; i++) { |
| 214 | if (i % 16 == 0) |
| 215 | printf("\n%02x: ", i / 16); |
| 216 | printf("%02x ", datareg(iobase, i)); |
| 217 | } |
| 218 | printf("\n"); |
| 219 | } |
| 220 | |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 221 | void probing_for(const char *vendor, const char *info, uint16_t port) |
Uwe Hermann | 2c290e3 | 2007-09-20 00:00:49 +0000 | [diff] [blame] | 222 | { |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 223 | if (!verbose) |
| 224 | return; |
| 225 | |
Uwe Hermann | 8b8d039 | 2007-10-04 15:23:38 +0000 | [diff] [blame] | 226 | /* Yes, there's no space between '%s' and 'at'! */ |
Uwe Hermann | eec5ff4 | 2008-03-01 18:49:39 +0000 | [diff] [blame] | 227 | 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] | 228 | } |
| 229 | |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 230 | /** Print a list of all supported chips from the given vendor. */ |
| 231 | void print_vendor_chips(const char *vendor, |
| 232 | const struct superio_registers reg_table[]) |
| 233 | { |
| 234 | int i; |
| 235 | |
| 236 | for (i = 0; reg_table[i].superio_id != EOT; i++) { |
| 237 | printf("%s %s", vendor, reg_table[i].name); |
| 238 | |
| 239 | /* Unless the ldn is empty, assume this chip has a dump. */ |
| 240 | if (reg_table[i].ldn[0].ldn != EOT) |
| 241 | printf(" (dump available)"); |
| 242 | |
| 243 | printf("\n"); |
| 244 | } |
| 245 | |
| 246 | /* If we printed any chips for this vendor, put in a blank line. */ |
| 247 | if (i != 0) |
| 248 | printf("\n"); |
| 249 | } |
| 250 | |
| 251 | /** Print a list of all chips supported by superiotool. */ |
| 252 | void print_list_of_supported_chips(void) |
| 253 | { |
| 254 | int i; |
| 255 | |
| 256 | printf("Supported Super I/O chips:\n\n"); |
| 257 | |
| 258 | for (i = 0; i < ARRAY_SIZE(vendor_print_functions); i++) |
| 259 | vendor_print_functions[i].print_list(); |
| 260 | |
Paul Menzel | a8843de | 2017-06-05 12:33:23 +0200 | [diff] [blame] | 261 | printf("See <https://coreboot.org/Superiotool#Supported_devices> " |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 262 | "for more information.\n"); |
| 263 | } |
| 264 | |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 265 | static void print_version(void) |
| 266 | { |
Ulf Jordan | 39a5bf7 | 2007-10-13 18:06:12 +0000 | [diff] [blame] | 267 | printf("superiotool r%s\n", SUPERIOTOOL_VERSION); |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 270 | int main(int argc, char *argv[]) |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 271 | { |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 272 | int i, j, opt, option_index; |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 273 | #if defined(__FreeBSD__) |
| 274 | int io_fd; |
| 275 | #endif |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 276 | |
Uwe Hermann | 246be7d | 2007-10-31 22:22:11 +0000 | [diff] [blame] | 277 | static const struct option long_options[] = { |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 278 | {"dump", no_argument, NULL, 'd'}, |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 279 | {"extra-dump", no_argument, NULL, 'e'}, |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 280 | {"alternate-dump", no_argument, NULL, 'a'}, |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 281 | {"list-supported", no_argument, NULL, 'l'}, |
Uwe Hermann | eddc473 | 2007-09-20 23:57:44 +0000 | [diff] [blame] | 282 | {"verbose", no_argument, NULL, 'V'}, |
| 283 | {"version", no_argument, NULL, 'v'}, |
| 284 | {"help", no_argument, NULL, 'h'}, |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 285 | {0, 0, 0, 0} |
| 286 | }; |
| 287 | |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 288 | while ((opt = getopt_long(argc, argv, "dealVvh", |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 289 | long_options, &option_index)) != EOF) { |
| 290 | switch (opt) { |
| 291 | case 'd': |
| 292 | dump = 1; |
| 293 | break; |
Ronald Hoogenboom | 0be73bb | 2008-02-25 22:32:41 +0000 | [diff] [blame] | 294 | case 'e': |
| 295 | extra_dump = 1; |
| 296 | break; |
Nico Huber | 3812a72 | 2016-10-12 12:12:51 +0200 | [diff] [blame] | 297 | case 'a': |
| 298 | alternate_dump = 1; |
| 299 | break; |
Robinson P. Tryon | 552cfb7 | 2008-01-15 22:30:55 +0000 | [diff] [blame] | 300 | case 'l': |
| 301 | print_list_of_supported_chips(); |
| 302 | exit(0); |
| 303 | break; |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 304 | case 'V': |
| 305 | verbose = 1; |
| 306 | break; |
| 307 | case 'v': |
Robinson P. Tryon | ec1edd1 | 2007-10-02 23:32:21 +0000 | [diff] [blame] | 308 | print_version(); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 309 | exit(0); |
| 310 | break; |
| 311 | case 'h': |
Uwe Hermann | e474956 | 2007-09-19 16:26:18 +0000 | [diff] [blame] | 312 | printf(USAGE); |
Uwe Hermann | 969a9f6 | 2008-03-17 13:43:48 +0000 | [diff] [blame] | 313 | printf(USAGE_INFO); |
Uwe Hermann | 3acf31e | 2007-09-19 01:55:35 +0000 | [diff] [blame] | 314 | exit(0); |
| 315 | break; |
| 316 | default: |
| 317 | /* Unknown option. */ |
| 318 | exit(1); |
| 319 | break; |
| 320 | } |
| 321 | } |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 322 | |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 323 | #if defined(__FreeBSD__) |
| 324 | if ((io_fd = open("/dev/io", O_RDWR)) < 0) { |
| 325 | perror("/dev/io"); |
Fabian Groffen | 318ddb8 | 2023-03-10 18:12:25 +0100 | [diff] [blame^] | 326 | #elif defined(__NetBSD__) |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 327 | if (iopl(3) < 0) { |
| 328 | perror("iopl"); |
Fabian Groffen | 318ddb8 | 2023-03-10 18:12:25 +0100 | [diff] [blame^] | 329 | #else |
| 330 | if (ioperm(0, 6000, 1) < 0) { |
| 331 | perror("ioperm"); |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 332 | #endif |
Uwe Hermann | 7e7e9ac | 2007-09-19 15:52:23 +0000 | [diff] [blame] | 333 | printf("Superiotool must be run as root.\n"); |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 334 | exit(1); |
| 335 | } |
| 336 | |
Uwe Hermann | d937b52 | 2007-10-17 23:42:02 +0000 | [diff] [blame] | 337 | print_version(); |
| 338 | |
Carl-Daniel Hailfinger | bb38f32 | 2010-01-24 01:40:46 +0000 | [diff] [blame] | 339 | #ifdef PCI_SUPPORT |
| 340 | /* Do some basic libpci init. */ |
| 341 | pacc = pci_alloc(); |
| 342 | pci_init(pacc); |
| 343 | pci_scan_bus(pacc); |
| 344 | #endif |
| 345 | |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 346 | for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) { |
| 347 | for (j = 0; superio_ports_table[i].ports[j] != EOT; j++) |
| 348 | superio_ports_table[i].probe_idregs( |
| 349 | superio_ports_table[i].ports[j]); |
| 350 | } |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 351 | |
Uwe Hermann | e9d4616 | 2007-10-07 20:01:23 +0000 | [diff] [blame] | 352 | if (!chip_found) |
| 353 | printf("No Super I/O found\n"); |
| 354 | |
Andriy Gapon | b64aa60 | 2008-10-28 22:13:38 +0000 | [diff] [blame] | 355 | #if defined(__FreeBSD__) |
| 356 | close(io_fd); |
| 357 | #endif |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 358 | return 0; |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 359 | } |