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 | * |
| 4 | * Copyright (C) 2008 by coresystems GmbH |
| 5 | * written by Stefan Reinauer <stepan@coresystems.de> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 21 | #include <stdio.h> |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 23 | #include <getopt.h> |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 24 | #include <fcntl.h> |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 25 | #include <sys/mman.h> |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 26 | #include "inteltool.h" |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 27 | |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 28 | static const struct { |
| 29 | uint16_t vendor_id, device_id; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 30 | char *name; |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 31 | } supported_chips_list[] = { |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 32 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX, "82443LX" }, |
| 33 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX, "82443BX" }, |
| 34 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_NO_AGP, "82443BX without AGP" }, |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 35 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810, "i810" }, |
| 36 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810DC, "i810-DC100" }, |
Uwe Hermann | 710e8b1 | 2008-05-17 21:33:35 +0000 | [diff] [blame] | 37 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845, "i845" }, |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 38 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945P, "i945P" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 39 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945GM, "i945GM" }, |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 40 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PM965, "PM965" }, |
| 41 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82975X, "i975X" }, |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame^] | 42 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q35, "Q35" }, |
| 43 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82G33, "P35/G33/G31/P31" }, |
| 44 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82Q33, "Q33" }, |
Warren Turkal | 9702b6b | 2009-06-30 14:11:42 +0000 | [diff] [blame] | 45 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58, "X58" }, |
| 46 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10R, "ICH10R" }, |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 47 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8M, "ICH8-M" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 48 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7MDH, "ICH7-M DH" }, |
Stefan Reinauer | f9b9945 | 2008-05-14 20:05:00 +0000 | [diff] [blame] | 49 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7M, "ICH7-M" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 50 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7, "ICH7" }, |
Stefan Reinauer | f9b9945 | 2008-05-14 20:05:00 +0000 | [diff] [blame] | 51 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7DH, "ICH7DH" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 52 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4M, "ICH4-M" }, |
| 53 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4, "ICH4" }, |
Uwe Hermann | 710e8b1 | 2008-05-17 21:33:35 +0000 | [diff] [blame] | 54 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH2, "ICH2" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 55 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH0, "ICH0" }, |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 56 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" }, |
| 57 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371XX, "82371AB/EB/MB" }, |
Stefan Reinauer | 9f7af6e | 2008-05-14 14:22:59 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 60 | #ifndef __DARWIN__ |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 61 | static int fd_mem; |
| 62 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 63 | void *map_physical(unsigned long phys_addr, size_t len) |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 64 | { |
| 65 | void *virt_addr; |
| 66 | |
| 67 | virt_addr = mmap(0, len, PROT_WRITE | PROT_READ, MAP_SHARED, |
| 68 | fd_mem, (off_t) phys_addr); |
| 69 | |
| 70 | if (virt_addr == MAP_FAILED) { |
Stefan Reinauer | f182456 | 2009-04-22 23:17:44 +0000 | [diff] [blame] | 71 | printf("Error mapping physical memory 0x%08lx[0x%x]\n", phys_addr, len); |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | return virt_addr; |
| 76 | } |
| 77 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 78 | void unmap_physical(void *virt_addr, size_t len) |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 79 | { |
| 80 | munmap(virt_addr, len); |
| 81 | } |
| 82 | #endif |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 83 | |
| 84 | void print_version(void) |
| 85 | { |
| 86 | printf("inteltool v%s -- ", INTELTOOL_VERSION); |
| 87 | printf("Copyright (C) 2008 coresystems GmbH\n\n"); |
| 88 | printf( |
| 89 | "This program is free software: you can redistribute it and/or modify\n" |
| 90 | "it under the terms of the GNU General Public License as published by\n" |
| 91 | "the Free Software Foundation, version 2 of the License.\n\n" |
| 92 | "This program is distributed in the hope that it will be useful,\n" |
| 93 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
| 94 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
| 95 | "GNU General Public License for more details.\n\n" |
| 96 | "You should have received a copy of the GNU General Public License\n" |
| 97 | "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n"); |
| 98 | } |
| 99 | |
| 100 | void print_usage(const char *name) |
| 101 | { |
Stefan Reinauer | d466e6a | 2008-05-14 13:52:50 +0000 | [diff] [blame] | 102 | printf("usage: %s [-vh?grpmedPMa]\n", name); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 103 | printf("\n" |
| 104 | " -v | --version: print the version\n" |
| 105 | " -h | --help: print this help\n\n" |
| 106 | " -g | --gpio: dump soutbridge GPIO registers\n" |
| 107 | " -r | --rcba: dump soutbridge RCBA registers\n" |
| 108 | " -p | --pmbase: dump soutbridge Power Management registers\n\n" |
| 109 | " -m | --mchbar: dump northbridge Memory Controller registers\n" |
| 110 | " -e | --epbar: dump northbridge EPBAR registers\n" |
| 111 | " -d | --dmibar: dump northbridge DMIBAR registers\n" |
| 112 | " -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n" |
| 113 | " -M | --msrs: dump CPU MSRs\n" |
Stefan Reinauer | d466e6a | 2008-05-14 13:52:50 +0000 | [diff] [blame] | 114 | " -a | --all: dump all known registers\n" |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 115 | "\n"); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 116 | exit(1); |
| 117 | } |
| 118 | |
| 119 | int main(int argc, char *argv[]) |
| 120 | { |
| 121 | struct pci_access *pacc; |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 122 | struct pci_dev *sb = NULL, *nb, *dev; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 123 | int i, opt, option_index = 0; |
Stefan Reinauer | 26ba091 | 2008-08-18 10:58:09 +0000 | [diff] [blame] | 124 | unsigned int id; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 125 | |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 126 | char *sbname = "unknown", *nbname = "unknown"; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 127 | |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 128 | int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0; |
| 129 | int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0; |
| 130 | int dump_pciexbar = 0, dump_coremsrs = 0; |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 131 | |
| 132 | static struct option long_options[] = { |
| 133 | {"version", 0, 0, 'v'}, |
| 134 | {"help", 0, 0, 'h'}, |
| 135 | {"gpios", 0, 0, 'g'}, |
| 136 | {"mchbar", 0, 0, 'm'}, |
| 137 | {"rcba", 0, 0, 'r'}, |
| 138 | {"pmbase", 0, 0, 'p'}, |
| 139 | {"epbar", 0, 0, 'e'}, |
| 140 | {"dmibar", 0, 0, 'd'}, |
| 141 | {"pciexpress", 0, 0, 'P'}, |
| 142 | {"msrs", 0, 0, 'M'}, |
| 143 | {"all", 0, 0, 'a'}, |
| 144 | {0, 0, 0, 0} |
| 145 | }; |
| 146 | |
Stefan Reinauer | d466e6a | 2008-05-14 13:52:50 +0000 | [diff] [blame] | 147 | while ((opt = getopt_long(argc, argv, "vh?grpmedPMa", |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 148 | long_options, &option_index)) != EOF) { |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 149 | switch (opt) { |
| 150 | case 'v': |
| 151 | print_version(); |
| 152 | exit(0); |
| 153 | break; |
| 154 | case 'g': |
| 155 | dump_gpios = 1; |
| 156 | break; |
| 157 | case 'm': |
| 158 | dump_mchbar = 1; |
| 159 | break; |
| 160 | case 'r': |
| 161 | dump_rcba = 1; |
| 162 | break; |
| 163 | case 'p': |
| 164 | dump_pmbase = 1; |
| 165 | break; |
| 166 | case 'e': |
| 167 | dump_epbar = 1; |
| 168 | break; |
| 169 | case 'd': |
| 170 | dump_dmibar = 1; |
| 171 | break; |
| 172 | case 'P': |
| 173 | dump_pciexbar = 1; |
| 174 | break; |
| 175 | case 'M': |
| 176 | dump_coremsrs = 1; |
| 177 | break; |
| 178 | case 'a': |
| 179 | dump_gpios = 1; |
| 180 | dump_mchbar = 1; |
| 181 | dump_rcba = 1; |
| 182 | dump_pmbase = 1; |
| 183 | dump_epbar = 1; |
| 184 | dump_dmibar = 1; |
| 185 | dump_pciexbar = 1; |
| 186 | dump_coremsrs = 1; |
| 187 | break; |
| 188 | case 'h': |
| 189 | case '?': |
| 190 | default: |
| 191 | print_usage(argv[0]); |
| 192 | exit(0); |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 197 | if (iopl(3)) { |
| 198 | printf("You need to be root.\n"); |
| 199 | exit(1); |
| 200 | } |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 201 | |
Stefan Reinauer | f7f2f25 | 2009-09-01 09:52:14 +0000 | [diff] [blame] | 202 | #ifndef __DARWIN__ |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 203 | if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { |
| 204 | perror("Can not open /dev/mem"); |
| 205 | exit(1); |
| 206 | } |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 207 | #endif |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 208 | |
| 209 | pacc = pci_alloc(); |
| 210 | pci_init(pacc); |
| 211 | pci_scan_bus(pacc); |
| 212 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 213 | /* Find the required devices */ |
Maciej Pijanka | 90d1740 | 2009-09-30 17:05:46 +0000 | [diff] [blame] | 214 | for (dev = pacc->devices; dev; dev = dev->next) { |
| 215 | pci_fill_info(dev, PCI_FILL_CLASS); |
| 216 | /* The ISA/LPC bridge can be 0x1f, 0x07, or 0x04 so we probe. */ |
| 217 | if (dev->device_class == 0x0601) { /* ISA/LPC bridge */ |
| 218 | if (sb == NULL) |
| 219 | sb = dev; |
| 220 | else |
| 221 | fprintf(stderr, "Multiple devices with class ID" |
| 222 | " 0x0601, using %02x%02x:%02x.%02x\n", |
| 223 | dev->domain, dev->bus, dev->dev, |
| 224 | dev->func); |
| 225 | } |
| 226 | } |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 227 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 228 | if (!sb) { |
| 229 | printf("No southbridge found.\n"); |
| 230 | exit(1); |
| 231 | } |
| 232 | |
| 233 | pci_fill_info(sb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS); |
| 234 | |
| 235 | if (sb->vendor_id != PCI_VENDOR_ID_INTEL) { |
| 236 | printf("Not an Intel(R) southbridge.\n"); |
| 237 | exit(1); |
| 238 | } |
| 239 | |
| 240 | nb = pci_get_dev(pacc, 0, 0, 0x00, 0); |
| 241 | if (!nb) { |
| 242 | printf("No northbridge found.\n"); |
| 243 | exit(1); |
| 244 | } |
| 245 | |
| 246 | pci_fill_info(nb, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS); |
| 247 | |
| 248 | if (nb->vendor_id != PCI_VENDOR_ID_INTEL) { |
| 249 | printf("Not an Intel(R) northbridge.\n"); |
| 250 | exit(1); |
| 251 | } |
| 252 | |
Stefan Reinauer | 26ba091 | 2008-08-18 10:58:09 +0000 | [diff] [blame] | 253 | id = cpuid(1); |
| 254 | printf("Intel CPU: Family %x, Model %x\n", |
| 255 | (id >> 8) & 0xf, (id >> 4) & 0xf); |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 256 | |
| 257 | /* Determine names */ |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 258 | for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++) |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 259 | if (nb->device_id == supported_chips_list[i].device_id) |
| 260 | nbname = supported_chips_list[i].name; |
Uwe Hermann | 9a6b6b5 | 2008-05-14 21:20:55 +0000 | [diff] [blame] | 261 | for (i = 0; i < ARRAY_SIZE(supported_chips_list); i++) |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 262 | if (sb->device_id == supported_chips_list[i].device_id) |
| 263 | sbname = supported_chips_list[i].name; |
| 264 | |
| 265 | printf("Intel Northbridge: %04x:%04x (%s)\n", |
| 266 | nb->vendor_id, nb->device_id, nbname); |
| 267 | |
| 268 | printf("Intel Southbridge: %04x:%04x (%s)\n", |
| 269 | sb->vendor_id, sb->device_id, sbname); |
| 270 | |
| 271 | /* Now do the deed */ |
| 272 | |
| 273 | if (dump_gpios) { |
| 274 | print_gpios(sb); |
| 275 | printf("\n\n"); |
| 276 | } |
| 277 | |
| 278 | if (dump_rcba) { |
| 279 | print_rcba(sb); |
| 280 | printf("\n\n"); |
| 281 | } |
| 282 | |
| 283 | if (dump_pmbase) { |
| 284 | print_pmbase(sb); |
| 285 | printf("\n\n"); |
| 286 | } |
| 287 | |
| 288 | if (dump_mchbar) { |
| 289 | print_mchbar(nb); |
| 290 | printf("\n\n"); |
| 291 | } |
| 292 | |
| 293 | if (dump_epbar) { |
| 294 | print_epbar(nb); |
| 295 | printf("\n\n"); |
| 296 | } |
| 297 | |
| 298 | if (dump_dmibar) { |
| 299 | print_dmibar(nb); |
| 300 | printf("\n\n"); |
| 301 | } |
| 302 | |
| 303 | if (dump_pciexbar) { |
| 304 | print_pciexbar(nb); |
| 305 | printf("\n\n"); |
| 306 | } |
| 307 | |
| 308 | if (dump_coremsrs) { |
| 309 | print_intel_core_msrs(); |
| 310 | printf("\n\n"); |
| 311 | } |
| 312 | |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 313 | /* Clean up */ |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 314 | pci_free_dev(nb); |
Uwe Hermann | e23e372 | 2009-09-30 17:14:24 +0000 | [diff] [blame] | 315 | // pci_free_dev(sb); // TODO: glibc detected "double free or corruption" |
Stefan Reinauer | 03646be | 2008-05-13 22:14:21 +0000 | [diff] [blame] | 316 | pci_cleanup(pacc); |
| 317 | |
| 318 | return 0; |
| 319 | } |