Debian Codegraph @

util/superiotool/superiotool.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #ifndef SUPERIOTOOL_H
4 #define SUPERIOTOOL_H
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <getopt.h>
11 #include <commonlib/bsd/helpers.h>
12 #include <sys/types.h>
13 #if defined(__linux__)
14 #include <sys/io.h>
15 #endif
16 #if (defined(__MACH__) && defined(__APPLE__))
17 /* DirectHW is available here: https://www.coreboot.org/DirectHW */
18 #include <DirectHW/DirectHW.h>
19 #endif
20
21 #ifdef PCI_SUPPORT
22 # ifdef __NetBSD__
23 #include <pciutils/pci.h>
24 # else
25 #include <pci/pci.h>
26 # endif
27 #endif
28
29 #if defined(__FreeBSD__)
30 #include <machine/cpufunc.h>
31 #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
32 #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
33 #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
34 #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
35 #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
36 #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
37 #else
38 #define OUTB outb
39 #define OUTW outw
40 #define OUTL outl
41 #define INB inb
42 #define INW inw
43 #define INL inl
44 #endif
45
46 #if defined(__NetBSD__) && (defined(__i386__) || defined(__x86_64__))
47 #include <machine/sysarch.h>
48 #if defined(__i386__)
49 #define iopl i386_iopl
50 #elif defined(__x86_64__)
51 #define iopl x86_64_iopl
52 #endif
53
54 static __inline__ void
55 outb(uint8_t value, uint16_t port)
56 {
57 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
58 }
59
60 static __inline__ void
61 outw(uint16_t value, uint16_t port)
62 {
63 __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
64 }
65
66 static __inline__ void
67 outl(uint32_t value, uint16_t port)
68 {
69 __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
70 }
71
72 static __inline__ uint8_t inb(uint16_t port)
73 {
74 uint8_t value;
75 __asm__ __volatile__ ("inb %w1,%0":"=a" (value):"Nd" (port));
76 return value;
77 }
78
79 static __inline__ uint16_t inw(uint16_t port)
80 {
81 uint16_t value;
82 __asm__ __volatile__ ("inw %w1,%0":"=a" (value):"Nd" (port));
83 return value;
84 }
85
86 static __inline__ uint32_t inl(uint16_t port)
87 {
88 uint32_t value;
89 __asm__ __volatile__ ("inl %1,%0":"=a" (value):"Nd" (port));
90 return value;
91 }
92 #endif
93
94 #define USAGE "Usage: superiotool [-d] [-e] [-a] [-l] [-V] [-v] [-h]\n\n\
95 -d | --dump Dump Super I/O register contents\n\
96 -e | --extra-dump Dump secondary registers too (e.g. EC registers)\n\
97 -a | --alternate-dump Use alternative dump format, more suitable for diff\n\
98 -l | --list-supported Show the list of supported Super I/O chips\n\
99 -V | --verbose Verbose mode\n\
100 -v | --version Show the superiotool version\n\
101 -h | --help Show a short help text\n\n"
102
103 #define USAGE_INFO "\
104 Per default (no options) superiotool will just probe for a Super I/O\n\
105 and print its vendor, name, ID, revision, and config port.\n"
106
107 #define NOTFOUND " Failed. Returned data: "
108
109 #define EOT -1 /* End Of Table */
110 #define NOLDN -2 /* NO LDN needed */
111 #define NANA -3 /* Not Available:
112 Used for registers having externally controlled
113 values that can change during runtime like
114 GPIO input value registers. */
115 #define RSVD -4 /* Reserved */
116 #define MISC -5 /* Needs special comment in output:
117 Used for registers depending on external pin straps
118 configuring static, but board-specific settings like
119 SIO base address or AMD/Intel power seqencing type. */
120 #define MAXLDN 0x14 /* Biggest LDN */
121 #define LDNSIZE (MAXLDN + 3) /* Biggest LDN + 0 + NOLDN + EOT */
122 #define MAXNUMIDX 170 /* Maximum number of indices */
123 #define IDXSIZE (MAXNUMIDX + 1)
124 #define MAXNUMPORTS (6 + 1) /* Maximum number of Super I/O ports */
125
126 /* Select registers for various components. */
127 #define LDN_SEL 0x07 /* LDN select register */
128 #define WINBOND_HWM_SEL 0x4e /* Hardware monitor bank select */
129
130 /* Command line parameters. */
131 extern int dump, verbose, extra_dump;
132
133 extern int chip_found;
134
135 /* Extra selector structure (see fintek.c) */
136 struct extra_selector {
137 const char *name;
138 uint8_t idx;
139 uint8_t mask;
140 uint8_t val;
141 };
142
143 struct superio_registers {
144 int32_t superio_id; /* Signed, as we need EOT. */
145 const char *name; /* Super I/O name */
146 struct {
147 int8_t ldn;
148 const char *name; /* LDN name */
149 int16_t idx[IDXSIZE];
150 int16_t def[IDXSIZE];
151 struct extra_selector esel;
152 } ldn[LDNSIZE];
153 };
154
155 /* pci.c */
156 #ifdef PCI_SUPPORT
157 extern struct pci_access *pacc;
158 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
159 #endif
160
161 /* superiotool.c */
162 uint8_t regval(uint16_t port, uint8_t reg);
163 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
164 void enter_conf_mode_winbond_fintek_ite_8787(uint16_t port);
165 void exit_conf_mode_winbond_fintek_ite_8787(uint16_t port);
166 void enter_conf_mode_fintek_7777(uint16_t port);
167 void exit_conf_mode_fintek_7777(uint16_t port);
168 int superio_unknown(const struct superio_registers reg_table[], uint16_t id);
169 const char *get_superio_name(const struct superio_registers reg_table[],
170 uint16_t id);
171 void dump_superio(const char *name, const struct superio_registers reg_table[],
172 uint16_t port, uint16_t id, uint8_t ldn_sel);
173 void dump_io(uint16_t iobase, uint16_t length);
174 void dump_data(uint16_t iobase, int bank);
175 void probing_for(const char *vendor, const char *info, uint16_t port);
176 void print_vendor_chips(const char *vendor,
177 const struct superio_registers reg_table[]);
178
179 /* ali.c */
180 void probe_idregs_ali(uint16_t port);
181 void print_ali_chips(void);
182
183 /* aspeed.c */
184 void probe_idregs_aspeed(uint16_t port);
185 void print_aspeed_chips(void);
186
187 /* amd.c */
188 void probe_idregs_amd(uint16_t port);
189 void print_amd_chips(void);
190
191 /* serverengines.c */
192 void probe_idregs_serverengines(uint16_t port);
193 void print_serverengines_chips(void);
194
195 /* exar.c */
196 void probe_idregs_exar(uint16_t port);
197 void print_exar_chips(void);
198
199 /* fintek.c */
200 void probe_idregs_fintek(uint16_t port);
201 void probe_idregs_fintek_alternative(uint16_t port);
202 void print_fintek_chips(void);
203
204 /* infineon.c */
205 void probe_idregs_infineon(uint16_t port);
206 void print_infineon_chips(void);
207
208 /* ite.c */
209 void probe_idregs_ite(uint16_t port);
210 void print_ite_chips(void);
211
212 /* nsc.c */
213 void probe_idregs_nsc(uint16_t port);
214 void print_nsc_chips(void);
215
216 /* nuvoton.c */
217 void probe_idregs_nuvoton(uint16_t port);
218 void print_nuvoton_chips(void);
219
220 /* smsc.c */
221 void probe_idregs_smsc(uint16_t port);
222 void print_smsc_chips(void);
223
224 /* winbond.c */
225 void probe_idregs_winbond(uint16_t port);
226 void print_winbond_chips(void);
227
228 /* via.c */
229 #ifdef PCI_SUPPORT
230 void probe_idregs_via(uint16_t port);
231 void print_via_chips(void);
232 #endif
233
234 /** Table of which config ports to probe for each Super I/O family. */
235 static const struct {
236 void (*probe_idregs) (uint16_t port);
237 int ports[MAXNUMPORTS]; /* Signed, as we need EOT. */
238 } superio_ports_table[] = {
239 {probe_idregs_ali, {0x3f0, 0x370, EOT}},
240 {probe_idregs_aspeed, {0x2e, 0x4e, EOT}},
241 {probe_idregs_exar, {0x2e, 0x4e, EOT}},
242 {probe_idregs_fintek, {0x2e, 0x4e, EOT}},
243 {probe_idregs_fintek_alternative, {0x2e, 0x4e, EOT}},
244 /* Only use 0x370 for ITE, but 0x3f0 or 0x3bd would also be valid. */
245 {probe_idregs_ite, {0x20e, 0x25e, 0x2e, 0x4e, 0x370, 0x6e, EOT}},
246 {probe_idregs_nsc, {0x2e, 0x4e, 0x15c, 0x164e, EOT}},
247 /* I/O pairs on Nuvoton EC chips can be configured by firmware in
248 * addition to the following hardware strapping options. */
249 {probe_idregs_nuvoton, {0x164e, 0x2e, 0x4e, EOT}},
250 {probe_idregs_smsc, {0x2e, 0x4e, 0x162e, 0x164e, 0x3f0, 0x370, EOT}},
251 {probe_idregs_winbond, {0x2e, 0x4e, 0x3f0, 0x370, 0x250, EOT}},
252 #ifdef PCI_SUPPORT
253 {probe_idregs_via, {0x2e, 0x4e, 0x3f0, EOT}},
254 /* in fact read the BASE from HW */
255 {probe_idregs_amd, {0xaa, EOT}},
256 #endif
257 {probe_idregs_serverengines, {0x2e, EOT}},
258 {probe_idregs_infineon, {0x2e, 0x4e, EOT}},
259 };
260
261 /** Table of functions to print out supported Super I/O chips. */
262 static const struct {
263 void (*print_list) (void);
264 } vendor_print_functions[] = {
265 {print_ali_chips},
266 {print_exar_chips},
267 {print_fintek_chips},
268 {print_ite_chips},
269 {print_nsc_chips},
270 {print_nuvoton_chips},
271 {print_smsc_chips},
272 {print_winbond_chips},
273 #ifdef PCI_SUPPORT
274 {print_via_chips},
275 {print_amd_chips},
276 {print_aspeed_chips},
277 #endif
278 {print_serverengines_chips},
279 {print_infineon_chips},
280 };
281
282 #endif