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