1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <device/pci.h>
6 #if CONFIG_LOGICAL_CPUS==1
7 #include <cpu/amd/multicore.h>
10 static unsigned node_link_to_bus(unsigned node, unsigned link)
15 dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
19 for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
24 config_map = pci_read_config32(dev, reg);
25 if ((config_map & 3) != 3) {
28 dst_node = (config_map >> 4) & 7;
29 dst_link = (config_map >> 8) & 3;
30 bus_base = (config_map >> 16) & 0xff;
32 printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n",
33 dst_node, dst_link, bus_base,
36 if ((dst_node == node) && (dst_link == link))
44 static void *smp_write_config_table(void *v)
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;
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;
59 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
60 memset(mc, 0, sizeof(*mc));
62 memcpy(mc->mpc_signature, sig, sizeof(sig));
63 mc->mpc_length = sizeof(*mc); /* initially just the header */
65 mc->mpc_checksum = 0; /* not yet computed */
66 memcpy(mc->mpc_oem, oem, sizeof(oem));
67 memcpy(mc->mpc_productid, productid, sizeof(productid));
70 mc->mpc_entry_count = 0; /* No entries yet... */
71 mc->mpc_lapic = LAPIC_ADDR;
76 smp_write_processors(mc);
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");
89 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x04,0));
91 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
92 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
94 printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
97 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
103 dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0));
105 bus_8151_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
106 printk(BIOS_DEBUG, "bus_8151_1=%d\n",bus_8151_1);
110 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
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 ");
123 smp_write_bus(mc, bus_isa, "ISA ");
125 /*I/O APICs: APIC ID Version State Address*/
126 #if CONFIG_LOGICAL_CPUS==1
127 apicid_base = get_apicid_base(1);
129 apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
131 apicid_8111 = apicid_base+0;
132 smp_write_ioapic(mc, apicid_8111, 0x11, 0xfec00000);
134 mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
136 /*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
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);
142 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
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);
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);
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);
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);
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); //
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); //
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); //
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); //
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); //
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... */
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);
205 unsigned long write_smp_table(unsigned long addr)
208 v = smp_write_floating_table(addr);
209 return (unsigned long)smp_write_config_table(v);