blob: 8c015597598672f03701c5d39c6f3c37a74f8f9c [file] [log] [blame]
Patrick Georgi7333a112020-05-08 20:48:04 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann0120e1a2007-09-16 18:11:03 +00002
3#ifndef SUPERIOTOOL_H
4#define SUPERIOTOOL_H
5
6#include <stdio.h>
7#include <stdlib.h>
Uwe Hermann6ff6af72007-09-18 22:24:34 +00008#include <stdint.h>
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +00009#include <string.h>
Uwe Hermann3acf31e2007-09-19 01:55:35 +000010#include <getopt.h>
Fabian Groffen318ddb82023-03-10 18:12:25 +010011#if defined(__linux__)
Uwe Hermann0120e1a2007-09-16 18:11:03 +000012#include <sys/io.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000013#endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000014#if (defined(__MACH__) && defined(__APPLE__))
Paul Menzela8843de2017-06-05 12:33:23 +020015/* DirectHW is available here: https://www.coreboot.org/DirectHW */
Stefan Reinauercff573d2011-03-18 22:08:39 +000016#include <DirectHW/DirectHW.h>
Stefan Reinauere95eb612009-09-01 09:57:55 +000017#endif
Andriy Gaponb64aa602008-10-28 22:13:38 +000018
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000019#ifdef PCI_SUPPORT
Andrey Korolyovdecefea2016-01-04 02:20:04 +030020# ifdef __NetBSD__
21#include <pciutils/pci.h>
22# else
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000023#include <pci/pci.h>
Andrey Korolyovdecefea2016-01-04 02:20:04 +030024# endif
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000025#endif
26
Fabian Groffen318ddb82023-03-10 18:12:25 +010027#include <sys/types.h>
28#include <stdint.h>
29
Andriy Gaponb64aa602008-10-28 22:13:38 +000030#if defined(__FreeBSD__)
31#include <sys/types.h>
32#include <machine/cpufunc.h>
33#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
34#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
35#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
36#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
37#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
38#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
39#else
40#define OUTB outb
41#define OUTW outw
42#define OUTL outl
43#define INB inb
44#define INW inw
45#define INL inl
46#endif
Uwe Hermann0120e1a2007-09-16 18:11:03 +000047
Jonathan Kollasch760498f2010-10-24 14:18:55 +000048#if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000049#include <sys/types.h>
50#include <machine/sysarch.h>
51#if defined(__i386__)
52#define iopl i386_iopl
53#elif defined(__x86_64__)
54#define iopl x86_64_iopl
55#endif
56
57static __inline__ void
58outb(uint8_t value, uint16_t port)
59{
60 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
61}
62
63static __inline__ void
64outw(uint16_t value, uint16_t port)
65{
66 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
67}
68
69static __inline__ void
70outl(uint32_t value, uint16_t port)
71{
72 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
73}
74
75static __inline__ uint8_t inb(uint16_t port)
76{
77 uint8_t value;
78 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
79 return value;
80}
81
82static __inline__ uint16_t inw(uint16_t port)
83{
84 uint16_t value;
85 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
86 return value;
87}
88
89static __inline__ uint32_t inl(uint16_t port)
90{
91 uint32_t value;
92 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
93 return value;
94}
95#endif
96
Nico Huber3812a722016-10-12 12:12:51 +020097#define USAGE "Usage: superiotool [-d] [-e] [-a] [-l] [-V] [-v] [-h]\n\n\
Uwe Hermann74b29b92007-11-17 17:13:52 +000098 -d | --dump Dump Super I/O register contents\n\
Uwe Hermanneec5ff42008-03-01 18:49:39 +000099 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
Nico Huber3812a722016-10-12 12:12:51 +0200100 -a | --alternate-dump Use alternative dump format, more suitable for diff\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000101 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +0000102 -V | --verbose Verbose mode\n\
103 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000104 -h | --help Show a short help text\n\n"
105
106#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000107Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000108and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000109
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000110#define NOTFOUND " Failed. Returned data: "
111
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000112#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
113
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000114#define EOT -1 /* End Of Table */
115#define NOLDN -2 /* NO LDN needed */
Felix Helde5b05d62019-06-11 19:23:55 +0200116#define NANA -3 /* Not Available:
117 Used for registers having externally controlled
118 values that can change during runtime like
119 GPIO input value registers. */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000120#define RSVD -4 /* Reserved */
Felix Helde5b05d62019-06-11 19:23:55 +0200121#define MISC -5 /* Needs special comment in output:
122 Used for registers depending on external pin straps
123 configuring static, but board-specific settings like
124 SIO base address or AMD/Intel power seqencing type. */
Tom Sylla92af5092008-06-07 11:36:30 +0000125#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000126#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000127#define MAXNUMIDX 170 /* Maximum number of indices */
Elyes HAOUASb9585c52018-05-29 22:23:48 +0200128#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000129#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000130
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000131/* Select registers for various components. */
132#define LDN_SEL 0x07 /* LDN select register */
133#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
134
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000135/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000136extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000137
Uwe Hermanne9d46162007-10-07 20:01:23 +0000138extern int chip_found;
139
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000140struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000141 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000142 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000143 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000144 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000145 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000146 int16_t idx[IDXSIZE];
147 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000148 } ldn[LDNSIZE];
149};
150
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000151/* pci.c */
152#ifdef PCI_SUPPORT
153extern struct pci_access *pacc;
154struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
155#endif
156
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000157/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000158uint8_t regval(uint16_t port, uint8_t reg);
159void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000160void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
161void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000162void enter_conf_mode_fintek_7777(uint16_t port);
163void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000164int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000165const char *get_superio_name(const struct superio_registers reg_table[],
166 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000167void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000168 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000169void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700170void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000171void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000172void print_vendor_chips(const char *vendor,
173 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000174
Uwe Hermann945045b2007-09-28 15:39:10 +0000175/* ali.c */
176void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000177void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000178
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200179/* aspeed.c */
180void probe_idregs_aspeed(uint16_t port);
181void print_aspeed_chips(void);
182
Rudolf Marek113c3492011-10-27 20:42:11 +0200183/* amd.c */
184void probe_idregs_amd(uint16_t port);
185void print_amd_chips(void);
186
Ruud Schramp18b02362011-04-11 07:46:27 +0000187/* serverengines.c */
188void probe_idregs_serverengines(uint16_t port);
189void print_serverengines_chips(void);
190
Derek Waldner3b421192016-04-14 12:13:48 -0500191/* exar.c */
192void probe_idregs_exar(uint16_t port);
193void print_exar_chips(void);
194
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000195/* fintek.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000196void probe_idregs_fintek(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000197void probe_idregs_fintek_alternative(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000198void print_fintek_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000199
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600200/* infineon.c */
201void probe_idregs_infineon(uint16_t port);
202void print_infineon_chips(void);
203
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000204/* ite.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000205void probe_idregs_ite(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000206void print_ite_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000207
208/* nsc.c */
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000209void probe_idregs_nsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000210void print_nsc_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000211
David Hendrickse1822d92010-07-22 22:56:44 +0000212/* nuvoton.c */
213void probe_idregs_nuvoton(uint16_t port);
214void print_nuvoton_chips(void);
215
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000216/* smsc.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000217void probe_idregs_smsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000218void print_smsc_chips(void);
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000219
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000220/* winbond.c */
221void probe_idregs_winbond(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000222void print_winbond_chips(void);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000223
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000224/* via.c */
225#ifdef PCI_SUPPORT
226void probe_idregs_via(uint16_t port);
227void print_via_chips(void);
228#endif
229
Uwe Hermannc3da3662007-09-26 16:14:16 +0000230/** Table of which config ports to probe for each Super I/O family. */
Uwe Hermann246be7d2007-10-31 22:22:11 +0000231static const struct {
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000232 void (*probe_idregs) (uint16_t port);
233 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000234} superio_ports_table[] = {
Uwe Hermann945045b2007-09-28 15:39:10 +0000235 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200236 {probe_idregs_aspeed, {0x2e, 0x4e, EOT}},
Derek Waldner3b421192016-04-14 12:13:48 -0500237 {probe_idregs_exar, {0x2e, 0x4e, EOT}},
Uwe Hermann0f867322007-09-24 01:40:09 +0000238 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000239 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
Urja Rannikko38204a22008-10-23 23:33:18 +0000240 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
Patrick Rudolph6085d392019-01-09 16:42:07 +0100241 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, 0x6e, EOT}},
Sven Schnelleed61c4a2011-02-02 23:49:41 +0000242 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
David Hendrickse1822d92010-07-22 22:56:44 +0000243 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
244 * addition to the following hardware strapping options. */
Stefan Reinauer3187d022011-04-22 23:12:40 +0000245 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
Uwe Hermann14f304a2007-10-08 01:11:11 +0000246 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
Uwe Hermannc3da3662007-09-26 16:14:16 +0000247 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000248#ifdef PCI_SUPPORT
Lubomir Rintel2f6a29e2017-10-31 09:25:05 +0100249 {probe_idregs_via, {0x2e, 0x4e, 0x3f0, EOT}},
Rudolf Marek113c3492011-10-27 20:42:11 +0200250 /* in fact read the BASE from HW */
251 {probe_idregs_amd, {0xaa, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000252#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000253 {probe_idregs_serverengines, {0x2e, EOT}},
Jonathan A. Kollaschcb34bba2012-01-02 19:11:49 -0600254 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000255};
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000256
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000257/** Table of functions to print out supported Super I/O chips. */
258static const struct {
259 void (*print_list) (void);
260} vendor_print_functions[] = {
261 {print_ali_chips},
Derek Waldner3b421192016-04-14 12:13:48 -0500262 {print_exar_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000263 {print_fintek_chips},
264 {print_ite_chips},
265 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000266 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000267 {print_smsc_chips},
268 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000269#ifdef PCI_SUPPORT
270 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200271 {print_amd_chips},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200272 {print_aspeed_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000273#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000274 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600275 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000276};
277
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000278#endif