bb14f3310b94c7e38e9658659ec286c6ab39d7e2
[coreboot.git] / src / mainboard / tyan / s2912_fam10 / 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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
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, MA  02110-1301 USA
20  */
21
22 /* This file was generated by getpir.c, do not modify! 
23  * (but if you do, please run checkpir on it to verify)
24  * Contains the IRQ Routing Table dumped directly from your memory , wich BIOS sets up
25
26  * Documentation at : http://www.microsoft.com/hwdev/busbios/PCIIRQ.HTM
27 */
28 #include <console/console.h>
29 #include <device/pci.h>
30 #include <string.h>
31 #include <stdint.h>
32 #include <arch/pirq_routing.h>
33
34 #include <cpu/amd/amdfam10_sysconf.h>
35 #include "mb_sysconf.h"
36
37 static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus, uint8_t devfn, uint8_t link0, uint16_t bitmap0, 
38                 uint8_t link1, uint16_t bitmap1, uint8_t link2, uint16_t bitmap2,uint8_t link3, uint16_t bitmap3,
39                 uint8_t slot, uint8_t rfu)
40 {
41         pirq_info->bus = bus; 
42         pirq_info->devfn = devfn;
43                 pirq_info->irq[0].link = link0;
44                 pirq_info->irq[0].bitmap = bitmap0;
45                 pirq_info->irq[1].link = link1;
46                 pirq_info->irq[1].bitmap = bitmap1;
47                 pirq_info->irq[2].link = link2;
48                 pirq_info->irq[2].bitmap = bitmap2;
49                 pirq_info->irq[3].link = link3;
50                 pirq_info->irq[3].bitmap = bitmap3;
51         pirq_info->slot = slot;
52         pirq_info->rfu = rfu;
53 }
54
55
56
57 unsigned long write_pirq_routing_table(unsigned long addr)
58 {
59
60         struct irq_routing_table *pirq;
61         struct irq_info *pirq_info;
62         unsigned slot_num;
63         uint8_t *v;
64         struct mb_sysconf_t *m;
65         unsigned sbdn;
66
67         uint8_t sum=0;
68         int i;
69
70         get_bus_conf(); // it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c
71         sbdn = sysconf.sbdn;
72         m = sysconf.mb;
73
74         /* Align the table to be 16 byte aligned. */
75         addr += 15;
76         addr &= ~15;
77
78         /* This table must be betweeen 0xf0000 & 0x100000 */
79         printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
80
81         pirq = (void *)(addr);
82         v = (uint8_t *)(addr);
83         
84         pirq->signature = PIRQ_SIGNATURE;
85         pirq->version  = PIRQ_VERSION;
86         
87         pirq->rtr_bus = m->bus_mcp55[0];
88         pirq->rtr_devfn = ((sbdn+6)<<3)|0;
89
90         pirq->exclusive_irqs = 0;
91         
92         pirq->rtr_vendor = 0x10de;
93         pirq->rtr_device = 0x0370;
94
95         pirq->miniport_data = 0;
96
97         memset(pirq->rfu, 0, sizeof(pirq->rfu));
98
99         pirq_info = (void *) ( &pirq->checksum + 1);
100         slot_num = 0;
101 //pci bridge
102         write_pirq_info(pirq_info, m->bus_mcp55[0], ((sbdn+6)<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
103         pirq_info++; slot_num++;
104         
105         for(i=1; i< sysconf.hc_possible_num; i++) {
106                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
107                 unsigned busn = (sysconf.pci1234[i] >> 12) & 0xff;
108                 unsigned devn = sysconf.hcdn[i] & 0xff;
109
110                 write_pirq_info(pirq_info, busn, (devn<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
111                 pirq_info++; slot_num++;
112         }
113
114 #if CONFIG_CBB
115         write_pirq_info(pirq_info, CONFIG_CBB, (0<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
116         pirq_info++; slot_num++;
117         if(sysconf.nodes>32) {
118                 write_pirq_info(pirq_info, CONFIG_CBB-1, (0<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
119                 pirq_info++; slot_num++;
120         }
121 #endif
122
123         pirq->size = 32 + 16 * slot_num; 
124
125         for (i = 0; i < pirq->size; i++)
126                 sum += v[i];    
127
128         sum = pirq->checksum - sum;
129
130         if (sum != pirq->checksum) {
131                 pirq->checksum = sum;
132         }
133
134         printk(BIOS_INFO, "done.\n");
135
136         return  (unsigned long) pirq_info;
137
138 }