blob: d7e6385dfb4b5fa82f17c1475abf3ed32200a075 [file] [log] [blame]
Dave Frodinc43bce52014-12-03 08:22:46 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 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.
Dave Frodinc43bce52014-12-03 08:22:46 -070014 */
15
16#include <console/console.h>
17#include <device/pci.h>
18#include <string.h>
19#include <stdint.h>
20#include <arch/pirq_routing.h>
21#include <cpu/amd/amdfam16.h>
22
23static void write_pirq_info(struct irq_info *pirq_info, u8 bus, u8 devfn,
24 u8 link0, u16 bitmap0, u8 link1, u16 bitmap1,
25 u8 link2, u16 bitmap2, u8 link3, u16 bitmap3,
26 u8 slot, u8 rfu)
27{
28 pirq_info->bus = bus;
29 pirq_info->devfn = devfn;
30 pirq_info->irq[0].link = link0;
31 pirq_info->irq[0].bitmap = bitmap0;
32 pirq_info->irq[1].link = link1;
33 pirq_info->irq[1].bitmap = bitmap1;
34 pirq_info->irq[2].link = link2;
35 pirq_info->irq[2].bitmap = bitmap2;
36 pirq_info->irq[3].link = link3;
37 pirq_info->irq[3].bitmap = bitmap3;
38 pirq_info->slot = slot;
39 pirq_info->rfu = rfu;
40}
41
Dave Frodinc43bce52014-12-03 08:22:46 -070042unsigned long write_pirq_routing_table(unsigned long addr)
43{
44 struct irq_routing_table *pirq;
45 struct irq_info *pirq_info;
46 u32 slot_num;
47 u8 *v;
48
49 u8 sum = 0;
50 int i;
51
52 /* Align the table to be 16 byte aligned. */
53 addr += 15;
54 addr &= ~15;
55
56 /* This table must be between 0xf0000 & 0x100000 */
57 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
58
59 pirq = (void *)(addr);
60 v = (u8 *) (addr);
61
62 pirq->signature = PIRQ_SIGNATURE;
63 pirq->version = PIRQ_VERSION;
64
65 pirq->rtr_bus = 0;
66 pirq->rtr_devfn = PCI_DEVFN(0x14, 4);
67
68 pirq->exclusive_irqs = 0;
69
70 pirq->rtr_vendor = 0x1002;
71 pirq->rtr_device = 0x4384;
72
73 pirq->miniport_data = 0;
74
75 memset(pirq->rfu, 0, sizeof(pirq->rfu));
76
77 pirq_info = (void *)(&pirq->checksum + 1);
78 slot_num = 0;
79
80 /* pci bridge */
81 write_pirq_info(pirq_info, 0, PCI_DEVFN(0x14, 4),
82 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0,
83 0);
84 pirq_info++;
85
86 slot_num++;
87
88 pirq->size = 32 + 16 * slot_num;
89
90 for (i = 0; i < pirq->size; i++)
91 sum += v[i];
92
93 sum = pirq->checksum - sum;
94
95 if (sum != pirq->checksum) {
96 pirq->checksum = sum;
97 }
98
99 printk(BIOS_INFO, "write_pirq_routing_table done.\n");
100
101 return (unsigned long)pirq_info;
102}