southbridge/ricoh,ti: Remove trailing whitespace in debug output
[coreboot.git] / util / viatool / viatool.c
blob3f19f2819cdf5bb3c84ee052125d12db5d17616b
1 /*
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.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <inttypes.h>
26 #include <getopt.h>
27 #include <fcntl.h>
28 #include <sys/mman.h>
29 #include <unistd.h>
30 #include "viatool.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
38 static const struct {
39 uint16_t vendor_id, device_id;
40 char *name;
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" },
49 #ifndef __DARWIN__
50 static int fd_mem;
52 void *map_physical(uint64_t phys_addr, size_t len)
54 void *virt_addr;
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",
61 phys_addr, len);
62 return NULL;
65 return virt_addr;
68 void unmap_physical(void *virt_addr, size_t len)
70 munmap(virt_addr, len);
72 #endif
74 void print_version(void)
76 printf("inteltool v%s -- ", VIATOOL_VERSION);
77 printf("Copyright (C) 2013 Alexandru Gagniuc\n\n");
78 printf(
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);
93 printf("\n"
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"
99 "\n");
100 exit(1);
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;
108 unsigned int id;
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'},
116 {"help", 0, 0, 'h'},
117 {"mchbar", 0, 0, 'm'},
118 {"msrs", 0, 0, 'M'},
119 {"quirks", 0, 0, 'q'},
120 {"all", 0, 0, 'a'},
121 {0, 0, 0, 0}
124 while ((opt = getopt_long(argc, argv, "vh?gGrpmedPMaA",
125 long_options, &option_index)) != EOF) {
126 switch (opt) {
127 case 'v':
128 print_version();
129 exit(0);
130 break;
131 case 'M':
132 dump_coremsrs = 1;
133 break;
134 case 'q':
135 dump_quirks = 1;
136 break;
137 case 'a':
138 dump_coremsrs = 1;
139 dump_quirks = 1;
140 break;
141 case 'h':
142 case '?':
143 default:
144 print_usage(argv[0]);
145 exit(0);
146 break;
150 #if defined(__FreeBSD__)
151 if (open("/dev/io", O_RDWR) < 0) {
152 perror("/dev/io");
153 #else
154 if (iopl(3)) {
155 perror("iopl");
156 #endif
157 printf("You need to be root.\n");
158 exit(1);
161 #ifndef __DARWIN__
162 if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
163 perror("Can not open /dev/mem");
164 exit(1);
166 #endif
168 pacc = pci_alloc();
169 pci_init(pacc);
170 pci_scan_bus(pacc);
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 */
177 if (sb == NULL)
178 sb = dev;
179 else
180 fprintf(stderr, "Multiple devices with class ID"
181 " 0x0601, using %02x%02x:%02x.%02x\n",
182 dev->domain, dev->bus, dev->dev,
183 dev->func);
187 if (!sb) {
188 printf("No southbridge found.\n");
189 exit(1);
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");
196 exit(1);
199 nb = pci_get_dev(pacc, 0, 0, 0x00, 0);
200 if (!nb) {
201 printf("No northbridge found.\n");
202 exit(1);
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");
209 exit(1);
212 id = cpuid(1);
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 */
240 if (dump_coremsrs) {
241 print_intel_core_msrs();
242 printf("\n\n");
245 if (dump_quirks) {
246 print_quirks_north(nb, pacc);
247 print_quirks_south(sb, pacc);
250 /* Clean up */
251 pci_free_dev(nb);
252 // pci_free_dev(sb); // TODO: glibc detected "double free or corruption"
253 pci_cleanup(pacc);
255 return 0;