xref: /openbmc/linux/drivers/xen/events/events_2l.c (revision b79345ef)
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 
evtchn_2l_max_channels(void)45d0b075ffSDavid Vrabel static unsigned evtchn_2l_max_channels(void)
46d0b075ffSDavid Vrabel {
47bf2bbe07SDavid Vrabel 	return EVTCHN_2L_NR_CHANNELS;
48d0b075ffSDavid Vrabel }
49d0b075ffSDavid Vrabel 
evtchn_2l_remove(evtchn_port_t evtchn,unsigned int cpu)509e77d96bSJuergen Gross static void evtchn_2l_remove(evtchn_port_t evtchn, unsigned int cpu)
519e77d96bSJuergen Gross {
529e77d96bSJuergen Gross 	clear_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, cpu)));
539e77d96bSJuergen Gross }
549e77d96bSJuergen Gross 
evtchn_2l_bind_to_cpu(evtchn_port_t evtchn,unsigned int cpu,unsigned int old_cpu)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 
evtchn_2l_clear_pending(evtchn_port_t port)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 
evtchn_2l_set_pending(evtchn_port_t port)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 
evtchn_2l_is_pending(evtchn_port_t port)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 
evtchn_2l_mask(evtchn_port_t port)800102e4efSYan Yankovskyi static void evtchn_2l_mask(evtchn_port_t port)
819a489f45SDavid Vrabel {
829a489f45SDavid Vrabel 	struct shared_info *s = HYPERVISOR_shared_info;
839a489f45SDavid Vrabel 	sync_set_bit(port, BM(&s->evtchn_mask[0]));
849a489f45SDavid Vrabel }
859a489f45SDavid Vrabel 
evtchn_2l_unmask(evtchn_port_t port)860102e4efSYan Yankovskyi static void evtchn_2l_unmask(evtchn_port_t port)
879a489f45SDavid Vrabel {
889a489f45SDavid Vrabel 	struct shared_info *s = HYPERVISOR_shared_info;
899a489f45SDavid Vrabel 	unsigned int cpu = get_cpu();
909a489f45SDavid Vrabel 	int do_hypercall = 0, evtchn_pending = 0;
919a489f45SDavid Vrabel 
929a489f45SDavid Vrabel 	BUG_ON(!irqs_disabled());
939a489f45SDavid Vrabel 
944d3fe31bSJuergen Gross 	smp_wmb();	/* All writes before unmask must be visible. */
954d3fe31bSJuergen Gross 
969a489f45SDavid Vrabel 	if (unlikely((cpu != cpu_from_evtchn(port))))
979a489f45SDavid Vrabel 		do_hypercall = 1;
989a489f45SDavid Vrabel 	else {
999a489f45SDavid Vrabel 		/*
1009a489f45SDavid Vrabel 		 * Need to clear the mask before checking pending to
1019a489f45SDavid Vrabel 		 * avoid a race with an event becoming pending.
1029a489f45SDavid Vrabel 		 *
1039a489f45SDavid Vrabel 		 * EVTCHNOP_unmask will only trigger an upcall if the
1049a489f45SDavid Vrabel 		 * mask bit was set, so if a hypercall is needed
1059a489f45SDavid Vrabel 		 * remask the event.
1069a489f45SDavid Vrabel 		 */
1079a489f45SDavid Vrabel 		sync_clear_bit(port, BM(&s->evtchn_mask[0]));
1089a489f45SDavid Vrabel 		evtchn_pending = sync_test_bit(port, BM(&s->evtchn_pending[0]));
1099a489f45SDavid Vrabel 
1109a489f45SDavid Vrabel 		if (unlikely(evtchn_pending && xen_hvm_domain())) {
1119a489f45SDavid Vrabel 			sync_set_bit(port, BM(&s->evtchn_mask[0]));
1129a489f45SDavid Vrabel 			do_hypercall = 1;
1139a489f45SDavid Vrabel 		}
1149a489f45SDavid Vrabel 	}
1159a489f45SDavid Vrabel 
1169a489f45SDavid Vrabel 	/* Slow path (hypercall) if this is a non-local port or if this is
1179a489f45SDavid Vrabel 	 * an hvm domain and an event is pending (hvm domains don't have
1189a489f45SDavid Vrabel 	 * their own implementation of irq_enable). */
1199a489f45SDavid Vrabel 	if (do_hypercall) {
1209a489f45SDavid Vrabel 		struct evtchn_unmask unmask = { .port = port };
1219a489f45SDavid Vrabel 		(void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
1229a489f45SDavid Vrabel 	} else {
1239a489f45SDavid Vrabel 		struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
1249a489f45SDavid Vrabel 
1259a489f45SDavid Vrabel 		/*
1269a489f45SDavid Vrabel 		 * The following is basically the equivalent of
1279a489f45SDavid Vrabel 		 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
1289a489f45SDavid Vrabel 		 * the interrupt edge' if the channel is masked.
1299a489f45SDavid Vrabel 		 */
1309a489f45SDavid Vrabel 		if (evtchn_pending &&
1319a489f45SDavid Vrabel 		    !sync_test_and_set_bit(port / BITS_PER_EVTCHN_WORD,
1329a489f45SDavid Vrabel 					   BM(&vcpu_info->evtchn_pending_sel)))
1339a489f45SDavid Vrabel 			vcpu_info->evtchn_upcall_pending = 1;
1349a489f45SDavid Vrabel 	}
1359a489f45SDavid Vrabel 
1369a489f45SDavid Vrabel 	put_cpu();
1379a489f45SDavid Vrabel }
1389a489f45SDavid Vrabel 
1399a489f45SDavid Vrabel static DEFINE_PER_CPU(unsigned int, current_word_idx);
1409a489f45SDavid Vrabel static DEFINE_PER_CPU(unsigned int, current_bit_idx);
1419a489f45SDavid Vrabel 
1429a489f45SDavid Vrabel /*
1439a489f45SDavid Vrabel  * Mask out the i least significant bits of w
1449a489f45SDavid Vrabel  */
1459a489f45SDavid Vrabel #define MASK_LSBS(w, i) (w & ((~((xen_ulong_t)0UL)) << i))
1469a489f45SDavid Vrabel 
active_evtchns(unsigned int cpu,struct shared_info * sh,unsigned int idx)1479a489f45SDavid Vrabel static inline xen_ulong_t active_evtchns(unsigned int cpu,
1489a489f45SDavid Vrabel 					 struct shared_info *sh,
1499a489f45SDavid Vrabel 					 unsigned int idx)
1509a489f45SDavid Vrabel {
1519a489f45SDavid Vrabel 	return sh->evtchn_pending[idx] &
1529a489f45SDavid Vrabel 		per_cpu(cpu_evtchn_mask, cpu)[idx] &
1539a489f45SDavid Vrabel 		~sh->evtchn_mask[idx];
1549a489f45SDavid Vrabel }
1559a489f45SDavid Vrabel 
1569a489f45SDavid Vrabel /*
1579a489f45SDavid Vrabel  * Search the CPU's pending events bitmasks.  For each one found, map
1589a489f45SDavid Vrabel  * the event number to an irq, and feed it into do_IRQ() for handling.
1599a489f45SDavid Vrabel  *
1609a489f45SDavid Vrabel  * Xen uses a two-level bitmap to speed searching.  The first level is
1619a489f45SDavid Vrabel  * a bitset of words which contain pending event bits.  The second
1629a489f45SDavid Vrabel  * level is a bitset of pending events themselves.
1639a489f45SDavid Vrabel  */
evtchn_2l_handle_events(unsigned cpu,struct evtchn_loop_ctrl * ctrl)164e99502f7SJuergen Gross static void evtchn_2l_handle_events(unsigned cpu, struct evtchn_loop_ctrl *ctrl)
1659a489f45SDavid Vrabel {
1669a489f45SDavid Vrabel 	int irq;
1679a489f45SDavid Vrabel 	xen_ulong_t pending_words;
1689a489f45SDavid Vrabel 	xen_ulong_t pending_bits;
1699a489f45SDavid Vrabel 	int start_word_idx, start_bit_idx;
1709a489f45SDavid Vrabel 	int word_idx, bit_idx;
1719a489f45SDavid Vrabel 	int i;
1729a489f45SDavid Vrabel 	struct shared_info *s = HYPERVISOR_shared_info;
1739a489f45SDavid Vrabel 	struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
174*b79345efSJuergen Gross 	evtchn_port_t evtchn;
1759a489f45SDavid Vrabel 
1769a489f45SDavid Vrabel 	/* Timer interrupt has highest priority. */
177*b79345efSJuergen Gross 	irq = irq_evtchn_from_virq(cpu, VIRQ_TIMER, &evtchn);
1789a489f45SDavid Vrabel 	if (irq != -1) {
1799a489f45SDavid Vrabel 		word_idx = evtchn / BITS_PER_LONG;
1809a489f45SDavid Vrabel 		bit_idx = evtchn % BITS_PER_LONG;
181589d03e9SThomas Gleixner 		if (active_evtchns(cpu, s, word_idx) & (1ULL << bit_idx))
182589d03e9SThomas Gleixner 			generic_handle_irq(irq);
1839a489f45SDavid Vrabel 	}
1849a489f45SDavid Vrabel 
1859a489f45SDavid Vrabel 	/*
1869a489f45SDavid Vrabel 	 * Master flag must be cleared /before/ clearing
1879a489f45SDavid Vrabel 	 * selector flag. xchg_xen_ulong must contain an
1889a489f45SDavid Vrabel 	 * appropriate barrier.
1899a489f45SDavid Vrabel 	 */
1909a489f45SDavid Vrabel 	pending_words = xchg_xen_ulong(&vcpu_info->evtchn_pending_sel, 0);
1919a489f45SDavid Vrabel 
1929a489f45SDavid Vrabel 	start_word_idx = __this_cpu_read(current_word_idx);
1939a489f45SDavid Vrabel 	start_bit_idx = __this_cpu_read(current_bit_idx);
1949a489f45SDavid Vrabel 
1959a489f45SDavid Vrabel 	word_idx = start_word_idx;
1969a489f45SDavid Vrabel 
1979a489f45SDavid Vrabel 	for (i = 0; pending_words != 0; i++) {
1989a489f45SDavid Vrabel 		xen_ulong_t words;
1999a489f45SDavid Vrabel 
2009a489f45SDavid Vrabel 		words = MASK_LSBS(pending_words, word_idx);
2019a489f45SDavid Vrabel 
2029a489f45SDavid Vrabel 		/*
2039a489f45SDavid Vrabel 		 * If we masked out all events, wrap to beginning.
2049a489f45SDavid Vrabel 		 */
2059a489f45SDavid Vrabel 		if (words == 0) {
2069a489f45SDavid Vrabel 			word_idx = 0;
2079a489f45SDavid Vrabel 			bit_idx = 0;
2089a489f45SDavid Vrabel 			continue;
2099a489f45SDavid Vrabel 		}
2109a489f45SDavid Vrabel 		word_idx = EVTCHN_FIRST_BIT(words);
2119a489f45SDavid Vrabel 
2129a489f45SDavid Vrabel 		pending_bits = active_evtchns(cpu, s, word_idx);
2139a489f45SDavid Vrabel 		bit_idx = 0; /* usually scan entire word from start */
2149a489f45SDavid Vrabel 		/*
2159a489f45SDavid Vrabel 		 * We scan the starting word in two parts.
2169a489f45SDavid Vrabel 		 *
2179a489f45SDavid Vrabel 		 * 1st time: start in the middle, scanning the
2189a489f45SDavid Vrabel 		 * upper bits.
2199a489f45SDavid Vrabel 		 *
2209a489f45SDavid Vrabel 		 * 2nd time: scan the whole word (not just the
2219a489f45SDavid Vrabel 		 * parts skipped in the first pass) -- if an
2229a489f45SDavid Vrabel 		 * event in the previously scanned bits is
2239a489f45SDavid Vrabel 		 * pending again it would just be scanned on
2249a489f45SDavid Vrabel 		 * the next loop anyway.
2259a489f45SDavid Vrabel 		 */
2269a489f45SDavid Vrabel 		if (word_idx == start_word_idx) {
2279a489f45SDavid Vrabel 			if (i == 0)
2289a489f45SDavid Vrabel 				bit_idx = start_bit_idx;
2299a489f45SDavid Vrabel 		}
2309a489f45SDavid Vrabel 
2319a489f45SDavid Vrabel 		do {
2329a489f45SDavid Vrabel 			xen_ulong_t bits;
2330102e4efSYan Yankovskyi 			evtchn_port_t port;
2349a489f45SDavid Vrabel 
2359a489f45SDavid Vrabel 			bits = MASK_LSBS(pending_bits, bit_idx);
2369a489f45SDavid Vrabel 
2379a489f45SDavid Vrabel 			/* If we masked out all events, move on. */
2389a489f45SDavid Vrabel 			if (bits == 0)
2399a489f45SDavid Vrabel 				break;
2409a489f45SDavid Vrabel 
2419a489f45SDavid Vrabel 			bit_idx = EVTCHN_FIRST_BIT(bits);
2429a489f45SDavid Vrabel 
2439a489f45SDavid Vrabel 			/* Process port. */
2449a489f45SDavid Vrabel 			port = (word_idx * BITS_PER_EVTCHN_WORD) + bit_idx;
245e99502f7SJuergen Gross 			handle_irq_for_port(port, ctrl);
2469a489f45SDavid Vrabel 
2479a489f45SDavid Vrabel 			bit_idx = (bit_idx + 1) % BITS_PER_EVTCHN_WORD;
2489a489f45SDavid Vrabel 
2499a489f45SDavid Vrabel 			/* Next caller starts at last processed + 1 */
2509a489f45SDavid Vrabel 			__this_cpu_write(current_word_idx,
2519a489f45SDavid Vrabel 					 bit_idx ? word_idx :
2529a489f45SDavid Vrabel 					 (word_idx+1) % BITS_PER_EVTCHN_WORD);
2539a489f45SDavid Vrabel 			__this_cpu_write(current_bit_idx, bit_idx);
2549a489f45SDavid Vrabel 		} while (bit_idx != 0);
2559a489f45SDavid Vrabel 
2569a489f45SDavid Vrabel 		/* Scan start_l1i twice; all others once. */
2579a489f45SDavid Vrabel 		if ((word_idx != start_word_idx) || (i != 0))
2589a489f45SDavid Vrabel 			pending_words &= ~(1UL << word_idx);
2599a489f45SDavid Vrabel 
2609a489f45SDavid Vrabel 		word_idx = (word_idx + 1) % BITS_PER_EVTCHN_WORD;
2619a489f45SDavid Vrabel 	}
2629a489f45SDavid Vrabel }
2639a489f45SDavid Vrabel 
xen_debug_interrupt(int irq,void * dev_id)2649a489f45SDavid Vrabel irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
2659a489f45SDavid Vrabel {
2669a489f45SDavid Vrabel 	struct shared_info *sh = HYPERVISOR_shared_info;
2679a489f45SDavid Vrabel 	int cpu = smp_processor_id();
2689a489f45SDavid Vrabel 	xen_ulong_t *cpu_evtchn = per_cpu(cpu_evtchn_mask, cpu);
2699a489f45SDavid Vrabel 	int i;
2709a489f45SDavid Vrabel 	unsigned long flags;
2719a489f45SDavid Vrabel 	static DEFINE_SPINLOCK(debug_lock);
2729a489f45SDavid Vrabel 	struct vcpu_info *v;
2739a489f45SDavid Vrabel 
2749a489f45SDavid Vrabel 	spin_lock_irqsave(&debug_lock, flags);
2759a489f45SDavid Vrabel 
2769a489f45SDavid Vrabel 	printk("\nvcpu %d\n  ", cpu);
2779a489f45SDavid Vrabel 
2789a489f45SDavid Vrabel 	for_each_online_cpu(i) {
2799a489f45SDavid Vrabel 		int pending;
2809a489f45SDavid Vrabel 		v = per_cpu(xen_vcpu, i);
2819a489f45SDavid Vrabel 		pending = (get_irq_regs() && i == cpu)
2829a489f45SDavid Vrabel 			? xen_irqs_disabled(get_irq_regs())
2839a489f45SDavid Vrabel 			: v->evtchn_upcall_mask;
2849a489f45SDavid Vrabel 		printk("%d: masked=%d pending=%d event_sel %0*"PRI_xen_ulong"\n  ", i,
2859a489f45SDavid Vrabel 		       pending, v->evtchn_upcall_pending,
2869a489f45SDavid Vrabel 		       (int)(sizeof(v->evtchn_pending_sel)*2),
2879a489f45SDavid Vrabel 		       v->evtchn_pending_sel);
2889a489f45SDavid Vrabel 	}
2899a489f45SDavid Vrabel 	v = per_cpu(xen_vcpu, cpu);
2909a489f45SDavid Vrabel 
2919a489f45SDavid Vrabel 	printk("\npending:\n   ");
2929a489f45SDavid Vrabel 	for (i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
2939a489f45SDavid Vrabel 		printk("%0*"PRI_xen_ulong"%s",
2949a489f45SDavid Vrabel 		       (int)sizeof(sh->evtchn_pending[0])*2,
2959a489f45SDavid Vrabel 		       sh->evtchn_pending[i],
2969a489f45SDavid Vrabel 		       i % 8 == 0 ? "\n   " : " ");
2979a489f45SDavid Vrabel 	printk("\nglobal mask:\n   ");
2989a489f45SDavid Vrabel 	for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
2999a489f45SDavid Vrabel 		printk("%0*"PRI_xen_ulong"%s",
3009a489f45SDavid Vrabel 		       (int)(sizeof(sh->evtchn_mask[0])*2),
3019a489f45SDavid Vrabel 		       sh->evtchn_mask[i],
3029a489f45SDavid Vrabel 		       i % 8 == 0 ? "\n   " : " ");
3039a489f45SDavid Vrabel 
3049a489f45SDavid Vrabel 	printk("\nglobally unmasked:\n   ");
3059a489f45SDavid Vrabel 	for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
3069a489f45SDavid Vrabel 		printk("%0*"PRI_xen_ulong"%s",
3079a489f45SDavid Vrabel 		       (int)(sizeof(sh->evtchn_mask[0])*2),
3089a489f45SDavid Vrabel 		       sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
3099a489f45SDavid Vrabel 		       i % 8 == 0 ? "\n   " : " ");
3109a489f45SDavid Vrabel 
3119a489f45SDavid Vrabel 	printk("\nlocal cpu%d mask:\n   ", cpu);
312bf2bbe07SDavid Vrabel 	for (i = (EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD)-1; i >= 0; i--)
3139a489f45SDavid Vrabel 		printk("%0*"PRI_xen_ulong"%s", (int)(sizeof(cpu_evtchn[0])*2),
3149a489f45SDavid Vrabel 		       cpu_evtchn[i],
3159a489f45SDavid Vrabel 		       i % 8 == 0 ? "\n   " : " ");
3169a489f45SDavid Vrabel 
3179a489f45SDavid Vrabel 	printk("\nlocally unmasked:\n   ");
3189a489f45SDavid Vrabel 	for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) {
3199a489f45SDavid Vrabel 		xen_ulong_t pending = sh->evtchn_pending[i]
3209a489f45SDavid Vrabel 			& ~sh->evtchn_mask[i]
3219a489f45SDavid Vrabel 			& cpu_evtchn[i];
3229a489f45SDavid Vrabel 		printk("%0*"PRI_xen_ulong"%s",
3239a489f45SDavid Vrabel 		       (int)(sizeof(sh->evtchn_mask[0])*2),
3249a489f45SDavid Vrabel 		       pending, i % 8 == 0 ? "\n   " : " ");
3259a489f45SDavid Vrabel 	}
3269a489f45SDavid Vrabel 
3279a489f45SDavid Vrabel 	printk("\npending list:\n");
328bf2bbe07SDavid Vrabel 	for (i = 0; i < EVTCHN_2L_NR_CHANNELS; i++) {
3299a489f45SDavid Vrabel 		if (sync_test_bit(i, BM(sh->evtchn_pending))) {
3309a489f45SDavid Vrabel 			int word_idx = i / BITS_PER_EVTCHN_WORD;
331*b79345efSJuergen Gross 			printk("  %d: event %d -> irq %u%s%s%s\n",
3329a489f45SDavid Vrabel 			       cpu_from_evtchn(i), i,
333*b79345efSJuergen Gross 			       irq_from_evtchn(i),
3349a489f45SDavid Vrabel 			       sync_test_bit(word_idx, BM(&v->evtchn_pending_sel))
3359a489f45SDavid Vrabel 			       ? "" : " l2-clear",
3369a489f45SDavid Vrabel 			       !sync_test_bit(i, BM(sh->evtchn_mask))
3379a489f45SDavid Vrabel 			       ? "" : " globally-masked",
3389a489f45SDavid Vrabel 			       sync_test_bit(i, BM(cpu_evtchn))
3399a489f45SDavid Vrabel 			       ? "" : " locally-masked");
3409a489f45SDavid Vrabel 		}
3419a489f45SDavid Vrabel 	}
3429a489f45SDavid Vrabel 
3439a489f45SDavid Vrabel 	spin_unlock_irqrestore(&debug_lock, flags);
3449a489f45SDavid Vrabel 
3459a489f45SDavid Vrabel 	return IRQ_HANDLED;
3469a489f45SDavid Vrabel }
347ab9a1ccaSDavid Vrabel 
evtchn_2l_resume(void)3485cec9883SBoris Ostrovsky static void evtchn_2l_resume(void)
3495cec9883SBoris Ostrovsky {
3505cec9883SBoris Ostrovsky 	int i;
3515cec9883SBoris Ostrovsky 
3525cec9883SBoris Ostrovsky 	for_each_online_cpu(i)
3535cec9883SBoris Ostrovsky 		memset(per_cpu(cpu_evtchn_mask, i), 0, sizeof(xen_ulong_t) *
3545cec9883SBoris Ostrovsky 				EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD);
3555cec9883SBoris Ostrovsky }
3565cec9883SBoris Ostrovsky 
evtchn_2l_percpu_deinit(unsigned int cpu)3579e77d96bSJuergen Gross static int evtchn_2l_percpu_deinit(unsigned int cpu)
3589e77d96bSJuergen Gross {
3599e77d96bSJuergen Gross 	memset(per_cpu(cpu_evtchn_mask, cpu), 0, sizeof(xen_ulong_t) *
3609e77d96bSJuergen Gross 			EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD);
3619e77d96bSJuergen Gross 
3629e77d96bSJuergen Gross 	return 0;
3639e77d96bSJuergen Gross }
3649e77d96bSJuergen Gross 
365ab9a1ccaSDavid Vrabel static const struct evtchn_ops evtchn_ops_2l = {
366d0b075ffSDavid Vrabel 	.max_channels      = evtchn_2l_max_channels,
367d0b075ffSDavid Vrabel 	.nr_channels       = evtchn_2l_max_channels,
3689e77d96bSJuergen Gross 	.remove            = evtchn_2l_remove,
369ab9a1ccaSDavid Vrabel 	.bind_to_cpu       = evtchn_2l_bind_to_cpu,
370ab9a1ccaSDavid Vrabel 	.clear_pending     = evtchn_2l_clear_pending,
371ab9a1ccaSDavid Vrabel 	.set_pending       = evtchn_2l_set_pending,
372ab9a1ccaSDavid Vrabel 	.is_pending        = evtchn_2l_is_pending,
373ab9a1ccaSDavid Vrabel 	.mask              = evtchn_2l_mask,
374ab9a1ccaSDavid Vrabel 	.unmask            = evtchn_2l_unmask,
375ab9a1ccaSDavid Vrabel 	.handle_events     = evtchn_2l_handle_events,
3765cec9883SBoris Ostrovsky 	.resume	           = evtchn_2l_resume,
3779e77d96bSJuergen Gross 	.percpu_deinit     = evtchn_2l_percpu_deinit,
378ab9a1ccaSDavid Vrabel };
379ab9a1ccaSDavid Vrabel 
xen_evtchn_2l_init(void)380ab9a1ccaSDavid Vrabel void __init xen_evtchn_2l_init(void)
381ab9a1ccaSDavid Vrabel {
382ab9a1ccaSDavid Vrabel 	pr_info("Using 2-level ABI\n");
383ab9a1ccaSDavid Vrabel 	evtchn_ops = &evtchn_ops_2l;
384ab9a1ccaSDavid Vrabel }
385