Add new --list-supported switch for printing the list of Super I/Os
[coreboot.git] / util / superiotool / superiotool.h
1 /*
2  * This file is part of the superiotool project.
3  *
4  * Copyright (C) 2007 Carl-Daniel Hailfinger
5  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6  * Copyright (C) 2008 Robinson P. Tryon <bishop.robinson@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #ifndef SUPERIOTOOL_H
24 #define SUPERIOTOOL_H
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <string.h>
30 #include <getopt.h>
31 #include <sys/io.h>
32
33 #define USAGE "Usage: superiotool [-d] [-l] [-V] [-v] [-h]\n\n\
34   -d | --dump            Dump Super I/O register contents\n\
35   -l | --list-supported  Show the list of supported Super I/O chips\n\
36   -V | --verbose         Verbose mode\n\
37   -v | --version         Show the superiotool version\n\
38   -h | --help            Show a short help text\n\n\
39 Per default (no options) superiotool will just probe for a Super I/O\n\
40 and print its vendor, name, ID, revision, and config port.\n"
41
42 #define NOTFOUND "  Failed. Returned data: "
43
44 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
45
46 #define EOT             -1              /* End Of Table */
47 #define NOLDN           -2              /* NO LDN needed */
48 #define NANA            -3              /* Not Available */
49 #define RSVD            -4              /* Reserved */
50 #define MISC            -5              /* Needs special comment in output */
51 #define MAXNAMELEN      30              /* Maximum Name Length */
52 #define MAXLDN          0x10            /* Biggest LDN */
53 #define LDNSIZE         (MAXLDN + 3)    /* Biggest LDN + 0 + NOLDN + EOT */
54 #define MAXNUMIDX       70              /* Maximum number of indexes */
55 #define IDXSIZE         (MAXNUMIDX + 1)
56 #define MAXNUMPORTS     (6 + 1)         /* Maximum number of Super I/O ports */
57
58 /* Command line parameters. */
59 extern int dump, verbose;
60
61 extern int chip_found;
62
63 struct superio_registers {
64         int32_t superio_id;             /* Signed, as we need EOT. */
65         const char name[MAXNAMELEN];    /* Super I/O name */
66         struct {
67                 int ldn;
68                 const char *name;       /* LDN name */
69                 int idx[IDXSIZE];
70                 int def[IDXSIZE];
71         } ldn[LDNSIZE];
72 };
73
74 /* superiotool.c */
75 uint8_t regval(uint16_t port, uint8_t reg);
76 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
77 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
78 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
79 int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
80 const char *get_superio_name(const struct superio_registers reg_table[],
81                              uint16_t id);
82 void dump_superio(const char *name, const struct superio_registers reg_table[],
83                   uint16_t port, uint16_t id);
84 void probing_for(const char *vendor, const char *info, uint16_t port);
85 void print_vendor_chips(const char *vendor,
86                         const struct superio_registers reg_table[]);
87
88 /* ali.c */
89 void probe_idregs_ali(uint16_t port);
90 void print_ali_chips(void);
91
92 /* fintek.c */
93 void probe_idregs_fintek(uint16_t port);
94 void print_fintek_chips(void);
95
96 /* ite.c */
97 void probe_idregs_ite(uint16_t port);
98 void print_ite_chips(void);
99
100 /* nsc.c */
101 void probe_idregs_nsc(uint16_t port);
102 void print_nsc_chips(void);
103
104 /* smsc.c */
105 void probe_idregs_smsc(uint16_t port);
106 void print_smsc_chips(void);
107
108 /* winbond.c */
109 void probe_idregs_winbond(uint16_t port);
110 void print_winbond_chips(void);
111
112 /** Table of which config ports to probe for each Super I/O family. */
113 static const struct {
114         void (*probe_idregs) (uint16_t port);
115         int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
116 } superio_ports_table[] = {
117         {probe_idregs_ali,      {0x3f0, 0x370, EOT}},
118         {probe_idregs_fintek,   {0x2e, 0x4e, EOT}},
119         {probe_idregs_ite,      {0x2e, 0x4e, EOT}},
120         {probe_idregs_nsc,      {0x2e, 0x4e, EOT}},
121         {probe_idregs_smsc,     {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
122         {probe_idregs_winbond,  {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
123 };
124
125
126 /** Table of functions to print out supported Super I/O chips. */
127 static const struct {
128         void (*print_list) (void);
129 } vendor_print_functions[] = {
130         {print_ali_chips},
131         {print_fintek_chips},
132         {print_ite_chips},
133         {print_nsc_chips},
134         {print_smsc_chips},
135         {print_winbond_chips},
136 };
137
138 #endif