fix broken stuff :-(((
[coreboot.git] / src / northbridge / amd / amdk8 / misc_control.c
1 /* Turn off machine check triggers when reading
2  * pci space where there are no devices.
3  * This is necessary when scaning the bus for
4  * devices which is done by the kernel
5  *
6  * written in 2003 by Eric Biederman
7  * 
8  *  - Athlon64 workarounds by Stefan Reinauer
9  *  - "reset once" logic by Yinghai Lu
10  */
11
12 #include <console/console.h>
13 #include <device/device.h>
14 #include <device/pci.h>
15 #include <device/pci_ids.h>
16 #include <device/pci_ops.h>
17 #include "./cpu_rev.c"
18
19 static cpu_reset_count = 0;
20 static void misc_control_init(struct device *dev)
21 {
22         uint32_t cmd;
23         
24         printk_debug("NB: Function 3 Misc Control.. ");
25         
26         /* disable error reporting */
27         cmd = pci_read_config32(dev, 0x44);
28         cmd |= (1<<6) | (1<<25);
29         pci_write_config32(dev, 0x44, cmd );
30         if (is_cpu_pre_c0()) {
31                 /* errata 58 */
32                 cmd = pci_read_config32(dev, 0x80);
33                 cmd &= ~(1<<0);
34                 pci_write_config32(dev, 0x80, cmd );
35                 cmd = pci_read_config32(dev, 0x84);
36                 cmd &= ~(1<<24);
37                 cmd &= ~(1<<8);
38                 pci_write_config32(dev, 0x84, cmd );
39                 /* errata 66 */
40                 cmd = pci_read_config32(dev, 0x70);
41                 cmd &= ~(1<<0);
42                 cmd |= (1<<1);
43                 pci_write_config32(dev, 0x70, cmd );
44                 cmd = pci_read_config32(dev, 0x7c);
45                 cmd &= ~(3<<4);
46                 pci_write_config32(dev, 0x7c, cmd );
47         }
48         else {
49                 /* errata 98 */
50 #if 0           
51                 cmd = pci_read_config32(dev, 0xd4);
52                 if(cmd != 0x04e20707) {
53                         cmd = 0x04e20707;
54                         pci_write_config32(dev, 0xd4, cmd );
55                         hard_reset();
56                 }
57 #endif
58
59                 cmd = 0x04e20707;
60                 pci_write_config32(dev, 0xd4, cmd );
61         }
62
63 /*
64  * FIXME: This preprocessor check is a mere workaround. 
65  * The right fix is to walk over all links on all nodes
66  * and set the FIFO read pointer optimization value to
67  * 0x25 for each link connected to an AMD HT device.
68  *
69  * The reason this is only enabled for machines with more 
70  * than one CPU is that Athlon64 machines don't have the
71  * link at all that is optimized in the code.
72  */
73
74 #if CONFIG_MAX_CPUS > 1 
75 #if HAVE_HARD_RESET==1
76         cpu_reset_count++;
77         cmd = pci_read_config32(dev, 0xdc);
78         if((cmd & 0x0000ff00) != 0x02500) {
79                 cmd &= 0xffff00ff;
80                 cmd |= 0x00002500;
81                 pci_write_config32(dev, 0xdc, cmd );
82                 if(cpu_reset_count==CONFIG_MAX_CPUS) {
83                         printk_debug("resetting cpu\n");
84                         hard_reset();
85                 }
86         } 
87 #endif
88 #endif  
89         printk_debug("done.\n");
90 }
91
92 static struct device_operations mcf3_ops  = {
93         .read_resources   = pci_dev_read_resources,
94         .set_resources    = pci_dev_set_resources,
95         .enable_resources = pci_dev_enable_resources,
96         .init             = misc_control_init,
97         .scan_bus         = 0,
98 };
99
100 static struct pci_driver mcf3_driver __pci_driver = {
101         .ops    = &mcf3_ops,
102         .vendor = PCI_VENDOR_ID_AMD,
103         .device = 0x1103,
104 };
105