split the one file, as the several printing functions will continue to grow
[coreboot.git] / util / inteltool / memory.c
1 /*
2  * inteltool - dump all registers on an Intel CPU + chipset based system.
3  *
4  * Copyright (C) 2008 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 <sys/mman.h>
24
25 #include "inteltool.h"
26
27 /*
28  * (G)MCH MMIO Config Space
29  */
30 int print_mchbar(struct pci_dev *nb)
31 {
32         int i, size = (16 * 1024);
33         volatile uint8_t *mchbar;
34         uint32_t mchbar_phys;
35
36         printf("\n============= MCHBAR ============\n\n");
37
38         switch (nb->device_id) {
39         case PCI_DEVICE_ID_INTEL_82945GM:
40                 mchbar_phys = pci_read_long(nb, 0x44) & 0xfffffffe;
41                 break;
42         case 0x1234: // Dummy for non-existent functionality
43                 printf("This northbrigde does not have MCHBAR.\n");
44                 return 1;
45         default:
46                 printf("Error: Dumping MCHBAR on this northbridge is not (yet) supported.\n");
47                 return 1;
48         }
49
50         mchbar = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
51                       fd_mem, (off_t) mchbar_phys);
52         
53         if (mchbar == MAP_FAILED) {
54                 perror("Error mapping MCHBAR");
55                 exit(1);
56         }
57
58         printf("MCHBAR = 0x%08x (MEM)\n\n", mchbar_phys);
59
60         for (i = 0; i < size; i += 4) {
61                 if (*(uint32_t *)(mchbar + i))
62                         printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(mchbar+i));
63         }
64
65         munmap((void *)mchbar, size);
66         return 0;
67 }
68
69