Unify Local APIC address definitions
[coreboot.git] / src / mainboard / kontron / 986lcd-m / mptable.c
index bdba295bfca9512b016758bf047238f3f17a15fe..03f737046feac296f87f367563ae063d04548c33 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-
 #include <device/device.h>
 #include <device/pci.h>
 #include <console/console.h>
 #include <arch/smp/mpspec.h>
+#include <arch/ioapic.h>
 #include <string.h>
 #include <stdint.h>
 
 static void *smp_write_config_table(void *v)
 {
-        static const char sig[4] = "PCMP";
-        static const char oem[8] = "COREBOOT";
-        static const char productid[12] = "986LCD-M    ";
         struct mp_config_table *mc;
        struct device *riser = NULL, *firewire = NULL;
-       int i;
-       int max_pci_bus, firewire_bus = 0, riser_bus = 0, isa_bus;
+       int firewire_bus = 0, riser_bus = 0, isa_bus;
        int ioapic_id;
 
         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
-        memset(mc, 0, sizeof(*mc));
-
-        memcpy(mc->mpc_signature, sig, sizeof(sig));
-        mc->mpc_length = sizeof(*mc); /* initially just the header */
-        mc->mpc_spec = 0x04;
-        mc->mpc_checksum = 0; /* not yet computed */
-        memcpy(mc->mpc_oem, oem, sizeof(oem));
-        memcpy(mc->mpc_productid, productid, sizeof(productid));
-        mc->mpc_oemptr = 0;
-        mc->mpc_oemsize = 0;
-        mc->mpc_entry_count = 0; /* No entries yet... */
-        mc->mpc_lapic = LAPIC_ADDR;
-        mc->mpe_length = 0;
-        mc->mpe_checksum = 0;
-        mc->reserved = 0;
+
+       mptable_init(mc, LOCAL_APIC_ADDR);
 
         smp_write_processors(mc);
-       max_pci_bus=0;
 
        firewire = dev_find_device(0x104c, 0x8023, 0);
        if (firewire) {
                firewire_bus = firewire->bus->secondary;
-               printk(BIOS_SPEW, "Firewire device is on bus %x\n",
-                               firewire_bus);
-               max_pci_bus = firewire_bus;
        }
 
        // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the
@@ -70,23 +49,14 @@ static void *smp_write_config_table(void *v)
        if (!riser)
                riser = dev_find_device(0x3388, 0x0022, 0);
        if (riser) {
-               riser_bus = riser->link[0].secondary;
-               printk(BIOS_SPEW, "Riser bus is %x\n", riser_bus);
-               max_pci_bus = riser_bus;
+               riser_bus = riser->link_list->secondary;
        }
 
-       /* ISA bus follows */
-       isa_bus = max_pci_bus + 1;
-
-       /* Bus:         Bus ID  Type */
-       for (i=0; i <= max_pci_bus; i++)
-               smp_write_bus(mc, i, "PCI   ");
-
-       smp_write_bus(mc, isa_bus, "ISA   ");
+       mptable_write_buses(mc, NULL, &isa_bus);
 
        /* I/O APICs:   APIC ID Version State           Address */
        ioapic_id = 2;
-       smp_write_ioapic(mc, ioapic_id, 0x20, 0xfec00000);
+       smp_write_ioapic(mc, ioapic_id, 0x20, IO_APIC_ADDR);
 
        /* Legacy Interrupts */
        mptable_add_isa_interrupts(mc, isa_bus, ioapic_id, 0);
@@ -132,38 +102,15 @@ static void *smp_write_config_table(void *v)
        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x2, 0x0, ioapic_id, 0x10);
 
        /* Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
-       smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x0);
-       smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x1);
+       mptable_lintsrc(mc, isa_bus);
 
        /* Compute the checksums */
-       mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
-       mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
-
-       printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n", mc, smp_next_mpe_entry(mc));
-
-       return smp_next_mpe_entry(mc);
-}
-
-/* MP table generation in coreboot is not very well designed;
- * One of the issues is that it knows nothing about Virtual
- * Wire mode, which everyone uses since a decade or so. This
- * function fixes up our floating table. This spares us doing
- * a half-baked fix of adding a new parameter to 200+ calls
- * to smp_write_floating_table()
- */
-static void fixup_virtual_wire(void *v)
-{
-        struct intel_mp_floating *mf = v;
-
-        mf->mpf_checksum = 0;
-        mf->mpf_feature2 = MP_FEATURE_VIRTUALWIRE;
-        mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
+       return mptable_finalize(mc);
 }
 
 unsigned long write_smp_table(unsigned long addr)
 {
        void *v;
-       v = smp_write_floating_table(addr);
-       fixup_virtual_wire(v);
+       v = smp_write_floating_table(addr, 1);
        return (unsigned long)smp_write_config_table(v);
 }