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