2 * viatool - dump all registers on an Intel CPU + chipset based system.
4 * Copyright (C) 2008-2010 by coresystems GmbH
5 * written by Stefan Reinauer <stepan@coresystems.de>
6 * Copyright (C) 2009 Carl-Daniel Hailfinger
7 * Copyright (C) 2013 Alexandru Gagniuc
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 * http://pci-ids.ucw.cz/read/PC/8086
34 * http://en.wikipedia.org/wiki/Intel_Tick-Tock
35 * http://en.wikipedia.org/wiki/List_of_Intel_chipsets
36 * http://en.wikipedia.org/wiki/Intel_Xeon_chipsets
39 uint16_t vendor_id
, device_id
;
41 } supported_chips_list
[] = {
42 { PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_VX900_SATA
, "VX900 SATA"},
43 /* Host bridges/DRAM controllers (Northbridges) */
44 { PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_VX900
, "VX900"},
45 /* Southbridges (LPC controllers) */
46 { PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_VX900_LPC
, "VX900" },
52 void *map_physical(uint64_t phys_addr
, size_t len
)
56 virt_addr
= mmap(0, len
, PROT_WRITE
| PROT_READ
, MAP_SHARED
,
57 fd_mem
, (off_t
) phys_addr
);
59 if (virt_addr
== MAP_FAILED
) {
60 printf("Error mapping physical memory 0x%08" PRIx64
"[0x%zx]\n",
68 void unmap_physical(void *virt_addr
, size_t len
)
70 munmap(virt_addr
, len
);
74 void print_version(void)
76 printf("inteltool v%s -- ", VIATOOL_VERSION
);
77 printf("Copyright (C) 2013 Alexandru Gagniuc\n\n");
79 "This program is free software: you can redistribute it and/or modify\n"
80 "it under the terms of the GNU General Public License as published by\n"
81 "the Free Software Foundation, version 2 of the License.\n\n"
82 "This program is distributed in the hope that it will be useful,\n"
83 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
84 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
85 "GNU General Public License for more details.\n\n"
86 "You should have received a copy of the GNU General Public License\n"
87 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
90 void print_usage(const char *name
)
92 printf("usage: %s [-vh?gGrpmedPMa]\n", name
);
94 " -v | --version: print the version\n"
95 " -h | --help: print this help\n\n"
96 " -M | --msrs: dump CPU MSRs\n"
97 " -a | --all: dump all known registers\n"
98 " -q | --quirks: dump hierarchical configs\n"
103 int main(int argc
, char *argv
[])
105 struct pci_access
*pacc
;
106 struct pci_dev
*sb
= NULL
, *nb
, *dev
;
107 int i
, opt
, option_index
= 0;
110 char *sbname
= "unknown", *nbname
= "unknown";
112 int dump_coremsrs
= 0, dump_quirks
= 0;
114 static struct option long_options
[] = {
115 {"version", 0, 0, 'v'},
117 {"mchbar", 0, 0, 'm'},
119 {"quirks", 0, 0, 'q'},
124 while ((opt
= getopt_long(argc
, argv
, "vh?gGrpmedPMaA",
125 long_options
, &option_index
)) != EOF
) {
144 print_usage(argv
[0]);
150 #if defined(__FreeBSD__)
151 if (open("/dev/io", O_RDWR
) < 0) {
157 printf("You need to be root.\n");
162 if ((fd_mem
= open("/dev/mem", O_RDWR
)) < 0) {
163 perror("Can not open /dev/mem");
172 /* Find the required devices */
173 for (dev
= pacc
->devices
; dev
; dev
= dev
->next
) {
174 pci_fill_info(dev
, PCI_FILL_CLASS
);
175 /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */
176 if (dev
->device_class
== 0x0601) { /* ISA/LPC bridge */
180 fprintf(stderr
, "Multiple devices with class ID"
181 " 0x0601, using %02x%02x:%02x.%02x\n",
182 dev
->domain
, dev
->bus
, dev
->dev
,
188 printf("No southbridge found.\n");
192 pci_fill_info(sb
, PCI_FILL_IDENT
|PCI_FILL_BASES
|PCI_FILL_SIZES
|PCI_FILL_CLASS
);
194 if (sb
->vendor_id
!= PCI_VENDOR_ID_VIA
) {
195 printf("Not a VIA southbridge.\n");
199 nb
= pci_get_dev(pacc
, 0, 0, 0x00, 0);
201 printf("No northbridge found.\n");
205 pci_fill_info(nb
, PCI_FILL_IDENT
|PCI_FILL_BASES
|PCI_FILL_SIZES
|PCI_FILL_CLASS
);
207 if (nb
->vendor_id
!= PCI_VENDOR_ID_VIA
) {
208 printf("Not a VIA northbridge.\n");
214 /* Intel has suggested applications to display the family of a CPU as
215 * the sum of the "Family" and the "Extended Family" fields shown
216 * above, and the model as the sum of the "Model" and the 4-bit
217 * left-shifted "Extended Model" fields.
218 * http://download.intel.com/design/processor/applnots/24161832.pdf
220 printf("CPU: Processor Type: %x, Family %x, Model %x, Stepping %x\n",
221 (id
>> 12) & 0x3, ((id
>> 8) & 0xf) + ((id
>> 20) & 0xff),
222 ((id
>> 12) & 0xf0) + ((id
>> 4) & 0xf), (id
& 0xf));
224 /* Determine names */
225 for (i
= 0; i
< ARRAY_SIZE(supported_chips_list
); i
++)
226 if (nb
->device_id
== supported_chips_list
[i
].device_id
)
227 nbname
= supported_chips_list
[i
].name
;
228 for (i
= 0; i
< ARRAY_SIZE(supported_chips_list
); i
++)
229 if (sb
->device_id
== supported_chips_list
[i
].device_id
)
230 sbname
= supported_chips_list
[i
].name
;
232 printf("Northbridge: %04x:%04x (%s)\n",
233 nb
->vendor_id
, nb
->device_id
, nbname
);
235 printf("Southbridge: %04x:%04x (%s)\n",
236 sb
->vendor_id
, sb
->device_id
, sbname
);
238 /* Now do the deed */
241 print_intel_core_msrs();
246 print_quirks_north(nb
, pacc
);
247 print_quirks_south(sb
, pacc
);
252 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"