ia64/xen-unstable
view tools/libxc/xc_private.h @ 4895:24dfd18ea63e
bitkeeper revision 1.1159.258.120 (42848bfe8kMyWWcBA64rq7h7l7AyoA)
Shadow code bug fix (found by Ian) that was breaking refcounts, and subsequently
causing migration problems.
Shadow code bug fix (found by Ian) that was breaking refcounts, and subsequently
causing migration problems.
author | mafetter@fleming.research |
---|---|
date | Fri May 13 11:14:06 2005 +0000 (2005-05-13) |
parents | ac7313eb3788 |
children | 0dc3b8b8c298 |
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
33 #define L1_PAGETABLE_SHIFT 12
34 #define L2_PAGETABLE_SHIFT 22
36 #define ENTRIES_PER_L1_PAGETABLE 1024
37 #define ENTRIES_PER_L2_PAGETABLE 1024
39 #define PAGE_SHIFT L1_PAGETABLE_SHIFT
40 #define PAGE_SIZE (1UL << PAGE_SHIFT)
41 #define PAGE_MASK (~(PAGE_SIZE-1))
43 typedef unsigned long l1_pgentry_t;
44 typedef unsigned long l2_pgentry_t;
46 #define l1_table_offset(_a) \
47 (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
48 #define l2_table_offset(_a) \
49 ((_a) >> L2_PAGETABLE_SHIFT)
51 #define ERROR(_m, _a...) \
52 fprintf(stderr, "ERROR: " _m "\n" , ## _a )
54 #define PERROR(_m, _a...) \
55 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
56 errno, strerror(errno))
58 static inline int do_privcmd(int xc_handle,
59 unsigned int cmd,
60 unsigned long data)
61 {
62 return ioctl(xc_handle, cmd, data);
63 }
65 static inline int do_xen_hypercall(int xc_handle,
66 privcmd_hypercall_t *hypercall)
67 {
68 return do_privcmd(xc_handle,
69 IOCTL_PRIVCMD_HYPERCALL,
70 (unsigned long)hypercall);
71 }
73 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
74 {
75 int ret = -1, retries = 0;
76 privcmd_hypercall_t hypercall;
78 op->interface_version = DOM0_INTERFACE_VERSION;
80 hypercall.op = __HYPERVISOR_dom0_op;
81 hypercall.arg[0] = (unsigned long)op;
83 if ( mlock(op, sizeof(*op)) != 0 )
84 {
85 PERROR("Could not lock memory for Xen hypercall");
86 goto out1;
87 }
89 again:
90 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
91 {
92 if ( (errno == EAGAIN) && (retries++ < 10) )
93 {
94 /*
95 * This was added for memory allocation, where we can get EAGAIN
96 * if memory is unavailable because it is on the scrub list.
97 */
98 sleep(1);
99 goto again;
100 }
101 if ( errno == EACCES )
102 fprintf(stderr, "Dom0 operation failed -- need to"
103 " rebuild the user-space tool set?\n");
104 goto out2;
105 }
107 out2: (void)munlock(op, sizeof(*op));
108 out1: return ret;
109 }
111 static inline int do_dom_mem_op(int xc_handle,
112 unsigned int memop,
113 unsigned int *extent_list,
114 unsigned int nr_extents,
115 unsigned int extent_order,
116 domid_t domid)
117 {
118 privcmd_hypercall_t hypercall;
119 long ret = -EINVAL;
121 hypercall.op = __HYPERVISOR_dom_mem_op;
122 hypercall.arg[0] = (unsigned long)memop;
123 hypercall.arg[1] = (unsigned long)extent_list;
124 hypercall.arg[2] = (unsigned long)nr_extents;
125 hypercall.arg[3] = (unsigned long)extent_order;
126 hypercall.arg[4] = (unsigned long)domid;
128 if ( mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0 )
129 {
130 PERROR("Could not lock memory for Xen hypercall");
131 goto out1;
132 }
134 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
135 {
136 fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
137 " rebuild the user-space tool set?\n",ret,errno);
138 goto out2;
139 }
141 out2: (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
142 out1: return ret;
143 }
146 /*
147 * PFN mapping.
148 */
149 int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
150 unsigned long csum_page (void * page);
152 /*
153 * MMU updates.
154 */
155 #define MAX_MMU_UPDATES 1024
156 typedef struct {
157 mmu_update_t updates[MAX_MMU_UPDATES];
158 int idx;
159 domid_t subject;
160 } mmu_t;
161 mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
162 int add_mmu_update(int xc_handle, mmu_t *mmu,
163 unsigned long ptr, unsigned long val);
164 int finish_mmu_updates(int xc_handle, mmu_t *mmu);
167 /*
168 * ioctl-based mfn mapping interface
169 */
171 /*
172 typedef struct privcmd_mmap_entry {
173 unsigned long va;
174 unsigned long mfn;
175 unsigned long npages;
176 } privcmd_mmap_entry_t;
178 typedef struct privcmd_mmap {
179 int num;
180 domid_t dom;
181 privcmd_mmap_entry_t *entry;
182 } privcmd_mmap_t;
183 */
185 #define mfn_mapper_queue_size 128
187 typedef struct mfn_mapper {
188 int xc_handle;
189 int size;
190 int prot;
191 int error;
192 int max_queue_size;
193 void * addr;
194 privcmd_mmap_t ioctl;
196 } mfn_mapper_t;
198 #include "xc_io.h"
200 unsigned long xc_get_m2p_start_mfn ( int xc_handle );
202 #endif /* __XC_PRIVATE_H__ */