1 1.1 cherry /* 2 1.1 cherry * hvm/save.h 3 1.1 cherry * 4 1.1 cherry * Structure definitions for HVM state that is held by Xen and must 5 1.1 cherry * be saved along with the domain's memory and device-model state. 6 1.1 cherry * 7 1.1 cherry * Copyright (c) 2007 XenSource Ltd. 8 1.1 cherry * 9 1.1 cherry * Permission is hereby granted, free of charge, to any person obtaining a copy 10 1.1 cherry * of this software and associated documentation files (the "Software"), to 11 1.1 cherry * deal in the Software without restriction, including without limitation the 12 1.1 cherry * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 1.1 cherry * sell copies of the Software, and to permit persons to whom the Software is 14 1.1 cherry * furnished to do so, subject to the following conditions: 15 1.1 cherry * 16 1.1 cherry * The above copyright notice and this permission notice shall be included in 17 1.1 cherry * all copies or substantial portions of the Software. 18 1.1 cherry * 19 1.1 cherry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 1.1 cherry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 1.1 cherry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 1.1 cherry * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 1.1 cherry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 1.1 cherry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 1.1 cherry * DEALINGS IN THE SOFTWARE. 26 1.1 cherry */ 27 1.1 cherry 28 1.1 cherry #ifndef __XEN_PUBLIC_HVM_SAVE_H__ 29 1.1 cherry #define __XEN_PUBLIC_HVM_SAVE_H__ 30 1.1 cherry 31 1.1 cherry /* 32 1.1 cherry * Structures in this header *must* have the same layout in 32bit 33 1.1 cherry * and 64bit environments: this means that all fields must be explicitly 34 1.1 cherry * sized types and aligned to their sizes, and the structs must be 35 1.1 cherry * a multiple of eight bytes long. 36 1.1 cherry * 37 1.1 cherry * Only the state necessary for saving and restoring (i.e. fields 38 1.1 cherry * that are analogous to actual hardware state) should go in this file. 39 1.1 cherry * Internal mechanisms should be kept in Xen-private headers. 40 1.1 cherry */ 41 1.1 cherry 42 1.1 cherry #if !defined(__GNUC__) || defined(__STRICT_ANSI__) 43 1.1 cherry #error "Anonymous structs/unions are a GNU extension." 44 1.1 cherry #endif 45 1.1 cherry 46 1.1 cherry /* 47 1.1 cherry * Each entry is preceded by a descriptor giving its type and length 48 1.1 cherry */ 49 1.1 cherry struct hvm_save_descriptor { 50 1.1 cherry uint16_t typecode; /* Used to demux the various types below */ 51 1.1 cherry uint16_t instance; /* Further demux within a type */ 52 1.1 cherry uint32_t length; /* In bytes, *not* including this descriptor */ 53 1.1 cherry }; 54 1.1 cherry 55 1.1 cherry 56 1.1 cherry /* 57 1.1 cherry * Each entry has a datatype associated with it: for example, the CPU state 58 1.1 cherry * is saved as a HVM_SAVE_TYPE(CPU), which has HVM_SAVE_LENGTH(CPU), 59 1.1 cherry * and is identified by a descriptor with typecode HVM_SAVE_CODE(CPU). 60 1.1 cherry * DECLARE_HVM_SAVE_TYPE binds these things together with some type-system 61 1.1 cherry * ugliness. 62 1.1 cherry */ 63 1.1 cherry 64 1.1 cherry #ifdef __XEN__ 65 1.1 cherry # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \ 66 1.1 cherry static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \ 67 1.1 cherry { return _fix(h, size); } \ 68 1.1 cherry struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \ 69 1.1 cherry struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; } 70 1.1 cherry 71 1.1 cherry # include <xen/lib.h> /* BUG() */ 72 1.1 cherry # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \ 73 1.1 cherry static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h, uint32_t size) \ 74 1.1 cherry { BUG(); return -1; } \ 75 1.1 cherry struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \ 76 1.1 cherry struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; } 77 1.1 cherry #else 78 1.1 cherry # define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix) \ 79 1.1 cherry struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];} 80 1.1 cherry 81 1.1 cherry # define DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \ 82 1.1 cherry struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];} 83 1.1 cherry #endif 84 1.1 cherry 85 1.1 cherry #define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t) 86 1.1 cherry #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x))) 87 1.1 cherry #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c)) 88 1.1 cherry 89 1.1 cherry #ifdef __XEN__ 90 1.1 cherry # define HVM_SAVE_TYPE_COMPAT(_x) typeof (((struct __HVM_SAVE_TYPE_COMPAT_##_x *)(0))->t) 91 1.1 cherry # define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x))) 92 1.1 cherry 93 1.1 cherry # define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->cpt)-1) 94 1.1 cherry # define HVM_SAVE_FIX_COMPAT(_x, _dst, _size) __HVM_SAVE_FIX_COMPAT_##_x(_dst, _size) 95 1.1 cherry #endif 96 1.1 cherry 97 1.1 cherry /* 98 1.1 cherry * The series of save records is teminated by a zero-type, zero-length 99 1.1 cherry * descriptor. 100 1.1 cherry */ 101 1.1 cherry 102 1.1 cherry struct hvm_save_end {}; 103 1.1 cherry DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end); 104 1.1 cherry 105 1.1 cherry #if defined(__i386__) || defined(__x86_64__) 106 1.1 cherry #include "../arch-x86/hvm/save.h" 107 1.1 cherry #elif defined(__arm__) || defined(__aarch64__) 108 1.1 cherry #include "../arch-arm/hvm/save.h" 109 1.1 cherry #else 110 1.1 cherry #error "unsupported architecture" 111 1.1 cherry #endif 112 1.1 cherry 113 1.1 cherry #endif /* __XEN_PUBLIC_HVM_SAVE_H__ */ 114