check in the current code for IBM/E325, can somebody help to fix it ?
[coreboot.git] / src / mainboard / arima / hdama / 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 void *smp_write_config_table(void *v, unsigned long * processor_map)
8 {
9         static const char sig[4] = "PCMP";
10         static const char oem[8] = "LNXI    ";
11         static const char productid[12] = "HDAMA       ";
12         struct mp_config_table *mc;
13         unsigned char bus_num;
14         unsigned char bus_isa;
15         unsigned char bus_8131_1;
16         unsigned char bus_8131_2;
17         unsigned char bus_8111_1;
18
19         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
20         memset(mc, 0, sizeof(*mc));
21
22         memcpy(mc->mpc_signature, sig, sizeof(sig));
23         mc->mpc_length = sizeof(*mc); /* initially just the header */
24         mc->mpc_spec = 0x04;
25         mc->mpc_checksum = 0; /* not yet computed */
26         memcpy(mc->mpc_oem, oem, sizeof(oem));
27         memcpy(mc->mpc_productid, productid, sizeof(productid));
28         mc->mpc_oemptr = 0;
29         mc->mpc_oemsize = 0;
30         mc->mpc_entry_count = 0; /* No entries yet... */
31         mc->mpc_lapic = LAPIC_ADDR;
32         mc->mpe_length = 0;
33         mc->mpe_checksum = 0;
34         mc->reserved = 0;
35
36         smp_write_processors(mc, processor_map);
37
38         {
39                 device_t dev;
40
41                 /* 8111 */
42                 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
43                 if (dev) {
44                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
45                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
46                         bus_isa++;
47                 } else {
48                         printk_debug("ERROR - could not find PCI 1:03.0, using defaults\n");
49
50                         bus_8111_1 = 4;
51                         bus_isa = 5;
52                 }
53                 /* 8131-1 */
54                 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
55                 if (dev) {
56                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
57                 } else {
58                         printk_debug("ERROR - could not find PCI 1:01.0, using defaults\n");
59                         bus_8131_1 = 2;
60                 }
61                 /* 8131-2 */
62                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
63                 if (dev) {
64                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
65                 } else {
66                         printk_debug("ERROR - could not find PCI 1:02.0, using defaults\n");
67
68                         bus_8131_2 = 3;
69                 }
70         }
71
72         /* define bus and isa numbers */
73         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
74                 smp_write_bus(mc, bus_num, "PCI   ");
75         }
76         smp_write_bus(mc, bus_isa, "ISA   ");
77
78         /* IOAPIC handling */
79         smp_write_ioapic(mc, 2, 0x11, 0xfec00000);
80         {
81                 device_t dev;
82                 uint32_t base;
83                 /* 8131-1 apic #3 */
84                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
85                 if (dev) {
86                         base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
87                         base &= PCI_BASE_ADDRESS_MEM_MASK;
88                         smp_write_ioapic(mc, 0x03, 0x11, base);
89                 }
90                 /* 8131-2 apic #4 */
91                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
92                 if (dev) {
93                         base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
94                         base &= PCI_BASE_ADDRESS_MEM_MASK;
95                         smp_write_ioapic(mc, 0x04, 0x11, base);
96                 }
97         }
98
99         /* ISA backward compatibility interrupts  */
100         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
101                 bus_isa, 0x00, 0x02, 0x00);
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
103                 bus_isa, 0x01, 0x02, 0x01);
104         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
105                 bus_isa, 0x00, 0x02, 0x02);
106         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
107                 bus_isa, 0x03, 0x02, 0x03);
108         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
109                 bus_isa, 0x04, 0x02, 0x04);
110         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
111                 bus_isa, 0x05, 0x02, 0x05);
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
113                 bus_isa, 0x06, 0x02, 0x06);
114         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
115                 bus_isa, 0x07, 0x02, 0x07);
116         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
117                 bus_isa, 0x08, 0x02, 0x08);
118         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
119                 bus_isa, 0x09, 0x02, 0x09);
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
121                 bus_isa, 0x0a, 0x02, 0x0a);
122         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
123                 bus_isa, 0x0b, 0x02, 0x0b);
124         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
125                 bus_isa, 0x0c, 0x02, 0x0c);
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
127                 bus_isa, 0x0d, 0x02, 0x0d);
128         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
129                 bus_isa, 0x0e, 0x02, 0x0e);
130         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
131                 bus_isa, 0x0f, 0x02, 0x0f);
132
133         /* Standard local interrupt assignments */
134         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
135                 bus_isa, 0x00, MP_APIC_ALL, 0x00);
136         smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
137                 bus_isa, 0x00, MP_APIC_ALL, 0x01);
138
139         /* PCI Ints:         Type       Polarity               Trigger                  Bus ID      PCIDEVNUM|IRQ  APIC ID PIN# */
140         /* On board nics */
141         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x03<<2)|0, 0x02, 0x13);
142         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x04<<2)|0, 0x02, 0x13);
143
144         /* PCI Slot 1 */
145         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x01<<2)|0, 0x02, 0x11);
146         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x01<<2)|1, 0x02, 0x12);
147         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x01<<2)|2, 0x02, 0x13);
148         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x01<<2)|3, 0x02, 0x10);
149
150         /* PCI Slot 2 */
151         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x02<<2)|0, 0x02, 0x12);
152         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x02<<2)|1, 0x02, 0x13);
153         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x02<<2)|2, 0x02, 0x10);
154         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x02<<2)|3, 0x02, 0x11);
155
156         /* PCI Slot 3 */
157         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|0, 0x02, 0x11);
158         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|1, 0x02, 0x12);
159         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|2, 0x02, 0x13);
160         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|3, 0x02, 0x10);
161
162         /* PCI Slot 4 */
163         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (2<<2)|0, 0x02, 0x12);
164         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (2<<2)|1, 0x02, 0x13);
165         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (2<<2)|2, 0x02, 0x10);
166         smp_write_intsrc(mc, mp_INT,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (2<<2)|3, 0x02, 0x11);
167
168         /* PCI Slot 5 */
169 #warning "FIXME get the irqs right, it's just hacked to work for now"
170         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
171                 bus_8111_1, (5<<2)|0, 0x02, 0x11);
172         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
173                 bus_8111_1, (5<<2)|1, 0x02, 0x12);
174         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
175                 bus_8111_1, (5<<2)|2, 0x02, 0x13);
176         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
177                 bus_8111_1, (5<<2)|3, 0x02, 0x10);
178
179         /* PCI Slot 6 */
180 #warning "FIXME get the irqs right, it's just hacked to work for now"
181         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
182                 bus_8111_1, (4<<2)|0, 0x02, 0x10);
183         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
184                 bus_8111_1, (4<<2)|1, 0x02, 0x11);
185         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
186                 bus_8111_1, (4<<2)|2, 0x02, 0x12);
187         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
188                 bus_8111_1, (4<<2)|3, 0x02, 0x13);
189
190         /* There is no extension information... */
191
192         /* Compute the checksums */
193         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
194         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
195         printk_debug("Wrote the mp table end at: %p - %p\n",
196                      mc, smp_next_mpe_entry(mc));
197         return smp_next_mpe_entry(mc);
198 }
199
200 unsigned long write_smp_table(unsigned long addr, unsigned long *processor_map)
201 {
202         void *v;
203         v = smp_write_floating_table(addr);
204         return (unsigned long)smp_write_config_table(v, processor_map);
205 }
206