Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 1 | /* |
| 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. |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 18 | #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 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 27 | static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus, uint8_t devfn, uint8_t link0, uint16_t bitmap0, |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 28 | uint8_t link1, uint16_t bitmap1, uint8_t link2, uint16_t bitmap2,uint8_t link3, uint16_t bitmap3, |
| 29 | uint8_t slot, uint8_t rfu) |
| 30 | { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 31 | pirq_info->bus = bus; |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 32 | pirq_info->devfn = devfn; |
| 33 | pirq_info->irq[0].link = link0; |
| 34 | pirq_info->irq[0].bitmap = bitmap0; |
| 35 | pirq_info->irq[1].link = link1; |
| 36 | pirq_info->irq[1].bitmap = bitmap1; |
| 37 | pirq_info->irq[2].link = link2; |
| 38 | pirq_info->irq[2].bitmap = bitmap2; |
| 39 | pirq_info->irq[3].link = link3; |
| 40 | pirq_info->irq[3].bitmap = bitmap3; |
| 41 | pirq_info->slot = slot; |
| 42 | pirq_info->rfu = rfu; |
| 43 | } |
| 44 | |
Stefan Reinauer | e9de1e2 | 2010-04-07 15:30:11 +0000 | [diff] [blame] | 45 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 46 | |
| 47 | unsigned 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 | |
| 57 | uint8_t sum=0; |
| 58 | int i; |
| 59 | |
| 60 | get_bus_conf(); // it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c |
| 61 | sbdn = sysconf.sbdn; |
| 62 | m = sysconf.mb; |
| 63 | |
| 64 | /* Align the table to be 16 byte aligned. */ |
| 65 | addr += 15; |
| 66 | addr &= ~15; |
| 67 | |
Kyösti Mälkki | 9533d83 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 68 | /* This table must be between 0xf0000 & 0x100000 */ |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 69 | printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr); |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 70 | |
| 71 | pirq = (void *)(addr); |
| 72 | v = (uint8_t *)(addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 73 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 74 | pirq->signature = PIRQ_SIGNATURE; |
| 75 | pirq->version = PIRQ_VERSION; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 76 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 77 | pirq->rtr_bus = m->bus_mcp55[0]; |
| 78 | pirq->rtr_devfn = ((sbdn+6)<<3)|0; |
| 79 | |
| 80 | pirq->exclusive_irqs = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 81 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 82 | 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 | |
| 89 | pirq_info = (void *) ( &pirq->checksum + 1); |
| 90 | slot_num = 0; |
| 91 | //pci bridge |
| 92 | write_pirq_info(pirq_info, m->bus_mcp55[0], ((sbdn+6)<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0); |
| 93 | pirq_info++; slot_num++; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 94 | |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 95 | for(i=1; i< sysconf.hc_possible_num; i++) { |
| 96 | if(!(sysconf.pci1234[i] & 0x1) ) continue; |
| 97 | unsigned busn = (sysconf.pci1234[i] >> 12) & 0xff; |
| 98 | unsigned devn = sysconf.hcdn[i] & 0xff; |
| 99 | |
| 100 | write_pirq_info(pirq_info, busn, (devn<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0); |
| 101 | pirq_info++; slot_num++; |
| 102 | } |
| 103 | |
| 104 | #if CONFIG_CBB |
| 105 | write_pirq_info(pirq_info, CONFIG_CBB, (0<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0); |
| 106 | pirq_info++; slot_num++; |
| 107 | if(sysconf.nodes>32) { |
| 108 | write_pirq_info(pirq_info, CONFIG_CBB-1, (0<<3)|0, 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0); |
| 109 | pirq_info++; slot_num++; |
| 110 | } |
| 111 | #endif |
| 112 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 113 | pirq->size = 32 + 16 * slot_num; |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 114 | |
| 115 | for (i = 0; i < pirq->size; i++) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 116 | sum += v[i]; |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 117 | |
| 118 | sum = pirq->checksum - sum; |
| 119 | |
| 120 | if (sum != pirq->checksum) { |
| 121 | pirq->checksum = sum; |
| 122 | } |
| 123 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 124 | printk(BIOS_INFO, "done.\n"); |
Timothy Pearson | d3b2bbe | 2010-03-01 10:56:51 +0000 | [diff] [blame] | 125 | |
| 126 | return (unsigned long) pirq_info; |
| 127 | |
| 128 | } |