1241744Sgrehan/*- 2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3330449Seadler * 4241744Sgrehan * Copyright (c) 2012 NetApp, Inc. 5241744Sgrehan * All rights reserved. 6241744Sgrehan * 7241744Sgrehan * Redistribution and use in source and binary forms, with or without 8241744Sgrehan * modification, are permitted provided that the following conditions 9241744Sgrehan * are met: 10241744Sgrehan * 1. Redistributions of source code must retain the above copyright 11241744Sgrehan * notice, this list of conditions and the following disclaimer. 12241744Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 13241744Sgrehan * notice, this list of conditions and the following disclaimer in the 14241744Sgrehan * documentation and/or other materials provided with the distribution. 15241744Sgrehan * 16241744Sgrehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17241744Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18241744Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19241744Sgrehan * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20241744Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21241744Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22241744Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23241744Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24241744Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25241744Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26241744Sgrehan * SUCH DAMAGE. 27241744Sgrehan * 28241744Sgrehan * $FreeBSD: stable/11/usr.sbin/bhyve/mem.h 336161 2018-07-10 04:26:32Z araujo $ 29241744Sgrehan */ 30241744Sgrehan 31241744Sgrehan#ifndef _MEM_H_ 32241744Sgrehan#define _MEM_H_ 33241744Sgrehan 34241744Sgrehan#include <sys/linker_set.h> 35241744Sgrehan 36241744Sgrehanstruct vmctx; 37241744Sgrehan 38241744Sgrehantypedef int (*mem_func_t)(struct vmctx *ctx, int vcpu, int dir, uint64_t addr, 39241744Sgrehan int size, uint64_t *val, void *arg1, long arg2); 40241744Sgrehan 41241744Sgrehanstruct mem_range { 42241744Sgrehan const char *name; 43241744Sgrehan int flags; 44241744Sgrehan mem_func_t handler; 45241744Sgrehan void *arg1; 46241744Sgrehan long arg2; 47241744Sgrehan uint64_t base; 48241744Sgrehan uint64_t size; 49241744Sgrehan}; 50241744Sgrehan#define MEM_F_READ 0x1 51241744Sgrehan#define MEM_F_WRITE 0x2 52241744Sgrehan#define MEM_F_RW 0x3 53269700Sneel#define MEM_F_IMMUTABLE 0x4 /* mem_range cannot be unregistered */ 54241744Sgrehan 55241744Sgrehanvoid init_mem(void); 56269008Sneelint emulate_mem(struct vmctx *, int vcpu, uint64_t paddr, struct vie *vie, 57269008Sneel struct vm_guest_paging *paging); 58336161Saraujo 59241744Sgrehanint register_mem(struct mem_range *memp); 60247144Sgrehanint register_mem_fallback(struct mem_range *memp); 61249321Sneelint unregister_mem(struct mem_range *memp); 62241744Sgrehan 63241744Sgrehan#endif /* _MEM_H_ */ 64