Unify Local APIC address definitions
[coreboot.git] / src / mainboard / tyan / s2882 / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
5 #include <device/pci_ids.h>
6 #include <string.h>
7 #include <stdint.h>
8 #if CONFIG_LOGICAL_CPUS==1
9 #include <cpu/amd/multicore.h>
10 #endif
11
12 static unsigned node_link_to_bus(unsigned node, unsigned link)
13 {
14         device_t dev;
15         unsigned reg;
16
17         dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
18         if (!dev) {
19                 return 0;
20         }
21         for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
22                 uint32_t config_map;
23                 unsigned dst_node;
24                 unsigned dst_link;
25                 unsigned bus_base;
26                 config_map = pci_read_config32(dev, reg);
27                 if ((config_map & 3) != 3) {
28                         continue;
29                 }
30                 dst_node = (config_map >> 4) & 7;
31                 dst_link = (config_map >> 8) & 3;
32                 bus_base = (config_map >> 16) & 0xff;
33 #if 0
34                 printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n",
35                         dst_node, dst_link, bus_base,
36                         reg, config_map);
37 #endif
38                 if ((dst_node == node) && (dst_link == link))
39                 {
40                         return bus_base;
41                 }
42         }
43         return 0;
44 }
45
46 static void *smp_write_config_table(void *v)
47 {
48         struct mp_config_table *mc;
49         int bus_isa;
50         unsigned char bus_chain_0;
51         unsigned char bus_8131_1;
52         unsigned char bus_8131_2;
53         unsigned char bus_8111_1;
54         unsigned apicid_base;
55         unsigned apicid_8111;
56         unsigned apicid_8131_1;
57         unsigned apicid_8131_2;
58
59         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
60
61         mptable_init(mc, LOCAL_APIC_ADDR);
62
63         smp_write_processors(mc);
64         {
65                 device_t dev;
66
67                 /* HT chain 0 */
68                 bus_chain_0 = node_link_to_bus(0, 0);
69                 if (bus_chain_0 == 0) {
70                         printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
71                         bus_chain_0 = 1;
72                 }
73
74                 /* 8111 */
75                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x03,0));
76                 if (dev) {
77                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
78                 }
79                 else {
80                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
81
82                         bus_8111_1 = 4;
83                 }
84                 /* 8131-1 */
85                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x01,0));
86                 if (dev) {
87                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
88
89                 }
90                 else {
91                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
92
93                         bus_8131_1 = 2;
94                 }
95                 /* 8131-2 */
96                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0));
97                 if (dev) {
98                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
99
100                 }
101                 else {
102                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
103
104                         bus_8131_2 = 3;
105                 }
106         }
107         mptable_write_buses(mc, NULL, &bus_isa);
108
109 /*I/O APICs:    APIC ID Version State           Address*/
110 #if CONFIG_LOGICAL_CPUS==1
111         apicid_base = get_apicid_base(3);
112 #else
113         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
114 #endif
115         apicid_8111 = apicid_base+0;
116         apicid_8131_1 = apicid_base+1;
117         apicid_8131_2 = apicid_base+2;
118
119         smp_write_ioapic(mc, apicid_8111, 0x11, IO_APIC_ADDR);
120         {
121                 device_t dev;
122                 struct resource *res;
123                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x1,1));
124                 if (dev) {
125                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
126                         if (res) {
127                                 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
128                         }
129                 }
130                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x2,1));
131                 if (dev) {
132                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
133                         if (res) {
134                                 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
135                         }
136                 }
137
138         }
139
140         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
141
142 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (4<<2)|3, apicid_8111, 0x13);
144
145
146 //On Board AMD USB
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
148
149
150 //On Board ATI Display Adapter
151         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (6<<2)|0, apicid_8111, 0x12);
152
153 #if 1
154 //Slot 5 PCI 32
155         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|0, apicid_8111, 0x10);
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|1, apicid_8111, 0x11);
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|2, apicid_8111, 0x12); //
158         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|3, apicid_8111, 0x13); //
159
160 #endif
161 //Onboard SI Serial ATA
162         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (5<<2)|0, apicid_8111, 0x13);
163
164 //Onboard Intel 82551 10/100M NIC
165         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (8<<2)|0, apicid_8111, 0x12);
166
167 #if 1
168 //Slot 3 PCIX 100/66
169         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|0, apicid_8131_1, 0x3);
170         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|1, apicid_8131_1, 0x0);
171         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|2, apicid_8131_1, 0x1);//
172         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|3, apicid_8131_1, 0x2);//
173
174 //Slot 4 PCIX 100/66
175         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|0, apicid_8131_1, 0x2);
176         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|1, apicid_8131_1, 0x3);//
177         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|2, apicid_8131_1, 0x0);//
178         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|3, apicid_8131_1, 0x1);//
179
180
181 #endif
182 //Onboard adaptec scsi
183         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (6<<2)|0, apicid_8131_1, 0x0);
184         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (6<<2)|1, apicid_8131_1, 0x1);
185
186 //On Board NIC
187         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, apicid_8131_1, 0x0);
188         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|1, apicid_8131_1, 0x1);
189
190
191 #if 1
192 //Slot 1 PCI-X 133/100/66
193         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|0, apicid_8131_2, 0x0);
194         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|1, apicid_8131_2, 0x1);
195         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|2, apicid_8131_2, 0x2); //
196         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|3, apicid_8131_2, 0x3); //
197
198 //Slot 2 PCI-X 133/100/66
199         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|0, apicid_8131_2, 0x1);
200         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|1, apicid_8131_2, 0x2);
201         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|2, apicid_8131_2, 0x3);//
202         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|3, apicid_8131_2, 0x0);//
203
204 #endif
205 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
206         mptable_lintsrc(mc, bus_isa);
207         /* There is no extension information... */
208
209         /* Compute the checksums */
210         return mptable_finalize(mc);
211 }
212
213 unsigned long write_smp_table(unsigned long addr)
214 {
215         void *v;
216         v = smp_write_floating_table(addr, 0);
217         return (unsigned long)smp_write_config_table(v);
218 }