direct-io.hg

view tools/libxc/xc_private.h @ 2787:a5c335665fd6

bitkeeper revision 1.1159.142.2 (41849fadYlUYMwSy6tcq8Y-Yi8NMZA)

Clean up libxc by allowing direct use of Xen headers from userland:
#include <xen/...>
author kaf24@freefall.cl.cam.ac.uk
date Sun Oct 31 08:17:49 2004 +0000 (2004-10-31)
parents 1e99cd1cb3a3
children 3f929065a1d1
line source
2 #ifndef __XC_PRIVATE_H__
3 #define __XC_PRIVATE_H__
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <sys/mman.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <stdlib.h>
13 #include <sys/ioctl.h>
14 #include <errno.h>
15 #include <string.h>
17 #include "xc.h"
19 #include <asm-xen/proc_cmd.h>
22 #define _PAGE_PRESENT 0x001
23 #define _PAGE_RW 0x002
24 #define _PAGE_USER 0x004
25 #define _PAGE_PWT 0x008
26 #define _PAGE_PCD 0x010
27 #define _PAGE_ACCESSED 0x020
28 #define _PAGE_DIRTY 0x040
29 #define _PAGE_PAT 0x080
30 #define _PAGE_PSE 0x080
31 #define _PAGE_GLOBAL 0x100
34 #define L1_PAGETABLE_SHIFT 12
35 #define L2_PAGETABLE_SHIFT 22
37 #define ENTRIES_PER_L1_PAGETABLE 1024
38 #define ENTRIES_PER_L2_PAGETABLE 1024
40 #define PAGE_SHIFT L1_PAGETABLE_SHIFT
41 #define PAGE_SIZE (1UL << PAGE_SHIFT)
42 #define PAGE_MASK (~(PAGE_SIZE-1))
44 typedef unsigned long l1_pgentry_t;
45 typedef unsigned long l2_pgentry_t;
47 #define l1_table_offset(_a) \
48 (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
49 #define l2_table_offset(_a) \
50 ((_a) >> L2_PAGETABLE_SHIFT)
52 #define ERROR(_m, _a...) \
53 fprintf(stderr, "ERROR: " _m "\n" , ## _a )
55 #define PERROR(_m, _a...) \
56 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
57 errno, strerror(errno))
59 static inline int do_privcmd(int xc_handle,
60 unsigned int cmd,
61 unsigned long data)
62 {
63 return ioctl(xc_handle, cmd, data);
64 }
66 static inline int do_xen_hypercall(int xc_handle,
67 privcmd_hypercall_t *hypercall)
68 {
69 return do_privcmd(xc_handle,
70 IOCTL_PRIVCMD_HYPERCALL,
71 (unsigned long)hypercall);
72 }
74 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
75 {
76 int ret = -1;
77 privcmd_hypercall_t hypercall;
79 op->interface_version = DOM0_INTERFACE_VERSION;
81 hypercall.op = __HYPERVISOR_dom0_op;
82 hypercall.arg[0] = (unsigned long)op;
84 if ( mlock(op, sizeof(*op)) != 0 )
85 {
86 PERROR("Could not lock memory for Xen hypercall");
87 goto out1;
88 }
90 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
91 {
92 if ( errno == EACCES )
93 fprintf(stderr, "Dom0 operation failed -- need to"
94 " rebuild the user-space tool set?\n");
95 goto out2;
96 }
98 out2: (void)munlock(op, sizeof(*op));
99 out1: return ret;
100 }
102 static inline int do_dom_mem_op(int xc_handle,
103 unsigned int memop,
104 unsigned int *extent_list,
105 unsigned int nr_extents,
106 unsigned int extent_order,
107 domid_t domid)
108 {
109 privcmd_hypercall_t hypercall;
110 long ret = -EINVAL;
112 hypercall.op = __HYPERVISOR_dom_mem_op;
113 hypercall.arg[0] = (unsigned long)memop;
114 hypercall.arg[1] = (unsigned long)extent_list;
115 hypercall.arg[2] = (unsigned long)nr_extents;
116 hypercall.arg[3] = (unsigned long)extent_order;
117 hypercall.arg[4] = (unsigned long)domid;
119 if ( mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0 )
120 {
121 PERROR("Could not lock memory for Xen hypercall");
122 goto out1;
123 }
125 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
126 {
127 fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
128 " rebuild the user-space tool set?\n",ret,errno);
129 goto out2;
130 }
132 out2: (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
133 out1: return ret;
134 }
137 /*
138 * PFN mapping.
139 */
140 int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
141 unsigned long csum_page (void * page);
143 /*
144 * MMU updates.
145 */
146 #define MAX_MMU_UPDATES 1024
147 typedef struct {
148 mmu_update_t updates[MAX_MMU_UPDATES];
149 int idx;
150 domid_t subject;
151 } mmu_t;
152 mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
153 int add_mmu_update(int xc_handle, mmu_t *mmu,
154 unsigned long ptr, unsigned long val);
155 int finish_mmu_updates(int xc_handle, mmu_t *mmu);
158 /*
159 * ioctl-based mfn mapping interface
160 */
162 /*
163 typedef struct privcmd_mmap_entry {
164 unsigned long va;
165 unsigned long mfn;
166 unsigned long npages;
167 } privcmd_mmap_entry_t;
169 typedef struct privcmd_mmap {
170 int num;
171 domid_t dom;
172 privcmd_mmap_entry_t *entry;
173 } privcmd_mmap_t;
174 */
176 #define mfn_mapper_queue_size 128
178 typedef struct mfn_mapper {
179 int xc_handle;
180 int size;
181 int prot;
182 int error;
183 int max_queue_size;
184 void * addr;
185 privcmd_mmap_t ioctl;
187 } mfn_mapper_t;
189 #include "xc_io.h"
191 unsigned long xc_get_m2p_start_mfn ( int xc_handle );
193 #endif /* __XC_PRIVATE_H__ */