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] = "X6DHR-iG ";
13 struct mp_config_table *mc;
14 unsigned char bus_num;
15 unsigned char bus_isa;
16 unsigned char bus_pxhd_1;
17 unsigned char bus_pxhd_2;
18 unsigned char bus_pxhd_3;
19 unsigned char bus_pxhd_4;
20 unsigned char bus_ich5r_1;
22 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
23 memset(mc, 0, sizeof(*mc));
25 memcpy(mc->mpc_signature, sig, sizeof(sig));
26 mc->mpc_length = sizeof(*mc); /* initially just the header */
28 mc->mpc_checksum = 0; /* not yet computed */
29 memcpy(mc->mpc_oem, oem, sizeof(oem));
30 memcpy(mc->mpc_productid, productid, sizeof(productid));
33 mc->mpc_entry_count = 0; /* No entries yet... */
34 mc->mpc_lapic = LAPIC_ADDR;
39 smp_write_processors(mc);
45 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
47 bus_ich5r_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
48 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
52 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1f.0, using defaults\n");
58 dev = dev_find_slot(2, PCI_DEVFN(0x0,0));
60 bus_pxhd_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
64 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
69 dev = dev_find_slot(2, PCI_DEVFN(0x00,2));
71 bus_pxhd_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
75 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
81 dev = dev_find_slot(5, PCI_DEVFN(0x0,0));
83 bus_pxhd_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
87 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
92 dev = dev_find_slot(5, PCI_DEVFN(0x00,2));
94 bus_pxhd_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
98 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
105 /* define bus and isa numbers */
106 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
107 smp_write_bus(mc, bus_num, "PCI ");
109 smp_write_bus(mc, bus_isa, "ISA ");
111 /* IOAPIC handling */
113 smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
115 struct resource *res;
118 dev = dev_find_slot(2, PCI_DEVFN(0x00,1));
120 res = find_resource(dev, PCI_BASE_ADDRESS_0);
122 smp_write_ioapic(mc, 0x03, 0x20, res->base);
126 printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.1\n");
129 dev = dev_find_slot(2, PCI_DEVFN(0x00,3));
131 res = find_resource(dev, PCI_BASE_ADDRESS_0);
133 smp_write_ioapic(mc, 0x04, 0x20, res->base);
137 printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.3\n");
140 dev = dev_find_slot(5, PCI_DEVFN(0x00,1));
142 res = find_resource(dev, PCI_BASE_ADDRESS_0);
144 smp_write_ioapic(mc, 0x05, 0x20, res->base);
148 printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.1\n");
151 dev = dev_find_slot(5, PCI_DEVFN(0x00,3));
153 res = find_resource(dev, PCI_BASE_ADDRESS_0);
155 smp_write_ioapic(mc, 0x08, 0x20, res->base);
159 printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.3\n");
163 mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
165 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
166 0x00, 0x74, 0x02, 0x10);
167 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
168 0x00, 0x76, 0x02, 0x12);
169 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
170 0x00, 0x77, 0x02, 0x17);
171 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
172 0x00, 0x75, 0x02, 0x13);
173 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
174 0x00, 0x74, 0x02, 0x10);
175 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
176 0x00, 0x7c, 0x02, 0x12);
177 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
178 0x00, 0x7d, 0x02, 0x11);
179 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
180 bus_pxhd_2, 0x08, 0x04, 0x06);
181 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
182 bus_pxhd_2, 0x09, 0x04, 0x07);
183 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
184 bus_pxhd_3, 0x08, 0x05, 0x00);
185 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
186 bus_pxhd_4, 0x08, 0x08, 0x00);
187 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
188 (bus_isa - 1), 0x04, 0x02, 0x10);
190 /* Standard local interrupt assignments */
191 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
192 bus_isa, 0x00, MP_APIC_ALL, 0x00);
193 smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
194 bus_isa, 0x00, MP_APIC_ALL, 0x01);
196 /* There is no extension information... */
198 /* Compute the checksums */
199 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
201 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
202 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
203 mc, smp_next_mpe_entry(mc));
204 return smp_next_mpe_entry(mc);
207 unsigned long write_smp_table(unsigned long addr)
210 v = smp_write_floating_table(addr);
211 return (unsigned long)smp_write_config_table(v);