blob: fd49c309eef86a90156a36d6025bc54612f7a805 [file] [log] [blame]
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00001/*
2 * This file is part of the LinuxBIOS project.
3 *
4 * Copyright (C) 2006 Ronald Minnich <rminnich@gmail.com>
Uwe Hermannbd263922007-09-01 19:42:42 +00005 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
Uwe Hermann519419b2007-09-16 20:59:01 +00006 * Copyright (C) 2007 Carl-Daniel Hailfinger
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00007 *
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 Hermann0120e1a2007-09-16 18:11:03 +000023#include "superiotool.h"
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000024
Uwe Hermannde24a0e2007-09-19 00:03:14 +000025uint8_t regval(uint16_t port, uint8_t reg)
Uwe Hermann2046ff92007-09-01 21:02:44 +000026{
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000027 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000028 return inb(port + 1);
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000029}
30
Uwe Hermannde24a0e2007-09-19 00:03:14 +000031void regwrite(uint16_t port, uint8_t reg, uint8_t val)
Uwe Hermann2046ff92007-09-01 21:02:44 +000032{
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000033 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000034 outb(val, port + 1);
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000035}
36
Uwe Hermann25a6c0f2007-09-19 00:48:42 +000037void dump_superio(const char *vendor, const struct superio_registers reg_table[],
Uwe Hermannde24a0e2007-09-19 00:03:14 +000038 uint16_t port, uint16_t id)
Uwe Hermann519419b2007-09-16 20:59:01 +000039{
Uwe Hermann25a6c0f2007-09-19 00:48:42 +000040 int i, j, k, nodump;
Uwe Hermannde24a0e2007-09-19 00:03:14 +000041 int *idx;
Uwe Hermann519419b2007-09-16 20:59:01 +000042
Uwe Hermann519419b2007-09-16 20:59:01 +000043 for (i = 0; /* Nothing */; i++) {
44 if (reg_table[i].superio_id == EOT)
45 break;
46
Uwe Hermannde24a0e2007-09-19 00:03:14 +000047 if ((uint16_t)reg_table[i].superio_id != id)
Uwe Hermann519419b2007-09-16 20:59:01 +000048 continue;
49
Uwe Hermann25a6c0f2007-09-19 00:48:42 +000050 nodump = 1;
Uwe Hermann519419b2007-09-16 20:59:01 +000051
Uwe Hermannde24a0e2007-09-19 00:03:14 +000052 for (j = 0; /* Nothing */; j++) {
Uwe Hermann519419b2007-09-16 20:59:01 +000053 if (reg_table[i].ldn[j].ldn == EOT)
54 break;
55
Uwe Hermann25a6c0f2007-09-19 00:48:42 +000056 printf("%s %s\n", vendor, reg_table[i].name);
57 nodump = 0;
58
Uwe Hermann519419b2007-09-16 20:59:01 +000059 if (reg_table[i].ldn[j].ldn != NOLDN) {
Uwe Hermannde24a0e2007-09-19 00:03:14 +000060 printf("Switching to LDN 0x%02x\n",
Uwe Hermann519419b2007-09-16 20:59:01 +000061 reg_table[i].ldn[j].ldn);
Uwe Hermannde24a0e2007-09-19 00:03:14 +000062 regwrite(port, 0x07, reg_table[i].ldn[j].ldn);
Uwe Hermann519419b2007-09-16 20:59:01 +000063 }
64
65 idx = reg_table[i].ldn[j].idx;
66
67 printf("idx ");
Uwe Hermannde24a0e2007-09-19 00:03:14 +000068 for (k = 0; /* Nothing */; k++) {
Uwe Hermann519419b2007-09-16 20:59:01 +000069 if (idx[k] == EOT)
70 break;
71 printf("%02x ", idx[k]);
72 }
73
74 printf("\nval ");
Uwe Hermannde24a0e2007-09-19 00:03:14 +000075 for (k = 0; /* Nothing */; k++) {
Uwe Hermann519419b2007-09-16 20:59:01 +000076 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 Hermannde24a0e2007-09-19 00:03:14 +000083 for (k = 0; /* Nothing */; k++) {
Uwe Hermann519419b2007-09-16 20:59:01 +000084 if (idx[k] == EOT)
85 break;
Uwe Hermann6ff6af72007-09-18 22:24:34 +000086 else if (idx[k] == NANA)
Uwe Hermann519419b2007-09-16 20:59:01 +000087 printf("NA ");
Uwe Hermann6ff6af72007-09-18 22:24:34 +000088 else if (idx[k] == RSVD)
89 printf("RR ");
Uwe Hermann519419b2007-09-16 20:59:01 +000090 else
91 printf("%02x ", idx[k]);
92 }
93 printf("\n");
94 }
Uwe Hermann25a6c0f2007-09-19 00:48:42 +000095
96 if (nodump)
97 printf("No dump for %s %s\n", vendor, reg_table[i].name);
Uwe Hermann519419b2007-09-16 20:59:01 +000098 }
99}
100
Uwe Hermann2046ff92007-09-01 21:02:44 +0000101int main(int argc, char *argv[])
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000102{
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000103 int i, j;
104
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000105 if (iopl(3) < 0) {
106 perror("iopl");
107 exit(1);
108 }
109
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000110 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 Reinauer6a5bc462007-01-17 10:57:42 +0000115
116 return 0;
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000117}