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