Unify Local APIC address definitions
[coreboot.git] / src / mainboard / ibm / e325 / 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
12         int bus_isa;
13         unsigned char bus_8111_0;
14         unsigned char bus_8111_1;
15         unsigned char bus_8131_1;
16         unsigned char bus_8131_2;
17
18         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
19
20         mptable_init(mc, LOCAL_APIC_ADDR);
21
22         smp_write_processors(mc);
23
24         {
25                 device_t dev;
26
27                 /* 8111 */
28                 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
29                 if (dev) {
30                         bus_8111_0 = pci_read_config8(dev, PCI_PRIMARY_BUS);
31                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
32                 } else {
33                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
34                         bus_8111_0 = 1;
35                         bus_8111_1 = 4;
36                 }
37
38                 /* 8131-1 */
39                 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
40                 if (dev) {
41                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
42
43                 } else {
44                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
45                         bus_8131_1 = 2;
46                 }
47
48                 /* 8131-2 */
49                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
50                 if (dev) {
51                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
52                 } else {
53                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
54                         bus_8131_2 = 3;
55                 }
56         }
57
58         mptable_write_buses(mc, NULL, &bus_isa);
59
60         /* Legacy IOAPIC #2 */
61         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
62         {
63                 device_t dev;
64                 struct resource *res;
65                 /* 8131-1 apic #3 */
66                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
67                 if (dev) {
68                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
69                         if (res) {
70                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
71                         }
72                 }
73                 /* 8131-2 apic #4 */
74                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
75                 if (dev) {
76                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
77                         if (res) {
78                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
79                         }
80                 }
81         }
82
83         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
84
85         /* PCI Ints:         Type       Polarity            Trigger                     Bus ID      PCIDEVNUM|IRQ  APIC ID PIN# */
86         /* Integrated SMBus 2.0 */
87         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|3, 0x2, 0x13);
88         /* Integrated AMD AC97 Audio */
89         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|1, 0x2, 0x11);
90
91         /* Integrated AMD USB */
92         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x00<<2)|3, 0x2, 0x13);
93
94         /* On board ATI Rage XL */
95         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x05<<2)|0, 0x2, 0x10);
96
97         /* On board Broadcom nics */
98         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|0, 0x3, 0x00);
99         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|1, 0x3, 0x01);
100
101         /* On board LSI SCSI */
102         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x02<<2)|0, 0x3, 0x02);
103
104         /* PCI Slot 1 PCIX */
105         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|0, 0x2, 0x10);
106         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|1, 0x2, 0x11);
107         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|2, 0x2, 0x12);
108         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|3, 0x2, 0x13);
109
110         /* PCI Slot 2 PCIX */
111         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|0, 0x2, 0x11);
112         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|1, 0x2, 0x12);
113         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|2, 0x2, 0x13);
114         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|3, 0x2, 0x10);
115
116         /* Standard local interrupt assignments:
117          *                    Type       Polarity               Trigger                  Bus ID   IRQ   APIC ID      PIN# */
118         mptable_lintsrc(mc, bus_isa);
119
120         /* There is no extension information... */
121
122         /* Compute the checksums */
123         return mptable_finalize(mc);
124 }
125
126 unsigned long write_smp_table(unsigned long addr)
127 {
128         void *v;
129         v = smp_write_floating_table(addr, 0);
130         return (unsigned long)smp_write_config_table(v);
131 }
132