1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
7 #if CONFIG_LOGICAL_CPUS==1
8 #include <cpu/amd/multicore.h>
12 static unsigned node_link_to_bus(unsigned node, unsigned link)
17 dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
21 for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
26 config_map = pci_read_config32(dev, reg);
27 if ((config_map & 3) != 3) {
30 dst_node = (config_map >> 4) & 7;
31 dst_link = (config_map >> 8) & 3;
32 bus_base = (config_map >> 16) & 0xff;
34 printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n",
35 dst_node, dst_link, bus_base,
38 if ((dst_node == node) && (dst_link == link))
47 static void *smp_write_config_table(void *v)
49 static const char sig[4] = "PCMP";
50 static const char oem[8] = "COREBOOT";
51 static const char productid[12] = "S2880 ";
52 struct mp_config_table *mc;
55 unsigned char bus_chain_0;
56 unsigned char bus_8131_1;
57 unsigned char bus_8131_2;
58 unsigned char bus_8111_1;
61 unsigned apicid_8131_1;
62 unsigned apicid_8131_2;
64 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
65 memset(mc, 0, sizeof(*mc));
67 memcpy(mc->mpc_signature, sig, sizeof(sig));
68 mc->mpc_length = sizeof(*mc); /* initially just the header */
70 mc->mpc_checksum = 0; /* not yet computed */
71 memcpy(mc->mpc_oem, oem, sizeof(oem));
72 memcpy(mc->mpc_productid, productid, sizeof(productid));
75 mc->mpc_entry_count = 0; /* No entries yet... */
76 mc->mpc_lapic = LAPIC_ADDR;
81 smp_write_processors(mc);
87 bus_chain_0 = node_link_to_bus(0, 0);
88 if (bus_chain_0 == 0) {
89 printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n");
94 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x03,0));
96 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
99 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
104 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x01,0));
106 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
110 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
115 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0));
117 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
121 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
128 mptable_write_buses(mc, NULL, &bus_isa);
130 /*I/O APICs: APIC ID Version State Address*/
131 #if CONFIG_LOGICAL_CPUS==1
132 apicid_base = get_apicid_base(3);
134 apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
136 apicid_8111 = apicid_base+0;
137 apicid_8131_1 = apicid_base+1;
138 apicid_8131_2 = apicid_base+2;
139 smp_write_ioapic(mc, apicid_8111, 0x11, IO_APIC_ADDR);
143 struct resource *res;
144 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x1,1));
146 res = find_resource(dev, PCI_BASE_ADDRESS_0);
148 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
151 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x2,1));
153 res = find_resource(dev, PCI_BASE_ADDRESS_0);
155 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
161 mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
163 /*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
164 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (4<<2)|0, apicid_8111, 0x13);
168 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
170 //On Board ATI Display Adapter
171 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (6<<2)|0, apicid_8111, 0x12);
174 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|0, apicid_8111, 0x10);
175 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|1, apicid_8111, 0x11);
176 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|2, apicid_8111, 0x12); //
177 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|3, apicid_8111, 0x13); //
179 //On Board Promise Serial ATA
180 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (5<<2)|0, apicid_8111, 0x11);
183 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|0, apicid_8131_1, 0x3);
184 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|1, apicid_8131_1, 0x0);
185 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|2, apicid_8131_1, 0x1);//
186 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|3, apicid_8131_1, 0x2);//
189 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|0, apicid_8131_1, 0x2);
190 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|1, apicid_8131_1, 0x3);//
191 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|2, apicid_8131_1, 0x0);//
192 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|3, apicid_8131_1, 0x1);//
194 //On Board NIC and LSI scsi
195 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, apicid_8131_1, 0x0);
196 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|1, apicid_8131_1, 0x1);
197 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (0xa<<2)|0, apicid_8131_1, 0x0);
198 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (0xa<<2)|1, apicid_8131_1, 0x1);
200 //Slot 1 PCI-X 133/100/66
201 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|0, apicid_8131_2, 0x0);
202 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|1, apicid_8131_2, 0x1);
203 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|2, apicid_8131_2, 0x2); //
204 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|3, apicid_8131_2, 0x3); //
206 //Slot 2 PCI-X 133/100/66
207 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|0, apicid_8131_2, 0x1);
208 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|1, apicid_8131_2, 0x2);
209 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|2, apicid_8131_2, 0x3);//
210 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|3, apicid_8131_2, 0x0);//
212 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
213 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
214 smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
215 /* There is no extension information... */
217 /* Compute the checksums */
218 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
219 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
220 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
221 mc, smp_next_mpe_entry(mc));
222 return smp_next_mpe_entry(mc);
225 unsigned long write_smp_table(unsigned long addr)
228 v = smp_write_floating_table(addr);
229 return (unsigned long)smp_write_config_table(v);