Move generation of mptable entries for ISA to generic code.
[coreboot.git] / src / mainboard / tyan / s2875 / 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 #if CONFIG_LOGICAL_CPUS==1
7 #include <cpu/amd/multicore.h>
8 #endif
9
10 static unsigned node_link_to_bus(unsigned node, unsigned link)
11 {
12         device_t dev;
13         unsigned reg;
14
15         dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
16         if (!dev) {
17                 return 0;
18         }
19         for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
20                 uint32_t config_map;
21                 unsigned dst_node;
22                 unsigned dst_link;
23                 unsigned bus_base;
24                 config_map = pci_read_config32(dev, reg);
25                 if ((config_map & 3) != 3) {
26                         continue;
27                 }
28                 dst_node = (config_map >> 4) & 7;
29                 dst_link = (config_map >> 8) & 3;
30                 bus_base = (config_map >> 16) & 0xff;
31 #if 0
32                 printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n",
33                         dst_node, dst_link, bus_base,
34                         reg, config_map);
35 #endif
36                 if ((dst_node == node) && (dst_link == link))
37                 {
38                         return bus_base;
39                 }
40         }
41         return 0;
42 }
43
44 static void *smp_write_config_table(void *v)
45 {
46         static const char sig[4] = "PCMP";
47         static const char oem[8] = "COREBOOT";
48         static const char productid[12] = "S2875       ";
49         struct mp_config_table *mc;
50
51         unsigned char bus_num;
52         unsigned char bus_isa;
53         unsigned char bus_chain_0;
54         unsigned char bus_8111_1;
55         unsigned char bus_8151_1;
56         unsigned apicid_base;
57         unsigned apicid_8111;
58
59         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
60         memset(mc, 0, sizeof(*mc));
61
62         memcpy(mc->mpc_signature, sig, sizeof(sig));
63         mc->mpc_length = sizeof(*mc); /* initially just the header */
64         mc->mpc_spec = 0x04;
65         mc->mpc_checksum = 0; /* not yet computed */
66         memcpy(mc->mpc_oem, oem, sizeof(oem));
67         memcpy(mc->mpc_productid, productid, sizeof(productid));
68         mc->mpc_oemptr = 0;
69         mc->mpc_oemsize = 0;
70         mc->mpc_entry_count = 0; /* No entries yet... */
71         mc->mpc_lapic = LAPIC_ADDR;
72         mc->mpe_length = 0;
73         mc->mpe_checksum = 0;
74         mc->reserved = 0;
75
76         smp_write_processors(mc);
77
78         {
79                 device_t dev;
80
81                 /* HT chain 0 */
82                 bus_chain_0 = node_link_to_bus(0, 0);
83                 if (bus_chain_0 == 0) {
84                         printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
85                         bus_chain_0 = 1;
86                 }
87
88                 /* 8111 */
89                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x04,0));
90                 if (dev) {
91                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
92                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
93                         bus_isa++;
94                         printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
95                 }
96                 else {
97                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
98
99                         bus_8111_1 = 3;
100                         bus_isa = 4;
101                 }
102                        /* 8151 */
103                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0));
104                 if (dev) {
105                         bus_8151_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
106                         printk(BIOS_DEBUG, "bus_8151_1=%d\n",bus_8151_1);
107
108                 }
109                 else {
110                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
111
112                         bus_8151_1 = 2;
113                 }
114
115
116         }
117
118 /*Bus:          Bus ID  Type*/
119        /* define bus and isa numbers */
120         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
121                 smp_write_bus(mc, bus_num, "PCI   ");
122         }
123         smp_write_bus(mc, bus_isa, "ISA   ");
124
125 /*I/O APICs:    APIC ID Version State           Address*/
126 #if CONFIG_LOGICAL_CPUS==1
127         apicid_base = get_apicid_base(1);
128 #else
129         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
130 #endif
131         apicid_8111 = apicid_base+0;
132         smp_write_ioapic(mc, apicid_8111, 0x11, 0xfec00000);
133
134         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
135
136 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
137 //??? What
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (5<<2)|3, apicid_8111, 0x13);
139 //Onboard AMD AC97 Audio ???
140         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (5<<2)|1, apicid_8111, 0x11);
141 // Onboard AMD USB
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
143
144 //  AGP Display Adapter
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8151_1, 0x0, apicid_8111, 0x10);
146
147 // Onboard Serial ATA
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x05<<2)|0, apicid_8111, 0x13);
149 //Onboard Firewire
150         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|0, apicid_8111, 0x11);
151 //Onboard Broadcom NIC
152         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|0, apicid_8111, 0x12);
153
154 //Onboard VIA USB 1.1
155         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x11);
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|1, apicid_8111, 0x12);
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|2, apicid_8111, 0x13);
158
159 //Slot 1
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|0, apicid_8111, 0x12);
161         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|1, apicid_8111, 0x13);
162         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|2, apicid_8111, 0x10); //
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|3, apicid_8111, 0x11); //
164
165 //Slot 2
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|0, apicid_8111, 0x11);
167         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|1, apicid_8111, 0x12);
168         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|2, apicid_8111, 0x13); //
169         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|3, apicid_8111, 0x10); //
170
171 //Slot 3
172         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|0, apicid_8111, 0x10);
173         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|1, apicid_8111, 0x11);
174         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|2, apicid_8111, 0x12); //
175         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|3, apicid_8111, 0x13); //
176
177 //Slot 4
178         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|0, apicid_8111, 0x13);
179         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|1, apicid_8111, 0x10);
180         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|2, apicid_8111, 0x11); //
181         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|3, apicid_8111, 0x12); //
182
183
184 //Slot 5
185         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|0, apicid_8111, 0x10);
186         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|1, apicid_8111, 0x11);
187         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|2, apicid_8111, 0x12); //
188         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|3, apicid_8111, 0x13); //
189
190
191
192 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
193         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
194         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
195         /* There is no extension information... */
196
197         /* Compute the checksums */
198         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
199         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
200         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
201                 mc, smp_next_mpe_entry(mc));
202         return smp_next_mpe_entry(mc);
203 }
204
205 unsigned long write_smp_table(unsigned long addr)
206 {
207         void *v;
208         v = smp_write_floating_table(addr);
209         return (unsigned long)smp_write_config_table(v);
210 }