14d1e669cSPeter Grehan /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 31de7b4b8SPedro F. Giffuni * 44d1e669cSPeter Grehan * Copyright (c) 2012 NetApp, Inc. 54d1e669cSPeter Grehan * All rights reserved. 64d1e669cSPeter Grehan * 74d1e669cSPeter Grehan * Redistribution and use in source and binary forms, with or without 84d1e669cSPeter Grehan * modification, are permitted provided that the following conditions 94d1e669cSPeter Grehan * are met: 104d1e669cSPeter Grehan * 1. Redistributions of source code must retain the above copyright 114d1e669cSPeter Grehan * notice, this list of conditions and the following disclaimer. 124d1e669cSPeter Grehan * 2. Redistributions in binary form must reproduce the above copyright 134d1e669cSPeter Grehan * notice, this list of conditions and the following disclaimer in the 144d1e669cSPeter Grehan * documentation and/or other materials provided with the distribution. 154d1e669cSPeter Grehan * 164d1e669cSPeter Grehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 174d1e669cSPeter Grehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 184d1e669cSPeter Grehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 194d1e669cSPeter Grehan * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 204d1e669cSPeter Grehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 214d1e669cSPeter Grehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 224d1e669cSPeter Grehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 234d1e669cSPeter Grehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 244d1e669cSPeter Grehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 254d1e669cSPeter Grehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 264d1e669cSPeter Grehan * SUCH DAMAGE. 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 347d9ef309SJohn Baldwin struct vcpu; 354d1e669cSPeter Grehan 367d9ef309SJohn Baldwin typedef int (*mem_func_t)(struct vcpu *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 5112a6eb99SNeel Natu #define MEM_F_IMMUTABLE 0x4 /* mem_range cannot be unregistered */ 524d1e669cSPeter Grehan 53730510dcSJohn Baldwin void init_mem(int ncpu); 547d9ef309SJohn Baldwin int emulate_mem(struct vcpu *vcpu, uint64_t paddr, struct vie *vie, 55d665d229SNeel Natu struct vm_guest_paging *paging); 564d1e669cSPeter Grehan 577d9ef309SJohn Baldwin int read_mem(struct vcpu *vpu, uint64_t gpa, uint64_t *rval, int size); 584d1e669cSPeter Grehan int register_mem(struct mem_range *memp); 590ab13648SPeter Grehan int register_mem_fallback(struct mem_range *memp); 60028d9311SNeel Natu int unregister_mem(struct mem_range *memp); 617d9ef309SJohn Baldwin int write_mem(struct vcpu *vcpu, uint64_t gpa, uint64_t wval, int size); 624d1e669cSPeter Grehan 634d1e669cSPeter Grehan #endif /* _MEM_H_ */ 64