ia64/xen-unstable

view tools/libxc/xc_private.h @ 1820:3d4f8eb89670

bitkeeper revision 1.1106.1.2 (40faa780dekT3E5arFwcbQDu1MbX6g)

Cleaned up Xen's instruction emulator.
author kaf24@scramble.cl.cam.ac.uk
date Sun Jul 18 16:38:24 2004 +0000 (2004-07-18)
parents 7ee821f4caea
children 01ddb3c0f57e dae98734f12e
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 /* from xen/include/hypervisor-ifs */
20 #include <hypervisor-if.h>
21 #include <dom0_ops.h>
22 #include <event_channel.h>
23 #include <sched_ctl.h>
25 #include <asm-xen/proc_cmd.h>
27 /* from xend/lib */
28 #include <domain_controller.h>
30 #define _PAGE_PRESENT 0x001
31 #define _PAGE_RW 0x002
32 #define _PAGE_USER 0x004
33 #define _PAGE_PWT 0x008
34 #define _PAGE_PCD 0x010
35 #define _PAGE_ACCESSED 0x020
36 #define _PAGE_DIRTY 0x040
37 #define _PAGE_PAT 0x080
38 #define _PAGE_PSE 0x080
39 #define _PAGE_GLOBAL 0x100
42 #define L1_PAGETABLE_SHIFT 12
43 #define L2_PAGETABLE_SHIFT 22
45 #define ENTRIES_PER_L1_PAGETABLE 1024
46 #define ENTRIES_PER_L2_PAGETABLE 1024
48 #define PAGE_SHIFT L1_PAGETABLE_SHIFT
49 #define PAGE_SIZE (1UL << PAGE_SHIFT)
50 #define PAGE_MASK (~(PAGE_SIZE-1))
52 typedef unsigned long l1_pgentry_t;
53 typedef unsigned long l2_pgentry_t;
55 #define l1_table_offset(_a) \
56 (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
57 #define l2_table_offset(_a) \
58 ((_a) >> L2_PAGETABLE_SHIFT)
60 #define ERROR(_m, _a...) \
61 fprintf(stderr, "ERROR: " _m "\n" , ## _a )
63 #define PERROR(_m, _a...) \
64 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
65 errno, strerror(errno))
67 static inline int do_privcmd(int xc_handle,
68 unsigned int cmd,
69 unsigned long data)
70 {
71 return ioctl(xc_handle, cmd, data);
72 }
74 static inline int do_xen_hypercall(int xc_handle,
75 privcmd_hypercall_t *hypercall)
76 {
77 return do_privcmd(xc_handle,
78 IOCTL_PRIVCMD_HYPERCALL,
79 (unsigned long)hypercall);
80 }
82 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
83 {
84 int ret = -1;
85 privcmd_hypercall_t hypercall;
87 op->interface_version = DOM0_INTERFACE_VERSION;
89 hypercall.op = __HYPERVISOR_dom0_op;
90 hypercall.arg[0] = (unsigned long)op;
92 if ( mlock(op, sizeof(*op)) != 0 )
93 {
94 PERROR("Could not lock memory for Xen hypercall");
95 goto out1;
96 }
98 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
99 {
100 if ( errno == EACCES )
101 fprintf(stderr, "Dom0 operation failed -- need to"
102 " rebuild the user-space tool set?\n");
103 goto out2;
104 }
106 out2: (void)munlock(op, sizeof(*op));
107 out1: return ret;
108 }
110 static inline int do_multicall_op(int xc_handle,
111 void *call_list, int nr_calls)
112 {
113 int ret = -1;
114 privcmd_hypercall_t hypercall;
116 hypercall.op = __HYPERVISOR_multicall;
117 hypercall.arg[0] = (unsigned long)call_list;
118 hypercall.arg[1] = (unsigned long)nr_calls;
120 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
121 {
122 if ( errno == EACCES )
123 fprintf(stderr, "Dom0 operation failed -- need to"
124 " rebuild the user-space tool set?\n");
125 goto out1;
126 }
128 out1: return ret;
129 }
131 /*
132 * PFN mapping.
133 */
134 void *init_pfn_mapper(domid_t domid);
135 int close_pfn_mapper(void *pm_handle);
136 void *map_pfn_writeable(void *pm_handle, unsigned long pfn);
137 void *map_pfn_readonly(void *pm_handle, unsigned long pfn);
138 void unmap_pfn(void *pm_handle, void *vaddr);
139 int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
140 unsigned long csum_page (void * page);
142 /*
143 * MMU updates.
144 */
145 #define MAX_MMU_UPDATES 1024
146 typedef struct {
147 mmu_update_t updates[MAX_MMU_UPDATES];
148 int idx;
149 domid_t subject;
150 } mmu_t;
151 mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
152 int add_mmu_update(int xc_handle, mmu_t *mmu,
153 unsigned long ptr, unsigned long val);
154 int finish_mmu_updates(int xc_handle, mmu_t *mmu);
157 /*
158 * ioctl-based mfn mapping interface
159 */
161 /*
162 typedef struct privcmd_mmap_entry {
163 unsigned long va;
164 unsigned long mfn;
165 unsigned long npages;
166 } privcmd_mmap_entry_t;
168 typedef struct privcmd_mmap {
169 int num;
170 domid_t dom;
171 privcmd_mmap_entry_t *entry;
172 } privcmd_mmap_t;
173 */
175 #define mfn_mapper_queue_size 128
177 typedef struct mfn_mapper {
178 int xc_handle;
179 int size;
180 int prot;
181 int error;
182 int max_queue_size;
183 void * addr;
184 privcmd_mmap_t ioctl;
186 } mfn_mapper_t;
188 void * mfn_mapper_map_single(int xc_handle, domid_t dom, int size, int prot,
189 unsigned long mfn );
191 void * mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
192 unsigned long *arr, int num );
194 mfn_mapper_t * mfn_mapper_init(int xc_handle, domid_t dom, int size, int prot);
196 void * mfn_mapper_base(mfn_mapper_t *t);
198 void mfn_mapper_close(mfn_mapper_t *t);
200 int mfn_mapper_flush_queue(mfn_mapper_t *t);
202 void * mfn_mapper_queue_entry(mfn_mapper_t *t, int offset,
203 unsigned long mfn, int size );
205 long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid );
207 #include "xc_io.h"
209 int xc_domain_getfullinfo(int xc_handle,
210 u32 domid,
211 dom0_op_t *op,
212 full_execution_context_t *ctxt );
213 #endif /* __XC_PRIVATE_H__ */