debuggers.hg

view tools/libxc/xc_private.h @ 2624:23bc5e8a9321

bitkeeper revision 1.1159.98.1 (415e7911bLQPew3o_RI5Cm8viw6VCQ)

Remove Xen-specific ioctl from /dev/mem device. Update domain-building
tools to use the correct device file for mapping foreign memory.
author kaf24@freefall.cl.cam.ac.uk
date Sat Oct 02 09:46:57 2004 +0000 (2004-10-02)
parents 11be1dfb262b
children 1e99cd1cb3a3
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>
24 #include <io/domain_controller.h>
26 #include <asm-xen/proc_cmd.h>
29 #define _PAGE_PRESENT 0x001
30 #define _PAGE_RW 0x002
31 #define _PAGE_USER 0x004
32 #define _PAGE_PWT 0x008
33 #define _PAGE_PCD 0x010
34 #define _PAGE_ACCESSED 0x020
35 #define _PAGE_DIRTY 0x040
36 #define _PAGE_PAT 0x080
37 #define _PAGE_PSE 0x080
38 #define _PAGE_GLOBAL 0x100
41 #define L1_PAGETABLE_SHIFT 12
42 #define L2_PAGETABLE_SHIFT 22
44 #define ENTRIES_PER_L1_PAGETABLE 1024
45 #define ENTRIES_PER_L2_PAGETABLE 1024
47 #define PAGE_SHIFT L1_PAGETABLE_SHIFT
48 #define PAGE_SIZE (1UL << PAGE_SHIFT)
49 #define PAGE_MASK (~(PAGE_SIZE-1))
51 typedef unsigned long l1_pgentry_t;
52 typedef unsigned long l2_pgentry_t;
54 #define l1_table_offset(_a) \
55 (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
56 #define l2_table_offset(_a) \
57 ((_a) >> L2_PAGETABLE_SHIFT)
59 #define ERROR(_m, _a...) \
60 fprintf(stderr, "ERROR: " _m "\n" , ## _a )
62 #define PERROR(_m, _a...) \
63 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
64 errno, strerror(errno))
66 static inline int do_privcmd(int xc_handle,
67 unsigned int cmd,
68 unsigned long data)
69 {
70 return ioctl(xc_handle, cmd, data);
71 }
73 static inline int do_xen_hypercall(int xc_handle,
74 privcmd_hypercall_t *hypercall)
75 {
76 return do_privcmd(xc_handle,
77 IOCTL_PRIVCMD_HYPERCALL,
78 (unsigned long)hypercall);
79 }
81 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
82 {
83 int ret = -1;
84 privcmd_hypercall_t hypercall;
86 op->interface_version = DOM0_INTERFACE_VERSION;
88 hypercall.op = __HYPERVISOR_dom0_op;
89 hypercall.arg[0] = (unsigned long)op;
91 if ( mlock(op, sizeof(*op)) != 0 )
92 {
93 PERROR("Could not lock memory for Xen hypercall");
94 goto out1;
95 }
97 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
98 {
99 if ( errno == EACCES )
100 fprintf(stderr, "Dom0 operation failed -- need to"
101 " rebuild the user-space tool set?\n");
102 goto out2;
103 }
105 out2: (void)munlock(op, sizeof(*op));
106 out1: return ret;
107 }
109 static inline int do_dom_mem_op(int xc_handle,
110 unsigned int memop,
111 unsigned int *extent_list,
112 unsigned int nr_extents,
113 unsigned int extent_order,
114 domid_t domid)
115 {
116 privcmd_hypercall_t hypercall;
117 long ret = -EINVAL;
119 hypercall.op = __HYPERVISOR_dom_mem_op;
120 hypercall.arg[0] = (unsigned long)memop;
121 hypercall.arg[1] = (unsigned long)extent_list;
122 hypercall.arg[2] = (unsigned long)nr_extents;
123 hypercall.arg[3] = (unsigned long)extent_order;
124 hypercall.arg[4] = (unsigned long)domid;
126 if ( mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0 )
127 {
128 PERROR("Could not lock memory for Xen hypercall");
129 goto out1;
130 }
132 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
133 {
134 fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
135 " rebuild the user-space tool set?\n",ret,errno);
136 goto out2;
137 }
139 out2: (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
140 out1: return ret;
141 }
144 /*
145 * PFN mapping.
146 */
147 int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
148 unsigned long csum_page (void * page);
150 /*
151 * MMU updates.
152 */
153 #define MAX_MMU_UPDATES 1024
154 typedef struct {
155 mmu_update_t updates[MAX_MMU_UPDATES];
156 int idx;
157 domid_t subject;
158 } mmu_t;
159 mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
160 int add_mmu_update(int xc_handle, mmu_t *mmu,
161 unsigned long ptr, unsigned long val);
162 int finish_mmu_updates(int xc_handle, mmu_t *mmu);
165 /*
166 * ioctl-based mfn mapping interface
167 */
169 /*
170 typedef struct privcmd_mmap_entry {
171 unsigned long va;
172 unsigned long mfn;
173 unsigned long npages;
174 } privcmd_mmap_entry_t;
176 typedef struct privcmd_mmap {
177 int num;
178 domid_t dom;
179 privcmd_mmap_entry_t *entry;
180 } privcmd_mmap_t;
181 */
183 #define mfn_mapper_queue_size 128
185 typedef struct mfn_mapper {
186 int xc_handle;
187 int size;
188 int prot;
189 int error;
190 int max_queue_size;
191 void * addr;
192 privcmd_mmap_t ioctl;
194 } mfn_mapper_t;
196 long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid );
198 #include "xc_io.h"
200 int xc_domain_getfullinfo(int xc_handle,
201 u32 domid,
202 dom0_op_t *op,
203 full_execution_context_t *ctxt );
205 unsigned long xc_get_m2p_start_mfn ( int xc_handle );
207 #endif /* __XC_PRIVATE_H__ */