1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef AMD_BLOCK_PCI_UTIL_H 4 #define AMD_BLOCK_PCI_UTIL_H 5 6 #include <types.h> 7 #include <soc/amd_pci_int_defs.h> 8 #include <device/device.h> 9 10 /* FCH index/data registers */ 11 #define PCI_INTR_INDEX 0xc00 12 #define PCI_INTR_DATA 0xc01 13 14 #define FCH_IRQ_ROUTING_ENTRIES 0x80 15 16 struct fch_irq_routing { 17 uint8_t intr_index; 18 uint8_t pic_irq_num; 19 uint8_t apic_irq_num; 20 }; 21 22 const struct fch_irq_routing *mb_get_fch_irq_mapping(size_t *length); 23 24 struct pirq_struct { 25 u8 devfn; 26 u8 PIN[4]; /* PINA/B/C/D are index 0/1/2/3 */ 27 }; 28 29 struct irq_idx_name { 30 uint8_t index; 31 const char *const name; 32 }; 33 34 extern const struct pirq_struct *pirq_data_ptr; 35 extern u32 pirq_data_size; 36 37 u8 read_pci_int_idx(u8 index, int mode); 38 void write_pci_int_idx(u8 index, int mode, u8 data); 39 void write_pci_cfg_irqs(void); 40 void write_pci_int_table(void); 41 const struct irq_idx_name *sb_get_apic_reg_association(size_t *size); 42 43 enum pci_routing_swizzle { 44 PCI_SWIZZLE_ABCD = 0, 45 PCI_SWIZZLE_BCDA, 46 PCI_SWIZZLE_CDAB, 47 PCI_SWIZZLE_DABC, 48 }; 49 50 /** 51 * Each PCI bridge has its INTx lines routed to one of the GNB IO-APIC PCI 52 * groups. Each group has 4 interrupts. The INTx lines can be swizzled before 53 * being routed to the IO-APIC. If the IO-APIC redirection entry is masked, the 54 * interrupt is reduced modulo 8 onto INT[A-H] and forwarded to the FCH IO-APIC. 55 **/ 56 struct pci_routing_info { 57 uint8_t devfn; 58 uint8_t group; 59 uint8_t swizzle; 60 uint8_t bridge_irq; /* also called 'map' */ 61 } __packed; 62 63 void populate_pirq_data(void); 64 65 /* Implemented by the SoC */ 66 const struct pci_routing_info *get_pci_routing_table(size_t *entries); 67 68 const struct pci_routing_info *get_pci_routing_info(unsigned int devfn); 69 70 unsigned int pci_calculate_irq(const struct pci_routing_info *routing_info, unsigned int pin); 71 72 void acpigen_write_pci_GNB_PRT(const struct device *dev); 73 void acpigen_write_pci_FCH_PRT(const struct device *dev); 74 75 #endif /* AMD_BLOCK_PCI_UTIL_H */ 76