1 /* inteltool - dump all registers on an Intel CPU + chipset based system. */
2 /* SPDX-License-Identifier: GPL-2.0-only */
10 volatile uint8_t *mchbar
;
12 static void write_mchbar32 (uint32_t addr
, uint32_t val
)
14 * (volatile uint32_t *) (mchbar
+ addr
) = val
;
17 static uint32_t read_mchbar32 (uint32_t addr
)
19 return * (volatile uint32_t *) (mchbar
+ addr
);
22 static uint8_t read_mchbar8 (uint32_t addr
)
24 return * (volatile uint8_t *) (mchbar
+ addr
);
27 static u16
read_500 (int channel
, u16 addr
, int split
)
30 write_mchbar32 (0x500 + (channel
<< 10), 0);
31 while (read_mchbar32 (0x500 + (channel
<< 10)) & 0x800000);
32 write_mchbar32 (0x500 + (channel
<< 10), 0x80000000 | (((read_mchbar8 (0x246 + (channel
<< 10)) >> 2) & 3) + 0xb88 - addr
));
33 while (read_mchbar32 (0x500 + (channel
<< 10)) & 0x800000);
34 val
= read_mchbar32 (0x508 + (channel
<< 10));
36 return val
& ((1 << split
) - 1);
39 static inline u16
get_lane_offset (int slot
, int rank
, int lane
)
41 return 0x124 * lane
+ ((lane
& 4) ? 0x23e : 0) + 11 * rank
+ 22 * slot
- 0x452 * (lane
== 8);
44 static inline u16
get_timing_register_addr (int lane
, int tm
, int slot
, int rank
)
46 const u16 offs
[] = { 0x1d, 0xa8, 0xe6, 0x5c };
47 return get_lane_offset (slot
, rank
, lane
) + offs
[(tm
+ 3) % 4];
50 static void write_1d0 (u32 val
, u16 addr
, int bits
, int flag
)
52 write_mchbar32 (0x1d0, 0);
53 while (read_mchbar32 (0x1d0) & 0x800000);
54 write_mchbar32 (0x1d4, (val
& ((1 << bits
) - 1)) | (2 << bits
) | (flag
<< bits
));
55 write_mchbar32 (0x1d0, 0x40000000 | addr
);
56 while (read_mchbar32 (0x1d0) & 0x800000);
59 static u16
read_1d0 (u16 addr
, int split
)
62 write_mchbar32 (0x1d0, 0);
63 while (read_mchbar32 (0x1d0) & 0x800000);
64 write_mchbar32 (0x1d0, 0x80000000 | (((read_mchbar8 (0x246) >> 2) & 3) + 0x361 - addr
));
65 while (read_mchbar32 (0x1d0) & 0x800000);
66 val
= read_mchbar32 (0x1d8);
67 write_1d0 (0, 0x33d, 0, 0);
68 write_1d0 (0, 0x33d, 0, 0);
69 return val
& ((1 << split
) - 1);
72 static void dump_timings (void)
74 int channel
, slot
, rank
, lane
, i
;
75 printf ("Timings:\n");
76 for (channel
= 0; channel
< 2; channel
++)
77 for (slot
= 0; slot
< 2; slot
++)
78 for (rank
= 0; rank
< 2; rank
++) {
79 printf ("channel %d, slot %d, rank %d\n", channel
, slot
, rank
);
80 for (lane
= 0; lane
< 9; lane
++) {
81 printf ("lane %d: ", lane
);
82 for (i
= 0; i
< 4; i
++) {
83 printf ("%x ", read_500 (channel
,
84 get_timing_register_addr (lane
, i
, slot
, rank
), 9));
90 printf ("[178] = %x\n", read_1d0 (0x178, 7));
91 printf ("[10b] = %x\n", read_1d0 (0x10b, 6));
96 * (G)MCH MMIO Config Space
98 int print_mchbar(struct pci_dev
*nb
, struct pci_access
*pacc
, const char *dump_spd_file
)
100 int i
, size
= (16 * 1024);
101 uint64_t mchbar_phys
;
102 struct pci_dev
*nb_device6
; /* "overflow device" on i865 */
105 printf("\n============= MCHBAR ============\n\n");
107 switch (nb
->device_id
) {
108 case PCI_DEVICE_ID_INTEL_82865
:
110 * On i865, the memory access enable/disable bit (MCHBAREN on
111 * i945/i965) is not in the MCHBAR (i945/i965) register but in
112 * the PCICMD6 register. BAR6 and PCICMD6 reside on device 6.
114 * The actual base address is in BAR6 on i865 where on
115 * i945/i965 the base address is in MCHBAR.
117 nb_device6
= pci_get_dev(pacc
, 0, 0, 0x06, 0); /* Device 6 */
118 mchbar_phys
= pci_read_long(nb_device6
, 0x10); /* BAR6 */
119 pcicmd6
= pci_read_long(nb_device6
, 0x04); /* PCICMD6 */
121 /* Try to enable Memory Access Enable (MAE). */
122 if (!(pcicmd6
& (1 << 1))) {
123 printf("Access to BAR6 is currently disabled, "
124 "attempting to enable.\n");
125 pci_write_long(nb_device6
, 0x04, pcicmd6
| (1 << 1));
126 if (pci_read_long(nb_device6
, 0x04) & (1 << 1))
127 printf("Enabled successfully.\n");
129 printf("Enable FAILED!\n");
131 mchbar_phys
&= 0xfffff000; /* Bits 31:12 from BAR6 */
133 case PCI_DEVICE_ID_INTEL_82915
:
134 case PCI_DEVICE_ID_INTEL_82945GM
:
135 case PCI_DEVICE_ID_INTEL_82945GSE
:
136 case PCI_DEVICE_ID_INTEL_82945P
:
137 case PCI_DEVICE_ID_INTEL_82975X
:
138 mchbar_phys
= pci_read_long(nb
, 0x44) & 0xfffffffe;
140 case PCI_DEVICE_ID_INTEL_82965PM
:
141 case PCI_DEVICE_ID_INTEL_82Q35
:
142 case PCI_DEVICE_ID_INTEL_82G33
:
143 case PCI_DEVICE_ID_INTEL_82Q33
:
144 mchbar_phys
= pci_read_long(nb
, 0x48) & 0xfffffffe;
145 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
147 case PCI_DEVICE_ID_INTEL_82946
:
148 case PCI_DEVICE_ID_INTEL_82Q965
:
149 case PCI_DEVICE_ID_INTEL_ATOM_DXXX
:
150 case PCI_DEVICE_ID_INTEL_ATOM_NXXX
:
151 mchbar_phys
= pci_read_long(nb
, 0x48);
153 /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads.
154 * If it isn't, try to set it. This may fail, because there is
155 * some bit that locks that bit, and isn't in the public
159 if(!(mchbar_phys
& 1))
161 printf("Access to the MCHBAR is currently disabled, "
162 "attempting to enable.\n");
164 pci_write_long(nb
, 0x48, mchbar_phys
);
165 if(pci_read_long(nb
, 0x48) & 1)
166 printf("Enabled successfully.\n");
168 printf("Enable FAILED!\n");
170 mchbar_phys
&= 0xfffffffe;
171 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
173 case PCI_DEVICE_ID_INTEL_82443LX
:
174 case PCI_DEVICE_ID_INTEL_82443BX
:
175 case PCI_DEVICE_ID_INTEL_82810
:
176 case PCI_DEVICE_ID_INTEL_82810E_DC
:
177 case PCI_DEVICE_ID_INTEL_82810_DC
:
178 case PCI_DEVICE_ID_INTEL_82830M
:
179 printf("This northbridge does not have MCHBAR.\n");
181 case PCI_DEVICE_ID_INTEL_82XX4X
:
182 case PCI_DEVICE_ID_INTEL_82Q45
:
183 case PCI_DEVICE_ID_INTEL_82G45
:
184 case PCI_DEVICE_ID_INTEL_82G41
:
185 case PCI_DEVICE_ID_INTEL_82B43
:
186 case PCI_DEVICE_ID_INTEL_82B43_2
:
187 case PCI_DEVICE_ID_INTEL_82X38
:
188 case PCI_DEVICE_ID_INTEL_32X0
:
189 mchbar_phys
= pci_read_long(nb
, 0x48) & 0xfffffffe;
190 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
192 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN
:
193 mchbar_phys
= pci_read_long(nb
, 0x48);
194 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
195 mchbar_phys
&= 0x0000000fffffc000UL
; /* 35:14 */
197 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D
:
198 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M
:
199 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3
:
200 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D
:
201 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M
:
202 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3
:
203 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c
:
204 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_D
:
205 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_M
:
206 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_E3
:
207 case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_U
:
208 case PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_U
:
209 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D2
:
210 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_U
:
211 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_Y
:
212 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_M
:
213 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_WST
:
214 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D
:
215 case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_E
:
216 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U
:
217 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_Y
:
218 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U_Q
:
219 case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_E3
:
220 case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_1
:
221 case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_2
:
222 mchbar_phys
= pci_read_long(nb
, 0x48);
223 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
224 mchbar_phys
&= 0x0000007fffff8000UL
; /* 38:15 */
227 case PCI_DEVICE_ID_INTEL_CORE_10TH_GEN_U
:
228 mchbar_phys
= pci_read_long(nb
, 0x48);
229 mchbar_phys
|= ((uint64_t)pci_read_long(nb
, 0x4c)) << 32;
230 mchbar_phys
&= 0x0000007fffff0000UL
; /* 38:16 */
234 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
238 mchbar
= map_physical(mchbar_phys
, size
);
240 if (mchbar
== NULL
) {
241 if (nb
->device_id
== PCI_DEVICE_ID_INTEL_82865
)
242 perror("Error mapping BAR6");
244 perror("Error mapping MCHBAR");
248 if (nb
->device_id
== PCI_DEVICE_ID_INTEL_82865
)
249 printf("BAR6 = 0x%08" PRIx64
" (MEM)\n\n", mchbar_phys
);
251 printf("MCHBAR = 0x%08" PRIx64
" (MEM)\n\n", mchbar_phys
);
253 for (i
= 0; i
< size
; i
+= 4) {
254 if (read32(mchbar
+ i
))
255 printf("0x%04x: 0x%08"PRIx32
"\n", i
, read32(mchbar
+i
));
258 switch (nb
->device_id
)
260 case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN
:
261 printf ("clock_speed_index = %x\n", read_500 (0,0x609, 6) >> 1);
263 if (dump_spd_file
!= NULL
)
264 printf("\nCreating a memory timings file is not supported on this chipset.\n");
266 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D
:
267 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M
:
268 case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3
:
269 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D
:
270 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M
:
271 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3
:
272 case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c
:
273 ivybridge_dump_timings(dump_spd_file
);
276 if (dump_spd_file
!= NULL
)
277 printf("\nCreating a memory timings file is not supported on this chipset.\n");
279 unmap_physical((void *)mchbar
, size
);