blob: cafd34ab373ac5470f1532b9ac85dc0fd366de52 [file] [log] [blame]
Stefan Reinauer23190272008-08-20 13:41:24 +00001/*
2 * inteltool - dump all registers on an Intel CPU + chipset based system.
3 *
Stefan Reinauer14e22772010-04-27 06:56:47 +00004 * Copyright (C) 2008-2010 by coresystems GmbH
Anton Kochkovc7fc4422012-07-21 06:36:47 +04005 * Copyright (C) 2012 Anton Kochkov
Stefan Reinauer14e22772010-04-27 06:56:47 +00006 *
Stefan Reinauer23190272008-08-20 13:41:24 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
Stefan Reinauera7b296d2011-11-14 12:40:34 -080023#include <inttypes.h>
Stefan Reinauer23190272008-08-20 13:41:24 +000024#include "inteltool.h"
25
Stefan Taunerdbc6fcd2013-06-20 18:05:06 +020026/* 320766 */
27static const io_register_t nehalem_dmi_registers[] = {
28 { 0x00, 4, "DMIVCH" }, // DMI Virtual Channel Capability Header
29 { 0x04, 4, "DMIVCCAP1" }, // DMI Port VC Capability Register 1
30 { 0x08, 4, "DMIVCCAP2" }, // DMI Port VC Capability Register 2
31 { 0x0C, 4, "DMIVCCTL" }, // DMI Port VC Control
32 { 0x10, 4, "DMIVC0RCAP" }, // DMI VC0 Resource Capability
33 { 0x14, 4, "DMIVC0RCTL" }, // DMI VC0 Resource Control
34/* { 0x18, 2, "RSVD" }, // Reserved */
35 { 0x1A, 2, "DMIVC0RSTS" }, // DMI VC0 Resource Status
36 { 0x1C, 4, "DMIVC1RCAP" }, // DMI VC1 Resource Capability
37 { 0x20, 4, "DMIVC1RCTL" }, // DMI VC1 Resource Control
38/* { 0x24, 2, "RSVD" }, // Reserved */
39 { 0x26, 2, "DMIVC1RSTS" }, // DMI VC1 Resource Status
40/* ... - Reserved */
41 { 0x84, 4, "DMILCAP" }, // DMI Link Capabilities
42 { 0x88, 2, "DMILCTL" }, // DMI Link Control
43 { 0x8A, 2, "DMILSTS" }, // DMI Link Status
44/* ... - Reserved */
45};
46
47/* 322812 */
48static const io_register_t westmere_dmi_registers[] = {
49 { 0x00, 4, "DMIVCECH" }, // DMI Virtual Channel Enhanced Capability
50 { 0x04, 4, "DMIPVCCAP1" }, // DMI Port VC Capability Register 1
51 { 0x08, 4, "DMIPVCCAP2" }, // DMI Port VC Capability Register 2
52 { 0x0C, 2, "DMIPVCCTL" }, // DMI Port VC Control
53/* { 0x0E, 2, "RSVD" }, // Reserved */
54 { 0x10, 4, "DMIVC0RCAP" }, // DMI VC0 Resource Capability
55 { 0x14, 4, "DMIVC0RCTL" }, // DMI VC0 Resource Control
56/* { 0x18, 2, "RSVD" }, // Reserved */
57 { 0x1A, 2, "DMIVC0RSTS" }, // DMI VC0 Resource Status
58 { 0x1C, 4, "DMIVC1RCAP" }, // DMI VC1 Resource Capability
59 { 0x20, 4, "DMIVC1RCTL1" }, // DMI VC1 Resource Control
60/* { 0x24, 2, "RSVD" }, // Reserved */
61 { 0x26, 2, "DMIC1RSTS" }, // DMI VC1 Resource Status
62/* ... - Reserved */
63 { 0x84, 4, "DMILCAP" }, // DMI Link Capabilities
64 { 0x88, 2, "DMILCTL" }, // DMI Link Control
65 { 0x8A, 2, "DMILSTS" }, // DMI Link Status
66/* ... - Reserved */
67};
68
Anton Kochkovc7fc4422012-07-21 06:36:47 +040069static const io_register_t sandybridge_dmi_registers[] = {
70 { 0x00, 4, "DMI VCECH" }, // DMI Virtual Channel Enhanced Capability
71 { 0x04, 4, "DMI PVCCAP1" }, // DMI Port VC Capability Register 1
72 { 0x08, 4, "DMI PVVAP2" }, // DMI Port VC Capability Register 2
73 { 0x0C, 2, "DMI PVCCTL" }, // DMI Port VC Control
74/* { 0x0E, 2, "RSVD" }, // Reserved */
75 { 0x10, 4, "DMI VC0RCAP" }, // DMI VC0 Resource Capability
76 { 0x14, 4, "DMI VC0RCTL" }, // DMI VC0 Resource Control
77/* { 0x18, 2, "RSVD" }, // Reserved */
78 { 0x1A, 2, "DMI VC0RSTS" }, // DMI VC0 Resource Status
79 { 0x1C, 4, "DMI VC1RCAP" }, // DMI VC1 Resource Capability
80 { 0x20, 4, "DMI VC1RCTL" }, // DMI VC1 Resource Control
81/* { 0x24, 2, "RSVD" }, // Reserved */
82 { 0x26, 2, "DMI VC1RSTS" }, // DMI VC1 Resource Status
83 { 0x28, 4, "DMI VCPRCAP" }, // DMI VCp Resource Capability
84 { 0x2C, 4, "DMI VCPRCTL" }, // DMI VCp Resource Control
85/* { 0x30, 2, "RSVD" }, // Reserved */
86 { 0x32, 2, "DMI VCPRSTS" }, // DMI VCp Resource Status
87 { 0x34, 4, "DMI VCMRCAP" }, // DMI VCm Resource Capability
88 { 0x38, 4, "DMI VCMRCTL" }, // DMI VCm Resource Control
89/* { 0x3C, 2, "RSVD" }, // Reserved */
90 { 0x3E, 2, "DMI VCMRSTS" }, // DMI VCm Resource Status
91/* { 0x40, 4, "RSVD" }, // Reserved */
92 { 0x44, 4, "DMI ESC" }, // DMI Element Self Description
93/* { 0x48, 8, "RSVD" }, // Reserved */
94 { 0x50, 4, "DMI LE1D" }, // DMI Link Entry 1 Description
95/* { 0x54, 4, "RSVD" }, // Reserved */
96 { 0x58, 4, "DMI LE1A" }, // DMI Link Entry 1 Address
97 { 0x5C, 4, "DMI LUE1A" }, // DMI Link Upper Entry 1 Address
98 { 0x60, 4, "DMI LE2D" }, // DMI Link Entry 2 Description
99/* { 0x64, 4, "RSVD" }, // Reserved */
100 { 0x68, 4, "DMI LE2A" }, // DMI Link Entry 2 Address
101/* { 0x6C, 4, "RSVD" }, // Reserved
102 { 0x70, 8, "RSVD" }, // Reserved
103 { 0x78, 8, "RSVD" }, // Reserved
104 { 0x80, 4, "RSVD" }, // Reserved */
105 { 0x84, 4, "LCAP" }, // Link Capabilities
106 { 0x88, 2, "LCTL" }, // Link Control
107 { 0x8A, 2, "LSTS" }, // Link Status
108/* { 0x8C, 4, "RSVD" }, // Reserved
109 { 0x90, 4, "RSVD" }, // Reserved
110 { 0x94, 4, "RSVD" }, // Reserved */
111 { 0x98, 2, "LCTL2" }, // Link Control 2
112 { 0x9A, 2, "LSTS2" }, // Link Status 2
113/* ... - Reserved */
114 { 0xBC0, 4, "AFE_BMUF0" }, // AFE BMU Configuration Function 0
115 { 0xBC4, 4, "RSVD" }, // Reserved
116 { 0xBC8, 4, "RSVD" }, // Reserved
117 { 0xBCC, 4, "AFE_BMUT0" }, // AFE BMU Configuration Test 0
118/* ... - Reserved */
119};
120
Stefan Reinauer23190272008-08-20 13:41:24 +0000121/*
122 * Egress Port Root Complex MMIO configuration space
123 */
124int print_epbar(struct pci_dev *nb)
125{
126 int i, size = (4 * 1024);
127 volatile uint8_t *epbar;
Stefan Reinauer1162f252008-12-04 15:18:20 +0000128 uint64_t epbar_phys;
Stefan Reinauer23190272008-08-20 13:41:24 +0000129
130 printf("\n============= EPBAR =============\n\n");
131
132 switch (nb->device_id) {
Pat Erleyca3548e2010-04-21 06:23:19 +0000133 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000134 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000135 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000136 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200137 case PCI_DEVICE_ID_INTEL_82946:
Stefan Reinauer1162f252008-12-04 15:18:20 +0000138 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000139 epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe;
140 break;
Stefan Tauner04c06002012-10-13 02:19:30 +0200141 case PCI_DEVICE_ID_INTEL_82965PM:
142 case PCI_DEVICE_ID_INTEL_82Q965:
143 case PCI_DEVICE_ID_INTEL_82Q35:
144 case PCI_DEVICE_ID_INTEL_82G33:
145 case PCI_DEVICE_ID_INTEL_82Q33:
146 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200147 case PCI_DEVICE_ID_INTEL_32X0:
Stefan Tauner04c06002012-10-13 02:19:30 +0200148 case PCI_DEVICE_ID_INTEL_82X4X:
Corey Osgood23d98c72010-07-29 19:25:31 +0000149 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
150 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Stefan Tauner04c06002012-10-13 02:19:30 +0200151 epbar_phys = pci_read_long(nb, 0x40) & 0xfffffffe;
152 epbar_phys |= ((uint64_t)pci_read_long(nb, 0x44)) << 32;
153 break;
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000154 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200155 case PCI_DEVICE_ID_INTEL_82810_DC:
156 case PCI_DEVICE_ID_INTEL_82810E_DC:
Stefan Reinauer04844812010-02-22 11:26:06 +0000157 case PCI_DEVICE_ID_INTEL_82830M:
Idwer Vollering312fc962010-12-17 22:34:58 +0000158 case PCI_DEVICE_ID_INTEL_82865:
159 printf("This northbridge does not have EPBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000160 return 1;
161 default:
162 printf("Error: Dumping EPBAR on this northbridge is not (yet) supported.\n");
163 return 1;
164 }
165
Stefan Reinauer1162f252008-12-04 15:18:20 +0000166 epbar = map_physical(epbar_phys, size);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000167
Stefan Reinauer1162f252008-12-04 15:18:20 +0000168 if (epbar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +0000169 perror("Error mapping EPBAR");
170 exit(1);
171 }
172
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800173 printf("EPBAR = 0x%08" PRIx64 " (MEM)\n\n", epbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000174 for (i = 0; i < size; i += 4) {
175 if (*(uint32_t *)(epbar + i))
176 printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(epbar+i));
177 }
178
Stefan Reinauer1162f252008-12-04 15:18:20 +0000179 unmap_physical((void *)epbar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000180 return 0;
181}
182
183/*
184 * MCH-ICH Serial Interconnect Ingress Root Complex MMIO configuration space
185 */
186int print_dmibar(struct pci_dev *nb)
187{
188 int i, size = (4 * 1024);
189 volatile uint8_t *dmibar;
Stefan Reinauer1162f252008-12-04 15:18:20 +0000190 uint64_t dmibar_phys;
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400191 const io_register_t *dmi_registers = NULL;
Stefan Reinauer23190272008-08-20 13:41:24 +0000192
193 printf("\n============= DMIBAR ============\n\n");
194
195 switch (nb->device_id) {
Pat Erleyca3548e2010-04-21 06:23:19 +0000196 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000197 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000198 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000199 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Reinauer1162f252008-12-04 15:18:20 +0000200 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000201 dmibar_phys = pci_read_long(nb, 0x4c) & 0xfffffffe;
202 break;
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200203 case PCI_DEVICE_ID_INTEL_82946:
Stefan Tauner04c06002012-10-13 02:19:30 +0200204 case PCI_DEVICE_ID_INTEL_82965PM:
205 case PCI_DEVICE_ID_INTEL_82Q965:
Warren Turkal53291952010-09-03 09:32:17 +0000206 case PCI_DEVICE_ID_INTEL_82Q35:
207 case PCI_DEVICE_ID_INTEL_82G33:
208 case PCI_DEVICE_ID_INTEL_82Q33:
Stefan Tauner04c06002012-10-13 02:19:30 +0200209 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200210 case PCI_DEVICE_ID_INTEL_32X0:
Stefan Tauner04c06002012-10-13 02:19:30 +0200211 case PCI_DEVICE_ID_INTEL_82X4X:
Corey Osgood23d98c72010-07-29 19:25:31 +0000212 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
213 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Warren Turkal53291952010-09-03 09:32:17 +0000214 dmibar_phys = pci_read_long(nb, 0x68) & 0xfffffffe;
215 dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32;
216 break;
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000217 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200218 case PCI_DEVICE_ID_INTEL_82810_DC:
219 case PCI_DEVICE_ID_INTEL_82810E_DC:
Idwer Vollering312fc962010-12-17 22:34:58 +0000220 case PCI_DEVICE_ID_INTEL_82865:
221 printf("This northbridge does not have DMIBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000222 return 1;
Stefan Tauner04c06002012-10-13 02:19:30 +0200223 case PCI_DEVICE_ID_INTEL_82X58:
Warren Turkal3235eea2010-09-03 09:31:13 +0000224 dmibar_phys = pci_read_long(nb, 0x50) & 0xfffff000;
225 break;
Stefan Taunerdbc6fcd2013-06-20 18:05:06 +0200226 case PCI_DEVICE_ID_INTEL_CORE_0TH_GEN:
227 /* DMIBAR is called DMIRCBAR in Nehalem */
228 dmibar_phys = pci_read_long(nb, 0x50) & 0xfffff000; /* 31:12 */
229 dmi_registers = nehalem_dmi_registers;
230 size = ARRAY_SIZE(nehalem_dmi_registers);
231 break;
Stefan Tauner04c06002012-10-13 02:19:30 +0200232 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
233 dmibar_phys = pci_read_long(nb, 0x68);
234 dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32;
235 dmibar_phys &= 0x0000000ffffff000UL; /* 35:12 */
Stefan Taunerdbc6fcd2013-06-20 18:05:06 +0200236 dmi_registers = westmere_dmi_registers;
237 size = ARRAY_SIZE(westmere_dmi_registers);
Stefan Tauner04c06002012-10-13 02:19:30 +0200238 break;
239 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN:
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400240 dmi_registers = sandybridge_dmi_registers;
241 size = ARRAY_SIZE(sandybridge_dmi_registers);
Stefan Tauner04c06002012-10-13 02:19:30 +0200242 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN: /* pretty printing not implemented yet */
243 dmibar_phys = pci_read_long(nb, 0x68);
244 dmibar_phys |= ((uint64_t)pci_read_long(nb, 0x6c)) << 32;
245 dmibar_phys &= 0x0000007ffffff000UL; /* 38:12 */
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400246 break;
Stefan Reinauer23190272008-08-20 13:41:24 +0000247 default:
248 printf("Error: Dumping DMIBAR on this northbridge is not (yet) supported.\n");
249 return 1;
250 }
251
Stefan Reinauer1162f252008-12-04 15:18:20 +0000252 dmibar = map_physical(dmibar_phys, size);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000253
Stefan Reinauer1162f252008-12-04 15:18:20 +0000254 if (dmibar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +0000255 perror("Error mapping DMIBAR");
256 exit(1);
257 }
258
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800259 printf("DMIBAR = 0x%08" PRIx64 " (MEM)\n\n", dmibar_phys);
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400260 if (dmi_registers != NULL) {
261 for (i = 0; i < size; i++) {
262 switch (dmi_registers[i].size) {
263 case 4:
264 printf("dmibase+0x%04x: 0x%08x (%s)\n",
265 dmi_registers[i].addr,
266 *(uint32_t *)(dmibar+dmi_registers[i].addr),
267 dmi_registers[i].name);
268 break;
269 case 2:
270 printf("dmibase+0x%04x: 0x%04x (%s)\n",
271 dmi_registers[i].addr,
272 *(uint16_t *)(dmibar+dmi_registers[i].addr),
273 dmi_registers[i].name);
274 break;
275 case 1:
276 printf("dmibase+0x%04x: 0x%02x (%s)\n",
277 dmi_registers[i].addr,
278 *(uint8_t *)(dmibar+dmi_registers[i].addr),
279 dmi_registers[i].name);
280 break;
281 }
282 }
283 } else {
284 for (i = 0; i < size; i += 4) {
285 if (*(uint32_t *)(dmibar + i))
286 printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(dmibar+i));
287 }
Stefan Reinauer23190272008-08-20 13:41:24 +0000288 }
289
Stefan Reinauer1162f252008-12-04 15:18:20 +0000290 unmap_physical((void *)dmibar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000291 return 0;
292}
293
294/*
295 * PCIe MMIO configuration space
296 */
297int print_pciexbar(struct pci_dev *nb)
298{
Stefan Reinauer1162f252008-12-04 15:18:20 +0000299 uint64_t pciexbar_reg;
300 uint64_t pciexbar_phys;
Stefan Reinauer23190272008-08-20 13:41:24 +0000301 volatile uint8_t *pciexbar;
302 int max_busses, devbase, i;
303 int bus, dev, fn;
304
305 printf("========= PCIEXBAR ========\n\n");
306
307 switch (nb->device_id) {
Pat Erleyca3548e2010-04-21 06:23:19 +0000308 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000309 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000310 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000311 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Reinauer1162f252008-12-04 15:18:20 +0000312 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000313 pciexbar_reg = pci_read_long(nb, 0x48);
314 break;
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200315 case PCI_DEVICE_ID_INTEL_82946:
Stefan Tauner04c06002012-10-13 02:19:30 +0200316 case PCI_DEVICE_ID_INTEL_82965PM:
317 case PCI_DEVICE_ID_INTEL_82Q965:
318 case PCI_DEVICE_ID_INTEL_82Q35:
319 case PCI_DEVICE_ID_INTEL_82G33:
320 case PCI_DEVICE_ID_INTEL_82Q33:
321 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200322 case PCI_DEVICE_ID_INTEL_32X0:
Stefan Tauner04c06002012-10-13 02:19:30 +0200323 case PCI_DEVICE_ID_INTEL_82X4X:
Corey Osgood23d98c72010-07-29 19:25:31 +0000324 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
325 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Stefan Tauner04c06002012-10-13 02:19:30 +0200326 pciexbar_reg = pci_read_long(nb, 0x60);
327 pciexbar_reg |= ((uint64_t)pci_read_long(nb, 0x64)) << 32;
328 break;
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000329 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200330 case PCI_DEVICE_ID_INTEL_82810_DC:
331 case PCI_DEVICE_ID_INTEL_82810E_DC:
Idwer Vollering312fc962010-12-17 22:34:58 +0000332 case PCI_DEVICE_ID_INTEL_82865:
333 printf("Error: This northbridge does not have PCIEXBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000334 return 1;
335 default:
336 printf("Error: Dumping PCIEXBAR on this northbridge is not (yet) supported.\n");
337 return 1;
338 }
339
340 if (!(pciexbar_reg & (1 << 0))) {
341 printf("PCIEXBAR register is disabled.\n");
342 return 0;
343 }
344
345 switch ((pciexbar_reg >> 1) & 3) {
346 case 0: // 256MB
Paul Menzel17c05f22013-04-03 10:00:33 +0200347 pciexbar_phys = pciexbar_reg & (0xffULL << 28);
Stefan Reinauer23190272008-08-20 13:41:24 +0000348 max_busses = 256;
349 break;
350 case 1: // 128M
Paul Menzel17c05f22013-04-03 10:00:33 +0200351 pciexbar_phys = pciexbar_reg & (0x1ffULL << 27);
Stefan Reinauer23190272008-08-20 13:41:24 +0000352 max_busses = 128;
353 break;
354 case 2: // 64M
Paul Menzel17c05f22013-04-03 10:00:33 +0200355 pciexbar_phys = pciexbar_reg & (0x3ffULL << 26);
Stefan Reinauer23190272008-08-20 13:41:24 +0000356 max_busses = 64;
357 break;
358 default: // RSVD
359 printf("Undefined address base. Bailing out.\n");
360 return 1;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000361 }
Stefan Reinauer23190272008-08-20 13:41:24 +0000362
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800363 printf("PCIEXBAR: 0x%08" PRIx64 "\n", pciexbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000364
Stefan Reinauer1162f252008-12-04 15:18:20 +0000365 pciexbar = map_physical(pciexbar_phys, (max_busses * 1024 * 1024));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000366
Stefan Reinauer1162f252008-12-04 15:18:20 +0000367 if (pciexbar == NULL) {
Stefan Reinauer23190272008-08-20 13:41:24 +0000368 perror("Error mapping PCIEXBAR");
369 exit(1);
370 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000371
Stefan Reinauer23190272008-08-20 13:41:24 +0000372 for (bus = 0; bus < max_busses; bus++) {
373 for (dev = 0; dev < 32; dev++) {
374 for (fn = 0; fn < 8; fn++) {
375 devbase = (bus * 1024 * 1024) + (dev * 32 * 1024) + (fn * 4 * 1024);
376
377 if (*(uint16_t *)(pciexbar + devbase) == 0xffff)
378 continue;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000379
Stefan Reinauer23190272008-08-20 13:41:24 +0000380 /* This is a heuristics. Anyone got a better check? */
381 if( (*(uint32_t *)(pciexbar + devbase + 256) == 0xffffffff) &&
382 (*(uint32_t *)(pciexbar + devbase + 512) == 0xffffffff) ) {
383#if DEBUG
384 printf("Skipped non-PCIe device %02x:%02x.%01x\n", bus, dev, fn);
385#endif
386 continue;
387 }
388
389 printf("\nPCIe %02x:%02x.%01x extended config space:", bus, dev, fn);
390 for (i = 0; i < 4096; i++) {
391 if((i % 0x10) == 0)
392 printf("\n%04x:", i);
393 printf(" %02x", *(pciexbar+devbase+i));
394 }
395 printf("\n");
396 }
397 }
398 }
399
Stefan Reinauer1162f252008-12-04 15:18:20 +0000400 unmap_physical((void *)pciexbar, (max_busses * 1024 * 1024));
Stefan Reinauer23190272008-08-20 13:41:24 +0000401
402 return 0;
403}