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