/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 NetApp, Inc.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _INOUT_H_29#define _INOUT_H_3031#include <sys/linker_set.h>3233struct vcpu;34struct vmctx;35struct vm_exit;3637/*38* inout emulation handlers return 0 on success and -1 on failure.39*/40typedef int (*inout_func_t)(struct vmctx *ctx, int in, int port,41int bytes, uint32_t *eax, void *arg);4243struct inout_port {44const char *name;45int port;46int size;47int flags;48inout_func_t handler;49void *arg;50};51#define IOPORT_F_IN 0x152#define IOPORT_F_OUT 0x253#define IOPORT_F_INOUT (IOPORT_F_IN | IOPORT_F_OUT)5455/*56* The following flags are used internally and must not be used by57* device models.58*/59#define IOPORT_F_DEFAULT 0x80000000 /* claimed by default handler */6061#define INOUT_PORT(name, port, flags, handler) \62static struct inout_port __CONCAT(__inout_port, __LINE__) = { \63#name, \64(port), \651, \66(flags), \67(handler), \680 \69}; \70DATA_SET(inout_port_set, __CONCAT(__inout_port, __LINE__))7172void init_inout(void);73int emulate_inout(struct vmctx *ctx, struct vcpu *vcpu, struct vm_exit *vmexit);74int register_inout(struct inout_port *iop);75int unregister_inout(struct inout_port *iop);7677#endif /* _INOUT_H_ */787980