correctly mark code segments as code in SELF
[coreboot.git] / util / k8resdump / k8resdump.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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 v2 as published by
8  * the Free Software Foundation.
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /* This program will dump the IO/memory/PCI resources from the K8
21  * memory controller
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <pci/pci.h>
30
31 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
32
33 static uint8_t dram_bases[] =
34     { 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78 };
35 static uint8_t dram_limits[] =
36     { 0x44, 0x4C, 0x54, 0x5C, 0x64, 0x6C, 0x74, 0x7C };
37 static uint8_t iomem_bases[] =
38     { 0x80, 0x88, 0x90, 0x98, 0xA0, 0xA8, 0xB0, 0xB8 };
39 static uint8_t iomem_limits[] =
40     { 0x84, 0x8C, 0x94, 0x9C, 0xA4, 0xAC, 0xB4, 0xBC };
41
42 static uint8_t pciio_bases[] = { 0xC0, 0xC8, 0xD0, 0xD8 };
43 static uint8_t pciio_limits[] = { 0xC4, 0xCC, 0xD4, 0xDC };
44
45 void print_info(struct pci_dev *dev)
46 {
47         int i;
48         uint32_t regb, regl;
49
50         for (i = 0; i < ARRAY_SIZE(dram_bases); i++) {
51                 regb = pci_read_long(dev, dram_bases[i]);
52                 regl = pci_read_long(dev, dram_limits[i]);
53
54                 printf
55                     ("DRAM map: #%d 0x%04x000000 - 0x%04xffffff Access: %s/%s"
56                      "  IntlvEN:0x%x IntlvSEL:0x%x Dstnode:%d\n",
57                      i, regb >> 16, regl >> 16, regb & 1 ? "R" : "",
58                      regb & 2 ? "W" : "", (regb & 0x700) >> 8,
59                      (regl & 0x700) >> 8, (regl & 0x7));
60         }
61
62
63         for (i = 0; i < ARRAY_SIZE(iomem_bases); i++) {
64                 regb = pci_read_long(dev, iomem_bases[i]);
65                 regl = pci_read_long(dev, iomem_limits[i]);
66
67                 printf
68                     ("MMIO map: #%d 0x%06x0000 - 0x%06xffff Access: %s/%s  %s %s"
69                      " %s Dstnode:%d DstLink %d\n",
70                      i, regb >> 8, regl >> 8, regb & 1 ? "R" : "",
71                      regb & 2 ? "W" : "", regb & 4 ? "CPU Dis" : "",
72                      regb & 8 ? "Locked" : "",
73                      regl & 0x80 ? "NonPosted" : "", regl & 0x7,
74                      (regl & 0x30) >> 4);
75         }
76
77         for (i = 0; i < ARRAY_SIZE(pciio_bases); i++) {
78                 regb = pci_read_long(dev, pciio_bases[i]);
79                 regl = pci_read_long(dev, pciio_limits[i]);
80
81                 printf
82                     ("  IO map: #%d  0x%03x000 - 0x%03xfff Access: %s/%s  %s %s"
83                      " Dstnode:%d DstLink %d\n",
84                      i, (regb & ~0xff000000) >> 12,
85                      (regl & ~0xff000000) >> 12, regb & 1 ? "R" : "",
86                      regb & 2 ? "W" : "", regb & 0x20 ? "ISA" : "",
87                      regb & 0x10 ? "VGA" : "", regl & 0x7,
88                      (regl & 0x30) >> 4);
89         }
90
91
92 }
93
94 int main(void)
95 {
96         struct pci_access *pacc;
97         struct pci_dev *dev;
98
99         if (getuid()) {
100                 fprintf(stderr, "Please run me root, need access to all"
101                         " PCI regs!\n");
102                 exit(1);
103         }
104
105         pacc = pci_alloc();
106         pci_init(pacc);
107         pci_scan_bus(pacc);
108         for (dev = pacc->devices; dev; dev = dev->next) {
109                 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES |
110                               PCI_FILL_CLASS);
111                 if ((dev->vendor_id == 0x1022) /* AMD */
112                     && (dev->device_id == 0x1101)) { /* Address MAP */
113                         print_info(dev);
114                 }
115         }
116         pci_cleanup(pacc);
117         return 0;
118 }