Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2015 Raptor Engineering |
| 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; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/pci_ids.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 | |
| 26 | /* Free irqs are 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, and 15 */ |
Elyes HAOUAS | 6350a2e | 2016-09-16 20:49:38 +0200 | [diff] [blame] | 27 | #define IRQBM ((1 << 3)|(1 << 4)|(1 << 5)|(1 << 6)|(1 << 7)|(1 << 9)|(1 << 10)|(1 << 11)|(1 << 12)|(1 << 14)|(1 << 15)) |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 28 | |
| 29 | #define LNKA 1 |
| 30 | #define LNKB 2 |
| 31 | #define LNKC 3 |
| 32 | #define LNKD 4 |
| 33 | |
| 34 | /* |
| 35 | * For simplicity map LNK[E-H] to LNK[A-D]. |
| 36 | * This also means we are 82C596 compatible. |
| 37 | * Needs 0:11.0 0x46[4] set to 0. |
| 38 | */ |
| 39 | #define LNKE 1 |
| 40 | #define LNKF 2 |
| 41 | #define LNKG 3 |
| 42 | #define LNKH 4 |
| 43 | |
| 44 | static void write_pirq_info(struct irq_info *pirq_info, u8 bus, u8 devfn, |
| 45 | u8 link0, u16 bitmap0, u8 link1, u16 bitmap1, |
| 46 | u8 link2, u16 bitmap2, u8 link3, u16 bitmap3, |
| 47 | u8 slot, u8 rfu) |
| 48 | { |
| 49 | pirq_info->bus = bus; |
| 50 | pirq_info->devfn = devfn; |
| 51 | pirq_info->irq[0].link = link0; |
| 52 | pirq_info->irq[0].bitmap = bitmap0; |
| 53 | pirq_info->irq[1].link = link1; |
| 54 | pirq_info->irq[1].bitmap = bitmap1; |
| 55 | pirq_info->irq[2].link = link2; |
| 56 | pirq_info->irq[2].bitmap = bitmap2; |
| 57 | pirq_info->irq[3].link = link3; |
| 58 | pirq_info->irq[3].bitmap = bitmap3; |
| 59 | pirq_info->slot = slot; |
| 60 | pirq_info->rfu = rfu; |
| 61 | } |
Paul Menzel | 95fe8fb | 2016-07-28 17:20:20 +0200 | [diff] [blame] | 62 | |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 63 | extern u8 bus_isa; |
| 64 | extern u8 bus_sr5650[14]; |
| 65 | extern u8 bus_sp5100[2]; |
| 66 | extern u32 sbdn_sp5100; |
| 67 | extern u32 sbdn_sr5650; |
| 68 | |
| 69 | unsigned long write_pirq_routing_table(unsigned long addr) |
| 70 | { |
| 71 | struct irq_routing_table *pirq; |
| 72 | struct irq_info *pirq_info; |
| 73 | u32 slot_num; |
| 74 | u8 *v; |
| 75 | |
| 76 | u8 sum = 0; |
| 77 | int i; |
| 78 | |
| 79 | get_bus_conf(); /* it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c */ |
| 80 | |
| 81 | /* Align the table to be 16 byte aligned. */ |
| 82 | addr += 15; |
| 83 | addr &= ~15; |
| 84 | |
| 85 | /* This table must be between 0xf0000 & 0x100000 */ |
| 86 | printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr); |
| 87 | |
| 88 | pirq = (void *)(addr); |
| 89 | v = (u8 *) (addr); |
| 90 | |
| 91 | pirq->signature = PIRQ_SIGNATURE; |
| 92 | pirq->version = PIRQ_VERSION; |
| 93 | |
| 94 | /* Where the interrupt router resides */ |
| 95 | pirq->rtr_bus = bus_sp5100[0]; |
| 96 | pirq->rtr_devfn = PCI_DEVFN(0x14, 4); |
| 97 | |
| 98 | pirq->exclusive_irqs = 0; |
| 99 | |
| 100 | pirq->rtr_vendor = PCI_VENDOR_ID_ATI; |
| 101 | pirq->rtr_device = PCI_DEVICE_ID_ATI_SB700_PCI; |
| 102 | |
| 103 | pirq->miniport_data = 0; |
| 104 | |
| 105 | memset(pirq->rfu, 0, sizeof(pirq->rfu)); |
| 106 | |
| 107 | pirq_info = (void *)(&pirq->checksum + 1); |
| 108 | slot_num = 0; |
| 109 | |
| 110 | /* pci bridge */ |
Paul Menzel | 95fe8fb | 2016-07-28 17:20:20 +0200 | [diff] [blame] | 111 | write_pirq_info(pirq_info, bus_sp5100[0], |
| 112 | ((sbdn_sp5100 + 0x14) << 3) | 4, LNKA, IRQBM, LNKB, |
| 113 | IRQBM, LNKC, IRQBM, LNKD, IRQBM, 0, 0); |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 114 | pirq_info++; |
| 115 | slot_num++; |
| 116 | |
| 117 | pirq->size = 32 + 16 * slot_num; |
| 118 | |
| 119 | for (i = 0; i < pirq->size; i++) |
| 120 | sum += v[i]; |
| 121 | |
| 122 | sum = pirq->checksum - sum; |
| 123 | if (sum != pirq->checksum) { |
| 124 | pirq->checksum = sum; |
| 125 | } |
| 126 | |
| 127 | printk(BIOS_INFO, "done.\n"); |
| 128 | |
| 129 | return (unsigned long)pirq_info; |
| 130 | } |