xref: /illumos-gate/usr/src/cmd/bhyve/amd64/inout.h (revision 5c4a5fe16715fb423db76577a6883b5bbecdbe45)
1*5c4a5fe1SAndy Fiddaman /*-
2*5c4a5fe1SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
3*5c4a5fe1SAndy Fiddaman  *
4*5c4a5fe1SAndy Fiddaman  * Copyright (c) 2011 NetApp, Inc.
5*5c4a5fe1SAndy Fiddaman  * All rights reserved.
6*5c4a5fe1SAndy Fiddaman  *
7*5c4a5fe1SAndy Fiddaman  * Redistribution and use in source and binary forms, with or without
8*5c4a5fe1SAndy Fiddaman  * modification, are permitted provided that the following conditions
9*5c4a5fe1SAndy Fiddaman  * are met:
10*5c4a5fe1SAndy Fiddaman  * 1. Redistributions of source code must retain the above copyright
11*5c4a5fe1SAndy Fiddaman  *    notice, this list of conditions and the following disclaimer.
12*5c4a5fe1SAndy Fiddaman  * 2. Redistributions in binary form must reproduce the above copyright
13*5c4a5fe1SAndy Fiddaman  *    notice, this list of conditions and the following disclaimer in the
14*5c4a5fe1SAndy Fiddaman  *    documentation and/or other materials provided with the distribution.
15*5c4a5fe1SAndy Fiddaman  *
16*5c4a5fe1SAndy Fiddaman  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17*5c4a5fe1SAndy Fiddaman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*5c4a5fe1SAndy Fiddaman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*5c4a5fe1SAndy Fiddaman  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20*5c4a5fe1SAndy Fiddaman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*5c4a5fe1SAndy Fiddaman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*5c4a5fe1SAndy Fiddaman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*5c4a5fe1SAndy Fiddaman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*5c4a5fe1SAndy Fiddaman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*5c4a5fe1SAndy Fiddaman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*5c4a5fe1SAndy Fiddaman  * SUCH DAMAGE.
27*5c4a5fe1SAndy Fiddaman  */
28*5c4a5fe1SAndy Fiddaman /*
29*5c4a5fe1SAndy Fiddaman  * This file and its contents are supplied under the terms of the
30*5c4a5fe1SAndy Fiddaman  * Common Development and Distribution License ("CDDL"), version 1.0.
31*5c4a5fe1SAndy Fiddaman  * You may only use this file in accordance with the terms of version
32*5c4a5fe1SAndy Fiddaman  * 1.0 of the CDDL.
33*5c4a5fe1SAndy Fiddaman  *
34*5c4a5fe1SAndy Fiddaman  * A full copy of the text of the CDDL should have accompanied this
35*5c4a5fe1SAndy Fiddaman  * source.  A copy of the CDDL is also available via the Internet at
36*5c4a5fe1SAndy Fiddaman  * http://www.illumos.org/license/CDDL.
37*5c4a5fe1SAndy Fiddaman  *
38*5c4a5fe1SAndy Fiddaman  * Copyright 2014 Pluribus Networks Inc.
39*5c4a5fe1SAndy Fiddaman  */
40*5c4a5fe1SAndy Fiddaman 
41*5c4a5fe1SAndy Fiddaman #ifndef _INOUT_H_
42*5c4a5fe1SAndy Fiddaman #define	_INOUT_H_
43*5c4a5fe1SAndy Fiddaman 
44*5c4a5fe1SAndy Fiddaman #include <sys/linker_set.h>
45*5c4a5fe1SAndy Fiddaman 
46*5c4a5fe1SAndy Fiddaman struct vcpu;
47*5c4a5fe1SAndy Fiddaman struct vmctx;
48*5c4a5fe1SAndy Fiddaman struct vm_exit;
49*5c4a5fe1SAndy Fiddaman #ifndef __FreeBSD__
50*5c4a5fe1SAndy Fiddaman struct vm_inout;
51*5c4a5fe1SAndy Fiddaman #endif
52*5c4a5fe1SAndy Fiddaman 
53*5c4a5fe1SAndy Fiddaman /*
54*5c4a5fe1SAndy Fiddaman  * inout emulation handlers return 0 on success and -1 on failure.
55*5c4a5fe1SAndy Fiddaman  */
56*5c4a5fe1SAndy Fiddaman typedef int (*inout_func_t)(struct vmctx *ctx, int in, int port,
57*5c4a5fe1SAndy Fiddaman 			    int bytes, uint32_t *eax, void *arg);
58*5c4a5fe1SAndy Fiddaman 
59*5c4a5fe1SAndy Fiddaman struct inout_port {
60*5c4a5fe1SAndy Fiddaman 	const char	*name;
61*5c4a5fe1SAndy Fiddaman 	int		port;
62*5c4a5fe1SAndy Fiddaman 	int		size;
63*5c4a5fe1SAndy Fiddaman 	int		flags;
64*5c4a5fe1SAndy Fiddaman 	inout_func_t	handler;
65*5c4a5fe1SAndy Fiddaman 	void		*arg;
66*5c4a5fe1SAndy Fiddaman };
67*5c4a5fe1SAndy Fiddaman #define	IOPORT_F_IN		0x1
68*5c4a5fe1SAndy Fiddaman #define	IOPORT_F_OUT		0x2
69*5c4a5fe1SAndy Fiddaman #define	IOPORT_F_INOUT		(IOPORT_F_IN | IOPORT_F_OUT)
70*5c4a5fe1SAndy Fiddaman 
71*5c4a5fe1SAndy Fiddaman /*
72*5c4a5fe1SAndy Fiddaman  * The following flags are used internally and must not be used by
73*5c4a5fe1SAndy Fiddaman  * device models.
74*5c4a5fe1SAndy Fiddaman  */
75*5c4a5fe1SAndy Fiddaman #define	IOPORT_F_DEFAULT	0x80000000	/* claimed by default handler */
76*5c4a5fe1SAndy Fiddaman 
77*5c4a5fe1SAndy Fiddaman #define	INOUT_PORT(name, port, flags, handler)				\
78*5c4a5fe1SAndy Fiddaman 	static struct inout_port __CONCAT(__inout_port, __LINE__) = {	\
79*5c4a5fe1SAndy Fiddaman 		#name,							\
80*5c4a5fe1SAndy Fiddaman 		(port),							\
81*5c4a5fe1SAndy Fiddaman 		1,							\
82*5c4a5fe1SAndy Fiddaman 		(flags),						\
83*5c4a5fe1SAndy Fiddaman 		(handler),						\
84*5c4a5fe1SAndy Fiddaman 		0							\
85*5c4a5fe1SAndy Fiddaman 	};								\
86*5c4a5fe1SAndy Fiddaman 	DATA_SET(inout_port_set, __CONCAT(__inout_port, __LINE__))
87*5c4a5fe1SAndy Fiddaman 
88*5c4a5fe1SAndy Fiddaman void	init_inout(void);
89*5c4a5fe1SAndy Fiddaman #ifdef __FreeBSD__
90*5c4a5fe1SAndy Fiddaman int	emulate_inout(struct vmctx *, struct vcpu *vcpu, struct vm_exit *vmexit);
91*5c4a5fe1SAndy Fiddaman #else
92*5c4a5fe1SAndy Fiddaman int	emulate_inout(struct vmctx *, struct vcpu *vcpu, struct vm_inout *inout);
93*5c4a5fe1SAndy Fiddaman #endif
94*5c4a5fe1SAndy Fiddaman int	register_inout(struct inout_port *iop);
95*5c4a5fe1SAndy Fiddaman int	unregister_inout(struct inout_port *iop);
96*5c4a5fe1SAndy Fiddaman 
97*5c4a5fe1SAndy Fiddaman #endif	/* _INOUT_H_ */
98