We define IO_APIC_ADDR in <arch/ioapic.h>, let's use it.
[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         static const char sig[4] = "PCMP";
11         static const char oem[8] = "COREBOOT";
12         static const char productid[12] = "E325        ";
13         struct mp_config_table *mc;
14
15         unsigned char bus_num;
16         unsigned char bus_isa;
17         unsigned char bus_8111_0;
18         unsigned char bus_8111_1;
19         unsigned char bus_8131_1;
20         unsigned char bus_8131_2;
21
22         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
23         memset(mc, 0, sizeof(*mc));
24
25         memcpy(mc->mpc_signature, sig, sizeof(sig));
26         mc->mpc_length = sizeof(*mc); /* initially just the header */
27         mc->mpc_spec = 0x04;
28         mc->mpc_checksum = 0; /* not yet computed */
29         memcpy(mc->mpc_oem, oem, sizeof(oem));
30         memcpy(mc->mpc_productid, productid, sizeof(productid));
31         mc->mpc_oemptr = 0;
32         mc->mpc_oemsize = 0;
33         mc->mpc_entry_count = 0; /* No entries yet... */
34         mc->mpc_lapic = LAPIC_ADDR;
35         mc->mpe_length = 0;
36         mc->mpe_checksum = 0;
37         mc->reserved = 0;
38
39         smp_write_processors(mc);
40
41         {
42                 device_t dev;
43
44                 /* 8111 */
45                 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
46                 if (dev) {
47                         bus_8111_0 = pci_read_config8(dev, PCI_PRIMARY_BUS);
48                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
49                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
50                         bus_isa++;
51                 } else {
52                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
53                         bus_8111_0 = 1;
54                         bus_8111_1 = 4;
55                         bus_isa = 5;
56                 }
57
58                 /* 8131-1 */
59                 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
60                 if (dev) {
61                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
62
63                 } else {
64                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
65                         bus_8131_1 = 2;
66                 }
67
68                 /* 8131-2 */
69                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
70                 if (dev) {
71                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
72                 } else {
73                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
74                         bus_8131_2 = 3;
75                 }
76         }
77
78         /* define bus and isa numbers */
79         for (bus_num = 0; bus_num < bus_isa; bus_num++) {
80                 smp_write_bus(mc, bus_num, "PCI   ");
81         }
82         smp_write_bus(mc, bus_isa, "ISA   ");
83
84         /* Legacy IOAPIC #2 */
85         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
86         {
87                 device_t dev;
88                 struct resource *res;
89                 /* 8131-1 apic #3 */
90                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
91                 if (dev) {
92                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
93                         if (res) {
94                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
95                         }
96                 }
97                 /* 8131-2 apic #4 */
98                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
99                 if (dev) {
100                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
101                         if (res) {
102                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
103                         }
104                 }
105         }
106
107         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
108
109         /* PCI Ints:         Type       Polarity            Trigger                     Bus ID      PCIDEVNUM|IRQ  APIC ID PIN# */
110         /* Integrated SMBus 2.0 */
111         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|3, 0x2, 0x13);
112         /* Integrated AMD AC97 Audio */
113         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|1, 0x2, 0x11);
114
115         /* Integrated AMD USB */
116         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x00<<2)|3, 0x2, 0x13);
117
118         /* On board ATI Rage XL */
119         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x05<<2)|0, 0x2, 0x10);
120
121         /* On board Broadcom nics */
122         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|0, 0x3, 0x00);
123         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|1, 0x3, 0x01);
124
125         /* On board LSI SCSI */
126         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x02<<2)|0, 0x3, 0x02);
127
128         /* PCI Slot 1 PCIX */
129         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|0, 0x2, 0x10);
130         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|1, 0x2, 0x11);
131         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|2, 0x2, 0x12);
132         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|3, 0x2, 0x13);
133
134         /* PCI Slot 2 PCIX */
135         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|0, 0x2, 0x11);
136         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|1, 0x2, 0x12);
137         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|2, 0x2, 0x13);
138         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|3, 0x2, 0x10);
139
140         /* Standard local interrupt assignments:
141          *                    Type       Polarity               Trigger                  Bus ID   IRQ   APIC ID      PIN# */
142         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x00);
143         smp_write_lintsrc(mc, mp_NMI,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x01);
144
145         /* There is no extension information... */
146
147         /* Compute the checksums */
148         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
149         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
150         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
151                      mc, smp_next_mpe_entry(mc));
152         return smp_next_mpe_entry(mc);
153 }
154
155 unsigned long write_smp_table(unsigned long addr)
156 {
157         void *v;
158         v = smp_write_floating_table(addr);
159         return (unsigned long)smp_write_config_table(v);
160 }
161