diff --git a/hypervisor/arch/x86/irq.c b/hypervisor/arch/x86/irq.c index 9e25cd452..8a9c0a7a5 100644 --- a/hypervisor/arch/x86/irq.c +++ b/hypervisor/arch/x86/irq.c @@ -8,32 +8,6 @@ static spinlock_t exception_spinlock = { .head = 0, .tail = 0, }; -struct irq_request_info { - /* vector set to 0xE0 ~ 0xFF for pri_register_handler - * and set to VECTOR_INVALID for normal_register_handler - */ - uint32_t vector; - dev_handler_t func; - void *dev_data; - bool share; - bool lowpri; - char *name; -}; - -/* any field change in below required irq_lock protection with irqsave */ -struct irq_desc { - uint32_t irq; /* index to irq_desc_base */ - enum irq_state used; /* this irq have assigned to device */ - enum irq_desc_state state; /* irq_desc status */ - uint32_t vector; /* assigned vector */ - void *handler_data; /* irq_handler private data */ - int (*irq_handler)(struct irq_desc *irq_desc, void *handler_data); - struct dev_handler_node *dev_list; - spinlock_t irq_lock; - uint64_t *irq_cnt; /* this irq cnt happened on CPUs */ - uint64_t irq_lost_cnt; -}; - static struct irq_desc *irq_desc_base; static uint32_t vector_to_irq[NR_MAX_VECTOR + 1]; diff --git a/hypervisor/include/arch/x86/irq.h b/hypervisor/include/arch/x86/irq.h index 0c6fa0d4a..73d5ba40e 100644 --- a/hypervisor/include/arch/x86/irq.h +++ b/hypervisor/include/arch/x86/irq.h @@ -4,8 +4,10 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef IRQ_H -#define IRQ_H +#ifndef ARCH_IRQ_H +#define ARCH_IRQ_H + +#include /* vectors for normal, usually for devices */ #define VECTOR_FOR_NOR_LOWPRI_START 0x20U @@ -33,40 +35,6 @@ #define DEFAULT_DELIVERY_MODE IOAPIC_RTE_DELLOPRI #define ALL_CPUS_MASK ((1U << phys_cpu_num) - 1U) -struct irq_desc; - -enum irq_mode { - IRQ_PULSE, - IRQ_ASSERT, - IRQ_DEASSERT, -}; - -enum irq_state { - IRQ_NOT_ASSIGNED = 0, - IRQ_ASSIGNED_SHARED, - IRQ_ASSIGNED_NOSHARE, -}; - -enum irq_desc_state { - IRQ_DESC_PENDING, - IRQ_DESC_IN_PROCESS, -}; - -typedef int (*dev_handler_t)(int irq, void*); -struct dev_handler_node { - char name[32]; - void *dev_data; - dev_handler_t dev_handler; - struct dev_handler_node *next; - struct irq_desc *desc; -}; - -struct irq_routing_entry { - unsigned short bdf; /* BDF */ - int irq; /* PCI cfg offset 0x3C: IRQ pin */ - int intx; /* PCI cfg offset 0x3D: 0-3 = INTA,INTB,INTC,INTD*/ -}; - /* * Definition of the stack frame layout */ @@ -97,44 +65,15 @@ struct intr_excp_ctx { uint64_t ss; }; -uint32_t irq_mark_used(uint32_t irq); -uint32_t irq_alloc(void); - -uint32_t irq_desc_alloc_vector(uint32_t irq, bool lowpri); -void irq_desc_try_free_vector(uint32_t irq); - -uint32_t irq_to_vector(uint32_t irq); -uint32_t dev_to_irq(struct dev_handler_node *node); -uint32_t dev_to_vector(struct dev_handler_node *node); - int handle_level_interrupt_common(struct irq_desc *desc, void *handler_data); int common_handler_edge(struct irq_desc *desc, void *handler_data); int common_dev_handler_level(struct irq_desc *desc, void *handler_data); int quick_handler_nolock(struct irq_desc *desc, void *handler_data); -typedef int (*irq_handler_t)(struct irq_desc*, void*); -void update_irq_handler(uint32_t irq, irq_handler_t func); - int init_default_irqs(uint16_t cpu); void dispatch_interrupt(struct intr_excp_ctx *ctx); -struct dev_handler_node* -pri_register_handler(uint32_t irq, - uint32_t vector, - dev_handler_t func, - void *dev_data, - const char *name); - -struct dev_handler_node* -normal_register_handler(uint32_t irq, - dev_handler_t func, - void *dev_data, - bool share, - bool lowpri, - const char *name); -void unregister_handler_common(struct dev_handler_node *node); - void get_cpu_interrupt_info(char *str, int str_max); void setup_notification(void); @@ -171,4 +110,4 @@ int acrn_handle_pending_request(struct vcpu *vcpu); int interrupt_init(uint32_t logical_id); void cancel_event_injection(struct vcpu *vcpu); -#endif /* IRQ_H */ +#endif /* ARCH_IRQ_H */ diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index 51f375787..7dd9c742f 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -4,7 +4,8 @@ #include #include #include -#include +#include +#include #include #include #include diff --git a/hypervisor/include/common/irq.h b/hypervisor/include/common/irq.h new file mode 100644 index 000000000..d0c8b68a7 --- /dev/null +++ b/hypervisor/include/common/irq.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef COMMON_IRQ_H +#define COMMON_IRQ_H + +enum irq_mode { + IRQ_PULSE, + IRQ_ASSERT, + IRQ_DEASSERT, +}; + +enum irq_state { + IRQ_NOT_ASSIGNED = 0, + IRQ_ASSIGNED_SHARED, + IRQ_ASSIGNED_NOSHARE, +}; + +enum irq_desc_state { + IRQ_DESC_PENDING, + IRQ_DESC_IN_PROCESS, +}; + +typedef int (*dev_handler_t)(int irq, void*); +struct irq_request_info { + /* vector set to 0xE0 ~ 0xFF for pri_register_handler + * and set to VECTOR_INVALID for normal_register_handler + */ + uint32_t vector; + dev_handler_t func; + void *dev_data; + bool share; + bool lowpri; + char *name; +}; + +/* any field change in below required irq_lock protection with irqsave */ +struct irq_desc { + uint32_t irq; /* index to irq_desc_base */ + enum irq_state used; /* this irq have assigned to device */ + enum irq_desc_state state; /* irq_desc status */ + uint32_t vector; /* assigned vector */ + void *handler_data; /* irq_handler private data */ + int (*irq_handler)(struct irq_desc *irq_desc, void *handler_data); + struct dev_handler_node *dev_list; + spinlock_t irq_lock; + uint64_t *irq_cnt; /* this irq cnt happened on CPUs */ + uint64_t irq_lost_cnt; +}; + +struct dev_handler_node { + char name[32]; + void *dev_data; + dev_handler_t dev_handler; + struct dev_handler_node *next; + struct irq_desc *desc; +}; + +uint32_t irq_mark_used(uint32_t irq); + +uint32_t irq_desc_alloc_vector(uint32_t irq, bool lowpri); +void irq_desc_try_free_vector(uint32_t irq); + +uint32_t irq_to_vector(uint32_t irq); +uint32_t dev_to_irq(struct dev_handler_node *node); +uint32_t dev_to_vector(struct dev_handler_node *node); + +struct dev_handler_node* +pri_register_handler(uint32_t irq, + uint32_t vector, + dev_handler_t func, + void *dev_data, + const char *name); + +struct dev_handler_node* +normal_register_handler(uint32_t irq, + dev_handler_t func, + void *dev_data, + bool share, + bool lowpri, + const char *name); +void unregister_handler_common(struct dev_handler_node *node); + +typedef int (*irq_handler_t)(struct irq_desc*, void*); +void update_irq_handler(uint32_t irq, irq_handler_t func); + +#endif /* COMMON_IRQ_H */