xref: /freebsd/usr.sbin/bhyve/mem.h (revision d665d229cef8b8617a89e94898a4e8d770aedd34)
14d1e669cSPeter Grehan /*-
24d1e669cSPeter Grehan  * Copyright (c) 2012 NetApp, Inc.
34d1e669cSPeter Grehan  * All rights reserved.
44d1e669cSPeter Grehan  *
54d1e669cSPeter Grehan  * Redistribution and use in source and binary forms, with or without
64d1e669cSPeter Grehan  * modification, are permitted provided that the following conditions
74d1e669cSPeter Grehan  * are met:
84d1e669cSPeter Grehan  * 1. Redistributions of source code must retain the above copyright
94d1e669cSPeter Grehan  *    notice, this list of conditions and the following disclaimer.
104d1e669cSPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
114d1e669cSPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
124d1e669cSPeter Grehan  *    documentation and/or other materials provided with the distribution.
134d1e669cSPeter Grehan  *
144d1e669cSPeter Grehan  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
154d1e669cSPeter Grehan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164d1e669cSPeter Grehan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174d1e669cSPeter Grehan  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
184d1e669cSPeter Grehan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194d1e669cSPeter Grehan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204d1e669cSPeter Grehan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214d1e669cSPeter Grehan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224d1e669cSPeter Grehan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234d1e669cSPeter Grehan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244d1e669cSPeter Grehan  * SUCH DAMAGE.
254d1e669cSPeter Grehan  *
264d1e669cSPeter Grehan  * $FreeBSD$
274d1e669cSPeter Grehan  */
284d1e669cSPeter Grehan 
294d1e669cSPeter Grehan #ifndef _MEM_H_
304d1e669cSPeter Grehan #define	_MEM_H_
314d1e669cSPeter Grehan 
324d1e669cSPeter Grehan #include <sys/linker_set.h>
334d1e669cSPeter Grehan 
344d1e669cSPeter Grehan struct vmctx;
354d1e669cSPeter Grehan 
364d1e669cSPeter Grehan typedef int (*mem_func_t)(struct vmctx *ctx, int vcpu, int dir, uint64_t addr,
374d1e669cSPeter Grehan 			  int size, uint64_t *val, void *arg1, long arg2);
384d1e669cSPeter Grehan 
394d1e669cSPeter Grehan struct mem_range {
404d1e669cSPeter Grehan 	const char 	*name;
414d1e669cSPeter Grehan 	int		flags;
424d1e669cSPeter Grehan 	mem_func_t	handler;
434d1e669cSPeter Grehan 	void		*arg1;
444d1e669cSPeter Grehan 	long		arg2;
454d1e669cSPeter Grehan 	uint64_t  	base;
464d1e669cSPeter Grehan 	uint64_t  	size;
474d1e669cSPeter Grehan };
484d1e669cSPeter Grehan #define	MEM_F_READ		0x1
494d1e669cSPeter Grehan #define	MEM_F_WRITE		0x2
504d1e669cSPeter Grehan #define	MEM_F_RW		0x3
514d1e669cSPeter Grehan 
524d1e669cSPeter Grehan void	init_mem(void);
53*d665d229SNeel Natu int     emulate_mem(struct vmctx *, int vcpu, uint64_t paddr, struct vie *vie,
54*d665d229SNeel Natu 		    struct vm_guest_paging *paging);
554d1e669cSPeter Grehan 
564d1e669cSPeter Grehan int	register_mem(struct mem_range *memp);
570ab13648SPeter Grehan int	register_mem_fallback(struct mem_range *memp);
58028d9311SNeel Natu int	unregister_mem(struct mem_range *memp);
594d1e669cSPeter Grehan 
604d1e669cSPeter Grehan #endif	/* _MEM_H_ */
61