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 | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 25 | uint8_t regval(uint16_t port, uint8_t reg) |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 26 | { |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 27 | outb(reg, port); |
Carl-Daniel Hailfinger | b1786c2 | 2007-08-28 10:43:57 +0000 | [diff] [blame] | 28 | return inb(port + 1); |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 31 | void regwrite(uint16_t port, uint8_t reg, uint8_t val) |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 32 | { |
Carl-Daniel Hailfinger | 7a7890a | 2007-08-27 07:28:28 +0000 | [diff] [blame] | 33 | outb(reg, port); |
Carl-Daniel Hailfinger | b1786c2 | 2007-08-28 10:43:57 +0000 | [diff] [blame] | 34 | outb(val, port + 1); |
Carl-Daniel Hailfinger | 7a7890a | 2007-08-27 07:28:28 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 37 | void dump_superio(const char *vendor, const struct superio_registers reg_table[], |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 38 | uint16_t port, uint16_t id) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 39 | { |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 40 | int i, j, k, nodump; |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 41 | int *idx; |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 42 | |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 43 | for (i = 0; /* Nothing */; i++) { |
| 44 | if (reg_table[i].superio_id == EOT) |
| 45 | break; |
| 46 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 47 | if ((uint16_t)reg_table[i].superio_id != id) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 48 | continue; |
| 49 | |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 50 | nodump = 1; |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 51 | |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 52 | for (j = 0; /* Nothing */; j++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 53 | if (reg_table[i].ldn[j].ldn == EOT) |
| 54 | break; |
| 55 | |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 56 | printf("%s %s\n", vendor, reg_table[i].name); |
| 57 | nodump = 0; |
| 58 | |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 59 | if (reg_table[i].ldn[j].ldn != NOLDN) { |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 60 | printf("Switching to LDN 0x%02x\n", |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 61 | reg_table[i].ldn[j].ldn); |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 62 | regwrite(port, 0x07, reg_table[i].ldn[j].ldn); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | idx = reg_table[i].ldn[j].idx; |
| 66 | |
| 67 | printf("idx "); |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 68 | for (k = 0; /* Nothing */; k++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 69 | if (idx[k] == EOT) |
| 70 | break; |
| 71 | printf("%02x ", idx[k]); |
| 72 | } |
| 73 | |
| 74 | printf("\nval "); |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 75 | for (k = 0; /* Nothing */; k++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 76 | if (idx[k] == EOT) |
| 77 | break; |
| 78 | printf("%02x ", regval(port, idx[k])); |
| 79 | } |
| 80 | |
| 81 | printf("\ndef "); |
| 82 | idx = reg_table[i].ldn[j].def; |
Uwe Hermann | de24a0e | 2007-09-19 00:03:14 +0000 | [diff] [blame] | 83 | for (k = 0; /* Nothing */; k++) { |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 84 | if (idx[k] == EOT) |
| 85 | break; |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 86 | else if (idx[k] == NANA) |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 87 | printf("NA "); |
Uwe Hermann | 6ff6af7 | 2007-09-18 22:24:34 +0000 | [diff] [blame] | 88 | else if (idx[k] == RSVD) |
| 89 | printf("RR "); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 90 | else |
| 91 | printf("%02x ", idx[k]); |
| 92 | } |
| 93 | printf("\n"); |
| 94 | } |
Uwe Hermann | 25a6c0f | 2007-09-19 00:48:42 +0000 | [diff] [blame] | 95 | |
| 96 | if (nodump) |
| 97 | printf("No dump for %s %s\n", vendor, reg_table[i].name); |
Uwe Hermann | 519419b | 2007-09-16 20:59:01 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Uwe Hermann | 2046ff9 | 2007-09-01 21:02:44 +0000 | [diff] [blame] | 101 | int main(int argc, char *argv[]) |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 102 | { |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 103 | int i, j; |
| 104 | |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 105 | if (iopl(3) < 0) { |
| 106 | perror("iopl"); |
| 107 | exit(1); |
| 108 | } |
| 109 | |
Uwe Hermann | d754d2c | 2007-09-18 23:30:24 +0000 | [diff] [blame] | 110 | for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) { |
| 111 | for (j = 0; superio_ports_table[i].ports[j] != EOT; j++) |
| 112 | superio_ports_table[i].probe_idregs( |
| 113 | superio_ports_table[i].ports[j]); |
| 114 | } |
Stefan Reinauer | 6a5bc46 | 2007-01-17 10:57:42 +0000 | [diff] [blame] | 115 | |
| 116 | return 0; |
Ronald G. Minnich | 394e7c4 | 2006-02-22 22:12:21 +0000 | [diff] [blame] | 117 | } |