xref: /onnv-gate/usr/src/uts/i86xpv/sys/evtchn_impl.h (revision 10175:dd9708d1f561)
15084Sjohnlev /*
25084Sjohnlev  * CDDL HEADER START
35084Sjohnlev  *
45084Sjohnlev  * The contents of this file are subject to the terms of the
55084Sjohnlev  * Common Development and Distribution License (the "License").
65084Sjohnlev  * You may not use this file except in compliance with the License.
75084Sjohnlev  *
85084Sjohnlev  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95084Sjohnlev  * or http://www.opensolaris.org/os/licensing.
105084Sjohnlev  * See the License for the specific language governing permissions
115084Sjohnlev  * and limitations under the License.
125084Sjohnlev  *
135084Sjohnlev  * When distributing Covered Code, include this CDDL HEADER in each
145084Sjohnlev  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155084Sjohnlev  * If applicable, add the following below this CDDL HEADER, with the
165084Sjohnlev  * fields enclosed by brackets "[]" replaced with your own identifying
175084Sjohnlev  * information: Portions Copyright [yyyy] [name of copyright owner]
185084Sjohnlev  *
195084Sjohnlev  * CDDL HEADER END
205084Sjohnlev  */
215084Sjohnlev 
225084Sjohnlev /*
23*10175SStuart.Maybee@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
245084Sjohnlev  * Use is subject to license terms.
255084Sjohnlev  */
265084Sjohnlev /*
275084Sjohnlev  * evtchn.h (renamed to evtchn_impl.h)
285084Sjohnlev  *
295084Sjohnlev  * Communication via Xen event channels.
305084Sjohnlev  * Also definitions for the device that demuxes notifications to userspace.
315084Sjohnlev  *
325084Sjohnlev  * Copyright (c) 2004-2005, K A Fraser
335084Sjohnlev  *
345084Sjohnlev  * This file may be distributed separately from the Linux kernel, or
355084Sjohnlev  * incorporated into other software packages, subject to the following license:
365084Sjohnlev  *
375084Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
385084Sjohnlev  * of this source file (the "Software"), to deal in the Software without
395084Sjohnlev  * restriction, including without limitation the rights to use, copy, modify,
405084Sjohnlev  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
415084Sjohnlev  * and to permit persons to whom the Software is furnished to do so, subject to
425084Sjohnlev  * the following conditions:
435084Sjohnlev  *
445084Sjohnlev  * The above copyright notice and this permission notice shall be included in
455084Sjohnlev  * all copies or substantial portions of the Software.
465084Sjohnlev  *
475084Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
485084Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
495084Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
505084Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
515084Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
525084Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
535084Sjohnlev  * IN THE SOFTWARE.
545084Sjohnlev  */
555084Sjohnlev 
565084Sjohnlev #ifndef _SYS_EVTCHN_H
575084Sjohnlev #define	_SYS_EVTCHN_H
585084Sjohnlev 
595084Sjohnlev #ifdef __cplusplus
605084Sjohnlev extern "C" {
615084Sjohnlev #endif
625084Sjohnlev 
635084Sjohnlev #include <sys/types.h>
645084Sjohnlev #include <sys/privregs.h>
655084Sjohnlev #include <sys/systm.h>
665084Sjohnlev #include <sys/traptrace.h>
675084Sjohnlev #include <sys/ddi_intr.h>
685084Sjohnlev #include <sys/ddi_intr_impl.h>
695084Sjohnlev #include <sys/avintr.h>
705084Sjohnlev #include <sys/cpuvar.h>
715084Sjohnlev #include <sys/hypervisor.h>
725084Sjohnlev 
735084Sjohnlev /* evtchn binding types */
745084Sjohnlev #define	IRQT_UNBOUND	0	/* unassigned irq */
755084Sjohnlev #define	IRQT_PIRQ	1	/* IRQ from phys hdw device */
765084Sjohnlev #define	IRQT_VIRQ	2	/* Virtual IRQ from Xen */
775084Sjohnlev #define	IRQT_IPI	3	/* Inter VCPU interrupt IRQ */
785084Sjohnlev #define	IRQT_EVTCHN	4	/* Virtual device IRQ */
795084Sjohnlev #define	IRQT_DEV_EVTCHN	5	/* Special evtchn device IRQ */
805084Sjohnlev 
815084Sjohnlev #define	SET_EVTCHN_BIT(bit, arrayp) \
825084Sjohnlev 	((arrayp)[bit >> EVTCHN_SHIFT] |= \
835084Sjohnlev 	(1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1))))
845084Sjohnlev #define	CLEAR_EVTCHN_BIT(bit, arrayp) \
855084Sjohnlev 	((arrayp)[bit >> EVTCHN_SHIFT] &= \
865084Sjohnlev 		~((1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1)))))
875084Sjohnlev #define	TEST_EVTCHN_BIT(bit, arrayp) \
885084Sjohnlev 	((arrayp)[bit >> EVTCHN_SHIFT] & \
895084Sjohnlev 		(1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1))))
905084Sjohnlev 
915084Sjohnlev /* Xen will never allocate port zero for any purpose. */
925084Sjohnlev #define	INVALID_EVTCHN	0
935084Sjohnlev 
945084Sjohnlev /* XXPV - should these defines be somewhere else? xenos.h perhaps? */
955084Sjohnlev 
965084Sjohnlev #define	IPL_DEBUG	15	/* domain debug interrupt */
975084Sjohnlev #define	IPL_CONS	9
985084Sjohnlev #define	IPL_VIF		6
995084Sjohnlev #define	IPL_VBD		5
1005084Sjohnlev #define	IPL_EVTCHN	1
1015084Sjohnlev 
1025084Sjohnlev #define	PIRQ_BASE	0	/* base of pirq range */
1035084Sjohnlev #define	NR_PIRQS	256	/* Number of supported physical irqs */
1045084Sjohnlev #define	DYNIRQ_BASE	(PIRQ_BASE + NR_PIRQS) /* base of dynamic irq range */
1055084Sjohnlev #define	NR_DYNIRQS	256	/* Number of dynamic irqs */
1065084Sjohnlev #define	NR_IRQS		(NR_PIRQS + NR_DYNIRQS) /* total irq count */
1075084Sjohnlev 
1085084Sjohnlev #define	PIRQ_TO_IRQ(pirq)	((pirq) + PIRQ_BASE)
1095084Sjohnlev #define	IRQ_TO_PIRQ(irq)	((irq) - PIRQ_BASE)
1105084Sjohnlev 
1115084Sjohnlev #define	DYNIRQ_TO_IRQ(dirq)	((dirq) + DYNIRQ_BASE)
1125084Sjohnlev #define	IRQ_TO_DYNIRQ(irq)	((irq) - DYNIRQ_BASE)
1135084Sjohnlev 
1145084Sjohnlev #if defined(_LP64)
1155084Sjohnlev #define	EVTCHN_SHIFT	6	/* log2(NBBY * sizeof (ulong_t)) */
1165084Sjohnlev #else
1175084Sjohnlev #define	EVTCHN_SHIFT	5	/* log2(NBBY * sizeof (ulong_t)) */
1185084Sjohnlev #endif
1195084Sjohnlev 
1205084Sjohnlev #define	INVALID_IRQ -1
1215084Sjohnlev 
1225084Sjohnlev extern int ec_dev_irq;
1235084Sjohnlev extern kmutex_t ec_lock;
1245084Sjohnlev 
1255084Sjohnlev typedef struct mec_info {
1265084Sjohnlev 	ushort_t mi_evtchns[NCPU];	/* event channels for this IRQ */
1275084Sjohnlev 	short mi_irq;			/* the IRQ, or INVALID_IRQ */
1285084Sjohnlev 	char mi_shared;			/* one evtchn for all CPUs? */
1295084Sjohnlev } mec_info_t;
1305084Sjohnlev 
1315084Sjohnlev /*
1325084Sjohnlev  * Careful: ii_ipl is /only/ set if there's a handler for this IRQ.
1335084Sjohnlev  */
1345084Sjohnlev typedef struct irq_info {
1355084Sjohnlev 	union {
1365084Sjohnlev 		ushort_t evtchn;	/* event channel */
1375084Sjohnlev 		ushort_t index;		/* index to next table if mec */
1385084Sjohnlev 	} ii_u;
1395084Sjohnlev 	uchar_t ii_type;		/* IRQ type as above */
1405084Sjohnlev 	union {
1415084Sjohnlev 		uchar_t ipl;		/* IPL of IRQ, != 0 => has handler */
1425084Sjohnlev 		uchar_t	has_handler;	/* alternate name for ipl */
1435084Sjohnlev 	} ii_u2;
1445084Sjohnlev } irq_info_t;
1455084Sjohnlev 
146*10175SStuart.Maybee@Sun.COM extern int ec_is_edge_pirq(int);
147*10175SStuart.Maybee@Sun.COM extern int ec_init(void);
1485084Sjohnlev extern void ec_init_debug_irq(void);
1495084Sjohnlev extern void ec_suspend(void);
1505084Sjohnlev extern void ec_resume(void);
1515084Sjohnlev extern void ec_wait_on_evtchn(int, int (*)(void *), void *);
1525084Sjohnlev extern void ec_wait_on_ipi(int, int (*)(void *), void *);
1535084Sjohnlev 
1545529Ssmaybe extern void ec_setup_pirq(int, int, cpuset_t *);
1555084Sjohnlev extern void ec_set_irq_affinity(int, cpuset_t);
1565084Sjohnlev extern int ec_set_irq_priority(int, int);
1575084Sjohnlev 
1585084Sjohnlev extern int ec_bind_ipi_to_irq(int, int);
1595084Sjohnlev extern void ec_bind_cpu_ipis(int);
1605084Sjohnlev extern int ec_bind_evtchn_to_irq(int);
1615084Sjohnlev extern int ec_bind_virq_to_irq(int, int);
1625084Sjohnlev extern void ec_unbind_irq(int irq);
1635084Sjohnlev 
1645084Sjohnlev extern void ec_send_ipi(int, int);
1655084Sjohnlev extern void ec_try_ipi(int, int);
1665084Sjohnlev extern void ec_clear_irq(int);
1675084Sjohnlev extern void ec_unmask_irq(int);
1685084Sjohnlev extern void ec_try_unmask_irq(int);
1695084Sjohnlev extern int ec_block_irq(int);
1705084Sjohnlev extern void ec_unpend_irq(int);
1715084Sjohnlev extern int ec_irq_needs_rebind(int, int);
1725084Sjohnlev extern int ec_irq_rebindable(int);
1735084Sjohnlev extern int ec_pending_irq(unsigned int);
1745084Sjohnlev extern void ec_enable_irq(unsigned int);
1755084Sjohnlev extern void ec_disable_irq(unsigned int);
1765084Sjohnlev 
1775084Sjohnlev extern int xen_bind_interdomain(int, int, int *);
1785084Sjohnlev extern int xen_bind_virq(unsigned int, processorid_t, int *);
1795084Sjohnlev extern int xen_alloc_unbound_evtchn(int, int *);
1805084Sjohnlev extern void ec_bind_vcpu(int, int);
1815084Sjohnlev 
1825084Sjohnlev extern int ec_mask_evtchn(unsigned int);
1835084Sjohnlev extern void ec_unmask_evtchn(unsigned int);
1845084Sjohnlev extern void ec_clear_evtchn(unsigned int);
1855084Sjohnlev 
1865084Sjohnlev extern void ec_notify_via_evtchn(unsigned int);
1875084Sjohnlev 
1885084Sjohnlev /*
1895084Sjohnlev  * /dev/xen/evtchn handling.
1905084Sjohnlev  */
1915084Sjohnlev extern void ec_irq_add_evtchn(int, int);
1925084Sjohnlev extern void ec_irq_rm_evtchn(int, int);
1935084Sjohnlev extern int ec_dev_alloc_irq(void);
1945084Sjohnlev 
1955084Sjohnlev #ifdef __cplusplus
1965084Sjohnlev }
1975084Sjohnlev #endif
1985084Sjohnlev 
1995084Sjohnlev #endif /* _SYS_EVTCHN_H */
200