direct-io.hg

view tools/libxc/xc_linux.c @ 10276:b3d901ba705d

Represent PFNs with their own type, rather than 'unsigned long'.
('long' changes size and alignment between 32- and 64-bit ABIs.)
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 06 09:48:17 2006 +0100 (2006-06-06)
parents 24dbb153ab39
children 7fba181c8531
line source
1 /******************************************************************************
2 *
3 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
10 */
12 #include "xc_private.h"
14 #include <xen/memory.h>
15 #include <xen/sys/evtchn.h>
17 int xc_interface_open(void)
18 {
19 int fd = open("/proc/xen/privcmd", O_RDWR);
20 if ( fd == -1 )
21 PERROR("Could not obtain handle on privileged command interface");
22 return fd;
23 }
25 int xc_interface_close(int xc_handle)
26 {
27 return close(xc_handle);
28 }
30 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
31 xen_pfn_t *arr, int num)
32 {
33 privcmd_mmapbatch_t ioctlx;
34 void *addr;
35 addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
36 if ( addr == MAP_FAILED )
37 return NULL;
39 ioctlx.num=num;
40 ioctlx.dom=dom;
41 ioctlx.addr=(unsigned long)addr;
42 ioctlx.arr=arr;
43 if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
44 {
45 int saved_errno = errno;
46 perror("XXXXXXXX");
47 (void)munmap(addr, num*PAGE_SIZE);
48 errno = saved_errno;
49 return NULL;
50 }
51 return addr;
53 }
55 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
56 int size, int prot,
57 unsigned long mfn)
58 {
59 privcmd_mmap_t ioctlx;
60 privcmd_mmap_entry_t entry;
61 void *addr;
62 addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
63 if ( addr == MAP_FAILED )
64 return NULL;
66 ioctlx.num=1;
67 ioctlx.dom=dom;
68 ioctlx.entry=&entry;
69 entry.va=(unsigned long) addr;
70 entry.mfn=mfn;
71 entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
72 if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
73 {
74 int saved_errno = errno;
75 (void)munmap(addr, size);
76 errno = saved_errno;
77 return NULL;
78 }
79 return addr;
80 }
82 int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
83 privcmd_mmap_entry_t *entries, int nr)
84 {
85 privcmd_mmap_t ioctlx;
87 ioctlx.num = nr;
88 ioctlx.dom = dom;
89 ioctlx.entry = entries;
91 return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
92 }
94 static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
95 {
96 return ioctl(xc_handle, cmd, data);
97 }
99 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
100 {
101 return do_privcmd(xc_handle,
102 IOCTL_PRIVCMD_HYPERCALL,
103 (unsigned long)hypercall);
104 }
106 /*
107 * Local variables:
108 * mode: C
109 * c-set-style: "BSD"
110 * c-basic-offset: 4
111 * tab-width: 4
112 * indent-tabs-mode: nil
113 * End:
114 */