Index: sys/arm64/include/xen/arch-intr.h =================================================================== --- /dev/null +++ sys/arm64/include/xen/arch-intr.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015 Julien Grall + * + * 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 AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_XEN_ARCH_INTR_H_ +#define _MACHINE_XEN_ARCH_INTR_H_ + +typedef struct intr_event *xen_arch_isrc_t; + +#endif /* _MACHINE_XEN_ARCH_INTR_H_ */ Index: sys/arm64/xen/xen_arch_intr.c =================================================================== --- /dev/null +++ sys/arm64/xen/xen_arch_intr.c @@ -0,0 +1,175 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015 Julien Grall + * + * 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 AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static void +xen_intr_arch_disable_source(void *arg) +{ + struct xenisrc *isrc; + + isrc = arg; + xen_intr_disable_source(isrc, true); +} + +static void +xen_intr_arch_enable_source(void *arg) +{ + struct xenisrc *isrc; + + isrc = arg; + xen_intr_enable_source(isrc); +} + +static void +xen_intr_arch_eoi_source(void *arg) +{ + struct xenisrc *isrc; + + isrc = arg; + xen_intr_eoi_source(isrc); +} + +static int +xen_intr_arch_assign_cpu(void *arg, int cpuid) +{ + struct xenisrc *isrc; + + isrc = arg; + return (xen_intr_assign_cpu(isrc, cpuid)); +} + +void +xen_arch_intr_init(void) +{ + /* Nothing to do */ +} + +int +xen_arch_intr_setup(struct xenisrc *isrc) +{ + + return (intr_event_create(&isrc->xi_arch, isrc, 0, + isrc->xi_vector /* IRQ */, + xen_intr_arch_disable_source /* mask */, + xen_intr_arch_enable_source /* unmask */, + xen_intr_arch_eoi_source /* EOI */, + xen_intr_arch_assign_cpu /* cpu assign */, + "xen%d", isrc->xi_port)); +} + +bool +xen_arch_intr_has_handlers(struct xenisrc *isrc) +{ + return (!CK_SLIST_EMPTY(&isrc->xi_arch->ie_handlers)); +} + +bool +xen_arch_intr_execute_handlers(struct xenisrc *isrc, struct trapframe *frame) +{ + int error; + + error = intr_event_handle(isrc->xi_arch, frame); + if (error != 0) { + xen_intr_disable_source(isrc, true); + log(LOG_ERR, "Stray evchn%d: %d\n", + isrc->xi_port, error); + return (false); + } + return (true); +} + +int +xen_arch_intr_add_handler(const char *name, driver_filter_t filter, + driver_intr_t handler, void *arg, enum intr_type flags, + struct xenisrc *isrc) +{ + int error; + + KASSERT(!xen_arch_intr_has_handlers(isrc), + ("Only one handler is allowed per event channel")); + + error = intr_event_add_handler(isrc->xi_arch, + name, filter, handler, + arg, intr_priority(flags), flags, &isrc->xi_cookie); + if (error != 0) + return (error); + + /* Enable the event channel */ + xen_intr_enable_intr(isrc); + xen_intr_enable_source(isrc); + + return (0); +} + +int +xen_arch_intr_remove_handler(struct xenisrc *isrc) +{ + int error; + + error = intr_event_remove_handler(isrc->xi_cookie); + if (error != 0) + return (error); + + /* Disable the event channel */ + xen_intr_disable_source(isrc, true); + xen_intr_disable_intr(isrc); + + return (0); +} + +int +xen_arch_intr_describe(struct xenisrc *isrc, const char *descr) +{ + + return (intr_event_describe_handler(isrc->xi_arch, + isrc->xi_cookie, descr)); +} + +int +xen_arch_intr_event_bind(struct xenisrc *isrc, u_int cpu) +{ + + return (intr_event_bind(isrc->xi_arch, cpu)); +} Index: sys/conf/files.arm64 =================================================================== --- sys/conf/files.arm64 +++ sys/conf/files.arm64 @@ -586,3 +586,4 @@ # Xen arm64/xen/hypercall.S optional xenhvm +arm64/xen/xen_arch_intr.c optional xenhvm