Skip to content

Commit f6e45c9

Browse files
lyan3lijinxia
authored andcommitted
hv: pirq: remove unnecessary dev_handler_node struct
Since we don't support shared irq, dev_handler_node which works as action node, is not needed anymore. This commit removes the dev_handler_node struct and does some relevant changes, including: - moves necessary fields to struct irq_desc: action, priv_data, name; and removes unused handler_data; - changes return type of pri_/normal_register_handler() from dev_handler_node* to int32_t, which is irq num (>= 0) on success, and errno (> 0) on failure. - changes unregister_irq_handler() to take argument unint32_t instead of dev_handler_node*; - changes are made to the places where these APIs are called. Signed-off-by: Yan, Like <like.yan@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com>
1 parent d773df9 commit f6e45c9

File tree

8 files changed

+134
-169
lines changed

8 files changed

+134
-169
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ lookup_entry_by_vintx(struct vm *vm, uint8_t vpin,
142142
static void
143143
ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
144144
{
145-
uint32_t phys_irq = dev_to_irq(entry->node);
145+
uint32_t phys_irq = entry->allocated_pirq;
146146
struct ptdev_intx_info *intx = &entry->ptdev_intr_info.intx;
147147

148148
if (entry->type == PTDEV_INTR_MSI) {
@@ -235,8 +235,8 @@ ptdev_build_physical_rte(struct vm *vm,
235235
struct ptdev_remapping_info *entry)
236236
{
237237
union ioapic_rte rte;
238-
uint32_t phys_irq = dev_to_irq(entry->node);
239-
uint32_t vector = dev_to_vector(entry->node);
238+
uint32_t phys_irq = entry->allocated_pirq;
239+
uint32_t vector = irq_to_vector(phys_irq);
240240
struct ptdev_intx_info *intx = &entry->ptdev_intr_info.intx;
241241

242242
if (intx->vpin_src == PTDEV_VPIN_IOAPIC) {
@@ -457,7 +457,7 @@ static void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
457457
}
458458

459459
if (is_entry_active(entry)) {
460-
phys_irq = dev_to_irq(entry->node);
460+
phys_irq = entry->allocated_pirq;
461461
if (!irq_is_gsi(phys_irq)) {
462462
goto END;
463463
}
@@ -509,8 +509,8 @@ static void ptdev_intr_handle_irq(struct vm *vm,
509509

510510
dev_dbg(ACRN_DBG_PTIRQ,
511511
"dev-assign: irq=0x%x assert vr: 0x%x vRTE=0x%lx",
512-
dev_to_irq(entry->node),
513-
irq_to_vector(dev_to_irq(entry->node)),
512+
entry->allocated_pirq,
513+
irq_to_vector(entry->allocated_pirq),
514514
rte.full);
515515
break;
516516
}
@@ -570,9 +570,9 @@ void ptdev_softirq(__unused uint16_t cpu_id)
570570
msi->vmsi_data);
571571
dev_dbg(ACRN_DBG_PTIRQ,
572572
"dev-assign: irq=0x%x MSI VR: 0x%x-0x%x",
573-
dev_to_irq(entry->node),
573+
entry->allocated_pirq,
574574
msi->virt_vector,
575-
irq_to_vector(dev_to_irq(entry->node)));
575+
irq_to_vector(entry->allocated_pirq));
576576
dev_dbg(ACRN_DBG_PTIRQ,
577577
" vmsi_addr: 0x%x vmsi_data: 0x%x",
578578
msi->vmsi_addr,
@@ -671,10 +671,11 @@ int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf,
671671
}
672672

673673
/* build physical config MSI, update to info->pmsi_xxx */
674-
ptdev_build_physical_msi(vm, info, dev_to_vector(entry->node));
674+
ptdev_build_physical_msi(vm, info, irq_to_vector(entry->allocated_pirq));
675675
entry->ptdev_intr_info.msi = *info;
676676
entry->ptdev_intr_info.msi.virt_vector = info->vmsi_data & 0xFFU;
677-
entry->ptdev_intr_info.msi.phys_vector = dev_to_vector(entry->node);
677+
entry->ptdev_intr_info.msi.phys_vector =
678+
irq_to_vector(entry->allocated_pirq);
678679

679680
/* update irq handler according to info in guest */
680681
ptdev_update_irq_handler(vm, entry);
@@ -709,7 +710,7 @@ static void activate_physical_ioapic(struct vm *vm,
709710
struct ptdev_remapping_info *entry)
710711
{
711712
union ioapic_rte rte;
712-
uint32_t phys_irq = dev_to_irq(entry->node);
713+
uint32_t phys_irq = entry->allocated_pirq;
713714

714715
/* disable interrupt */
715716
GSI_MASK_IRQ(phys_irq);
@@ -999,8 +1000,8 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
9991000
*bdf = 0U;
10001001
*vbdf = 0U;
10011002
}
1002-
*irq = dev_to_irq(entry->node);
1003-
*vector = dev_to_vector(entry->node);
1003+
*irq = entry->allocated_pirq;
1004+
*vector = irq_to_vector(entry->allocated_pirq);
10041005
} else {
10051006
(void)strcpy_s(type, 16U, "NONE");
10061007
*irq = IRQ_INVALID;

hypervisor/arch/x86/irq.c

Lines changed: 59 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -151,31 +151,12 @@ static void disable_pic_irq(void)
151151
pio_write8(0xffU, 0x21U);
152152
}
153153

154-
static void
155-
irq_desc_append_dev(struct irq_desc *desc, void *node)
156-
{
157-
spinlock_rflags;
158-
159-
spinlock_irqsave_obtain(&desc->irq_lock);
160-
161-
ASSERT(desc->action == NULL, "irq already registered");
162-
/* assign if first node */
163-
desc->action = node;
164-
desc->used = IRQ_ASSIGNED;
165-
if (desc->irq_handler == NULL) {
166-
desc->irq_handler = common_handler_edge;
167-
}
168-
169-
spinlock_irqrestore_release(&desc->irq_lock);
170-
}
171-
172-
static struct dev_handler_node*
173-
common_register_handler(uint32_t irq_arg,
154+
static int32_t common_register_handler(uint32_t irq_arg,
174155
struct irq_request_info *info)
175156
{
176-
struct dev_handler_node *node = NULL;
177157
struct irq_desc *desc;
178158
uint32_t irq = irq_arg;
159+
spinlock_rflags;
179160

180161
/* ======================================================
181162
* This is low level ISR handler registering function
@@ -217,43 +198,48 @@ common_register_handler(uint32_t irq_arg,
217198

218199
if (irq >= NR_IRQS) {
219200
pr_err("failed to assign IRQ");
220-
goto OUT;
221-
}
222-
223-
node = calloc(1U, sizeof(struct dev_handler_node));
224-
if (node == NULL) {
225-
pr_err("failed to alloc node");
226-
irq_desc_try_free_vector(irq);
227-
goto OUT;
201+
return -EINVAL;
228202
}
229203

230204
desc = &irq_desc_array[irq];
231-
irq_desc_append_dev(desc, node);
205+
if (desc->irq_handler == NULL) {
206+
desc->irq_handler = common_handler_edge;
207+
}
232208

233209
if (info->vector >= VECTOR_FIXED_START &&
234210
info->vector <= VECTOR_FIXED_END) {
235211
irq_desc_set_vector(irq, info->vector);
236212
} else if (info->vector > NR_MAX_VECTOR) {
237213
irq_desc_alloc_vector(irq);
238-
} else {
214+
}
215+
216+
if (desc->vector == VECTOR_INVALID) {
239217
pr_err("the input vector is not correct");
240-
free(node);
241-
return NULL;
218+
/* FIXME: free allocated irq */
219+
return -EINVAL;
242220
}
243221

244-
node->dev_handler = info->func;
245-
node->dev_data = info->dev_data;
246-
node->desc = desc;
247-
/* we are okay using strcpy_s here even with spinlock
248-
* since no #PG in HV right now
249-
*/
250-
(void)strcpy_s(node->name, 32U, info->name);
222+
if (desc->action == NULL) {
223+
spinlock_irqsave_obtain(&desc->irq_lock);
224+
desc->priv_data = info->priv_data;
225+
desc->action = info->func;
251226

252-
dev_dbg(ACRN_DBG_IRQ, "[%s] %s irq%d vr:0x%x",
253-
__func__, node->name, irq, desc->vector);
227+
/* we are okay using strcpy_s here even with spinlock
228+
* since no #PG in HV right now
229+
*/
230+
(void)strcpy_s(desc->name, 32U, info->name);
254231

255-
OUT:
256-
return node;
232+
spinlock_irqrestore_release(&desc->irq_lock);
233+
} else {
234+
pr_err("%s: request irq(%u) vr(%u) for %s failed,\
235+
already requested", __func__,
236+
irq, irq_to_vector(irq), info->name);
237+
return -EBUSY;
238+
}
239+
240+
dev_dbg(ACRN_DBG_IRQ, "[%s] %s irq%d vr:0x%x",
241+
__func__, info->name, irq, desc->vector);
242+
return (int32_t)irq;
257243
}
258244

259245
/* it is safe to call irq_desc_alloc_vector multiple times*/
@@ -318,16 +304,6 @@ uint32_t irq_to_vector(uint32_t irq)
318304
}
319305
}
320306

