1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
8 static void *smp_write_config_table(void *v)
10 static const char sig[4] = "PCMP";
11 static const char oem[8] = "COREBOOT";
12 static const char productid[12] = "DK8X ";
13 struct mp_config_table *mc;
14 unsigned char bus_num;
15 unsigned char bus_isa;
16 unsigned char bus_8131_1;
17 unsigned char bus_8131_2;
18 unsigned char bus_8111_1;
20 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
21 memset(mc, 0, sizeof(*mc));
23 memcpy(mc->mpc_signature, sig, sizeof(sig));
24 mc->mpc_length = sizeof(*mc); /* initially just the header */
26 mc->mpc_checksum = 0; /* not yet computed */
27 memcpy(mc->mpc_oem, oem, sizeof(oem));
28 memcpy(mc->mpc_productid, productid, sizeof(productid));
31 mc->mpc_entry_count = 0; /* No entries yet... */
32 mc->mpc_lapic = LAPIC_ADDR;
37 smp_write_processors(mc);
43 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
45 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
46 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
50 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
56 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
58 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
62 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
67 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
69 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
73 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
79 /* define bus and isa numbers */
80 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
81 smp_write_bus(mc, bus_num, "PCI ");
83 smp_write_bus(mc, bus_isa, "ISA ");
86 smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
91 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
93 res = find_resource(dev, PCI_BASE_ADDRESS_0);
95 smp_write_ioapic(mc, 0x03, 0x11, res->base);
99 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
101 res = find_resource(dev, PCI_BASE_ADDRESS_0);
103 smp_write_ioapic(mc, 0x04, 0x11, res->base);
108 mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
110 /* Standard local interrupt assignments */
111 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
112 bus_isa, 0x00, MP_APIC_ALL, 0x00);
113 smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
114 bus_isa, 0x00, MP_APIC_ALL, 0x01);
118 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
119 bus_8131_2, (1<<2)|0, 0x02, 0x11);
120 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
121 bus_8131_2, (1<<2)|1, 0x02, 0x12);
122 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
123 bus_8131_2, (1<<2)|2, 0x02, 0x13);
124 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
125 bus_8131_2, (1<<2)|3, 0x02, 0x10);
128 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
129 bus_8131_2, (2<<2)|0, 0x02, 0x12);
130 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
131 bus_8131_2, (2<<2)|1, 0x02, 0x13);
132 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
133 bus_8131_2, (2<<2)|2, 0x02, 0x10);
134 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
135 bus_8131_2, (2<<2)|3, 0x02, 0x11);
138 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
139 bus_8131_1, (1<<2)|0, 0x02, 0x11);
140 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
141 bus_8131_1, (1<<2)|1, 0x02, 0x12);
142 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
143 bus_8131_1, (1<<2)|2, 0x02, 0x13);
144 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
145 bus_8131_1, (1<<2)|3, 0x02, 0x10);
148 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
149 bus_8131_1, (2<<2)|0, 0x02, 0x12);
150 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
151 bus_8131_1, (2<<2)|1, 0x02, 0x13);
152 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
153 bus_8131_1, (2<<2)|2, 0x02, 0x10);
154 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
155 bus_8131_1, (2<<2)|3, 0x02, 0x11);
158 // FIXME get the irqs right, it's just hacked to work for now
159 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
160 bus_8111_1, (5<<2)|0, 0x02, 0x11);
161 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
162 bus_8111_1, (5<<2)|1, 0x02, 0x12);
163 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
164 bus_8111_1, (5<<2)|2, 0x02, 0x13);
165 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
166 bus_8111_1, (5<<2)|3, 0x02, 0x10);
169 // FIXME get the irqs right, it's just hacked to work for now
170 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
171 bus_8111_1, (4<<2)|0, 0x02, 0x10);
172 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
173 bus_8111_1, (4<<2)|1, 0x02, 0x11);
174 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
175 bus_8111_1, (4<<2)|2, 0x02, 0x12);
176 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
177 bus_8111_1, (4<<2)|3, 0x02, 0x13);
180 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
181 bus_8131_1, (3<<2)|0, 0x02, 0x13);
182 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
183 bus_8131_1, (4<<2)|0, 0x02, 0x13);
185 /* There is no extension information... */
187 /* Compute the checksums */
188 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
189 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
190 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
191 mc, smp_next_mpe_entry(mc));
192 return smp_next_mpe_entry(mc);
195 unsigned long write_smp_table(unsigned long addr)
198 v = smp_write_floating_table(addr);
199 return (unsigned long)smp_write_config_table(v);