blob: 6f7530067c62abdad6760588bd804b1131bb7411 [file] [log] [blame]
Stefan Reinauer03646be2008-05-13 22:14:21 +00001/*
2 * inteltool - dump all registers on an Intel CPU + chipset based system.
3 *
Stefan Reinauer04844812010-02-22 11:26:06 +00004 * Copyright (C) 2008-2010 by coresystems GmbH
Stefan Reinauer03646be2008-05-13 22:14:21 +00005 * 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" },
Stefan Reinauer04844812010-02-22 11:26:06 +000037 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82830M, "i830M" },
Uwe Hermann710e8b12008-05-17 21:33:35 +000038 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845, "i845" },
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +000039 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945P, "i945P" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000040 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GM, "i945GM" },
Stefan Reinauer1162f252008-12-04 15:18:20 +000041 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM965, "PM965" },
42 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82975X, "i975X" },
Loïc Grenié8429de72009-11-02 15:01:49 +000043 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q35, "Q35" },
44 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82G33, "P35/G33/G31/P31" },
45 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q33, "Q33" },
Warren Turkal9702b6b2009-06-30 14:11:42 +000046 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58, "X58" },
47 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10R, "ICH10R" },
Stefan Reinauer1162f252008-12-04 15:18:20 +000048 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000049 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000050 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000051 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000052 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000053 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" },
54 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" },
Uwe Hermann710e8b12008-05-17 21:33:35 +000055 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000056 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" },
Maciej Pijanka90d17402009-09-30 17:05:46 +000057 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" },
58 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371XX, "82371AB/EB/MB" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000059};
60
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000061#ifndef __DARWIN__
Stefan Reinauer1162f252008-12-04 15:18:20 +000062static int fd_mem;
63
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000064void *map_physical(unsigned long phys_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +000065{
66 void *virt_addr;
67
68 virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED,
69 fd_mem, (off_t) phys_addr);
70
71 if (virt_addr == MAP_FAILED) {
Stefan Reinauerf1824562009-04-22 23:17:44 +000072 printf("Error mapping physical memory 0x%08lx[0x%x]\n", phys_addr, len);
Stefan Reinauer1162f252008-12-04 15:18:20 +000073 return NULL;
74 }
75
76 return virt_addr;
77}
78
Stefan Reinauerf7f2f252009-09-01 09:52:14 +000079void unmap_physical(void *virt_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +000080{
81 munmap(virt_addr, len);
82}
83#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +000084
85void print_version(void)
86{
87 printf("inteltool v%s -- ", INTELTOOL_VERSION);
88 printf("Copyright (C) 2008 coresystems GmbH\n\n");
89 printf(
90 "This program is free software: you can redistribute it and/or modify\n"
91 "it under the terms of the GNU General Public License as published by\n"
92 "the Free Software Foundation, version 2 of the License.\n\n"
93 "This program is distributed in the hope that it will be useful,\n"
94 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
95 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
96 "GNU General Public License for more details.\n\n"
97 "You should have received a copy of the GNU General Public License\n"
98 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
99}
100
101void print_usage(const char *name)
102{
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000103 printf("usage: %s [-vh?grpmedPMa]\n", name);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000104 printf("\n"
105 " -v | --version: print the version\n"
106 " -h | --help: print this help\n\n"
107 " -g | --gpio: dump soutbridge GPIO registers\n"
108 " -r | --rcba: dump soutbridge RCBA registers\n"
109 " -p | --pmbase: dump soutbridge Power Management registers\n\n"
110 " -m | --mchbar: dump northbridge Memory Controller registers\n"
111 " -e | --epbar: dump northbridge EPBAR registers\n"
112 " -d | --dmibar: dump northbridge DMIBAR registers\n"
113 " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n"
114 " -M | --msrs: dump CPU MSRs\n"
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000115 " -a | --all: dump all known registers\n"
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000116 "\n");
Stefan Reinauer03646be2008-05-13 22:14:21 +0000117 exit(1);
118}
119
120int main(int argc, char *argv[])
121{
122 struct pci_access *pacc;
Maciej Pijanka90d17402009-09-30 17:05:46 +0000123 struct pci_dev *sb = NULL, *nb, *dev;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000124 int i, opt, option_index = 0;
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000125 unsigned int id;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000126
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000127 char *sbname = "unknown", *nbname = "unknown";
Stefan Reinauer03646be2008-05-13 22:14:21 +0000128
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000129 int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0;
130 int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0;
131 int dump_pciexbar = 0, dump_coremsrs = 0;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000132
133 static struct option long_options[] = {
134 {"version", 0, 0, 'v'},
135 {"help", 0, 0, 'h'},
136 {"gpios", 0, 0, 'g'},
137 {"mchbar", 0, 0, 'm'},
138 {"rcba", 0, 0, 'r'},
139 {"pmbase", 0, 0, 'p'},
140 {"epbar", 0, 0, 'e'},
141 {"dmibar", 0, 0, 'd'},
142 {"pciexpress", 0, 0, 'P'},
143 {"msrs", 0, 0, 'M'},
144 {"all", 0, 0, 'a'},
145 {0, 0, 0, 0}
146 };
147
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000148 while ((opt = getopt_long(argc, argv, "vh?grpmedPMa",
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000149 long_options, &option_index)) != EOF) {
Stefan Reinauer03646be2008-05-13 22:14:21 +0000150 switch (opt) {
151 case 'v':
152 print_version();
153 exit(0);
154 break;
155 case 'g':
156 dump_gpios = 1;
157 break;
158 case 'm':
159 dump_mchbar = 1;
160 break;
161 case 'r':
162 dump_rcba = 1;
163 break;
164 case 'p':
165 dump_pmbase = 1;
166 break;
167 case 'e':
168 dump_epbar = 1;
169 break;
170 case 'd':
171 dump_dmibar = 1;
172 break;
173 case 'P':
174 dump_pciexbar = 1;
175 break;
176 case 'M':
177 dump_coremsrs = 1;
178 break;
179 case 'a':
180 dump_gpios = 1;
181 dump_mchbar = 1;
182 dump_rcba = 1;
183 dump_pmbase = 1;
184 dump_epbar = 1;
185 dump_dmibar = 1;
186 dump_pciexbar = 1;
187 dump_coremsrs = 1;
188 break;
189 case 'h':
190 case '?':
191 default:
192 print_usage(argv[0]);
193 exit(0);
194 break;
195 }
196 }
197
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000198 if (iopl(3)) {
199 printf("You need to be root.\n");
200 exit(1);
201 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000202
Stefan Reinauerf7f2f252009-09-01 09:52:14 +0000203#ifndef __DARWIN__
Stefan Reinauer03646be2008-05-13 22:14:21 +0000204 if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
205 perror("Can not open /dev/mem");
206 exit(1);
207 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000208#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +0000209
210 pacc = pci_alloc();
211 pci_init(pacc);
212 pci_scan_bus(pacc);
213
Stefan Reinauer03646be2008-05-13 22:14:21 +0000214 /* Find the required devices */
Maciej Pijanka90d17402009-09-30 17:05:46 +0000215 for (dev = pacc->devices; dev; dev = dev->next) {
216 pci_fill_info(dev, PCI_FILL_CLASS);
217 /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */
218 if (dev->device_class == 0x0601) { /* ISA/LPC bridge */
219 if (sb == NULL)
220 sb = dev;
221 else
222 fprintf(stderr, "Multiple devices with class ID"
223 " 0x0601, using %02x%02x:%02x.%02x\n",
224 dev->domain, dev->bus, dev->dev,
225 dev->func);
226 }
227 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000228
Stefan Reinauer03646be2008-05-13 22:14:21 +0000229 if (!sb) {
230 printf("No southbridge found.\n");
231 exit(1);
232 }
233
234 pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
235
236 if (sb->vendor_id != PCI_VENDOR_ID_INTEL) {
237 printf("Not an Intel(R) southbridge.\n");
238 exit(1);
239 }
240
241 nb = pci_get_dev(pacc, 0, 0, 0x00, 0);
242 if (!nb) {
243 printf("No northbridge found.\n");
244 exit(1);
245 }
246
247 pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
248
249 if (nb->vendor_id != PCI_VENDOR_ID_INTEL) {
250 printf("Not an Intel(R) northbridge.\n");
251 exit(1);
252 }
253
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000254 id = cpuid(1);
255 printf("Intel CPU: Family %x, Model %x\n",
256 (id >> 8) & 0xf, (id >> 4) & 0xf);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000257
258 /* Determine names */
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000259 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000260 if (nb->device_id == supported_chips_list[i].device_id)
261 nbname = supported_chips_list[i].name;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000262 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000263 if (sb->device_id == supported_chips_list[i].device_id)
264 sbname = supported_chips_list[i].name;
265
266 printf("Intel Northbridge: %04x:%04x (%s)\n",
267 nb->vendor_id, nb->device_id, nbname);
268
269 printf("Intel Southbridge: %04x:%04x (%s)\n",
270 sb->vendor_id, sb->device_id, sbname);
271
272 /* Now do the deed */
273
274 if (dump_gpios) {
275 print_gpios(sb);
276 printf("\n\n");
277 }
278
279 if (dump_rcba) {
280 print_rcba(sb);
281 printf("\n\n");
282 }
283
284 if (dump_pmbase) {
285 print_pmbase(sb);
286 printf("\n\n");
287 }
288
289 if (dump_mchbar) {
290 print_mchbar(nb);
291 printf("\n\n");
292 }
293
294 if (dump_epbar) {
295 print_epbar(nb);
296 printf("\n\n");
297 }
298
299 if (dump_dmibar) {
300 print_dmibar(nb);
301 printf("\n\n");
302 }
303
304 if (dump_pciexbar) {
305 print_pciexbar(nb);
306 printf("\n\n");
307 }
308
309 if (dump_coremsrs) {
310 print_intel_core_msrs();
311 printf("\n\n");
312 }
313
Stefan Reinauer03646be2008-05-13 22:14:21 +0000314 /* Clean up */
Stefan Reinauer03646be2008-05-13 22:14:21 +0000315 pci_free_dev(nb);
Uwe Hermanne23e3722009-09-30 17:14:24 +0000316 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"
Stefan Reinauer03646be2008-05-13 22:14:21 +0000317 pci_cleanup(pacc);
318
319 return 0;
320}