@@ -248,15 +248,6 @@ static int set_evtchn_to_irq(evtchn_port_t evtchn, unsigned int irq)
248248 return 0 ;
249249}
250250
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-
260251/* Get info for IRQ */
261252static struct irq_info * info_for_irq (unsigned irq )
262253{
@@ -274,6 +265,19 @@ static void set_info_for_irq(unsigned int irq, struct irq_info *info)
274265 irq_set_chip_data (irq , info );
275266}
276267
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+
277281/* Per CPU channel accounting */
278282static void channels_on_cpu_dec (struct irq_info * info )
279283{
@@ -429,7 +433,9 @@ static evtchn_port_t evtchn_from_irq(unsigned int irq)
429433
430434unsigned int irq_from_evtchn (evtchn_port_t evtchn )
431435{
432- return get_evtchn_to_irq (evtchn );
436+ struct irq_info * info = evtchn_to_info (evtchn );
437+
438+ return info ? info -> irq : -1 ;
433439}
434440EXPORT_SYMBOL_GPL (irq_from_evtchn );
435441
@@ -473,25 +479,11 @@ static unsigned pirq_from_irq(unsigned irq)
473479 return info -> u .pirq .pirq ;
474480}
475481
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-
486482unsigned int cpu_from_evtchn (evtchn_port_t evtchn )
487483{
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 );
493485
494- return ret ;
486+ return info ? info -> cpu : 0 ;
495487}
496488
497489static void do_mask (struct irq_info * info , u8 reason )
@@ -540,13 +532,12 @@ static bool pirq_needs_eoi_flag(unsigned irq)
540532static void bind_evtchn_to_cpu (evtchn_port_t evtchn , unsigned int cpu ,
541533 bool force_affinity )
542534{
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 );
545536
546- BUG_ON (irq == -1 );
537+ BUG_ON (info == NULL );
547538
548539 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 );
550541
551542 irq_data_update_affinity (data , cpumask_of (cpu ));
552543 irq_data_update_effective_affinity (data , cpumask_of (cpu ));
@@ -979,13 +970,13 @@ static void __unbind_from_irq(unsigned int irq)
979970 }
980971
981972 if (VALID_EVTCHN (evtchn )) {
982- unsigned int cpu = cpu_from_irq ( irq ) ;
973+ unsigned int cpu = info -> cpu ;
983974 struct xenbus_device * dev ;
984975
985976 if (!info -> is_static )
986977 xen_evtchn_close (evtchn );
987978
988- switch (type_from_irq ( irq ) ) {
979+ switch (info -> type ) {
989980 case IRQT_VIRQ :
990981 per_cpu (virq_to_irq , cpu )[virq_from_irq (irq )] = -1 ;
991982 break ;
@@ -1185,15 +1176,16 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *chip,
11851176{
11861177 int irq ;
11871178 int ret ;
1179+ struct irq_info * info ;
11881180
11891181 if (evtchn >= xen_evtchn_max_channels ())
11901182 return - ENOMEM ;
11911183
11921184 mutex_lock (& irq_mapping_update_lock );
11931185
1194- irq = get_evtchn_to_irq (evtchn );
1186+ info = evtchn_to_info (evtchn );
11951187
1196- if (irq == -1 ) {
1188+ if (! info ) {
11971189 irq = xen_allocate_irq_dynamic ();
11981190 if (irq < 0 )
11991191 goto out ;
@@ -1216,9 +1208,9 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *chip,
12161208 */
12171209 bind_evtchn_to_cpu (evtchn , 0 , false);
12181210 } 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 ))
12211212 info -> refcnt ++ ;
1213+ irq = info -> irq ;
12221214 }
12231215
12241216out :
@@ -1556,13 +1548,7 @@ EXPORT_SYMBOL_GPL(xen_set_irq_priority);
15561548
15571549int evtchn_make_refcounted (evtchn_port_t evtchn , bool is_static )
15581550{
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 );
15661552
15671553 if (!info )
15681554 return - ENOENT ;
@@ -1578,7 +1564,6 @@ EXPORT_SYMBOL_GPL(evtchn_make_refcounted);
15781564
15791565int evtchn_get (evtchn_port_t evtchn )
15801566{
1581- int irq ;
15821567 struct irq_info * info ;
15831568 int err = - ENOENT ;
15841569
@@ -1587,11 +1572,7 @@ int evtchn_get(evtchn_port_t evtchn)
15871572
15881573 mutex_lock (& irq_mapping_update_lock );
15891574
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 );
15951576
15961577 if (!info )
15971578 goto done ;
@@ -1611,10 +1592,11 @@ EXPORT_SYMBOL_GPL(evtchn_get);
16111592
16121593void evtchn_put (evtchn_port_t evtchn )
16131594{
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 ))
16161598 return ;
1617- unbind_from_irq (irq );
1599+ unbind_from_irq (info -> irq );
16181600}
16191601EXPORT_SYMBOL_GPL (evtchn_put );
16201602
@@ -1644,12 +1626,10 @@ struct evtchn_loop_ctrl {
16441626
16451627void handle_irq_for_port (evtchn_port_t port , struct evtchn_loop_ctrl * ctrl )
16461628{
1647- int irq ;
1648- struct irq_info * info ;
1629+ struct irq_info * info = evtchn_to_info (port );
16491630 struct xenbus_device * dev ;
16501631
1651- irq = get_evtchn_to_irq (port );
1652- if (irq == -1 )
1632+ if (!info )
16531633 return ;
16541634
16551635 /*
@@ -1674,7 +1654,6 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
16741654 }
16751655 }
16761656
1677- info = info_for_irq (irq );
16781657 if (xchg_acquire (& info -> is_active , 1 ))
16791658 return ;
16801659
@@ -1688,7 +1667,7 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
16881667 info -> eoi_time = get_jiffies_64 () + event_eoi_delay ;
16891668 }
16901669
1691- generic_handle_irq (irq );
1670+ generic_handle_irq (info -> irq );
16921671}
16931672
16941673int xen_evtchn_do_upcall (void )
@@ -1746,7 +1725,7 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int irq)
17461725 mutex_lock (& irq_mapping_update_lock );
17471726
17481727 /* 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 ));
17501729 /* Expect irq to have been bound before,
17511730 so there should be a proper type */
17521731 BUG_ON (info -> type == IRQT_UNBOUND );
0 commit comments