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 | 0484481 | 2010-02-22 11:26:06 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 by coresystems GmbH |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 5 | * |
| 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: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 46 | epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe; |
| 47 | epbar_phys |= ((uint64_t)pci_read_long(nb, 0x44)) << 32; |
| 48 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 49 | case PCI_DEVICE_ID_INTEL_82810: |
| 50 | case PCI_DEVICE_ID_INTEL_82810DC: |
Stefan Reinauer | 0484481 | 2010-02-22 11:26:06 +0000 | [diff] [blame] | 51 | case PCI_DEVICE_ID_INTEL_82830M: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 52 | printf("This northbrigde does not have EPBAR.\n"); |
| 53 | return 1; |
| 54 | default: |
| 55 | printf("Error: Dumping EPBAR on this northbridge is not (yet) supported.\n"); |
| 56 | return 1; |
| 57 | } |
| 58 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 59 | epbar = map_physical(epbar_phys, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 60 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 61 | if (epbar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 62 | perror("Error mapping EPBAR"); |
| 63 | exit(1); |
| 64 | } |
| 65 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 66 | printf("EPBAR = 0x%08llx (MEM)\n\n", epbar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 67 | for (i = 0; i < size; i += 4) { |
| 68 | if (*(uint32_t *)(epbar + i)) |
| 69 | printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(epbar+i)); |
| 70 | } |
| 71 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 72 | unmap_physical((void *)epbar, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * MCH-ICH Serial Interconnect Ingress Root Complex MMIO configuration space |
| 78 | */ |
| 79 | int print_dmibar(struct pci_dev *nb) |
| 80 | { |
| 81 | int i, size = (4 * 1024); |
| 82 | volatile uint8_t *dmibar; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 83 | uint64_t dmibar_phys; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 84 | |
| 85 | printf("\n============= DMIBAR ============\n\n"); |
| 86 | |
| 87 | switch (nb->device_id) { |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame^] | 88 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 89 | case PCI_DEVICE_ID_INTEL_82945GM: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 90 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 91 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 92 | dmibar_phys = pci_read_long(nb, 0x4c) & 0xfffffffe; |
| 93 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 94 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 95 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 96 | case PCI_DEVICE_ID_INTEL_82G33: |
| 97 | case PCI_DEVICE_ID_INTEL_82Q33: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 98 | dmibar_phys = pci_read_long(nb, 0x68) & 0xfffffffe; |
| 99 | dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32; |
| 100 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 101 | case PCI_DEVICE_ID_INTEL_82810: |
| 102 | case PCI_DEVICE_ID_INTEL_82810DC: |
Stefan Reinauer | 0484481 | 2010-02-22 11:26:06 +0000 | [diff] [blame] | 103 | case PCI_DEVICE_ID_INTEL_82830M: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 104 | printf("This northbrigde does not have DMIBAR.\n"); |
| 105 | return 1; |
| 106 | default: |
| 107 | printf("Error: Dumping DMIBAR on this northbridge is not (yet) supported.\n"); |
| 108 | return 1; |
| 109 | } |
| 110 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 111 | dmibar = map_physical(dmibar_phys, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 112 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 113 | if (dmibar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 114 | perror("Error mapping DMIBAR"); |
| 115 | exit(1); |
| 116 | } |
| 117 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 118 | printf("DMIBAR = 0x%08llx (MEM)\n\n", dmibar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 119 | for (i = 0; i < size; i += 4) { |
| 120 | if (*(uint32_t *)(dmibar + i)) |
| 121 | printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(dmibar+i)); |
| 122 | } |
| 123 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 124 | unmap_physical((void *)dmibar, size); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * PCIe MMIO configuration space |
| 130 | */ |
| 131 | int print_pciexbar(struct pci_dev *nb) |
| 132 | { |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 133 | uint64_t pciexbar_reg; |
| 134 | uint64_t pciexbar_phys; |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 135 | volatile uint8_t *pciexbar; |
| 136 | int max_busses, devbase, i; |
| 137 | int bus, dev, fn; |
| 138 | |
| 139 | printf("========= PCIEXBAR ========\n\n"); |
| 140 | |
| 141 | switch (nb->device_id) { |
Pat Erley | ca3548e | 2010-04-21 06:23:19 +0000 | [diff] [blame^] | 142 | case PCI_DEVICE_ID_INTEL_82915: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 143 | case PCI_DEVICE_ID_INTEL_82945GM: |
Stefan Reinauer | 3d9a12f | 2008-11-02 11:11:40 +0000 | [diff] [blame] | 144 | case PCI_DEVICE_ID_INTEL_82945P: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 145 | case PCI_DEVICE_ID_INTEL_82975X: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 146 | pciexbar_reg = pci_read_long(nb, 0x48); |
| 147 | break; |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 148 | case PCI_DEVICE_ID_INTEL_PM965: |
Loïc Grenié | 8429de7 | 2009-11-02 15:01:49 +0000 | [diff] [blame] | 149 | case PCI_DEVICE_ID_INTEL_82Q35: |
| 150 | case PCI_DEVICE_ID_INTEL_82G33: |
| 151 | case PCI_DEVICE_ID_INTEL_82Q33: |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 152 | pciexbar_reg = pci_read_long(nb, 0x60); |
| 153 | pciexbar_reg |= ((uint64_t)pci_read_long(nb, 0x64)) << 32; |
| 154 | break; |
Stefan Reinauer | b2aedb1 | 2009-08-29 15:45:43 +0000 | [diff] [blame] | 155 | case PCI_DEVICE_ID_INTEL_82810: |
| 156 | case PCI_DEVICE_ID_INTEL_82810DC: |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 157 | printf("Error: This northbrigde does not have PCIEXBAR.\n"); |
| 158 | return 1; |
| 159 | default: |
| 160 | printf("Error: Dumping PCIEXBAR on this northbridge is not (yet) supported.\n"); |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | if (!(pciexbar_reg & (1 << 0))) { |
| 165 | printf("PCIEXBAR register is disabled.\n"); |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | switch ((pciexbar_reg >> 1) & 3) { |
| 170 | case 0: // 256MB |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 171 | pciexbar_phys = pciexbar_reg & (0xff << 28); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 172 | max_busses = 256; |
| 173 | break; |
| 174 | case 1: // 128M |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 175 | pciexbar_phys = pciexbar_reg & (0x1ff << 27); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 176 | max_busses = 128; |
| 177 | break; |
| 178 | case 2: // 64M |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 179 | pciexbar_phys = pciexbar_reg & (0x3ff << 26); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 180 | max_busses = 64; |
| 181 | break; |
| 182 | default: // RSVD |
| 183 | printf("Undefined address base. Bailing out.\n"); |
| 184 | return 1; |
| 185 | } |
| 186 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 187 | printf("PCIEXBAR: 0x%08llx\n", pciexbar_phys); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 188 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 189 | pciexbar = map_physical(pciexbar_phys, (max_busses * 1024 * 1024)); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 190 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 191 | if (pciexbar == NULL) { |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 192 | perror("Error mapping PCIEXBAR"); |
| 193 | exit(1); |
| 194 | } |
| 195 | |
| 196 | for (bus = 0; bus < max_busses; bus++) { |
| 197 | for (dev = 0; dev < 32; dev++) { |
| 198 | for (fn = 0; fn < 8; fn++) { |
| 199 | devbase = (bus * 1024 * 1024) + (dev * 32 * 1024) + (fn * 4 * 1024); |
| 200 | |
| 201 | if (*(uint16_t *)(pciexbar + devbase) == 0xffff) |
| 202 | continue; |
| 203 | |
| 204 | /* This is a heuristics. Anyone got a better check? */ |
| 205 | if( (*(uint32_t *)(pciexbar + devbase + 256) == 0xffffffff) && |
| 206 | (*(uint32_t *)(pciexbar + devbase + 512) == 0xffffffff) ) { |
| 207 | #if DEBUG |
| 208 | printf("Skipped non-PCIe device %02x:%02x.%01x\n", bus, dev, fn); |
| 209 | #endif |
| 210 | continue; |
| 211 | } |
| 212 | |
| 213 | printf("\nPCIe %02x:%02x.%01x extended config space:", bus, dev, fn); |
| 214 | for (i = 0; i < 4096; i++) { |
| 215 | if((i % 0x10) == 0) |
| 216 | printf("\n%04x:", i); |
| 217 | printf(" %02x", *(pciexbar+devbase+i)); |
| 218 | } |
| 219 | printf("\n"); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
Stefan Reinauer | 1162f25 | 2008-12-04 15:18:20 +0000 | [diff] [blame] | 224 | unmap_physical((void *)pciexbar, (max_busses * 1024 * 1024)); |
Stefan Reinauer | 2319027 | 2008-08-20 13:41:24 +0000 | [diff] [blame] | 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | |