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