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