debuggers.hg

view xen/include/xen/hvm/save.h @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 46f8fc57b1a4
line source
1 /*
2 * save.h: HVM support routines for save/restore
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 */
18 #ifndef __XEN_HVM_SAVE_H__
19 #define __XEN_HVM_SAVE_H__
21 #include <public/xen.h>
22 #include <public/hvm/save.h>
23 #include <asm/types.h>
25 /* Marshalling and unmarshalling uses a buffer with size and cursor. */
26 typedef struct hvm_domain_context {
27 uint32_t cur;
28 uint32_t size;
29 uint8_t *data;
30 } hvm_domain_context_t;
32 /* Marshalling an entry: check space and fill in the header */
33 static inline int _hvm_init_entry(struct hvm_domain_context *h,
34 uint16_t tc, uint16_t inst, uint32_t len)
35 {
36 struct hvm_save_descriptor *d
37 = (struct hvm_save_descriptor *)&h->data[h->cur];
38 if ( h->size - h->cur < len + sizeof (*d) )
39 {
40 gdprintk(XENLOG_WARNING,
41 "HVM save: no room for %"PRIu32" + %u bytes "
42 "for typecode %"PRIu16"\n",
43 len, (unsigned) sizeof (*d), tc);
44 return -1;
45 }
46 d->typecode = tc;
47 d->instance = inst;
48 d->length = len;
49 h->cur += sizeof (*d);
50 return 0;
51 }
53 /* Marshalling: copy the contents in a type-safe way */
54 #define _hvm_write_entry(_x, _h, _src) do { \
55 *(HVM_SAVE_TYPE(_x) *)(&(_h)->data[(_h)->cur]) = *(_src); \
56 (_h)->cur += HVM_SAVE_LENGTH(_x); \
57 } while (0)
59 /* Marshalling: init and copy; evaluates to zero on success */
60 #define hvm_save_entry(_x, _inst, _h, _src) ({ \
61 int r; \
62 r = _hvm_init_entry((_h), HVM_SAVE_CODE(_x), \
63 (_inst), HVM_SAVE_LENGTH(_x)); \
64 if ( r == 0 ) \
65 _hvm_write_entry(_x, (_h), (_src)); \
66 r; })
68 /* Unmarshalling: test an entry's size and typecode and record the instance */
69 static inline int _hvm_check_entry(struct hvm_domain_context *h,
70 uint16_t type, uint32_t len)
71 {
72 struct hvm_save_descriptor *d
73 = (struct hvm_save_descriptor *)&h->data[h->cur];
74 if ( len + sizeof (*d) > h->size - h->cur)
75 {
76 gdprintk(XENLOG_WARNING,
77 "HVM restore: not enough data left to read %u bytes "
78 "for type %u\n", len, type);
79 return -1;
80 }
81 if ( type != d->typecode || len != d->length )
82 {
83 gdprintk(XENLOG_WARNING,
84 "HVM restore mismatch: expected type %u length %u, "
85 "saw type %u length %u\n", type, len, d->typecode, d->length);
86 return -1;
87 }
88 h->cur += sizeof (*d);
89 return 0;
90 }
92 /* Unmarshalling: copy the contents in a type-safe way */
93 #define _hvm_read_entry(_x, _h, _dst) do { \
94 *(_dst) = *(HVM_SAVE_TYPE(_x) *) (&(_h)->data[(_h)->cur]); \
95 (_h)->cur += HVM_SAVE_LENGTH(_x); \
96 } while (0)
98 /* Unmarshalling: check, then copy. Evaluates to zero on success. */
99 #define hvm_load_entry(_x, _h, _dst) ({ \
100 int r; \
101 r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), HVM_SAVE_LENGTH(_x)); \
102 if ( r == 0 ) \
103 _hvm_read_entry(_x, (_h), (_dst)); \
104 r; })
106 /* Unmarshalling: what is the instance ID of the next entry? */
107 static inline uint16_t hvm_load_instance(struct hvm_domain_context *h)
108 {
109 struct hvm_save_descriptor *d
110 = (struct hvm_save_descriptor *)&h->data[h->cur];
111 return d->instance;
112 }
114 /* Handler types for different types of save-file entry.
115 * The save handler may save multiple instances of a type into the buffer;
116 * the load handler will be called once for each instance found when
117 * restoring. Both return non-zero on error. */
118 typedef int (*hvm_save_handler) (struct domain *d,
119 hvm_domain_context_t *h);
120 typedef int (*hvm_load_handler) (struct domain *d,
121 hvm_domain_context_t *h);
123 /* Init-time function to declare a pair of handlers for a type,
124 * and the maximum buffer space needed to save this type of state */
125 void hvm_register_savevm(uint16_t typecode,
126 const char *name,
127 hvm_save_handler save_state,
128 hvm_load_handler load_state,
129 size_t size, int kind);
131 /* The space needed for saving can be per-domain or per-vcpu: */
132 #define HVMSR_PER_DOM 0
133 #define HVMSR_PER_VCPU 1
135 /* Syntactic sugar around that function: specify the max number of
136 * saves, and this calculates the size of buffer needed */
137 #define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k) \
138 static int __hvm_register_##_x##_save_and_restore(void) \
139 { \
140 hvm_register_savevm(HVM_SAVE_CODE(_x), \
141 #_x, \
142 &_save, \
143 &_load, \
144 (_num) * (HVM_SAVE_LENGTH(_x) \
145 + sizeof (struct hvm_save_descriptor)), \
146 _k); \
147 return 0; \
148 } \
149 __initcall(__hvm_register_##_x##_save_and_restore);
152 /* Entry points for saving and restoring HVM domain state */
153 size_t hvm_save_size(struct domain *d);
154 int hvm_save(struct domain *d, hvm_domain_context_t *h);
155 int hvm_load(struct domain *d, hvm_domain_context_t *h);
157 /* Arch-specific definitions. */
158 struct hvm_save_header;
159 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr);
160 int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr);
162 #endif /* __XEN_HVM_SAVE_H__ */