1*31cf78c9SMark Johnston /*- 2*31cf78c9SMark Johnston * SPDX-License-Identifier: BSD-2-Clause 3*31cf78c9SMark Johnston * 4*31cf78c9SMark Johnston * Copyright (c) 2011 NetApp, Inc. 5*31cf78c9SMark Johnston * All rights reserved. 6*31cf78c9SMark Johnston * 7*31cf78c9SMark Johnston * Redistribution and use in source and binary forms, with or without 8*31cf78c9SMark Johnston * modification, are permitted provided that the following conditions 9*31cf78c9SMark Johnston * are met: 10*31cf78c9SMark Johnston * 1. Redistributions of source code must retain the above copyright 11*31cf78c9SMark Johnston * notice, this list of conditions and the following disclaimer. 12*31cf78c9SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 13*31cf78c9SMark Johnston * notice, this list of conditions and the following disclaimer in the 14*31cf78c9SMark Johnston * documentation and/or other materials provided with the distribution. 15*31cf78c9SMark Johnston * 16*31cf78c9SMark Johnston * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17*31cf78c9SMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*31cf78c9SMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*31cf78c9SMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20*31cf78c9SMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*31cf78c9SMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*31cf78c9SMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*31cf78c9SMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*31cf78c9SMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*31cf78c9SMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*31cf78c9SMark Johnston * SUCH DAMAGE. 27*31cf78c9SMark Johnston */ 28*31cf78c9SMark Johnston 29*31cf78c9SMark Johnston #ifndef _INOUT_H_ 30*31cf78c9SMark Johnston #define _INOUT_H_ 31*31cf78c9SMark Johnston 32*31cf78c9SMark Johnston #include <sys/linker_set.h> 33*31cf78c9SMark Johnston 34*31cf78c9SMark Johnston struct vcpu; 35*31cf78c9SMark Johnston struct vmctx; 36*31cf78c9SMark Johnston struct vm_exit; 37*31cf78c9SMark Johnston 38*31cf78c9SMark Johnston /* 39*31cf78c9SMark Johnston * inout emulation handlers return 0 on success and -1 on failure. 40*31cf78c9SMark Johnston */ 41*31cf78c9SMark Johnston typedef int (*inout_func_t)(struct vmctx *ctx, int in, int port, 42*31cf78c9SMark Johnston int bytes, uint32_t *eax, void *arg); 43*31cf78c9SMark Johnston 44*31cf78c9SMark Johnston struct inout_port { 45*31cf78c9SMark Johnston const char *name; 46*31cf78c9SMark Johnston int port; 47*31cf78c9SMark Johnston int size; 48*31cf78c9SMark Johnston int flags; 49*31cf78c9SMark Johnston inout_func_t handler; 50*31cf78c9SMark Johnston void *arg; 51*31cf78c9SMark Johnston }; 52*31cf78c9SMark Johnston #define IOPORT_F_IN 0x1 53*31cf78c9SMark Johnston #define IOPORT_F_OUT 0x2 54*31cf78c9SMark Johnston #define IOPORT_F_INOUT (IOPORT_F_IN | IOPORT_F_OUT) 55*31cf78c9SMark Johnston 56*31cf78c9SMark Johnston /* 57*31cf78c9SMark Johnston * The following flags are used internally and must not be used by 58*31cf78c9SMark Johnston * device models. 59*31cf78c9SMark Johnston */ 60*31cf78c9SMark Johnston #define IOPORT_F_DEFAULT 0x80000000 /* claimed by default handler */ 61*31cf78c9SMark Johnston 62*31cf78c9SMark Johnston #define INOUT_PORT(name, port, flags, handler) \ 63*31cf78c9SMark Johnston static struct inout_port __CONCAT(__inout_port, __LINE__) = { \ 64*31cf78c9SMark Johnston #name, \ 65*31cf78c9SMark Johnston (port), \ 66*31cf78c9SMark Johnston 1, \ 67*31cf78c9SMark Johnston (flags), \ 68*31cf78c9SMark Johnston (handler), \ 69*31cf78c9SMark Johnston 0 \ 70*31cf78c9SMark Johnston }; \ 71*31cf78c9SMark Johnston DATA_SET(inout_port_set, __CONCAT(__inout_port, __LINE__)) 72*31cf78c9SMark Johnston 73*31cf78c9SMark Johnston void init_inout(void); 74*31cf78c9SMark Johnston int emulate_inout(struct vmctx *ctx, struct vcpu *vcpu, struct vm_exit *vmexit); 75*31cf78c9SMark Johnston int register_inout(struct inout_port *iop); 76*31cf78c9SMark Johnston int unregister_inout(struct inout_port *iop); 77*31cf78c9SMark Johnston 78*31cf78c9SMark Johnston #endif /* _INOUT_H_ */ 79