Deleted Added
sdiff udiff text old ( 268935 ) new ( 268953 )
full compact
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 $
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: stable/10/lib/libvmmapi/vmmapi.c 268935 2014-07-21 02:39:17Z 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;
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;
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
183static int
184setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr)
185{
186 int error;
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) {
198 *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
199 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 ---