1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 29a489f45SDavid Vrabel /* 39a489f45SDavid Vrabel * Xen event channels (2-level ABI) 49a489f45SDavid Vrabel * 59a489f45SDavid Vrabel * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 69a489f45SDavid Vrabel */ 79a489f45SDavid Vrabel 89a489f45SDavid Vrabel #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt 99a489f45SDavid Vrabel 109a489f45SDavid Vrabel #include <linux/linkage.h> 119a489f45SDavid Vrabel #include <linux/interrupt.h> 129a489f45SDavid Vrabel #include <linux/irq.h> 139a489f45SDavid Vrabel 149a489f45SDavid Vrabel #include <asm/sync_bitops.h> 159a489f45SDavid Vrabel #include <asm/xen/hypercall.h> 169a489f45SDavid Vrabel #include <asm/xen/hypervisor.h> 179a489f45SDavid Vrabel 189a489f45SDavid Vrabel #include <xen/xen.h> 199a489f45SDavid Vrabel #include <xen/xen-ops.h> 209a489f45SDavid Vrabel #include <xen/events.h> 219a489f45SDavid Vrabel #include <xen/interface/xen.h> 229a489f45SDavid Vrabel #include <xen/interface/event_channel.h> 239a489f45SDavid Vrabel 249a489f45SDavid Vrabel #include "events_internal.h" 259a489f45SDavid Vrabel 269a489f45SDavid Vrabel /* 279a489f45SDavid Vrabel * Note sizeof(xen_ulong_t) can be more than sizeof(unsigned long). Be 289a489f45SDavid Vrabel * careful to only use bitops which allow for this (e.g 299a489f45SDavid Vrabel * test_bit/find_first_bit and friends but not __ffs) and to pass 309a489f45SDavid Vrabel * BITS_PER_EVTCHN_WORD as the bitmask length. 319a489f45SDavid Vrabel */ 329a489f45SDavid Vrabel #define BITS_PER_EVTCHN_WORD (sizeof(xen_ulong_t)*8) 339a489f45SDavid Vrabel /* 349a489f45SDavid Vrabel * Make a bitmask (i.e. unsigned long *) of a xen_ulong_t 359a489f45SDavid Vrabel * array. Primarily to avoid long lines (hence the terse name). 369a489f45SDavid Vrabel */ 379a489f45SDavid Vrabel #define BM(x) (unsigned long *)(x) 389a489f45SDavid Vrabel /* Find the first set bit in a evtchn mask */ 399a489f45SDavid Vrabel #define EVTCHN_FIRST_BIT(w) find_first_bit(BM(&(w)), BITS_PER_EVTCHN_WORD) 409a489f45SDavid Vrabel 4125528213SPeter Zijlstra #define EVTCHN_MASK_SIZE (EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD) 4225528213SPeter Zijlstra 4325528213SPeter Zijlstra static DEFINE_PER_CPU(xen_ulong_t [EVTCHN_MASK_SIZE], cpu_evtchn_mask); 449a489f45SDavid Vrabel 45d0b075ffSDavid Vrabel static unsigned evtchn_2l_max_channels(void) 46d0b075ffSDavid Vrabel { 47bf2bbe07SDavid Vrabel return EVTCHN_2L_NR_CHANNELS; 48d0b075ffSDavid Vrabel } 49d0b075ffSDavid Vrabel 50*9e77d96bSJuergen Gross static void evtchn_2l_remove(evtchn_port_t evtchn, unsigned int cpu) 51*9e77d96bSJuergen Gross { 52*9e77d96bSJuergen Gross clear_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, cpu))); 53*9e77d96bSJuergen Gross } 54*9e77d96bSJuergen Gross 557e14cde1SJuergen Gross static void evtchn_2l_bind_to_cpu(evtchn_port_t evtchn, unsigned int cpu, 567e14cde1SJuergen Gross unsigned int old_cpu) 579a489f45SDavid Vrabel { 587e14cde1SJuergen Gross clear_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, old_cpu))); 597e14cde1SJuergen Gross set_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, cpu))); 609a489f45SDavid Vrabel } 619a489f45SDavid Vrabel 620102e4efSYan Yankovskyi static void evtchn_2l_clear_pending(evtchn_port_t port) 639a489f45SDavid Vrabel { 649a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 659a489f45SDavid Vrabel sync_clear_bit(port, BM(&s->evtchn_pending[0])); 669a489f45SDavid Vrabel } 679a489f45SDavid Vrabel 680102e4efSYan Yankovskyi static void evtchn_2l_set_pending(evtchn_port_t port) 699a489f45SDavid Vrabel { 709a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 719a489f45SDavid Vrabel sync_set_bit(port, BM(&s->evtchn_pending[0])); 729a489f45SDavid Vrabel } 739a489f45SDavid Vrabel 740102e4efSYan Yankovskyi static bool evtchn_2l_is_pending(evtchn_port_t port) 759a489f45SDavid Vrabel { 769a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 779a489f45SDavid Vrabel return sync_test_bit(port, BM(&s->evtchn_pending[0])); 789a489f45SDavid Vrabel } 799a489f45SDavid Vrabel 800102e4efSYan Yankovskyi static bool evtchn_2l_test_and_set_mask(evtchn_port_t port) 819a489f45SDavid Vrabel { 829a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 839a489f45SDavid Vrabel return sync_test_and_set_bit(port, BM(&s->evtchn_mask[0])); 849a489f45SDavid Vrabel } 859a489f45SDavid Vrabel 860102e4efSYan Yankovskyi static void evtchn_2l_mask(evtchn_port_t port) 879a489f45SDavid Vrabel { 889a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 899a489f45SDavid Vrabel sync_set_bit(port, BM(&s->evtchn_mask[0])); 909a489f45SDavid Vrabel } 919a489f45SDavid Vrabel 920102e4efSYan Yankovskyi static void evtchn_2l_unmask(evtchn_port_t port) 939a489f45SDavid Vrabel { 949a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 959a489f45SDavid Vrabel unsigned int cpu = get_cpu(); 969a489f45SDavid Vrabel int do_hypercall = 0, evtchn_pending = 0; 979a489f45SDavid Vrabel 989a489f45SDavid Vrabel BUG_ON(!irqs_disabled()); 999a489f45SDavid Vrabel 1004d3fe31bSJuergen Gross smp_wmb(); /* All writes before unmask must be visible. */ 1014d3fe31bSJuergen Gross 1029a489f45SDavid Vrabel if (unlikely((cpu != cpu_from_evtchn(port)))) 1039a489f45SDavid Vrabel do_hypercall = 1; 1049a489f45SDavid Vrabel else { 1059a489f45SDavid Vrabel /* 1069a489f45SDavid Vrabel * Need to clear the mask before checking pending to 1079a489f45SDavid Vrabel * avoid a race with an event becoming pending. 1089a489f45SDavid Vrabel * 1099a489f45SDavid Vrabel * EVTCHNOP_unmask will only trigger an upcall if the 1109a489f45SDavid Vrabel * mask bit was set, so if a hypercall is needed 1119a489f45SDavid Vrabel * remask the event. 1129a489f45SDavid Vrabel */ 1139a489f45SDavid Vrabel sync_clear_bit(port, BM(&s->evtchn_mask[0])); 1149a489f45SDavid Vrabel evtchn_pending = sync_test_bit(port, BM(&s->evtchn_pending[0])); 1159a489f45SDavid Vrabel 1169a489f45SDavid Vrabel if (unlikely(evtchn_pending && xen_hvm_domain())) { 1179a489f45SDavid Vrabel sync_set_bit(port, BM(&s->evtchn_mask[0])); 1189a489f45SDavid Vrabel do_hypercall = 1; 1199a489f45SDavid Vrabel } 1209a489f45SDavid Vrabel } 1219a489f45SDavid Vrabel 1229a489f45SDavid Vrabel /* Slow path (hypercall) if this is a non-local port or if this is 1239a489f45SDavid Vrabel * an hvm domain and an event is pending (hvm domains don't have 1249a489f45SDavid Vrabel * their own implementation of irq_enable). */ 1259a489f45SDavid Vrabel if (do_hypercall) { 1269a489f45SDavid Vrabel struct evtchn_unmask unmask = { .port = port }; 1279a489f45SDavid Vrabel (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask); 1289a489f45SDavid Vrabel } else { 1299a489f45SDavid Vrabel struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); 1309a489f45SDavid Vrabel 1319a489f45SDavid Vrabel /* 1329a489f45SDavid Vrabel * The following is basically the equivalent of 1339a489f45SDavid Vrabel * 'hw_resend_irq'. Just like a real IO-APIC we 'lose 1349a489f45SDavid Vrabel * the interrupt edge' if the channel is masked. 1359a489f45SDavid Vrabel */ 1369a489f45SDavid Vrabel if (evtchn_pending && 1379a489f45SDavid Vrabel !sync_test_and_set_bit(port / BITS_PER_EVTCHN_WORD, 1389a489f45SDavid Vrabel BM(&vcpu_info->evtchn_pending_sel))) 1399a489f45SDavid Vrabel vcpu_info->evtchn_upcall_pending = 1; 1409a489f45SDavid Vrabel } 1419a489f45SDavid Vrabel 1429a489f45SDavid Vrabel put_cpu(); 1439a489f45SDavid Vrabel } 1449a489f45SDavid Vrabel 1459a489f45SDavid Vrabel static DEFINE_PER_CPU(unsigned int, current_word_idx); 1469a489f45SDavid Vrabel static DEFINE_PER_CPU(unsigned int, current_bit_idx); 1479a489f45SDavid Vrabel 1489a489f45SDavid Vrabel /* 1499a489f45SDavid Vrabel * Mask out the i least significant bits of w 1509a489f45SDavid Vrabel */ 1519a489f45SDavid Vrabel #define MASK_LSBS(w, i) (w & ((~((xen_ulong_t)0UL)) << i)) 1529a489f45SDavid Vrabel 1539a489f45SDavid Vrabel static inline xen_ulong_t active_evtchns(unsigned int cpu, 1549a489f45SDavid Vrabel struct shared_info *sh, 1559a489f45SDavid Vrabel unsigned int idx) 1569a489f45SDavid Vrabel { 1579a489f45SDavid Vrabel return sh->evtchn_pending[idx] & 1589a489f45SDavid Vrabel per_cpu(cpu_evtchn_mask, cpu)[idx] & 1599a489f45SDavid Vrabel ~sh->evtchn_mask[idx]; 1609a489f45SDavid Vrabel } 1619a489f45SDavid Vrabel 1629a489f45SDavid Vrabel /* 1639a489f45SDavid Vrabel * Search the CPU's pending events bitmasks. For each one found, map 1649a489f45SDavid Vrabel * the event number to an irq, and feed it into do_IRQ() for handling. 1659a489f45SDavid Vrabel * 1669a489f45SDavid Vrabel * Xen uses a two-level bitmap to speed searching. The first level is 1679a489f45SDavid Vrabel * a bitset of words which contain pending event bits. The second 1689a489f45SDavid Vrabel * level is a bitset of pending events themselves. 1699a489f45SDavid Vrabel */ 170e99502f7SJuergen Gross static void evtchn_2l_handle_events(unsigned cpu, struct evtchn_loop_ctrl *ctrl) 1719a489f45SDavid Vrabel { 1729a489f45SDavid Vrabel int irq; 1739a489f45SDavid Vrabel xen_ulong_t pending_words; 1749a489f45SDavid Vrabel xen_ulong_t pending_bits; 1759a489f45SDavid Vrabel int start_word_idx, start_bit_idx; 1769a489f45SDavid Vrabel int word_idx, bit_idx; 1779a489f45SDavid Vrabel int i; 1789a489f45SDavid Vrabel struct shared_info *s = HYPERVISOR_shared_info; 1799a489f45SDavid Vrabel struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); 1809a489f45SDavid Vrabel 1819a489f45SDavid Vrabel /* Timer interrupt has highest priority. */ 1829a489f45SDavid Vrabel irq = irq_from_virq(cpu, VIRQ_TIMER); 1839a489f45SDavid Vrabel if (irq != -1) { 1840102e4efSYan Yankovskyi evtchn_port_t evtchn = evtchn_from_irq(irq); 1859a489f45SDavid Vrabel word_idx = evtchn / BITS_PER_LONG; 1869a489f45SDavid Vrabel bit_idx = evtchn % BITS_PER_LONG; 187589d03e9SThomas Gleixner if (active_evtchns(cpu, s, word_idx) & (1ULL << bit_idx)) 188589d03e9SThomas Gleixner generic_handle_irq(irq); 1899a489f45SDavid Vrabel } 1909a489f45SDavid Vrabel 1919a489f45SDavid Vrabel /* 1929a489f45SDavid Vrabel * Master flag must be cleared /before/ clearing 1939a489f45SDavid Vrabel * selector flag. xchg_xen_ulong must contain an 1949a489f45SDavid Vrabel * appropriate barrier. 1959a489f45SDavid Vrabel */ 1969a489f45SDavid Vrabel pending_words = xchg_xen_ulong(&vcpu_info->evtchn_pending_sel, 0); 1979a489f45SDavid Vrabel 1989a489f45SDavid Vrabel start_word_idx = __this_cpu_read(current_word_idx); 1999a489f45SDavid Vrabel start_bit_idx = __this_cpu_read(current_bit_idx); 2009a489f45SDavid Vrabel 2019a489f45SDavid Vrabel word_idx = start_word_idx; 2029a489f45SDavid Vrabel 2039a489f45SDavid Vrabel for (i = 0; pending_words != 0; i++) { 2049a489f45SDavid Vrabel xen_ulong_t words; 2059a489f45SDavid Vrabel 2069a489f45SDavid Vrabel words = MASK_LSBS(pending_words, word_idx); 2079a489f45SDavid Vrabel 2089a489f45SDavid Vrabel /* 2099a489f45SDavid Vrabel * If we masked out all events, wrap to beginning. 2109a489f45SDavid Vrabel */ 2119a489f45SDavid Vrabel if (words == 0) { 2129a489f45SDavid Vrabel word_idx = 0; 2139a489f45SDavid Vrabel bit_idx = 0; 2149a489f45SDavid Vrabel continue; 2159a489f45SDavid Vrabel } 2169a489f45SDavid Vrabel word_idx = EVTCHN_FIRST_BIT(words); 2179a489f45SDavid Vrabel 2189a489f45SDavid Vrabel pending_bits = active_evtchns(cpu, s, word_idx); 2199a489f45SDavid Vrabel bit_idx = 0; /* usually scan entire word from start */ 2209a489f45SDavid Vrabel /* 2219a489f45SDavid Vrabel * We scan the starting word in two parts. 2229a489f45SDavid Vrabel * 2239a489f45SDavid Vrabel * 1st time: start in the middle, scanning the 2249a489f45SDavid Vrabel * upper bits. 2259a489f45SDavid Vrabel * 2269a489f45SDavid Vrabel * 2nd time: scan the whole word (not just the 2279a489f45SDavid Vrabel * parts skipped in the first pass) -- if an 2289a489f45SDavid Vrabel * event in the previously scanned bits is 2299a489f45SDavid Vrabel * pending again it would just be scanned on 2309a489f45SDavid Vrabel * the next loop anyway. 2319a489f45SDavid Vrabel */ 2329a489f45SDavid Vrabel if (word_idx == start_word_idx) { 2339a489f45SDavid Vrabel if (i == 0) 2349a489f45SDavid Vrabel bit_idx = start_bit_idx; 2359a489f45SDavid Vrabel } 2369a489f45SDavid Vrabel 2379a489f45SDavid Vrabel do { 2389a489f45SDavid Vrabel xen_ulong_t bits; 2390102e4efSYan Yankovskyi evtchn_port_t port; 2409a489f45SDavid Vrabel 2419a489f45SDavid Vrabel bits = MASK_LSBS(pending_bits, bit_idx); 2429a489f45SDavid Vrabel 2439a489f45SDavid Vrabel /* If we masked out all events, move on. */ 2449a489f45SDavid Vrabel if (bits == 0) 2459a489f45SDavid Vrabel break; 2469a489f45SDavid Vrabel 2479a489f45SDavid Vrabel bit_idx = EVTCHN_FIRST_BIT(bits); 2489a489f45SDavid Vrabel 2499a489f45SDavid Vrabel /* Process port. */ 2509a489f45SDavid Vrabel port = (word_idx * BITS_PER_EVTCHN_WORD) + bit_idx; 251e99502f7SJuergen Gross handle_irq_for_port(port, ctrl); 2529a489f45SDavid Vrabel 2539a489f45SDavid Vrabel bit_idx = (bit_idx + 1) % BITS_PER_EVTCHN_WORD; 2549a489f45SDavid Vrabel 2559a489f45SDavid Vrabel /* Next caller starts at last processed + 1 */ 2569a489f45SDavid Vrabel __this_cpu_write(current_word_idx, 2579a489f45SDavid Vrabel bit_idx ? word_idx : 2589a489f45SDavid Vrabel (word_idx+1) % BITS_PER_EVTCHN_WORD); 2599a489f45SDavid Vrabel __this_cpu_write(current_bit_idx, bit_idx); 2609a489f45SDavid Vrabel } while (bit_idx != 0); 2619a489f45SDavid Vrabel 2629a489f45SDavid Vrabel /* Scan start_l1i twice; all others once. */ 2639a489f45SDavid Vrabel if ((word_idx != start_word_idx) || (i != 0)) 2649a489f45SDavid Vrabel pending_words &= ~(1UL << word_idx); 2659a489f45SDavid Vrabel 2669a489f45SDavid Vrabel word_idx = (word_idx + 1) % BITS_PER_EVTCHN_WORD; 2679a489f45SDavid Vrabel } 2689a489f45SDavid Vrabel } 2699a489f45SDavid Vrabel 2709a489f45SDavid Vrabel irqreturn_t xen_debug_interrupt(int irq, void *dev_id) 2719a489f45SDavid Vrabel { 2729a489f45SDavid Vrabel struct shared_info *sh = HYPERVISOR_shared_info; 2739a489f45SDavid Vrabel int cpu = smp_processor_id(); 2749a489f45SDavid Vrabel xen_ulong_t *cpu_evtchn = per_cpu(cpu_evtchn_mask, cpu); 2759a489f45SDavid Vrabel int i; 2769a489f45SDavid Vrabel unsigned long flags; 2779a489f45SDavid Vrabel static DEFINE_SPINLOCK(debug_lock); 2789a489f45SDavid Vrabel struct vcpu_info *v; 2799a489f45SDavid Vrabel 2809a489f45SDavid Vrabel spin_lock_irqsave(&debug_lock, flags); 2819a489f45SDavid Vrabel 2829a489f45SDavid Vrabel printk("\nvcpu %d\n ", cpu); 2839a489f45SDavid Vrabel 2849a489f45SDavid Vrabel for_each_online_cpu(i) { 2859a489f45SDavid Vrabel int pending; 2869a489f45SDavid Vrabel v = per_cpu(xen_vcpu, i); 2879a489f45SDavid Vrabel pending = (get_irq_regs() && i == cpu) 2889a489f45SDavid Vrabel ? xen_irqs_disabled(get_irq_regs()) 2899a489f45SDavid Vrabel : v->evtchn_upcall_mask; 2909a489f45SDavid Vrabel printk("%d: masked=%d pending=%d event_sel %0*"PRI_xen_ulong"\n ", i, 2919a489f45SDavid Vrabel pending, v->evtchn_upcall_pending, 2929a489f45SDavid Vrabel (int)(sizeof(v->evtchn_pending_sel)*2), 2939a489f45SDavid Vrabel v->evtchn_pending_sel); 2949a489f45SDavid Vrabel } 2959a489f45SDavid Vrabel v = per_cpu(xen_vcpu, cpu); 2969a489f45SDavid Vrabel 2979a489f45SDavid Vrabel printk("\npending:\n "); 2989a489f45SDavid Vrabel for (i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--) 2999a489f45SDavid Vrabel printk("%0*"PRI_xen_ulong"%s", 3009a489f45SDavid Vrabel (int)sizeof(sh->evtchn_pending[0])*2, 3019a489f45SDavid Vrabel sh->evtchn_pending[i], 3029a489f45SDavid Vrabel i % 8 == 0 ? "\n " : " "); 3039a489f45SDavid Vrabel printk("\nglobal mask:\n "); 3049a489f45SDavid Vrabel for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) 3059a489f45SDavid Vrabel printk("%0*"PRI_xen_ulong"%s", 3069a489f45SDavid Vrabel (int)(sizeof(sh->evtchn_mask[0])*2), 3079a489f45SDavid Vrabel sh->evtchn_mask[i], 3089a489f45SDavid Vrabel i % 8 == 0 ? "\n " : " "); 3099a489f45SDavid Vrabel 3109a489f45SDavid Vrabel printk("\nglobally unmasked:\n "); 3119a489f45SDavid Vrabel for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) 3129a489f45SDavid Vrabel printk("%0*"PRI_xen_ulong"%s", 3139a489f45SDavid Vrabel (int)(sizeof(sh->evtchn_mask[0])*2), 3149a489f45SDavid Vrabel sh->evtchn_pending[i] & ~sh->evtchn_mask[i], 3159a489f45SDavid Vrabel i % 8 == 0 ? "\n " : " "); 3169a489f45SDavid Vrabel 3179a489f45SDavid Vrabel printk("\nlocal cpu%d mask:\n ", cpu); 318bf2bbe07SDavid Vrabel for (i = (EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD)-1; i >= 0; i--) 3199a489f45SDavid Vrabel printk("%0*"PRI_xen_ulong"%s", (int)(sizeof(cpu_evtchn[0])*2), 3209a489f45SDavid Vrabel cpu_evtchn[i], 3219a489f45SDavid Vrabel i % 8 == 0 ? "\n " : " "); 3229a489f45SDavid Vrabel 3239a489f45SDavid Vrabel printk("\nlocally unmasked:\n "); 3249a489f45SDavid Vrabel for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) { 3259a489f45SDavid Vrabel xen_ulong_t pending = sh->evtchn_pending[i] 3269a489f45SDavid Vrabel & ~sh->evtchn_mask[i] 3279a489f45SDavid Vrabel & cpu_evtchn[i]; 3289a489f45SDavid Vrabel printk("%0*"PRI_xen_ulong"%s", 3299a489f45SDavid Vrabel (int)(sizeof(sh->evtchn_mask[0])*2), 3309a489f45SDavid Vrabel pending, i % 8 == 0 ? "\n " : " "); 3319a489f45SDavid Vrabel } 3329a489f45SDavid Vrabel 3339a489f45SDavid Vrabel printk("\npending list:\n"); 334bf2bbe07SDavid Vrabel for (i = 0; i < EVTCHN_2L_NR_CHANNELS; i++) { 3359a489f45SDavid Vrabel if (sync_test_bit(i, BM(sh->evtchn_pending))) { 3369a489f45SDavid Vrabel int word_idx = i / BITS_PER_EVTCHN_WORD; 3379a489f45SDavid Vrabel printk(" %d: event %d -> irq %d%s%s%s\n", 3389a489f45SDavid Vrabel cpu_from_evtchn(i), i, 339d0b075ffSDavid Vrabel get_evtchn_to_irq(i), 3409a489f45SDavid Vrabel sync_test_bit(word_idx, BM(&v->evtchn_pending_sel)) 3419a489f45SDavid Vrabel ? "" : " l2-clear", 3429a489f45SDavid Vrabel !sync_test_bit(i, BM(sh->evtchn_mask)) 3439a489f45SDavid Vrabel ? "" : " globally-masked", 3449a489f45SDavid Vrabel sync_test_bit(i, BM(cpu_evtchn)) 3459a489f45SDavid Vrabel ? "" : " locally-masked"); 3469a489f45SDavid Vrabel } 3479a489f45SDavid Vrabel } 3489a489f45SDavid Vrabel 3499a489f45SDavid Vrabel spin_unlock_irqrestore(&debug_lock, flags); 3509a489f45SDavid Vrabel 3519a489f45SDavid Vrabel return IRQ_HANDLED; 3529a489f45SDavid Vrabel } 353ab9a1ccaSDavid Vrabel 3545cec9883SBoris Ostrovsky static void evtchn_2l_resume(void) 3555cec9883SBoris Ostrovsky { 3565cec9883SBoris Ostrovsky int i; 3575cec9883SBoris Ostrovsky 3585cec9883SBoris Ostrovsky for_each_online_cpu(i) 3595cec9883SBoris Ostrovsky memset(per_cpu(cpu_evtchn_mask, i), 0, sizeof(xen_ulong_t) * 3605cec9883SBoris Ostrovsky EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD); 3615cec9883SBoris Ostrovsky } 3625cec9883SBoris Ostrovsky 363*9e77d96bSJuergen Gross static int evtchn_2l_percpu_deinit(unsigned int cpu) 364*9e77d96bSJuergen Gross { 365*9e77d96bSJuergen Gross memset(per_cpu(cpu_evtchn_mask, cpu), 0, sizeof(xen_ulong_t) * 366*9e77d96bSJuergen Gross EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD); 367*9e77d96bSJuergen Gross 368*9e77d96bSJuergen Gross return 0; 369*9e77d96bSJuergen Gross } 370*9e77d96bSJuergen Gross 371ab9a1ccaSDavid Vrabel static const struct evtchn_ops evtchn_ops_2l = { 372d0b075ffSDavid Vrabel .max_channels = evtchn_2l_max_channels, 373d0b075ffSDavid Vrabel .nr_channels = evtchn_2l_max_channels, 374*9e77d96bSJuergen Gross .remove = evtchn_2l_remove, 375ab9a1ccaSDavid Vrabel .bind_to_cpu = evtchn_2l_bind_to_cpu, 376ab9a1ccaSDavid Vrabel .clear_pending = evtchn_2l_clear_pending, 377ab9a1ccaSDavid Vrabel .set_pending = evtchn_2l_set_pending, 378ab9a1ccaSDavid Vrabel .is_pending = evtchn_2l_is_pending, 379ab9a1ccaSDavid Vrabel .test_and_set_mask = evtchn_2l_test_and_set_mask, 380ab9a1ccaSDavid Vrabel .mask = evtchn_2l_mask, 381ab9a1ccaSDavid Vrabel .unmask = evtchn_2l_unmask, 382ab9a1ccaSDavid Vrabel .handle_events = evtchn_2l_handle_events, 3835cec9883SBoris Ostrovsky .resume = evtchn_2l_resume, 384*9e77d96bSJuergen Gross .percpu_deinit = evtchn_2l_percpu_deinit, 385ab9a1ccaSDavid Vrabel }; 386ab9a1ccaSDavid Vrabel 387ab9a1ccaSDavid Vrabel void __init xen_evtchn_2l_init(void) 388ab9a1ccaSDavid Vrabel { 389ab9a1ccaSDavid Vrabel pr_info("Using 2-level ABI\n"); 390ab9a1ccaSDavid Vrabel evtchn_ops = &evtchn_ops_2l; 391ab9a1ccaSDavid Vrabel } 392