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