blob: 513fd57c58b501d0e5f5f68498793aaf960fc99d [file] [log] [blame]
Ward Vandewege2583dd22009-09-30 14:46:43 +00001/*
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.
Ward Vandewege2583dd22009-09-30 14:46:43 +000016 */
17
Ward Vandewege2583dd22009-09-30 14:46:43 +000018#include <console/console.h>
19#include <device/pci.h>
20#include <string.h>
21#include <stdint.h>
22#include <arch/pirq_routing.h>
23
24#include <cpu/amd/amdfam10_sysconf.h>
25#include "mb_sysconf.h"
26
Paul Menzel95fe8fb2016-07-28 17:20:20 +020027static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus,
28 uint8_t devfn, uint8_t link0, uint16_t bitmap0,
29 uint8_t link1, uint16_t bitmap1, uint8_t link2,
30 uint16_t bitmap2, uint8_t link3, uint16_t bitmap3,
31 uint8_t slot, uint8_t rfu)
Ward Vandewege2583dd22009-09-30 14:46:43 +000032{
Stefan Reinauer14e22772010-04-27 06:56:47 +000033 pirq_info->bus = bus;
Ward Vandewege2583dd22009-09-30 14:46:43 +000034 pirq_info->devfn = devfn;
Paul Menzel95fe8fb2016-07-28 17:20:20 +020035 pirq_info->irq[0].link = link0;
36 pirq_info->irq[0].bitmap = bitmap0;
37 pirq_info->irq[1].link = link1;
38 pirq_info->irq[1].bitmap = bitmap1;
39 pirq_info->irq[2].link = link2;
40 pirq_info->irq[2].bitmap = bitmap2;
41 pirq_info->irq[3].link = link3;
42 pirq_info->irq[3].bitmap = bitmap3;
Ward Vandewege2583dd22009-09-30 14:46:43 +000043 pirq_info->slot = slot;
44 pirq_info->rfu = rfu;
45}
46
Ward Vandewege2583dd22009-09-30 14:46:43 +000047unsigned long write_pirq_routing_table(unsigned long addr)
48{
49
50 struct irq_routing_table *pirq;
51 struct irq_info *pirq_info;
52 unsigned slot_num;
53 uint8_t *v;
54 struct mb_sysconf_t *m;
55 unsigned sbdn;
56
Paul Menzel95fe8fb2016-07-28 17:20:20 +020057 uint8_t sum = 0;
Ward Vandewege2583dd22009-09-30 14:46:43 +000058 int i;
59
Paul Menzel95fe8fb2016-07-28 17:20:20 +020060 get_bus_conf(); // it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c
Ward Vandewege2583dd22009-09-30 14:46:43 +000061 sbdn = sysconf.sbdn;
62 m = sysconf.mb;
63
64 /* Align the table to be 16 byte aligned. */
65 addr += 15;
66 addr &= ~15;
67
68 /* This table must be between 0xf0000 & 0x100000 */
Myles Watson08e0fb82010-03-22 16:33:25 +000069 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
Ward Vandewege2583dd22009-09-30 14:46:43 +000070
71 pirq = (void *)(addr);
Paul Menzel95fe8fb2016-07-28 17:20:20 +020072 v = (uint8_t *) (addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +000073
Ward Vandewege2583dd22009-09-30 14:46:43 +000074 pirq->signature = PIRQ_SIGNATURE;
Paul Menzel95fe8fb2016-07-28 17:20:20 +020075 pirq->version = PIRQ_VERSION;
Stefan Reinauer14e22772010-04-27 06:56:47 +000076
Ward Vandewege2583dd22009-09-30 14:46:43 +000077 pirq->rtr_bus = m->bus_mcp55[0];
Paul Menzel95fe8fb2016-07-28 17:20:20 +020078 pirq->rtr_devfn = ((sbdn + 6) << 3) | 0;
Ward Vandewege2583dd22009-09-30 14:46:43 +000079
80 pirq->exclusive_irqs = 0;
Stefan Reinauer14e22772010-04-27 06:56:47 +000081
Ward Vandewege2583dd22009-09-30 14:46:43 +000082 pirq->rtr_vendor = 0x10de;
83 pirq->rtr_device = 0x0370;
84
85 pirq->miniport_data = 0;
86
87 memset(pirq->rfu, 0, sizeof(pirq->rfu));
88
Paul Menzel95fe8fb2016-07-28 17:20:20 +020089 pirq_info = (void *)(&pirq->checksum + 1);
Ward Vandewege2583dd22009-09-30 14:46:43 +000090 slot_num = 0;
91//pci bridge
Paul Menzel95fe8fb2016-07-28 17:20:20 +020092 write_pirq_info(pirq_info, m->bus_mcp55[0], ((sbdn + 6) << 3) | 0, 0x1,
93 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
94 pirq_info++;
95 slot_num++;
Stefan Reinauer14e22772010-04-27 06:56:47 +000096
Paul Menzel95fe8fb2016-07-28 17:20:20 +020097 for (i = 1; i < sysconf.hc_possible_num; i++) {
98 if (!(sysconf.pci1234[i] & 0x1))
99 continue;
Ward Vandewege2583dd22009-09-30 14:46:43 +0000100 unsigned busn = (sysconf.pci1234[i] >> 12) & 0xff;
101 unsigned devn = sysconf.hcdn[i] & 0xff;
102
Paul Menzel95fe8fb2016-07-28 17:20:20 +0200103 write_pirq_info(pirq_info, busn, (devn << 3) | 0, 0x1, 0xdef8,
104 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
105 pirq_info++;
106 slot_num++;
Ward Vandewege2583dd22009-09-30 14:46:43 +0000107 }
108
109#if CONFIG_CBB
Paul Menzel95fe8fb2016-07-28 17:20:20 +0200110 write_pirq_info(pirq_info, CONFIG_CBB, (0 << 3) | 0, 0x1, 0xdef8, 0x2,
111 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
112 pirq_info++;
113 slot_num++;
114 if (sysconf.nodes > 32) {
115 write_pirq_info(pirq_info, CONFIG_CBB - 1, (0 << 3) | 0, 0x1,
116 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8,
117 0, 0);
118 pirq_info++;
119 slot_num++;
Ward Vandewege2583dd22009-09-30 14:46:43 +0000120 }
121#endif
122
Stefan Reinauer14e22772010-04-27 06:56:47 +0000123 pirq->size = 32 + 16 * slot_num;
Ward Vandewege2583dd22009-09-30 14:46:43 +0000124
125 for (i = 0; i < pirq->size; i++)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000126 sum += v[i];
Ward Vandewege2583dd22009-09-30 14:46:43 +0000127
128 sum = pirq->checksum - sum;
129
130 if (sum != pirq->checksum) {
131 pirq->checksum = sum;
132 }
133
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000134 printk(BIOS_INFO, "done.\n");
Ward Vandewege2583dd22009-09-30 14:46:43 +0000135
Paul Menzel95fe8fb2016-07-28 17:20:20 +0200136 return (unsigned long)pirq_info;
Ward Vandewege2583dd22009-09-30 14:46:43 +0000137
138}