- Updated to 2.6.22-rc2-git7:
[linux-flexiantxendom0-3.2.10.git] / include / xen / interface / hvm / save.h
1 /* 
2  * hvm/save.h
3  *
4  * Structure definitions for HVM state that is held by Xen and must
5  * be saved along with the domain's memory and device-model state.
6  *
7  * 
8  * Copyright (c) 2007 XenSource Ltd.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to
12  * deal in the Software without restriction, including without limitation the
13  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14  * sell copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  */
28
29 #ifndef __XEN_PUBLIC_HVM_SAVE_H__
30 #define __XEN_PUBLIC_HVM_SAVE_H__
31
32 /*
33  * Structures in this header *must* have the same layout in 32bit 
34  * and 64bit environments: this means that all fields must be explicitly 
35  * sized types and aligned to their sizes.
36  *
37  * Only the state necessary for saving and restoring (i.e. fields 
38  * that are analogous to actual hardware state) should go in this file. 
39  * Internal mechanisms should be kept in Xen-private headers.
40  */
41
42 /* 
43  * Each entry is preceded by a descriptor giving its type and length
44  */
45 struct hvm_save_descriptor {
46     uint16_t typecode;          /* Used to demux the various types below */
47     uint16_t instance;          /* Further demux within a type */
48     uint32_t length;            /* In bytes, *not* including this descriptor */
49 };
50
51
52 /* 
53  * Each entry has a datatype associated with it: for example, the CPU state 
54  * is saved as a HVM_SAVE_TYPE(CPU), which has HVM_SAVE_LENGTH(CPU), 
55  * and is identified by a descriptor with typecode HVM_SAVE_CODE(CPU).
56  * DECLARE_HVM_SAVE_TYPE binds these things together with some type-system
57  * ugliness.
58  */
59
60 #define DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                   \
61   struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; }
62
63 #define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)
64 #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x)))
65 #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c))
66
67
68 /* 
69  * Save/restore header: general info about the save file. 
70  */
71
72 #define HVM_FILE_MAGIC   0x54381286
73 #define HVM_FILE_VERSION 0x00000001
74
75 struct hvm_save_header {
76     uint32_t magic;             /* Must be HVM_FILE_MAGIC */
77     uint32_t version;           /* File format version */
78     uint64_t changeset;         /* Version of Xen that saved this file */
79     uint32_t cpuid;             /* CPUID[0x01][%eax] on the saving machine */
80 };
81
82 DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
83
84
85 /*
86  * Processor
87  */
88
89 struct hvm_hw_cpu {
90     uint8_t  fpu_regs[512];
91
92     uint64_t rax;
93     uint64_t rbx;
94     uint64_t rcx;
95     uint64_t rdx;
96     uint64_t rbp;
97     uint64_t rsi;
98     uint64_t rdi;
99     uint64_t rsp;
100     uint64_t r8;
101     uint64_t r9;
102     uint64_t r10;
103     uint64_t r11;
104     uint64_t r12;
105     uint64_t r13;
106     uint64_t r14;
107     uint64_t r15;
108
109     uint64_t rip;
110     uint64_t rflags;
111
112     uint64_t cr0;
113     uint64_t cr2;
114     uint64_t cr3;
115     uint64_t cr4;
116
117     uint64_t dr0;
118     uint64_t dr1;
119     uint64_t dr2;
120     uint64_t dr3;
121     uint64_t dr6;
122     uint64_t dr7;    
123
124     uint32_t cs_sel;
125     uint32_t ds_sel;
126     uint32_t es_sel;
127     uint32_t fs_sel;
128     uint32_t gs_sel;
129     uint32_t ss_sel;
130     uint32_t tr_sel;
131     uint32_t ldtr_sel;
132
133     uint32_t cs_limit;
134     uint32_t ds_limit;
135     uint32_t es_limit;
136     uint32_t fs_limit;
137     uint32_t gs_limit;
138     uint32_t ss_limit;
139     uint32_t tr_limit;
140     uint32_t ldtr_limit;
141     uint32_t idtr_limit;
142     uint32_t gdtr_limit;
143
144     uint64_t cs_base;
145     uint64_t ds_base;
146     uint64_t es_base;
147     uint64_t fs_base;
148     uint64_t gs_base;
149     uint64_t ss_base;
150     uint64_t tr_base;
151     uint64_t ldtr_base;
152     uint64_t idtr_base;
153     uint64_t gdtr_base;
154
155     uint32_t cs_arbytes;
156     uint32_t ds_arbytes;
157     uint32_t es_arbytes;
158     uint32_t fs_arbytes;
159     uint32_t gs_arbytes;
160     uint32_t ss_arbytes;
161     uint32_t tr_arbytes;
162     uint32_t ldtr_arbytes;
163
164     uint32_t sysenter_cs;
165     uint32_t padding0;
166
167     uint64_t sysenter_esp;
168     uint64_t sysenter_eip;
169
170     /* msr for em64t */
171     uint64_t shadow_gs;
172
173     /* msr content saved/restored. */
174     uint64_t msr_flags;
175     uint64_t msr_lstar;
176     uint64_t msr_star;
177     uint64_t msr_cstar;
178     uint64_t msr_syscall_mask;
179     uint64_t msr_efer;
180
181     /* guest's idea of what rdtsc() would return */
182     uint64_t tsc;
183 };
184
185 DECLARE_HVM_SAVE_TYPE(CPU, 2, struct hvm_hw_cpu);
186
187
188 /*
189  * PIC
190  */
191
192 struct hvm_hw_vpic {
193     /* IR line bitmasks. */
194     uint8_t irr;
195     uint8_t imr;
196     uint8_t isr;
197
198     /* Line IRx maps to IRQ irq_base+x */
199     uint8_t irq_base;
200
201     /*
202      * Where are we in ICW2-4 initialisation (0 means no init in progress)?
203      * Bits 0-1 (=x): Next write at A=1 sets ICW(x+1).
204      * Bit 2: ICW1.IC4  (1 == ICW4 included in init sequence)
205      * Bit 3: ICW1.SNGL (0 == ICW3 included in init sequence)
206      */
207     uint8_t init_state:4;
208
209     /* IR line with highest priority. */
210     uint8_t priority_add:4;
211
212     /* Reads from A=0 obtain ISR or IRR? */
213     uint8_t readsel_isr:1;
214
215     /* Reads perform a polling read? */
216     uint8_t poll:1;
217
218     /* Automatically clear IRQs from the ISR during INTA? */
219     uint8_t auto_eoi:1;
220
221     /* Automatically rotate IRQ priorities during AEOI? */
222     uint8_t rotate_on_auto_eoi:1;
223
224     /* Exclude slave inputs when considering in-service IRQs? */
225     uint8_t special_fully_nested_mode:1;
226
227     /* Special mask mode excludes masked IRs from AEOI and priority checks. */
228     uint8_t special_mask_mode:1;
229
230     /* Is this a master PIC or slave PIC? (NB. This is not programmable.) */
231     uint8_t is_master:1;
232
233     /* Edge/trigger selection. */
234     uint8_t elcr;
235
236     /* Virtual INT output. */
237     uint8_t int_output;
238 };
239
240 DECLARE_HVM_SAVE_TYPE(PIC, 3, struct hvm_hw_vpic);
241
242
243 /*
244  * IO-APIC
245  */
246
247 #ifdef __ia64__
248 #define VIOAPIC_IS_IOSAPIC 1
249 #define VIOAPIC_NUM_PINS  24
250 #else
251 #define VIOAPIC_NUM_PINS  48 /* 16 ISA IRQs, 32 non-legacy PCI IRQS. */
252 #endif
253
254 struct hvm_hw_vioapic {
255     uint64_t base_address;
256     uint32_t ioregsel;
257     uint32_t id;
258     union vioapic_redir_entry
259     {
260         uint64_t bits;
261         struct {
262             uint8_t vector;
263             uint8_t delivery_mode:3;
264             uint8_t dest_mode:1;
265             uint8_t delivery_status:1;
266             uint8_t polarity:1;
267             uint8_t remote_irr:1;
268             uint8_t trig_mode:1;
269             uint8_t mask:1;
270             uint8_t reserve:7;
271 #if !VIOAPIC_IS_IOSAPIC
272             uint8_t reserved[4];
273             uint8_t dest_id;
274 #else
275             uint8_t reserved[3];
276             uint16_t dest_id;
277 #endif
278         } fields;
279     } redirtbl[VIOAPIC_NUM_PINS];
280 };
281
282 DECLARE_HVM_SAVE_TYPE(IOAPIC, 4, struct hvm_hw_vioapic);
283
284
285 /*
286  * LAPIC
287  */
288
289 struct hvm_hw_lapic {
290     uint64_t             apic_base_msr;
291     uint32_t             disabled; /* VLAPIC_xx_DISABLED */
292     uint32_t             timer_divisor;
293 };
294
295 DECLARE_HVM_SAVE_TYPE(LAPIC, 5, struct hvm_hw_lapic);
296
297 struct hvm_hw_lapic_regs {
298     /* A 4k page of register state */
299     uint8_t  data[0x400];
300 };
301
302 DECLARE_HVM_SAVE_TYPE(LAPIC_REGS, 6, struct hvm_hw_lapic_regs);
303
304
305 /*
306  * IRQs
307  */
308
309 struct hvm_hw_pci_irqs {
310     /*
311      * Virtual interrupt wires for a single PCI bus.
312      * Indexed by: device*4 + INTx#.
313      */
314     union {
315         DECLARE_BITMAP(i, 32*4);
316         uint64_t pad[2];
317     };
318 };
319
320 DECLARE_HVM_SAVE_TYPE(PCI_IRQ, 7, struct hvm_hw_pci_irqs);
321
322 struct hvm_hw_isa_irqs {
323     /*
324      * Virtual interrupt wires for ISA devices.
325      * Indexed by ISA IRQ (assumes no ISA-device IRQ sharing).
326      */
327     union {
328         DECLARE_BITMAP(i, 16);
329         uint64_t pad[1];
330     };
331 };
332
333 DECLARE_HVM_SAVE_TYPE(ISA_IRQ, 8, struct hvm_hw_isa_irqs);
334
335 struct hvm_hw_pci_link {
336     /*
337      * PCI-ISA interrupt router.
338      * Each PCI <device:INTx#> is 'wire-ORed' into one of four links using
339      * the traditional 'barber's pole' mapping ((device + INTx#) & 3).
340      * The router provides a programmable mapping from each link to a GSI.
341      */
342     uint8_t route[4];
343 };
344
345 DECLARE_HVM_SAVE_TYPE(PCI_LINK, 9, struct hvm_hw_pci_link);
346
347 /* 
348  *  PIT
349  */
350
351 struct hvm_hw_pit {
352     struct hvm_hw_pit_channel {
353         uint32_t count; /* can be 65536 */
354         uint16_t latched_count;
355         uint8_t count_latched;
356         uint8_t status_latched;
357         uint8_t status;
358         uint8_t read_state;
359         uint8_t write_state;
360         uint8_t write_latch;
361         uint8_t rw_mode;
362         uint8_t mode;
363         uint8_t bcd; /* not supported */
364         uint8_t gate; /* timer start */
365     } channels[3];  /* 3 x 16 bytes */
366     uint32_t speaker_data_on;
367 };
368
369 DECLARE_HVM_SAVE_TYPE(PIT, 10, struct hvm_hw_pit);
370
371
372 /* 
373  * RTC
374  */ 
375
376 #define RTC_CMOS_SIZE 14
377 struct hvm_hw_rtc {
378     /* CMOS bytes */
379     uint8_t cmos_data[RTC_CMOS_SIZE];
380     /* Index register for 2-part operations */
381     uint8_t cmos_index;
382 };
383
384 DECLARE_HVM_SAVE_TYPE(RTC, 11, struct hvm_hw_rtc);
385
386
387 /*
388  * HPET
389  */
390
391 #define HPET_TIMER_NUM     3    /* 3 timers supported now */
392 struct hvm_hw_hpet {
393     /* Memory-mapped, software visible registers */
394     uint64_t capability;        /* capabilities */
395     uint64_t res0;              /* reserved */
396     uint64_t config;            /* configuration */
397     uint64_t res1;              /* reserved */
398     uint64_t isr;               /* interrupt status reg */
399     uint64_t res2[25];          /* reserved */
400     uint64_t mc64;              /* main counter */
401     uint64_t res3;              /* reserved */
402     struct {                    /* timers */
403         uint64_t config;        /* configuration/cap */
404         uint64_t cmp;           /* comparator */
405         uint64_t fsb;           /* FSB route, not supported now */
406         uint64_t res4;          /* reserved */
407     } timers[HPET_TIMER_NUM];
408     uint64_t res5[4*(24-HPET_TIMER_NUM)];  /* reserved, up to 0x3ff */
409
410     /* Hidden register state */
411     uint64_t period[HPET_TIMER_NUM]; /* Last value written to comparator */
412 };
413
414 DECLARE_HVM_SAVE_TYPE(HPET, 12, struct hvm_hw_hpet);
415
416
417 /*
418  * PM timer
419  */
420
421 struct hvm_hw_pmtimer {
422     uint32_t tmr_val;   /* PM_TMR_BLK.TMR_VAL: 32bit free-running counter */
423     uint16_t pm1a_sts;  /* PM1a_EVT_BLK.PM1a_STS: status register */
424     uint16_t pm1a_en;   /* PM1a_EVT_BLK.PM1a_EN: enable register */
425 };
426
427 DECLARE_HVM_SAVE_TYPE(PMTIMER, 13, struct hvm_hw_pmtimer);
428
429 /* 
430  * Largest type-code in use
431  */
432 #define HVM_SAVE_CODE_MAX 13
433
434
435 /* 
436  * The series of save records is teminated by a zero-type, zero-length 
437  * descriptor.
438  */
439
440 struct hvm_save_end {};
441 DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);
442
443 #endif /* __XEN_PUBLIC_HVM_SAVE_H__ */