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