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.
29 #include <machine/sysarch.h>
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");
88 void print_usage(const char *name
)
90 printf("usage: %s [-vh?gGrpmedPMa]\n", name
);
92 " -v | --version: print the version\n"
93 " -h | --help: print this help\n\n"
94 " -M | --msrs: dump CPU MSRs\n"
95 " -a | --all: dump all known registers\n"
96 " -q | --quirks: dump hierarchical configs\n"
101 int main(int argc
, char *argv
[])
103 struct pci_access
*pacc
;
104 struct pci_dev
*sb
= NULL
, *nb
, *dev
;
105 int i
, opt
, option_index
= 0;
108 char *sbname
= "unknown", *nbname
= "unknown";
110 int dump_coremsrs
= 0, dump_quirks
= 0;
112 static struct option long_options
[] = {
113 {"version", 0, 0, 'v'},
115 {"mchbar", 0, 0, 'm'},
117 {"quirks", 0, 0, 'q'},
122 while ((opt
= getopt_long(argc
, argv
, "vh?gGrpmedPMaA",
123 long_options
, &option_index
)) != EOF
) {
142 print_usage(argv
[0]);
148 #if defined(__FreeBSD__)
149 if (open("/dev/io", O_RDWR
) < 0) {
151 #elif defined(__NetBSD__)
156 if (x86_64_iopl(3)) {
163 printf("You need to be root.\n");
168 if ((fd_mem
= open("/dev/mem", O_RDWR
)) < 0) {
169 perror("Can not open /dev/mem");
178 /* Find the required devices */
179 for (dev
= pacc
->devices
; dev
; dev
= dev
->next
) {
180 pci_fill_info(dev
, PCI_FILL_CLASS
);
181 /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */
182 if (dev
->device_class
== 0x0601) { /* ISA/LPC bridge */
186 fprintf(stderr
, "Multiple devices with class ID"
187 " 0x0601, using %02x%02x:%02x.%02x\n",
188 dev
->domain
, dev
->bus
, dev
->dev
,
194 printf("No southbridge found.\n");
198 pci_fill_info(sb
, PCI_FILL_IDENT
|PCI_FILL_BASES
|PCI_FILL_SIZES
|PCI_FILL_CLASS
);
200 if (sb
->vendor_id
!= PCI_VENDOR_ID_VIA
) {
201 printf("Not a VIA southbridge.\n");
205 nb
= pci_get_dev(pacc
, 0, 0, 0x00, 0);
207 printf("No northbridge found.\n");
211 pci_fill_info(nb
, PCI_FILL_IDENT
|PCI_FILL_BASES
|PCI_FILL_SIZES
|PCI_FILL_CLASS
);
213 if (nb
->vendor_id
!= PCI_VENDOR_ID_VIA
) {
214 printf("Not a VIA northbridge.\n");
220 /* Intel has suggested applications to display the family of a CPU as
221 * the sum of the "Family" and the "Extended Family" fields shown
222 * above, and the model as the sum of the "Model" and the 4-bit
223 * left-shifted "Extended Model" fields.
224 * http://download.intel.com/design/processor/applnots/24161832.pdf
226 printf("CPU: Processor Type: %x, Family %x, Model %x, Stepping %x\n",
227 (id
>> 12) & 0x3, ((id
>> 8) & 0xf) + ((id
>> 20) & 0xff),
228 ((id
>> 12) & 0xf0) + ((id
>> 4) & 0xf), (id
& 0xf));
230 /* Determine names */
231 for (i
= 0; i
< ARRAY_SIZE(supported_chips_list
); i
++)
232 if (nb
->device_id
== supported_chips_list
[i
].device_id
)
233 nbname
= supported_chips_list
[i
].name
;
234 for (i
= 0; i
< ARRAY_SIZE(supported_chips_list
); i
++)
235 if (sb
->device_id
== supported_chips_list
[i
].device_id
)
236 sbname
= supported_chips_list
[i
].name
;
238 printf("Northbridge: %04x:%04x (%s)\n",
239 nb
->vendor_id
, nb
->device_id
, nbname
);
241 printf("Southbridge: %04x:%04x (%s)\n",
242 sb
->vendor_id
, sb
->device_id
, sbname
);
244 /* Now do the deed */
247 print_intel_core_msrs();
252 print_quirks_north(nb
, pacc
);
253 print_quirks_south(sb
, pacc
);
258 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"