2 * This file is part of the coreboot project.
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)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <console/console.h>
25 #include <device/pci.h>
28 #include <arch/pirq_routing.h>
29 #include <cpu/amd/amdk8_sysconf.h>
31 extern unsigned char bus_isa;
32 extern unsigned char bus_ck804[6];
36 * Add one line to IRQ table.
38 static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus,
39 uint8_t devfn, uint8_t link0, uint16_t bitmap0,
40 uint8_t link1, uint16_t bitmap1, uint8_t link2,
41 uint16_t bitmap2, uint8_t link3, uint16_t bitmap3,
42 uint8_t slot, uint8_t rfu)
45 pirq_info->devfn = devfn;
46 pirq_info->irq[0].link = link0;
47 pirq_info->irq[0].bitmap = bitmap0;
48 pirq_info->irq[1].link = link1;
49 pirq_info->irq[1].bitmap = bitmap1;
50 pirq_info->irq[2].link = link2;
51 pirq_info->irq[2].bitmap = bitmap2;
52 pirq_info->irq[3].link = link3;
53 pirq_info->irq[3].bitmap = bitmap3;
54 pirq_info->slot = slot;
59 * Create the IRQ routing table.
60 * Values are derived from getpir generated code.
62 unsigned long write_pirq_routing_table(unsigned long addr)
64 struct irq_routing_table *pirq;
65 struct irq_info *pirq_info;
66 unsigned slot_num, sbdn;
70 /* get_bus_conf() will find out all bus num and APIC that share with
71 * mptable.c and mptable.c.
76 /* Align the table to be 16 byte aligned. */
80 /* This table must be betweeen 0xf0000 & 0x100000. */
81 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
83 pirq = (void *)(addr);
84 v = (uint8_t *)(addr);
86 pirq->signature = PIRQ_SIGNATURE;
87 pirq->version = PIRQ_VERSION;
88 pirq->rtr_bus = bus_ck804[0];
89 pirq->rtr_devfn = ((sbdn + 9) << 3) | 0;
90 pirq->exclusive_irqs = 0x828;
91 pirq->rtr_vendor = 0x10de;
92 pirq->rtr_device = 0x005c;
93 pirq->miniport_data = 0;
95 memset(pirq->rfu, 0, sizeof(pirq->rfu));
97 pirq_info = (void *)(&pirq->checksum + 1);
101 write_pirq_info(pirq_info, bus_ck804[1], (0 << 3) | 0, 0x3, 0xdeb8, 0x4,
102 0xdeb8, 0x1, 0xdeb8, 0x2, 0xdeb8, 4, 0);
107 write_pirq_info(pirq_info, bus_ck804[2], (0 << 3) | 0, 0x4, 0xdeb8, 0x1,
108 0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 5, 0);
113 write_pirq_info(pirq_info, bus_ck804[3], (0 << 3) | 0, 0x1, 0xdeb8, 0x2,
114 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 6, 0);
119 write_pirq_info(pirq_info, bus_ck804[4], (0x4 << 3) | 0, 0x2,
120 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0x1, 0xdeb8, 7, 0);
124 /* Slot5 - Slot7 PCI */
125 for (i = 0; i < 3; i++) {
126 write_pirq_info(pirq_info, bus_ck804[5], (0 << (6 + i)) | 0,
127 ((i + 0) % 4) + 1, 0xdeb8,
128 ((i + 1) % 4) + 1, 0xdeb8,
129 ((i + 2) % 4) + 1, 0xdeb8,
130 ((i + 3) % 4) + 1, 0xdeb8, i, 0);
136 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 9) << 3) | 0, 0x1,
137 0xdeb8, 0x2, 0xdeb8, 0x3, 0xdeb8, 0x4, 0xdeb8, 0, 0);
142 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 1) << 3) | 0, 0x2,
143 0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
148 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 2) << 3) | 0, 0x1,
149 0xdeb8, 0x2, 0xdeb8, 0, 0, 0, 0, 0, 0);
154 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 4) << 3) | 0, 0x1,
155 0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
160 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 7) << 3) | 0, 0x1,
161 0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
166 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 8) << 3) | 0, 0x1,
167 0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
172 write_pirq_info(pirq_info, bus_ck804[0], ((sbdn + 0xa) << 3) | 0, 0x1,
173 0xdeb8, 0, 0, 0, 0, 0, 0, 0, 0);
179 write_pirq_info(pirq_info, bus_ck804_1, (0x5 << 3) | 0, 0x3, 0xdeb8, 0,
180 0, 0, 0, 0, 0, 0, 0);
185 pirq->size = 32 + 16 * slot_num;
187 for (i = 0; i < pirq->size; i++)
190 sum = pirq->checksum - sum;
191 if (sum != pirq->checksum)
192 pirq->checksum = sum;
194 printk(BIOS_INFO, "done.\n");
196 return (unsigned long)pirq_info;