blob: d96396f24ae37765d015f3bf7dd3fc26771097b0 [file] [log] [blame]
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00001/*
Uwe Hermannafe83092007-09-28 15:45:43 +00002 * This file is part of the superiotool project.
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00003 *
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
Robinson P. Tryon552cfb72008-01-15 22:30:55 +00007 * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
Stefan Reinauer6a5bc462007-01-17 10:57:42 +00008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
Uwe Hermann0120e1a2007-09-16 18:11:03 +000024#include "superiotool.h"
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000025
Uwe Hermann3acf31e2007-09-19 01:55:35 +000026/* Command line options. */
Uwe Hermann7dabe5e2007-10-17 23:43:59 +000027int dump = 0, verbose = 0;
Uwe Hermann3acf31e2007-09-19 01:55:35 +000028
Uwe Hermanne9d46162007-10-07 20:01:23 +000029/* Global flag which indicates whether a chip was detected at all. */
30int chip_found = 0;
31
Uwe Hermannde24a0e2007-09-19 00:03:14 +000032uint8_t regval(uint16_t port, uint8_t reg)
Uwe Hermann2046ff92007-09-01 21:02:44 +000033{
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000034 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000035 return inb(port + 1);
Ronald G. Minnich394e7c42006-02-22 22:12:21 +000036}
37
Uwe Hermannde24a0e2007-09-19 00:03:14 +000038void regwrite(uint16_t port, uint8_t reg, uint8_t val)
Uwe Hermann2046ff92007-09-01 21:02:44 +000039{
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000040 outb(reg, port);
Carl-Daniel Hailfingerb1786c22007-08-28 10:43:57 +000041 outb(val, port + 1);
Carl-Daniel Hailfinger7a7890a2007-08-27 07:28:28 +000042}
43
Uwe Hermannb4db2202007-09-20 23:37:56 +000044void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port)
45{
46 outb(0x87, port);
47 outb(0x87, port);
48}
49
50void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port)
51{
52 outb(0xaa, port); /* Fintek, Winbond */
53 regwrite(port, 0x02, 0x02); /* ITE */
54}
55
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +000056int superio_unknown(const struct superio_registers reg_table[], uint16_t id)
57{
58 return !strncmp(get_superio_name(reg_table, id), "<unknown>", 9);
59}
60
Uwe Hermann3acf31e2007-09-19 01:55:35 +000061const char *get_superio_name(const struct superio_registers reg_table[],
62 uint16_t id)
63{
64 int i;
65
66 for (i = 0; /* Nothing */; i++) {
67 if (reg_table[i].superio_id == EOT)
68 break;
69
70 if ((uint16_t)reg_table[i].superio_id != id)
71 continue;
72
73 return reg_table[i].name;
74 }
75
76 return "<unknown>";
77}
78
Uwe Hermann2c290e32007-09-20 00:00:49 +000079static void dump_regs(const struct superio_registers reg_table[],
80 int i, int j, uint16_t port)
81{
Ward Vandewege2ee78d82007-09-24 22:02:31 +000082 int k;
83 const int *idx;
Uwe Hermann2c290e32007-09-20 00:00:49 +000084
85 if (reg_table[i].ldn[j].ldn != NOLDN) {
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +000086 printf("LDN 0x%02x", reg_table[i].ldn[j].ldn);
Uwe Hermann2c290e32007-09-20 00:00:49 +000087 if (reg_table[i].ldn[j].name != NULL)
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +000088 printf(" (%s)", reg_table[i].ldn[j].name);
Uwe Hermann2c290e32007-09-20 00:00:49 +000089 regwrite(port, 0x07, reg_table[i].ldn[j].ldn);
90 } else {
91 printf("Register dump:");
92 }
93
94 idx = reg_table[i].ldn[j].idx;
95
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +000096 printf("\nidx");
97 for (k = 0; idx[k] != EOT; k++) {
98 if (k && !(k % 8))
99 putchar(' ');
100 printf(" %02x", idx[k]);
Uwe Hermann2c290e32007-09-20 00:00:49 +0000101 }
102
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000103 printf("\nval");
104 for (k = 0; idx[k] != EOT; k++) {
105 if (k && !(k % 8))
106 putchar(' ');
107 printf(" %02x", regval(port, idx[k]));
Uwe Hermann2c290e32007-09-20 00:00:49 +0000108 }
109
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000110 printf("\ndef");
Uwe Hermann2c290e32007-09-20 00:00:49 +0000111 idx = reg_table[i].ldn[j].def;
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000112 for (k = 0; idx[k] != EOT; k++) {
113 if (k && !(k % 8))
114 putchar(' ');
115 if (idx[k] == NANA)
116 printf(" NA");
Uwe Hermann2c290e32007-09-20 00:00:49 +0000117 else if (idx[k] == RSVD)
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000118 printf(" RR");
Uwe Hermann59b99d92007-11-29 02:43:50 +0000119 else if (idx[k] == MISC)
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000120 printf(" MM");
Uwe Hermann2c290e32007-09-20 00:00:49 +0000121 else
Frieder Ferlemanna422c2d2007-11-13 09:09:33 +0000122 printf(" %02x", idx[k]);
Uwe Hermann2c290e32007-09-20 00:00:49 +0000123 }
124 printf("\n");
125}
126
127void dump_superio(const char *vendor,
128 const struct superio_registers reg_table[],
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000129 uint16_t port, uint16_t id)
Uwe Hermann519419b2007-09-16 20:59:01 +0000130{
Uwe Hermann2c290e32007-09-20 00:00:49 +0000131 int i, j, no_dump_available = 1;
Uwe Hermann519419b2007-09-16 20:59:01 +0000132
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000133 if (!dump)
134 return;
135
Uwe Hermann519419b2007-09-16 20:59:01 +0000136 for (i = 0; /* Nothing */; i++) {
137 if (reg_table[i].superio_id == EOT)
138 break;
139
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000140 if ((uint16_t)reg_table[i].superio_id != id)
Uwe Hermann519419b2007-09-16 20:59:01 +0000141 continue;
142
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000143 for (j = 0; /* Nothing */; j++) {
Uwe Hermann519419b2007-09-16 20:59:01 +0000144 if (reg_table[i].ldn[j].ldn == EOT)
145 break;
Uwe Hermann2c290e32007-09-20 00:00:49 +0000146 no_dump_available = 0;
147 dump_regs(reg_table, i, j, port);
Uwe Hermann519419b2007-09-16 20:59:01 +0000148 }
Uwe Hermann25a6c0f2007-09-19 00:48:42 +0000149
Uwe Hermann2c290e32007-09-20 00:00:49 +0000150 if (no_dump_available)
151 printf("No dump available for this Super I/O\n");
Uwe Hermann519419b2007-09-16 20:59:01 +0000152 }
153}
154
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000155void probing_for(const char *vendor, const char *info, uint16_t port)
Uwe Hermann2c290e32007-09-20 00:00:49 +0000156{
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000157 if (!verbose)
158 return;
159
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000160 /* Yes, there's no space between '%s' and 'at'! */
161 printf("Probing for %s Super I/O %sat 0x%x...\n",
162 vendor, info, port);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000163}
164
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000165/** Print a list of all supported chips from the given vendor. */
166void print_vendor_chips(const char *vendor,
167 const struct superio_registers reg_table[])
168{
169 int i;
170
171 for (i = 0; reg_table[i].superio_id != EOT; i++) {
172 printf("%s %s", vendor, reg_table[i].name);
173
174 /* Unless the ldn is empty, assume this chip has a dump. */
175 if (reg_table[i].ldn[0].ldn != EOT)
176 printf(" (dump available)");
177
178 printf("\n");
179 }
180
181 /* If we printed any chips for this vendor, put in a blank line. */
182 if (i != 0)
183 printf("\n");
184}
185
186/** Print a list of all chips supported by superiotool. */
187void print_list_of_supported_chips(void)
188{
189 int i;
190
191 printf("Supported Super I/O chips:\n\n");
192
193 for (i = 0; i < ARRAY_SIZE(vendor_print_functions); i++)
194 vendor_print_functions[i].print_list();
195
196 printf("See <http://coreboot.org/Superiotool#Supported_devices> "
197 "for more information.\n");
198}
199
Robinson P. Tryonec1edd12007-10-02 23:32:21 +0000200static void print_version(void)
201{
Ulf Jordan39a5bf72007-10-13 18:06:12 +0000202 printf("superiotool r%s\n", SUPERIOTOOL_VERSION);
Robinson P. Tryonec1edd12007-10-02 23:32:21 +0000203}
204
Uwe Hermann2046ff92007-09-01 21:02:44 +0000205int main(int argc, char *argv[])
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000206{
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000207 int i, j, opt, option_index;
208
Uwe Hermann246be7d2007-10-31 22:22:11 +0000209 static const struct option long_options[] = {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000210 {"dump", no_argument, NULL, 'd'},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000211 {"list-supported", no_argument, NULL, 'l'},
Uwe Hermanneddc4732007-09-20 23:57:44 +0000212 {"verbose", no_argument, NULL, 'V'},
213 {"version", no_argument, NULL, 'v'},
214 {"help", no_argument, NULL, 'h'},
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000215 {0, 0, 0, 0}
216 };
217
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000218 while ((opt = getopt_long(argc, argv, "dlVvh",
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000219 long_options, &option_index)) != EOF) {
220 switch (opt) {
221 case 'd':
222 dump = 1;
223 break;
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000224 case 'l':
225 print_list_of_supported_chips();
226 exit(0);
227 break;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000228 case 'V':
229 verbose = 1;
230 break;
231 case 'v':
Robinson P. Tryonec1edd12007-10-02 23:32:21 +0000232 print_version();
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000233 exit(0);
234 break;
235 case 'h':
Uwe Hermanne4749562007-09-19 16:26:18 +0000236 printf(USAGE);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000237 exit(0);
238 break;
239 default:
240 /* Unknown option. */
241 exit(1);
242 break;
243 }
244 }
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000245
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000246 if (iopl(3) < 0) {
247 perror("iopl");
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000248 printf("Superiotool must be run as root.\n");
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000249 exit(1);
250 }
251
Uwe Hermannd937b522007-10-17 23:42:02 +0000252 print_version();
253
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000254 for (i = 0; i < ARRAY_SIZE(superio_ports_table); i++) {
255 for (j = 0; superio_ports_table[i].ports[j] != EOT; j++)
256 superio_ports_table[i].probe_idregs(
257 superio_ports_table[i].ports[j]);
258 }
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000259
Uwe Hermanne9d46162007-10-07 20:01:23 +0000260 if (!chip_found)
261 printf("No Super I/O found\n");
262
Stefan Reinauer6a5bc462007-01-17 10:57:42 +0000263 return 0;
Ronald G. Minnich394e7c42006-02-22 22:12:21 +0000264}