add i945GSE to inteltool
[coreboot.git] / util / inteltool / memory.c
1 /*
2  * inteltool - dump all registers on an Intel CPU + chipset based system.
3  *
4  * Copyright (C) 2008-2010 by coresystems GmbH
5  *
6  * 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>
23 #include "inteltool.h"
24
25 /*
26  * (G)MCH MMIO Config Space
27  */
28 int print_mchbar(struct pci_dev *nb)
29 {
30         int i, size = (16 * 1024);
31         volatile uint8_t *mchbar;
32         uint64_t mchbar_phys;
33
34         printf("\n============= MCHBAR ============\n\n");
35
36         switch (nb->device_id) {
37         case PCI_DEVICE_ID_INTEL_82915:
38         case PCI_DEVICE_ID_INTEL_82945GM:
39         case PCI_DEVICE_ID_INTEL_82945GSE:
40         case PCI_DEVICE_ID_INTEL_82945P:
41         case PCI_DEVICE_ID_INTEL_82975X:
42                 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
43                 break;
44         case PCI_DEVICE_ID_INTEL_PM965:
45         case PCI_DEVICE_ID_INTEL_82Q35:
46         case PCI_DEVICE_ID_INTEL_82G33:
47         case PCI_DEVICE_ID_INTEL_82Q33:
48                 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
49                 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
50                 break;
51         case PCI_DEVICE_ID_INTEL_Q965:
52         case PCI_DEVICE_ID_INTEL_ATOM_DXXX:
53         case PCI_DEVICE_ID_INTEL_ATOM_NXXX:
54                 mchbar_phys = pci_read_long(nb, 0x48);
55
56                 /* Test if bit 0 of the MCHBAR reg is 1 to enable memory reads.
57                  * If it isn't, try to set it. This may fail, because there is 
58                  * some bit that locks that bit, and isn't in the public 
59                  * datasheets.
60                  */
61
62                 if(!(mchbar_phys & 1))
63                 {
64                         printf("Access to the MCHBAR is currently disabled, "\
65                                                 "attempting to enable.\n");
66                         mchbar_phys |= 0x1;
67                         pci_write_long(nb, 0x48, mchbar_phys);
68                         if(pci_read_long(nb, 0x48) & 1)
69                                 printf("Enabled successfully.\n");
70                         else
71                                 printf("Enable FAILED!\n");
72                 }
73                 mchbar_phys &= 0xfffffffe;
74                 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
75                 break;
76         case PCI_DEVICE_ID_INTEL_82443LX:
77         case PCI_DEVICE_ID_INTEL_82443BX:
78         case PCI_DEVICE_ID_INTEL_82810:
79         case PCI_DEVICE_ID_INTEL_82810E_MC:
80         case PCI_DEVICE_ID_INTEL_82810DC:
81         case PCI_DEVICE_ID_INTEL_82830M:
82                 printf("This northbrigde does not have MCHBAR.\n");
83                 return 1;
84         case PCI_DEVICE_ID_INTEL_GS45:
85                 mchbar_phys = pci_read_long(nb, 0x48) & 0xfffffffe;
86                 mchbar_phys |= ((uint64_t)pci_read_long(nb, 0x4c)) << 32;
87                 break;
88         default:
89                 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
90                 return 1;
91         }
92
93         mchbar = map_physical(mchbar_phys, size);
94
95         if (mchbar == NULL) {
96                 perror("Error mapping MCHBAR");
97                 exit(1);
98         }
99
100         printf("MCHBAR = 0x%08llx (MEM)\n\n", mchbar_phys);
101
102         for (i = 0; i < size; i += 4) {
103                 if (*(uint32_t *)(mchbar + i))
104                         printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(mchbar+i));
105         }
106
107         unmap_physical((void *)mchbar, size);
108         return 0;
109 }
110
111