blob: 14090309ee0690f994525f41d11b0a19cbfec112 [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>
Konrad Adamczykd6b4db12023-04-11 10:26:12 +000011#include <commonlib/bsd/helpers.h>
Fabian Groffen318ddb82023-03-10 18:12:25 +010012#if defined(__linux__)
Uwe Hermann0120e1a2007-09-16 18:11:03 +000013#include <sys/io.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000014#endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000015#if (defined(__MACH__) && defined(__APPLE__))
Paul Menzela8843de2017-06-05 12:33:23 +020016/* DirectHW is available here: https://www.coreboot.org/DirectHW */
Stefan Reinauercff573d2011-03-18 22:08:39 +000017#include <DirectHW/DirectHW.h>
Stefan Reinauere95eb612009-09-01 09:57:55 +000018#endif
Andriy Gaponb64aa602008-10-28 22:13:38 +000019
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000020#ifdef PCI_SUPPORT
Andrey Korolyovdecefea2016-01-04 02:20:04 +030021# ifdef __NetBSD__
22#include <pciutils/pci.h>
23# else
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000024#include <pci/pci.h>
Andrey Korolyovdecefea2016-01-04 02:20:04 +030025# endif
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000026#endif
27
Fabian Groffen318ddb82023-03-10 18:12:25 +010028#include <sys/types.h>
29#include <stdint.h>
30
Andriy Gaponb64aa602008-10-28 22:13:38 +000031#if defined(__FreeBSD__)
32#include <sys/types.h>
33#include <machine/cpufunc.h>
34#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
35#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
36#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
37#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
38#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
39#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
40#else
41#define OUTB outb
42#define OUTW outw
43#define OUTL outl
44#define INB inb
45#define INW inw
46#define INL inl
47#endif
Uwe Hermann0120e1a2007-09-16 18:11:03 +000048
Jonathan Kollasch760498f2010-10-24 14:18:55 +000049#if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000050#include <sys/types.h>
51#include <machine/sysarch.h>
52#if defined(__i386__)
53#define iopl i386_iopl
54#elif defined(__x86_64__)
55#define iopl x86_64_iopl
56#endif
57
58static __inline__ void
59outb(uint8_t value, uint16_t port)
60{
61 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
62}
63
64static __inline__ void
65outw(uint16_t value, uint16_t port)
66{
67 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
68}
69
70static __inline__ void
71outl(uint32_t value, uint16_t port)
72{
73 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
74}
75
76static __inline__ uint8_t inb(uint16_t port)
77{
78 uint8_t value;
79 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
80 return value;
81}
82
83static __inline__ uint16_t inw(uint16_t port)
84{
85 uint16_t value;
86 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
87 return value;
88}
89
90static __inline__ uint32_t inl(uint16_t port)
91{
92 uint32_t value;
93 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
94 return value;
95}
96#endif
97
Nico Huber3812a722016-10-12 12:12:51 +020098#define USAGE "Usage: superiotool [-d] [-e] [-a] [-l] [-V] [-v] [-h]\n\n\
Uwe Hermann74b29b92007-11-17 17:13:52 +000099 -d | --dump Dump Super I/O register contents\n\
Uwe Hermanneec5ff42008-03-01 18:49:39 +0000100 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
Nico Huber3812a722016-10-12 12:12:51 +0200101 -a | --alternate-dump Use alternative dump format, more suitable for diff\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000102 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +0000103 -V | --verbose Verbose mode\n\
104 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000105 -h | --help Show a short help text\n\n"
106
107#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000108Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000109and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000110
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000111#define NOTFOUND " Failed. Returned data: "
112
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000113#define EOT -1 /* End Of Table */
114#define NOLDN -2 /* NO LDN needed */
Felix Helde5b05d62019-06-11 19:23:55 +0200115#define NANA -3 /* Not Available:
116 Used for registers having externally controlled
117 values that can change during runtime like
118 GPIO input value registers. */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000119#define RSVD -4 /* Reserved */
Felix Helde5b05d62019-06-11 19:23:55 +0200120#define MISC -5 /* Needs special comment in output:
121 Used for registers depending on external pin straps
122 configuring static, but board-specific settings like
123 SIO base address or AMD/Intel power seqencing type. */
Tom Sylla92af5092008-06-07 11:36:30 +0000124#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000125#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000126#define MAXNUMIDX 170 /* Maximum number of indices */
Elyes HAOUASb9585c52018-05-29 22:23:48 +0200127#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000128#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000129
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000130/* Select registers for various components. */
131#define LDN_SEL 0x07 /* LDN select register */
132#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
133
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000134/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000135extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000136
Uwe Hermanne9d46162007-10-07 20:01:23 +0000137extern int chip_found;
138
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000139struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000140 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000141 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000142 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000143 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000144 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000145 int16_t idx[IDXSIZE];
146 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000147 } ldn[LDNSIZE];
148};
149
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000150/* pci.c */
151#ifdef PCI_SUPPORT
152extern struct pci_access *pacc;
153struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
154#endif
155
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000156/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000157uint8_t regval(uint16_t port, uint8_t reg);
158void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000159void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
160void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000161void enter_conf_mode_fintek_7777(uint16_t port);
162void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000163int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000164const char *get_superio_name(const struct superio_registers reg_table[],
165 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000166void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000167 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000168void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700169void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000170void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000171void print_vendor_chips(const char *vendor,
172 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000173
Uwe Hermann945045b2007-09-28 15:39:10 +0000174/* ali.c */
175void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000176void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000177
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200178/* aspeed.c */
179void probe_idregs_aspeed(uint16_t port);
180void print_aspeed_chips(void);
181
Rudolf Marek113c3492011-10-27 20:42:11 +0200182/* amd.c */
183void probe_idregs_amd(uint16_t port);
184void print_amd_chips(void);
185
Ruud Schramp18b02362011-04-11 07:46:27 +0000186/* serverengines.c */
187void probe_idregs_serverengines(uint16_t port);
188void print_serverengines_chips(void);
189
Derek Waldner3b421192016-04-14 12:13:48 -0500190/* exar.c */
191void probe_idregs_exar(uint16_t port);
192void print_exar_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}},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200235 {probe_idregs_aspeed, {0x2e, 0x4e, EOT}},
Derek Waldner3b421192016-04-14 12:13:48 -0500236 {probe_idregs_exar, {0x2e, 0x4e, EOT}},
Uwe Hermann0f867322007-09-24 01:40:09 +0000237 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000238 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
Urja Rannikko38204a22008-10-23 23:33:18 +0000239 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
Patrick Rudolph6085d392019-01-09 16:42:07 +0100240 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, 0x6e, EOT}},
Sven Schnelleed61c4a2011-02-02 23:49:41 +0000241 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
David Hendrickse1822d92010-07-22 22:56:44 +0000242 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
243 * addition to the following hardware strapping options. */
Stefan Reinauer3187d022011-04-22 23:12:40 +0000244 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
Uwe Hermann14f304a2007-10-08 01:11:11 +0000245 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
Uwe Hermannc3da3662007-09-26 16:14:16 +0000246 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000247#ifdef PCI_SUPPORT
Lubomir Rintel2f6a29e2017-10-31 09:25:05 +0100248 {probe_idregs_via, {0x2e, 0x4e, 0x3f0, EOT}},
Rudolf Marek113c3492011-10-27 20:42:11 +0200249 /* in fact read the BASE from HW */
250 {probe_idregs_amd, {0xaa, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000251#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000252 {probe_idregs_serverengines, {0x2e, EOT}},
Jonathan A. Kollaschcb34bba2012-01-02 19:11:49 -0600253 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000254};
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000255
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000256/** Table of functions to print out supported Super I/O chips. */
257static const struct {
258 void (*print_list) (void);
259} vendor_print_functions[] = {
260 {print_ali_chips},
Derek Waldner3b421192016-04-14 12:13:48 -0500261 {print_exar_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000262 {print_fintek_chips},
263 {print_ite_chips},
264 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000265 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000266 {print_smsc_chips},
267 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000268#ifdef PCI_SUPPORT
269 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200270 {print_amd_chips},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200271 {print_aspeed_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000272#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000273 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600274 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000275};
276
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000277#endif