1843e1988Sjohnlev /* 2843e1988Sjohnlev * CDDL HEADER START 3843e1988Sjohnlev * 4843e1988Sjohnlev * The contents of this file are subject to the terms of the 5843e1988Sjohnlev * Common Development and Distribution License (the "License"). 6843e1988Sjohnlev * You may not use this file except in compliance with the License. 7843e1988Sjohnlev * 8843e1988Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9843e1988Sjohnlev * or http://www.opensolaris.org/os/licensing. 10843e1988Sjohnlev * See the License for the specific language governing permissions 11843e1988Sjohnlev * and limitations under the License. 12843e1988Sjohnlev * 13843e1988Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 14843e1988Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15843e1988Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 16843e1988Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 17843e1988Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 18843e1988Sjohnlev * 19843e1988Sjohnlev * CDDL HEADER END 20843e1988Sjohnlev */ 21843e1988Sjohnlev 22843e1988Sjohnlev /* 23*349b53ddSStuart Maybee * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24843e1988Sjohnlev * Use is subject to license terms. 25843e1988Sjohnlev */ 26843e1988Sjohnlev /* 27843e1988Sjohnlev * evtchn.h (renamed to evtchn_impl.h) 28843e1988Sjohnlev * 29843e1988Sjohnlev * Communication via Xen event channels. 30843e1988Sjohnlev * Also definitions for the device that demuxes notifications to userspace. 31843e1988Sjohnlev * 32843e1988Sjohnlev * Copyright (c) 2004-2005, K A Fraser 33843e1988Sjohnlev * 34843e1988Sjohnlev * This file may be distributed separately from the Linux kernel, or 35843e1988Sjohnlev * incorporated into other software packages, subject to the following license: 36843e1988Sjohnlev * 37843e1988Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 38843e1988Sjohnlev * of this source file (the "Software"), to deal in the Software without 39843e1988Sjohnlev * restriction, including without limitation the rights to use, copy, modify, 40843e1988Sjohnlev * merge, publish, distribute, sublicense, and/or sell copies of the Software, 41843e1988Sjohnlev * and to permit persons to whom the Software is furnished to do so, subject to 42843e1988Sjohnlev * the following conditions: 43843e1988Sjohnlev * 44843e1988Sjohnlev * The above copyright notice and this permission notice shall be included in 45843e1988Sjohnlev * all copies or substantial portions of the Software. 46843e1988Sjohnlev * 47843e1988Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48843e1988Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49843e1988Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50843e1988Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51843e1988Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 52843e1988Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 53843e1988Sjohnlev * IN THE SOFTWARE. 54843e1988Sjohnlev */ 55843e1988Sjohnlev 56843e1988Sjohnlev #ifndef _SYS_EVTCHN_H 57843e1988Sjohnlev #define _SYS_EVTCHN_H 58843e1988Sjohnlev 59843e1988Sjohnlev #ifdef __cplusplus 60843e1988Sjohnlev extern "C" { 61843e1988Sjohnlev #endif 62843e1988Sjohnlev 63843e1988Sjohnlev #include <sys/types.h> 64843e1988Sjohnlev #include <sys/privregs.h> 65843e1988Sjohnlev #include <sys/systm.h> 66843e1988Sjohnlev #include <sys/traptrace.h> 67843e1988Sjohnlev #include <sys/ddi_intr.h> 68843e1988Sjohnlev #include <sys/ddi_intr_impl.h> 69843e1988Sjohnlev #include <sys/avintr.h> 70843e1988Sjohnlev #include <sys/cpuvar.h> 71843e1988Sjohnlev #include <sys/hypervisor.h> 72843e1988Sjohnlev 73843e1988Sjohnlev /* evtchn binding types */ 74843e1988Sjohnlev #define IRQT_UNBOUND 0 /* unassigned irq */ 75843e1988Sjohnlev #define IRQT_PIRQ 1 /* IRQ from phys hdw device */ 76843e1988Sjohnlev #define IRQT_VIRQ 2 /* Virtual IRQ from Xen */ 77843e1988Sjohnlev #define IRQT_IPI 3 /* Inter VCPU interrupt IRQ */ 78843e1988Sjohnlev #define IRQT_EVTCHN 4 /* Virtual device IRQ */ 79843e1988Sjohnlev #define IRQT_DEV_EVTCHN 5 /* Special evtchn device IRQ */ 80843e1988Sjohnlev 81843e1988Sjohnlev #define SET_EVTCHN_BIT(bit, arrayp) \ 82843e1988Sjohnlev ((arrayp)[bit >> EVTCHN_SHIFT] |= \ 83843e1988Sjohnlev (1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1)))) 84843e1988Sjohnlev #define CLEAR_EVTCHN_BIT(bit, arrayp) \ 85843e1988Sjohnlev ((arrayp)[bit >> EVTCHN_SHIFT] &= \ 86843e1988Sjohnlev ~((1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1))))) 87843e1988Sjohnlev #define TEST_EVTCHN_BIT(bit, arrayp) \ 88843e1988Sjohnlev ((arrayp)[bit >> EVTCHN_SHIFT] & \ 89843e1988Sjohnlev (1ul << ((bit) & ((1ul << EVTCHN_SHIFT) - 1)))) 90843e1988Sjohnlev 91843e1988Sjohnlev /* Xen will never allocate port zero for any purpose. */ 92843e1988Sjohnlev #define INVALID_EVTCHN 0 93843e1988Sjohnlev 94843e1988Sjohnlev /* XXPV - should these defines be somewhere else? xenos.h perhaps? */ 95843e1988Sjohnlev 96843e1988Sjohnlev #define IPL_DEBUG 15 /* domain debug interrupt */ 97843e1988Sjohnlev #define IPL_CONS 9 98843e1988Sjohnlev #define IPL_VIF 6 99843e1988Sjohnlev #define IPL_VBD 5 100843e1988Sjohnlev #define IPL_EVTCHN 1 101843e1988Sjohnlev 102843e1988Sjohnlev #define PIRQ_BASE 0 /* base of pirq range */ 103843e1988Sjohnlev #define NR_PIRQS 256 /* Number of supported physical irqs */ 104843e1988Sjohnlev #define DYNIRQ_BASE (PIRQ_BASE + NR_PIRQS) /* base of dynamic irq range */ 105843e1988Sjohnlev #define NR_DYNIRQS 256 /* Number of dynamic irqs */ 106843e1988Sjohnlev #define NR_IRQS (NR_PIRQS + NR_DYNIRQS) /* total irq count */ 107843e1988Sjohnlev 108843e1988Sjohnlev #define PIRQ_TO_IRQ(pirq) ((pirq) + PIRQ_BASE) 109843e1988Sjohnlev #define IRQ_TO_PIRQ(irq) ((irq) - PIRQ_BASE) 110843e1988Sjohnlev 111843e1988Sjohnlev #define DYNIRQ_TO_IRQ(dirq) ((dirq) + DYNIRQ_BASE) 112843e1988Sjohnlev #define IRQ_TO_DYNIRQ(irq) ((irq) - DYNIRQ_BASE) 113843e1988Sjohnlev 114843e1988Sjohnlev #if defined(_LP64) 115843e1988Sjohnlev #define EVTCHN_SHIFT 6 /* log2(NBBY * sizeof (ulong_t)) */ 116843e1988Sjohnlev #else 117843e1988Sjohnlev #define EVTCHN_SHIFT 5 /* log2(NBBY * sizeof (ulong_t)) */ 118843e1988Sjohnlev #endif 119843e1988Sjohnlev 120843e1988Sjohnlev #define INVALID_IRQ -1 121843e1988Sjohnlev 122843e1988Sjohnlev extern int ec_dev_irq; 123843e1988Sjohnlev extern kmutex_t ec_lock; 124843e1988Sjohnlev 125843e1988Sjohnlev typedef struct mec_info { 126843e1988Sjohnlev ushort_t mi_evtchns[NCPU]; /* event channels for this IRQ */ 127843e1988Sjohnlev short mi_irq; /* the IRQ, or INVALID_IRQ */ 128843e1988Sjohnlev char mi_shared; /* one evtchn for all CPUs? */ 129843e1988Sjohnlev } mec_info_t; 130843e1988Sjohnlev 131843e1988Sjohnlev /* 132843e1988Sjohnlev * Careful: ii_ipl is /only/ set if there's a handler for this IRQ. 133843e1988Sjohnlev */ 134843e1988Sjohnlev typedef struct irq_info { 135843e1988Sjohnlev union { 136843e1988Sjohnlev ushort_t evtchn; /* event channel */ 137843e1988Sjohnlev ushort_t index; /* index to next table if mec */ 138843e1988Sjohnlev } ii_u; 139843e1988Sjohnlev uchar_t ii_type; /* IRQ type as above */ 140843e1988Sjohnlev union { 141843e1988Sjohnlev uchar_t ipl; /* IPL of IRQ, != 0 => has handler */ 142843e1988Sjohnlev uchar_t has_handler; /* alternate name for ipl */ 143843e1988Sjohnlev } ii_u2; 144843e1988Sjohnlev } irq_info_t; 145843e1988Sjohnlev 146*349b53ddSStuart Maybee extern int ec_is_edge_pirq(int); 147*349b53ddSStuart Maybee extern int ec_init(void); 148843e1988Sjohnlev extern void ec_init_debug_irq(void); 149843e1988Sjohnlev extern void ec_suspend(void); 150843e1988Sjohnlev extern void ec_resume(void); 151843e1988Sjohnlev extern void ec_wait_on_evtchn(int, int (*)(void *), void *); 152843e1988Sjohnlev extern void ec_wait_on_ipi(int, int (*)(void *), void *); 153843e1988Sjohnlev 154b9bc7f78Ssmaybe extern void ec_setup_pirq(int, int, cpuset_t *); 155843e1988Sjohnlev extern void ec_set_irq_affinity(int, cpuset_t); 156843e1988Sjohnlev extern int ec_set_irq_priority(int, int); 157843e1988Sjohnlev 158843e1988Sjohnlev extern int ec_bind_ipi_to_irq(int, int); 159843e1988Sjohnlev extern void ec_bind_cpu_ipis(int); 160843e1988Sjohnlev extern int ec_bind_evtchn_to_irq(int); 161843e1988Sjohnlev extern int ec_bind_virq_to_irq(int, int); 162843e1988Sjohnlev extern void ec_unbind_irq(int irq); 163843e1988Sjohnlev 164843e1988Sjohnlev extern void ec_send_ipi(int, int); 165843e1988Sjohnlev extern void ec_try_ipi(int, int); 166843e1988Sjohnlev extern void ec_clear_irq(int); 167843e1988Sjohnlev extern void ec_unmask_irq(int); 168843e1988Sjohnlev extern void ec_try_unmask_irq(int); 169843e1988Sjohnlev extern int ec_block_irq(int); 170843e1988Sjohnlev extern void ec_unpend_irq(int); 171843e1988Sjohnlev extern int ec_irq_needs_rebind(int, int); 172843e1988Sjohnlev extern int ec_irq_rebindable(int); 173843e1988Sjohnlev extern int ec_pending_irq(unsigned int); 174843e1988Sjohnlev extern void ec_enable_irq(unsigned int); 175843e1988Sjohnlev extern void ec_disable_irq(unsigned int); 176843e1988Sjohnlev 177843e1988Sjohnlev extern int xen_bind_interdomain(int, int, int *); 178843e1988Sjohnlev extern int xen_bind_virq(unsigned int, processorid_t, int *); 179843e1988Sjohnlev extern int xen_alloc_unbound_evtchn(int, int *); 180843e1988Sjohnlev extern void ec_bind_vcpu(int, int); 181843e1988Sjohnlev 182843e1988Sjohnlev extern int ec_mask_evtchn(unsigned int); 183843e1988Sjohnlev extern void ec_unmask_evtchn(unsigned int); 184843e1988Sjohnlev extern void ec_clear_evtchn(unsigned int); 185843e1988Sjohnlev 186843e1988Sjohnlev extern void ec_notify_via_evtchn(unsigned int); 187843e1988Sjohnlev 188843e1988Sjohnlev /* 189843e1988Sjohnlev * /dev/xen/evtchn handling. 190843e1988Sjohnlev */ 191843e1988Sjohnlev extern void ec_irq_add_evtchn(int, int); 192843e1988Sjohnlev extern void ec_irq_rm_evtchn(int, int); 193843e1988Sjohnlev extern int ec_dev_alloc_irq(void); 194843e1988Sjohnlev 195843e1988Sjohnlev #ifdef __cplusplus 196843e1988Sjohnlev } 197843e1988Sjohnlev #endif 198843e1988Sjohnlev 199843e1988Sjohnlev #endif /* _SYS_EVTCHN_H */ 200