blob: 6ae32ccf1ae93e419bbffb3caadcf60149752eaa [file] [log] [blame]
Stefan Reinauer03646be2008-05-13 22:14:21 +00001/*
2 * inteltool - dump all registers on an Intel CPU + chipset based system.
3 *
4 * Copyright (C) 2008 by coresystems GmbH
5 * written by Stefan Reinauer <stepan@coresystems.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; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
Stefan Reinauer03646be2008-05-13 22:14:21 +000021#include <stdio.h>
Stefan Reinauer03646be2008-05-13 22:14:21 +000022#include <stdlib.h>
Stefan Reinauer03646be2008-05-13 22:14:21 +000023#include <getopt.h>
Stefan Reinauer23190272008-08-20 13:41:24 +000024#include <fcntl.h>
Stefan Reinauer1162f252008-12-04 15:18:20 +000025#include <sys/mman.h>
Stefan Reinauer23190272008-08-20 13:41:24 +000026#include "inteltool.h"
Stefan Reinauer03646be2008-05-13 22:14:21 +000027
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000028static const struct {
29 uint16_t vendor_id, device_id;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +000030 char *name;
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000031} supported_chips_list[] = {
Maciej Pijanka90d17402009-09-30 17:05:46 +000032 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX, "82443LX" },
33 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX, "82443BX" },
34 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_NO_AGP, "82443BX without AGP" },
Stefan Reinauerb2aedb12009-08-29 15:45:43 +000035 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810, "i810" },
36 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810DC, "i810-DC100" },
Uwe Hermann710e8b12008-05-17 21:33:35 +000037 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845, "i845" },
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +000038 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945P, "i945P" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000039 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GM, "i945GM" },
Stefan Reinauer1162f252008-12-04 15:18:20 +000040 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM965, "PM965" },
41 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82975X, "i975X" },
Warren Turkal9702b6b2009-06-30 14:11:42 +000042 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58, "X58" },
43 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10R, "ICH10R" },
Stefan Reinauer1162f252008-12-04 15:18:20 +000044 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000045 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000046 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000047 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000048 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000049 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" },
50 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" },
Uwe Hermann710e8b12008-05-17 21:33:35 +000051 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000052 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" },
Maciej Pijanka90d17402009-09-30 17:05:46 +000053 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" },
54 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371XX, "82371AB/EB/MB" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000055};
56
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000057#ifndef __DARWIN__
Stefan Reinauer1162f252008-12-04 15:18:20 +000058static int fd_mem;
59
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000060void *map_physical(unsigned long phys_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +000061{
62 void *virt_addr;
63
64 virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED,
65 fd_mem, (off_t) phys_addr);
66
67 if (virt_addr == MAP_FAILED) {
Stefan Reinauerf1824562009-04-22 23:17:44 +000068 printf("Error mapping physical memory 0x%08lx[0x%x]\n", phys_addr, len);
Stefan Reinauer1162f252008-12-04 15:18:20 +000069 return NULL;
70 }
71
72 return virt_addr;
73}
74
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000075void unmap_physical(void *virt_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +000076{
77 munmap(virt_addr, len);
78}
79#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +000080
81void print_version(void)
82{
83 printf("inteltool v%s -- ", INTELTOOL_VERSION);
84 printf("Copyright (C) 2008 coresystems GmbH\n\n");
85 printf(
86 "This program is free software: you can redistribute it and/or modify\n"
87 "it under the terms of the GNU General Public License as published by\n"
88 "the Free Software Foundation, version 2 of the License.\n\n"
89 "This program is distributed in the hope that it will be useful,\n"
90 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
91 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
92 "GNU General Public License for more details.\n\n"
93 "You should have received a copy of the GNU General Public License\n"
94 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
95}
96
97void print_usage(const char *name)
98{
Stefan Reinauerd466e6a2008-05-14 13:52:50 +000099 printf("usage: %s [-vh?grpmedPMa]\n", name);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000100 printf("\n"
101 " -v | --version: print the version\n"
102 " -h | --help: print this help\n\n"
103 " -g | --gpio: dump soutbridge GPIO registers\n"
104 " -r | --rcba: dump soutbridge RCBA registers\n"
105 " -p | --pmbase: dump soutbridge Power Management registers\n\n"
106 " -m | --mchbar: dump northbridge Memory Controller registers\n"
107 " -e | --epbar: dump northbridge EPBAR registers\n"
108 " -d | --dmibar: dump northbridge DMIBAR registers\n"
109 " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n"
110 " -M | --msrs: dump CPU MSRs\n"
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000111 " -a | --all: dump all known registers\n"
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000112 "\n");
Stefan Reinauer03646be2008-05-13 22:14:21 +0000113 exit(1);
114}
115
116int main(int argc, char *argv[])
117{
118 struct pci_access *pacc;
Maciej Pijanka90d17402009-09-30 17:05:46 +0000119 struct pci_dev *sb = NULL, *nb, *dev;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000120 int i, opt, option_index = 0;
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000121 unsigned int id;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000122
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000123 char *sbname = "unknown", *nbname = "unknown";
Stefan Reinauer03646be2008-05-13 22:14:21 +0000124
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000125 int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0;
126 int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0;
127 int dump_pciexbar = 0, dump_coremsrs = 0;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000128
129 static struct option long_options[] = {
130 {"version", 0, 0, 'v'},
131 {"help", 0, 0, 'h'},
132 {"gpios", 0, 0, 'g'},
133 {"mchbar", 0, 0, 'm'},
134 {"rcba", 0, 0, 'r'},
135 {"pmbase", 0, 0, 'p'},
136 {"epbar", 0, 0, 'e'},
137 {"dmibar", 0, 0, 'd'},
138 {"pciexpress", 0, 0, 'P'},
139 {"msrs", 0, 0, 'M'},
140 {"all", 0, 0, 'a'},
141 {0, 0, 0, 0}
142 };
143
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000144 while ((opt = getopt_long(argc, argv, "vh?grpmedPMa",
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000145 long_options, &option_index)) != EOF) {
Stefan Reinauer03646be2008-05-13 22:14:21 +0000146 switch (opt) {
147 case 'v':
148 print_version();
149 exit(0);
150 break;
151 case 'g':
152 dump_gpios = 1;
153 break;
154 case 'm':
155 dump_mchbar = 1;
156 break;
157 case 'r':
158 dump_rcba = 1;
159 break;
160 case 'p':
161 dump_pmbase = 1;
162 break;
163 case 'e':
164 dump_epbar = 1;
165 break;
166 case 'd':
167 dump_dmibar = 1;
168 break;
169 case 'P':
170 dump_pciexbar = 1;
171 break;
172 case 'M':
173 dump_coremsrs = 1;
174 break;
175 case 'a':
176 dump_gpios = 1;
177 dump_mchbar = 1;
178 dump_rcba = 1;
179 dump_pmbase = 1;
180 dump_epbar = 1;
181 dump_dmibar = 1;
182 dump_pciexbar = 1;
183 dump_coremsrs = 1;
184 break;
185 case 'h':
186 case '?':
187 default:
188 print_usage(argv[0]);
189 exit(0);
190 break;
191 }
192 }
193
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000194 if (iopl(3)) {
195 printf("You need to be root.\n");
196 exit(1);
197 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000198
Stefan Reinauerf7f2f252009-09-01 09:52:14 +0000199#ifndef __DARWIN__
Stefan Reinauer03646be2008-05-13 22:14:21 +0000200 if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
201 perror("Can not open /dev/mem");
202 exit(1);
203 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000204#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +0000205
206 pacc = pci_alloc();
207 pci_init(pacc);
208 pci_scan_bus(pacc);
209
Stefan Reinauer03646be2008-05-13 22:14:21 +0000210 /* Find the required devices */
Maciej Pijanka90d17402009-09-30 17:05:46 +0000211 for (dev = pacc->devices; dev; dev = dev->next) {
212 pci_fill_info(dev, PCI_FILL_CLASS);
213 /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */
214 if (dev->device_class == 0x0601) { /* ISA/LPC bridge */
215 if (sb == NULL)
216 sb = dev;
217 else
218 fprintf(stderr, "Multiple devices with class ID"
219 " 0x0601, using %02x%02x:%02x.%02x\n",
220 dev->domain, dev->bus, dev->dev,
221 dev->func);
222 }
223 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000224
Stefan Reinauer03646be2008-05-13 22:14:21 +0000225 if (!sb) {
226 printf("No southbridge found.\n");
227 exit(1);
228 }
229
230 pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
231
232 if (sb->vendor_id != PCI_VENDOR_ID_INTEL) {
233 printf("Not an Intel(R) southbridge.\n");
234 exit(1);
235 }
236
237 nb = pci_get_dev(pacc, 0, 0, 0x00, 0);
238 if (!nb) {
239 printf("No northbridge found.\n");
240 exit(1);
241 }
242
243 pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
244
245 if (nb->vendor_id != PCI_VENDOR_ID_INTEL) {
246 printf("Not an Intel(R) northbridge.\n");
247 exit(1);
248 }
249
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000250 id = cpuid(1);
251 printf("Intel CPU: Family %x, Model %x\n",
252 (id >> 8) & 0xf, (id >> 4) & 0xf);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000253
254 /* Determine names */
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000255 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000256 if (nb->device_id == supported_chips_list[i].device_id)
257 nbname = supported_chips_list[i].name;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000258 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000259 if (sb->device_id == supported_chips_list[i].device_id)
260 sbname = supported_chips_list[i].name;
261
262 printf("Intel Northbridge: %04x:%04x (%s)\n",
263 nb->vendor_id, nb->device_id, nbname);
264
265 printf("Intel Southbridge: %04x:%04x (%s)\n",
266 sb->vendor_id, sb->device_id, sbname);
267
268 /* Now do the deed */
269
270 if (dump_gpios) {
271 print_gpios(sb);
272 printf("\n\n");
273 }
274
275 if (dump_rcba) {
276 print_rcba(sb);
277 printf("\n\n");
278 }
279
280 if (dump_pmbase) {
281 print_pmbase(sb);
282 printf("\n\n");
283 }
284
285 if (dump_mchbar) {
286 print_mchbar(nb);
287 printf("\n\n");
288 }
289
290 if (dump_epbar) {
291 print_epbar(nb);
292 printf("\n\n");
293 }
294
295 if (dump_dmibar) {
296 print_dmibar(nb);
297 printf("\n\n");
298 }
299
300 if (dump_pciexbar) {
301 print_pciexbar(nb);
302 printf("\n\n");
303 }
304
305 if (dump_coremsrs) {
306 print_intel_core_msrs();
307 printf("\n\n");
308 }
309
Stefan Reinauer03646be2008-05-13 22:14:21 +0000310 /* Clean up */
Stefan Reinauer03646be2008-05-13 22:14:21 +0000311 pci_free_dev(nb);
Uwe Hermanne23e3722009-09-30 17:14:24 +0000312 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"
Stefan Reinauer03646be2008-05-13 22:14:21 +0000313 pci_cleanup(pacc);
314
315 return 0;
316}