1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <stdio.h>
22#include <stdlib.h>
23#include "inteltool.h"
24
25
26
27
28int print_mchbar(struct pci_dev *nb, struct pci_access *pacc)
29{
30 int i, size = (16 * 1024);
31 volatile uint8_t *mchbar;
32 uint64_t mchbar_phys;
33 struct pci_dev *nb_device6;
34 uint16_t pcicmd6;
35
36 printf("\n============= MCHBAR ============\n\n");
37
38 switch (nb->device_id) {
39 case PCI_DEVICE_ID_INTEL_82865:
40
41
42
43
44
45
46
47
48 nb_device6 = pci_get_dev(pacc, 0, 0, 0x06, 0);
49 mchbar_phys = pci_read_long(nb_device6, 0x10);
50 pcicmd6 = pci_read_long(nb_device6, 0x04);
51
52
53 if (!(pcicmd6 & (1 << 1))) {
54 printf("Access to BAR6 is currently disabled, "
55 "attempting to enable.\n");
56 pci_write_long(nb_device6, 0x04, pcicmd6 | (1 << 1));
57 if (pci_read_long(nb_device6, 0x04) & (1 << 1))
58 printf("Enabled successfully.\n");
59 else
60 printf("Enable FAILED!\n");
61 }
62 mchbar_phys &= 0xfffff000;
63 break;
64 case PCI_DEVICE_ID_INTEL_82915:
65 case PCI_DEVICE_ID_INTEL_82945GM:
66 case PCI_DEVICE_ID_INTEL_82945GSE:
67 case PCI_DEVICE_ID_INTEL_82945P:
68 case PCI_DEVICE_ID_INTEL_82975X:
69 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
70 break;
71 case PCI_DEVICE_ID_INTEL_PM965:
72 case PCI_DEVICE_ID_INTEL_82Q35:
73 case PCI_DEVICE_ID_INTEL_82G33:
74 case PCI_DEVICE_ID_INTEL_82Q33:
75 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
76 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
77 break;
78 case PCI_DEVICE_ID_INTEL_Q965:
79 case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
80 case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
81 mchbar_phys = pci_read_long(nb, 0x48);
82
83
84
85
86
87
88
89 if(!(mchbar_phys & 1))
90 {
91 printf("Access to the MCHBAR is currently disabled, "\
92 "attempting to enable.\n");
93 mchbar_phys |= 0x1;
94 pci_write_long(nb, 0x48, mchbar_phys);
95 if(pci_read_long(nb, 0x48) & 1)
96 printf("Enabled successfully.\n");
97 else
98 printf("Enable FAILED!\n");
99 }
100 mchbar_phys &= 0xfffffffe;
101 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
102 break;
103 case PCI_DEVICE_ID_INTEL_82443LX:
104 case PCI_DEVICE_ID_INTEL_82443BX:
105 case PCI_DEVICE_ID_INTEL_82810:
106 case PCI_DEVICE_ID_INTEL_82810E_MC:
107 case PCI_DEVICE_ID_INTEL_82810DC:
108 case PCI_DEVICE_ID_INTEL_82830M:
109 printf("This northbridge does not have MCHBAR.\n");
110 return 1;
111 case PCI_DEVICE_ID_INTEL_GS45:
112 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
113 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
114 break;
115 default:
116 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
117 return 1;
118 }
119
120 mchbar = map_physical(mchbar_phys, size);
121
122 if (mchbar == NULL) {
123 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
124 perror("Error mapping BAR6");
125 else
126 perror("Error mapping MCHBAR");
127 exit(1);
128 }
129
130 if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
131 printf("BAR6 = 0x%08llx (MEM)\n\n", mchbar_phys);
132 else
133 printf("MCHBAR = 0x%08llx (MEM)\n\n", mchbar_phys);
134
135 for (i = 0; i < size; i += 4) {
136 if (*(uint32_t *)(mchbar + i))
137 printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(mchbar+i));
138 }
139
140 unmap_physical((void *)mchbar, size);
141 return 0;
142}
143
144
145