dd7cefcc8545cf6871fd2c053774ea4ede7e18b9
[coreboot.git] / src / mainboard / tyan / s2885 / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <device/pci.h>
4 #include <string.h>
5 #include <stdint.h>
6
7 void *smp_write_config_table(void *v, unsigned long * processor_map)
8 {
9         static const char sig[4] = "PCMP";
10         static const char oem[8] = "TYAN    ";
11         static const char productid[12] = "S2885       ";
12         struct mp_config_table *mc;
13
14         unsigned char bus_num;
15         unsigned char bus_isa;
16         unsigned char bus_8131_1;
17         unsigned char bus_8131_2;
18         unsigned char bus_8111_1;
19         unsigned char bus_8151_1;
20
21
22         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
23         memset(mc, 0, sizeof(*mc));
24
25         memcpy(mc->mpc_signature, sig, sizeof(sig));
26         mc->mpc_length = sizeof(*mc); /* initially just the header */
27         mc->mpc_spec = 0x04;
28         mc->mpc_checksum = 0; /* not yet computed */
29         memcpy(mc->mpc_oem, oem, sizeof(oem));
30         memcpy(mc->mpc_productid, productid, sizeof(productid));
31         mc->mpc_oemptr = 0;
32         mc->mpc_oemsize = 0;
33         mc->mpc_entry_count = 0; /* No entries yet... */
34         mc->mpc_lapic = LAPIC_ADDR;
35         mc->mpe_length = 0;
36         mc->mpe_checksum = 0;
37         mc->reserved = 0;
38
39         smp_write_processors(mc, processor_map);
40
41        {
42                 device_t dev;
43
44                 /* 8111 */
45                 dev = dev_find_slot(3, PCI_DEVFN(0x03,0));
46                 if (dev) {
47                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
48                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
49                         bus_isa++;
50                         printk_debug("bus_isa=%d\n",bus_isa);
51                 }
52                 else {
53                         printk_debug("ERROR - could not find PCI 3:03.0, using defaults\n");
54
55                         bus_8111_1 = 6;
56                         bus_isa = 7;
57                 }
58                 /* 8131-1 */
59                 dev = dev_find_slot(3, PCI_DEVFN(0x01,0));
60                 if (dev) {
61                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
62
63                 }
64                 else {
65                         printk_debug("ERROR - could not find PCI 3:01.0, using defaults\n");
66
67                         bus_8131_1 = 4;
68                 }
69                 /* 8131-2 */
70                 dev = dev_find_slot(3, PCI_DEVFN(0x02,0));
71                 if (dev) {
72                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
73
74                 }
75                 else {
76                         printk_debug("ERROR - could not find PCI 3:02.0, using defaults\n");
77
78                         bus_8131_2 = 5;
79                 }
80                        /* 8151 */
81                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
82                 if (dev) {
83                         bus_8151_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
84                         printk_debug("bus_8151_1=%d\n",bus_8151_1);
85    
86                 }
87                 else {
88                         printk_debug("ERROR - could not find PCI 1:02.0, using defaults\n");
89
90                         bus_8151_1 = 2;
91                 }
92   
93    
94         }
95
96
97
98 /*Bus:          Bus ID  Type*/
99        /* define bus and isa numbers */
100         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
101                 smp_write_bus(mc, bus_num, "PCI   ");
102         }
103         smp_write_bus(mc, bus_isa, "ISA   ");
104
105 /*I/O APICs:    APIC ID Version State           Address*/
106         smp_write_ioapic(mc, 2, 0x11, 0xfec00000);
107         {
108                 struct pci_dev *dev;
109                 uint32_t base;
110                 dev = dev_find_slot(3, PCI_DEVFN(0x1,1));
111                 if (dev) {
112                         base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
113                         base &= PCI_BASE_ADDRESS_MEM_MASK;
114                         smp_write_ioapic(mc, 3, 0x11, base);
115                 }
116                 dev = dev_find_slot(3, PCI_DEVFN(0x2,1));
117                 if (dev) {
118                         base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
119                         base &= PCI_BASE_ADDRESS_MEM_MASK;
120                         smp_write_ioapic(mc, 4, 0x11, base);
121                 }
122         }
123   
124 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#
125 */      smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, 0x2, 0x0);
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x1, 0x2, 0x1);
127         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x0, 0x2, 0x2);
128         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x3, 0x2, 0x3);
129         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x4, 0x2, 0x4);
130         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x5, 0x2, 0x5);
131         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x6, 0x2, 0x6);
132         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x7, 0x2, 0x7);
133         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x8, 0x2, 0x8);
134         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xc, 0x2, 0xc);
135         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xd, 0x2, 0xd);
136         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xe, 0x2, 0xe);
137         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xf, 0x2, 0xf);
138 //??? What
139         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x3, (4<<2)|3, 0x2, 0x13);
140 //Onboard AMD AC97 Audio ???
141         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x3, (4<<2)|1, 0x2, 0x11);
142 // Onboard AMD USB
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, 0x2, 0x13);
144
145 //  AGP Display Adapter
146         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8151_1, 0x0, 0x2, 0x10);
147
148 // Onboard Serial ATA        
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, 0x2, 0x11);
150 //Onboard Firewire
151         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0c<<2)|0, 0x2, 0x13);
152 //Onboard Broadcom NIC
153         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, 0x3, 0x0);
154
155 //Slot 5 PCI 32
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|0, 0x2, 0x10);
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|1, 0x2, 0x11);
158         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|2, 0x2, 0x12); //
159         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|3, 0x2, 0x13); //
160
161 //Slot 3 PCIX 100/66
162         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|0, 0x3, 0x3);
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|1, 0x3, 0x0);
164         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|2, 0x3, 0x1);//
165         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|3, 0x3, 0x2);//
166
167 //Slot 4 PCIX 100/66        
168         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|0, 0x3, 0x2);
169         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|1, 0x3, 0x3);//
170         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|2, 0x3, 0x0);//
171         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|3, 0x3, 0x1);//
172
173 //Slot 1 PCI-X 133/100/66
174         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|0, 0x4, 0x0);
175         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|1, 0x4, 0x1);
176         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|2, 0x4, 0x2); //
177         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|3, 0x4, 0x3); //
178
179 //Slot 2 PCI-X 133/100/66
180         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|0, 0x4, 0x1);
181         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|1, 0x4, 0x2);
182         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|2, 0x4, 0x3);//
183         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|3, 0x4, 0x0);//
184
185 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
186         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
187         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
188         /* There is no extension information... */
189
190         /* Compute the checksums */
191         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
192         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
193         printk_debug("Wrote the mp table end at: %p - %p\n",
194                 mc, smp_next_mpe_entry(mc));
195         return smp_next_mpe_entry(mc);
196 }
197
198 unsigned long write_smp_table(unsigned long addr, unsigned long *processor_map)
199 {
200         void *v;
201         v = smp_write_floating_table(addr);
202         return (unsigned long)smp_write_config_table(v, processor_map);
203 }