5144cec6d2c754fb85a240df2bb8fee5c51ac938
[coreboot.git] / src / mainboard / tyan / s2850 / 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 apicid_base;
52         unsigned apicid_8111;
53
54         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
55
56         mptable_init(mc, LAPIC_ADDR);
57
58         smp_write_processors(mc);
59         {
60                 device_t dev;
61
62                 /* HT chain 0 */
63                 bus_chain_0 = node_link_to_bus(0, 0);
64                 if (bus_chain_0 == 0) {
65                         printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
66                         bus_chain_0 = 1;
67                 }
68                 /* 8111 */
69                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x01,0));
70                 if (dev) {
71                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
72                 }
73                 else {
74                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
75
76                         bus_8111_1 = 2;
77                 }
78         }
79 /*Bus:          Bus ID  Type*/
80         mptable_write_buses(mc, NULL, &bus_isa);
81
82 /*I/O APICs:    APIC ID Version State           Address*/
83 #if CONFIG_LOGICAL_CPUS==1
84         apicid_base = get_apicid_base(1);
85 #else
86         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
87 #endif
88         apicid_8111 = apicid_base+0;
89
90         smp_write_ioapic(mc, apicid_8111, 0x11, IO_APIC_ADDR);
91
92         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
93
94 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
95
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (2<<2)|3, apicid_8111, 0x13);
97
98 //On Board AMD USB
99         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
100
101 //On Board ATI Display Adapter
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x12);
103
104 //Onboard Broadcom 5705 NIC
105         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0d<<2)|0, apicid_8111, 0x13);
106         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0e<<2)|0, apicid_8111, 0x10);
107 //Onboard SI Serial ATA
108         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0c<<2)|0, apicid_8111, 0x11);
109
110
111 //PCI Slot 1
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|0, apicid_8111, 0x10);
113         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|1, apicid_8111, 0x11);
114         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|2, apicid_8111, 0x12);
115         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|3, apicid_8111, 0x13);
116
117
118 //PCI Slot 2
119         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|0, apicid_8111, 0x11);
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|1, apicid_8111, 0x12);
121         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|2, apicid_8111, 0x13);
122         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|3, apicid_8111, 0x10);
123
124
125 //PCI Slot 3
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|0, apicid_8111, 0x12);
127         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|1, apicid_8111, 0x13);
128         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|2, apicid_8111, 0x10);
129         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|3, apicid_8111, 0x11);
130
131
132 //PCI Slot 4
133         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|0, apicid_8111, 0x13);
134         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|1, apicid_8111, 0x10);
135         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|2, apicid_8111, 0x11);
136         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|3, apicid_8111, 0x12);
137
138 //PCI Slot 5
139         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|0, apicid_8111, 0x10);
140         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|1, apicid_8111, 0x11);
141         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|2, apicid_8111, 0x12);
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|3, apicid_8111, 0x13);
143
144 //PCI Slot 6
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|0, apicid_8111, 0x11);
146         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|1, apicid_8111, 0x12);
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|2, apicid_8111, 0x13);
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|3, apicid_8111, 0x10);
149
150 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
151         mptable_lintsrc(mc, bus_isa);
152         /* There is no extension information... */
153
154         /* Compute the checksums */
155         return mptable_finalize(mc);
156 }
157
158 unsigned long write_smp_table(unsigned long addr)
159 {
160         void *v;
161         v = smp_write_floating_table(addr, 0);
162         return (unsigned long)smp_write_config_table(v);
163 }