blob: 5891512da65d19ae4a93494c6270ae0d075477e3 [file] [log] [blame]
Bingxun Shifb1fddb2007-02-09 00:26:10 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Bingxun Shifb1fddb2007-02-09 00:26:10 +00003 *
4 * Copyright (C) 2006 AMD
5 * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6 *
7 * Copyright (C) 2006 MSI
8 * Written by Bingxun Shi <bingxunshi@gmail.com> for MSI.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
Bingxun Shifb1fddb2007-02-09 00:26:10 +000019 */
20
Bingxun Shifb1fddb2007-02-09 00:26:10 +000021#include <console/console.h>
22#include <device/pci.h>
23#include <string.h>
24#include <stdint.h>
25#include <arch/pirq_routing.h>
26
27#include <cpu/amd/amdk8_sysconf.h>
28#include "mb_sysconf.h"
29
30static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus, uint8_t devfn, uint8_t link0, uint16_t bitmap0,
Elyes HAOUASd36905c2014-07-23 09:23:29 +020031 uint8_t link1, uint16_t bitmap1, uint8_t link2, uint16_t bitmap2,uint8_t link3, uint16_t bitmap3,
32 uint8_t slot, uint8_t rfu)
Bingxun Shifb1fddb2007-02-09 00:26:10 +000033{
Elyes HAOUASd36905c2014-07-23 09:23:29 +020034 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;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000046}
47
Stefan Reinauere9de1e22010-04-07 15:30:11 +000048
Carl-Daniel Hailfingera5436c62008-12-22 17:41:01 +000049
Bingxun Shifb1fddb2007-02-09 00:26:10 +000050unsigned long write_pirq_routing_table(unsigned long addr)
51{
52
Elyes HAOUASd36905c2014-07-23 09:23:29 +020053 struct irq_routing_table *pirq;
54 struct irq_info *pirq_info;
55 unsigned slot_num;
56 uint8_t *v;
57 struct mb_sysconf_t *m;
58 unsigned sbdn;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000059
Elyes HAOUASd36905c2014-07-23 09:23:29 +020060 uint8_t sum=0;
61 int i;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000062
Elyes HAOUASd36905c2014-07-23 09:23:29 +020063 get_bus_conf(); // it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c
64 sbdn = sysconf.sbdn;
65 m = sysconf.mb;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000066
Elyes HAOUASd36905c2014-07-23 09:23:29 +020067 /* Align the table to be 16 byte aligned. */
68 addr += 15;
69 addr &= ~15;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000070
Elyes HAOUASd36905c2014-07-23 09:23:29 +020071 /* This table must be between 0xf0000 & 0x100000 */
72 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
Bingxun Shifb1fddb2007-02-09 00:26:10 +000073
Elyes HAOUASd36905c2014-07-23 09:23:29 +020074 pirq = (void *)(addr);
75 v = (uint8_t *)(addr);
Bingxun Shifb1fddb2007-02-09 00:26:10 +000076
Elyes HAOUASd36905c2014-07-23 09:23:29 +020077 pirq->signature = PIRQ_SIGNATURE;
78 pirq->version = PIRQ_VERSION;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000079
Elyes HAOUASd36905c2014-07-23 09:23:29 +020080 pirq->rtr_bus = m->bus_mcp55[0];
81 pirq->rtr_devfn = ((sbdn+6)<<3)|0;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000082
Elyes HAOUASd36905c2014-07-23 09:23:29 +020083 pirq->exclusive_irqs = 0;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000084
Elyes HAOUASd36905c2014-07-23 09:23:29 +020085 pirq->rtr_vendor = 0x10de;
86 pirq->rtr_device = 0x0370;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000087
Elyes HAOUASd36905c2014-07-23 09:23:29 +020088 pirq->miniport_data = 0;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000089
Elyes HAOUASd36905c2014-07-23 09:23:29 +020090 memset(pirq->rfu, 0, sizeof(pirq->rfu));
Bingxun Shifb1fddb2007-02-09 00:26:10 +000091
Elyes HAOUASd36905c2014-07-23 09:23:29 +020092 pirq_info = (void *) ( &pirq->checksum + 1);
93 slot_num = 0;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000094//pci bridge
Elyes HAOUASd36905c2014-07-23 09:23:29 +020095 write_pirq_info(pirq_info, m->bus_mcp55[0], ((sbdn+6)<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
96 pirq_info++; slot_num++;
Bingxun Shifb1fddb2007-02-09 00:26:10 +000097
Elyes HAOUASd36905c2014-07-23 09:23:29 +020098 for(i=1; i< sysconf.hc_possible_num; i++) {
99 if(!(sysconf.pci1234[i] & 0x1) ) continue;
100 unsigned busn = (sysconf.pci1234[i] >> 16) & 0xff;
101 unsigned devn = sysconf.hcdn[i] & 0xff;
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000102
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200103 write_pirq_info(pirq_info, busn, (devn<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
104 pirq_info++; slot_num++;
105 }
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000106
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200107 pirq->size = 32 + 16 * slot_num;
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000108
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200109 for (i = 0; i < pirq->size; i++)
110 sum += v[i];
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000111
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200112 sum = pirq->checksum - sum;
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000113
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200114 if (sum != pirq->checksum) {
115 pirq->checksum = sum;
116 }
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000117
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200118 printk(BIOS_INFO, "done.\n");
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000119
Elyes HAOUASd36905c2014-07-23 09:23:29 +0200120 return (unsigned long) pirq_info;
Bingxun Shifb1fddb2007-02-09 00:26:10 +0000121
122}