Debian Codegraph @

src/soc/amd/phoenix/pci_irq_routing.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <amdblocks/amd_pci_util.h>
4 #include <amdblocks/smn.h>
5 #include <console/console.h>
6 #include <device/pci_def.h>
7 #include <types.h>
8
9 #define MAX_BRIDGES 20
10
11 #define SMN_DEVICE_REMAP_BASE_ADDR 0x13b100b8
12 #define SMN_PCI_INTERRUPT_ROUTING_BASE_ADDR 0x14300040
13
14 union iohc_nb_prog_device_remap {
15 struct {
16 uint32_t fn_num : 3; /* [ 2.. 0] */
17 uint32_t dev_num : 5; /* [ 7.. 3] */
18 uint32_t : 24; /* [31.. 8] */
19 };
20 uint32_t raw;
21 };
22
23 union ioapic_br_irq_routing {
24 struct {
25 uint32_t intr_grp : 3; /* [ 2.. 0] */
26 uint32_t : 1; /* [ 3.. 3] */
27 uint32_t intr_swz : 2; /* [ 5.. 4] */
28 uint32_t : 10; /* [15.. 6] */
29 uint32_t intr_map : 5; /* [20..16] */
30 uint32_t : 11; /* [31..21] */
31 };
32 uint32_t raw;
33 };
34
35 const struct pci_routing_info *get_pci_routing_table(size_t *entries)
36 {
37 static bool table_initialized;
38 static struct pci_routing_info routing_table[MAX_BRIDGES];
39
40 union iohc_nb_prog_device_remap dev_remap;
41 union ioapic_br_irq_routing ioapic_routing;
42
43 if (table_initialized) {
44 *entries = MAX_BRIDGES;
45 return routing_table;
46 }
47
48 /*
49 * For Phoenix, the logical and physical bridge numbers map 1:1, which may not be
50 * the case for other SoCs.
51 */
52 for (size_t i = 0; i < MAX_BRIDGES; ++i) {
53 dev_remap.raw = smn_read32(SMN_DEVICE_REMAP_BASE_ADDR
54 + sizeof(uint32_t) * i);
55 routing_table[i].devfn = (dev_remap.dev_num << 3) | dev_remap.fn_num;
56 }
57
58 for (size_t i = 0; i < MAX_BRIDGES; ++i) {
59 ioapic_routing.raw = smn_read32(SMN_PCI_INTERRUPT_ROUTING_BASE_ADDR
60 + sizeof(uint32_t) * i);
61 routing_table[i].group = ioapic_routing.intr_grp;
62 routing_table[i].swizzle = ioapic_routing.intr_swz;
63 routing_table[i].bridge_irq = ioapic_routing.intr_map;
64 printk(BIOS_DEBUG, "%02x.%x: group: %u, swizzle: %u, irq: %u\n",
65 PCI_SLOT(routing_table[i].devfn),
66 PCI_FUNC(routing_table[i].devfn),
67 routing_table[i].group,
68 routing_table[i].swizzle,
69 routing_table[i].bridge_irq);
70 }
71 table_initialized = true;
72
73 *entries = MAX_BRIDGES;
74 return routing_table;
75 }