ia64/xen-unstable

view tools/libxc/xc_private.h @ 6385:f34e732ed4bf

Xenstore testsuite robustness: save output rather than rerun on failure.
"make check" reruns a test which fails with more verbosity. If the test
fails intermittently, that doesn't work well: save the output and simply
dump it if the test fails.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 23 19:58:59 2005 +0000 (2005-08-23)
parents f294acb25858
children 6e899a3840b2 2f20c2fce2c5 e3d811cca4e1 1ae656509f02 23979fb12c49 84ee014ebd41 99914b54f7bf 81576d3d1ca8 3a8f27c6d56c cc5f88b719d0 fa0754a9f64f
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 <xen/linux/privcmd.h>
21 #define _PAGE_PRESENT 0x001
22 #define _PAGE_RW 0x002
23 #define _PAGE_USER 0x004
24 #define _PAGE_PWT 0x008
25 #define _PAGE_PCD 0x010
26 #define _PAGE_ACCESSED 0x020
27 #define _PAGE_DIRTY 0x040
28 #define _PAGE_PAT 0x080
29 #define _PAGE_PSE 0x080
30 #define _PAGE_GLOBAL 0x100
32 #if defined(__i386__)
33 #define L1_PAGETABLE_SHIFT 12
34 #define L2_PAGETABLE_SHIFT 22
35 #define L1_PAGETABLE_SHIFT_PAE 12
36 #define L2_PAGETABLE_SHIFT_PAE 21
37 #define L3_PAGETABLE_SHIFT_PAE 30
38 #elif defined(__x86_64__)
39 #define L1_PAGETABLE_SHIFT 12
40 #define L2_PAGETABLE_SHIFT 21
41 #define L3_PAGETABLE_SHIFT 30
42 #define L4_PAGETABLE_SHIFT 39
43 #endif
45 #if defined(__i386__)
46 #define ENTRIES_PER_L1_PAGETABLE 1024
47 #define ENTRIES_PER_L2_PAGETABLE 1024
48 #define L1_PAGETABLE_ENTRIES_PAE 512
49 #define L2_PAGETABLE_ENTRIES_PAE 512
50 #define L3_PAGETABLE_ENTRIES_PAE 4
51 #elif defined(__x86_64__)
52 #define L1_PAGETABLE_ENTRIES 512
53 #define L2_PAGETABLE_ENTRIES 512
54 #define L3_PAGETABLE_ENTRIES 512
55 #define L4_PAGETABLE_ENTRIES 512
56 #endif
58 #define PAGE_SHIFT XC_PAGE_SHIFT
59 #define PAGE_SIZE (1UL << PAGE_SHIFT)
60 #define PAGE_MASK (~(PAGE_SIZE-1))
62 typedef u32 l1_pgentry_32_t;
63 typedef u32 l2_pgentry_32_t;
64 typedef u64 l1_pgentry_64_t;
65 typedef u64 l2_pgentry_64_t;
66 typedef u64 l3_pgentry_64_t;
67 typedef unsigned long l1_pgentry_t;
68 typedef unsigned long l2_pgentry_t;
69 #if defined(__x86_64__)
70 typedef unsigned long l3_pgentry_t;
71 typedef unsigned long l4_pgentry_t;
72 #endif
74 #if defined(__i386__)
75 #define l1_table_offset(_a) \
76 (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
77 #define l2_table_offset(_a) \
78 ((_a) >> L2_PAGETABLE_SHIFT)
79 #define l1_table_offset_pae(_a) \
80 (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
81 #define l2_table_offset_pae(_a) \
82 (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
83 #define l3_table_offset_pae(_a) \
84 (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
85 #elif defined(__x86_64__)
86 #define l1_table_offset(_a) \
87 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
88 #define l2_table_offset(_a) \
89 (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
90 #define l3_table_offset(_a) \
91 (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
92 #define l4_table_offset(_a) \
93 (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
94 #endif
96 struct domain_setup_info
97 {
98 unsigned long v_start;
99 unsigned long v_end;
100 unsigned long v_kernstart;
101 unsigned long v_kernend;
102 unsigned long v_kernentry;
104 unsigned int load_symtab;
105 unsigned int pae_kernel;
106 unsigned long symtab_addr;
107 unsigned long symtab_len;
108 };
110 typedef int (*parseimagefunc)(char *image, unsigned long image_size,
111 struct domain_setup_info *dsi);
112 typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch,
113 u32 dom, unsigned long *parray,
114 struct domain_setup_info *dsi);
116 struct load_funcs
117 {
118 parseimagefunc parseimage;
119 loadimagefunc loadimage;
120 };
122 #define ERROR(_m, _a...) \
123 do { \
124 int __saved_errno = errno; \
125 fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \
126 errno = __saved_errno; \
127 } while (0)
130 #define PERROR(_m, _a...) \
131 do { \
132 int __saved_errno = errno; \
133 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
134 __saved_errno, strerror(__saved_errno)); \
135 errno = __saved_errno; \
136 } while (0)
138 static inline void safe_munlock(const void *addr, size_t len)
139 {
140 int saved_errno = errno;
141 (void)munlock(addr, len);
142 errno = saved_errno;
143 }
145 static inline int do_privcmd(int xc_handle,
146 unsigned int cmd,
147 unsigned long data)
148 {
149 return ioctl(xc_handle, cmd, data);
150 }
152 static inline int do_xen_hypercall(int xc_handle,
153 privcmd_hypercall_t *hypercall)
154 {
155 return do_privcmd(xc_handle,
156 IOCTL_PRIVCMD_HYPERCALL,
157 (unsigned long)hypercall);
158 }
160 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
161 {
162 int ret = -1;
163 privcmd_hypercall_t hypercall;
165 op->interface_version = DOM0_INTERFACE_VERSION;
167 hypercall.op = __HYPERVISOR_dom0_op;
168 hypercall.arg[0] = (unsigned long)op;
170 if ( mlock(op, sizeof(*op)) != 0 )
171 {
172 PERROR("Could not lock memory for Xen hypercall");
173 goto out1;
174 }
176 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
177 {
178 if ( errno == EACCES )
179 fprintf(stderr, "Dom0 operation failed -- need to"
180 " rebuild the user-space tool set?\n");
181 }
183 safe_munlock(op, sizeof(*op));
185 out1:
186 return ret;
187 }
189 static inline int do_dom_mem_op(int xc_handle,
190 unsigned int memop,
191 unsigned int *extent_list,
192 unsigned int nr_extents,
193 unsigned int extent_order,
194 domid_t domid)
195 {
196 privcmd_hypercall_t hypercall;
197 long ret = -EINVAL;
199 hypercall.op = __HYPERVISOR_dom_mem_op;
200 hypercall.arg[0] = (unsigned long)memop;
201 hypercall.arg[1] = (unsigned long)extent_list;
202 hypercall.arg[2] = (unsigned long)nr_extents;
203 hypercall.arg[3] = (unsigned long)extent_order;
204 hypercall.arg[4] = (unsigned long)domid;
206 if ( (extent_list != NULL) &&
207 (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
208 {
209 PERROR("Could not lock memory for Xen hypercall");
210 goto out1;
211 }
213 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
214 {
215 fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
216 " rebuild the user-space tool set?\n",ret,errno);
217 }
219 if ( extent_list != NULL )
220 safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
222 out1:
223 return ret;
224 }
226 static inline int do_mmuext_op(
227 int xc_handle,
228 struct mmuext_op *op,
229 unsigned int nr_ops,
230 domid_t dom)
231 {
232 privcmd_hypercall_t hypercall;
233 long ret = -EINVAL;
235 hypercall.op = __HYPERVISOR_mmuext_op;
236 hypercall.arg[0] = (unsigned long)op;
237 hypercall.arg[1] = (unsigned long)nr_ops;
238 hypercall.arg[2] = (unsigned long)0;
239 hypercall.arg[3] = (unsigned long)dom;
241 if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
242 {
243 PERROR("Could not lock memory for Xen hypercall");
244 goto out1;
245 }
247 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
248 {
249 fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
250 " rebuild the user-space tool set?\n",ret,errno);
251 }
253 safe_munlock(op, nr_ops*sizeof(*op));
255 out1:
256 return ret;
257 }
260 /*
261 * PFN mapping.
262 */
263 int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
264 unsigned long csum_page (void * page);
266 /*
267 * MMU updates.
268 */
269 #define MAX_MMU_UPDATES 1024
270 typedef struct {
271 mmu_update_t updates[MAX_MMU_UPDATES];
272 int idx;
273 domid_t subject;
274 } mmu_t;
275 mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
276 int add_mmu_update(int xc_handle, mmu_t *mmu,
277 unsigned long ptr, unsigned long val);
278 int finish_mmu_updates(int xc_handle, mmu_t *mmu);
281 /*
282 * ioctl-based mfn mapping interface
283 */
285 /*
286 typedef struct privcmd_mmap_entry {
287 unsigned long va;
288 unsigned long mfn;
289 unsigned long npages;
290 } privcmd_mmap_entry_t;
292 typedef struct privcmd_mmap {
293 int num;
294 domid_t dom;
295 privcmd_mmap_entry_t *entry;
296 } privcmd_mmap_t;
297 */
299 #define mfn_mapper_queue_size 128
301 typedef struct mfn_mapper {
302 int xc_handle;
303 int size;
304 int prot;
305 int error;
306 int max_queue_size;
307 void * addr;
308 privcmd_mmap_t ioctl;
310 } mfn_mapper_t;
312 unsigned long xc_get_m2p_start_mfn (int xc_handle);
314 int xc_copy_to_domain_page(int xc_handle, u32 domid,
315 unsigned long dst_pfn, void *src_page);
317 unsigned long xc_get_filesz(int fd);
319 char *xc_read_kernel_image(const char *filename, unsigned long *size);
321 void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
322 int xch, u32 dom, unsigned long *parray,
323 unsigned long vstart);
325 int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
326 domid_t dom);
328 /* image loading */
329 int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs);
330 int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs);
331 int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs);
333 #endif /* __XC_PRIVATE_H__ */