ia64/xen-unstable

view tools/libxc/xg_private.h @ 17428:b3fdc4c38995

libxc: Leave portability of xg_memalign() as in original patch, rather
than following ioemu/osdep.c. This unbreaks build of readnotes.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 09 16:54:44 2008 +0100 (2008-04-09)
parents f410fa7f379c
children 5b25d3264f7e
line source
1 #ifndef XG_PRIVATE_H
2 #define XG_PRIVATE_H
4 #include <unistd.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <malloc.h>
11 #include <sys/mman.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
15 #include "xenctrl.h"
16 #include "xenguest.h"
17 #include "xc_private.h"
19 #include <xen/memory.h>
20 #include <xen/elfnote.h>
22 #ifndef ELFSIZE
23 #include <limits.h>
24 #if UINT_MAX == ULONG_MAX
25 #define ELFSIZE 32
26 #else
27 #define ELFSIZE 64
28 #endif
29 #endif
31 char *xc_read_image(const char *filename, unsigned long *size);
32 char *xc_inflate_buffer(const char *in_buf,
33 unsigned long in_size,
34 unsigned long *out_size);
36 unsigned long csum_page (void * page);
38 #define _PAGE_PRESENT 0x001
39 #define _PAGE_RW 0x002
40 #define _PAGE_USER 0x004
41 #define _PAGE_PWT 0x008
42 #define _PAGE_PCD 0x010
43 #define _PAGE_ACCESSED 0x020
44 #define _PAGE_DIRTY 0x040
45 #define _PAGE_PAT 0x080
46 #define _PAGE_PSE 0x080
47 #define _PAGE_GLOBAL 0x100
49 #define L1_PAGETABLE_SHIFT_I386 12
50 #define L2_PAGETABLE_SHIFT_I386 22
51 #define L1_PAGETABLE_ENTRIES_I386 1024
52 #define L2_PAGETABLE_ENTRIES_I386 1024
54 #define L1_PAGETABLE_SHIFT_PAE 12
55 #define L2_PAGETABLE_SHIFT_PAE 21
56 #define L3_PAGETABLE_SHIFT_PAE 30
57 #define L1_PAGETABLE_ENTRIES_PAE 512
58 #define L2_PAGETABLE_ENTRIES_PAE 512
59 #define L3_PAGETABLE_ENTRIES_PAE 4
61 #define L1_PAGETABLE_SHIFT_X86_64 12
62 #define L2_PAGETABLE_SHIFT_X86_64 21
63 #define L3_PAGETABLE_SHIFT_X86_64 30
64 #define L4_PAGETABLE_SHIFT_X86_64 39
65 #define L1_PAGETABLE_ENTRIES_X86_64 512
66 #define L2_PAGETABLE_ENTRIES_X86_64 512
67 #define L3_PAGETABLE_ENTRIES_X86_64 512
68 #define L4_PAGETABLE_ENTRIES_X86_64 512
70 #if defined(__i386__)
71 #define L1_PAGETABLE_SHIFT L1_PAGETABLE_SHIFT_I386
72 #define L2_PAGETABLE_SHIFT L2_PAGETABLE_SHIFT_I386
73 #define L1_PAGETABLE_ENTRIES L1_PAGETABLE_ENTRIES_I386
74 #define L2_PAGETABLE_ENTRIES L2_PAGETABLE_ENTRIES_I386
75 #elif defined(__x86_64__)
76 #define L1_PAGETABLE_SHIFT L1_PAGETABLE_SHIFT_X86_64
77 #define L2_PAGETABLE_SHIFT L2_PAGETABLE_SHIFT_X86_64
78 #define L3_PAGETABLE_SHIFT L3_PAGETABLE_SHIFT_X86_64
79 #define L4_PAGETABLE_SHIFT L4_PAGETABLE_SHIFT_X86_64
80 #define L1_PAGETABLE_ENTRIES L1_PAGETABLE_ENTRIES_X86_64
81 #define L2_PAGETABLE_ENTRIES L2_PAGETABLE_ENTRIES_X86_64
82 #define L3_PAGETABLE_ENTRIES L3_PAGETABLE_ENTRIES_X86_64
83 #define L4_PAGETABLE_ENTRIES L4_PAGETABLE_ENTRIES_X86_64
84 #endif
86 typedef uint32_t l1_pgentry_32_t;
87 typedef uint32_t l2_pgentry_32_t;
88 typedef uint64_t l1_pgentry_64_t;
89 typedef uint64_t l2_pgentry_64_t;
90 typedef uint64_t l3_pgentry_64_t;
91 typedef uint64_t l4_pgentry_64_t;
93 #if defined(__i386__)
94 typedef l1_pgentry_32_t l1_pgentry_t;
95 typedef l2_pgentry_32_t l2_pgentry_t;
96 #elif defined(__x86_64__)
97 typedef l1_pgentry_64_t l1_pgentry_t;
98 typedef l2_pgentry_64_t l2_pgentry_t;
99 typedef l3_pgentry_64_t l3_pgentry_t;
100 typedef l4_pgentry_64_t l4_pgentry_t;
101 #endif
103 #define l1_table_offset_i386(_a) \
104 (((_a) >> L1_PAGETABLE_SHIFT_I386) & (L1_PAGETABLE_ENTRIES_I386 - 1))
105 #define l2_table_offset_i386(_a) \
106 (((_a) >> L2_PAGETABLE_SHIFT_I386) & (L2_PAGETABLE_ENTRIES_I386 - 1))
108 #define l1_table_offset_pae(_a) \
109 (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
110 #define l2_table_offset_pae(_a) \
111 (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
112 #define l3_table_offset_pae(_a) \
113 (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
115 #define l1_table_offset_x86_64(_a) \
116 (((_a) >> L1_PAGETABLE_SHIFT_X86_64) & (L1_PAGETABLE_ENTRIES_X86_64 - 1))
117 #define l2_table_offset_x86_64(_a) \
118 (((_a) >> L2_PAGETABLE_SHIFT_X86_64) & (L2_PAGETABLE_ENTRIES_X86_64 - 1))
119 #define l3_table_offset_x86_64(_a) \
120 (((_a) >> L3_PAGETABLE_SHIFT_X86_64) & (L3_PAGETABLE_ENTRIES_X86_64 - 1))
121 #define l4_table_offset_x86_64(_a) \
122 (((_a) >> L4_PAGETABLE_SHIFT_X86_64) & (L4_PAGETABLE_ENTRIES_X86_64 - 1))
124 #if defined(__i386__)
125 #define l1_table_offset(_a) l1_table_offset_i386(_a)
126 #define l2_table_offset(_a) l2_table_offset_i386(_a)
127 #elif defined(__x86_64__)
128 #define l1_table_offset(_a) l1_table_offset_x86_64(_a)
129 #define l2_table_offset(_a) l2_table_offset_x86_64(_a)
130 #define l3_table_offset(_a) l3_table_offset_x86_64(_a)
131 #define l4_table_offset(_a) l4_table_offset_x86_64(_a)
132 #endif
134 #define PAGE_SHIFT_X86 12
135 #define PAGE_SIZE_X86 (1UL << PAGE_SHIFT_X86)
136 #define PAGE_MASK_X86 (~(PAGE_SIZE_X86-1))
138 #define PAGE_SHIFT_IA64 14
139 #define PAGE_SIZE_IA64 (1UL << PAGE_SHIFT_IA64)
140 #define PAGE_MASK_IA64 (~(PAGE_SIZE_IA64-1))
142 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
145 /* XXX SMH: following skanky macros rely on variable p2m_size being set */
146 /* XXX TJD: also, "guest_width" should be the guest's sizeof(unsigned long) */
148 /* Number of xen_pfn_t in a page */
150 #define FPP (PAGE_SIZE/(guest_width))
152 /* Number of entries in the pfn_to_mfn_frame_list_list */
153 #define P2M_FLL_ENTRIES (((p2m_size)+(FPP*FPP)-1)/(FPP*FPP))
155 /* Number of entries in the pfn_to_mfn_frame_list */
156 #define P2M_FL_ENTRIES (((p2m_size)+FPP-1)/FPP)
158 /* Size in bytes of the pfn_to_mfn_frame_list */
159 #define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (guest_width))
160 #define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) * \
161 MAX((sizeof (xen_pfn_t)), guest_width))
163 /* Masks for PTE<->PFN conversions */
164 #define MADDR_BITS_X86 ((guest_width == 8) ? 52 : 44)
165 #define MFN_MASK_X86 ((1ULL << (MADDR_BITS_X86 - PAGE_SHIFT_X86)) - 1)
166 #define MADDR_MASK_X86 (MFN_MASK_X86 << PAGE_SHIFT_X86)
169 #define PAEKERN_no 0
170 #define PAEKERN_yes 1
171 #define PAEKERN_extended_cr3 2
172 #define PAEKERN_bimodal 3
174 int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
175 unsigned long dst_pfn, const char *src_page);
177 int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
178 domid_t dom);
180 /* Grrr portability */
181 static inline void *xg_memalign(size_t alignment, size_t size)
182 {
183 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600
184 int ret;
185 void *ptr;
186 ret = posix_memalign(&ptr, alignment, size);
187 if (ret != 0)
188 return NULL;
189 return ptr;
190 #elif defined(_BSD)
191 return valloc(size);
192 #else
193 return memalign(alignment, size);
194 #endif
195 }
197 #endif /* XG_PRIVATE_H */