blob: 92bb4eade6ad1031408151567a8a0046756ecf94 [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.
Uwe Hermann0120e1a2007-09-16 18:11:03 +000018 */
19
20#ifndef SUPERIOTOOL_H
21#define SUPERIOTOOL_H
22
23#include <stdio.h>
24#include <stdlib.h>
Uwe Hermann6ff6af72007-09-18 22:24:34 +000025#include <stdint.h>
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +000026#include <string.h>
Uwe Hermann3acf31e2007-09-19 01:55:35 +000027#include <getopt.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000028#if defined(__GLIBC__)
Uwe Hermann0120e1a2007-09-16 18:11:03 +000029#include <sys/io.h>
Andriy Gaponb64aa602008-10-28 22:13:38 +000030#endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000031#if (defined(__MACH__) && defined(__APPLE__))
Stefan Reinauercff573d2011-03-18 22:08:39 +000032/* DirectHW is available here: http://www.coreboot.org/DirectHW */
33#include <DirectHW/DirectHW.h>
Stefan Reinauere95eb612009-09-01 09:57:55 +000034#endif
Andriy Gaponb64aa602008-10-28 22:13:38 +000035
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000036#ifdef PCI_SUPPORT
Andrey Korolyovdecefea2016-01-04 02:20:04 +030037# ifdef __NetBSD__
38#include <pciutils/pci.h>
39# else
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000040#include <pci/pci.h>
Andrey Korolyovdecefea2016-01-04 02:20:04 +030041# endif
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000042#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
Nico Huber3812a722016-10-12 12:12:51 +0200111#define USAGE "Usage: superiotool [-d] [-e] [-a] [-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\
Nico Huber3812a722016-10-12 12:12:51 +0200114 -a | --alternate-dump Use alternative dump format, more suitable for diff\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000115 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +0000116 -V | --verbose Verbose mode\n\
117 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000118 -h | --help Show a short help text\n\n"
119
120#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000121Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000122and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000123
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000124#define NOTFOUND " Failed. Returned data: "
125
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000126#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
127
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000128#define EOT -1 /* End Of Table */
129#define NOLDN -2 /* NO LDN needed */
130#define NANA -3 /* Not Available */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000131#define RSVD -4 /* Reserved */
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000132#define MISC -5 /* Needs special comment in output */
Tom Sylla92af5092008-06-07 11:36:30 +0000133#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000134#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000135#define MAXNUMIDX 170 /* Maximum number of indices */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000136#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000137#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000138
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000139/* Select registers for various components. */
140#define LDN_SEL 0x07 /* LDN select register */
141#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
142
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000143/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000144extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000145
Uwe Hermanne9d46162007-10-07 20:01:23 +0000146extern int chip_found;
147
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000148struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000149 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000150 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000151 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000152 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000153 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000154 int16_t idx[IDXSIZE];
155 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000156 } ldn[LDNSIZE];
157};
158
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000159/* pci.c */
160#ifdef PCI_SUPPORT
161extern struct pci_access *pacc;
162struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
163#endif
164
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000165/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000166uint8_t regval(uint16_t port, uint8_t reg);
167void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000168void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
169void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000170void enter_conf_mode_fintek_7777(uint16_t port);
171void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000172int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000173const char *get_superio_name(const struct superio_registers reg_table[],
174 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000175void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000176 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000177void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700178void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000179void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000180void print_vendor_chips(const char *vendor,
181 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000182
Uwe Hermann945045b2007-09-28 15:39:10 +0000183/* ali.c */
184void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000185void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000186
Rudolf Marek113c3492011-10-27 20:42:11 +0200187/* amd.c */
188void probe_idregs_amd(uint16_t port);
189void print_amd_chips(void);
190
Ruud Schramp18b02362011-04-11 07:46:27 +0000191/* serverengines.c */
192void probe_idregs_serverengines(uint16_t port);
193void print_serverengines_chips(void);
194
Derek Waldner3b421192016-04-14 12:13:48 -0500195/* exar.c */
196void probe_idregs_exar(uint16_t port);
197void print_exar_chips(void);
198
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000199/* fintek.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000200void probe_idregs_fintek(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000201void probe_idregs_fintek_alternative(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000202void print_fintek_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000203
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600204/* infineon.c */
205void probe_idregs_infineon(uint16_t port);
206void print_infineon_chips(void);
207
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000208/* ite.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000209void probe_idregs_ite(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000210void print_ite_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000211
212/* nsc.c */
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000213void probe_idregs_nsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000214void print_nsc_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000215
David Hendrickse1822d92010-07-22 22:56:44 +0000216/* nuvoton.c */
217void probe_idregs_nuvoton(uint16_t port);
218void print_nuvoton_chips(void);
219
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000220/* smsc.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000221void probe_idregs_smsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000222void print_smsc_chips(void);
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000223
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000224/* winbond.c */
225void probe_idregs_winbond(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000226void print_winbond_chips(void);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000227
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000228/* via.c */
229#ifdef PCI_SUPPORT
230void probe_idregs_via(uint16_t port);
231void print_via_chips(void);
232#endif
233
Uwe Hermannc3da3662007-09-26 16:14:16 +0000234/** Table of which config ports to probe for each Super I/O family. */
Uwe Hermann246be7d2007-10-31 22:22:11 +0000235static const struct {
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000236 void (*probe_idregs) (uint16_t port);
237 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000238} superio_ports_table[] = {
Uwe Hermann945045b2007-09-28 15:39:10 +0000239 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
Derek Waldner3b421192016-04-14 12:13:48 -0500240 {probe_idregs_exar, {0x2e, 0x4e, EOT}},
Uwe Hermann0f867322007-09-24 01:40:09 +0000241 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000242 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
Urja Rannikko38204a22008-10-23 23:33:18 +0000243 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
Nico Huber28a13242013-04-25 15:10:46 +0200244 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, EOT}},
Sven Schnelleed61c4a2011-02-02 23:49:41 +0000245 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
David Hendrickse1822d92010-07-22 22:56:44 +0000246 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
247 * addition to the following hardware strapping options. */
Stefan Reinauer3187d022011-04-22 23:12:40 +0000248 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
Uwe Hermann14f304a2007-10-08 01:11:11 +0000249 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
Uwe Hermannc3da3662007-09-26 16:14:16 +0000250 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000251#ifdef PCI_SUPPORT
252 {probe_idregs_via, {0x3f0, EOT}},
Rudolf Marek113c3492011-10-27 20:42:11 +0200253 /* in fact read the BASE from HW */
254 {probe_idregs_amd, {0xaa, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000255#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000256 {probe_idregs_serverengines, {0x2e, EOT}},
Jonathan A. Kollaschcb34bba2012-01-02 19:11:49 -0600257 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000258};
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000259
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000260/** Table of functions to print out supported Super I/O chips. */
261static const struct {
262 void (*print_list) (void);
263} vendor_print_functions[] = {
264 {print_ali_chips},
Derek Waldner3b421192016-04-14 12:13:48 -0500265 {print_exar_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000266 {print_fintek_chips},
267 {print_ite_chips},
268 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000269 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000270 {print_smsc_chips},
271 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000272#ifdef PCI_SUPPORT
273 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200274 {print_amd_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000275#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000276 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600277 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000278};
279
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000280#endif