blob: 840e7b1bb53ace1e50469243a9c3013bfec430ec [file] [log] [blame]
Kerry Shehb7993512011-11-15 21:27:07 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Kerry Shehb7993512011-11-15 21:27:07 +080018 */
19
20
21#include <console/console.h>
22#include <device/pci.h>
23#include <string.h>
24#include <stdint.h>
25#include <arch/pirq_routing.h>
26#include <cpu/amd/amdfam14.h>
27
28
29static void write_pirq_info(struct irq_info *pirq_info, u8 bus, u8 devfn,
30 u8 link0, u16 bitmap0, u8 link1, u16 bitmap1,
31 u8 link2, u16 bitmap2, u8 link3, u16 bitmap3,
32 u8 slot, u8 rfu)
33{
34 pirq_info->bus = bus;
35 pirq_info->devfn = devfn;
36 pirq_info->irq[0].link = link0;
37 pirq_info->irq[0].bitmap = bitmap0;
38 pirq_info->irq[1].link = link1;
39 pirq_info->irq[1].bitmap = bitmap1;
40 pirq_info->irq[2].link = link2;
41 pirq_info->irq[2].bitmap = bitmap2;
42 pirq_info->irq[3].link = link3;
43 pirq_info->irq[3].bitmap = bitmap3;
44 pirq_info->slot = slot;
45 pirq_info->rfu = rfu;
46}
Kyösti Mälkki9c7d73c2013-09-09 09:23:19 +030047extern u8 bus_sb800[6];
Kerry Shehb7993512011-11-15 21:27:07 +080048extern unsigned long sbdn_sb800;
49
50unsigned long write_pirq_routing_table(unsigned long addr)
51{
52
53 struct irq_routing_table *pirq;
54 struct irq_info *pirq_info;
55 u32 slot_num;
56 u8 *v;
57
58 u8 sum = 0;
59 int i;
60
Kerry Shehb7993512011-11-15 21:27:07 +080061 /* Align the table to be 16 byte aligned. */
62 addr += 15;
63 addr &= ~15;
64
Kyösti Mälkki9533d832014-06-26 05:30:54 +030065 /* This table must be between 0xf0000 & 0x100000 */
Kerry Shehb7993512011-11-15 21:27:07 +080066 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
67
68 pirq = (void *)(addr);
69 v = (u8 *) (addr);
70
71 pirq->signature = PIRQ_SIGNATURE;
72 pirq->version = PIRQ_VERSION;
73
74 pirq->rtr_bus = bus_sb800[0];
75 pirq->rtr_devfn = ((sbdn_sb800 + 0x14) << 3) | 4;
76
77 pirq->exclusive_irqs = 0;
78
79 pirq->rtr_vendor = 0x1002;
80 pirq->rtr_device = 0x4384;
81
82 pirq->miniport_data = 0;
83
84 memset(pirq->rfu, 0, sizeof(pirq->rfu));
85
86 pirq_info = (void *)(&pirq->checksum + 1);
87 slot_num = 0;
88
89
90 /* pci bridge */
91 write_pirq_info(pirq_info, bus_sb800[0], ((sbdn_sb800 + 0x14) << 3) | 4,
92 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0,
93 0);
94 pirq_info++;
95
96
97
98 slot_num++;
99
100
101
102 pirq->size = 32 + 16 * slot_num;
103
104 for (i = 0; i < pirq->size; i++)
105 sum += v[i];
106
107 sum = pirq->checksum - sum;
108
109 if (sum != pirq->checksum) {
110 pirq->checksum = sum;
111 }
112
113 printk(BIOS_INFO, "write_pirq_routing_table done.\n");
114
115 return (unsigned long)pirq_info;
116
117}