blob: 3a31ae47176a5a1cc6e42167d3e64a763f9375a4 [file] [log] [blame]
Stefan Reinauer23190272008-08-20 13:41:24 +00001/*
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 Reinauer23190272008-08-20 13:41:24 +000022#include "inteltool.h"
23
24/*
25 * Egress Port Root Complex MMIO configuration space
26 */
27int print_epbar(struct pci_dev *nb)
28{
29 int i, size = (4 * 1024);
30 volatile uint8_t *epbar;
Stefan Reinauer1162f252008-12-04 15:18:20 +000031 uint64_t epbar_phys;
Stefan Reinauer23190272008-08-20 13:41:24 +000032
33 printf("\n============= EPBAR =============\n\n");
34
35 switch (nb->device_id) {
36 case PCI_DEVICE_ID_INTEL_82945GM:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +000037 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Reinauer1162f252008-12-04 15:18:20 +000038 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +000039 epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe;
40 break;
Stefan Reinauer1162f252008-12-04 15:18:20 +000041 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 Reinauerb2aedb12009-08-29 15:45:43 +000045 case PCI_DEVICE_ID_INTEL_82810:
46 case PCI_DEVICE_ID_INTEL_82810DC:
Stefan Reinauer23190272008-08-20 13:41:24 +000047 printf("This northbrigde does not have EPBAR.\n");
48 return 1;
49 default:
50 printf("Error: Dumping EPBAR on this northbridge is not (yet) supported.\n");
51 return 1;
52 }
53
Stefan Reinauer1162f252008-12-04 15:18:20 +000054 epbar = map_physical(epbar_phys, size);
Stefan Reinauer23190272008-08-20 13:41:24 +000055
Stefan Reinauer1162f252008-12-04 15:18:20 +000056 if (epbar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +000057 perror("Error mapping EPBAR");
58 exit(1);
59 }
60
Stefan Reinauer1162f252008-12-04 15:18:20 +000061 printf("EPBAR = 0x%08llx (MEM)\n\n", epbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +000062 for (i = 0; i < size; i += 4) {
63 if (*(uint32_t *)(epbar + i))
64 printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(epbar+i));
65 }
66
Stefan Reinauer1162f252008-12-04 15:18:20 +000067 unmap_physical((void *)epbar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +000068 return 0;
69}
70
71/*
72 * MCH-ICH Serial Interconnect Ingress Root Complex MMIO configuration space
73 */
74int print_dmibar(struct pci_dev *nb)
75{
76 int i, size = (4 * 1024);
77 volatile uint8_t *dmibar;
Stefan Reinauer1162f252008-12-04 15:18:20 +000078 uint64_t dmibar_phys;
Stefan Reinauer23190272008-08-20 13:41:24 +000079
80 printf("\n============= DMIBAR ============\n\n");
81
82 switch (nb->device_id) {
83 case PCI_DEVICE_ID_INTEL_82945GM:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +000084 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Reinauer1162f252008-12-04 15:18:20 +000085 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +000086 dmibar_phys = pci_read_long(nb, 0x4c) & 0xfffffffe;
87 break;
Stefan Reinauer1162f252008-12-04 15:18:20 +000088 case PCI_DEVICE_ID_INTEL_PM965:
89 dmibar_phys = pci_read_long(nb, 0x68) & 0xfffffffe;
90 dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32;
91 break;
Stefan Reinauerb2aedb12009-08-29 15:45:43 +000092 case PCI_DEVICE_ID_INTEL_82810:
93 case PCI_DEVICE_ID_INTEL_82810DC:
Stefan Reinauer23190272008-08-20 13:41:24 +000094 printf("This northbrigde does not have DMIBAR.\n");
95 return 1;
96 default:
97 printf("Error: Dumping DMIBAR on this northbridge is not (yet) supported.\n");
98 return 1;
99 }
100
Stefan Reinauer1162f252008-12-04 15:18:20 +0000101 dmibar = map_physical(dmibar_phys, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000102
Stefan Reinauer1162f252008-12-04 15:18:20 +0000103 if (dmibar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +0000104 perror("Error mapping DMIBAR");
105 exit(1);
106 }
107
Stefan Reinauer1162f252008-12-04 15:18:20 +0000108 printf("DMIBAR = 0x%08llx (MEM)\n\n", dmibar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000109 for (i = 0; i < size; i += 4) {
110 if (*(uint32_t *)(dmibar + i))
111 printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(dmibar+i));
112 }
113
Stefan Reinauer1162f252008-12-04 15:18:20 +0000114 unmap_physical((void *)dmibar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000115 return 0;
116}
117
118/*
119 * PCIe MMIO configuration space
120 */
121int print_pciexbar(struct pci_dev *nb)
122{
Stefan Reinauer1162f252008-12-04 15:18:20 +0000123 uint64_t pciexbar_reg;
124 uint64_t pciexbar_phys;
Stefan Reinauer23190272008-08-20 13:41:24 +0000125 volatile uint8_t *pciexbar;
126 int max_busses, devbase, i;
127 int bus, dev, fn;
128
129 printf("========= PCIEXBAR ========\n\n");
130
131 switch (nb->device_id) {
132 case PCI_DEVICE_ID_INTEL_82945GM:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000133 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Reinauer1162f252008-12-04 15:18:20 +0000134 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000135 pciexbar_reg = pci_read_long(nb, 0x48);
136 break;
Stefan Reinauer1162f252008-12-04 15:18:20 +0000137 case PCI_DEVICE_ID_INTEL_PM965:
138 pciexbar_reg = pci_read_long(nb, 0x60);
139 pciexbar_reg |= ((uint64_t)pci_read_long(nb, 0x64)) << 32;
140 break;
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000141 case PCI_DEVICE_ID_INTEL_82810:
142 case PCI_DEVICE_ID_INTEL_82810DC:
Stefan Reinauer23190272008-08-20 13:41:24 +0000143 printf("Error: This northbrigde does not have PCIEXBAR.\n");
144 return 1;
145 default:
146 printf("Error: Dumping PCIEXBAR on this northbridge is not (yet) supported.\n");
147 return 1;
148 }
149
150 if (!(pciexbar_reg & (1 << 0))) {
151 printf("PCIEXBAR register is disabled.\n");
152 return 0;
153 }
154
155 switch ((pciexbar_reg >> 1) & 3) {
156 case 0: // 256MB
Stefan Reinauer1162f252008-12-04 15:18:20 +0000157 pciexbar_phys = pciexbar_reg & (0xff << 28);
Stefan Reinauer23190272008-08-20 13:41:24 +0000158 max_busses = 256;
159 break;
160 case 1: // 128M
Stefan Reinauer1162f252008-12-04 15:18:20 +0000161 pciexbar_phys = pciexbar_reg & (0x1ff << 27);
Stefan Reinauer23190272008-08-20 13:41:24 +0000162 max_busses = 128;
163 break;
164 case 2: // 64M
Stefan Reinauer1162f252008-12-04 15:18:20 +0000165 pciexbar_phys = pciexbar_reg & (0x3ff << 26);
Stefan Reinauer23190272008-08-20 13:41:24 +0000166 max_busses = 64;
167 break;
168 default: // RSVD
169 printf("Undefined address base. Bailing out.\n");
170 return 1;
171 }
172
Stefan Reinauer1162f252008-12-04 15:18:20 +0000173 printf("PCIEXBAR: 0x%08llx\n", pciexbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000174
Stefan Reinauer1162f252008-12-04 15:18:20 +0000175 pciexbar = map_physical(pciexbar_phys, (max_busses * 1024 * 1024));
Stefan Reinauer23190272008-08-20 13:41:24 +0000176
Stefan Reinauer1162f252008-12-04 15:18:20 +0000177 if (pciexbar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +0000178 perror("Error mapping PCIEXBAR");
179 exit(1);
180 }
181
182 for (bus = 0; bus < max_busses; bus++) {
183 for (dev = 0; dev < 32; dev++) {
184 for (fn = 0; fn < 8; fn++) {
185 devbase = (bus * 1024 * 1024) + (dev * 32 * 1024) + (fn * 4 * 1024);
186
187 if (*(uint16_t *)(pciexbar + devbase) == 0xffff)
188 continue;
189
190 /* This is a heuristics. Anyone got a better check? */
191 if( (*(uint32_t *)(pciexbar + devbase + 256) == 0xffffffff) &&
192 (*(uint32_t *)(pciexbar + devbase + 512) == 0xffffffff) ) {
193#if DEBUG
194 printf("Skipped non-PCIe device %02x:%02x.%01x\n", bus, dev, fn);
195#endif
196 continue;
197 }
198
199 printf("\nPCIe %02x:%02x.%01x extended config space:", bus, dev, fn);
200 for (i = 0; i < 4096; i++) {
201 if((i % 0x10) == 0)
202 printf("\n%04x:", i);
203 printf(" %02x", *(pciexbar+devbase+i));
204 }
205 printf("\n");
206 }
207 }
208 }
209
Stefan Reinauer1162f252008-12-04 15:18:20 +0000210 unmap_physical((void *)pciexbar, (max_busses * 1024 * 1024));
Stefan Reinauer23190272008-08-20 13:41:24 +0000211
212 return 0;
213}
214
215