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