blob: a0f0a654122fc165ad78b257d13957066cf99127 [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
5 *
Stefan Reinauer23190272008-08-20 13:41:24 +00006 * 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
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
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +020026volatile uint8_t *mchbar;
27
28static void write_mchbar32 (uint32_t addr, uint32_t val)
29{
30 * (volatile uint32_t *) (mchbar + addr) = val;
31}
32
33static uint32_t read_mchbar32 (uint32_t addr)
34{
35 return * (volatile uint32_t *) (mchbar + addr);
36}
37
38static uint8_t read_mchbar8 (uint32_t addr)
39{
40 return * (volatile uint8_t *) (mchbar + addr);
41}
42
43static u16 read_500 (int channel, u16 addr, int split)
44{
45 uint32_t val;
46 write_mchbar32 (0x500 + (channel << 10), 0);
47 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
48 write_mchbar32 (0x500 + (channel << 10), 0x80000000 | (((read_mchbar8 (0x246 + (channel << 10)) >> 2) & 3) + 0xb88 - addr));
49 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
50 val = read_mchbar32 (0x508 + (channel << 10));
51
52 return val & ((1 << split) - 1);
53}
54
55static inline u16 get_lane_offset (int slot, int rank, int lane)
56{
57 return 0x124 * lane + ((lane & 4) ? 0x23e : 0) + 11 * rank + 22 * slot - 0x452 * (lane == 8);
58}
59
60static inline u16 get_timing_register_addr (int lane, int tm, int slot, int rank)
61{
62 const u16 offs[] = { 0x1d, 0xa8, 0xe6, 0x5c };
63 return get_lane_offset (slot, rank, lane) + offs[(tm + 3) % 4];
64}
65
66static void write_1d0 (u32 val, u16 addr, int bits, int flag)
67{
68 write_mchbar32 (0x1d0, 0);
69 while (read_mchbar32 (0x1d0) & 0x800000);
70 write_mchbar32 (0x1d4, (val & ((1 << bits) - 1)) | (2 << bits) | (flag << bits));
71 write_mchbar32 (0x1d0, 0x40000000 | addr);
72 while (read_mchbar32 (0x1d0) & 0x800000);
73}
74
75static u16 read_1d0 (u16 addr, int split)
76{
77 u32 val;
78 write_mchbar32 (0x1d0, 0);
79 while (read_mchbar32 (0x1d0) & 0x800000);
80 write_mchbar32 (0x1d0, 0x80000000 | (((read_mchbar8 (0x246) >> 2) & 3) + 0x361 - addr));
81 while (read_mchbar32 (0x1d0) & 0x800000);
82 val = read_mchbar32 (0x1d8);
83 write_1d0 (0, 0x33d, 0, 0);
84 write_1d0 (0, 0x33d, 0, 0);
85 return val & ((1 << split) - 1);
86}
87
88static void dump_timings (void)
89{
90 int channel, slot, rank, lane, i;
91 printf ("Timings:\n");
92 for (channel = 0; channel < 2; channel++)
93 for (slot = 0; slot < 2; slot++)
94 for (rank = 0; rank < 2; rank++) {
95 printf ("channel %d, slot %d, rank %d\n", channel, slot, rank);
96 for (lane = 0; lane < 9; lane++) {
97 printf ("lane %d: ", lane);
98 for (i = 0; i < 4; i++) {
99 printf ("%x ", read_500 (channel,
100 get_timing_register_addr (lane, i, slot, rank), 9));
101 }
102 printf ("\n");
103 }
104 }
105
106 printf ("[178] = %x\n", read_1d0 (0x178, 7));
107 printf ("[10b] = %x\n", read_1d0 (0x10b, 6));
108}
109
110
Stefan Reinauer23190272008-08-20 13:41:24 +0000111/*
112 * (G)MCH MMIO Config Space
113 */
Idwer Vollering312fc962010-12-17 22:34:58 +0000114int print_mchbar(struct pci_dev *nb, struct pci_access *pacc)
Stefan Reinauer23190272008-08-20 13:41:24 +0000115{
116 int i, size = (16 * 1024);
Idwer Vollering312fc962010-12-17 22:34:58 +0000117 uint64_t mchbar_phys;
118 struct pci_dev *nb_device6; /* "overflow device" on i865 */
119 uint16_t pcicmd6;
Stefan Reinauer23190272008-08-20 13:41:24 +0000120
121 printf("\n============= MCHBAR ============\n\n");
122
123 switch (nb->device_id) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000124 case PCI_DEVICE_ID_INTEL_82865:
125 /*
126 * On i865, the memory access enable/disable bit (MCHBAREN on
127 * i945/i965) is not in the MCHBAR (i945/i965) register but in
128 * the PCICMD6 register. BAR6 and PCICMD6 reside on device 6.
129 *
130 * The actual base address is in BAR6 on i865 where on
131 * i945/i965 the base address is in MCHBAR.
132 */
133 nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0); /* Device 6 */
134 mchbar_phys = pci_read_long(nb_device6, 0x10); /* BAR6 */
135 pcicmd6 = pci_read_long(nb_device6, 0x04); /* PCICMD6 */
136
137 /* Try to enable Memory Access Enable (MAE). */
138 if (!(pcicmd6 & (1 << 1))) {
139 printf("Access to BAR6 is currently disabled, "
140 "attempting to enable.\n");
141 pci_write_long(nb_device6, 0x04, pcicmd6 | (1 << 1));
142 if (pci_read_long(nb_device6, 0x04) & (1 << 1))
143 printf("Enabled successfully.\n");
144 else
145 printf("Enable FAILED!\n");
146 }
147 mchbar_phys &= 0xfffff000; /* Bits 31:12 from BAR6 */
148 break;
Pat Erleyca3548e2010-04-21 06:23:19 +0000149 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000150 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000151 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000152 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Tauner04c06002012-10-13 02:19:30 +0200153 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000154 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
155 break;
Stefan Tauner04c06002012-10-13 02:19:30 +0200156 case PCI_DEVICE_ID_INTEL_82965PM:
157 case PCI_DEVICE_ID_INTEL_82Q35:
158 case PCI_DEVICE_ID_INTEL_82G33:
159 case PCI_DEVICE_ID_INTEL_82Q33:
160 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
161 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
162 break;
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200163 case PCI_DEVICE_ID_INTEL_82946:
Stefan Tauner04c06002012-10-13 02:19:30 +0200164 case PCI_DEVICE_ID_INTEL_82Q965:
Corey Osgood23d98c72010-07-29 19:25:31 +0000165 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
166 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Stefan Tauner04c06002012-10-13 02:19:30 +0200167 mchbar_phys = pci_read_long(nb, 0x48);
Corey Osgood23d98c72010-07-29 19:25:31 +0000168
169 /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads.
Idwer Vollering312fc962010-12-17 22:34:58 +0000170 * If it isn't, try to set it. This may fail, because there is
171 * some bit that locks that bit, and isn't in the public
Corey Osgood23d98c72010-07-29 19:25:31 +0000172 * datasheets.
173 */
174
175 if(!(mchbar_phys & 1))
176 {
Stefan Tauner04c06002012-10-13 02:19:30 +0200177 printf("Access to the MCHBAR is currently disabled, "
178 "attempting to enable.\n");
Corey Osgood23d98c72010-07-29 19:25:31 +0000179 mchbar_phys |= 0x1;
180 pci_write_long(nb, 0x48, mchbar_phys);
Stefan Tauner04c06002012-10-13 02:19:30 +0200181 if(pci_read_long(nb, 0x48) & 1)
Corey Osgood23d98c72010-07-29 19:25:31 +0000182 printf("Enabled successfully.\n");
183 else
184 printf("Enable FAILED!\n");
185 }
186 mchbar_phys &= 0xfffffffe;
Stefan Tauner04c06002012-10-13 02:19:30 +0200187 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
188 break;
Maciej Pijanka90d17402009-09-30 17:05:46 +0000189 case PCI_DEVICE_ID_INTEL_82443LX:
190 case PCI_DEVICE_ID_INTEL_82443BX:
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000191 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200192 case PCI_DEVICE_ID_INTEL_82810E_DC:
193 case PCI_DEVICE_ID_INTEL_82810_DC:
Stefan Reinauer04844812010-02-22 11:26:06 +0000194 case PCI_DEVICE_ID_INTEL_82830M:
Idwer Vollering312fc962010-12-17 22:34:58 +0000195 printf("This northbridge does not have MCHBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000196 return 1;
Stefan Tauner04c06002012-10-13 02:19:30 +0200197 case PCI_DEVICE_ID_INTEL_82X4X:
198 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200199 case PCI_DEVICE_ID_INTEL_32X0:
Anton Kochkovda0b4562010-05-30 12:33:12 +0000200 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
201 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
Stefan Tauner04c06002012-10-13 02:19:30 +0200202 break;
203 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
204 mchbar_phys = pci_read_long(nb, 0x48);
205 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
206 mchbar_phys &= 0x0000000fffffc000UL; /* 35:14 */
Stefan Tauner04c06002012-10-13 02:19:30 +0200207 break;
208 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN:
Damien Zammit601da482014-05-26 23:00:23 +1000209 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_A: /* pretty printing not implemented yet */
210 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_B:
211 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_C:
212 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D:
Dennis Wassenbergae6685f2014-10-30 10:30:40 +0100213 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_U:
Stefan Tauner04c06002012-10-13 02:19:30 +0200214 mchbar_phys = pci_read_long(nb, 0x48);
215 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
216 mchbar_phys &= 0x0000007fffff8000UL; /* 38:15 */
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200217 size = 32768;
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400218 break;
Stefan Reinauer23190272008-08-20 13:41:24 +0000219 default:
220 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
221 return 1;
222 }
223
Stefan Reinauer1162f252008-12-04 15:18:20 +0000224 mchbar = map_physical(mchbar_phys, size);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000225
Stefan Reinauer1162f252008-12-04 15:18:20 +0000226 if (mchbar == NULL) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000227 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
228 perror("Error mapping BAR6");
229 else
230 perror("Error mapping MCHBAR");
Stefan Reinauer23190272008-08-20 13:41:24 +0000231 exit(1);
232 }
233
Idwer Vollering312fc962010-12-17 22:34:58 +0000234 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800235 printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Idwer Vollering312fc962010-12-17 22:34:58 +0000236 else
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800237 printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000238
Vladimir Serbinenko9c4f1b82014-11-04 21:05:12 +0100239 for (i = 0; i < size; i += 4) {
240 if (*(uint32_t *)(mchbar + i))
241 printf("0x%04x: 0x%08"PRIx32"\n", i, *(uint32_t *)(mchbar+i));
Stefan Reinauer23190272008-08-20 13:41:24 +0000242 }
243
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200244 switch (nb->device_id)
245 {
246 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +0200247 printf ("clock_speed_index = %x\n", read_500 (0,0x609, 6) >> 1);
248 dump_timings ();
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200249 break;
250 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_A:
251 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_B:
252 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_C:
253 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D:
254 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN:
255 ivybridge_dump_timings();
256 break;
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +0200257 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000258 unmap_physical((void *)mchbar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000259 return 0;
260}
261
262