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