inout.h revision 257396
116359Sasami/*-
216359Sasami * Copyright (c) 2011 NetApp, Inc.
316359Sasami * All rights reserved.
416359Sasami *
516359Sasami * Redistribution and use in source and binary forms, with or without
616359Sasami * modification, are permitted provided that the following conditions
716359Sasami * are met:
816359Sasami * 1. Redistributions of source code must retain the above copyright
916359Sasami *    notice, this list of conditions and the following disclaimer.
1016359Sasami * 2. Redistributions in binary form must reproduce the above copyright
1116359Sasami *    notice, this list of conditions and the following disclaimer in the
1216359Sasami *    documentation and/or other materials provided with the distribution.
1316359Sasami *
1416359Sasami * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
1516359Sasami * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1616359Sasami * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1716359Sasami * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
1816359Sasami * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1916359Sasami * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2016359Sasami * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2116359Sasami * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2216359Sasami * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2316359Sasami * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2416359Sasami * SUCH DAMAGE.
2516359Sasami *
2616359Sasami * $FreeBSD: stable/10/usr.sbin/bhyve/inout.h 257396 2013-10-30 20:42:09Z neel $
2716359Sasami */
2816359Sasami
2916359Sasami#ifndef _INOUT_H_
3016359Sasami#define	_INOUT_H_
3116359Sasami
3216359Sasami#include <sys/linker_set.h>
3350477Speter
3416359Sasamistruct vmctx;
3516359Sasami
3616359Sasamitypedef int (*inout_func_t)(struct vmctx *ctx, int vcpu, int in, int port,
3716359Sasami			    int bytes, uint32_t *eax, void *arg);
3816359Sasami
3916359Sasamistruct inout_port {
4016359Sasami	const char 	*name;
4116359Sasami	int		port;
4216359Sasami	int		size;
4316359Sasami	int		flags;
4416359Sasami	inout_func_t	handler;
4516359Sasami	void		*arg;
46263379Simp};
4716359Sasami#define	IOPORT_F_IN		0x1
4816359Sasami#define	IOPORT_F_OUT		0x2
4948217Skato#define	IOPORT_F_INOUT		(IOPORT_F_IN | IOPORT_F_OUT)
5048217Skato
5148217Skato/*
5248217Skato * The following flags are used internally and must not be used by
5348217Skato * device models.
5448217Skato */
5548217Skato#define	IOPORT_F_DEFAULT	0x80000000	/* claimed by default handler */
5648217Skato
5716359Sasami#define	INOUT_PORT(name, port, flags, handler)				\
5816359Sasami	static struct inout_port __CONCAT(__inout_port, __LINE__) = {	\
59263379Simp		#name,							\
6016359Sasami		(port),							\
6116359Sasami		1,							\
6216359Sasami		(flags),						\
6316359Sasami		(handler),						\
64		0							\
65	};								\
66	DATA_SET(inout_port_set, __CONCAT(__inout_port, __LINE__))
67
68void	init_inout(void);
69int	emulate_inout(struct vmctx *, int vcpu, int in, int port, int bytes,
70		      uint32_t *eax, int strict);
71int	register_inout(struct inout_port *iop);
72int	unregister_inout(struct inout_port *iop);
73void	init_bvmcons(void);
74
75#endif	/* _INOUT_H_ */
76