blob: 46f11a79852fb2e335db0da59a05a45d9e5989ef [file] [log] [blame]
Uwe Hermann0120e1a2007-09-16 18:11:03 +00001/*
Uwe Hermannafe83092007-09-28 15:45:43 +00002 * This file is part of the superiotool project.
Uwe Hermann0120e1a2007-09-16 18:11:03 +00003 *
Uwe Hermann4cb7e712007-09-16 18:17:44 +00004 * Copyright (C) 2007 Carl-Daniel Hailfinger
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +00005 * Copyright (C) 2007-2010 Uwe Hermann <uwe@hermann-uwe.de>
Robinson P. Tryon552cfb72008-01-15 22:30:55 +00006 * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
Stefan Reinauere95eb612009-09-01 09:57:55 +00007 * Copyright (C) 2008-2009 coresystems GmbH
Uwe Hermann0120e1a2007-09-16 18:11:03 +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
Paul Menzela46a7122013-02-23 18:37:27 +010021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Uwe Hermann0120e1a2007-09-16 18:11:03 +000022 */
23
24#ifndef SUPERIOTOOL_H
25#define SUPERIOTOOL_H
26
27#include <stdio.h>
28#include <stdlib.h>
Uwe Hermann6ff6af72007-09-18 22:24:34 +000029#include <stdint.h>
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +000030#include <string.h>
Uwe Hermann3acf31e2007-09-19 01:55:35 +000031#include <getopt.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000032#if defined(__GLIBC__)
Uwe Hermann0120e1a2007-09-16 18:11:03 +000033#include <sys/io.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000034#endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000035#if (defined(__MACH__) && defined(__APPLE__))
Stefan Reinauercff573d2011-03-18 22:08:39 +000036/* DirectHW is available here: http://www.coreboot.org/DirectHW */
37#include <DirectHW/DirectHW.h>
Stefan Reinauere95eb612009-09-01 09:57:55 +000038#endif
Andriy Gaponb64aa602008-10-28 22:13:38 +000039
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000040#ifdef PCI_SUPPORT
41#include <pci/pci.h>
42#endif
43
Andriy Gaponb64aa602008-10-28 22:13:38 +000044#if defined(__FreeBSD__)
45#include <sys/types.h>
46#include <machine/cpufunc.h>
47#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
48#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
49#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
50#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
51#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
52#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
53#else
54#define OUTB outb
55#define OUTW outw
56#define OUTL outl
57#define INB inb
58#define INW inw
59#define INL inl
60#endif
Uwe Hermann0120e1a2007-09-16 18:11:03 +000061
Jonathan Kollasch760498f2010-10-24 14:18:55 +000062#if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000063#include <sys/types.h>
64#include <machine/sysarch.h>
65#if defined(__i386__)
66#define iopl i386_iopl
67#elif defined(__x86_64__)
68#define iopl x86_64_iopl
69#endif
70
71static __inline__ void
72outb(uint8_t value, uint16_t port)
73{
74 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
75}
76
77static __inline__ void
78outw(uint16_t value, uint16_t port)
79{
80 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
81}
82
83static __inline__ void
84outl(uint32_t value, uint16_t port)
85{
86 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
87}
88
89static __inline__ uint8_t inb(uint16_t port)
90{
91 uint8_t value;
92 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
93 return value;
94}
95
96static __inline__ uint16_t inw(uint16_t port)
97{
98 uint16_t value;
99 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
100 return value;
101}
102
103static __inline__ uint32_t inl(uint16_t port)
104{
105 uint32_t value;
106 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
107 return value;
108}
109#endif
110
Uwe Hermanneec5ff42008-03-01 18:49:39 +0000111#define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\
Uwe Hermann74b29b92007-11-17 17:13:52 +0000112 -d | --dump Dump Super I/O register contents\n\
Uwe Hermanneec5ff42008-03-01 18:49:39 +0000113 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000114 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +0000115 -V | --verbose Verbose mode\n\
116 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000117 -h | --help Show a short help text\n\n"
118
119#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000120Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000121and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000122
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000123#define NOTFOUND " Failed. Returned data: "
124
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000125#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
126
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000127#define EOT -1 /* End Of Table */
128#define NOLDN -2 /* NO LDN needed */
129#define NANA -3 /* Not Available */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000130#define RSVD -4 /* Reserved */
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000131#define MISC -5 /* Needs special comment in output */
Tom Sylla92af5092008-06-07 11:36:30 +0000132#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000133#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000134#define MAXNUMIDX 170 /* Maximum number of indices */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000135#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000136#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000137
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000138/* Select registers for various components. */
139#define LDN_SEL 0x07 /* LDN select register */
140#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
141
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000142/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000143extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000144
Uwe Hermanne9d46162007-10-07 20:01:23 +0000145extern int chip_found;
146
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000147struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000148 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000149 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000150 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000151 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000152 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000153 int16_t idx[IDXSIZE];
154 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000155 } ldn[LDNSIZE];
156};
157
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000158/* pci.c */
159#ifdef PCI_SUPPORT
160extern struct pci_access *pacc;
161struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
162#endif
163
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000164/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000165uint8_t regval(uint16_t port, uint8_t reg);
166void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000167void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
168void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000169void enter_conf_mode_fintek_7777(uint16_t port);
170void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000171int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000172const char *get_superio_name(const struct superio_registers reg_table[],
173 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000174void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000175 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000176void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700177void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000178void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000179void print_vendor_chips(const char *vendor,
180 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000181
Uwe Hermann945045b2007-09-28 15:39:10 +0000182/* ali.c */
183void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000184void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000185
Rudolf Marek113c3492011-10-27 20:42:11 +0200186/* amd.c */
187void probe_idregs_amd(uint16_t port);
188void print_amd_chips(void);
189
Ruud Schramp18b02362011-04-11 07:46:27 +0000190/* serverengines.c */
191void probe_idregs_serverengines(uint16_t port);
192void print_serverengines_chips(void);
193
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000194/* fintek.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000195void probe_idregs_fintek(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000196void probe_idregs_fintek_alternative(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000197void print_fintek_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000198
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600199/* infineon.c */
200void probe_idregs_infineon(uint16_t port);
201void print_infineon_chips(void);
202
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000203/* ite.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000204void probe_idregs_ite(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000205void print_ite_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000206
207/* nsc.c */
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000208void probe_idregs_nsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000209void print_nsc_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000210
David Hendrickse1822d92010-07-22 22:56:44 +0000211/* nuvoton.c */
212void probe_idregs_nuvoton(uint16_t port);
213void print_nuvoton_chips(void);
214
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000215/* smsc.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000216void probe_idregs_smsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000217void print_smsc_chips(void);
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000218
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000219/* winbond.c */
220void probe_idregs_winbond(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000221void print_winbond_chips(void);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000222
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000223/* via.c */
224#ifdef PCI_SUPPORT
225void probe_idregs_via(uint16_t port);
226void print_via_chips(void);
227#endif
228
Uwe Hermannc3da3662007-09-26 16:14:16 +0000229/** Table of which config ports to probe for each Super I/O family. */
Uwe Hermann246be7d2007-10-31 22:22:11 +0000230static const struct {
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000231 void (*probe_idregs) (uint16_t port);
232 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000233} superio_ports_table[] = {
Uwe Hermann945045b2007-09-28 15:39:10 +0000234 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
Uwe Hermann0f867322007-09-24 01:40:09 +0000235 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000236 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
Urja Rannikko38204a22008-10-23 23:33:18 +0000237 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
Nico Huber28a13242013-04-25 15:10:46 +0200238 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, EOT}},
Sven Schnelleed61c4a2011-02-02 23:49:41 +0000239 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
David Hendrickse1822d92010-07-22 22:56:44 +0000240 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
241 * addition to the following hardware strapping options. */
Stefan Reinauer3187d022011-04-22 23:12:40 +0000242 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
Uwe Hermann14f304a2007-10-08 01:11:11 +0000243 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
Uwe Hermannc3da3662007-09-26 16:14:16 +0000244 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000245#ifdef PCI_SUPPORT
246 {probe_idregs_via, {0x3f0, EOT}},
Rudolf Marek113c3492011-10-27 20:42:11 +0200247 /* in fact read the BASE from HW */
248 {probe_idregs_amd, {0xaa, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000249#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000250 {probe_idregs_serverengines, {0x2e, EOT}},
Jonathan A. Kollaschcb34bba2012-01-02 19:11:49 -0600251 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000252};
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000253
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000254/** Table of functions to print out supported Super I/O chips. */
255static const struct {
256 void (*print_list) (void);
257} vendor_print_functions[] = {
258 {print_ali_chips},
259 {print_fintek_chips},
260 {print_ite_chips},
261 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000262 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000263 {print_smsc_chips},
264 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000265#ifdef PCI_SUPPORT
266 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200267 {print_amd_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000268#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000269 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600270 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000271};
272
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000273#endif