blob: cc87a0ffa5936d023f88385f7fd7d72731664404 [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
37#include <pci/pci.h>
38#endif
39
Andriy Gaponb64aa602008-10-28 22:13:38 +000040#if defined(__FreeBSD__)
41#include <sys/types.h>
42#include <machine/cpufunc.h>
43#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
44#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
45#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
46#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
47#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
48#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
49#else
50#define OUTB outb
51#define OUTW outw
52#define OUTL outl
53#define INB inb
54#define INW inw
55#define INL inl
56#endif
Uwe Hermann0120e1a2007-09-16 18:11:03 +000057
Jonathan Kollasch760498f2010-10-24 14:18:55 +000058#if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000059#include <sys/types.h>
60#include <machine/sysarch.h>
61#if defined(__i386__)
62#define iopl i386_iopl
63#elif defined(__x86_64__)
64#define iopl x86_64_iopl
65#endif
66
67static __inline__ void
68outb(uint8_t value, uint16_t port)
69{
70 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
71}
72
73static __inline__ void
74outw(uint16_t value, uint16_t port)
75{
76 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
77}
78
79static __inline__ void
80outl(uint32_t value, uint16_t port)
81{
82 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
83}
84
85static __inline__ uint8_t inb(uint16_t port)
86{
87 uint8_t value;
88 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
89 return value;
90}
91
92static __inline__ uint16_t inw(uint16_t port)
93{
94 uint16_t value;
95 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
96 return value;
97}
98
99static __inline__ uint32_t inl(uint16_t port)
100{
101 uint32_t value;
102 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
103 return value;
104}
105#endif
106
Uwe Hermanneec5ff42008-03-01 18:49:39 +0000107#define USAGE "Usage: superiotool [-d] [-e] [-l] [-V] [-v] [-h]\n\n\
Uwe Hermann74b29b92007-11-17 17:13:52 +0000108 -d | --dump Dump Super I/O register contents\n\
Uwe Hermanneec5ff42008-03-01 18:49:39 +0000109 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000110 -l | --list-supported Show the list of supported Super I/O chips\n\
Uwe Hermanneddc4732007-09-20 23:57:44 +0000111 -V | --verbose Verbose mode\n\
112 -v | --version Show the superiotool version\n\
Uwe Hermann969a9f62008-03-17 13:43:48 +0000113 -h | --help Show a short help text\n\n"
114
115#define USAGE_INFO "\
Uwe Hermanne4749562007-09-19 16:26:18 +0000116Per default (no options) superiotool will just probe for a Super I/O\n\
Uwe Hermannafe83092007-09-28 15:45:43 +0000117and print its vendor, name, ID, revision, and config port.\n"
Uwe Hermanne4749562007-09-19 16:26:18 +0000118
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000119#define NOTFOUND " Failed. Returned data: "
120
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000121#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
122
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000123#define EOT -1 /* End Of Table */
124#define NOLDN -2 /* NO LDN needed */
125#define NANA -3 /* Not Available */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000126#define RSVD -4 /* Reserved */
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000127#define MISC -5 /* Needs special comment in output */
Tom Sylla92af5092008-06-07 11:36:30 +0000128#define MAXLDN 0x14 /* Biggest LDN */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000129#define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000130#define MAXNUMIDX 170 /* Maximum number of indices */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000131#define IDXSIZE (MAXNUMIDX + 1)
Uwe Hermann14f304a2007-10-08 01:11:11 +0000132#define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000133
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000134/* Select registers for various components. */
135#define LDN_SEL 0x07 /* LDN select register */
136#define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
137
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000138/* Command line parameters. */
Ronald Hoogenboom0be73bb2008-02-25 22:32:41 +0000139extern int dump, verbose, extra_dump;
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000140
Uwe Hermanne9d46162007-10-07 20:01:23 +0000141extern int chip_found;
142
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000143struct superio_registers {
Uwe Hermanneddc4732007-09-20 23:57:44 +0000144 int32_t superio_id; /* Signed, as we need EOT. */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000145 const char *name; /* Super I/O name */
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000146 struct {
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000147 int8_t ldn;
Uwe Hermanneddc4732007-09-20 23:57:44 +0000148 const char *name; /* LDN name */
Uwe Hermann42cccdf2008-03-29 01:35:21 +0000149 int16_t idx[IDXSIZE];
150 int16_t def[IDXSIZE];
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000151 } ldn[LDNSIZE];
152};
153
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000154/* pci.c */
155#ifdef PCI_SUPPORT
156extern struct pci_access *pacc;
157struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
158#endif
159
Uwe Hermann4cb7e712007-09-16 18:17:44 +0000160/* superiotool.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000161uint8_t regval(uint16_t port, uint8_t reg);
162void regwrite(uint16_t port, uint8_t reg, uint8_t val);
Uwe Hermannb4db2202007-09-20 23:37:56 +0000163void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
164void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000165void enter_conf_mode_fintek_7777(uint16_t port);
166void exit_conf_mode_fintek_7777(uint16_t port);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000167int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
Uwe Hermann3acf31e2007-09-19 01:55:35 +0000168const char *get_superio_name(const struct superio_registers reg_table[],
169 uint16_t id);
Uwe Hermann519419b2007-09-16 20:59:01 +0000170void dump_superio(const char *name, const struct superio_registers reg_table[],
Stefan Reinauer7a51e502008-12-01 14:18:57 +0000171 uint16_t port, uint16_t id, uint8_t ldn_sel);
Stefan Reinauer6df0c622009-03-11 14:48:20 +0000172void dump_io(uint16_t iobase, uint16_t length);
Guenter Roecka89da092012-06-29 12:23:50 -0700173void dump_data(uint16_t iobase, int bank);
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000174void probing_for(const char *vendor, const char *info, uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000175void print_vendor_chips(const char *vendor,
176 const struct superio_registers reg_table[]);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000177
Uwe Hermann945045b2007-09-28 15:39:10 +0000178/* ali.c */
179void probe_idregs_ali(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000180void print_ali_chips(void);
Uwe Hermann945045b2007-09-28 15:39:10 +0000181
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
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000190/* fintek.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000191void probe_idregs_fintek(uint16_t port);
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000192void probe_idregs_fintek_alternative(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000193void print_fintek_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000194
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600195/* infineon.c */
196void probe_idregs_infineon(uint16_t port);
197void print_infineon_chips(void);
198
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000199/* ite.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000200void probe_idregs_ite(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000201void print_ite_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000202
203/* nsc.c */
Uwe Hermann8b8d0392007-10-04 15:23:38 +0000204void probe_idregs_nsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000205void print_nsc_chips(void);
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000206
David Hendrickse1822d92010-07-22 22:56:44 +0000207/* nuvoton.c */
208void probe_idregs_nuvoton(uint16_t port);
209void print_nuvoton_chips(void);
210
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000211/* smsc.c */
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000212void probe_idregs_smsc(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000213void print_smsc_chips(void);
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000214
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000215/* winbond.c */
216void probe_idregs_winbond(uint16_t port);
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000217void print_winbond_chips(void);
Uwe Hermann7e7e9ac2007-09-19 15:52:23 +0000218
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000219/* via.c */
220#ifdef PCI_SUPPORT
221void probe_idregs_via(uint16_t port);
222void print_via_chips(void);
223#endif
224
Uwe Hermannc3da3662007-09-26 16:14:16 +0000225/** Table of which config ports to probe for each Super I/O family. */
Uwe Hermann246be7d2007-10-31 22:22:11 +0000226static const struct {
Uwe Hermannde24a0e2007-09-19 00:03:14 +0000227 void (*probe_idregs) (uint16_t port);
228 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000229} superio_ports_table[] = {
Uwe Hermann945045b2007-09-28 15:39:10 +0000230 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
Uwe Hermann0f867322007-09-24 01:40:09 +0000231 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
Stefan Reinauere7b7ae22010-08-17 08:24:01 +0000232 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
Urja Rannikko38204a22008-10-23 23:33:18 +0000233 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
Nico Huber28a13242013-04-25 15:10:46 +0200234 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, EOT}},
Sven Schnelleed61c4a2011-02-02 23:49:41 +0000235 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
David Hendrickse1822d92010-07-22 22:56:44 +0000236 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
237 * addition to the following hardware strapping options. */
Stefan Reinauer3187d022011-04-22 23:12:40 +0000238 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
Uwe Hermann14f304a2007-10-08 01:11:11 +0000239 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
Uwe Hermannc3da3662007-09-26 16:14:16 +0000240 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000241#ifdef PCI_SUPPORT
242 {probe_idregs_via, {0x3f0, EOT}},
Rudolf Marek113c3492011-10-27 20:42:11 +0200243 /* in fact read the BASE from HW */
244 {probe_idregs_amd, {0xaa, EOT}},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000245#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000246 {probe_idregs_serverengines, {0x2e, EOT}},
Jonathan A. Kollaschcb34bba2012-01-02 19:11:49 -0600247 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
Uwe Hermannd754d2c2007-09-18 23:30:24 +0000248};
Uwe Hermann6ff6af72007-09-18 22:24:34 +0000249
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000250/** Table of functions to print out supported Super I/O chips. */
251static const struct {
252 void (*print_list) (void);
253} vendor_print_functions[] = {
254 {print_ali_chips},
255 {print_fintek_chips},
256 {print_ite_chips},
257 {print_nsc_chips},
David Hendrickse1822d92010-07-22 22:56:44 +0000258 {print_nuvoton_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000259 {print_smsc_chips},
260 {print_winbond_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000261#ifdef PCI_SUPPORT
262 {print_via_chips},
Rudolf Marek113c3492011-10-27 20:42:11 +0200263 {print_amd_chips},
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +0000264#endif
Ruud Schramp18b02362011-04-11 07:46:27 +0000265 {print_serverengines_chips},
Jonathan A. Kollasch3d1d6bb2011-11-07 10:56:42 -0600266 {print_infineon_chips},
Robinson P. Tryon552cfb72008-01-15 22:30:55 +0000267};
268
Uwe Hermann0120e1a2007-09-16 18:11:03 +0000269#endif