1452c9900e8aea2c4b7d95b2a50045df4e9c41fc
[coreboot.git] / src / mainboard / ibm / e326 / 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                 } else {
63                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
64                         bus_8131_1 = 2;
65                 }
66
67                 /* 8131-2 */
68                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
69                 if (dev) {
70                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
71                 } else {
72                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
73                         bus_8131_2 = 3;
74                 }
75         }
76
77         /* define bus and isa numbers */
78         for (bus_num = 0; bus_num < bus_isa; bus_num++) {
79                 smp_write_bus(mc, bus_num, "PCI   ");
80         }
81         smp_write_bus(mc, bus_isa, "ISA   ");
82
83         /* Legacy IOAPIC #2 */
84         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
85         {
86                 device_t dev;
87                 struct resource *res;
88                 /* 8131-1 apic #3 */
89                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
90                 if (dev) {
91                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
92                         if (res) {
93                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
94                         }
95                 }
96                 /* 8131-2 apic #4 */
97                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
98                 if (dev) {
99                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
100                         if (res) {
101                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
102                         }
103                 }
104         }
105
106         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
107
108         /* PCI Ints:         Type       Polarity            Trigger                     Bus ID      PCIDEVNUM|IRQ  APIC ID PIN# */
109         /* Integrated SMBus 2.0 */
110         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|3, 0x2, 0x13);
111         /* Integrated AMD AC97 Audio */
112         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|1, 0x2, 0x11);
113
114         /* Integrated AMD USB */
115         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x00<<2)|3, 0x2, 0x13);
116
117         /* On board ATI Rage XL */
118         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x05<<2)|0, 0x2, 0x10);
119
120         /* On board Broadcom nics */
121         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|0, 0x3, 0x00);
122         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|1, 0x3, 0x01);
123
124         /* On board LSI SCSI */
125         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x02<<2)|0, 0x3, 0x02);
126
127         /* PCI Slot 1 PCIX */
128         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|0, 0x2, 0x10);
129         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|1, 0x2, 0x11);
130         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|2, 0x2, 0x12);
131         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|3, 0x2, 0x13);
132
133         /* PCI Slot 2 PCIX */
134         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|0, 0x2, 0x11);
135         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|1, 0x2, 0x12);
136         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|2, 0x2, 0x13);
137         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|3, 0x2, 0x10);
138
139         /* Standard local interrupt assignments:
140          *                    Type       Polarity               Trigger                  Bus ID   IRQ   APIC ID      PIN# */
141         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x00);
142         smp_write_lintsrc(mc, mp_NMI,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x01);
143
144         /* There is no extension information... */
145
146         /* Compute the checksums */
147         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
148         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
149         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
150                      mc, smp_next_mpe_entry(mc));
151         return smp_next_mpe_entry(mc);
152 }
153
154 unsigned long write_smp_table(unsigned long addr)
155 {
156         void *v;
157         v = smp_write_floating_table(addr);
158         return (unsigned long)smp_write_config_table(v);
159 }
160