blob: c8fa6ac4fb3d432bf188bded24c91f67729399f6 [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[] = {
Uwe Hermann710e8b12008-05-17 21:33:35 +000032 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845, "i845" },
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +000033 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945P, "i945P" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000034 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GM, "i945GM" },
Stefan Reinauer1162f252008-12-04 15:18:20 +000035 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM965, "PM965" },
36 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82975X, "i975X" },
37 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000038 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000039 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000040 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +000041 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000042 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" },
43 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" },
Uwe Hermann710e8b12008-05-17 21:33:35 +000044 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000045 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" },
46 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" }
47};
48
Stefan Reinauer1162f252008-12-04 15:18:20 +000049#ifndef DARWIN
50static int fd_mem;
51
52void *map_physical(unsigned long phys_addr, int len)
53{
54 void *virt_addr;
55
56 virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED,
57 fd_mem, (off_t) phys_addr);
58
59 if (virt_addr == MAP_FAILED) {
60 printf("Error mapping physical memory 0x%08x[0x%x]\n", phys_addr, len);
61 return NULL;
62 }
63
64 return virt_addr;
65}
66
67void unmap_physical(void *virt_addr, int len)
68{
69 munmap(virt_addr, len);
70}
71#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +000072
73void print_version(void)
74{
75 printf("inteltool v%s -- ", INTELTOOL_VERSION);
76 printf("Copyright (C) 2008 coresystems GmbH\n\n");
77 printf(
78 "This program is free software: you can redistribute it and/or modify\n"
79 "it under the terms of the GNU General Public License as published by\n"
80 "the Free Software Foundation, version 2 of the License.\n\n"
81 "This program is distributed in the hope that it will be useful,\n"
82 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
83 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
84 "GNU General Public License for more details.\n\n"
85 "You should have received a copy of the GNU General Public License\n"
86 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
87}
88
89void print_usage(const char *name)
90{
Stefan Reinauerd466e6a2008-05-14 13:52:50 +000091 printf("usage: %s [-vh?grpmedPMa]\n", name);
Stefan Reinauer03646be2008-05-13 22:14:21 +000092 printf("\n"
93 " -v | --version: print the version\n"
94 " -h | --help: print this help\n\n"
95 " -g | --gpio: dump soutbridge GPIO registers\n"
96 " -r | --rcba: dump soutbridge RCBA registers\n"
97 " -p | --pmbase: dump soutbridge Power Management registers\n\n"
98 " -m | --mchbar: dump northbridge Memory Controller registers\n"
99 " -e | --epbar: dump northbridge EPBAR registers\n"
100 " -d | --dmibar: dump northbridge DMIBAR registers\n"
101 " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n"
102 " -M | --msrs: dump CPU MSRs\n"
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000103 " -a | --all: dump all known registers\n"
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000104 "\n");
Stefan Reinauer03646be2008-05-13 22:14:21 +0000105 exit(1);
106}
107
108int main(int argc, char *argv[])
109{
110 struct pci_access *pacc;
111 struct pci_dev *sb, *nb;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000112 int i, opt, option_index = 0;
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000113 unsigned int id;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000114
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000115 char *sbname = "unknown", *nbname = "unknown";
Stefan Reinauer03646be2008-05-13 22:14:21 +0000116
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000117 int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0;
118 int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0;
119 int dump_pciexbar = 0, dump_coremsrs = 0;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000120
121 static struct option long_options[] = {
122 {"version", 0, 0, 'v'},
123 {"help", 0, 0, 'h'},
124 {"gpios", 0, 0, 'g'},
125 {"mchbar", 0, 0, 'm'},
126 {"rcba", 0, 0, 'r'},
127 {"pmbase", 0, 0, 'p'},
128 {"epbar", 0, 0, 'e'},
129 {"dmibar", 0, 0, 'd'},
130 {"pciexpress", 0, 0, 'P'},
131 {"msrs", 0, 0, 'M'},
132 {"all", 0, 0, 'a'},
133 {0, 0, 0, 0}
134 };
135
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000136 while ((opt = getopt_long(argc, argv, "vh?grpmedPMa",
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000137 long_options, &option_index)) != EOF) {
Stefan Reinauer03646be2008-05-13 22:14:21 +0000138 switch (opt) {
139 case 'v':
140 print_version();
141 exit(0);
142 break;
143 case 'g':
144 dump_gpios = 1;
145 break;
146 case 'm':
147 dump_mchbar = 1;
148 break;
149 case 'r':
150 dump_rcba = 1;
151 break;
152 case 'p':
153 dump_pmbase = 1;
154 break;
155 case 'e':
156 dump_epbar = 1;
157 break;
158 case 'd':
159 dump_dmibar = 1;
160 break;
161 case 'P':
162 dump_pciexbar = 1;
163 break;
164 case 'M':
165 dump_coremsrs = 1;
166 break;
167 case 'a':
168 dump_gpios = 1;
169 dump_mchbar = 1;
170 dump_rcba = 1;
171 dump_pmbase = 1;
172 dump_epbar = 1;
173 dump_dmibar = 1;
174 dump_pciexbar = 1;
175 dump_coremsrs = 1;
176 break;
177 case 'h':
178 case '?':
179 default:
180 print_usage(argv[0]);
181 exit(0);
182 break;
183 }
184 }
185
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000186 if (iopl(3)) {
187 printf("You need to be root.\n");
188 exit(1);
189 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000190
Stefan Reinauer1162f252008-12-04 15:18:20 +0000191#ifndef DARWIN
Stefan Reinauer03646be2008-05-13 22:14:21 +0000192 if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
193 perror("Can not open /dev/mem");
194 exit(1);
195 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000196#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +0000197
198 pacc = pci_alloc();
199 pci_init(pacc);
200 pci_scan_bus(pacc);
201
Stefan Reinauer03646be2008-05-13 22:14:21 +0000202 /* Find the required devices */
203
204 sb = pci_get_dev(pacc, 0, 0, 0x1f, 0);
205 if (!sb) {
206 printf("No southbridge found.\n");
207 exit(1);
208 }
209
210 pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
211
212 if (sb->vendor_id != PCI_VENDOR_ID_INTEL) {
213 printf("Not an Intel(R) southbridge.\n");
214 exit(1);
215 }
216
217 nb = pci_get_dev(pacc, 0, 0, 0x00, 0);
218 if (!nb) {
219 printf("No northbridge found.\n");
220 exit(1);
221 }
222
223 pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
224
225 if (nb->vendor_id != PCI_VENDOR_ID_INTEL) {
226 printf("Not an Intel(R) northbridge.\n");
227 exit(1);
228 }
229
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000230 id = cpuid(1);
231 printf("Intel CPU: Family %x, Model %x\n",
232 (id >> 8) & 0xf, (id >> 4) & 0xf);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000233
234 /* Determine names */
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000235 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000236 if (nb->device_id == supported_chips_list[i].device_id)
237 nbname = supported_chips_list[i].name;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000238 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000239 if (sb->device_id == supported_chips_list[i].device_id)
240 sbname = supported_chips_list[i].name;
241
242 printf("Intel Northbridge: %04x:%04x (%s)\n",
243 nb->vendor_id, nb->device_id, nbname);
244
245 printf("Intel Southbridge: %04x:%04x (%s)\n",
246 sb->vendor_id, sb->device_id, sbname);
247
248 /* Now do the deed */
249
250 if (dump_gpios) {
251 print_gpios(sb);
252 printf("\n\n");
253 }
254
255 if (dump_rcba) {
256 print_rcba(sb);
257 printf("\n\n");
258 }
259
260 if (dump_pmbase) {
261 print_pmbase(sb);
262 printf("\n\n");
263 }
264
265 if (dump_mchbar) {
266 print_mchbar(nb);
267 printf("\n\n");
268 }
269
270 if (dump_epbar) {
271 print_epbar(nb);
272 printf("\n\n");
273 }
274
275 if (dump_dmibar) {
276 print_dmibar(nb);
277 printf("\n\n");
278 }
279
280 if (dump_pciexbar) {
281 print_pciexbar(nb);
282 printf("\n\n");
283 }
284
285 if (dump_coremsrs) {
286 print_intel_core_msrs();
287 printf("\n\n");
288 }
289
Stefan Reinauer03646be2008-05-13 22:14:21 +0000290 /* Clean up */
Stefan Reinauer03646be2008-05-13 22:14:21 +0000291 pci_free_dev(nb);
292 pci_free_dev(sb);
293 pci_cleanup(pacc);
294
295 return 0;
296}