Factor out common mptable code to mptable_init().
[coreboot.git] / src / mainboard / supermicro / x6dai_g / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
5 #include <string.h>
6 #include <stdint.h>
7
8 static void *smp_write_config_table(void *v)
9 {
10         struct mp_config_table *mc;
11         unsigned char bus_num;
12         unsigned char bus_isa;
13         unsigned char bus_6300;
14
15         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
16
17         mptable_init(mc, "X6DAI-G     ", LAPIC_ADDR);
18
19         smp_write_processors(mc);
20
21         {
22                 device_t dev;
23
24                 /* southbridge */
25                 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
26                 if (dev) {
27                         bus_6300 = pci_read_config8(dev, PCI_SECONDARY_BUS);
28                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
29                         bus_isa++;
30                 }
31                 else {
32                         printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
33                         bus_6300 = 5;
34                         bus_isa = 6;
35                 }
36         }
37
38         /* define bus and isa numbers */
39         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
40                 smp_write_bus(mc, bus_num, "PCI   ");
41         }
42         smp_write_bus(mc, bus_isa, "ISA   ");
43
44         /* IOAPIC handling */
45
46         smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
47         smp_write_ioapic(mc, 3, 0x20, IO_APIC_ADDR + 0x10000);
48
49         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
50
51         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
52                 0x00, 0x74, 0x02, 0x10);
53         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
54                 0x00, 0x77, 0x02, 0x17);
55         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
56                 0x00, 0x75, 0x02, 0x13);
57         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
58                 0x00, 0x7c, 0x02, 0x12);
59         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
60                 0x00, 0x7d, 0x02, 0x11);
61         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
62                 0x00, 0x7d, 0x02, 0x11);
63         /* Slot 1 function 0 */
64         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
65                 4, 0x04, 0x03, 0x00);
66         /* Slot 2 function 0 */
67         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
68                 4, 0x0c, 0x03, 0x01);
69         /* Slot 3 function 0 */
70         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
71                 bus_6300, 0x20, 0x02, 0x14);
72         /* Slot 4 function 0 */
73         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
74                 bus_6300, 0x08, 0x02, 0x15);
75         /* On board NIC */
76         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
77                 bus_6300, 0x0c, 0x02, 0x16);
78
79         /* Standard local interrupt assignments */
80 //      smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
81 //              bus_isa, 0x00, MP_APIC_ALL, 0x00);
82         smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
83                 bus_isa, 0x00, MP_APIC_ALL, 0x01);
84
85         /* There is no extension information... */
86
87         /* Compute the checksums */
88         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
89
90         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
91         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
92                 mc, smp_next_mpe_entry(mc));
93         return smp_next_mpe_entry(mc);
94 }
95
96 unsigned long write_smp_table(unsigned long addr)
97 {
98         void *v;
99         v = smp_write_floating_table(addr);
100         return (unsigned long)smp_write_config_table(v);
101 }
102