| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include <inttypes.h> |
| 8 |
#include "inteltool.h" |
| 9 |
|
| 10 |
volatile uint8_t *mchbar; |
| 11 |
|
| 12 |
static void write_mchbar32 (uint32_t addr, uint32_t val) |
| 13 |
{ |
| 14 |
* (volatile uint32_t *) (mchbar + addr) = val; |
| 15 |
} |
| 16 |
|
| 17 |
static uint32_t read_mchbar32 (uint32_t addr) |
| 18 |
{ |
| 19 |
return * (volatile uint32_t *) (mchbar + addr); |
| 20 |
} |
| 21 |
|
| 22 |
static uint8_t read_mchbar8 (uint32_t addr) |
| 23 |
{ |
| 24 |
return * (volatile uint8_t *) (mchbar + addr); |
| 25 |
} |
| 26 |
|
| 27 |
static u16 read_500 (int channel, u16 addr, int split) |
| 28 |
{ |
| 29 |
uint32_t val; |
| 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)); |
| 35 |
|
| 36 |
return val & ((1 << split) - 1); |
| 37 |
} |
| 38 |
|
| 39 |
static inline u16 get_lane_offset (int slot, int rank, int lane) |
| 40 |
{ |
| 41 |
return 0x124 * lane + ((lane & 4) ? 0x23e : 0) + 11 * rank + 22 * slot - 0x452 * (lane == 8); |
| 42 |
} |
| 43 |
|
| 44 |
static inline u16 get_timing_register_addr (int lane, int tm, int slot, int rank) |
| 45 |
{ |
| 46 |
const u16 offs[] = { 0x1d, 0xa8, 0xe6, 0x5c }; |
| 47 |
return get_lane_offset (slot, rank, lane) + offs[(tm + 3) % 4]; |
| 48 |
} |
| 49 |
|
| 50 |
static void write_1d0 (u32 val, u16 addr, int bits, int flag) |
| 51 |
{ |
| 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); |
| 57 |
} |
| 58 |
|
| 59 |
static u16 read_1d0 (u16 addr, int split) |
| 60 |
{ |
| 61 |
u32 val; |
| 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); |
| 70 |
} |
| 71 |
|
| 72 |
static void dump_timings (void) |
| 73 |
{ |
| 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)); |
| 85 |
} |
| 86 |
printf ("\n"); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
printf ("[178] = %x\n", read_1d0 (0x178, 7)); |
| 91 |
printf ("[10b] = %x\n", read_1d0 (0x10b, 6)); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
int print_mchbar(struct pci_dev *nb, struct pci_access *pacc, const char *dump_spd_file) |
| 99 |
{ |
| 100 |
int i, size = (16 * 1024); |
| 101 |
uint64_t mchbar_phys; |
| 102 |
struct pci_dev *nb_device6; |
| 103 |
uint16_t pcicmd6; |
| 104 |
|
| 105 |
printf("\n============= MCHBAR ============\n\n"); |
| 106 |
|
| 107 |
switch (nb->device_id) { |
| 108 |
case PCI_DEVICE_ID_INTEL_82865: |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0); |
| 118 |
mchbar_phys = pci_read_long(nb_device6, 0x10); |
| 119 |
pcicmd6 = pci_read_long(nb_device6, 0x04); |
| 120 |
|
| 121 |
|
| 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"); |
| 128 |
else |
| 129 |
printf("Enable FAILED!\n"); |
| 130 |
} |
| 131 |
mchbar_phys &= 0xfffff000; |
| 132 |
break; |
| 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; |
| 139 |
break; |
| 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; |
| 146 |
break; |
| 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 |
case PCI_DEVICE_ID_INTEL_CORE_ADL_ID_N_0_8: |
| 152 |
case PCI_DEVICE_ID_INTEL_CORE_ADL_ID_N_0_4: |
| 153 |
case PCI_DEVICE_ID_INTEL_CORE_ADL_ID_N_0_4_1: |
| 154 |
mchbar_phys = pci_read_long(nb, 0x48); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
if(!(mchbar_phys & 1)) |
| 163 |
{ |
| 164 |
printf("Access to the MCHBAR is currently disabled, " |
| 165 |
"attempting to enable.\n"); |
| 166 |
mchbar_phys |= 0x1; |
| 167 |
pci_write_long(nb, 0x48, mchbar_phys); |
| 168 |
if(pci_read_long(nb, 0x48) & 1) |
| 169 |
printf("Enabled successfully.\n"); |
| 170 |
else |
| 171 |
printf("Enable FAILED!\n"); |
| 172 |
} |
| 173 |
mchbar_phys &= 0xfffffffe; |
| 174 |
mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 175 |
break; |
| 176 |
case PCI_DEVICE_ID_INTEL_82443LX: |
| 177 |
case PCI_DEVICE_ID_INTEL_82443BX: |
| 178 |
case PCI_DEVICE_ID_INTEL_82810: |
| 179 |
case PCI_DEVICE_ID_INTEL_82810E_DC: |
| 180 |
case PCI_DEVICE_ID_INTEL_82810_DC: |
| 181 |
case PCI_DEVICE_ID_INTEL_82830M: |
| 182 |
printf("This northbridge does not have MCHBAR.\n"); |
| 183 |
return 1; |
| 184 |
case PCI_DEVICE_ID_INTEL_82XX4X: |
| 185 |
case PCI_DEVICE_ID_INTEL_82Q45: |
| 186 |
case PCI_DEVICE_ID_INTEL_82G45: |
| 187 |
case PCI_DEVICE_ID_INTEL_82G41: |
| 188 |
case PCI_DEVICE_ID_INTEL_82B43: |
| 189 |
case PCI_DEVICE_ID_INTEL_82B43_2: |
| 190 |
case PCI_DEVICE_ID_INTEL_82X38: |
| 191 |
case PCI_DEVICE_ID_INTEL_32X0: |
| 192 |
mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe; |
| 193 |
mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 194 |
break; |
| 195 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_D: |
| 196 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_M: |
| 197 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_0048: |
| 198 |
mchbar_phys = pci_read_long(nb, 0x48); |
| 199 |
mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 200 |
mchbar_phys &= 0x0000000fffffc000UL; |
| 201 |
break; |
| 202 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D: |
| 203 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M: |
| 204 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3: |
| 205 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D: |
| 206 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M: |
| 207 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3: |
| 208 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c: |
| 209 |
case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_D: |
| 210 |
case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_M: |
| 211 |
case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_E3: |
| 212 |
case PCI_DEVICE_ID_INTEL_CORE_4TH_GEN_U: |
| 213 |
case PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_U: |
| 214 |
case PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_D: |
| 215 |
case PCI_DEVICE_ID_INTEL_CORE_5TH_GEN_M: |
| 216 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D2: |
| 217 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_U: |
| 218 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_Y: |
| 219 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_M: |
| 220 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_WST: |
| 221 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_D: |
| 222 |
case PCI_DEVICE_ID_INTEL_CORE_6TH_GEN_E: |
| 223 |
case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U: |
| 224 |
case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_Y: |
| 225 |
case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_U_Q: |
| 226 |
case PCI_DEVICE_ID_INTEL_CORE_7TH_GEN_E3: |
| 227 |
case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_1: |
| 228 |
case PCI_DEVICE_ID_INTEL_CORE_8TH_GEN_U_2: |
| 229 |
case PCI_DEVICE_ID_INTEL_CORE_CML_U1: |
| 230 |
case PCI_DEVICE_ID_INTEL_CORE_CML_U2: |
| 231 |
case PCI_DEVICE_ID_INTEL_CORE_CML_U3: |
| 232 |
mchbar_phys = pci_read_long(nb, 0x48); |
| 233 |
mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 234 |
mchbar_phys &= 0x0000007fffff8000UL; |
| 235 |
size = 32768; |
| 236 |
break; |
| 237 |
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; |
| 241 |
size = 32768; |
| 242 |
break; |
| 243 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_1: |
| 244 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_2: |
| 245 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_3: |
| 246 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_4: |
| 247 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_5: |
| 248 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_6: |
| 249 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_7: |
| 250 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_8: |
| 251 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_9: |
| 252 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_10: |
| 253 |
case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_11: |
| 254 |
mchbar_phys = pci_read_long(nb, 0x48); |
| 255 |
mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32; |
| 256 |
mchbar_phys &= 0x0000007fffff0000UL; |
| 257 |
size = 65536; |
| 258 |
break; |
| 259 |
default: |
| 260 |
printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n"); |
| 261 |
printf("Error: Unknown PCI id: %04x/%04x\n", nb->vendor_id, nb->device_id); |
| 262 |
return 1; |
| 263 |
} |
| 264 |
|
| 265 |
mchbar = map_physical(mchbar_phys, size); |
| 266 |
|
| 267 |
if (mchbar == NULL) { |
| 268 |
if (nb->device_id == PCI_DEVICE_ID_INTEL_82865) |
| 269 |
perror("Error mapping BAR6"); |
| 270 |
else |
| 271 |
perror("Error mapping MCHBAR"); |
| 272 |
exit(1); |
| 273 |
} |
| 274 |
|
| 275 |
if (nb->device_id == PCI_DEVICE_ID_INTEL_82865) |
| 276 |
printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys); |
| 277 |
else |
| 278 |
printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys); |
| 279 |
|
| 280 |
for (i = 0; i < size; i += 4) { |
| 281 |
if (read32(mchbar + i)) |
| 282 |
printf("0x%04x: 0x%08"PRIx32"\n", i, read32(mchbar+i)); |
| 283 |
} |
| 284 |
|
| 285 |
switch (nb->device_id) |
| 286 |
{ |
| 287 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_D: |
| 288 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_M: |
| 289 |
case PCI_DEVICE_ID_INTEL_CORE_1ST_GEN_0048: |
| 290 |
printf ("clock_speed_index = %x\n", read_500 (0,0x609, 6) >> 1); |
| 291 |
dump_timings (); |
| 292 |
if (dump_spd_file != NULL) |
| 293 |
printf("\nCreating a memory timings file is not supported on this chipset.\n"); |
| 294 |
break; |
| 295 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_D: |
| 296 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_M: |
| 297 |
case PCI_DEVICE_ID_INTEL_CORE_2ND_GEN_E3: |
| 298 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_D: |
| 299 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_M: |
| 300 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_E3: |
| 301 |
case PCI_DEVICE_ID_INTEL_CORE_3RD_GEN_015c: |
| 302 |
ivybridge_dump_timings(dump_spd_file); |
| 303 |
break; |
| 304 |
default: |
| 305 |
if (dump_spd_file != NULL) |
| 306 |
printf("\nCreating a memory timings file is not supported on this chipset.\n"); |
| 307 |
} |
| 308 |
unmap_physical((void *)mchbar, size); |
| 309 |
return 0; |
| 310 |
} |