printk_foo -> printk(BIOS_FOO, ...)
[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 extern void get_bus_conf(void);
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 void pci_assign_irqs(unsigned, unsigned, const unsigned char *);
66
67 /**
68  * Create the IRQ routing table.
69  * Values are derived from getpir generated code.
70  */
71 unsigned long write_pirq_routing_table(unsigned long addr)
72 {
73
74         struct irq_routing_table *pirq;
75         struct irq_info *pirq_info;
76         unsigned slot_num;
77         uint8_t *v;
78
79         uint8_t sum = 0;
80         int i;
81         unsigned sbdn;
82
83         /* get_bus_conf() will find out all bus num and apic that share with 
84          * mptable.c and mptable.c
85          */
86         get_bus_conf();
87         sbdn = sysconf.sbdn;
88
89         /* Align the table to be 16 byte aligned. */
90         addr += 15;
91         addr &= ~15;
92
93         /* This table must be betweeen 0xf0000 & 0x100000 */
94         printk(BIOS_INFO, "Writing IRQ routing tables to 0x%x...", addr);
95
96         pirq = (void *)(addr);
97         v = (uint8_t *) (addr);
98
99         pirq->signature = PIRQ_SIGNATURE;
100         pirq->version = PIRQ_VERSION;
101
102         pirq->rtr_bus = bus_ck804[0];
103         pirq->rtr_devfn = ((sbdn + 9) << 3) | 0;
104
105         pirq->exclusive_irqs = 0x828;
106
107         pirq->rtr_vendor = 0x10de;
108         pirq->rtr_device = 0x005c;
109
110         pirq->miniport_data = 0;
111
112         memset(pirq->rfu, 0, sizeof(pirq->rfu));
113
114         pirq_info = (void *)(&pirq->checksum + 1);
115         slot_num = 0;
116
117 //Slot1 PCIE 16x 
118         write_pirq_info(pirq_info, bus_ck804[1], (0 << 3) | 0, 0x3, 0xdeb8, 0x4,
119                         0xdeb8, 0x1, 0xdeb8, 0x2, 0xdeb8, 4, 0);
120         pirq_info++;
121         slot_num++;
122
123 //Slot2 PCIE 1x
124         write_pirq_info(pirq_info, bus_ck804[2], (0 << 3) | 0, 0x4, 0xdeb8, 0x1,
125                         0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 5, 0);
126         pirq_info++;
127         slot_num++;
128
129 //Slot3 PCIE 1x
130         write_pirq_info(pirq_info, bus_ck804[3], (0 << 3) | 0, 0x1, 0xdeb8, 0x2,
131                         0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 6, 0);
132         pirq_info++;
133         slot_num++;
134
135 //Slot4 PCIE 4x 
136         write_pirq_info(pirq_info, bus_ck804[4], (0x4 << 3) | 0,
137                         0x2, 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0x1, 0xdeb8,
138                         7, 0);
139         pirq_info++;
140         slot_num++;
141
142 //Slot5 - 7 PCI
143         for (i = 0; i < 3; i++) {
144                 write_pirq_info(pirq_info, bus_ck804[5], (0 << (6 + i)) | 0,
145                                 ((i + 0) % 4) + 1, 0xdeb8,
146                                 ((i + 1) % 4) + 1, 0xdeb8,
147                                 ((i + 2) % 4) + 1, 0xdeb8,
148                                 ((i + 3) % 4) + 1, 0xdeb8, i, 0);
149                 pirq_info++;
150                 slot_num++;
151         }
152
153 //pci bridge
154         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 9) << 3) | 0, 0x1,
155                         0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0, 0);
156         pirq_info++;
157         slot_num++;
158
159 //smbus
160         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 1) << 3) | 0, 0x2,
161                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
162         pirq_info++;
163         slot_num++;
164
165 //usb
166         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 2) << 3) | 0, 0x1,
167                         0xdeb8, 0x2, 0xdeb8, 0, 0, 0, 0, 0, 0);
168         pirq_info++;
169         slot_num++;
170
171 //audio
172         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 4) << 3) | 0, 0x1,
173                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
174         pirq_info++;
175         slot_num++;
176 //sata
177         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 7) << 3) | 0, 0x1,
178                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
179         pirq_info++;
180         slot_num++;
181 //sata
182         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 8) << 3) | 0, 0x1,
183                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
184         pirq_info++;
185         slot_num++;
186 //nic
187         write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 0xa) << 3) | 0, 0x1,
188                         0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
189         pirq_info++;
190         slot_num++;
191
192         pirq->size = 32 + 16 * slot_num;
193
194         for (i = 0; i < pirq->size; i++)
195                 sum += v[i];
196
197         sum = pirq->checksum - sum;
198
199         if (sum != pirq->checksum) {
200                 pirq->checksum = sum;
201         }
202
203         printk(BIOS_INFO, "done.\n");
204
205 #if 0
206         unsigned char irq[4];
207         irq[0] = 0;
208         irq[1] = 0;
209         irq[2] = 0;
210         irq[3] = 0;
211
212         /* Bus, device, slots IRQs for {A,B,C,D}. */
213
214         irq[0] = 10; /* SMBus */ /* test me */
215         pci_assign_irqs(bus_ck804[0], 1, irq);
216
217         irq[0] = 10; /* USB */
218         irq[1] = 10;
219         pci_assign_irqs(bus_ck804[0], 2, irq);
220
221         irq[0] = 10; /* AC97 */
222         irq[1] = 0;
223         pci_assign_irqs(bus_ck804[0], 4, irq);
224
225         irq[0] = 11; /* SATA */
226         pci_assign_irqs(bus_ck804[0], 7, irq);
227
228         irq[0] = 5; /* SATA */
229         pci_assign_irqs(bus_ck804[0], 8, irq);
230
231         irq[0] = 10; /* Ethernet */
232         pci_assign_irqs(bus_ck804[0], 10, irq);
233
234         
235         /* physical slots */
236
237         irq[0] = 5; /* PCI E1 - x1 */
238         pci_assign_irqs(bus_ck804[2], 0, irq);
239
240         irq[0] = 11; /* PCI E2 - x16 */
241         pci_assign_irqs(bus_ck804[3], 0, irq);
242         
243         /* AGP-on-PCI "AGR" ignored */
244
245         irq[0] = 10; /* PCI1 */
246         irq[1] = 11;
247         irq[2] = 5;
248         irq[3] = 0;
249         pci_assign_irqs(bus_ck804[1], 7, irq);
250
251         irq[0] = 11; /* PCI2 */
252         irq[1] = 10;
253         irq[2] = 5;
254         irq[3] = 0;
255         pci_assign_irqs(bus_ck804[1], 8, irq);
256
257         irq[0] = 5; /* PCI3 */
258         irq[1] = 10;
259         irq[2] = 11;
260         irq[3] = 0;
261         pci_assign_irqs(bus_ck804[1], 9, irq);
262 #endif  
263
264         return (unsigned long)pirq_info;
265 }