Implement usage for --help and put the same information into the README, too.
[coreboot.git] / util / superiotool / superiotool.h
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Carl-Daniel Hailfinger
5  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #ifndef SUPERIOTOOL_H
23 #define SUPERIOTOOL_H
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdint.h>
28 #include <string.h>
29 #include <getopt.h>
30 #include <sys/io.h>
31
32 #define SUPERIOTOOL_VERSION "0.1"
33
34 #define USAGE "Usage: superiotool [-d] [-V] [-v] [-h]\n\n\
35   -d | --dump      Dump Super I/O registers\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, version, and config port.\n"
41
42 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
43
44 #define EOT             -1              /* End Of Table */
45 #define NOLDN           -2              /* NO LDN needed */
46 #define NANA            -3              /* Not Available */
47 #define RSVD            -4              /* Reserved */
48 #define MISC            -5              /* Needs special comment in output */
49 #define MAXNAMELEN      20              /* Maximum Name Length */
50 #define MAXLDN          0xa             /* Biggest LDN */
51 #define LDNSIZE         (MAXLDN + 3)    /* Biggest LDN + 0 + NOLDN + EOT */
52 #define MAXNUMIDX       70              /* Maximum number of indexes */
53 #define IDXSIZE         (MAXNUMIDX + 1)
54 #define MAXNUMPORTS     (2 + 1)         /* Maximum number of Super I/O ports */
55
56 /* Command line parameters. */
57 extern int dump, verbose;
58
59 struct superio_registers {
60         int32_t superio_id; /* Signed, as we need EOT. */
61         const char name[MAXNAMELEN];
62         struct {
63                 int ldn;
64                 int idx[IDXSIZE];
65                 int def[IDXSIZE];
66         } ldn[LDNSIZE];
67 };
68
69 /* superiotool.c */
70 uint8_t regval(uint16_t port, uint8_t reg);
71 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
72 int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
73 const char *get_superio_name(const struct superio_registers reg_table[],
74                              uint16_t id);
75 void dump_superio(const char *name, const struct superio_registers reg_table[],
76                   uint16_t port, uint16_t id);
77 void no_superio_found(uint16_t port);
78
79 /* fintek.c */
80 void dump_fintek(uint16_t port, uint16_t did);
81 void probe_idregs_fintek(uint16_t port);
82
83 /* ite.c */
84 void dump_ite(uint16_t port, uint16_t id);
85 void probe_idregs_ite(uint16_t port);
86
87 /* nsc.c */
88 void dump_ns8374(uint16_t port);
89 void probe_idregs_simple(uint16_t port);
90
91 /* smsc.c */
92 void probe_idregs_smsc(uint16_t port);
93
94 /* winbond.c */
95 void probe_idregs_winbond(uint16_t port);
96
97 /** Table of which config ports to probe on each Super I/O. */
98 const static struct {
99         void (*probe_idregs) (uint16_t port);
100         int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
101 } superio_ports_table[] = {
102         {probe_idregs_simple,   {0x2e,  0x4e,   EOT}},
103         {probe_idregs_fintek,   {0x2e,  0x4e,   EOT}},
104         {probe_idregs_ite,      {0x2e,  0x4e,   EOT}},
105         {probe_idregs_smsc,     {0x3f0, 0x370,  EOT}},
106         {probe_idregs_winbond,  {0x2e,  0x4e,   EOT}},
107 };
108
109 #endif