blob: be8b0cb3bde6f5e134709c4b7e14ef8c19cdc9bd [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
Anton Kochkovc7fc4422012-07-21 06:36:47 +040026static const io_register_t sandybridge_mch_registers[] = {
27/* Channel 0 */
28 { 0x4000, 4, "TC_DBP_C0" }, // Timing of DDR Bin Parameters
29 { 0x4004, 4, "TC_RAP_C0" }, // Timing of DDR Regular Access Parameters
30 { 0x4028, 4, "SC_IO_LATENCY_C0" }, // IO Latency Configuration
31 { 0x42A4, 4, "TC_SRFTP_C0" }, // Self-Refresh Timing Parameters
32 { 0x40B0, 4, "PM_PDWN_config_C0" }, // Power-down Configuration
33 { 0x4294, 4, "TC_RFP_C0" }, // Refresh Parameters
34 { 0x4298, 4, "TC_RFTP_C0" }, // Refresh Timing Parameters
35/* Channel 1 */
36 { 0x4400, 4, "TC_DBP_C1" }, // Timing of DDR Bin Parameters
37 { 0x4404, 4, "TC_RAP_C1" }, // Timing of DDR Regular Access Parameters
38 { 0x4428, 4, "SC_IO_LATENCY_C1" }, // IO Latency Configuration
39 { 0x46A4, 4, "TC_SRFTP_C1" }, // Self-Refresh Timing Parameters
40 { 0x44B0, 4, "PM_PDWN_config_C1" }, // Power-down Configuration
41 { 0x4694, 4, "TC_RFP_C1" }, // Refresh Parameters
42 { 0x4698, 4, "TC_RFTP_C1" }, // Refresh Timing Parameters
43/* Integrated Memory Peripheral Hub (IMPH) */
44 { 0x740C, 4, "CRDTCTL3" }, // Credit Control 3
45/* Common Registers */
46 { 0x5000, 4, "MAD_CHNL" }, // Address decoder Channel Configuration
47 { 0x5004, 4, "MAD_DIMM_ch0" }, // Address Decode Channel 0
48 { 0x5008, 4, "MAD_DIMM_ch1" }, // Address Decode Channel 1
49 { 0x5060, 4, "PM_SREF_config" }, // Self Refresh Configuration
50/* MMIO Registers Broadcast Group */
51 { 0x4CB0, 4, "PM_PDWN_config" }, // Power-down Configuration
52 { 0x4F84, 4, "PM_CMD_PWR" }, // Power Management Command Power
53 { 0x4F88, 4, "PM_BW_LIMIT_config" }, // BW Limit Configuration
54 { 0x4F8C, 4, "RESERVED" }, // Reserved, default value - 0xFF1D1519
55/* PCU MCHBAR Registers */
56 { 0x5880, 4, "MEM_TRML_ESTIMATION_CONFIG" }, // Memory Thermal Estimation Configuration
57 { 0x5884, 4, "RESERVED" }, // Reserved
58 { 0x5888, 4, "MEM_TRML_THRESHOLDS_CONFIG" }, // Memory Thermal Thresholds Configuration
59 { 0x58A0, 4, "MEM_TRML_STATUS_REPORT" }, // Memory Thermal Status Report
60 { 0x58A4, 4, "MEM_TRML_TEMPERATURE_REPORT" }, // Memory Thermal Temperature Report
61 { 0x58A8, 4, "MEM_TRML_INTERRUPT" }, // Memory Thermal Interrupt
62 { 0x5948, 4, "GT_PERF_STATUS" }, // GT Performance Status
63 { 0x5998, 4, "RP_STATE_CAP" }, // RP State Capability
64 { 0x5D10, 8, "SSKPD" }, // Sticky Scratchpad Data
65};
66
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +020067volatile uint8_t *mchbar;
68
69static void write_mchbar32 (uint32_t addr, uint32_t val)
70{
71 * (volatile uint32_t *) (mchbar + addr) = val;
72}
73
74static uint32_t read_mchbar32 (uint32_t addr)
75{
76 return * (volatile uint32_t *) (mchbar + addr);
77}
78
79static uint8_t read_mchbar8 (uint32_t addr)
80{
81 return * (volatile uint8_t *) (mchbar + addr);
82}
83
84static u16 read_500 (int channel, u16 addr, int split)
85{
86 uint32_t val;
87 write_mchbar32 (0x500 + (channel << 10), 0);
88 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
89 write_mchbar32 (0x500 + (channel << 10), 0x80000000 | (((read_mchbar8 (0x246 + (channel << 10)) >> 2) & 3) + 0xb88 - addr));
90 while (read_mchbar32 (0x500 + (channel << 10)) & 0x800000);
91 val = read_mchbar32 (0x508 + (channel << 10));
92
93 return val & ((1 << split) - 1);
94}
95
96static inline u16 get_lane_offset (int slot, int rank, int lane)
97{
98 return 0x124 * lane + ((lane & 4) ? 0x23e : 0) + 11 * rank + 22 * slot - 0x452 * (lane == 8);
99}
100
101static inline u16 get_timing_register_addr (int lane, int tm, int slot, int rank)
102{
103 const u16 offs[] = { 0x1d, 0xa8, 0xe6, 0x5c };
104 return get_lane_offset (slot, rank, lane) + offs[(tm + 3) % 4];
105}
106
107static void write_1d0 (u32 val, u16 addr, int bits, int flag)
108{
109 write_mchbar32 (0x1d0, 0);
110 while (read_mchbar32 (0x1d0) & 0x800000);
111 write_mchbar32 (0x1d4, (val & ((1 << bits) - 1)) | (2 << bits) | (flag << bits));
112 write_mchbar32 (0x1d0, 0x40000000 | addr);
113 while (read_mchbar32 (0x1d0) & 0x800000);
114}
115
116static u16 read_1d0 (u16 addr, int split)
117{
118 u32 val;
119 write_mchbar32 (0x1d0, 0);
120 while (read_mchbar32 (0x1d0) & 0x800000);
121 write_mchbar32 (0x1d0, 0x80000000 | (((read_mchbar8 (0x246) >> 2) & 3) + 0x361 - addr));
122 while (read_mchbar32 (0x1d0) & 0x800000);
123 val = read_mchbar32 (0x1d8);
124 write_1d0 (0, 0x33d, 0, 0);
125 write_1d0 (0, 0x33d, 0, 0);
126 return val & ((1 << split) - 1);
127}
128
129static void dump_timings (void)
130{
131 int channel, slot, rank, lane, i;
132 printf ("Timings:\n");
133 for (channel = 0; channel < 2; channel++)
134 for (slot = 0; slot < 2; slot++)
135 for (rank = 0; rank < 2; rank++) {
136 printf ("channel %d, slot %d, rank %d\n", channel, slot, rank);
137 for (lane = 0; lane < 9; lane++) {
138 printf ("lane %d: ", lane);
139 for (i = 0; i < 4; i++) {
140 printf ("%x ", read_500 (channel,
141 get_timing_register_addr (lane, i, slot, rank), 9));
142 }
143 printf ("\n");
144 }
145 }
146
147 printf ("[178] = %x\n", read_1d0 (0x178, 7));
148 printf ("[10b] = %x\n", read_1d0 (0x10b, 6));
149}
150
151
Stefan Reinauer23190272008-08-20 13:41:24 +0000152/*
153 * (G)MCH MMIO Config Space
154 */
Idwer Vollering312fc962010-12-17 22:34:58 +0000155int print_mchbar(struct pci_dev *nb, struct pci_access *pacc)
Stefan Reinauer23190272008-08-20 13:41:24 +0000156{
157 int i, size = (16 * 1024);
Idwer Vollering312fc962010-12-17 22:34:58 +0000158 uint64_t mchbar_phys;
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400159 const io_register_t *mch_registers = NULL;
Idwer Vollering312fc962010-12-17 22:34:58 +0000160 struct pci_dev *nb_device6; /* "overflow device" on i865 */
161 uint16_t pcicmd6;
Stefan Reinauer23190272008-08-20 13:41:24 +0000162
163 printf("\n============= MCHBAR ============\n\n");
164
165 switch (nb->device_id) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000166 case PCI_DEVICE_ID_INTEL_82865:
167 /*
168 * On i865, the memory access enable/disable bit (MCHBAREN on
169 * i945/i965) is not in the MCHBAR (i945/i965) register but in
170 * the PCICMD6 register. BAR6 and PCICMD6 reside on device 6.
171 *
172 * The actual base address is in BAR6 on i865 where on
173 * i945/i965 the base address is in MCHBAR.
174 */
175 nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0); /* Device 6 */
176 mchbar_phys = pci_read_long(nb_device6, 0x10); /* BAR6 */
177 pcicmd6 = pci_read_long(nb_device6, 0x04); /* PCICMD6 */
178
179 /* Try to enable Memory Access Enable (MAE). */
180 if (!(pcicmd6 & (1 << 1))) {
181 printf("Access to BAR6 is currently disabled, "
182 "attempting to enable.\n");
183 pci_write_long(nb_device6, 0x04, pcicmd6 | (1 << 1));
184 if (pci_read_long(nb_device6, 0x04) & (1 << 1))
185 printf("Enabled successfully.\n");
186 else
187 printf("Enable FAILED!\n");
188 }
189 mchbar_phys &= 0xfffff000; /* Bits 31:12 from BAR6 */
190 break;
Pat Erleyca3548e2010-04-21 06:23:19 +0000191 case PCI_DEVICE_ID_INTEL_82915:
Stefan Reinauer23190272008-08-20 13:41:24 +0000192 case PCI_DEVICE_ID_INTEL_82945GM:
Björn Busse2d33dc42010-08-01 15:33:30 +0000193 case PCI_DEVICE_ID_INTEL_82945GSE:
Stefan Reinauer3d9a12f2008-11-02 11:11:40 +0000194 case PCI_DEVICE_ID_INTEL_82945P:
Stefan Tauner04c06002012-10-13 02:19:30 +0200195 case PCI_DEVICE_ID_INTEL_82975X:
Stefan Reinauer23190272008-08-20 13:41:24 +0000196 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
197 break;
Stefan Tauner04c06002012-10-13 02:19:30 +0200198 case PCI_DEVICE_ID_INTEL_82965PM:
199 case PCI_DEVICE_ID_INTEL_82Q35:
200 case PCI_DEVICE_ID_INTEL_82G33:
201 case PCI_DEVICE_ID_INTEL_82Q33:
202 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
203 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
204 break;
Stefan Tauner1a00cf02012-10-13 06:23:52 +0200205 case PCI_DEVICE_ID_INTEL_82946:
Stefan Tauner04c06002012-10-13 02:19:30 +0200206 case PCI_DEVICE_ID_INTEL_82Q965:
Corey Osgood23d98c72010-07-29 19:25:31 +0000207 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
208 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
Stefan Tauner04c06002012-10-13 02:19:30 +0200209 mchbar_phys = pci_read_long(nb, 0x48);
Corey Osgood23d98c72010-07-29 19:25:31 +0000210
211 /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads.
Idwer Vollering312fc962010-12-17 22:34:58 +0000212 * If it isn't, try to set it. This may fail, because there is
213 * some bit that locks that bit, and isn't in the public
Corey Osgood23d98c72010-07-29 19:25:31 +0000214 * datasheets.
215 */
216
217 if(!(mchbar_phys & 1))
218 {
Stefan Tauner04c06002012-10-13 02:19:30 +0200219 printf("Access to the MCHBAR is currently disabled, "
220 "attempting to enable.\n");
Corey Osgood23d98c72010-07-29 19:25:31 +0000221 mchbar_phys |= 0x1;
222 pci_write_long(nb, 0x48, mchbar_phys);
Stefan Tauner04c06002012-10-13 02:19:30 +0200223 if(pci_read_long(nb, 0x48) & 1)
Corey Osgood23d98c72010-07-29 19:25:31 +0000224 printf("Enabled successfully.\n");
225 else
226 printf("Enable FAILED!\n");
227 }
228 mchbar_phys &= 0xfffffffe;
Stefan Tauner04c06002012-10-13 02:19:30 +0200229 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
230 break;
Maciej Pijanka90d17402009-09-30 17:05:46 +0000231 case PCI_DEVICE_ID_INTEL_82443LX:
232 case PCI_DEVICE_ID_INTEL_82443BX:
Stefan Reinauerb2aedb12009-08-29 15:45:43 +0000233 case PCI_DEVICE_ID_INTEL_82810:
Stefan Tauner04c06002012-10-13 02:19:30 +0200234 case PCI_DEVICE_ID_INTEL_82810E_DC:
235 case PCI_DEVICE_ID_INTEL_82810_DC:
Stefan Reinauer04844812010-02-22 11:26:06 +0000236 case PCI_DEVICE_ID_INTEL_82830M:
Idwer Vollering312fc962010-12-17 22:34:58 +0000237 printf("This northbridge does not have MCHBAR.\n");
Stefan Reinauer23190272008-08-20 13:41:24 +0000238 return 1;
Stefan Tauner04c06002012-10-13 02:19:30 +0200239 case PCI_DEVICE_ID_INTEL_82X4X:
240 case PCI_DEVICE_ID_INTEL_82X38:
Ruud Schrampbb41f502011-04-04 07:53:19 +0200241 case PCI_DEVICE_ID_INTEL_32X0:
Anton Kochkovda0b4562010-05-30 12:33:12 +0000242 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
243 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
Stefan Tauner04c06002012-10-13 02:19:30 +0200244 break;
245 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN:
246 mchbar_phys = pci_read_long(nb, 0x48);
247 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
248 mchbar_phys &= 0x0000000fffffc000UL; /* 35:14 */
249 mch_registers = NULL; /* No public documentation */
250 break;
251 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN:
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400252 mch_registers = sandybridge_mch_registers;
253 size = ARRAY_SIZE(sandybridge_mch_registers);
Stefan Tauner04c06002012-10-13 02:19:30 +0200254 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN: /* pretty printing not implemented yet */
255 mchbar_phys = pci_read_long(nb, 0x48);
256 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
257 mchbar_phys &= 0x0000007fffff8000UL; /* 38:15 */
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400258 break;
Stefan Reinauer23190272008-08-20 13:41:24 +0000259 default:
260 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
261 return 1;
262 }
263
Stefan Reinauer1162f252008-12-04 15:18:20 +0000264 mchbar = map_physical(mchbar_phys, size);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000265
Stefan Reinauer1162f252008-12-04 15:18:20 +0000266 if (mchbar == NULL) {
Idwer Vollering312fc962010-12-17 22:34:58 +0000267 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
268 perror("Error mapping BAR6");
269 else
270 perror("Error mapping MCHBAR");
Stefan Reinauer23190272008-08-20 13:41:24 +0000271 exit(1);
272 }
273
Idwer Vollering312fc962010-12-17 22:34:58 +0000274 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800275 printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Idwer Vollering312fc962010-12-17 22:34:58 +0000276 else
Stefan Reinauera7b296d2011-11-14 12:40:34 -0800277 printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
Stefan Reinauer23190272008-08-20 13:41:24 +0000278
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400279 if (mch_registers != NULL) {
Stefan Tauner04c06002012-10-13 02:19:30 +0200280 printf("%d registers:\n", size);
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400281 for (i = 0; i < size; i++) {
282 switch (mch_registers[i].size) {
283 case 8:
Stefan Tauner0dc775e2013-04-05 01:15:04 +0200284 printf("mchbase+0x%04x: 0x%016"PRIx64" (%s)\n",
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400285 mch_registers[i].addr,
286 *(uint64_t *)(mchbar+mch_registers[i].addr),
287 mch_registers[i].name);
288 break;
289 case 4:
Stefan Tauner0dc775e2013-04-05 01:15:04 +0200290 printf("mchbase+0x%04x: 0x%08"PRIx32" (%s)\n",
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400291 mch_registers[i].addr,
292 *(uint32_t *)(mchbar+mch_registers[i].addr),
293 mch_registers[i].name);
294 break;
295 case 2:
Stefan Tauner0dc775e2013-04-05 01:15:04 +0200296 printf("mchbase+0x%04x: 0x%04"PRIx16" (%s)\n",
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400297 mch_registers[i].addr,
298 *(uint16_t *)(mchbar+mch_registers[i].addr),
299 mch_registers[i].name);
300 break;
301 case 1:
Stefan Tauner0dc775e2013-04-05 01:15:04 +0200302 printf("mchbase+0x%04x: 0x%02"PRIx8" (%s)\n",
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400303 mch_registers[i].addr,
304 *(uint8_t *)(mchbar+mch_registers[i].addr),
305 mch_registers[i].name);
306 break;
307 }
308 }
309 } else {
310 for (i = 0; i < size; i += 4) {
311 if (*(uint32_t *)(mchbar + i))
Stefan Tauner0dc775e2013-04-05 01:15:04 +0200312 printf("0x%04x: 0x%08"PRIx32"\n", i, *(uint32_t *)(mchbar+i));
Anton Kochkovc7fc4422012-07-21 06:36:47 +0400313 }
Stefan Reinauer23190272008-08-20 13:41:24 +0000314 }
315
Vladimir Serbinenkoe4e8e092013-03-31 13:51:37 +0200316 if (nb->device_id == PCI_DEVICE_ID_INTEL_CORE_1ST_GEN) {
317 printf ("clock_speed_index = %x\n", read_500 (0,0x609, 6) >> 1);
318 dump_timings ();
319 }
Stefan Reinauer1162f252008-12-04 15:18:20 +0000320 unmap_physical((void *)mchbar, size);
Stefan Reinauer23190272008-08-20 13:41:24 +0000321 return 0;
322}
323
324