1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef ARCH_X86_IOAPIC_H 8 #define ARCH_X86_IOAPIC_H 9 10 #include <asm/apicreg.h> 11 12 #define NR_LEGACY_IRQ 16U 13 #define NR_LEGACY_PIN NR_LEGACY_IRQ 14 15 struct ioapic_info { 16 uint8_t id; /* IOAPIC ID as indicated in ACPI MADT */ 17 uint32_t addr; /* IOAPIC Register address */ 18 uint32_t gsi_base; /* Global System Interrupt where this IO-APIC's interrupt input start */ 19 uint32_t nr_pins; /* Number of Interrupt inputs as determined by Max. Redir Entry Register */ 20 }; 21 22 void ioapic_setup_irqs(void); 23 24 bool is_ioapic_irq(uint32_t irq); 25 uint32_t gsi_to_ioapic_pin(uint32_t gsi); 26 int32_t init_ioapic_id_info(void); 27 uint8_t ioapic_irq_to_ioapic_id(uint32_t irq); 28 29 uint8_t get_platform_ioapic_info (struct ioapic_info **plat_ioapic_info); 30 31 /** 32 * @defgroup ioapic_ext_apis IOAPIC External Interfaces 33 * 34 * This is a group that includes IOAPIC External Interfaces. 35 * 36 * @{ 37 */ 38 39 /** 40 * @brief Get irq num from gsi num 41 * 42 * @param[in] gsi The gsi number 43 * 44 * @return irq number 45 */ 46 uint32_t ioapic_gsi_to_irq(uint32_t gsi); 47 /** 48 * @brief Set the redirection table entry 49 * 50 * Set the redirection table entry of an interrupt 51 * 52 * @param[in] irq The number of irq to set 53 * @param[in] rte Union of ioapic_rte to set 54 */ 55 void ioapic_set_rte(uint32_t irq, union ioapic_rte rte); 56 57 /** 58 * @brief Get the redirection table entry 59 * 60 * Get the redirection table entry of an interrupt 61 * 62 * @param[in] irq The number of irq to fetch RTE 63 * @param[inout] rte Pointer to union ioapic_rte to return result RTE 64 * 65 * @pre rte != NULL 66 */ 67 void ioapic_get_rte(uint32_t irq, union ioapic_rte *rte); 68 69 /** 70 * @brief Suspend ioapic 71 * 72 * Suspend ioapic, mainly save the RTEs. 73 */ 74 void suspend_ioapic(void); 75 76 /** 77 * @brief Resume ioapic 78 * 79 * Resume ioapic, mainly restore the RTEs. 80 */ 81 void resume_ioapic(void); 82 83 /** 84 * @} 85 */ 86 /* End of ioapic_ext_apis */ 87 88 void ioapic_gsi_mask_irq(uint32_t irq); 89 void ioapic_gsi_unmask_irq(uint32_t irq); 90 91 void ioapic_get_rte_entry(void *ioapic_base, uint32_t pin, union ioapic_rte *rte); 92 93 void *gsi_to_ioapic_base(uint32_t gsi); 94 uint32_t get_max_nr_gsi(void); 95 uint8_t get_gsi_to_ioapic_index(uint32_t gsi); 96 uint32_t get_pic_pin_from_ioapic_pin(uint32_t pin_index); 97 bool is_gsi_valid(uint32_t gsi); 98 99 #endif /* ARCH_X86_IOAPIC_H */ 100