a51278b06a63fa286e6acd996f3608cd5fb374a0
[coreboot.git] / src / mainboard / tyan / s2885 / mainboard.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
5 #include <device/pci_ops.h>
6 #include "../../../northbridge/amd/amdk8/northbridge.h"
7 #include "chip.h"
8
9 #if 0
10 static void fixup_lsi_53c1030(struct device *pdev)
11 {
12 //      uint8_t byte;
13         uint16_t word;
14
15         byte = 1;
16         pci_write_config8(pdev, 0xff, byte);
17            // Set the device id 
18 //      pci_write_config_word(pdev, PCI_DEVICE_ID, PCI_DEVICE_ID_LSILOGIC_53C1030);
19            // Set the subsytem vendor id 
20 //      pci_write_config16(pdev, PCI_SUBSYSTEM_VENDOR_ID, PCI_VENDOR_ID_TYAN);  
21         word = 0x10f1;
22         pci_write_config16(pdev, PCI_SUBSYSTEM_VENDOR_ID, word);
23             // Set the subsytem id 
24         word = 0x2880;
25         pci_write_config16(pdev, PCI_SUBSYSTEM_ID, word);
26             // Disable writes to the device id 
27         byte = 0;
28         pci_write_config8(pdev, 0xff, byte);
29
30 //      lsi_scsi_init(pdev);
31         
32 }
33 #endif
34
35 #if 0
36 static void print_pci_regs(struct device *dev)
37 {
38       uint8_t byte;
39       int i;
40
41       for(i=0;i<256;i++) {
42              byte = pci_read_config8(dev, i);
43    
44              if((i%16)==0) printk_debug("\n%02x:",i);
45              printk_debug(" %02x",byte);
46       }
47       printk_debug("\n");
48         
49 //        pci_write_config8(dev, 0x4, byte);
50
51 }
52 #endif
53 #if 0
54 static void print_mem(void)
55 {
56         unsigned int i;
57         unsigned int low_1MB = 0xf4107000;
58         for(i=low_1MB;i<low_1MB+1024;i++) {
59              if((i%16)==0) printk_debug("\n %08x:",i);
60              printk_debug(" %02x ",(unsigned char)*((unsigned char *)i));
61              }
62 #if 0
63         for(i=low_1MB;i<low_1MB+1024*4;i++) {
64              if((i%16)==0) printk_debug("\n %08x:",i);
65              printk_debug(" %c ",(unsigned char)*((unsigned char *)i));
66              }
67 #endif
68  }
69 #endif
70 #if 0
71 static void amd8111_enable_rom(void)
72 {
73         uint8_t byte;
74         struct device *dev;
75
76         /* Enable 4MB rom access at 0xFFC00000 - 0xFFFFFFFF */
77         /* Locate the amd8111 */
78         dev = dev_find_device(0x1022, 0x7468, 0);
79
80         /* Set the 4MB enable bit bit */
81         byte = pci_read_config8(dev, 0x43);
82         byte |= 0x80;
83         pci_write_config8(dev, 0x43, byte);
84 }
85 #endif
86 #if 0
87 static void onboard_scsi_fixup(void)
88 {
89         struct device *dev;
90 #if 1
91         unsigned char i,j,k;
92
93         for(i=0;i<=15;i++) {
94                 for(j=0;j<=0x1f;j++) {
95                         for (k=0;k<=6;k++){
96                                 dev = dev_find_slot(i, PCI_DEVFN(j, k));
97                                 if (dev) {
98                                         printk_debug("%02x:%02x:%02x",i,j,k);
99                                         print_pci_regs(dev);
100                                 }
101                         }
102                 }
103         }
104 #endif
105
106
107 #if 0
108         dev = dev_find_device(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030,0);
109         if(!dev) {
110                 printk_info("LSI_SCSI_FW_FIXUP: No Device Found!");
111                 return;
112         }
113
114         lsi_scsi_init(dev); 
115 #endif
116 //      print_mem();
117 //      amd8111_enable_rom();
118 }
119 #endif
120 #if 0
121 static void vga_fixup(void) {
122         // we do this right here because:
123         // - all the hardware is working, and some VGA bioses seem to need
124         //   that
125         // - we need page 0 below for linuxbios tables.
126 #if CONFIG_REALMODE_IDT == 1
127         printk_debug("INSTALL REAL-MODE IDT\n");
128         setup_realmode_idt();
129 #endif
130 #if CONFIG_VGABIOS == 1
131         printk_debug("DO THE VGA BIOS\n");
132         do_vgabios(0x0600);
133         post_code(0x93);
134 #endif
135
136 }
137
138 #endif
139  
140 #if 0
141 static void
142 enable(struct chip *chip, enum chip_pass pass)
143 {
144
145         struct mainboard_tyan_s2895_config *conf = 
146                 (struct mainboard_tyan_s2895_config *)chip->chip_info;
147
148         switch (pass) {
149                 default: break;
150 //              case CONF_PASS_PRE_CONSOLE:
151 //              case CONF_PASS_PRE_PCI:
152 //              case CONF_PASS_POST_PCI:                
153                 case CONF_PASS_PRE_BOOT:
154 //                      if (conf->fixup_scsi)
155 //                              onboard_scsi_fixup();
156 //                      if (conf->fixup_vga)
157 //                              vga_fixup();
158                         printk_debug("mainboard fixup pass %d done\r\n",
159                                         pass);
160                         break;
161         }
162
163 }
164 #endif
165
166 #undef DEBUG
167 #define DEBUG 0
168 #if DEBUG 
169 static void debug_init(device_t dev)
170 {
171         unsigned bus;
172         unsigned devfn;
173 #if 0
174         for(bus = 0; bus < 256; bus++) {
175                 for(devfn = 0; devfn < 256; devfn++) {
176                         int i;
177                         dev = dev_find_slot(bus, devfn);
178                         if (!dev) {
179                                 continue;
180                         }
181                         if (!dev->enabled) {
182                                 continue;
183                         }
184                         printk_info("%02x:%02x.%0x aka %s\n", 
185                                 bus, devfn >> 3, devfn & 7, dev_path(dev));
186                         for(i = 0; i < 256; i++) {
187                                 if ((i & 0x0f) == 0) {
188                                         printk_info("%02x:", i);
189                                 }
190                                 printk_info(" %02x", pci_read_config8(dev, i));
191                                 if ((i & 0x0f) == 0xf) {
192                                         printk_info("\n");
193                                 }
194                         }
195                         printk_info("\n");
196                 }
197         }
198 #endif
199 #if 0
200         msr_t msr;
201         unsigned index;
202         unsigned eax, ebx, ecx, edx;
203         index = 0x80000007;
204         printk_debug("calling cpuid 0x%08x\n", index);
205         asm volatile(
206                 "cpuid"
207                 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
208                 : "a" (index)
209                 );
210         printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
211                 index, eax, ebx, ecx, edx);
212         if (edx & (3 << 1)) {
213                 index = 0xC0010042;
214                 printk_debug("Reading msr: 0x%08x\n", index);
215                 msr = rdmsr(index);
216                 printk_debug("msr[0x%08x]: 0x%08x%08x\n",
217                         index, msr.hi, msr.hi);
218         }
219 #endif
220 }
221
222 static void debug_noop(device_t dummy)
223 {
224 }
225
226 static struct device_operations debug_operations = {
227         .read_resources   = debug_noop,
228         .set_resources    = debug_noop,
229         .enable_resources = debug_noop,
230         .init             = debug_init,
231 };
232
233 static unsigned int scan_root_bus(device_t root, unsigned int max)
234 {
235         struct device_path path;
236         device_t debug;
237         max = root_dev_scan_bus(root, max);
238         path.type = DEVICE_PATH_PNP;
239         path.u.pnp.port   = 0;
240         path.u.pnp.device = 0;
241         debug = alloc_dev(&root->link[1], &path);
242         debug->ops = &debug_operations;
243         return max;
244 }
245 #endif
246
247 static void mainboard_init(device_t dev)
248 {       
249         root_dev_init(dev);
250         
251 //        do_verify_cpu_voltages();
252 }
253
254 static struct device_operations mainboard_operations = {
255         .read_resources   = root_dev_read_resources,
256         .set_resources    = root_dev_set_resources,
257         .enable_resources = root_dev_enable_resources,
258         .init             = mainboard_init,
259 #if !DEBUG
260         .scan_bus         = root_dev_scan_bus,
261 #else
262         .scan_bus         = scan_root_bus,
263 #endif
264         .enable           = 0,
265 };
266
267 static void enable_dev(struct device *dev)
268 {
269         dev_root.ops = &mainboard_operations;
270 }
271 struct chip_operations mainboard_tyan_s2885_ops = {
272         .enable_dev = enable_dev, 
273 };