a2fdd32986abd8fe04799b8904228be1b5969062
[coreboot.git] / src / mainboard / tyan / s2850 / 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
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
46 static void *smp_write_config_table(void *v)
47 {
48         static const char sig[4] = "PCMP";
49         static const char oem[8] = "COREBOOT";
50         static const char productid[12] = "S2850       ";
51         struct mp_config_table *mc;
52
53         int bus_isa;
54         unsigned char bus_chain_0;
55         unsigned char bus_8111_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                 device_t dev;
79
80                 /* HT chain 0 */
81                 bus_chain_0 = node_link_to_bus(0, 0);
82                 if (bus_chain_0 == 0) {
83                         printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
84                         bus_chain_0 = 1;
85                 }
86                 /* 8111 */
87                 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x01,0));
88                 if (dev) {
89                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
90                 }
91                 else {
92                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
93
94                         bus_8111_1 = 2;
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
108         smp_write_ioapic(mc, apicid_8111, 0x11, 0xfec00000);
109
110         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
111
112 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
113
114         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (2<<2)|3, apicid_8111, 0x13);
115
116 //On Board 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 //On Board ATI Display Adapter
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x12);
121
122 //Onboard Broadcom 5705 NIC
123         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0d<<2)|0, apicid_8111, 0x13);
124         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0e<<2)|0, apicid_8111, 0x10);
125 //Onboard SI Serial ATA
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0c<<2)|0, apicid_8111, 0x11);
127
128
129 //PCI Slot 1
130         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|0, apicid_8111, 0x10);
131         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|1, apicid_8111, 0x11);
132         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|2, apicid_8111, 0x12);
133         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x03<<2)|3, apicid_8111, 0x13);
134
135
136 //PCI Slot 2
137         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|0, apicid_8111, 0x11);
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|1, apicid_8111, 0x12);
139         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|2, apicid_8111, 0x13);
140         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x06<<2)|3, apicid_8111, 0x10);
141
142
143 //PCI Slot 3
144         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|0, apicid_8111, 0x12);
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|1, apicid_8111, 0x13);
146         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|2, apicid_8111, 0x10);
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x07<<2)|3, apicid_8111, 0x11);
148
149
150 //PCI Slot 4
151         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|0, apicid_8111, 0x13);
152         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|1, apicid_8111, 0x10);
153         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|2, apicid_8111, 0x11);
154         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x08<<2)|3, apicid_8111, 0x12);
155
156 //PCI Slot 5
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|0, apicid_8111, 0x10);
158         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|1, apicid_8111, 0x11);
159         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|2, apicid_8111, 0x12);
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x09<<2)|3, apicid_8111, 0x13);
161
162 //PCI Slot 6
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|0, apicid_8111, 0x11);
164         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|1, apicid_8111, 0x12);
165         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|2, apicid_8111, 0x13);
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|3, apicid_8111, 0x10);
167
168 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
169         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
170         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
171         /* There is no extension information... */
172
173         /* Compute the checksums */
174         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
175         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
176         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
177                 mc, smp_next_mpe_entry(mc));
178         return smp_next_mpe_entry(mc);
179 }
180
181 unsigned long write_smp_table(unsigned long addr)
182 {
183         void *v;
184         v = smp_write_floating_table(addr);
185         return (unsigned long)smp_write_config_table(v);
186 }