Unify DIMM SPD addressing. For Geode, change the
[coreboot.git] / src / mainboard / intel / eagleheights / debug.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2008 coresystems GmbH
5  * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; version 2 of
10  * the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20  * MA 02110-1301 USA
21  */
22
23 #define SMBUS_MEM_DEVICE_START 0x50
24 #define SMBUS_MEM_DEVICE_END 0x57
25 #define SMBUS_MEM_DEVICE_INC 1
26
27 static void print_reg(unsigned char index)
28 {
29         unsigned char data;
30
31         outb(index, 0x2e);
32         data = inb(0x2f);
33         print_debug("0x");
34         print_debug_hex8(index);
35         print_debug(": 0x");
36         print_debug_hex8(data);
37         print_debug("\n");
38         return;
39 }
40
41 static inline void xbus_en(void)
42 {
43         /* select the XBUS function in the SIO */
44         outb(0x07, 0x2e);
45         outb(0x0f, 0x2f);
46         outb(0x30, 0x2e);
47         outb(0x01, 0x2f);
48         return;
49 }
50
51 static void setup_func(unsigned char func)
52 {
53         /* select the function in the SIO */
54         outb(0x07, 0x2e);
55         outb(func, 0x2f);
56         /* print out the regs */
57         print_reg(0x30);
58         print_reg(0x60);
59         print_reg(0x61);
60         print_reg(0x62);
61         print_reg(0x63);
62         print_reg(0x70);
63         print_reg(0x71);
64         print_reg(0x74);
65         print_reg(0x75);
66         return;
67 }
68
69 static inline void siodump(void)
70 {
71         int i;
72         unsigned char data;
73
74          print_debug("\n*** SERVER I/O REGISTERS ***\n");
75         for (i=0x10; i<=0x2d; i++) {
76                 print_reg((unsigned char)i);
77         }
78 #if 0
79         print_debug("\n*** XBUS REGISTERS ***\n");
80         setup_func(0x0f);
81         for (i=0xf0; i<=0xff; i++) {
82                 print_reg((unsigned char)i);
83         }
84
85         print_debug("\n***  SERIAL 1 CONFIG REGISTERS ***\n");
86         setup_func(0x03);
87         print_reg(0xf0);
88
89         print_debug("\n***  SERIAL 2 CONFIG REGISTERS ***\n");
90         setup_func(0x02);
91         print_reg(0xf0);
92
93 #endif
94         print_debug("\n***  GPIO REGISTERS ***\n");
95         setup_func(0x07);
96         for (i=0xf0; i<=0xf8; i++) {
97                 print_reg((unsigned char)i);
98         }
99         print_debug("\n***  GPIO VALUES ***\n");
100         data = inb(0x68a);
101         print_debug("\nGPDO 4: 0x");
102         print_debug_hex8(data);
103         data = inb(0x68b);
104         print_debug("\nGPDI 4: 0x");
105         print_debug_hex8(data);
106         print_debug("\n");
107
108 #if 0
109
110         print_debug("\n***  WATCHDOG TIMER REGISTERS ***\n");
111         setup_func(0x0a);
112         print_reg(0xf0);
113
114         print_debug("\n***  FAN CONTROL REGISTERS ***\n");
115         setup_func(0x09);
116         print_reg(0xf0);
117         print_reg(0xf1);
118
119         print_debug("\n***  RTC REGISTERS ***\n");
120         setup_func(0x10);
121         print_reg(0xf0);
122         print_reg(0xf1);
123         print_reg(0xf3);
124         print_reg(0xf6);
125         print_reg(0xf7);
126         print_reg(0xfe);
127         print_reg(0xff);
128
129         print_debug("\n***  HEALTH MONITORING & CONTROL REGISTERS ***\n");
130         setup_func(0x14);
131         print_reg(0xf0);
132 #endif
133         return;
134 }
135
136 static void print_debug_pci_dev(unsigned dev)
137 {
138         print_debug("PCI: ");
139         print_debug_hex8((dev >> 16) & 0xff);
140         print_debug_char(':');
141         print_debug_hex8((dev >> 11) & 0x1f);
142         print_debug_char('.');
143         print_debug_hex8((dev >> 8) & 7);
144 }
145
146 static inline void print_pci_devices(void)
147 {
148         device_t dev;
149         for(dev = PCI_DEV(0, 0, 0);
150                 dev <= PCI_DEV(0, 0x1f, 0x7);
151                 dev += PCI_DEV(0,0,1)) {
152                 uint32_t id;
153                 id = pci_read_config32(dev, PCI_VENDOR_ID);
154                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
155                         (((id >> 16) & 0xffff) == 0xffff) ||
156                         (((id >> 16) & 0xffff) == 0x0000)) {
157                         continue;
158                 }
159                 print_debug_pci_dev(dev);
160                 print_debug("\n");
161         }
162 }
163
164 static inline void dump_pci_device(unsigned dev)
165 {
166         int i;
167         print_debug_pci_dev(dev);
168         print_debug("\n");
169
170         for(i = 0; i <= 255; i++) {
171                 unsigned char val;
172                 if ((i & 0x0f) == 0) {
173                         print_debug_hex8(i);
174                         print_debug_char(':');
175                 }
176                 val = pci_read_config8(dev, i);
177                 print_debug_char(' ');
178                 print_debug_hex8(val);
179                 if ((i & 0x0f) == 0x0f) {
180                         print_debug("\n");
181                 }
182         }
183 }
184
185 static inline void dump_bar14(unsigned dev)
186 {
187         int i;
188         unsigned long bar;
189
190         print_debug("BAR 14 Dump\n");
191
192         bar = pci_read_config32(dev, 0x14);
193         for(i = 0; i <= 0x300; i+=4) {
194 #if 0
195                 unsigned char val;
196                 if ((i & 0x0f) == 0) {
197                         print_debug_hex8(i);
198                         print_debug_char(':');
199                 }
200                 val = pci_read_config8(dev, i);
201 #endif
202                 if((i%4)==0) {
203                 print_debug("\n");
204                 print_debug_hex16(i);
205                 print_debug_char(' ');
206                 }
207                 print_debug_hex32(read32(bar + i));
208                 print_debug_char(' ');
209         }
210         print_debug("\n");
211 }
212
213 static inline void dump_pci_devices(void)
214 {
215         device_t dev;
216         for(dev = PCI_DEV(0, 0, 0);
217                 dev <= PCI_DEV(0, 0x1f, 0x7);
218                 dev += PCI_DEV(0,0,1)) {
219                 uint32_t id;
220                 id = pci_read_config32(dev, PCI_VENDOR_ID);
221                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
222                         (((id >> 16) & 0xffff) == 0xffff) ||
223                         (((id >> 16) & 0xffff) == 0x0000)) {
224                         continue;
225                 }
226                 dump_pci_device(dev);
227         }
228 }
229
230 static inline void dump_spd_registers(void)
231 {
232         unsigned device;
233         device = SMBUS_MEM_DEVICE_START;
234         while(device <= SMBUS_MEM_DEVICE_END) {
235                 int status = 0;
236                 int i;
237                 print_debug("\n");
238                 print_debug("dimm ");
239                 print_debug_hex8(device);
240
241                 for(i = 0; (i < 256) ; i++) {
242                         if ((i % 16) == 0) {
243                                 print_debug("\n");
244                                 print_debug_hex8(i);
245                                 print_debug(": ");
246                         }
247                         status = smbus_read_byte(device, i);
248                         if (status < 0) {
249                                  print_debug("bad device: ");
250                                  print_debug_hex8(-status);
251                                  print_debug("\n");
252                                  break;
253                         }
254                         print_debug_hex8(status);
255                         print_debug_char(' ');
256                 }
257                 device += SMBUS_MEM_DEVICE_INC;
258                 print_debug("\n");
259         }
260 }
261
262 static inline void dump_ipmi_registers(void)
263 {
264         unsigned device;
265         device = 0x42;
266         while(device <= 0x42) {
267                 int status = 0;
268                 int i;
269                 print_debug("\n");
270                 print_debug("ipmi ");
271                 print_debug_hex8(device);
272
273                 for(i = 0; (i < 8) ; i++) {
274                         status = smbus_read_byte(device, 2);
275                         if (status < 0) {
276                                  print_debug("bad device: ");
277                                  print_debug_hex8(-status);
278                                  print_debug("\n");
279                                  break;
280                         }
281                         print_debug_hex8(status);
282                         print_debug_char(' ');
283                 }
284                 device += SMBUS_MEM_DEVICE_INC;
285                 print_debug("\n");
286         }
287 }