Make the code a bit more generic (trivial). Different Super I/Os
[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 <sys/io.h>
29
30 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
31
32 #define EOT             -1              /* End Of Table */
33 #define NOLDN           -2              /* NO LDN needed */
34 #define NANA            -3              /* Not Available */
35 #define RSVD            -4              /* Reserved */
36 #define MAXNAMELEN      20              /* Maximum Name Length */
37 #define MAXLDN          0xa             /* Biggest LDN */
38 #define LDNSIZE         (MAXLDN + 3)    /* Biggest LDN + 0 + NOLDN + EOT */
39 #define MAXNUMIDX       70              /* Maximum number of indexes */
40 #define IDXSIZE         (MAXNUMIDX + 1)
41 #define MAXNUMPORTS     (2 + 1)         /* Maximum number of Super I/O ports */
42
43 struct superio_registers {
44         /* Yes, superio_id should be unsigned, but EOT has to be negative. */
45         signed short superio_id;
46         const char name[MAXNAMELEN];
47         struct {
48                 signed short ldn;
49                 signed short idx[IDXSIZE];
50                 signed short def[IDXSIZE];
51         } ldn[LDNSIZE];
52 };
53
54 /* superiotool.c */
55 unsigned char regval(unsigned short port, unsigned char reg);
56 void regwrite(unsigned short port, unsigned char reg, unsigned char val);
57 void dump_superio(const char *name, const struct superio_registers reg_table[],
58                   unsigned short port, unsigned short id);
59 void probe_superio(unsigned short port);
60
61 /* fintek.c */
62 void dump_fintek(unsigned short port, unsigned int did);
63 void probe_idregs_fintek(unsigned short port);
64
65 /* ite.c */
66 void dump_ite(unsigned short port, unsigned short id);
67 void probe_idregs_ite(unsigned short port);
68
69 /* nsc.c */
70 void dump_ns8374(unsigned short port);
71 void probe_idregs_simple(unsigned short port);
72
73 /* smsc.c */
74 void dump_smsc(uint32_t port, uint32_t id);
75 void probe_idregs_smsc(unsigned short port);
76
77 /** Table of which config ports to probe on each Super I/O. */
78 const static struct {
79         void (*probe_idregs) (unsigned short port);
80         signed short ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
81 } superio_ports_table[] = {
82         {probe_idregs_simple,   {0x2e,  0x4e,   EOT}},
83         {probe_idregs_fintek,   {0x2e,  0x4e,   EOT}},
84         {probe_idregs_ite,      {0x2e,  0x4e,   EOT}},
85         {probe_idregs_smsc,     {0x3f0, 0x370,  EOT}},
86 };
87
88 #endif