vmmapi.c (268935) | vmmapi.c (268953) |
---|---|
1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: stable/10/lib/libvmmapi/vmmapi.c 268935 2014-07-21 02:39:17Z jhb $ | 26 * $FreeBSD: stable/10/lib/libvmmapi/vmmapi.c 268953 2014-07-21 19:08:02Z jhb $ |
27 */ 28 29#include <sys/cdefs.h> | 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: stable/10/lib/libvmmapi/vmmapi.c 268935 2014-07-21 02:39:17Z jhb $"); | 30__FBSDID("$FreeBSD: stable/10/lib/libvmmapi/vmmapi.c 268953 2014-07-21 19:08:02Z jhb $"); |
31 32#include <sys/types.h> 33#include <sys/sysctl.h> 34#include <sys/ioctl.h> 35#include <sys/mman.h> 36 37#include <machine/specialreg.h> 38 --- 13 unchanged lines hidden (view full) --- 52 53#define MB (1024 * 1024UL) 54#define GB (1024 * 1024 * 1024UL) 55 56struct vmctx { 57 int fd; 58 uint32_t lowmem_limit; 59 enum vm_mmap_style vms; | 31 32#include <sys/types.h> 33#include <sys/sysctl.h> 34#include <sys/ioctl.h> 35#include <sys/mman.h> 36 37#include <machine/specialreg.h> 38 --- 13 unchanged lines hidden (view full) --- 52 53#define MB (1024 * 1024UL) 54#define GB (1024 * 1024 * 1024UL) 55 56struct vmctx { 57 int fd; 58 uint32_t lowmem_limit; 59 enum vm_mmap_style vms; |
60 int memflags; |
|
60 size_t lowmem; 61 char *lowmem_addr; 62 size_t highmem; 63 char *highmem_addr; 64 char *name; 65}; 66 67#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x))) --- 28 unchanged lines hidden (view full) --- 96vm_open(const char *name) 97{ 98 struct vmctx *vm; 99 100 vm = malloc(sizeof(struct vmctx) + strlen(name) + 1); 101 assert(vm != NULL); 102 103 vm->fd = -1; | 61 size_t lowmem; 62 char *lowmem_addr; 63 size_t highmem; 64 char *highmem_addr; 65 char *name; 66}; 67 68#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x))) --- 28 unchanged lines hidden (view full) --- 97vm_open(const char *name) 98{ 99 struct vmctx *vm; 100 101 vm = malloc(sizeof(struct vmctx) + strlen(name) + 1); 102 assert(vm != NULL); 103 104 vm->fd = -1; |
105 vm->memflags = 0; |
|
104 vm->lowmem_limit = 3 * GB; 105 vm->name = (char *)(vm + 1); 106 strcpy(vm->name, name); 107 108 if ((vm->fd = vm_device_open(vm->name)) < 0) 109 goto err; 110 111 return (vm); --- 63 unchanged lines hidden (view full) --- 175 176void 177vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit) 178{ 179 180 ctx->lowmem_limit = limit; 181} 182 | 106 vm->lowmem_limit = 3 * GB; 107 vm->name = (char *)(vm + 1); 108 strcpy(vm->name, name); 109 110 if ((vm->fd = vm_device_open(vm->name)) < 0) 111 goto err; 112 113 return (vm); --- 63 unchanged lines hidden (view full) --- 177 178void 179vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit) 180{ 181 182 ctx->lowmem_limit = limit; 183} 184 |
185void 186vm_set_memflags(struct vmctx *ctx, int flags) 187{ 188 189 ctx->memflags = flags; 190} 191 |
|
183static int 184setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr) 185{ | 192static int 193setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr) 194{ |
186 int error; | 195 int error, mmap_flags; |
187 struct vm_memory_segment seg; 188 189 /* 190 * Create and optionally map 'len' bytes of memory at guest 191 * physical address 'gpa' 192 */ 193 bzero(&seg, sizeof(seg)); 194 seg.gpa = gpa; 195 seg.len = len; 196 error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg); 197 if (error == 0 && addr != NULL) { | 196 struct vm_memory_segment seg; 197 198 /* 199 * Create and optionally map 'len' bytes of memory at guest 200 * physical address 'gpa' 201 */ 202 bzero(&seg, sizeof(seg)); 203 seg.gpa = gpa; 204 seg.len = len; 205 error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg); 206 if (error == 0 && addr != NULL) { |
198 *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, 199 ctx->fd, gpa); | 207 mmap_flags = MAP_SHARED; 208 if ((ctx->memflags & VM_MEM_F_INCORE) == 0) 209 mmap_flags |= MAP_NOCORE; 210 *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, mmap_flags, 211 ctx->fd, gpa); |
200 } 201 return (error); 202} 203 204int 205vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms) 206{ 207 char **addr; --- 706 unchanged lines hidden --- | 212 } 213 return (error); 214} 215 216int 217vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms) 218{ 219 char **addr; --- 706 unchanged lines hidden --- |