blob: f5f3f94fd43569f5158685ae599369ca9a25c8f7 [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.
Stefan Reinauer23190272008-08-20 13:41:24 +000014 */
15
16
17#include <stdio.h>
18#include <stdlib.h>
Stefan Reinauera7b296d2011-11-14 12:40:34 -080019#include <inttypes.h>
Stefan Reinauer23190272008-08-20 13:41:24 +000020#include "inteltool.h"
21
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +020022volatile uint8_t *mchbar;
23
24static void write_mchbar32 (uint32_t addr, uint32_t val)
25{
26 * (volatile uint32_t *) (mchbar + addr) = val;
27}
28
29static uint32_t read_mchbar32 (uint32_t addr)
30{
31 return * (volatile uint32_t *) (mchbar + addr);
32}
33
34static uint8_t read_mchbar8 (uint32_t addr)
35{
36 return * (volatile uint8_t *) (mchbar + addr);
37}
38
39static u16 read_500 (int channel, u16 addr, int split)
40{
41 uint32_t val;
42 write_mchbar32 (0x500 + (channel << 10), 0);
43 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
44 write_mchbar32 (0x500 + (channel << 10), 0x80000000 | (((read_mchbar8 (0x246 + (channel << 10)) >> 2) & 3) + 0xb88 - addr));
45 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
46 val = read_mchbar32 (0x508 + (channel << 10));
47
48 return val & ((1 << split) - 1);
49}
50
51static inline u16 get_lane_offset (int slot, int rank, int lane)
52{
53 return 0x124 * lane + ((lane & 4) ? 0x23e : 0) + 11 * rank + 22 * slot - 0x452 * (lane == 8);
54}
55
56static inline u16 get_timing_register_addr (int lane, int tm, int slot, int rank)
57{
58 const u16 offs[] = { 0x1d, 0xa8, 0xe6, 0x5c };
59 return get_lane_offset (slot, rank, lane) + offs[(tm + 3) % 4];
60}
61
62static void write_1d0 (u32 val, u16 addr, int bits, int flag)
63{
64 write_mchbar32 (0x1d0, 0);
65 while (read_mchbar32 (0x1d0) & 0x800000);
66 write_mchbar32 (0x1d4, (val & ((1 << bits) - 1)) | (2 << bits) | (flag << bits));
67 write_mchbar32 (0x1d0, 0x40000000 | addr);
68 while (read_mchbar32 (0x1d0) & 0x800000);
69}
70
71static u16 read_1d0 (u16 addr, int split)
72{
73 u32 val;
74 write_mchbar32 (0x1d0, 0);
75 while (read_mchbar32 (0x1d0) & 0x800000);
76 write_mchbar32 (0x1d0, 0x80000000 | (((read_mchbar8 (0x246) >> 2) & 3) + 0x361 - addr));
77 while (read_mchbar32 (0x1d0) & 0x800000);
78 val = read_mchbar32 (0x1d8);
79 write_1d0 (0, 0x33d, 0, 0);
80 write_1d0 (0, 0x33d, 0, 0);
81 return val & ((1 << split) - 1);
82}
83
84static void dump_timings (void)
85{
86 int channel, slot, rank, lane, i;
87 printf ("Timings:\n");
88 for (channel = 0; channel < 2; channel++)
89 for (slot = 0; slot < 2; slot++)
90 for (rank = 0; rank < 2; rank++) {
91 printf ("channel %d, slot %d, rank %d\n", channel, slot, rank);
92 for (lane = 0; lane < 9; lane++) {
93 printf ("lane %d: ", lane);
94 for (i = 0; i < 4; i++) {
95 printf ("%x ", read_500 (channel,
96 get_timing_register_addr (lane, i, slot, rank), 9));
97 }
98 printf ("\n");
99 }
100 }
101
102 printf ("[178] = %x\n", read_1d0 (0x178, 7));
103 printf ("[10b] = %x\n", read_1d0 (0x10b, 6));
104}
105
106
Stefan Reinauer23190272008-08-20 13:41:24 +0000107/*
108 * (G)MCH MMIO Config Space
109 */
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200110int print_mchbar(struct pci_dev *nb, struct pci_access *pacc, const char *dump_spd_file)
Stefan Reinauer23190272008-08-20 13:41:24 +0000111{
112 int i, size = (16 * 1024);
Idwer Vollering312fc962010-12-17 22:34:58 +0000113 uint64_t mchbar_phys;
114 struct pci_dev *nb_device6; /* "overflow device" on i865 */
115 uint16_t pcicmd6;
Stefan Reinauer23190272008-08-20 13:41:24 +0000116
117 printf("\n============= MCHBAR ============\n\n");
118
119 switch (nb->device_id) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000120 case PCI_DEVICE_ID_INTEL_82865:
121 /*
122 * On i865, the memory access enable/disable bit (MCHBAREN on
123 * i945/i965) is not in the MCHBAR (i945/i965) register but in
124 * the PCICMD6 register. BAR6 and PCICMD6 reside on device 6.
125 *
126 * The actual base address is in BAR6 on i865 where on
127 * i945/i965 the base address is in MCHBAR.
128 */
129 nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0); /* Device 6 */
130 mchbar_phys = pci_read_long(nb_device6, 0x10); /* BAR6 */
131 pcicmd6 = pci_read_long(nb_device6, 0x04); /* PCICMD6 */
132
133 /* Try to enable Memory Access Enable (MAE). */
134 if (!(pcicmd6 & (1 << 1))) {
135 printf("Access to BAR6 is currently disabled, "
136 "attempting to enable.\n");
137 pci_write_long(nb_device6, 0x04, pcicmd6 | (1 << 1));
138 if (pci_read_long(nb_device6, 0x04) & (1 << 1))
139 printf("Enabled successfully.\n");
140 else
141 printf("Enable FAILED!\n");
142 }
143 mchbar_phys &= 0xfffff000; /* Bits 31:12 from BAR6 */
144 break;
Pat Erleyca3548e2010-04-21 06:23:19 +0000145 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000146 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000147 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000148 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Tauner04c06002012-10-13 02:19:30 +0200149 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000150 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
151 break;
Stefan Tauner04c06002012-10-13 02:19:30 +0200152 case PCI_DEVICE_ID_INTEL_82965PM:
153 case PCI_DEVICE_ID_INTEL_82Q35:
154 case PCI_DEVICE_ID_INTEL_82G33:
155 case PCI_DEVICE_ID_INTEL_82Q33:
156 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
157 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
158 break;
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200159 case PCI_DEVICE_ID_INTEL_82946:
Stefan Tauner04c06002012-10-13 02:19:30 +0200160 case PCI_DEVICE_ID_INTEL_82Q965:
Corey Osgood23d98c72010-07-29 19:25:31 +0000161 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
162 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Stefan Tauner04c06002012-10-13 02:19:30 +0200163 mchbar_phys = pci_read_long(nb, 0x48);
Corey Osgood23d98c72010-07-29 19:25:31 +0000164
165 /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads.
Idwer Vollering312fc962010-12-17 22:34:58 +0000166 * If it isn't, try to set it. This may fail, because there is
167 * some bit that locks that bit, and isn't in the public
Corey Osgood23d98c72010-07-29 19:25:31 +0000168 * datasheets.
169 */
170
171 if(!(mchbar_phys & 1))
172 {
Stefan Tauner04c06002012-10-13 02:19:30 +0200173 printf("Access to the MCHBAR is currently disabled, "
174 "attempting to enable.\n");
Corey Osgood23d98c72010-07-29 19:25:31 +0000175 mchbar_phys |= 0x1;
176 pci_write_long(nb, 0x48, mchbar_phys);
Stefan Tauner04c06002012-10-13 02:19:30 +0200177 if(pci_read_long(nb, 0x48) & 1)
Corey Osgood23d98c72010-07-29 19:25:31 +0000178 printf("Enabled successfully.\n");
179 else
180 printf("Enable FAILED!\n");
181 }
182 mchbar_phys &= 0xfffffffe;
Stefan Tauner04c06002012-10-13 02:19:30 +0200183 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
184 break;
Maciej Pijanka90d17402009-09-30 17:05:46 +0000185 case PCI_DEVICE_ID_INTEL_82443LX:
186 case PCI_DEVICE_ID_INTEL_82443BX:
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000187 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200188 case PCI_DEVICE_ID_INTEL_82810E_DC:
189 case PCI_DEVICE_ID_INTEL_82810_DC:
Stefan Reinauer04844812010-02-22 11:26:06 +0000190 case PCI_DEVICE_ID_INTEL_82830M:
Idwer Vollering312fc962010-12-17 22:34:58 +0000191 printf("This northbridge does not have MCHBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000192 return 1;
Damien Zammit9c986642015-08-17 21:04:41 +1000193 case PCI_DEVICE_ID_INTEL_82XX4X:
194 case PCI_DEVICE_ID_INTEL_82Q45:
195 case PCI_DEVICE_ID_INTEL_82G45:
196 case PCI_DEVICE_ID_INTEL_82G41:
197 case PCI_DEVICE_ID_INTEL_82B43:
198 case PCI_DEVICE_ID_INTEL_82B43_2:
Stefan Tauner04c06002012-10-13 02:19:30 +0200199 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200200 case PCI_DEVICE_ID_INTEL_32X0:
Anton Kochkovda0b4562010-05-30 12:33:12 +0000201 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
202 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
Stefan Tauner04c06002012-10-13 02:19:30 +0200203 break;
204 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
205 mchbar_phys = pci_read_long(nb, 0x48);
206 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
207 mchbar_phys &= 0x0000000fffffc000UL; /* 35:14 */
Stefan Tauner04c06002012-10-13 02:19:30 +0200208 break;
Felix Held0cc8f292014-11-05 03:18:44 +0100209 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D:
210 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M:
Felix Heldfac95e32014-11-09 00:11:28 +0100211 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3:
Damien Zammit601da482014-05-26 23:00:23 +1000212 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D:
Felix Heldfac95e32014-11-09 00:11:28 +0100213 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M:
214 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3:
215 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c:
216 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_D:
217 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_M:
218 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_E3:
Dennis Wassenbergae6685f2014-10-30 10:30:40 +0100219 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_U:
Matt DeVillier5b667df2015-05-14 21:58:33 -0500220 case PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_U:
Nico Huber54fe32f2017-10-03 16:03:07 +0200221 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D2:
Nico Huber21e74242017-04-24 15:06:09 +0200222 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_WST:
Christoph Pomaska48ac29e2018-01-01 01:48:21 +0100223 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D:
Maxim Polyakov13176892019-08-27 18:20:08 +0300224 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_E:
Maximilian Schanderae848f82017-11-05 06:46:44 +0100225 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_M:
Matthew Garrett2bf28e52018-07-23 21:09:47 -0700226 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U:
227 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_Y:
228 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U_Q:
Christian Walter9a8c5e72019-05-06 17:50:57 +0200229 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_E3:
Matt DeVillier3c784452019-06-11 23:23:46 -0500230 case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_1:
231 case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_2:
Stefan Tauner04c06002012-10-13 02:19:30 +0200232 mchbar_phys = pci_read_long(nb, 0x48);
233 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
234 mchbar_phys &= 0x0000007fffff8000UL; /* 38:15 */
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200235 size = 32768;
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400236 break;
Johanna Schander4ddbbd82020-01-06 08:52:49 +0100237 case PCI_DEVICE_ID_INTEL_CORE_10TH_GEN_U:
238 mchbar_phys = pci_read_long(nb, 0x48);
239 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
240 mchbar_phys &= 0x0000007fffff0000UL; /* 38:16 */
241 size = 32768;
242 break;
Stefan Reinauer23190272008-08-20 13:41:24 +0000243 default:
244 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
245 return 1;
246 }
247
Stefan Reinauer1162f252008-12-04 15:18:20 +0000248 mchbar = map_physical(mchbar_phys, size);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000249
Stefan Reinauer1162f252008-12-04 15:18:20 +0000250 if (mchbar == NULL) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000251 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
252 perror("Error mapping BAR6");
253 else
254 perror("Error mapping MCHBAR");
Stefan Reinauer23190272008-08-20 13:41:24 +0000255 exit(1);
256 }
257
Idwer Vollering312fc962010-12-17 22:34:58 +0000258 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800259 printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Idwer Vollering312fc962010-12-17 22:34:58 +0000260 else
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800261 printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000262
Vladimir Serbinenko9c4f1b82014-11-04 21:05:12 +0100263 for (i = 0; i < size; i += 4) {
Michael Niewöhner10d52212020-03-13 19:08:21 +0100264 if (read32(mchbar + i))
265 printf("0x%04x: 0x%08"PRIx32"\n", i, read32(mchbar+i));
Stefan Reinauer23190272008-08-20 13:41:24 +0000266 }
267
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200268 switch (nb->device_id)
269 {
270 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +0200271 printf ("clock_speed_index = %x\n", read_500 (0,0x609, 6) >> 1);
272 dump_timings ();
Stefan Tauner572f0742016-05-05 17:29:39 +0200273 if (dump_spd_file != NULL)
274 printf("\nCreating a memory timings file is not supported on this chipset.\n");
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200275 break;
Felix Held0cc8f292014-11-05 03:18:44 +0100276 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D:
277 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M:
Felix Heldfac95e32014-11-09 00:11:28 +0100278 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3:
279 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D:
280 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M:
281 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3:
282 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c:
Vladimir Serbinenkofb69a692015-10-10 13:20:32 +0200283 ivybridge_dump_timings(dump_spd_file);
Vladimir Serbinenko44bc11c2014-08-16 19:14:02 +0200284 break;
Stefan Tauner572f0742016-05-05 17:29:39 +0200285 default:
286 if (dump_spd_file != NULL)
287 printf("\nCreating a memory timings file is not supported on this chipset.\n");
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +0200288 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000289 unmap_physical((void *)mchbar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000290 return 0;
291}