Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +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 | * |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 22 | #include "inteltool.h" |
| 23 | |
| 24 | /* |
| 25 | * Egress Port Root Complex MMIO configuration space |
| 26 | */ |
| 27 | int print_epbar(struct pci_dev *nb) |
| 28 | { |
| 29 | int i, size = (4 * 1024); |
| 30 | volatile uint8_t *epbar; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 31 | uint64_t epbar_phys; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 32 | |
| 33 | printf("\n============= EPBAR =============\n\n"); |
| 34 | |
| 35 | switch (nb->device_id) { |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame] | 36 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 37 | case PCI_DEVICE_ID_INTEL_82945GM: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 38 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 39 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 40 | epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe; |
| 41 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 42 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 43 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 44 | case PCI_DEVICE_ID_INTEL_82G33: |
| 45 | case PCI_DEVICE_ID_INTEL_82Q33: |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 46 | case PCI_DEVICE_ID_INTEL_GS45: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 47 | epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe; |
| 48 | epbar_phys |= ((uint64_t)pci_read_long(nb, 0x44)) << 32; |
| 49 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 50 | case PCI_DEVICE_ID_INTEL_82810: |
| 51 | case PCI_DEVICE_ID_INTEL_82810DC: |
Joseph Smith | e10757e | 2010-06-16 22:21:19 +0000 | [diff] [blame] | 52 | case PCI_DEVICE_ID_INTEL_82810E_MC: |
Stefan Reinauer | 0484481 | 2010-02-22 11:26:06 +0000 | [diff] [blame] | 53 | case PCI_DEVICE_ID_INTEL_82830M: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 54 | printf("This northbrigde does not have EPBAR.\n"); |
| 55 | return 1; |
| 56 | default: |
| 57 | printf("Error: Dumping EPBAR on this northbridge is not (yet) supported.\n"); |
| 58 | return 1; |
| 59 | } |
| 60 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 61 | epbar = map_physical(epbar_phys, size); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 62 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 63 | if (epbar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 64 | perror("Error mapping EPBAR"); |
| 65 | exit(1); |
| 66 | } |
| 67 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 68 | printf("EPBAR = 0x%08llx (MEM)\n\n", epbar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 69 | for (i = 0; i < size; i += 4) { |
| 70 | if (*(uint32_t *)(epbar + i)) |
| 71 | printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(epbar+i)); |
| 72 | } |
| 73 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 74 | unmap_physical((void *)epbar, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * MCH-ICH Serial Interconnect Ingress Root Complex MMIO configuration space |
| 80 | */ |
| 81 | int print_dmibar(struct pci_dev *nb) |
| 82 | { |
| 83 | int i, size = (4 * 1024); |
| 84 | volatile uint8_t *dmibar; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 85 | uint64_t dmibar_phys; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 86 | |
| 87 | printf("\n============= DMIBAR ============\n\n"); |
| 88 | |
| 89 | switch (nb->device_id) { |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame] | 90 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 91 | case PCI_DEVICE_ID_INTEL_82945GM: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 92 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 93 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 94 | dmibar_phys = pci_read_long(nb, 0x4c) & 0xfffffffe; |
| 95 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 96 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 97 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 98 | case PCI_DEVICE_ID_INTEL_82G33: |
| 99 | case PCI_DEVICE_ID_INTEL_82Q33: |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 100 | case PCI_DEVICE_ID_INTEL_GS45: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 101 | dmibar_phys = pci_read_long(nb, 0x68) & 0xfffffffe; |
| 102 | dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32; |
| 103 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 104 | case PCI_DEVICE_ID_INTEL_82810: |
| 105 | case PCI_DEVICE_ID_INTEL_82810DC: |
Joseph Smith | e10757e | 2010-06-16 22:21:19 +0000 | [diff] [blame] | 106 | case PCI_DEVICE_ID_INTEL_82810E_MC: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 107 | printf("This northbrigde does not have DMIBAR.\n"); |
| 108 | return 1; |
| 109 | default: |
| 110 | printf("Error: Dumping DMIBAR on this northbridge is not (yet) supported.\n"); |
| 111 | return 1; |
| 112 | } |
| 113 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 114 | dmibar = map_physical(dmibar_phys, size); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 115 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 116 | if (dmibar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 117 | perror("Error mapping DMIBAR"); |
| 118 | exit(1); |
| 119 | } |
| 120 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 121 | printf("DMIBAR = 0x%08llx (MEM)\n\n", dmibar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 122 | for (i = 0; i < size; i += 4) { |
| 123 | if (*(uint32_t *)(dmibar + i)) |
| 124 | printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(dmibar+i)); |
| 125 | } |
| 126 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 127 | unmap_physical((void *)dmibar, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * PCIe MMIO configuration space |
| 133 | */ |
| 134 | int print_pciexbar(struct pci_dev *nb) |
| 135 | { |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 136 | uint64_t pciexbar_reg; |
| 137 | uint64_t pciexbar_phys; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 138 | volatile uint8_t *pciexbar; |
| 139 | int max_busses, devbase, i; |
| 140 | int bus, dev, fn; |
| 141 | |
| 142 | printf("========= PCIEXBAR ========\n\n"); |
| 143 | |
| 144 | switch (nb->device_id) { |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame] | 145 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 146 | case PCI_DEVICE_ID_INTEL_82945GM: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 147 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 148 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 149 | pciexbar_reg = pci_read_long(nb, 0x48); |
| 150 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 151 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 152 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 153 | case PCI_DEVICE_ID_INTEL_82G33: |
| 154 | case PCI_DEVICE_ID_INTEL_82Q33: |
Anton Kochkov | da0b456 | 2010-05-30 12:33:12 +0000 | [diff] [blame] | 155 | case PCI_DEVICE_ID_INTEL_GS45: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 156 | pciexbar_reg = pci_read_long(nb, 0x60); |
| 157 | pciexbar_reg |= ((uint64_t)pci_read_long(nb, 0x64)) << 32; |
| 158 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 159 | case PCI_DEVICE_ID_INTEL_82810: |
| 160 | case PCI_DEVICE_ID_INTEL_82810DC: |
Joseph Smith | e10757e | 2010-06-16 22:21:19 +0000 | [diff] [blame] | 161 | case PCI_DEVICE_ID_INTEL_82810E_MC: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 162 | printf("Error: This northbrigde does not have PCIEXBAR.\n"); |
| 163 | return 1; |
| 164 | default: |
| 165 | printf("Error: Dumping PCIEXBAR on this northbridge is not (yet) supported.\n"); |
| 166 | return 1; |
| 167 | } |
| 168 | |
| 169 | if (!(pciexbar_reg & (1 << 0))) { |
| 170 | printf("PCIEXBAR register is disabled.\n"); |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | switch ((pciexbar_reg >> 1) & 3) { |
| 175 | case 0: // 256MB |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 176 | pciexbar_phys = pciexbar_reg & (0xff << 28); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 177 | max_busses = 256; |
| 178 | break; |
| 179 | case 1: // 128M |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 180 | pciexbar_phys = pciexbar_reg & (0x1ff << 27); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 181 | max_busses = 128; |
| 182 | break; |
| 183 | case 2: // 64M |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 184 | pciexbar_phys = pciexbar_reg & (0x3ff << 26); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 185 | max_busses = 64; |
| 186 | break; |
| 187 | default: // RSVD |
| 188 | printf("Undefined address base. Bailing out.\n"); |
| 189 | return 1; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 190 | } |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 191 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 192 | printf("PCIEXBAR: 0x%08llx\n", pciexbar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 193 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 194 | pciexbar = map_physical(pciexbar_phys, (max_busses * 1024 * 1024)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 195 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 196 | if (pciexbar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 197 | perror("Error mapping PCIEXBAR"); |
| 198 | exit(1); |
| 199 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 200 | |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 201 | for (bus = 0; bus < max_busses; bus++) { |
| 202 | for (dev = 0; dev < 32; dev++) { |
| 203 | for (fn = 0; fn < 8; fn++) { |
| 204 | devbase = (bus * 1024 * 1024) + (dev * 32 * 1024) + (fn * 4 * 1024); |
| 205 | |
| 206 | if (*(uint16_t *)(pciexbar + devbase) == 0xffff) |
| 207 | continue; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 208 | |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 209 | /* This is a heuristics. Anyone got a better check? */ |
| 210 | if( (*(uint32_t *)(pciexbar + devbase + 256) == 0xffffffff) && |
| 211 | (*(uint32_t *)(pciexbar + devbase + 512) == 0xffffffff) ) { |
| 212 | #if DEBUG |
| 213 | printf("Skipped non-PCIe device %02x:%02x.%01x\n", bus, dev, fn); |
| 214 | #endif |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | printf("\nPCIe %02x:%02x.%01x extended config space:", bus, dev, fn); |
| 219 | for (i = 0; i < 4096; i++) { |
| 220 | if((i % 0x10) == 0) |
| 221 | printf("\n%04x:", i); |
| 222 | printf(" %02x", *(pciexbar+devbase+i)); |
| 223 | } |
| 224 | printf("\n"); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 229 | unmap_physical((void *)pciexbar, (max_busses * 1024 * 1024)); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | |