67de027e67845e1a5bff63e4f0c833229826ebb0
[coreboot.git] / src / mainboard / tyan / s2875 / 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 <string.h>
6 #include <stdint.h>
7 #if CONFIG_LOGICAL_CPUS==1
8 #include <cpu/amd/multicore.h>
9 #endif
10
11 static unsigned node_link_to_bus(unsigned node, unsigned link)
12 {
13         device_t dev;
14         unsigned reg;
15
16         dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
17         if (!dev) {
18                 return 0;
19         }
20         for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
21                 uint32_t config_map;
22                 unsigned dst_node;
23                 unsigned dst_link;
24                 unsigned bus_base;
25                 config_map = pci_read_config32(dev, reg);
26                 if ((config_map & 3) != 3) {
27                         continue;
28                 }
29                 dst_node = (config_map >> 4) & 7;
30                 dst_link = (config_map >> 8) & 3;
31                 bus_base = (config_map >> 16) & 0xff;
32 #if 0
33                 printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n",
34                         dst_node, dst_link, bus_base,
35                         reg, config_map);
36 #endif
37                 if ((dst_node == node) && (dst_link == link))
38                 {
39                         return bus_base;
40                 }
41         }
42         return 0;
43 }
44
45 static void *smp_write_config_table(void *v)
46 {
47         struct mp_config_table *mc;
48         int bus_isa;
49         unsigned char bus_chain_0;
50         unsigned char bus_8111_1;
51         unsigned char bus_8151_1;
52         unsigned apicid_base;
53         unsigned apicid_8111;
54
55         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
56
57         mptable_init(mc, LAPIC_ADDR);
58
59         smp_write_processors(mc);
60
61         {
62                 device_t dev;
63
64                 /* HT chain 0 */
65                 bus_chain_0 = node_link_to_bus(0, 0);
66                 if (bus_chain_0 == 0) {
67                         printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
68                         bus_chain_0 = 1;
69                 }
70
71                 /* 8111 */
72                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x04,0));
73                 if (dev) {
74                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
75                 }
76                 else {
77                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
78
79                         bus_8111_1 = 3;
80                 }
81                        /* 8151 */
82                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0));
83                 if (dev) {
84                         bus_8151_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
85                         printk(BIOS_DEBUG, "bus_8151_1=%d\n",bus_8151_1);
86
87                 }
88                 else {
89                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
90
91                         bus_8151_1 = 2;
92                 }
93
94
95         }
96
97 /*Bus:          Bus ID  Type*/
98         mptable_write_buses(mc, NULL, &bus_isa);
99
100 /*I/O APICs:    APIC ID Version State           Address*/
101 #if CONFIG_LOGICAL_CPUS==1
102         apicid_base = get_apicid_base(1);
103 #else
104         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
105 #endif
106         apicid_8111 = apicid_base+0;
107         smp_write_ioapic(mc, apicid_8111, 0x11, IO_APIC_ADDR);
108
109         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
110
111 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
112 //??? What
113         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (5<<2)|3, apicid_8111, 0x13);
114 //Onboard AMD AC97 Audio ???
115         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (5<<2)|1, apicid_8111, 0x11);
116 // Onboard AMD USB
117         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
118
119 //  AGP Display Adapter
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8151_1, 0x0, apicid_8111, 0x10);
121
122 // Onboard Serial ATA
123         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x05<<2)|0, apicid_8111, 0x13);
124 //Onboard Firewire
125         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|0, apicid_8111, 0x11);
126 //Onboard Broadcom NIC
127         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|0, apicid_8111, 0x12);
128
129 //Onboard VIA USB 1.1
130         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x11);
131         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|1, apicid_8111, 0x12);
132         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|2, apicid_8111, 0x13);
133
134 //Slot 1
135         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|0, apicid_8111, 0x12);
136         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|1, apicid_8111, 0x13);
137         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|2, apicid_8111, 0x10); //
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|3, apicid_8111, 0x11); //
139
140 //Slot 2
141         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|0, apicid_8111, 0x11);
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|1, apicid_8111, 0x12);
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|2, apicid_8111, 0x13); //
144         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|3, apicid_8111, 0x10); //
145
146 //Slot 3
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|0, apicid_8111, 0x10);
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|1, apicid_8111, 0x11);
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|2, apicid_8111, 0x12); //
150         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|3, apicid_8111, 0x13); //
151
152 //Slot 4
153         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|0, apicid_8111, 0x13);
154         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|1, apicid_8111, 0x10);
155         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|2, apicid_8111, 0x11); //
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|3, apicid_8111, 0x12); //
157
158
159 //Slot 5
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|0, apicid_8111, 0x10);
161         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|1, apicid_8111, 0x11);
162         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|2, apicid_8111, 0x12); //
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x04<<2)|3, apicid_8111, 0x13); //
164
165
166
167 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
168         mptable_lintsrc(mc, bus_isa);
169         /* There is no extension information... */
170
171         /* Compute the checksums */
172         return mptable_finalize(mc);
173 }
174
175 unsigned long write_smp_table(unsigned long addr)
176 {
177         void *v;
178         v = smp_write_floating_table(addr, 0);
179         return (unsigned long)smp_write_config_table(v);
180 }