mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-23 09:47:44 +00:00
hv/mod_irq: split irq.c into arch/x86/irq.c and common/irq.c
The common irq file is responsible for managing the central irq_desc data structure and provides the following APIs for host interrupt handling. - init_interrupt() - reserve_irq_num() - request_irq() - free_irq() - set_irq_trigger_mode() - do_irq() API prototypes, constant and data structures belonging to common interrupt handling are all moved into include/common/irq.h. Conversely, the following arch specific APIs are added which are called from the common code at various points: - init_irq_descs_arch() - setup_irqs_arch() - init_interrupt_arch() - free_irq_arch() - request_irq_arch() - pre_irq_arch() - post_irq_arch() Tracked-On: #5825 Signed-off-by: Peter Fang <peter.fang@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef ARCH_IRQ_H
|
||||
#define ARCH_IRQ_H
|
||||
#ifndef ARCH_X86_IRQ_H
|
||||
#define ARCH_X86_IRQ_H
|
||||
|
||||
#include <acrn_common.h>
|
||||
#include <util.h>
|
||||
@@ -14,7 +14,7 @@
|
||||
/**
|
||||
* @file arch/x86/irq.h
|
||||
*
|
||||
* @brief public APIs for virtual IRQ
|
||||
* @brief public APIs for x86 IRQ handling
|
||||
*/
|
||||
|
||||
#define DBG_LEVEL_PTIRQ 6U
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#define NR_MAX_VECTOR 0xFFU
|
||||
#define VECTOR_INVALID (NR_MAX_VECTOR + 1U)
|
||||
#define NR_IRQS 256U
|
||||
#define IRQ_INVALID 0xffffffffU
|
||||
|
||||
/* # of NR_STATIC_MAPPINGS_1 entries for timer, vcpu notify, and PMI */
|
||||
#define NR_STATIC_MAPPINGS_1 3U
|
||||
@@ -82,13 +80,19 @@
|
||||
#define DEFAULT_DEST_MODE IOAPIC_RTE_DESTMODE_LOGICAL
|
||||
#define DEFAULT_DELIVERY_MODE IOAPIC_RTE_DELMODE_LOPRI
|
||||
|
||||
#define IRQ_ALLOC_BITMAP_SIZE INT_DIV_ROUNDUP(NR_IRQS, 64U)
|
||||
|
||||
#define INVALID_INTERRUPT_PIN 0xffffffffU
|
||||
|
||||
#define IRQF_NONE (0U)
|
||||
#define IRQF_LEVEL (1U << 1U) /* 1: level trigger; 0: edge trigger */
|
||||
#define IRQF_PT (1U << 2U) /* 1: for passthrough dev */
|
||||
/*
|
||||
* x86 irq data
|
||||
*/
|
||||
struct x86_irq_data {
|
||||
uint32_t vector; /**< assigned vector */
|
||||
#ifdef PROFILING_ON
|
||||
uint64_t ctx_rip;
|
||||
uint64_t ctx_rflags;
|
||||
uint64_t ctx_cs;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct acrn_vcpu;
|
||||
struct acrn_vm;
|
||||
@@ -116,18 +120,11 @@ struct smp_call_info_data {
|
||||
void smp_call_function(uint64_t mask, smp_call_func_t func, void *data);
|
||||
bool is_notification_nmi(const struct acrn_vm *vm);
|
||||
|
||||
void init_default_irqs(uint16_t cpu_id);
|
||||
|
||||
void dispatch_exception(struct intr_excp_ctx *ctx);
|
||||
|
||||
void setup_notification(void);
|
||||
void setup_pi_notification(void);
|
||||
|
||||
typedef void (*spurious_handler_t)(uint32_t vector);
|
||||
extern spurious_handler_t spurious_handler;
|
||||
|
||||
uint32_t alloc_irq_vector(uint32_t irq);
|
||||
|
||||
/* RFLAGS */
|
||||
#define HV_ARCH_VCPU_RFLAGS_TF (1UL<<8U)
|
||||
#define HV_ARCH_VCPU_RFLAGS_IF (1UL<<9U)
|
||||
@@ -242,99 +239,17 @@ int32_t interrupt_window_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
int32_t external_interrupt_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
int32_t acrn_handle_pending_request(struct acrn_vcpu *vcpu);
|
||||
|
||||
extern uint64_t irq_alloc_bitmap[IRQ_ALLOC_BITMAP_SIZE];
|
||||
|
||||
typedef void (*irq_action_t)(uint32_t irq, void *priv_data);
|
||||
|
||||
/*
|
||||
* x86 irq data
|
||||
*/
|
||||
struct x86_irq_data {
|
||||
uint32_t vector; /**< assigned vector */
|
||||
#ifdef PROFILING_ON
|
||||
uint64_t ctx_rip;
|
||||
uint64_t ctx_rflags;
|
||||
uint64_t ctx_cs;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interrupt descriptor
|
||||
* @brief Allocate a vectror and bind it to irq
|
||||
*
|
||||
* Any field change in below required lock protection with irqsave
|
||||
* For legacy irq (num < 16) and statically mapped ones, do nothing
|
||||
* if mapping is correct.
|
||||
*
|
||||
* @param[in] irq The irq num to bind
|
||||
*
|
||||
* @return valid vector num on susccess, VECTOR_INVALID on failure
|
||||
*/
|
||||
struct irq_desc {
|
||||
uint32_t irq; /**< index to irq_desc_base */
|
||||
|
||||
void *arch_data; /**< arch-specific data */
|
||||
|
||||
irq_action_t action; /**< callback registered from component */
|
||||
void *priv_data; /**< irq_action private data */
|
||||
uint32_t flags; /**< flags for trigger mode/ptdev */
|
||||
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup phys_int_ext_apis Physical Interrupt External Interfaces
|
||||
*
|
||||
* This is a group that includes Physical Interrupt External Interfaces.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Reserve an interrupt num
|
||||
*
|
||||
* Reserved interrupt num will not be available for dynamic IRQ allocations.
|
||||
* This is normally used by the hypervisor for static IRQ mappings and/or
|
||||
* arch specific, e.g. IOAPIC, interrupts during initialization.
|
||||
*
|
||||
* @param[in] req_irq irq_num to be reserved
|
||||
*
|
||||
* @retval >=0 on success, IRQ_INVALID on failure
|
||||
*/
|
||||
uint32_t reserve_irq_num(uint32_t req_irq);
|
||||
|
||||
/**
|
||||
* @brief Request an interrupt
|
||||
*
|
||||
* Request interrupt num if not specified, and register irq action for the
|
||||
* specified/allocated irq.
|
||||
*
|
||||
* @param[in] req_irq irq_num to request, if IRQ_INVALID, a free irq
|
||||
* number will be allocated
|
||||
* @param[in] action_fn Function to be called when the IRQ occurs
|
||||
* @param[in] priv_data Private data for action function.
|
||||
* @param[in] flags Interrupt type flags, including:
|
||||
* IRQF_NONE;
|
||||
* IRQF_LEVEL - 1: level trigger; 0: edge trigger;
|
||||
* IRQF_PT - 1: for passthrough dev
|
||||
*
|
||||
* @retval >=0 on success
|
||||
* @retval IRQ_INVALID on failure
|
||||
*/
|
||||
int32_t request_irq(uint32_t req_irq, irq_action_t action_fn, void *priv_data,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Free an interrupt
|
||||
*
|
||||
* Free irq num and unregister the irq action.
|
||||
*
|
||||
* @param[in] irq irq_num to be freed
|
||||
*/
|
||||
void free_irq(uint32_t irq);
|
||||
|
||||
/**
|
||||
* @brief Set interrupt trigger mode
|
||||
*
|
||||
* Set the irq trigger mode: edge-triggered or level-triggered
|
||||
*
|
||||
* @param[in] irq irq_num of interrupt to be set
|
||||
* @param[in] is_level_triggered Trigger mode to set
|
||||
*/
|
||||
void set_irq_trigger_mode(uint32_t irq, bool is_level_triggered);
|
||||
uint32_t alloc_irq_vector(uint32_t irq);
|
||||
|
||||
/**
|
||||
* @brief Get vector number of an interrupt from irq number
|
||||
@@ -363,22 +278,21 @@ void dispatch_interrupt(const struct intr_excp_ctx *ctx);
|
||||
*/
|
||||
void handle_nmi(__unused struct intr_excp_ctx *ctx);
|
||||
|
||||
/**
|
||||
* @brief Initialize interrupt
|
||||
*
|
||||
* To do interrupt initialization for a cpu, will be called for each physical cpu.
|
||||
*
|
||||
* @param[in] pcpu_id The id of physical cpu to initialize
|
||||
*/
|
||||
void init_interrupt(uint16_t pcpu_id);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* End of phys_int_ext_apis */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* End of acrn_virq */
|
||||
#endif /* ARCH_IRQ_H */
|
||||
|
||||
/* Arch specific routines called from generic IRQ handling */
|
||||
|
||||
struct irq_desc;
|
||||
|
||||
void init_irq_descs_arch(struct irq_desc *descs);
|
||||
void setup_irqs_arch(void);
|
||||
void init_interrupt_arch(uint16_t pcpu_id);
|
||||
void free_irq_arch(uint32_t irq);
|
||||
bool request_irq_arch(uint32_t irq);
|
||||
void pre_irq_arch(const struct irq_desc *desc);
|
||||
void post_irq_arch(const struct irq_desc *desc);
|
||||
|
||||
#endif /* ARCH_X86_IRQ_H */
|
||||
|
Reference in New Issue
Block a user