Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * inteltool - dump all registers on an Intel CPU + chipset based system. |
| 3 | * |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 by coresystems GmbH |
| 5 | * written by Stefan Reinauer <stepan@coresystems.de> |
Idwer Vollering | 3f91d81 | 2010-10-24 13:50:13 +0000 | [diff] [blame] | 6 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 7 | * |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 8 | * 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 |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 22 | #include <stdio.h> |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
Stefan Reinauer | a7b296d | 2011-11-14 12:40:34 -0800 | [diff] [blame] | 24 | #include <inttypes.h> |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 25 | #include <getopt.h> |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 26 | #include <fcntl.h> |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 27 | #include <sys/mman.h> |
Idwer Vollering | 3f91d81 | 2010-10-24 13:50:13 +0000 | [diff] [blame] | 28 | #include <unistd.h> |
Stefan Tauner | 0c8b7d1 | 2013-04-05 20:38:08 +0200 | [diff] [blame] | 29 | #include "inteltool.h" |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 30 | |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 31 | /* |
| 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 Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 37 | static const struct { |
| 38 | uint16_t vendor_id, device_id; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 39 | char *name; |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 40 | } supported_chips_list[] = { |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 41 | /* 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 Tauner | 1a00cf0 | 2012-10-13 06:23:52 +0200 | [diff] [blame] | 55 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82946, "946GZ/PL" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 56 | { 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é | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 59 | { 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 Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 61 | { 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" }, |
| 64 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82X4X, "GL40/GS40/GM45/GS45/PM45" }, |
| 65 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82X58, "X58" }, |
| 66 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000P, "Intel i5000P Memory Controller Hub" }, |
| 67 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000X, "Intel i5000X Memory Controller Hub" }, |
| 68 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000Z, "Intel i5000Z Memory Controller Hub" }, |
| 69 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000V, "Intel i5000V Memory Controller Hub" }, |
| 70 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_POULSBO, "SCH Poulsbo" }, |
Corey Osgood | 23d98c7 | 2010-07-29 19:25:31 +0000 | [diff] [blame] | 71 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ATOM_DXXX, "Atom D400/500 Series" }, |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 72 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ATOM_NXXX, "Atom N400 Series" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 73 | /* Host bridges /DRAM controllers integrated in CPUs */ |
Stefan Tauner | dbc6fcd | 2013-06-20 18:05:06 +0200 | [diff] [blame] | 74 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_0TH_GEN, "0th generation (Nehalem family) Core Processor" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 75 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_1ST_GEN, "1st generation (Westmere family) Core Processor" }, |
| 76 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_2ND_GEN, "2nd generation (Sandy Bridge family) Core Processor" }, |
| 77 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_3RD_GEN, "3rd generation (Ivy Bridge family) Core Processor" }, |
| 78 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CORE_4TH_GEN, "4th generation (Haswell family) Core Processor" }, |
| 79 | /* Southbridges (LPC controllers) */ |
| 80 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371XX, "371AB/EB/MB" }, |
Warren Turkal | 9702b6b | 2009-06-30 14:11:42 +0000 | [diff] [blame] | 81 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10R, "ICH10R" }, |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 82 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9DH, "ICH9DH" }, |
| 83 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9DO, "ICH9DO" }, |
| 84 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9R, "ICH9R" }, |
| 85 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9, "ICH9" }, |
| 86 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9M, "ICH9M" }, |
| 87 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9ME, "ICH9M-E" }, |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 88 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" }, |
Corey Osgood | f366ce0 | 2010-08-17 08:33:44 +0000 | [diff] [blame] | 89 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8, "ICH8" }, |
| 90 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_NM10, "NM10" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 91 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" }, |
Stefan Reinauer | f9b9945 | 2008-05-14 20:05:00 +0000 | [diff] [blame] | 92 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 93 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" }, |
Stefan Reinauer | f9b9945 | 2008-05-14 20:05:00 +0000 | [diff] [blame] | 94 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" }, |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame] | 95 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6, "ICH6" }, |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 96 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH5, "ICH5" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 97 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" }, |
| 98 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" }, |
Uwe Hermann | 710e8b1 | 2008-05-17 21:33:35 +0000 | [diff] [blame] | 99 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 100 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" }, |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 101 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 102 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I63XX, "631xESB/632xESB/3100" }, |
| 103 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_POULSBO_LPC, "SCH Poulsbo" }, |
Stefan Tauner | 088f569 | 2013-05-28 11:30:25 +0200 | [diff] [blame] | 104 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_DESKTOP, "3400 Desktop" }, |
| 105 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_MOBILE, "3400 Mobile" }, |
| 106 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_P55, "P55" }, |
| 107 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM55, "PM55" }, |
| 108 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H55, "H55" }, |
| 109 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM57, "QM57" }, |
| 110 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H57, "H57" }, |
| 111 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM55, "HM55" }, |
| 112 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q57, "Q57" }, |
| 113 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM57, "HM57" }, |
| 114 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400_MOBILE_SFF, "3400 Mobile SFF" }, |
| 115 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B55_A, "B55" }, |
| 116 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS57, "QS57" }, |
| 117 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3400, "3400" }, |
| 118 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3420, "3420" }, |
| 119 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_3450, "3450" }, |
| 120 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B55_B, "B55" }, |
Nico Huber | 76d6049 | 2013-03-29 17:57:15 +0100 | [diff] [blame] | 121 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z68, "Z68" }, |
| 122 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_P67, "P67" }, |
| 123 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_UM67, "UM67" }, |
| 124 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM65, "HM65" }, |
| 125 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H67, "H67" }, |
| 126 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM67, "HM67" }, |
| 127 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q65, "Q65" }, |
| 128 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS67, "QS67" }, |
| 129 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q67, "Q67" }, |
| 130 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM67, "QM67" }, |
| 131 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B65, "B65" }, |
| 132 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C202, "C202" }, |
| 133 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C204, "C204" }, |
| 134 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C206, "C206" }, |
| 135 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H61, "H61" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 136 | { PCI_VENDOR_ID_INTEL, 0x1d40, "X79" }, |
| 137 | { PCI_VENDOR_ID_INTEL, 0x1d41, "X79" }, |
Nico Huber | 76d6049 | 2013-03-29 17:57:15 +0100 | [diff] [blame] | 138 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z77, "Z77" }, |
| 139 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Z75, "Z75" }, |
| 140 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q77, "Q77" }, |
| 141 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q75, "Q75" }, |
| 142 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_B75, "B75" }, |
| 143 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_H77, "H77" }, |
| 144 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_C216, "C216" }, |
| 145 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QM77, "QM77" }, |
| 146 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QS77, "QS77" }, |
| 147 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM77, "HM77" }, |
| 148 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_UM77, "UM77" }, |
| 149 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM76, "HM76" }, |
| 150 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM75, "HM75" }, |
| 151 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HM70, "HM70" }, |
| 152 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_NM70, "NM70" }, |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 153 | { PCI_VENDOR_ID_INTEL, 0x2310, "DH89xxCC" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 156 | #ifndef __DARWIN__ |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 157 | static int fd_mem; |
| 158 | |
Stefan Reinauer | cff573d | 2011-03-18 22:08:39 +0000 | [diff] [blame] | 159 | void *map_physical(uint64_t phys_addr, size_t len) |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 160 | { |
| 161 | void *virt_addr; |
| 162 | |
| 163 | virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED, |
| 164 | fd_mem, (off_t) phys_addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 165 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 166 | if (virt_addr == MAP_FAILED) { |
Stefan Reinauer | a7b296d | 2011-11-14 12:40:34 -0800 | [diff] [blame] | 167 | printf("Error mapping physical memory 0x%08" PRIx64 "[0x%zx]\n", |
| 168 | phys_addr, len); |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 169 | return NULL; |
| 170 | } |
| 171 | |
| 172 | return virt_addr; |
| 173 | } |
| 174 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 175 | void unmap_physical(void *virt_addr, size_t len) |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 176 | { |
| 177 | munmap(virt_addr, len); |
| 178 | } |
| 179 | #endif |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 180 | |
| 181 | void print_version(void) |
| 182 | { |
| 183 | printf("inteltool v%s -- ", INTELTOOL_VERSION); |
| 184 | printf("Copyright (C) 2008 coresystems GmbH\n\n"); |
| 185 | printf( |
| 186 | "This program is free software: you can redistribute it and/or modify\n" |
| 187 | "it under the terms of the GNU General Public License as published by\n" |
| 188 | "the Free Software Foundation, version 2 of the License.\n\n" |
| 189 | "This program is distributed in the hope that it will be useful,\n" |
| 190 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
| 191 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
| 192 | "GNU General Public License for more details.\n\n" |
| 193 | "You should have received a copy of the GNU General Public License\n" |
| 194 | "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n"); |
| 195 | } |
| 196 | |
| 197 | void print_usage(const char *name) |
| 198 | { |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 199 | printf("usage: %s [-vh?gGrpmedPMa]\n", name); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 200 | printf("\n" |
| 201 | " -v | --version: print the version\n" |
| 202 | " -h | --help: print this help\n\n" |
| 203 | " -g | --gpio: dump soutbridge GPIO registers\n" |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 204 | " -G | --gpio-diffs: show GPIO differences from defaults\n" |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 205 | " -r | --rcba: dump soutbridge RCBA registers\n" |
| 206 | " -p | --pmbase: dump soutbridge Power Management registers\n\n" |
| 207 | " -m | --mchbar: dump northbridge Memory Controller registers\n" |
| 208 | " -e | --epbar: dump northbridge EPBAR registers\n" |
| 209 | " -d | --dmibar: dump northbridge DMIBAR registers\n" |
| 210 | " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n" |
| 211 | " -M | --msrs: dump CPU MSRs\n" |
Sven Schnelle | 4b7b320 | 2012-01-08 15:27:18 +0100 | [diff] [blame] | 212 | " -A | --ambs: dump AMB registers\n" |
Stefan Reinauer | d466e6a | 2008-05-14 13:52:50 +0000 | [diff] [blame] | 213 | " -a | --all: dump all known registers\n" |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 214 | "\n"); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 215 | exit(1); |
| 216 | } |
| 217 | |
| 218 | int main(int argc, char *argv[]) |
| 219 | { |
| 220 | struct pci_access *pacc; |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 221 | struct pci_dev *sb = NULL, *nb, *dev; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 222 | int i, opt, option_index = 0; |
Stefan Reinauer | 26ba091 | 2008-08-18 10:58:09 +0000 | [diff] [blame] | 223 | unsigned int id; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 224 | |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 225 | char *sbname = "unknown", *nbname = "unknown"; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 226 | |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 227 | int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0; |
| 228 | int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0; |
Sven Schnelle | 4b7b320 | 2012-01-08 15:27:18 +0100 | [diff] [blame] | 229 | int dump_pciexbar = 0, dump_coremsrs = 0, dump_ambs = 0; |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 230 | int show_gpio_diffs = 0; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 231 | |
| 232 | static struct option long_options[] = { |
| 233 | {"version", 0, 0, 'v'}, |
| 234 | {"help", 0, 0, 'h'}, |
| 235 | {"gpios", 0, 0, 'g'}, |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 236 | {"gpio-diffs", 0, 0, 'G'}, |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 237 | {"mchbar", 0, 0, 'm'}, |
| 238 | {"rcba", 0, 0, 'r'}, |
| 239 | {"pmbase", 0, 0, 'p'}, |
| 240 | {"epbar", 0, 0, 'e'}, |
| 241 | {"dmibar", 0, 0, 'd'}, |
| 242 | {"pciexpress", 0, 0, 'P'}, |
| 243 | {"msrs", 0, 0, 'M'}, |
Sven Schnelle | 4b7b320 | 2012-01-08 15:27:18 +0100 | [diff] [blame] | 244 | {"ambs", 0, 0, 'A'}, |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 245 | {"all", 0, 0, 'a'}, |
| 246 | {0, 0, 0, 0} |
| 247 | }; |
| 248 | |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 249 | while ((opt = getopt_long(argc, argv, "vh?gGrpmedPMaA", |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 250 | long_options, &option_index)) != EOF) { |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 251 | switch (opt) { |
| 252 | case 'v': |
| 253 | print_version(); |
| 254 | exit(0); |
| 255 | break; |
| 256 | case 'g': |
| 257 | dump_gpios = 1; |
| 258 | break; |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 259 | case 'G': |
| 260 | show_gpio_diffs = 1; |
| 261 | break; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 262 | case 'm': |
| 263 | dump_mchbar = 1; |
| 264 | break; |
| 265 | case 'r': |
| 266 | dump_rcba = 1; |
| 267 | break; |
| 268 | case 'p': |
| 269 | dump_pmbase = 1; |
| 270 | break; |
| 271 | case 'e': |
| 272 | dump_epbar = 1; |
| 273 | break; |
| 274 | case 'd': |
| 275 | dump_dmibar = 1; |
| 276 | break; |
| 277 | case 'P': |
| 278 | dump_pciexbar = 1; |
| 279 | break; |
| 280 | case 'M': |
| 281 | dump_coremsrs = 1; |
| 282 | break; |
| 283 | case 'a': |
| 284 | dump_gpios = 1; |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 285 | show_gpio_diffs = 1; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 286 | dump_mchbar = 1; |
| 287 | dump_rcba = 1; |
| 288 | dump_pmbase = 1; |
| 289 | dump_epbar = 1; |
| 290 | dump_dmibar = 1; |
| 291 | dump_pciexbar = 1; |
| 292 | dump_coremsrs = 1; |
Sven Schnelle | 4b7b320 | 2012-01-08 15:27:18 +0100 | [diff] [blame] | 293 | dump_ambs = 1; |
| 294 | break; |
| 295 | case 'A': |
| 296 | dump_ambs = 1; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 297 | break; |
| 298 | case 'h': |
| 299 | case '?': |
| 300 | default: |
| 301 | print_usage(argv[0]); |
| 302 | exit(0); |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
Idwer Vollering | 3f91d81 | 2010-10-24 13:50:13 +0000 | [diff] [blame] | 307 | #if defined(__FreeBSD__) |
Stefan Tauner | 0c8b7d1 | 2013-04-05 20:38:08 +0200 | [diff] [blame] | 308 | if (open("/dev/io", O_RDWR) < 0) { |
Idwer Vollering | 3f91d81 | 2010-10-24 13:50:13 +0000 | [diff] [blame] | 309 | perror("/dev/io"); |
| 310 | #else |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 311 | if (iopl(3)) { |
Idwer Vollering | 3f91d81 | 2010-10-24 13:50:13 +0000 | [diff] [blame] | 312 | perror("iopl"); |
| 313 | #endif |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 314 | printf("You need to be root.\n"); |
| 315 | exit(1); |
| 316 | } |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 317 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 318 | #ifndef __DARWIN__ |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 319 | if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { |
| 320 | perror("Can not open /dev/mem"); |
| 321 | exit(1); |
| 322 | } |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 323 | #endif |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 324 | |
| 325 | pacc = pci_alloc(); |
| 326 | pci_init(pacc); |
| 327 | pci_scan_bus(pacc); |
| 328 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 329 | /* Find the required devices */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 330 | for (dev = pacc->devices; dev; dev = dev->next) { |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 331 | pci_fill_info(dev, PCI_FILL_CLASS); |
| 332 | /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */ |
| 333 | if (dev->device_class == 0x0601) { /* ISA/LPC bridge */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 334 | if (sb == NULL) |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 335 | sb = dev; |
| 336 | else |
| 337 | fprintf(stderr, "Multiple devices with class ID" |
| 338 | " 0x0601, using %02x%02x:%02x.%02x\n", |
| 339 | dev->domain, dev->bus, dev->dev, |
| 340 | dev->func); |
| 341 | } |
| 342 | } |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 343 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 344 | if (!sb) { |
| 345 | printf("No southbridge found.\n"); |
| 346 | exit(1); |
| 347 | } |
| 348 | |
| 349 | pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS); |
| 350 | |
| 351 | if (sb->vendor_id != PCI_VENDOR_ID_INTEL) { |
| 352 | printf("Not an Intel(R) southbridge.\n"); |
| 353 | exit(1); |
| 354 | } |
| 355 | |
| 356 | nb = pci_get_dev(pacc, 0, 0, 0x00, 0); |
| 357 | if (!nb) { |
| 358 | printf("No northbridge found.\n"); |
| 359 | exit(1); |
| 360 | } |
| 361 | |
| 362 | pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS); |
| 363 | |
| 364 | if (nb->vendor_id != PCI_VENDOR_ID_INTEL) { |
| 365 | printf("Not an Intel(R) northbridge.\n"); |
| 366 | exit(1); |
| 367 | } |
| 368 | |
Stefan Reinauer | 26ba091 | 2008-08-18 10:58:09 +0000 | [diff] [blame] | 369 | id = cpuid(1); |
Stefan Reinauer | 74cd5698 | 2010-06-01 10:04:28 +0000 | [diff] [blame] | 370 | |
| 371 | /* Intel has suggested applications to display the family of a CPU as |
| 372 | * the sum of the "Family" and the "Extended Family" fields shown |
| 373 | * above, and the model as the sum of the "Model" and the 4-bit |
| 374 | * left-shifted "Extended Model" fields. |
| 375 | * http://download.intel.com/design/processor/applnots/24161832.pdf |
| 376 | */ |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 377 | printf("CPU: Processor Type: %x, Family %x, Model %x, Stepping %x\n", |
Stefan Reinauer | 74cd5698 | 2010-06-01 10:04:28 +0000 | [diff] [blame] | 378 | (id >> 12) & 0x3, ((id >> 8) & 0xf) + ((id >> 20) & 0xff), |
| 379 | ((id >> 12) & 0xf0) + ((id >> 4) & 0xf), (id & 0xf)); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 380 | |
| 381 | /* Determine names */ |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 382 | for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++) |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 383 | if (nb->device_id == supported_chips_list[i].device_id) |
| 384 | nbname = supported_chips_list[i].name; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 385 | for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++) |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 386 | if (sb->device_id == supported_chips_list[i].device_id) |
| 387 | sbname = supported_chips_list[i].name; |
| 388 | |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 389 | printf("Northbridge: %04x:%04x (%s)\n", |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 390 | nb->vendor_id, nb->device_id, nbname); |
| 391 | |
Stefan Tauner | 04c0600 | 2012-10-13 02:19:30 +0200 | [diff] [blame] | 392 | printf("Southbridge: %04x:%04x (%s)\n", |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 393 | sb->vendor_id, sb->device_id, sbname); |
| 394 | |
| 395 | /* Now do the deed */ |
| 396 | |
| 397 | if (dump_gpios) { |
Nico Huber | 09dcbf0 | 2013-04-01 15:08:04 +0200 | [diff] [blame] | 398 | print_gpios(sb, 1, show_gpio_diffs); |
| 399 | printf("\n\n"); |
| 400 | } else if (show_gpio_diffs) { |
| 401 | print_gpios(sb, 0, show_gpio_diffs); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 402 | printf("\n\n"); |
| 403 | } |
| 404 | |
| 405 | if (dump_rcba) { |
| 406 | print_rcba(sb); |
| 407 | printf("\n\n"); |
| 408 | } |
| 409 | |
| 410 | if (dump_pmbase) { |
Tobias Diedrich | 3645e61 | 2010-11-27 14:44:19 +0000 | [diff] [blame] | 411 | print_pmbase(sb, pacc); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 412 | printf("\n\n"); |
| 413 | } |
| 414 | |
| 415 | if (dump_mchbar) { |
Idwer Vollering | 312fc96 | 2010-12-17 22:34:58 +0000 | [diff] [blame] | 416 | print_mchbar(nb, pacc); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 417 | printf("\n\n"); |
| 418 | } |
| 419 | |
| 420 | if (dump_epbar) { |
| 421 | print_epbar(nb); |
| 422 | printf("\n\n"); |
| 423 | } |
| 424 | |
| 425 | if (dump_dmibar) { |
| 426 | print_dmibar(nb); |
| 427 | printf("\n\n"); |
| 428 | } |
| 429 | |
| 430 | if (dump_pciexbar) { |
| 431 | print_pciexbar(nb); |
| 432 | printf("\n\n"); |
| 433 | } |
| 434 | |
| 435 | if (dump_coremsrs) { |
| 436 | print_intel_core_msrs(); |
| 437 | printf("\n\n"); |
| 438 | } |
| 439 | |
Sven Schnelle | 4b7b320 | 2012-01-08 15:27:18 +0100 | [diff] [blame] | 440 | if (dump_ambs) { |
| 441 | print_ambs(nb, pacc); |
| 442 | } |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 443 | /* Clean up */ |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 444 | pci_free_dev(nb); |
Uwe Hermann | e23e372 | 2009-09-30 17:14:24 +0000 | [diff] [blame] | 445 | // pci_free_dev(sb); // TODO: glibc detected "double free or corruption" |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 446 | pci_cleanup(pacc); |
| 447 | |
| 448 | return 0; |
| 449 | } |