2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Vincent Legoll <vincent.legoll@gmail.com>
5 * Copyright (C) 2008 Ronald G. Minnich <rminnich@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 * K8 northbridge utilities (dump routing registers).
19 * Designed to be called at any time.
20 * It can be called before RAM is set up by including this file.
21 * It can be called after RAM is set up by including amdk8.h and enabling the
22 * compilation of this file in src/northbridge/amd/amdk8/Makefile.inc.
25 #include <console/console.h>
26 #include <device/pci.h>
27 #include <device/pci_ops.h>
32 /* the DRAM, MMIO,and PCIIO routing are 64-bit registers, hence the ending at
33 * 0x78, 0xb8, and 0xd8
35 #define DRAM_ROUTE_START 0x40
36 #define DRAM_ROUTE_END 0x78
37 #define MMIO_ROUTE_START 0x80
38 #define MMIO_ROUTE_END 0xb8
39 #define PCIIO_ROUTE_START 0xc0
40 #define PCIIO_ROUTE_END 0xd8
41 #define CONFIG_ROUTE_START 0xe0
42 #define CONFIG_ROUTE_END 0xec
44 #define PCI_IO_BASE0 0xc0
45 #define PCI_IO_BASE1 0xc8
46 #define PCI_IO_BASE2 0xd0
47 #define PCI_IO_BASE3 0xd8
48 #define PCI_IO_BASE_VGA_EN (1 << 4)
49 #define PCI_IO_BASE_NO_ISA (1 << 5)
51 #define BITS(r, shift, mask) (((r>>shift)&mask))
54 * Return "R" if the register has read-enable bit set.
56 static const char *re(u32 i
)
58 return ((i
& 1) ? "R" : "");
62 * Return "W" if the register has write-enable bit set.
64 static const char *we(u32 i
)
66 return ((i
& 1) ? "W" : "");
70 * Return a string containing the interleave settings.
72 static const char *ileave(u32 base
)
74 switch ((base
>> 8) & 7) {
76 return "No interleave";
89 * Return the node number.
90 * For one case (config registers) these are not the right bit fields.
92 static int r_node(u32 reg
)
94 return BITS(reg
, 0, 0x7);
98 * Return the link number.
99 * For one case (config registers) these are not the right bit fields.
101 static int r_link(u32 reg
)
103 return BITS(reg
, 4, 0x3);
107 * Print the DRAM routing info for one base/limit pair.
109 * Show base, limit, dest node, dest link on that node, read and write
110 * enable, and interleave information.
112 * @param level Printing level
113 * @param which Register number
114 * @param base Base register
115 * @param lim Limit register
117 static void showdram(int level
, u8 which
, u32 base
, u32 lim
)
119 printk(level
, "DRAM(%02x)%010llx-%010llx, ->(%d), %s, %s, %s, %d\n",
120 which
, (((u64
) base
& 0xffff0000) << 8),
121 (((u64
) lim
& 0xffff0000) << 8) + 0xffffff,
122 r_node(lim
), re(base
), we(base
), ileave(base
), (lim
>> 8) & 3);
126 * Print the config routing info for a config register.
128 * Show base, limit, dest node, dest link on that node, read and write
129 * enable, and device number compare enable
131 * @param level Printing level
132 * @param which Register number
133 * @param reg Config register
135 static void showconfig(int level
, u8 which
, u32 reg
)
137 /* Don't use r_node() and r_link() here. */
138 printk(level
, "CONFIG(%02x)%02x-%02x ->(%d,%d),%s %s (%s numbers)\n",
139 which
, BITS(reg
, 16, 0xff), BITS(reg
, 24, 0xff),
140 BITS(reg
, 4, 0x7), BITS(reg
, 8, 0x3),
142 BITS(reg
, 2, 0x1)?"dev":"bus");
146 * Print the PCIIO routing info for one base/limit pair.
148 * Show base, limit, dest node, dest link on that node, read and write
149 * enable, and VGA and ISA Enable.
151 * @param level Printing level
152 * @param which Register number
153 * @param base Base register
154 * @param lim Limit register
156 static void showpciio(int level
, u8 which
, u32 base
, u32 lim
)
158 printk(level
, "PCIIO(%02x)%07x-%07x, ->(%d,%d), %s, %s,VGA %d ISA %d\n",
159 which
, BITS(base
, 12, 0x3fff) << 12,
160 (BITS(lim
, 12, 0x3fff) << 12) + 0xfff, r_node(lim
), r_link(lim
),
161 re(base
), we(base
), BITS(base
, 4, 0x1), BITS(base
, 5, 0x1));
165 * Print the MMIO routing info for one base/limit pair.
167 * Show base, limit, dest node, dest link on that node, read and write
168 * enable, and CPU Disable, Lock, and Non-posted.
170 * @param level Printing level
171 * @param which Register number
172 * @param base Base register
173 * @param lim Limit register
175 static void showmmio(int level
, u8 which
, u32 base
, u32 lim
)
177 printk(level
, "MMIO(%02x)%010llx-%010llx, ->(%d,%d), %s, %s, "
178 "CPU disable %d, Lock %d, Non posted %d\n",
179 which
, ((u64
) BITS(base
, 0, 0xffffff00)) << 8,
180 (((u64
) BITS(lim
, 0, 0xffffff00)) << 8) + 0xffff, r_node(lim
),
181 r_link(lim
), re(base
), we(base
), BITS(base
, 4, 0x1),
182 BITS(base
, 7, 0x1), BITS(lim
, 7, 0x1));
186 * Show all DRAM routing registers. This function is callable at any time.
188 * @param level The debug level.
189 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
192 static void showalldram(int level
, device_t dev
)
195 for (reg
= DRAM_ROUTE_START
; reg
<= DRAM_ROUTE_END
; reg
+= 8) {
196 u32 base
= pci_read_config32(dev
, reg
);
197 u32 lim
= pci_read_config32(dev
, reg
+ 4);
198 if (base
|| lim
!=(reg
-DRAM_ROUTE_START
)/8)
199 showdram(level
, reg
, base
, lim
);
204 * Show all MMIO routing registers. This function is callable at any time.
206 * @param level The debug level.
207 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
210 static void showallmmio(int level
, device_t dev
)
213 for (reg
= MMIO_ROUTE_START
; reg
<= MMIO_ROUTE_END
; reg
+= 8) {
214 u32 base
= pci_read_config32(dev
, reg
);
215 u32 lim
= pci_read_config32(dev
, reg
+ 4);
217 showmmio(level
, reg
, base
, lim
);
222 * Show all PCIIO routing registers. This function is callable at any time.
224 * @param level The debug level.
225 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
228 static void showallpciio(int level
, device_t dev
)
231 for (reg
= PCIIO_ROUTE_START
; reg
<= PCIIO_ROUTE_END
; reg
+= 8) {
232 u32 base
= pci_read_config32(dev
, reg
);
233 u32 lim
= pci_read_config32(dev
, reg
+ 4);
235 showpciio(level
, reg
, base
, lim
);
240 * Show all config routing registers. This function is callable at any time.
242 * @param level The debug level.
243 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
246 static void showallconfig(int level
, device_t dev
)
249 for (reg
= CONFIG_ROUTE_START
; reg
<= CONFIG_ROUTE_END
; reg
+= 4) {
250 u32 val
= pci_read_config32(dev
, reg
);
252 showconfig(level
, reg
, val
);
257 * Show all routing registers. This function is callable at any time.
259 * @param level The debug level.
260 * @param dev A 32-bit number in the standard bus/dev/fn format which is used
263 void showallroutes(int level
, device_t dev
)
265 showalldram(level
, dev
);
266 showallmmio(level
, dev
);
267 showallpciio(level
, dev
);
268 showallconfig(level
, dev
);