@@ -248,15 +248,6 @@ static int set_evtchn_to_irq(evtchn_port_t evtchn, unsigned int irq)
248
248
return 0 ;
249
249
}
250
250
251
- static int get_evtchn_to_irq (evtchn_port_t evtchn )
252
- {
253
- if (evtchn >= xen_evtchn_max_channels ())
254
- return -1 ;
255
- if (evtchn_to_irq [EVTCHN_ROW (evtchn )] == NULL )
256
- return -1 ;
257
- return READ_ONCE (evtchn_to_irq [EVTCHN_ROW (evtchn )][EVTCHN_COL (evtchn )]);
258
- }
259
-
260
251
/* Get info for IRQ */
261
252
static struct irq_info * info_for_irq (unsigned irq )
262
253
{
@@ -274,6 +265,19 @@ static void set_info_for_irq(unsigned int irq, struct irq_info *info)
274
265
irq_set_chip_data (irq , info );
275
266
}
276
267
268
+ static struct irq_info * evtchn_to_info (evtchn_port_t evtchn )
269
+ {
270
+ int irq ;
271
+
272
+ if (evtchn >= xen_evtchn_max_channels ())
273
+ return NULL ;
274
+ if (evtchn_to_irq [EVTCHN_ROW (evtchn )] == NULL )
275
+ return NULL ;
276
+ irq = READ_ONCE (evtchn_to_irq [EVTCHN_ROW (evtchn )][EVTCHN_COL (evtchn )]);
277
+
278
+ return (irq < 0 ) ? NULL : info_for_irq (irq );
279
+ }
280
+
277
281
/* Per CPU channel accounting */
278
282
static void channels_on_cpu_dec (struct irq_info * info )
279
283
{
@@ -429,7 +433,9 @@ static evtchn_port_t evtchn_from_irq(unsigned int irq)
429
433
430
434
unsigned int irq_from_evtchn (evtchn_port_t evtchn )
431
435
{
432
- return get_evtchn_to_irq (evtchn );
436
+ struct irq_info * info = evtchn_to_info (evtchn );
437
+
438
+ return info ? info -> irq : -1 ;
433
439
}
434
440
EXPORT_SYMBOL_GPL (irq_from_evtchn );
435
441
@@ -473,25 +479,11 @@ static unsigned pirq_from_irq(unsigned irq)
473
479
return info -> u .pirq .pirq ;
474
480
}
475
481
476
- static enum xen_irq_type type_from_irq (unsigned irq )
477
- {
478
- return info_for_irq (irq )-> type ;
479
- }
480
-
481
- static unsigned cpu_from_irq (unsigned irq )
482
- {
483
- return info_for_irq (irq )-> cpu ;
484
- }
485
-
486
482
unsigned int cpu_from_evtchn (evtchn_port_t evtchn )
487
483
{
488
- int irq = get_evtchn_to_irq (evtchn );
489
- unsigned ret = 0 ;
490
-
491
- if (irq != -1 )
492
- ret = cpu_from_irq (irq );
484
+ struct irq_info * info = evtchn_to_info (evtchn );
493
485
494
- return ret ;
486
+ return info ? info -> cpu : 0 ;
495
487
}
496
488
497
489
static void do_mask (struct irq_info * info , u8 reason )
@@ -540,13 +532,12 @@ static bool pirq_needs_eoi_flag(unsigned irq)
540
532
static void bind_evtchn_to_cpu (evtchn_port_t evtchn , unsigned int cpu ,
541
533
bool force_affinity )
542
534
{
543
- int irq = get_evtchn_to_irq (evtchn );
544
- struct irq_info * info = info_for_irq (irq );
535
+ struct irq_info * info = evtchn_to_info (evtchn );
545
536
546
- BUG_ON (irq == -1 );
537
+ BUG_ON (info == NULL );
547
538
548
539
if (IS_ENABLED (CONFIG_SMP ) && force_affinity ) {
549
- struct irq_data * data = irq_get_irq_data (irq );
540
+ struct irq_data * data = irq_get_irq_data (info -> irq );
550
541
551
542
irq_data_update_affinity (data , cpumask_of (cpu ));
552
543
irq_data_update_effective_affinity (data , cpumask_of (cpu ));
@@ -979,13 +970,13 @@ static void __unbind_from_irq(unsigned int irq)
979
970
}
980
971
981
972
if (VALID_EVTCHN (evtchn )) {
982
- unsigned int cpu = cpu_from_irq ( irq ) ;
973
+ unsigned int cpu = info -> cpu ;
983
974
struct xenbus_device * dev ;
984
975
985
976
if (!info -> is_static )
986
977
xen_evtchn_close (evtchn );
987
978
988
- switch (type_from_irq ( irq ) ) {
979
+ switch (info -> type ) {
989
980
case IRQT_VIRQ :
990
981
per_cpu (virq_to_irq , cpu )[virq_from_irq (irq )] = -1 ;
991
982
break ;
@@ -1185,15 +1176,16 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *chip,
1185
1176
{
1186
1177
int irq ;
1187
1178
int ret ;
1179
+ struct irq_info * info ;
1188
1180
1189
1181
if (evtchn >= xen_evtchn_max_channels ())
1190
1182
return - ENOMEM ;
1191
1183
1192
1184
mutex_lock (& irq_mapping_update_lock );
1193
1185
1194
- irq = get_evtchn_to_irq (evtchn );
1186
+ info = evtchn_to_info (evtchn );
1195
1187
1196
- if (irq == -1 ) {
1188
+ if (! info ) {
1197
1189
irq = xen_allocate_irq_dynamic ();
1198
1190
if (irq < 0 )
1199
1191
goto out ;
@@ -1216,9 +1208,9 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *chip,
1216
1208
*/
1217
1209
bind_evtchn_to_cpu (evtchn , 0 , false);
1218
1210
} else {
1219
- struct irq_info * info = info_for_irq (irq );
1220
- if (!WARN_ON (!info || info -> type != IRQT_EVTCHN ))
1211
+ if (!WARN_ON (info -> type != IRQT_EVTCHN ))
1221
1212
info -> refcnt ++ ;
1213
+ irq = info -> irq ;
1222
1214
}
1223
1215
1224
1216
out :
@@ -1556,13 +1548,7 @@ EXPORT_SYMBOL_GPL(xen_set_irq_priority);
1556
1548
1557
1549
int evtchn_make_refcounted (evtchn_port_t evtchn , bool is_static )
1558
1550
{
1559
- int irq = get_evtchn_to_irq (evtchn );
1560
- struct irq_info * info ;
1561
-
1562
- if (irq == -1 )
1563
- return - ENOENT ;
1564
-
1565
- info = info_for_irq (irq );
1551
+ struct irq_info * info = evtchn_to_info (evtchn );
1566
1552
1567
1553
if (!info )
1568
1554
return - ENOENT ;
@@ -1578,7 +1564,6 @@ EXPORT_SYMBOL_GPL(evtchn_make_refcounted);
1578
1564
1579
1565
int evtchn_get (evtchn_port_t evtchn )
1580
1566
{
1581
- int irq ;
1582
1567
struct irq_info * info ;
1583
1568
int err = - ENOENT ;
1584
1569
@@ -1587,11 +1572,7 @@ int evtchn_get(evtchn_port_t evtchn)
1587
1572
1588
1573
mutex_lock (& irq_mapping_update_lock );
1589
1574
1590
- irq = get_evtchn_to_irq (evtchn );
1591
- if (irq == -1 )
1592
- goto done ;
1593
-
1594
- info = info_for_irq (irq );
1575
+ info = evtchn_to_info (evtchn );
1595
1576
1596
1577
if (!info )
1597
1578
goto done ;
@@ -1611,10 +1592,11 @@ EXPORT_SYMBOL_GPL(evtchn_get);
1611
1592
1612
1593
void evtchn_put (evtchn_port_t evtchn )
1613
1594
{
1614
- int irq = get_evtchn_to_irq (evtchn );
1615
- if (WARN_ON (irq == -1 ))
1595
+ struct irq_info * info = evtchn_to_info (evtchn );
1596
+
1597
+ if (WARN_ON (!info ))
1616
1598
return ;
1617
- unbind_from_irq (irq );
1599
+ unbind_from_irq (info -> irq );
1618
1600
}
1619
1601
EXPORT_SYMBOL_GPL (evtchn_put );
1620
1602
@@ -1644,12 +1626,10 @@ struct evtchn_loop_ctrl {
1644
1626
1645
1627
void handle_irq_for_port (evtchn_port_t port , struct evtchn_loop_ctrl * ctrl )
1646
1628
{
1647
- int irq ;
1648
- struct irq_info * info ;
1629
+ struct irq_info * info = evtchn_to_info (port );
1649
1630
struct xenbus_device * dev ;
1650
1631
1651
- irq = get_evtchn_to_irq (port );
1652
- if (irq == -1 )
1632
+ if (!info )
1653
1633
return ;
1654
1634
1655
1635
/*
@@ -1674,7 +1654,6 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
1674
1654
}
1675
1655
}
1676
1656
1677
- info = info_for_irq (irq );
1678
1657
if (xchg_acquire (& info -> is_active , 1 ))
1679
1658
return ;
1680
1659
@@ -1688,7 +1667,7 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
1688
1667
info -> eoi_time = get_jiffies_64 () + event_eoi_delay ;
1689
1668
}
1690
1669
1691
- generic_handle_irq (irq );
1670
+ generic_handle_irq (info -> irq );
1692
1671
}
1693
1672
1694
1673
int xen_evtchn_do_upcall (void )
@@ -1746,7 +1725,7 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int irq)
1746
1725
mutex_lock (& irq_mapping_update_lock );
1747
1726
1748
1727
/* After resume the irq<->evtchn mappings are all cleared out */
1749
- BUG_ON (get_evtchn_to_irq (evtchn ) != -1 );
1728
+ BUG_ON (evtchn_to_info (evtchn ));
1750
1729
/* Expect irq to have been bound before,
1751
1730
so there should be a proper type */
1752
1731
BUG_ON (info -> type == IRQT_UNBOUND );
0 commit comments