321-
uint32_t dev_to_irq(struct dev_handler_node *node)
322-
{
323-
return node->desc->irq;
324-
}
325-
326-
uint32_t dev_to_vector(struct dev_handler_node *node)
327-
{
328-
return node->desc->vector;
329-
}
330-
331307
void init_default_irqs(uint16_t cpu_id)
332308
{
333309
if (cpu_id != BOOT_CPU_ID) {
@@ -395,7 +371,7 @@ void dispatch_interrupt(struct intr_excp_ctx *ctx)
395371
goto ERR;
396372
}
397373

398-
desc->irq_handler(desc, desc->handler_data);
374+
desc->irq_handler(desc, NULL);
399375
return;
400376
ERR:
401377
handle_spurious_interrupt(vr);
@@ -427,7 +403,7 @@ void partition_mode_dispatch_interrupt(struct intr_excp_ctx *ctx)
427403
int handle_level_interrupt_common(struct irq_desc *desc,
428404
__unused void *handler_data)
429405
{
430-
struct dev_handler_node *action = desc->action;
406+
irq_action_t action = desc->action;
431407
spinlock_rflags;
432408

433409
/*
@@ -451,9 +427,9 @@ int handle_level_interrupt_common(struct irq_desc *desc,
451427
/* Send EOI to LAPIC/IOAPIC IRR */
452428
send_lapic_eoi();
453429

454-
if (action != NULL && action->dev_handler != NULL) {
455-
action->dev_handler(desc->irq, action->dev_data);
456-
}
430+
if (action != NULL) {
431+
action(desc->irq, desc->priv_data);
432+
}
457433

458434
if (irq_is_gsi(desc->irq)) {
459435
GSI_UNMASK_IRQ(desc->irq);
@@ -467,7 +443,7 @@ int handle_level_interrupt_common(struct irq_desc *desc,
467443

468444
int common_handler_edge(struct irq_desc *desc, __unused void *handler_data)
469445
{
470-
struct dev_handler_node *action = desc->action;
446+
irq_action_t action = desc->action;
471447
spinlock_rflags;
472448

473449
/*
@@ -486,8 +462,8 @@ int common_handler_edge(struct irq_desc *desc, __unused void *handler_data)
486462
/* Send EOI to LAPIC/IOAPIC IRR */
487463
send_lapic_eoi();
488464

489-
if (action != NULL && action->dev_handler != NULL) {
490-
action->dev_handler(desc->irq, action->dev_data);
465+
if (action != NULL) {
466+
action(desc->irq, desc->priv_data);
491467
}
492468

493469
desc->state = IRQ_DESC_PENDING;
@@ -498,7 +474,7 @@ int common_handler_edge(struct irq_desc *desc, __unused void *handler_data)
498474

499475
int common_dev_handler_level(struct irq_desc *desc, __unused void *handler_data)
500476
{
501-
struct dev_handler_node *action = desc->action;
477+
irq_action_t action = desc->action;
502478
spinlock_rflags;
503479

504480
/*
@@ -522,8 +498,8 @@ int common_dev_handler_level(struct irq_desc *desc, __unused void *handler_data)
522498
/* Send EOI to LAPIC/IOAPIC IRR */
523499
send_lapic_eoi();
524500

525-
if (action != NULL && action->dev_handler != NULL) {
526-
action->dev_handler(desc->irq, action->dev_data);
501+
if (action != NULL) {
502+
action(desc->irq, desc->priv_data);
527503
}
528504

529505
desc->state = IRQ_DESC_PENDING;
@@ -536,13 +512,13 @@ int common_dev_handler_level(struct irq_desc *desc, __unused void *handler_data)
536512
/* no desc->irq_lock for quick handling local interrupt like lapic timer */
537513
int quick_handler_nolock(struct irq_desc *desc, __unused void *handler_data)
538514
{
539-
struct dev_handler_node *action = desc->action;
515+
irq_action_t action = desc->action;
540516

541517
/* Send EOI to LAPIC/IOAPIC IRR */
542518
send_lapic_eoi();
543519

544-
if (action != NULL && action->dev_handler != NULL) {
545-
action->dev_handler(desc->irq, action->dev_data);
520+
if (action != NULL) {
521+
action(desc->irq, desc->priv_data);
546522
}
547523

548524
return 0;
@@ -564,45 +540,43 @@ void update_irq_handler(uint32_t irq, irq_handler_t func)
564540
spinlock_irqrestore_release(&desc->irq_lock);
565541
}
566542

567-
void unregister_handler_common(struct dev_handler_node *node)
543+
void unregister_handler_common(uint32_t irq)
568544
{
569545
struct irq_desc *desc;
570546

571547
spinlock_rflags;
572548

573-
if (node == NULL) {
549+
if (irq >= NR_IRQS) {
574550
return;
575551
}
576552

553+
desc = &irq_desc_array[irq];
577554
dev_dbg(ACRN_DBG_IRQ, "[%s] %s irq%d vr:0x%x",
578-
__func__, node->name,
579-
dev_to_irq(node),
580-
dev_to_vector(node));
555+
__func__, desc->name, irq, irq_to_vector(irq));
581556

582-
desc = node->desc;
583557
spinlock_irqsave_obtain(&desc->irq_lock);
584558

585559
desc->action = NULL;
560+
desc->priv_data = NULL;
561+
memset(desc->name, '\0', 32U);
586562

587563
spinlock_irqrestore_release(&desc->irq_lock);
588564
irq_desc_try_free_vector(desc->irq);
589-
free(node);
590565
}
591566

592567
/*
593568
* Allocate IRQ with Vector from VECTOR_DYNAMIC_START ~ VECTOR_DYNAMIC_END
594569
*/
595-
struct dev_handler_node*
596-
normal_register_handler(uint32_t irq,
597-
dev_handler_t func,
598-
void *dev_data,
570+
int32_t normal_register_handler(uint32_t irq,
571+
irq_action_t func,
572+
void *priv_data,
599573
const char *name)
600574
{
601575
struct irq_request_info info;
602576

603577
info.vector = VECTOR_INVALID;
604578
info.func = func;
605-
info.dev_data = dev_data;
579+
info.priv_data = priv_data;
606580
info.name = (char *)name;
607581

608582
return common_register_handler(irq, &info);
@@ -614,22 +588,21 @@ normal_register_handler(uint32_t irq,
614588
* User can install same irq/isr on different CPU by call this function multiple
615589
* times
616590
*/
617-
struct dev_handler_node*
618-
pri_register_handler(uint32_t irq,
591+
int32_t pri_register_handler(uint32_t irq,
619592
uint32_t vector,
620-
dev_handler_t func,
621-
void *dev_data,
593+
irq_action_t func,
594+
void *priv_data,
622595
const char *name)
623596
{
624597
struct irq_request_info info;
625598

626599
if (vector < VECTOR_FIXED_START || vector > VECTOR_FIXED_END) {
627-
return NULL;
600+
return -EINVAL;
628601
}
629602

630603
info.vector = vector;
631604
info.func = func;
632-
info.dev_data = dev_data;
605+
info.priv_data = priv_data;
633606
info.name = (char *)name;
634607

635608
return common_register_handler(irq, &info);

0 commit comments

Comments
 (0)