blob: f91b3ade68d701c54f93ccac95c65efc6b7f0894 [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 Reinauer14e22772010-04-27 06:56:47 +00004 * Copyright (C) 2008-2010 by coresystems GmbH
5 * written by Stefan Reinauer <stepan@coresystems.de>
Idwer Vollering3f91d812010-10-24 13:50:13 +00006 * Copyright (C) 2009 Carl-Daniel Hailfinger
Stefan Reinauer14e22772010-04-27 06:56:47 +00007 *
Stefan Reinauer03646be2008-05-13 22:14:21 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
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
Patrick Georgib890a122015-03-26 15:17:45 +010019 * Foundation, Inc.
Stefan Reinauer03646be2008-05-13 22:14:21 +000020 */
21
Stefan Reinauer03646be2008-05-13 22:14:21 +000022#include <stdio.h>
Stefan Reinauer03646be2008-05-13 22:14:21 +000023#include <stdlib.h>
Stefan Reinauera7b296d2011-11-14 12:40:34 -080024#include <inttypes.h>
Stefan Reinauer03646be2008-05-13 22:14:21 +000025#include <getopt.h>
Stefan Reinauer23190272008-08-20 13:41:24 +000026#include <fcntl.h>
Stefan Reinauer1162f252008-12-04 15:18:20 +000027#include <sys/mman.h>
Idwer Vollering3f91d812010-10-24 13:50:13 +000028#include <unistd.h>
Stefan Tauner0c8b7d12013-04-05 20:38:08 +020029#include "inteltool.h"
Stefan Reinauer03646be2008-05-13 22:14:21 +000030
Stefan Tauner04c06002012-10-13 02:19:30 +020031/*
32 * http://pci-ids.ucw.cz/read/PC/8086
33 * http://en.wikipedia.org/wiki/Intel_Tick-Tock
34 * http://en.wikipedia.org/wiki/List_of_Intel_chipsets
35 * http://en.wikipedia.org/wiki/Intel_Xeon_chipsets
36 */
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000037static const struct {
38 uint16_t vendor_id, device_id;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +000039 char *name;
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +000040} supported_chips_list[] = {
Stefan Tauner04c06002012-10-13 02:19:30 +020041 /* Host bridges/DRAM controllers (Northbridges) */
42 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX, "443LX" },
43 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX, "443BX" },
44 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_NO_AGP, "443BX without AGP" },
45 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810, "810" },
46 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_DC, "810-DC100" },
47 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_DC, "810E DC-133" },
48 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82830M, "830M" },
49 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845, "845" },
50 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865, "865" },
51 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915, "915G/P/GV/GL/PL/910GL" },
52 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945P, "945P" },
53 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GM, "945GM" },
54 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GSE, "945GSE" },
Stefan Tauner1a00cf02012-10-13 06:23:52 +020055 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82946, "946GZ/PL" },
Stefan Tauner04c06002012-10-13 02:19:30 +020056 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82965PM, "965PM" },
57 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q965, "Q963/82Q965" },
58 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82975X, "975X" },
Loïc Grenié8429de72009-11-02 15:01:49 +000059 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82G33, "P35/G33/G31/P31" },
60 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q33, "Q33" },
Stefan Tauner04c06002012-10-13 02:19:30 +020061 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q35, "Q35" },
62 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82X38, "X38/X48" },
63 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_32X0, "3200/3210" },
Damien Zammit9c986642015-08-17 21:04:41 +100064 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82XX4X, "GL40/GS40/GM45/GS45/PM45" },
65 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q45, "Q45/Q43" },
66 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82G45, "G45/G43/P45/P43" },
67 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82G41, "G41" },
68 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82B43, "B43 (Base)" },
69 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82B43_2, "B43 (Soft)" },
Stefan Tauner04c06002012-10-13 02:19:30 +020070 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82X58, "X58" },
71 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000P, "Intel i5000P Memory Controller Hub" },
72 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000X, "Intel i5000X Memory Controller Hub" },
73 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000Z, "Intel i5000Z Memory Controller Hub" },
74 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000V, "Intel i5000V Memory Controller Hub" },
75 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_POULSBO, "SCH Poulsbo" },
Corey Osgood23d98c72010-07-29 19:25:31 +000076 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ATOM_DXXX, "Atom D400/500 Series" },
Idwer Vollering312fc962010-12-17 22:34:58 +000077 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ATOM_NXXX, "Atom N400 Series" },
Stefan Tauner04c06002012-10-13 02:19:30 +020078 /* Host bridges /DRAM controllers integrated in CPUs */
Stefan Taunerdbc6fcd2013-06-20 18:05:06 +020079 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_0TH_GEN, "0th generation (Nehalem family) Core Processor" },
Stefan Tauner04c06002012-10-13 02:19:30 +020080 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_1ST_GEN, "1st generation (Westmere family) Core Processor" },
Felix Held0cc8f292014-11-05 03:18:44 +010081 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D, "2nd generation (Sandy Bridge family) Core Processor (Desktop)" },
82 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M, "2nd generation (Sandy Bridge family) Core Processor (Mobile)" },
Felix Heldfac95e32014-11-09 00:11:28 +010083 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3, "2nd generation (Sandy Bridge family) Core Processor (Xeon E3)" },
84 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D, "3rd generation (Ivy Bridge family) Core Processor (Desktop)" },
85 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M, "3rd generation (Ivy Bridge family) Core Processor (Mobile)" },
86 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3, "3rd generation (Ivy Bridge family) Core Processor (Xeon E3 v2)" },
87 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c, "3rd generation (Ivy Bridge family) Core Processor" },
88 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_D, "4th generation (Haswell family) Core Processor (Desktop)" },
89 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_M, "4th generation (Haswell family) Core Processor (Mobile)" },
90 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_E3, "4th generation (Haswell family) Core Processor (Xeon E3 v3)" },
Dennis Wassenbergae6685f2014-10-30 10:30:40 +010091 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_U, "4th generation (Haswell family) Core Processor ULT" },
Matt DeVillier5b667df2015-05-14 21:58:33 -050092 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_U, "5th generation (Broadwell family) Core Processor ULT" },
Martin Roth51dde6f2014-12-07 22:11:54 -070093 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL, "Bay Trail" },
Stefan Tauner04c06002012-10-13 02:19:30 +020094 /* Southbridges (LPC controllers) */
95 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371XX, "371AB/EB/MB" },
Warren Turkal9702b6b2009-06-30 14:11:42 +000096 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10R, "ICH10R" },
Anton Kochkovda0b4562010-05-30 12:33:12 +000097 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9DH, "ICH9DH" },
98 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9DO, "ICH9DO" },
99 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9R, "ICH9R" },
100 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9, "ICH9" },
101 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9M, "ICH9M" },
102 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9ME, "ICH9M-E" },
Stefan Reinauer1162f252008-12-04 15:18:20 +0000103 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" },
Lubomir Rintel2a13bad2015-03-01 10:14:15 +0100104 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8ME, "ICH8M-E" },
Corey Osgoodf366ce02010-08-17 08:33:44 +0000105 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8, "ICH8" },
106 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_NM10, "NM10" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +0000107 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +0000108 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +0000109 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" },
Stefan Reinauerf9b99452008-05-14 20:05:00 +0000110 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" },
Pat Erleyca3548e2010-04-21 06:23:19 +0000111 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6, "ICH6" },
Idwer Vollering312fc962010-12-17 22:34:58 +0000112 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH5, "ICH5" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +0000113 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" },
114 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" },
Uwe Hermann710e8b12008-05-17 21:33:35 +0000115 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +0000116 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" },
Maciej Pijanka90d17402009-09-30 17:05:46 +0000117 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" },
Stefan Tauner04c06002012-10-13 02:19:30 +0200118 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I63XX, "631xESB/632xESB/3100" },
119 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_POULSBO_LPC, "SCH Poulsbo" },
Stefan Tauner088f5692013-05-28 11:30:25 +0200120 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_DESKTOP, "3400 Desktop" },
121 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_MOBILE, "3400 Mobile" },
122 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_P55, "P55" },
123 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM55, "PM55" },
124 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H55, "H55" },
125 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM57, "QM57" },
126 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H57, "H57" },
127 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM55, "HM55" },
128 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q57, "Q57" },
129 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM57, "HM57" },
130 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_MOBILE_SFF, "3400 Mobile SFF" },
131 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B55_A, "B55" },
132 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS57, "QS57" },
133 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400, "3400" },
134 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3420, "3420" },
135 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3450, "3450" },
136 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B55_B, "B55" },
Nico Huber76d60492013-03-29 17:57:15 +0100137 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z68, "Z68" },
138 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_P67, "P67" },
139 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_UM67, "UM67" },
140 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM65, "HM65" },
141 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H67, "H67" },
142 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM67, "HM67" },
143 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q65, "Q65" },
144 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS67, "QS67" },
145 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q67, "Q67" },
146 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM67, "QM67" },
147 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B65, "B65" },
148 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C202, "C202" },
149 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C204, "C204" },
150 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C206, "C206" },
151 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H61, "H61" },
Stefan Tauner04c06002012-10-13 02:19:30 +0200152 { PCI_VENDOR_ID_INTEL, 0x1d40, "X79" },
153 { PCI_VENDOR_ID_INTEL, 0x1d41, "X79" },
Nico Huber76d60492013-03-29 17:57:15 +0100154 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z77, "Z77" },
155 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z75, "Z75" },
156 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q77, "Q77" },
157 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q75, "Q75" },
158 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B75, "B75" },
159 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H77, "H77" },
160 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C216, "C216" },
161 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM77, "QM77" },
162 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS77, "QS77" },
163 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM77, "HM77" },
164 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_UM77, "UM77" },
165 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM76, "HM76" },
166 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM75, "HM75" },
167 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM70, "HM70" },
168 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_NM70, "NM70" },
Dennis Wassenbergae6685f2014-10-30 10:30:40 +0100169 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_FULL, "Lynx Point Low Power Full Featured Engineering Sample" },
170 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_PREM, "Lynx Point Low Power Premium SKU" },
171 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_BASE, "Lynx Point Low Power Base SKU" },
Matt DeVillier5b667df2015-05-14 21:58:33 -0500172 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP, "Wildcat Point Low Power SKU" },
Stefan Tauner04c06002012-10-13 02:19:30 +0200173 { PCI_VENDOR_ID_INTEL, 0x2310, "DH89xxCC" },
Martin Roth51dde6f2014-12-07 22:11:54 -0700174 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_LPC, "Bay Trail" },
Stefan Reinauer9f7af6e2008-05-14 14:22:59 +0000175};
176
Stefan Reinauerf7f2f252009-09-01 09:52:14 +0000177#ifndef __DARWIN__
Stefan Reinauer1162f252008-12-04 15:18:20 +0000178static int fd_mem;
179
Stefan Reinauercff573d2011-03-18 22:08:39 +0000180void *map_physical(uint64_t phys_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +0000181{
182 void *virt_addr;
183
184 virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED,
185 fd_mem, (off_t) phys_addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000186
Stefan Reinauer1162f252008-12-04 15:18:20 +0000187 if (virt_addr == MAP_FAILED) {
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800188 printf("Error mapping physical memory 0x%08" PRIx64 "[0x%zx]\n",
189 phys_addr, len);
Stefan Reinauer1162f252008-12-04 15:18:20 +0000190 return NULL;
191 }
192
193 return virt_addr;
194}
195
Stefan Reinauerf7f2f252009-09-01 09:52:14 +0000196void unmap_physical(void *virt_addr, size_t len)
Stefan Reinauer1162f252008-12-04 15:18:20 +0000197{
198 munmap(virt_addr, len);
199}
200#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +0000201
202void print_version(void)
203{
204 printf("inteltool v%s -- ", INTELTOOL_VERSION);
205 printf("Copyright (C) 2008 coresystems GmbH\n\n");
206 printf(
207 "This program is free software: you can redistribute it and/or modify\n"
208 "it under the terms of the GNU General Public License as published by\n"
209 "the Free Software Foundation, version 2 of the License.\n\n"
210 "This program is distributed in the hope that it will be useful,\n"
211 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
212 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
213 "GNU General Public License for more details.\n\n"
214 "You should have received a copy of the GNU General Public License\n"
215 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
216}
217
218void print_usage(const char *name)
219{
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100220 printf("usage: %s [-vh?gGrpmedPMas]\n", name);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000221 printf("\n"
222 " -v | --version: print the version\n"
223 " -h | --help: print this help\n\n"
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100224 " -s | --spi: dump southbridge spi and bios_cntrl registers\n"
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200225 " -f | --gfx: dump graphics registers\n"
Idwer Volleringb123e0d2014-08-25 23:59:42 +0200226 " -g | --gpio: dump southbridge GPIO registers\n"
Nico Huber09dcbf02013-04-01 15:08:04 +0200227 " -G | --gpio-diffs: show GPIO differences from defaults\n"
Idwer Volleringb123e0d2014-08-25 23:59:42 +0200228 " -r | --rcba: dump southbridge RCBA registers\n"
229 " -p | --pmbase: dump southbridge Power Management registers\n\n"
Stefan Reinauer03646be2008-05-13 22:14:21 +0000230 " -m | --mchbar: dump northbridge Memory Controller registers\n"
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200231 " -S FILE | --spd=FILE: generate spd.bin equivalent to current timings\n"
Stefan Reinauer03646be2008-05-13 22:14:21 +0000232 " -e | --epbar: dump northbridge EPBAR registers\n"
233 " -d | --dmibar: dump northbridge DMIBAR registers\n"
234 " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n"
235 " -M | --msrs: dump CPU MSRs\n"
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100236 " -A | --ambs: dump AMB registers\n"
Stefan Reinauerd466e6a2008-05-14 13:52:50 +0000237 " -a | --all: dump all known registers\n"
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000238 "\n");
Stefan Reinauer03646be2008-05-13 22:14:21 +0000239 exit(1);
240}
241
242int main(int argc, char *argv[])
243{
244 struct pci_access *pacc;
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200245 struct pci_dev *sb = NULL, *nb, *gfx = NULL, *dev;
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200246 const char *dump_spd_file = 0;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000247 int i, opt, option_index = 0;
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000248 unsigned int id;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000249
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200250 char *sbname = "unknown", *nbname = "unknown", *gfxname = "unknown";
Stefan Reinauer03646be2008-05-13 22:14:21 +0000251
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000252 int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0;
253 int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0;
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100254 int dump_pciexbar = 0, dump_coremsrs = 0, dump_ambs = 0;
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200255 int dump_spi = 0, dump_gfx = 0;
Nico Huber09dcbf02013-04-01 15:08:04 +0200256 int show_gpio_diffs = 0;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000257
258 static struct option long_options[] = {
259 {"version", 0, 0, 'v'},
260 {"help", 0, 0, 'h'},
261 {"gpios", 0, 0, 'g'},
Nico Huber09dcbf02013-04-01 15:08:04 +0200262 {"gpio-diffs", 0, 0, 'G'},
Stefan Reinauer03646be2008-05-13 22:14:21 +0000263 {"mchbar", 0, 0, 'm'},
264 {"rcba", 0, 0, 'r'},
265 {"pmbase", 0, 0, 'p'},
266 {"epbar", 0, 0, 'e'},
267 {"dmibar", 0, 0, 'd'},
268 {"pciexpress", 0, 0, 'P'},
269 {"msrs", 0, 0, 'M'},
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100270 {"ambs", 0, 0, 'A'},
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100271 {"spi", 0, 0, 's'},
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200272 {"spd", 0, 0, 'S'},
Stefan Reinauer03646be2008-05-13 22:14:21 +0000273 {"all", 0, 0, 'a'},
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200274 {"gfx", 0, 0, 'f'},
Stefan Reinauer03646be2008-05-13 22:14:21 +0000275 {0, 0, 0, 0}
276 };
277
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200278 while ((opt = getopt_long(argc, argv, "vh?gGrpmedPMaAsfS:",
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000279 long_options, &option_index)) != EOF) {
Stefan Reinauer03646be2008-05-13 22:14:21 +0000280 switch (opt) {
281 case 'v':
282 print_version();
283 exit(0);
284 break;
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200285 case 'S':
286 dump_spd_file = optarg;
287 dump_mchbar = 1;
288 break;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000289 case 'g':
290 dump_gpios = 1;
291 break;
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200292 case 'f':
293 dump_gfx = 1;
294 break;
Nico Huber09dcbf02013-04-01 15:08:04 +0200295 case 'G':
296 show_gpio_diffs = 1;
297 break;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000298 case 'm':
299 dump_mchbar = 1;
300 break;
301 case 'r':
302 dump_rcba = 1;
303 break;
304 case 'p':
305 dump_pmbase = 1;
306 break;
307 case 'e':
308 dump_epbar = 1;
309 break;
310 case 'd':
311 dump_dmibar = 1;
312 break;
313 case 'P':
314 dump_pciexbar = 1;
315 break;
316 case 'M':
317 dump_coremsrs = 1;
318 break;
319 case 'a':
320 dump_gpios = 1;
Nico Huber09dcbf02013-04-01 15:08:04 +0200321 show_gpio_diffs = 1;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000322 dump_mchbar = 1;
323 dump_rcba = 1;
324 dump_pmbase = 1;
325 dump_epbar = 1;
326 dump_dmibar = 1;
327 dump_pciexbar = 1;
328 dump_coremsrs = 1;
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100329 dump_ambs = 1;
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100330 dump_spi = 1;
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200331 dump_gfx = 1;
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100332 break;
333 case 'A':
334 dump_ambs = 1;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000335 break;
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100336 case 's':
337 dump_spi = 1;
338 break;
Stefan Reinauer03646be2008-05-13 22:14:21 +0000339 case 'h':
340 case '?':
341 default:
342 print_usage(argv[0]);
343 exit(0);
344 break;
345 }
346 }
347
Idwer Vollering3f91d812010-10-24 13:50:13 +0000348#if defined(__FreeBSD__)
Stefan Tauner0c8b7d12013-04-05 20:38:08 +0200349 if (open("/dev/io", O_RDWR) < 0) {
Idwer Vollering3f91d812010-10-24 13:50:13 +0000350 perror("/dev/io");
351#else
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000352 if (iopl(3)) {
Idwer Vollering3f91d812010-10-24 13:50:13 +0000353 perror("iopl");
354#endif
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000355 printf("You need to be root.\n");
356 exit(1);
357 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000358
Stefan Reinauerf7f2f252009-09-01 09:52:14 +0000359#ifndef __DARWIN__
Stefan Reinauer03646be2008-05-13 22:14:21 +0000360 if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
361 perror("Can not open /dev/mem");
362 exit(1);
363 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000364#endif
Stefan Reinauer03646be2008-05-13 22:14:21 +0000365
366 pacc = pci_alloc();
367 pci_init(pacc);
368 pci_scan_bus(pacc);
369
Stefan Reinauer03646be2008-05-13 22:14:21 +0000370 /* Find the required devices */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000371 for (dev = pacc->devices; dev; dev = dev->next) {
Maciej Pijanka90d17402009-09-30 17:05:46 +0000372 pci_fill_info(dev, PCI_FILL_CLASS);
373 /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */
374 if (dev->device_class == 0x0601) { /* ISA/LPC bridge */
Mathias Krause5ad6ec52014-11-05 21:27:01 +0100375 if (sb == NULL) {
Maciej Pijanka90d17402009-09-30 17:05:46 +0000376 sb = dev;
Mathias Krause5ad6ec52014-11-05 21:27:01 +0100377 } else {
Maciej Pijanka90d17402009-09-30 17:05:46 +0000378 fprintf(stderr, "Multiple devices with class ID"
379 " 0x0601, using %02x%02x:%02x.%02x\n",
Mathias Krause5ad6ec52014-11-05 21:27:01 +0100380 sb->domain, sb->bus, sb->dev, sb->func);
381 break;
382 }
Maciej Pijanka90d17402009-09-30 17:05:46 +0000383 }
384 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000385
Stefan Reinauer03646be2008-05-13 22:14:21 +0000386 if (!sb) {
387 printf("No southbridge found.\n");
388 exit(1);
389 }
390
391 pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
392
393 if (sb->vendor_id != PCI_VENDOR_ID_INTEL) {
394 printf("Not an Intel(R) southbridge.\n");
395 exit(1);
396 }
397
398 nb = pci_get_dev(pacc, 0, 0, 0x00, 0);
399 if (!nb) {
400 printf("No northbridge found.\n");
401 exit(1);
402 }
403
404 pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
405
406 if (nb->vendor_id != PCI_VENDOR_ID_INTEL) {
407 printf("Not an Intel(R) northbridge.\n");
408 exit(1);
409 }
410
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200411 gfx = pci_get_dev(pacc, 0, 0, 0x02, 0);
412
413 if (gfx) {
414 pci_fill_info(gfx, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
415
416 if (gfx->vendor_id != PCI_VENDOR_ID_INTEL)
417 gfx = 0;
418 }
419
Stefan Reinauer26ba0912008-08-18 10:58:09 +0000420 id = cpuid(1);
Stefan Reinauer74cd56982010-06-01 10:04:28 +0000421
422 /* Intel has suggested applications to display the family of a CPU as
423 * the sum of the "Family" and the "Extended Family" fields shown
424 * above, and the model as the sum of the "Model" and the 4-bit
425 * left-shifted "Extended Model" fields.
426 * http://download.intel.com/design/processor/applnots/24161832.pdf
427 */
Damien Zammitdcea7002013-07-17 23:59:40 +1000428 printf("CPU: ID 0x%x, Processor Type 0x%x, Family 0x%x, Model 0x%x, Stepping 0x%x\n",
429 id, (id >> 12) & 0x3, ((id >> 8) & 0xf) + ((id >> 20) & 0xff),
Stefan Reinauer74cd56982010-06-01 10:04:28 +0000430 ((id >> 12) & 0xf0) + ((id >> 4) & 0xf), (id & 0xf));
Stefan Reinauer03646be2008-05-13 22:14:21 +0000431
432 /* Determine names */
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000433 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000434 if (nb->device_id == supported_chips_list[i].device_id)
435 nbname = supported_chips_list[i].name;
Uwe Hermann9a6b6b52008-05-14 21:20:55 +0000436 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
Stefan Reinauer03646be2008-05-13 22:14:21 +0000437 if (sb->device_id == supported_chips_list[i].device_id)
438 sbname = supported_chips_list[i].name;
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200439 if (gfx) {
440 for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++)
441 if (gfx->device_id == supported_chips_list[i].device_id)
442 gfxname = supported_chips_list[i].name;
443 }
Stefan Reinauer03646be2008-05-13 22:14:21 +0000444
Stefan Tauner04c06002012-10-13 02:19:30 +0200445 printf("Northbridge: %04x:%04x (%s)\n",
Stefan Reinauer03646be2008-05-13 22:14:21 +0000446 nb->vendor_id, nb->device_id, nbname);
447
Stefan Tauner04c06002012-10-13 02:19:30 +0200448 printf("Southbridge: %04x:%04x (%s)\n",
Stefan Reinauer03646be2008-05-13 22:14:21 +0000449 sb->vendor_id, sb->device_id, sbname);
450
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200451 if (gfx) {
452 printf("IGD: %04x:%04x (%s)\n",
453 gfx->vendor_id, gfx->device_id, gfxname);
454 }
455
Stefan Reinauer03646be2008-05-13 22:14:21 +0000456 /* Now do the deed */
457
458 if (dump_gpios) {
Nico Huber09dcbf02013-04-01 15:08:04 +0200459 print_gpios(sb, 1, show_gpio_diffs);
460 printf("\n\n");
461 } else if (show_gpio_diffs) {
462 print_gpios(sb, 0, show_gpio_diffs);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000463 printf("\n\n");
464 }
465
466 if (dump_rcba) {
467 print_rcba(sb);
468 printf("\n\n");
469 }
470
471 if (dump_pmbase) {
Tobias Diedrich3645e612010-11-27 14:44:19 +0000472 print_pmbase(sb, pacc);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000473 printf("\n\n");
474 }
475
476 if (dump_mchbar) {
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200477 print_mchbar(nb, pacc, dump_spd_file);
Stefan Reinauer03646be2008-05-13 22:14:21 +0000478 printf("\n\n");
479 }
480
481 if (dump_epbar) {
482 print_epbar(nb);
483 printf("\n\n");
484 }
485
486 if (dump_dmibar) {
487 print_dmibar(nb);
488 printf("\n\n");
489 }
490
491 if (dump_pciexbar) {
492 print_pciexbar(nb);
493 printf("\n\n");
494 }
495
496 if (dump_coremsrs) {
497 print_intel_core_msrs();
498 printf("\n\n");
499 }
500
Sven Schnelle4b7b3202012-01-08 15:27:18 +0100501 if (dump_ambs) {
502 print_ambs(nb, pacc);
503 }
Alexander Couzensaa3dd5d2015-01-03 02:52:10 +0100504
505 if (dump_spi) {
506 print_spi(sb);
507 }
Vladimir Serbinenko188aec02015-05-20 14:04:41 +0200508
509 if (dump_gfx) {
510 print_gfx(gfx);
511 }
512
Stefan Reinauer03646be2008-05-13 22:14:21 +0000513 /* Clean up */
Stefan Reinauer03646be2008-05-13 22:14:21 +0000514 pci_free_dev(nb);
Uwe Hermanne23e3722009-09-30 17:14:24 +0000515 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"
Stefan Reinauer03646be2008-05-13 22:14:21 +0000516 pci_cleanup(pacc);
517
518 return 0;
519}