ia64/xen-unstable

changeset 16152:07063bca8a10

Split asm-x86/hvm/support into arch generic part and x86 specific part.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Keir Fraser <keir@xensource.com>
date Thu Oct 18 10:55:26 2007 +0100 (2007-10-18)
parents 46a7c9a15b0f
children a87d94be1172
files xen/include/asm-x86/hvm/support.h xen/include/xen/hvm/save.h
line diff
     1.1 --- a/xen/include/asm-x86/hvm/support.h	Thu Oct 18 10:24:50 2007 +0100
     1.2 +++ b/xen/include/asm-x86/hvm/support.h	Thu Oct 18 10:55:26 2007 +0100
     1.3 @@ -22,6 +22,7 @@
     1.4  #define __ASM_X86_HVM_SUPPORT_H__
     1.5  
     1.6  #include <xen/sched.h>
     1.7 +#include <xen/hvm/save.h>
     1.8  #include <asm/types.h>
     1.9  #include <asm/regs.h>
    1.10  #include <asm/processor.h>
    1.11 @@ -76,144 +77,6 @@ extern unsigned int opt_hvm_debug_level;
    1.12  #define HVM_DBG_LOG(level, _f, _a...)
    1.13  #endif
    1.14  
    1.15 -/*
    1.16 - * Save/restore support 
    1.17 - */
    1.18 -
    1.19 -/* Marshalling and unmarshalling uses a buffer with size and cursor. */
    1.20 -typedef struct hvm_domain_context {
    1.21 -    uint32_t cur;
    1.22 -    uint32_t size;
    1.23 -    uint8_t *data;
    1.24 -} hvm_domain_context_t;
    1.25 -
    1.26 -/* Marshalling an entry: check space and fill in the header */
    1.27 -static inline int _hvm_init_entry(struct hvm_domain_context *h,
    1.28 -                                  uint16_t tc, uint16_t inst, uint32_t len)
    1.29 -{
    1.30 -    struct hvm_save_descriptor *d 
    1.31 -        = (struct hvm_save_descriptor *)&h->data[h->cur];
    1.32 -    if ( h->size - h->cur < len + sizeof (*d) )
    1.33 -    {
    1.34 -        gdprintk(XENLOG_WARNING,
    1.35 -                 "HVM save: no room for %"PRIu32" + %u bytes "
    1.36 -                 "for typecode %"PRIu16"\n",
    1.37 -                 len, (unsigned) sizeof (*d), tc);
    1.38 -        return -1;
    1.39 -    }
    1.40 -    d->typecode = tc;
    1.41 -    d->instance = inst;
    1.42 -    d->length = len;
    1.43 -    h->cur += sizeof (*d);
    1.44 -    return 0;
    1.45 -}
    1.46 -
    1.47 -/* Marshalling: copy the contents in a type-safe way */
    1.48 -#define _hvm_write_entry(_x, _h, _src) do {                     \
    1.49 -    *(HVM_SAVE_TYPE(_x) *)(&(_h)->data[(_h)->cur]) = *(_src);   \
    1.50 -    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
    1.51 -} while (0)
    1.52 -
    1.53 -/* Marshalling: init and copy; evaluates to zero on success */
    1.54 -#define hvm_save_entry(_x, _inst, _h, _src) ({          \
    1.55 -    int r;                                              \
    1.56 -    r = _hvm_init_entry((_h), HVM_SAVE_CODE(_x),        \
    1.57 -                        (_inst), HVM_SAVE_LENGTH(_x));  \
    1.58 -    if ( r == 0 )                                       \
    1.59 -        _hvm_write_entry(_x, (_h), (_src));             \
    1.60 -    r; })
    1.61 -
    1.62 -/* Unmarshalling: test an entry's size and typecode and record the instance */
    1.63 -static inline int _hvm_check_entry(struct hvm_domain_context *h, 
    1.64 -                                   uint16_t type, uint32_t len)
    1.65 -{
    1.66 -    struct hvm_save_descriptor *d 
    1.67 -        = (struct hvm_save_descriptor *)&h->data[h->cur];
    1.68 -    if ( len + sizeof (*d) > h->size - h->cur)
    1.69 -    {
    1.70 -        gdprintk(XENLOG_WARNING, 
    1.71 -                 "HVM restore: not enough data left to read %u bytes "
    1.72 -                 "for type %u\n", len, type);
    1.73 -        return -1;
    1.74 -    }    
    1.75 -    if ( type != d->typecode || len != d->length )
    1.76 -    {
    1.77 -        gdprintk(XENLOG_WARNING, 
    1.78 -                 "HVM restore mismatch: expected type %u length %u, "
    1.79 -                 "saw type %u length %u\n", type, len, d->typecode, d->length);
    1.80 -        return -1;
    1.81 -    }
    1.82 -    h->cur += sizeof (*d);
    1.83 -    return 0;
    1.84 -}
    1.85 -
    1.86 -/* Unmarshalling: copy the contents in a type-safe way */
    1.87 -#define _hvm_read_entry(_x, _h, _dst) do {                      \
    1.88 -    *(_dst) = *(HVM_SAVE_TYPE(_x) *) (&(_h)->data[(_h)->cur]);  \
    1.89 -    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
    1.90 -} while (0)
    1.91 -
    1.92 -/* Unmarshalling: check, then copy. Evaluates to zero on success. */
    1.93 -#define hvm_load_entry(_x, _h, _dst) ({                                 \
    1.94 -    int r;                                                              \
    1.95 -    r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), HVM_SAVE_LENGTH(_x)); \
    1.96 -    if ( r == 0 )                                                       \
    1.97 -        _hvm_read_entry(_x, (_h), (_dst));                              \
    1.98 -    r; })
    1.99 -
   1.100 -/* Unmarshalling: what is the instance ID of the next entry? */
   1.101 -static inline uint16_t hvm_load_instance(struct hvm_domain_context *h)
   1.102 -{
   1.103 -    struct hvm_save_descriptor *d 
   1.104 -        = (struct hvm_save_descriptor *)&h->data[h->cur];
   1.105 -    return d->instance;
   1.106 -}
   1.107 -
   1.108 -/* Handler types for different types of save-file entry. 
   1.109 - * The save handler may save multiple instances of a type into the buffer;
   1.110 - * the load handler will be called once for each instance found when
   1.111 - * restoring.  Both return non-zero on error. */
   1.112 -typedef int (*hvm_save_handler) (struct domain *d, 
   1.113 -                                 hvm_domain_context_t *h);
   1.114 -typedef int (*hvm_load_handler) (struct domain *d,
   1.115 -                                 hvm_domain_context_t *h);
   1.116 -
   1.117 -/* Init-time function to declare a pair of handlers for a type,
   1.118 - * and the maximum buffer space needed to save this type of state */
   1.119 -void hvm_register_savevm(uint16_t typecode,
   1.120 -                         const char *name, 
   1.121 -                         hvm_save_handler save_state,
   1.122 -                         hvm_load_handler load_state,
   1.123 -                         size_t size, int kind);
   1.124 -
   1.125 -/* The space needed for saving can be per-domain or per-vcpu: */
   1.126 -#define HVMSR_PER_DOM  0
   1.127 -#define HVMSR_PER_VCPU 1
   1.128 -
   1.129 -/* Syntactic sugar around that function: specify the max number of
   1.130 - * saves, and this calculates the size of buffer needed */
   1.131 -#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k)             \
   1.132 -static int __hvm_register_##_x##_save_and_restore(void)                   \
   1.133 -{                                                                         \
   1.134 -    hvm_register_savevm(HVM_SAVE_CODE(_x),                                \
   1.135 -                        #_x,                                              \
   1.136 -                        &_save,                                           \
   1.137 -                        &_load,                                           \
   1.138 -                        (_num) * (HVM_SAVE_LENGTH(_x)                     \
   1.139 -                                  + sizeof (struct hvm_save_descriptor)), \
   1.140 -                        _k);                                              \
   1.141 -    return 0;                                                             \
   1.142 -}                                                                         \
   1.143 -__initcall(__hvm_register_##_x##_save_and_restore);
   1.144 -
   1.145 -
   1.146 -/* Entry points for saving and restoring HVM domain state */
   1.147 -size_t hvm_save_size(struct domain *d);
   1.148 -int hvm_save(struct domain *d, hvm_domain_context_t *h);
   1.149 -int hvm_load(struct domain *d, hvm_domain_context_t *h);
   1.150 -
   1.151 -/* End of save/restore */
   1.152 -
   1.153  extern char hvm_io_bitmap[];
   1.154  
   1.155  void hvm_enable(struct hvm_function_table *);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xen/include/xen/hvm/save.h	Thu Oct 18 10:55:26 2007 +0100
     2.3 @@ -0,0 +1,156 @@
     2.4 +/*
     2.5 + * save.h: HVM support routines for save/restore
     2.6 + *
     2.7 + * This program is free software; you can redistribute it and/or modify it
     2.8 + * under the terms and conditions of the GNU General Public License,
     2.9 + * version 2, as published by the Free Software Foundation.
    2.10 + *
    2.11 + * This program is distributed in the hope it will be useful, but WITHOUT
    2.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.13 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
    2.14 + * more details.
    2.15 + *
    2.16 + * You should have received a copy of the GNU General Public License along with
    2.17 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    2.18 + * Place - Suite 330, Boston, MA 02111-1307 USA.
    2.19 + */
    2.20 +
    2.21 +#ifndef __XEN_HVM_SAVE_H__
    2.22 +#define __XEN_HVM_SAVE_H__
    2.23 +
    2.24 +#include <public/hvm/save.h>
    2.25 +#include <asm/types.h>
    2.26 +
    2.27 +/* Marshalling and unmarshalling uses a buffer with size and cursor. */
    2.28 +typedef struct hvm_domain_context {
    2.29 +    uint32_t cur;
    2.30 +    uint32_t size;
    2.31 +    uint8_t *data;
    2.32 +} hvm_domain_context_t;
    2.33 +
    2.34 +/* Marshalling an entry: check space and fill in the header */
    2.35 +static inline int _hvm_init_entry(struct hvm_domain_context *h,
    2.36 +                                  uint16_t tc, uint16_t inst, uint32_t len)
    2.37 +{
    2.38 +    struct hvm_save_descriptor *d 
    2.39 +        = (struct hvm_save_descriptor *)&h->data[h->cur];
    2.40 +    if ( h->size - h->cur < len + sizeof (*d) )
    2.41 +    {
    2.42 +        gdprintk(XENLOG_WARNING,
    2.43 +                 "HVM save: no room for %"PRIu32" + %u bytes "
    2.44 +                 "for typecode %"PRIu16"\n",
    2.45 +                 len, (unsigned) sizeof (*d), tc);
    2.46 +        return -1;
    2.47 +    }
    2.48 +    d->typecode = tc;
    2.49 +    d->instance = inst;
    2.50 +    d->length = len;
    2.51 +    h->cur += sizeof (*d);
    2.52 +    return 0;
    2.53 +}
    2.54 +
    2.55 +/* Marshalling: copy the contents in a type-safe way */
    2.56 +#define _hvm_write_entry(_x, _h, _src) do {                     \
    2.57 +    *(HVM_SAVE_TYPE(_x) *)(&(_h)->data[(_h)->cur]) = *(_src);   \
    2.58 +    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
    2.59 +} while (0)
    2.60 +
    2.61 +/* Marshalling: init and copy; evaluates to zero on success */
    2.62 +#define hvm_save_entry(_x, _inst, _h, _src) ({          \
    2.63 +    int r;                                              \
    2.64 +    r = _hvm_init_entry((_h), HVM_SAVE_CODE(_x),        \
    2.65 +                        (_inst), HVM_SAVE_LENGTH(_x));  \
    2.66 +    if ( r == 0 )                                       \
    2.67 +        _hvm_write_entry(_x, (_h), (_src));             \
    2.68 +    r; })
    2.69 +
    2.70 +/* Unmarshalling: test an entry's size and typecode and record the instance */
    2.71 +static inline int _hvm_check_entry(struct hvm_domain_context *h, 
    2.72 +                                   uint16_t type, uint32_t len)
    2.73 +{
    2.74 +    struct hvm_save_descriptor *d 
    2.75 +        = (struct hvm_save_descriptor *)&h->data[h->cur];
    2.76 +    if ( len + sizeof (*d) > h->size - h->cur)
    2.77 +    {
    2.78 +        gdprintk(XENLOG_WARNING, 
    2.79 +                 "HVM restore: not enough data left to read %u bytes "
    2.80 +                 "for type %u\n", len, type);
    2.81 +        return -1;
    2.82 +    }    
    2.83 +    if ( type != d->typecode || len != d->length )
    2.84 +    {
    2.85 +        gdprintk(XENLOG_WARNING, 
    2.86 +                 "HVM restore mismatch: expected type %u length %u, "
    2.87 +                 "saw type %u length %u\n", type, len, d->typecode, d->length);
    2.88 +        return -1;
    2.89 +    }
    2.90 +    h->cur += sizeof (*d);
    2.91 +    return 0;
    2.92 +}
    2.93 +
    2.94 +/* Unmarshalling: copy the contents in a type-safe way */
    2.95 +#define _hvm_read_entry(_x, _h, _dst) do {                      \
    2.96 +    *(_dst) = *(HVM_SAVE_TYPE(_x) *) (&(_h)->data[(_h)->cur]);  \
    2.97 +    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
    2.98 +} while (0)
    2.99 +
   2.100 +/* Unmarshalling: check, then copy. Evaluates to zero on success. */
   2.101 +#define hvm_load_entry(_x, _h, _dst) ({                                 \
   2.102 +    int r;                                                              \
   2.103 +    r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), HVM_SAVE_LENGTH(_x)); \
   2.104 +    if ( r == 0 )                                                       \
   2.105 +        _hvm_read_entry(_x, (_h), (_dst));                              \
   2.106 +    r; })
   2.107 +
   2.108 +/* Unmarshalling: what is the instance ID of the next entry? */
   2.109 +static inline uint16_t hvm_load_instance(struct hvm_domain_context *h)
   2.110 +{
   2.111 +    struct hvm_save_descriptor *d 
   2.112 +        = (struct hvm_save_descriptor *)&h->data[h->cur];
   2.113 +    return d->instance;
   2.114 +}
   2.115 +
   2.116 +/* Handler types for different types of save-file entry. 
   2.117 + * The save handler may save multiple instances of a type into the buffer;
   2.118 + * the load handler will be called once for each instance found when
   2.119 + * restoring.  Both return non-zero on error. */
   2.120 +typedef int (*hvm_save_handler) (struct domain *d, 
   2.121 +                                 hvm_domain_context_t *h);
   2.122 +typedef int (*hvm_load_handler) (struct domain *d,
   2.123 +                                 hvm_domain_context_t *h);
   2.124 +
   2.125 +/* Init-time function to declare a pair of handlers for a type,
   2.126 + * and the maximum buffer space needed to save this type of state */
   2.127 +void hvm_register_savevm(uint16_t typecode,
   2.128 +                         const char *name, 
   2.129 +                         hvm_save_handler save_state,
   2.130 +                         hvm_load_handler load_state,
   2.131 +                         size_t size, int kind);
   2.132 +
   2.133 +/* The space needed for saving can be per-domain or per-vcpu: */
   2.134 +#define HVMSR_PER_DOM  0
   2.135 +#define HVMSR_PER_VCPU 1
   2.136 +
   2.137 +/* Syntactic sugar around that function: specify the max number of
   2.138 + * saves, and this calculates the size of buffer needed */
   2.139 +#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k)             \
   2.140 +static int __hvm_register_##_x##_save_and_restore(void)                   \
   2.141 +{                                                                         \
   2.142 +    hvm_register_savevm(HVM_SAVE_CODE(_x),                                \
   2.143 +                        #_x,                                              \
   2.144 +                        &_save,                                           \
   2.145 +                        &_load,                                           \
   2.146 +                        (_num) * (HVM_SAVE_LENGTH(_x)                     \
   2.147 +                                  + sizeof (struct hvm_save_descriptor)), \
   2.148 +                        _k);                                              \
   2.149 +    return 0;                                                             \
   2.150 +}                                                                         \
   2.151 +__initcall(__hvm_register_##_x##_save_and_restore);
   2.152 +
   2.153 +
   2.154 +/* Entry points for saving and restoring HVM domain state */
   2.155 +size_t hvm_save_size(struct domain *d);
   2.156 +int hvm_save(struct domain *d, hvm_domain_context_t *h);
   2.157 +int hvm_load(struct domain *d, hvm_domain_context_t *h);
   2.158 +
   2.159 +#endif /* __XEN_HVM_SAVE_H__ */