5ee1d1f44b772b00eb733eb3430c15c5eacc32f9
[coreboot.git] / src / mainboard / intel / eagleheights / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2008 coresystems GmbH
5  * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; version 2 of
10  * the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20  * MA 02110-1301 USA
21  */
22
23
24 #include <console/console.h>
25 #include <arch/io.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/pci.h>
28 #include <string.h>
29 #include <stdint.h>
30
31 // Generate MP-table IRQ numbers for PCI devices.
32 #define IO_APIC0 2
33
34 #define INT_A   0
35 #define INT_B   1
36 #define INT_C   2
37 #define INT_D   3
38 #define PCI_IRQ(dev, intLine)   (((dev)<<2) | intLine)
39
40 #define PIRQ_A 16
41 #define PIRQ_B 17
42 #define PIRQ_C 18
43 #define PIRQ_D 19
44 #define PIRQ_E 20
45 #define PIRQ_F 21
46 #define PIRQ_G 22
47 #define PIRQ_H 23
48
49 // RCBA
50 #define RCBA 0xF0
51
52 #define RCBA_D31IP 0x3100
53 #define RCBA_D30IP 0x3104
54 #define RCBA_D29IP 0x3108
55 #define RCBA_D28IP 0x310C
56 #define RCBA_D31IR 0x3140
57 #define RCBA_D30IR 0x3142
58 #define RCBA_D29IR 0x3144
59 #define RCBA_D28IR 0x3146
60
61 static void *smp_write_config_table(void *v)
62 {
63         static const char sig[4] = "PCMP";
64         static const char oem[8] = "COREBOOT";
65         static const char productid[12] = "EagleHeights";
66         struct mp_config_table *mc;
67         unsigned char bus_num, bus_chipset, bus_isa, bus_pci;
68         unsigned char bus_pcie_a, bus_pcie_a1, bus_pcie_b;
69         int i;
70         uint32_t pin, route;
71         device_t dev;
72         struct resource *res;
73         unsigned long rcba;
74
75         dev = dev_find_slot(0, PCI_DEVFN(0x1F,0));
76         res = find_resource(dev, RCBA);
77         if (!res) {
78           return NULL;
79         }
80         rcba = res->base;
81
82         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
83         memset(mc, 0, sizeof(*mc));
84
85         memcpy(mc->mpc_signature, sig, sizeof(sig));
86         mc->mpc_length = sizeof(*mc); /* initially just the header */
87         mc->mpc_spec = 0x04;
88         mc->mpc_checksum = 0; /* not yet computed */
89         memcpy(mc->mpc_oem, oem, sizeof(oem));
90         memcpy(mc->mpc_productid, productid, sizeof(productid));
91         mc->mpc_oemptr = 0;
92         mc->mpc_oemsize = 0;
93         mc->mpc_entry_count = 0; /* No entries yet... */
94         mc->mpc_lapic = LAPIC_ADDR;
95         mc->mpe_length = 0;
96         mc->mpe_checksum = 0;
97         mc->reserved = 0;
98
99         smp_write_processors(mc);
100
101         /* Get bus numbers */
102         bus_chipset = 0;
103
104         /* PCI */
105         dev = dev_find_slot(0, PCI_DEVFN(0x1E,0));
106         if (dev) {
107           bus_pci = pci_read_config8(dev, PCI_SECONDARY_BUS);
108           bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
109           bus_isa++;
110         } else {
111           printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
112           bus_pci = 6;
113           bus_isa = 7;
114         }
115
116         dev = dev_find_slot(0, PCI_DEVFN(2,0));
117         if(dev) {
118           bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS);
119         } else {
120           printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A  0:2.0, using defaults\n");
121           bus_pcie_a = 1;
122         }
123
124         dev = dev_find_slot(0, PCI_DEVFN(3,0));
125         if(dev) {
126           bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
127         } else {
128           printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
129           bus_pcie_a1 = 2;
130         }
131
132         dev = dev_find_slot(0, PCI_DEVFN(0x1C,0));
133         if(dev) {
134           bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS);
135         } else {
136           printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
137           bus_pcie_b = 3;
138         }
139
140         /*Bus: Bus ID Type*/
141         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
142           smp_write_bus(mc, bus_num, "PCI   ");
143         }
144         smp_write_bus(mc, bus_isa, "ISA   ");
145
146         /*I/O APICs: APIC ID Version State Address*/
147         smp_write_ioapic(mc, 2, 0x20, 0xfec00000);
148         /*
149         {
150                 device_t dev;
151                 struct resource *res;
152                 dev = dev_find_slot(1, PCI_DEVFN(0x1e,0));
153                 if (dev) {
154                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
155                         if (res) {
156                                 smp_write_ioapic(mc, 3, 0x20, res->base);
157                         }
158                 }
159                 dev = dev_find_slot(1, PCI_DEVFN(0x1c,0));
160                 if (dev) {
161                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
162                         if (res) {
163                                 smp_write_ioapic(mc, 4, 0x20, res->base);
164                         }
165                 }
166                 dev = dev_find_slot(4, PCI_DEVFN(0x1e,0));
167                 if (dev) {
168                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
169                         if (res) {
170                                 smp_write_ioapic(mc, 5, 0x20, res->base);
171                         }
172                 }
173                 dev = dev_find_slot(4, PCI_DEVFN(0x1c,0));
174                 if (dev) {
175                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
176                         if (res) {
177                                 smp_write_ioapic(mc, 8, 0x20, res->base);
178                         }
179                 }
180         }
181         */
182         mptable_add_isa_interrupts(mc, bus_isa, IO_APIC0, 0);
183
184         /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
185         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 0);
186         smp_write_intsrc(mc, mp_NMI,    MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 1);
187
188         /* Internal PCI device for i3100 */
189
190         /* EDMA
191          */
192         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(1, INT_A), IO_APIC0, PIRQ_A);
193
194         /* PCIe Port A
195          */
196         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(2, INT_A), IO_APIC0, PIRQ_A);
197
198         /* PCIe Port A1
199          */
200         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(3, INT_A), IO_APIC0, PIRQ_A);
201
202         /* PCIe Port B
203          */
204         for(i = 0; i < 4; i++) {
205           pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F;
206           if(pin > 0) {
207             pin -= 1;
208             route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07);
209             smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route);
210           }
211         }
212
213         /* USB 1.1 : device 29, function 0, 1
214          */
215         for(i = 0; i < 2; i++) {
216           pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F;
217           if(pin > 0) {
218             pin -= 1;
219             route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
220             smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
221           }
222         }
223
224         /* USB 2.0 : device 29, function 7
225         */
226         pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F;
227         if(pin > 0) {
228           pin -= 1;
229           route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
230           smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
231         }
232
233         /* SATA : device 31 function 2
234            SMBus : device 31 function 3
235            Performance counters : device 31 function 4
236          */
237         for(i = 2; i < 5; i++) {
238           pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F;
239           if(pin > 0) {
240             pin -= 1;
241             route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07);
242             smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route);
243           }
244         }
245
246         /* SLOTS */
247
248         /* PCIe 4x slot A
249          */
250         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
251         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
252         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
253         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
254
255         /* PCIe 4x slot A1
256          */
257         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
258         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
259         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
260         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
261
262         /* PCIe 4x slot B
263          */
264         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
265         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
266         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
267         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
268
269         /* PCI slot
270          */
271         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
272         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
273         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
274         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
275
276         /* There is no extension information... */
277
278         /* Compute the checksums */
279         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
280         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
281         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
282                 mc, smp_next_mpe_entry(mc));
283         return smp_next_mpe_entry(mc);
284 }
285
286 unsigned long write_smp_table(unsigned long addr)
287 {
288         void *v;
289         v = smp_write_floating_table(addr);
290         return (unsigned long)smp_write_config_table(v);
291 }