Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / msi / ms7135 / irq_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 AMD
5  * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6  * Copyright (C) 2007 Philipp Degler <pdegler@rumms.uni-mannheim.de>
7  * (Thanks to LSRA University of Mannheim for their support)
8  * Copyright (C) 2008 Jonathan A. Kollasch <jakllsch@kollasch.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 /* Documentation at: http://www.microsoft.com/hwdev/busbios/PCIIRQ.HTM */
26
27 /* This is probably not right, feel free to fix this if you don't want
28  * to use the mptable.
29  */
30
31 #include <console/console.h>
32 #include <device/pci.h>
33 #include <string.h>
34 #include <stdint.h>
35 #include <arch/pirq_routing.h>
36 #include <cpu/amd/amdk8_sysconf.h>
37
38 extern unsigned char bus_isa;
39 extern unsigned char bus_ck804[6];
40
41
42 /**
43  * Add one line to IRQ table.
44  */
45 static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus,
46                             uint8_t devfn, uint8_t link0, uint16_t bitmap0,
47                             uint8_t link1, uint16_t bitmap1, uint8_t link2,
48                             uint16_t bitmap2, uint8_t link3, uint16_t bitmap3,
49                             uint8_t slot, uint8_t rfu)
50 {
51         pirq_info->bus = bus;
52         pirq_info->devfn = devfn;
53         pirq_info->irq[0].link = link0;
54         pirq_info->irq[0].bitmap = bitmap0;
55         pirq_info->irq[1].link = link1;
56         pirq_info->irq[1].bitmap = bitmap1;
57         pirq_info->irq[2].link = link2;
58         pirq_info->irq[2].bitmap = bitmap2;
59         pirq_info->irq[3].link = link3;
60         pirq_info->irq[3].bitmap = bitmap3;
61         pirq_info->slot = slot;
62         pirq_info->rfu = rfu;
63 }
64
65 /**
66  * Create the IRQ routing table.
67  * Values are derived from getpir generated code.
68  */
69 unsigned long write_pirq_routing_table(unsigned long addr)
70 {
71
72         struct irq_routing_table *pirq;
73         struct irq_info *pirq_info;
74         unsigned slot_num;
75         uint8_t *v;
76
77         uint8_t sum = 0;
78         int i;
79         unsigned sbdn;
80
81         /* get_bus_conf() will find out all bus num and apic that share with
82          * mptable.c and mptable.c
83          */
84         get_bus_conf();
85         sbdn = sysconf.sbdn;
86
87         /* Align the table to be 16 byte aligned. */
88         addr += 15;
89         addr &= ~15;
90
91         /* This table must be betweeen 0xf0000 & 0x100000 */
92         printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
93
94         pirq = (void *)(addr);
95         v = (uint8_t *) (addr);
96
97         pirq->signature = PIRQ_SIGNATURE;
98         pirq->version = PIRQ_VERSION;
99
100         pirq->rtr_bus = bus_ck804[0];
101         pirq->rtr_devfn = ((sbdn + 9) << 3) | 0;
102
103         pirq->exclusive_irqs = 0x828;
104
105         pirq->rtr_vendor = 0x10de;
106         pirq->rtr_device = 0x005c;
107
108         pirq->miniport_data = 0;
109
110         memset(pirq->rfu, 0, sizeof(pirq->rfu));
111
112         pirq_info = (void *)(&pirq->checksum + 1);
113         slot_num = 0;
114
115 //Slot1 PCIE 16x
116         write_pirq_info(pirq_info, bus_ck804[1], (0 << 3) | 0, 0x3, 0xdeb8, 0x4,
117                         0xdeb8, 0x1, 0xdeb8, 0x2, 0xdeb8, 4, 0);
118         pirq_info++;
119         slot_num++;
120
121 //Slot2 PCIE 1x
122         write_pirq_info(pirq_info, bus_ck804[2], (0 << 3) | 0, 0x4, 0xdeb8, 0x1,
123                         0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 5, 0);
124         pirq_info++;
125         slot_num++;
126
127 //Slot3 PCIE 1x
128         write_pirq_info(pirq_info, bus_ck804[3], (0 << 3) | 0, 0x1, 0xdeb8, 0x2,
129                         0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 6, 0);
130         pirq_info++;
131         slot_num++;
132
133 //Slot4 PCIE 4x
134         write_pirq_info(pirq_info, bus_ck804[4], (0x4 << 3) | 0,
135                         0x2, 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0x1, 0xdeb8,
136                         7, 0);
137         pirq_info++;
138         slot_num++;
139
140 //Slot5 - 7 PCI
141         for (i = 0; i < 3; i++) {
142                 write_pirq_info(pirq_info, bus_ck804[5], (0 << (6 + i)) | 0,
143                                 ((i + 0) % 4) + 1, 0xdeb8,
144                                 ((i + 1) % 4) + 1, 0xdeb8,
145                                 ((i + 2) % 4) + 1, 0xdeb8,
146                                 ((i + 3) % 4) + 1, 0xdeb8, i, 0);
147                 pirq_info++;
148                 slot_num++;
149         }
150
151 //pci bridge
152         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 9) << 3) | 0, 0x1,
153                         0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0, 0);
154         pirq_info++;
155         slot_num++;
156
157 //smbus
158         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 1) << 3) | 0, 0x2,
159                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
160         pirq_info++;
161         slot_num++;
162
163 //usb
164         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 2) << 3) | 0, 0x1,
165                         0xdeb8, 0x2, 0xdeb8, 0, 0, 0, 0, 0, 0);
166         pirq_info++;
167         slot_num++;
168
169 //audio
170         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 4) << 3) | 0, 0x1,
171                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
172         pirq_info++;
173         slot_num++;
174 //sata
175         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 7) << 3) | 0, 0x1,
176                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
177         pirq_info++;
178         slot_num++;
179 //sata
180         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 8) << 3) | 0, 0x1,
181                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
182         pirq_info++;
183         slot_num++;
184 //nic
185         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 0xa) << 3) | 0, 0x1,
186                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
187         pirq_info++;
188         slot_num++;
189
190         pirq->size = 32 + 16 * slot_num;
191
192         for (i = 0; i < pirq->size; i++)
193                 sum += v[i];
194
195         sum = pirq->checksum - sum;
196
197         if (sum != pirq->checksum) {
198                 pirq->checksum = sum;
199         }
200
201         printk(BIOS_INFO, "done.\n");
202
203 #if 0
204         unsigned char irq[4];
205         irq[0] = 0;
206         irq[1] = 0;
207         irq[2] = 0;
208         irq[3] = 0;
209
210         /* Bus, device, slots IRQs for {A,B,C,D}. */
211
212         irq[0] = 10; /* SMBus */ /* test me */
213         pci_assign_irqs(bus_ck804[0], 1, irq);
214
215         irq[0] = 10; /* USB */
216         irq[1] = 10;
217         pci_assign_irqs(bus_ck804[0], 2, irq);
218
219         irq[0] = 10; /* AC97 */
220         irq[1] = 0;
221         pci_assign_irqs(bus_ck804[0], 4, irq);
222
223         irq[0] = 11; /* SATA */
224         pci_assign_irqs(bus_ck804[0], 7, irq);
225
226         irq[0] = 5; /* SATA */
227         pci_assign_irqs(bus_ck804[0], 8, irq);
228
229         irq[0] = 10; /* Ethernet */
230         pci_assign_irqs(bus_ck804[0], 10, irq);
231
232
233         /* physical slots */
234
235         irq[0] = 5; /* PCI E1 - x1 */
236         pci_assign_irqs(bus_ck804[2], 0, irq);
237
238         irq[0] = 11; /* PCI E2 - x16 */
239         pci_assign_irqs(bus_ck804[3], 0, irq);
240
241         /* AGP-on-PCI "AGR" ignored */
242
243         irq[0] = 10; /* PCI1 */
244         irq[1] = 11;
245         irq[2] = 5;
246         irq[3] = 0;
247         pci_assign_irqs(bus_ck804[1], 7, irq);
248
249         irq[0] = 11; /* PCI2 */
250         irq[1] = 10;
251         irq[2] = 5;
252         irq[3] = 0;
253         pci_assign_irqs(bus_ck804[1], 8, irq);
254
255         irq[0] = 5; /* PCI3 */
256         irq[1] = 10;
257         irq[2] = 11;
258         irq[3] = 0;
259         pci_assign_irqs(bus_ck804[1], 9, irq);
260 #endif
261
262         return (unsigned long)pirq_info;
263 }