ia64/xen-unstable

view tools/libxc/xg_save_restore.h @ 8964:8946b6dcd49e

Fix x86_64 Xen build.

event_callback_cs and failsafe_callback_cs are x86_32 only.

Signed-off-by: Ian Campbell <Ian.Campbell@XenSource.com>
author Ian.Campbell@xensource.com
date Wed Feb 22 17:26:39 2006 +0000 (2006-02-22)
parents 7acd50d945d7
children 74ee53209cca
line source
1 /*
2 ** xg_save_restore.h
3 **
4 ** Defintions and utilities for save / restore.
5 */
7 #include "xc_private.h"
9 #define DEBUG 1
10 #define PROGRESS 0
12 #define ERR(_f, _a...) do { \
13 fprintf(stderr, _f ": %d\n" , ## _a, errno);\
14 fflush(stderr); } \
15 while (0)
17 #if DEBUG
18 #define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
19 #else
20 #define DPRINTF(_f, _a...) ((void)0)
21 #endif
24 #if PROGRESS
25 #define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
26 #else
27 #define PPRINTF(_f, _a...)
28 #endif
31 /*
32 ** We process save/restore/migrate in batches of pages; the below
33 ** determines how many pages we (at maximum) deal with in each batch.
34 */
35 #define MAX_BATCH_SIZE 1024 /* up to 1024 pages (4MB) at a time */
37 /* When pinning page tables at the end of restore, we also use batching. */
38 #define MAX_PIN_BATCH 1024
42 /*
43 ** Determine various platform information required for save/restore, in
44 ** particular:
45 **
46 ** - the maximum MFN on this machine, used to compute the size of
47 ** the M2P table;
48 **
49 ** - the starting virtual address of the the hypervisor; we use this
50 ** to determine which parts of guest address space(s) do and don't
51 ** require canonicalization during save/restore; and
52 **
53 ** - the number of page-table levels for save/ restore. This should
54 ** be a property of the domain, but for the moment we just read it
55 ** from the hypervisor.
56 **
57 ** Returns 1 on success, 0 on failure.
58 */
59 static int get_platform_info(int xc_handle, uint32_t dom,
60 /* OUT */ unsigned long *max_mfn,
61 /* OUT */ unsigned long *hvirt_start,
62 /* OUT */ unsigned int *pt_levels)
64 {
65 xen_capabilities_info_t xen_caps = "";
66 xen_platform_parameters_t xen_params;
68 if (xc_version(xc_handle, XENVER_platform_parameters, &xen_params) != 0)
69 return 0;
71 if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0)
72 return 0;
74 *max_mfn = xc_memory_op(xc_handle, XENMEM_maximum_ram_page, NULL);
76 *hvirt_start = xen_params.virt_start;
78 if (strstr(xen_caps, "xen-3.0-x86_64"))
79 *pt_levels = 4;
80 else if (strstr(xen_caps, "xen-3.0-x86_32p"))
81 *pt_levels = 3;
82 else if (strstr(xen_caps, "xen-3.0-x86_32"))
83 *pt_levels = 2;
84 else
85 return 0;
87 return 1;
88 }
91 /*
92 ** Save/restore deal with the mfn_to_pfn (M2P) and pfn_to_mfn (P2M) tables.
93 ** The M2P simply holds the corresponding PFN, while the top bit of a P2M
94 ** entry tell us whether or not the the PFN is currently mapped.
95 */
97 #define PFN_TO_KB(_pfn) ((_pfn) << (PAGE_SHIFT - 10))
98 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
101 /*
102 ** The M2P is made up of some number of 'chunks' of at least 2MB in size.
103 ** The below definitions and utility function(s) deal with mapping the M2P
104 ** regarldess of the underlying machine memory size or architecture.
105 */
106 #define M2P_SHIFT L2_PAGETABLE_SHIFT_PAE
107 #define M2P_CHUNK_SIZE (1 << M2P_SHIFT)
108 #define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(unsigned long)), M2P_SHIFT)
109 #define M2P_CHUNKS(_m) (M2P_SIZE((_m)) >> M2P_SHIFT)
111 /* Size in bytes of the P2M (rounded up to the nearest PAGE_SIZE bytes) */
112 #define P2M_SIZE ROUNDUP((max_pfn * sizeof(unsigned long)), PAGE_SHIFT)
114 /* Number of unsigned longs in a page */
115 #define ulpp (PAGE_SIZE/sizeof(unsigned long))
117 /* Number of entries in the pfn_to_mfn_frame_list */
118 #define P2M_FL_ENTRIES (((max_pfn)+ulpp-1)/ulpp)
120 /* Size in bytes of the pfn_to_mfn_frame_list */
121 #define P2M_FL_SIZE ((P2M_FL_ENTRIES)*sizeof(unsigned long))
123 /* Number of entries in the pfn_to_mfn_frame_list_list */
124 #define P2M_FLL_ENTRIES (((max_pfn)+(ulpp*ulpp)-1)/(ulpp*ulpp))
126 /* Current guests allow 8MB 'slack' in their P2M */
127 #define NR_SLACK_ENTRIES ((8 * 1024 * 1024) / PAGE_SIZE)
129 /* Is the given PFN within the 'slack' region at the top of the P2M? */
130 #define IS_REAL_PFN(_pfn) ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES)
132 /* Returns TRUE if the PFN is currently mapped */
133 #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
135 #define INVALID_P2M_ENTRY (~0UL)