/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum, and by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
if (ih->ih_pic->pic_type == PIC_XEN) {
event_remove_handler(ih->ih_pin, ih->ih_realfun,
ih->ih_realarg);
/* event_remove_handler frees ih */
return;
}
#if defined(DOM0OPS) && defined(XENPV)
/*
* Cache state, to prevent a use after free situation with
* ih.
*/
struct pintrhand *pih = (struct pintrhand *)ih;
int pirq = pih->pirq;
int port = pih->evtch;
KASSERT(irq2port[pirq] != 0);
pirq_disestablish(pih);
if (evtsource[port] == NULL) {
/*
* Last handler was removed by
* event_remove_handler().
*
* We can safely unbind the pirq now.
*/
/*
* If the red zone is activated, protect both the top and
* the bottom of the stack with an unmapped page.
*/
istack = uvm_km_alloc(kernel_map,
INTRSTACKSIZE + redzone_const_or_zero(2 * PAGE_SIZE), 0,
UVM_KMF_WIRED|UVM_KMF_ZERO);
if (redzone_const_or_false(true)) {
pmap_kremove(istack, PAGE_SIZE);
pmap_kremove(istack + INTRSTACKSIZE + PAGE_SIZE, PAGE_SIZE);
pmap_update(pmap_kernel());
}
/*
* 33 used to be 1. Arbitrarily reserve 32 more register_t's
* of space for ddb(4) to examine some subroutine arguments
* and to hunt for the next stack frame.
*/
ci->ci_intrstack = (char *)istack + redzone_const_or_zero(PAGE_SIZE) +
INTRSTACKSIZE - 33 * sizeof(register_t);
#endif
#ifdef MULTIPROCESSOR
for (int i = 0; i < XEN_NIPIS; i++)
evcnt_attach_dynamic(&ci->ci_ipi_events[i], EVCNT_TYPE_MISC,
NULL, device_xname(ci->ci_dev), xen_ipi_names[i]);
#endif
ci->ci_idepth = -1;
}
/*
* Everything below from here is duplicated from x86/intr.c
* When intr.c and xen_intr.c are unified, these will need to be
* merged.
*/
/*
* Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
* by MI code and intrctl(8).
*/
const char * xen_intr_create_intrid(int legacy_irq, struct pic *pic,
int pin, char *buf, size_t len);
const char *
xen_intr_create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len)
{
int ih = 0;
if (pic->pic_type == PIC_XEN) {
ih = pin; /* Port == pin */
return xen_intr_string(pin, buf, len, pic);
}
/*
* If the device is pci, "legacy_irq" is always -1. Least 8 bit of "ih"
* is only used in intr_string() to show the irq number.
* If the device is "legacy"(such as floppy), it should not use
* intr_string().
*/
if (pic->pic_type == PIC_I8259) {
ih = legacy_irq;
return legacy_intr_string(ih, buf, len, pic);
}
#if NIOAPIC > 0 || NACPICA > 0
ih = ((pic->pic_apicid << APIC_INT_APIC_SHIFT) & APIC_INT_APIC_MASK)
| ((pin << APIC_INT_PIN_SHIFT) & APIC_INT_PIN_MASK);
if (pic->pic_type == PIC_IOAPIC) {
ih |= APIC_INT_VIA_APIC;
}
ih |= pin;
return intr_string(ih, buf, len);
#endif
return NULL; /* No pic found! */
}
static struct intrsource xen_dummy_intrsource;
struct intrsource *
xen_intr_allocate_io_intrsource(const char *intrid)
{
/* Nothing to do, required by MSI code */
return &xen_dummy_intrsource;
}
void
xen_intr_free_io_intrsource(const char *intrid)
{
/* Nothing to do, required by MSI code */
}