blob: a621ae5274abd23cb6507e26641bb9aa935e115e [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>
Andriy Gaponb64aa602008-10-28 22:13:38 +000011#if defined(__GLIBC__)
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
Andriy Gaponb64aa602008-10-28 22:13:38 +000027#if defined(__FreeBSD__)
28#include <sys/types.h>
29#include <machine/cpufunc.h>
30#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
31#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
32#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
33#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
34#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
35#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
36#else
37#define OUTB outb
38#define OUTW outw
39#define OUTL outl
40#define INB inb
41#define INW inw
42#define INL inl
43#endif
Uwe Hermann0120e1a2007-09-16 18:11:03 +000044
Jonathan Kollasch760498f2010-10-24 14:18:55 +000045#if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000046#include <sys/types.h>
47#include <machine/sysarch.h>
48#if defined(__i386__)
49#define iopl i386_iopl
50#elif defined(__x86_64__)
51#define iopl x86_64_iopl
52#endif
53
54static __inline__ void
55outb(uint8_t value, uint16_t port)
56{
57 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
58}
59
60static __inline__ void
61outw(uint16_t value, uint16_t port)
62{
63 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
64}
65
66static __inline__ void
67outl(uint32_t value, uint16_t port)
68{
69 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
70}
71
72static __inline__ uint8_t inb(uint16_t port)
73{
74 uint8_t value;
75 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
76 return value;
77}
78
79static __inline__ uint16_t inw(uint16_t port)
80{
81 uint16_t value;
82 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
83 return value;
84}
85
86static __inline__ uint32_t inl(uint16_t port)
87{
88 uint32_t value;
89 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
90 return value;
91}
92#endif
93
Nico Huber3812a722016-10-12 12:12:51 +020094#define USAGE "Usage: superiotool [-d] [-e] [-a] [-l] [-V] [-v] [-h]\n\n\
Uwe Hermann74b29b92007-11-17 17:13:52 +000095 -d | --dump Dump Super I/O register contents\n\
Uwe Hermanneec5ff42008-03-01 18:49:39 +000096 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
Nico Huber3812a722016-10-12 12:12:51 +020097 -a | --alternate-dump Use alternative dump format, more suitable for diff\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +000098 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +000099 -V | --verbose Verbose mode\n\
100 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000101 -h | --help Show a short help text\n\n"
102
103#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000104Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000105and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000106
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000107#define NOTFOUND " Failed. Returned data: "
108
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000109#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
110
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000111#define EOT -1 /* End Of Table */
112#define NOLDN -2 /* NO LDN needed */
Felix Helde5b05d62019-06-11 19:23:55 +0200113#define NANA -3 /* Not Available:
114 Used for registers having externally controlled
115 values that can change during runtime like
116 GPIO input value registers. */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000117#define RSVD -4 /* Reserved */
Felix Helde5b05d62019-06-11 19:23:55 +0200118#define MISC -5 /* Needs special comment in output:
119 Used for registers depending on external pin straps
120 configuring static, but board-specific settings like
121 SIO base address or AMD/Intel power seqencing type. */
Tom Sylla92af5092008-06-07 11:36:30 +0000122#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000123#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000124#define MAXNUMIDX 170 /* Maximum number of indices */
Elyes HAOUASb9585c52018-05-29 22:23:48 +0200125#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000126#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000127
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000128/* Select registers for various components. */
129#define LDN_SEL 0x07 /* LDN select register */
130#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
131
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000132/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000133extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000134
Uwe Hermanne9d46162007-10-07 20:01:23 +0000135extern int chip_found;
136
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000137struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000138 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000139 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000140 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000141 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000142 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000143 int16_t idx[IDXSIZE];
144 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000145 } ldn[LDNSIZE];
146};
147
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000148/* pci.c */
149#ifdef PCI_SUPPORT
150extern struct pci_access *pacc;
151struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
152#endif
153
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000154/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000155uint8_t regval(uint16_t port, uint8_t reg);
156void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000157void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
158void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000159void enter_conf_mode_fintek_7777(uint16_t port);
160void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000161int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000162const char *get_superio_name(const struct superio_registers reg_table[],
163 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000164void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000165 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000166void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700167void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000168void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000169void print_vendor_chips(const char *vendor,
170 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000171
Uwe Hermann945045b2007-09-28 15:39:10 +0000172/* ali.c */
173void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000174void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000175
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200176/* aspeed.c */
177void probe_idregs_aspeed(uint16_t port);
178void print_aspeed_chips(void);
179
Rudolf Marek113c3492011-10-27 20:42:11 +0200180/* amd.c */
181void probe_idregs_amd(uint16_t port);
182void print_amd_chips(void);
183
Ruud Schramp18b02362011-04-11 07:46:27 +0000184/* serverengines.c */
185void probe_idregs_serverengines(uint16_t port);
186void print_serverengines_chips(void);
187
Derek Waldner3b421192016-04-14 12:13:48 -0500188/* exar.c */
189void probe_idregs_exar(uint16_t port);
190void print_exar_chips(void);
191
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000192/* fintek.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000193void probe_idregs_fintek(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000194void probe_idregs_fintek_alternative(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000195void print_fintek_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000196
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600197/* infineon.c */
198void probe_idregs_infineon(uint16_t port);
199void print_infineon_chips(void);
200
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000201/* ite.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000202void probe_idregs_ite(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000203void print_ite_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000204
205/* nsc.c */
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000206void probe_idregs_nsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000207void print_nsc_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000208
David Hendrickse1822d92010-07-22 22:56:44 +0000209/* nuvoton.c */
210void probe_idregs_nuvoton(uint16_t port);
211void print_nuvoton_chips(void);
212
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000213/* smsc.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000214void probe_idregs_smsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000215void print_smsc_chips(void);
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000216
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000217/* winbond.c */
218void probe_idregs_winbond(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000219void print_winbond_chips(void);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000220
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000221/* via.c */
222#ifdef PCI_SUPPORT
223void probe_idregs_via(uint16_t port);
224void print_via_chips(void);
225#endif
226
Uwe Hermannc3da3662007-09-26 16:14:16 +0000227/** Table of which config ports to probe for each Super I/O family. */
Uwe Hermann246be7d2007-10-31 22:22:11 +0000228static const struct {
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000229 void (*probe_idregs) (uint16_t port);
230 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000231} superio_ports_table[] = {
Uwe Hermann945045b2007-09-28 15:39:10 +0000232 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200233 {probe_idregs_aspeed, {0x2e, 0x4e, EOT}},
Derek Waldner3b421192016-04-14 12:13:48 -0500234 {probe_idregs_exar, {0x2e, 0x4e, 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. */
Patrick Rudolph6085d392019-01-09 16:42:07 +0100238 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, 0x6e, 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
Lubomir Rintel2f6a29e2017-10-31 09:25:05 +0100246 {probe_idregs_via, {0x2e, 0x4e, 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},
Derek Waldner3b421192016-04-14 12:13:48 -0500259 {print_exar_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000260 {print_fintek_chips},
261 {print_ite_chips},
262 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000263 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000264 {print_smsc_chips},
265 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000266#ifdef PCI_SUPPORT
267 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200268 {print_amd_chips},
Patrick Rudolph674bb3b2019-05-24 09:07:04 +0200269 {print_aspeed_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000270#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000271 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600272 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000273};
274
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000275#endif