Angel Pons | 0fcb1b8 | 2020-04-03 01:21:20 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Elyes Haouas | 53529b2 | 2022-09-11 12:09:08 +0200 | [diff] [blame] | 4 | #include <commonlib/bsd/helpers.h> |
Mike Banon | e1ebabe | 2020-02-14 16:12:45 +0000 | [diff] [blame] | 5 | #include <device/pci_def.h> |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 6 | #include <string.h> |
| 7 | #include <stdint.h> |
| 8 | #include <arch/pirq_routing.h> |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 9 | |
| 10 | static void write_pirq_info(struct irq_info *pirq_info, u8 bus, u8 devfn, |
| 11 | u8 link0, u16 bitmap0, u8 link1, u16 bitmap1, |
| 12 | u8 link2, u16 bitmap2, u8 link3, u16 bitmap3, |
| 13 | u8 slot, u8 rfu) |
| 14 | { |
| 15 | pirq_info->bus = bus; |
| 16 | pirq_info->devfn = devfn; |
| 17 | pirq_info->irq[0].link = link0; |
| 18 | pirq_info->irq[0].bitmap = bitmap0; |
| 19 | pirq_info->irq[1].link = link1; |
| 20 | pirq_info->irq[1].bitmap = bitmap1; |
| 21 | pirq_info->irq[2].link = link2; |
| 22 | pirq_info->irq[2].bitmap = bitmap2; |
| 23 | pirq_info->irq[3].link = link3; |
| 24 | pirq_info->irq[3].bitmap = bitmap3; |
| 25 | pirq_info->slot = slot; |
| 26 | pirq_info->rfu = rfu; |
| 27 | } |
| 28 | |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 29 | unsigned long write_pirq_routing_table(unsigned long addr) |
| 30 | { |
| 31 | struct irq_routing_table *pirq; |
| 32 | struct irq_info *pirq_info; |
| 33 | u32 slot_num; |
| 34 | u8 *v; |
| 35 | |
| 36 | u8 sum = 0; |
| 37 | int i; |
| 38 | |
| 39 | /* Align the table to be 16 byte aligned. */ |
Elyes Haouas | 53529b2 | 2022-09-11 12:09:08 +0200 | [diff] [blame] | 40 | addr = ALIGN_UP(addr, 16); |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 41 | |
| 42 | /* This table must be between 0xf0000 & 0x100000 */ |
| 43 | printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr); |
| 44 | |
| 45 | pirq = (void *)(addr); |
| 46 | v = (u8 *) (addr); |
| 47 | |
| 48 | pirq->signature = PIRQ_SIGNATURE; |
| 49 | pirq->version = PIRQ_VERSION; |
| 50 | |
| 51 | pirq->rtr_bus = 0; |
| 52 | pirq->rtr_devfn = PCI_DEVFN(0x14, 4); |
| 53 | |
| 54 | pirq->exclusive_irqs = 0; |
| 55 | |
| 56 | pirq->rtr_vendor = 0x1002; |
| 57 | pirq->rtr_device = 0x4384; |
| 58 | |
| 59 | pirq->miniport_data = 0; |
| 60 | |
| 61 | memset(pirq->rfu, 0, sizeof(pirq->rfu)); |
| 62 | |
| 63 | pirq_info = (void *)(&pirq->checksum + 1); |
| 64 | slot_num = 0; |
| 65 | |
| 66 | /* pci bridge */ |
| 67 | write_pirq_info(pirq_info, 0, PCI_DEVFN(0x14, 4), |
| 68 | 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, |
| 69 | 0); |
| 70 | pirq_info++; |
| 71 | |
| 72 | slot_num++; |
| 73 | |
| 74 | pirq->size = 32 + 16 * slot_num; |
| 75 | |
| 76 | for (i = 0; i < pirq->size; i++) |
| 77 | sum += v[i]; |
| 78 | |
| 79 | sum = pirq->checksum - sum; |
| 80 | |
| 81 | if (sum != pirq->checksum) { |
| 82 | pirq->checksum = sum; |
| 83 | } |
| 84 | |
Elyes HAOUAS | 682b166 | 2020-03-03 10:21:37 +0100 | [diff] [blame] | 85 | printk(BIOS_INFO, "%s done.\n", __func__); |
Kyösti Mälkki | 595ef3d | 2015-05-27 12:44:16 +0300 | [diff] [blame] | 86 | |
| 87 | return (unsigned long)pirq_info; |
| 88 | } |