From 8fda0d8c5ff368de7e979274ded4ef09225c2af4 Mon Sep 17 00:00:00 2001 From: "Yan, Like" Date: Tue, 7 Aug 2018 15:19:56 +0800 Subject: [PATCH] hv: pirq: add static irq:vector mappings Since vector is x86 specific concept, we'd like to hide it from common irq APIs. This commit - adds static irq:vector mappings for special interrupt such as timer and cpu notification; - reserves the irq and vector at initialization; - removed the vector argument in pri_register_handler(), get reserved vector from irq_desc in common_register_handler(). Signed-off-by: Yan, Like Acked-by: Anthony Xu --- hypervisor/arch/x86/irq.c | 33 ++++++++++++++++++++----------- hypervisor/arch/x86/notify.c | 3 +-- hypervisor/arch/x86/timer.c | 4 +--- hypervisor/include/arch/x86/irq.h | 3 +++ hypervisor/include/common/irq.h | 2 -- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/hypervisor/arch/x86/irq.c b/hypervisor/arch/x86/irq.c index a24067577..c0de5beee 100644 --- a/hypervisor/arch/x86/irq.c +++ b/hypervisor/arch/x86/irq.c @@ -14,6 +14,12 @@ static uint32_t vector_to_irq[NR_MAX_VECTOR + 1]; spurious_handler_t spurious_handler; +#define NR_STATIC_MAPPINGS (2U) +static uint32_t irq_static_mappings[NR_STATIC_MAPPINGS][2] = { + {TIMER_IRQ, VECTOR_TIMER}, + {NOTIFY_IRQ, VECTOR_NOTIFY_VCPU}, +}; + static void init_irq_desc(void) { uint32_t i; @@ -28,6 +34,15 @@ static void init_irq_desc(void) vector_to_irq[i] = IRQ_INVALID; } + /* init fixed mapping for specific irq and vector */ + for (i = 0U; i < NR_STATIC_MAPPINGS; i++) { + uint32_t irq = irq_static_mappings[i][0]; + uint32_t vr = irq_static_mappings[i][1]; + + irq_desc_array[irq].vector = vr; + irq_desc_array[irq].used = IRQ_ASSIGNED; + vector_to_irq[vr] = irq; + } } /* @@ -155,7 +170,7 @@ static int32_t common_register_handler(uint32_t irq_arg, struct irq_request_info *info) { struct irq_desc *desc; - uint32_t irq = irq_arg; + uint32_t irq = irq_arg, vector; spinlock_rflags; /* ====================================================== @@ -206,10 +221,11 @@ static int32_t common_register_handler(uint32_t irq_arg, desc->irq_handler = common_handler_edge; } - if (info->vector >= VECTOR_FIXED_START && - info->vector <= VECTOR_FIXED_END) { - irq_desc_set_vector(irq, info->vector); - } else if (info->vector > NR_MAX_VECTOR) { + vector = desc->vector; + if (vector >= VECTOR_FIXED_START && + vector <= VECTOR_FIXED_END) { + irq_desc_set_vector(irq, vector); + } else if (vector > NR_MAX_VECTOR) { irq_desc_alloc_vector(irq); } @@ -574,7 +590,6 @@ int32_t normal_register_handler(uint32_t irq, { struct irq_request_info info; - info.vector = VECTOR_INVALID; info.func = func; info.priv_data = priv_data; info.name = (char *)name; @@ -589,18 +604,12 @@ int32_t normal_register_handler(uint32_t irq, * times */ int32_t pri_register_handler(uint32_t irq, - uint32_t vector, irq_action_t func, void *priv_data, const char *name) { struct irq_request_info info; - if (vector < VECTOR_FIXED_START || vector > VECTOR_FIXED_END) { - return -EINVAL; - } - - info.vector = vector; info.func = func; info.priv_data = priv_data; info.name = (char *)name; diff --git a/hypervisor/arch/x86/notify.c b/hypervisor/arch/x86/notify.c index 193db8183..c7cf62f11 100644 --- a/hypervisor/arch/x86/notify.c +++ b/hypervisor/arch/x86/notify.c @@ -20,7 +20,6 @@ static int kick_notification(__unused uint32_t irq, __unused void *data) static int request_notification_irq(irq_action_t func, void *data, const char *name) { - uint32_t irq = IRQ_INVALID; /* system allocate */ int32_t retval; if (notification_irq != IRQ_INVALID) { @@ -30,7 +29,7 @@ static int request_notification_irq(irq_action_t func, void *data, } /* all cpu register the same notification vector */ - retval = pri_register_handler(irq, VECTOR_NOTIFY_VCPU, func, data, name); + retval = pri_register_handler(NOTIFY_IRQ, func, data, name); if (retval < 0) { pr_err("Failed to add notify isr"); return -ENODEV; diff --git a/hypervisor/arch/x86/timer.c b/hypervisor/arch/x86/timer.c index 35e1870af..110e791cb 100644 --- a/hypervisor/arch/x86/timer.c +++ b/hypervisor/arch/x86/timer.c @@ -8,7 +8,6 @@ #include #define MAX_TIMER_ACTIONS 32U -#define TIMER_IRQ (NR_IRQS - 1U) #define CAL_MS 10U #define MIN_TIMER_PERIOD_US 500U @@ -112,8 +111,7 @@ static int request_timer_irq(irq_action_t func, const char *name) { int32_t retval; - retval = pri_register_handler(TIMER_IRQ, VECTOR_TIMER, - func, NULL, name); + retval = pri_register_handler(TIMER_IRQ, func, NULL, name); if (retval >= 0) { update_irq_handler(TIMER_IRQ, quick_handler_nolock); } else { diff --git a/hypervisor/include/arch/x86/irq.h b/hypervisor/include/arch/x86/irq.h index a83df530e..60c276c83 100644 --- a/hypervisor/include/arch/x86/irq.h +++ b/hypervisor/include/arch/x86/irq.h @@ -27,6 +27,9 @@ #define NR_IRQS (256U + 16U) #define IRQ_INVALID 0xffffffffU +#define TIMER_IRQ (NR_IRQS - 1U) +#define NOTIFY_IRQ (NR_IRQS - 2U) + #define DEFAULT_DEST_MODE IOAPIC_RTE_DESTLOG #define DEFAULT_DELIVERY_MODE IOAPIC_RTE_DELLOPRI #define ALL_CPUS_MASK ((1U << phys_cpu_num) - 1U) diff --git a/hypervisor/include/common/irq.h b/hypervisor/include/common/irq.h index b7614ced2..04c855f92 100644 --- a/hypervisor/include/common/irq.h +++ b/hypervisor/include/common/irq.h @@ -28,7 +28,6 @@ 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; irq_action_t func; void *priv_data; char *name; @@ -60,7 +59,6 @@ void irq_desc_try_free_vector(uint32_t irq); uint32_t irq_to_vector(uint32_t irq); int32_t pri_register_handler(uint32_t irq, - uint32_t vector, irq_action_t func, void *priv_data, const char *name);