debuggers.hg

view tools/libxc/xc_dom.h @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 5333e6497af6
children 3ffdb094c2c0
line source
1 #include <xen/libelf/libelf.h>
3 #define INVALID_P2M_ENTRY ((xen_pfn_t)-1)
5 /* --- typedefs and structs ---------------------------------------- */
7 typedef uint64_t xen_vaddr_t;
8 typedef uint64_t xen_paddr_t;
10 #define PRIpfn PRI_xen_pfn
12 struct xc_dom_seg {
13 xen_vaddr_t vstart;
14 xen_vaddr_t vend;
15 xen_pfn_t pfn;
16 };
18 struct xc_dom_mem {
19 struct xc_dom_mem *next;
20 void *mmap_ptr;
21 size_t mmap_len;
22 unsigned char memory[0];
23 };
25 struct xc_dom_phys {
26 struct xc_dom_phys *next;
27 void *ptr;
28 xen_pfn_t first;
29 xen_pfn_t count;
30 };
32 struct xc_dom_image {
33 /* files */
34 void *kernel_blob;
35 size_t kernel_size;
36 void *ramdisk_blob;
37 size_t ramdisk_size;
39 /* arguments and parameters */
40 char *cmdline;
41 uint32_t f_requested[XENFEAT_NR_SUBMAPS];
43 /* info from (elf) kernel image */
44 struct elf_dom_parms parms;
45 char *guest_type;
47 /* memory layout */
48 struct xc_dom_seg kernel_seg;
49 struct xc_dom_seg ramdisk_seg;
50 struct xc_dom_seg p2m_seg;
51 struct xc_dom_seg pgtables_seg;
52 struct xc_dom_seg devicetree_seg;
53 xen_pfn_t start_info_pfn;
54 xen_pfn_t console_pfn;
55 xen_pfn_t xenstore_pfn;
56 xen_pfn_t shared_info_pfn;
57 xen_pfn_t bootstack_pfn;
58 xen_vaddr_t virt_alloc_end;
59 xen_vaddr_t bsd_symtab_start;
61 /* initial page tables */
62 unsigned int pgtables;
63 unsigned int pg_l4;
64 unsigned int pg_l3;
65 unsigned int pg_l2;
66 unsigned int pg_l1;
67 unsigned int alloc_bootstack;
68 unsigned int extra_pages;
69 xen_vaddr_t virt_pgtab_end;
71 /* other state info */
72 uint32_t f_active[XENFEAT_NR_SUBMAPS];
73 xen_pfn_t *p2m_host;
74 void *p2m_guest;
76 /* physical memory */
77 xen_pfn_t total_pages;
78 struct xc_dom_phys *phys_pages;
79 int realmodearea_log;
81 /* malloc memory pool */
82 struct xc_dom_mem *memblocks;
84 /* memory footprint stats */
85 size_t alloc_malloc;
86 size_t alloc_mem_map;
87 size_t alloc_file_map;
88 size_t alloc_domU_map;
90 /* misc xen domain config stuff */
91 unsigned long flags;
92 unsigned int console_evtchn;
93 unsigned int xenstore_evtchn;
94 xen_pfn_t shared_info_mfn;
96 int guest_xc;
97 domid_t guest_domid;
98 int8_t vhpt_size_log2; /* for IA64 */
99 int8_t superpages;
100 int shadow_enabled;
102 int xen_version;
103 xen_capabilities_info_t xen_caps;
105 /* kernel loader, arch hooks */
106 struct xc_dom_loader *kernel_loader;
107 void *private_loader;
109 /* kernel loader */
110 struct xc_dom_arch *arch_hooks;
111 /* allocate up to virt_alloc_end */
112 int (*allocate) (struct xc_dom_image * dom, xen_vaddr_t up_to);
113 };
115 /* --- pluggable kernel loader ------------------------------------- */
117 struct xc_dom_loader {
118 char *name;
119 int (*probe) (struct xc_dom_image * dom);
120 int (*parser) (struct xc_dom_image * dom);
121 int (*loader) (struct xc_dom_image * dom);
123 struct xc_dom_loader *next;
124 };
126 #define __init __attribute__ ((constructor))
127 void xc_dom_register_loader(struct xc_dom_loader *loader);
129 /* --- arch specific hooks ----------------------------------------- */
131 struct xc_dom_arch {
132 /* pagetable setup */
133 int (*alloc_magic_pages) (struct xc_dom_image * dom);
134 int (*count_pgtables) (struct xc_dom_image * dom);
135 int (*setup_pgtables) (struct xc_dom_image * dom);
137 /* arch-specific data structs setup */
138 int (*start_info) (struct xc_dom_image * dom);
139 int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
140 int (*vcpu) (struct xc_dom_image * dom, void *vcpu_ctxt);
142 char *guest_type;
143 char *native_protocol;
144 int page_shift;
145 int sizeof_pfn;
147 struct xc_dom_arch *next;
148 };
149 void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
151 #define XC_DOM_PAGE_SHIFT(dom) ((dom)->arch_hooks->page_shift)
152 #define XC_DOM_PAGE_SIZE(dom) (1 << (dom)->arch_hooks->page_shift)
154 /* --- main functions ---------------------------------------------- */
156 struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char *features);
157 void xc_dom_release_phys(struct xc_dom_image *dom);
158 void xc_dom_release(struct xc_dom_image *dom);
159 int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
161 size_t xc_dom_check_gzip(void *blob, size_t ziplen);
162 int xc_dom_do_gunzip(void *src, size_t srclen, void *dst, size_t dstlen);
163 int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
165 int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
166 int xc_dom_ramdisk_file(struct xc_dom_image *dom, const char *filename);
167 int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
168 size_t memsize);
169 int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem,
170 size_t memsize);
172 int xc_dom_parse_image(struct xc_dom_image *dom);
173 struct xc_dom_arch *xc_dom_find_arch_hooks(char *guest_type);
174 int xc_dom_build_image(struct xc_dom_image *dom);
175 int xc_dom_update_guest_p2m(struct xc_dom_image *dom);
177 int xc_dom_boot_xen_init(struct xc_dom_image *dom, int xc, domid_t domid);
178 int xc_dom_boot_mem_init(struct xc_dom_image *dom);
179 void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
180 xen_pfn_t count);
181 int xc_dom_boot_image(struct xc_dom_image *dom);
182 int xc_dom_compat_check(struct xc_dom_image *dom);
184 /* --- debugging bits ---------------------------------------------- */
186 extern FILE *xc_dom_logfile;
188 void xc_dom_loginit(void);
189 int xc_dom_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
190 int xc_dom_panic_func(const char *file, int line, xc_error_code err,
191 const char *fmt, ...)
192 __attribute__ ((format(printf, 4, 5)));
193 #define xc_dom_panic(err, fmt, args...) \
194 xc_dom_panic_func(__FILE__, __LINE__, err, fmt, ## args)
195 #define xc_dom_trace(mark) \
196 xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
198 void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
200 /* --- simple memory pool ------------------------------------------ */
202 void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
203 void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
204 void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
205 const char *filename, size_t * size);
206 char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
208 /* --- alloc memory pool ------------------------------------------- */
210 int xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
211 int xc_dom_alloc_segment(struct xc_dom_image *dom,
212 struct xc_dom_seg *seg, char *name,
213 xen_vaddr_t start, xen_vaddr_t size);
215 /* --- misc bits --------------------------------------------------- */
217 void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
218 xen_pfn_t count);
219 void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
220 void xc_dom_unmap_all(struct xc_dom_image *dom);
222 static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
223 struct xc_dom_seg *seg)
224 {
225 xen_vaddr_t segsize = seg->vend - seg->vstart;
226 unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
227 xen_pfn_t pages = (segsize + page_size - 1) / page_size;
229 return xc_dom_pfn_to_ptr(dom, seg->pfn, pages);
230 }
232 static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
233 xen_vaddr_t vaddr)
234 {
235 unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
236 xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
237 unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
238 void *ptr = xc_dom_pfn_to_ptr(dom, page, 0);
239 return (ptr ? (ptr + offset) : NULL);
240 }
242 static inline int xc_dom_feature_translated(struct xc_dom_image *dom)
243 {
244 return elf_xen_feature_get(XENFEAT_auto_translated_physmap, dom->f_active);
245 }
247 static inline xen_pfn_t xc_dom_p2m_host(struct xc_dom_image *dom, xen_pfn_t pfn)
248 {
249 if (dom->shadow_enabled)
250 return pfn;
251 return dom->p2m_host[pfn];
252 }
254 static inline xen_pfn_t xc_dom_p2m_guest(struct xc_dom_image *dom,
255 xen_pfn_t pfn)
256 {
257 if (xc_dom_feature_translated(dom))
258 return pfn;
259 return dom->p2m_host[pfn];
260 }
262 /* --- arch bits --------------------------------------------------- */
264 int arch_setup_meminit(struct xc_dom_image *dom);
265 int arch_setup_bootearly(struct xc_dom_image *dom);
266 int arch_setup_bootlate(struct xc_dom_image *dom);
268 /*
269 * Local variables:
270 * mode: C
271 * c-set-style: "BSD"
272 * c-basic-offset: 4
273 * tab-width: 4
274 * indent-tabs-mode: nil
275 * End:
276 */