Home | History | Annotate | Line # | Download | only in public
      1  1.1  cherry /******************************************************************************
      2  1.1  cherry  * vcpu.h
      3  1.1  cherry  *
      4  1.1  cherry  * VCPU initialisation, query, and hotplug.
      5  1.1  cherry  *
      6  1.1  cherry  * Permission is hereby granted, free of charge, to any person obtaining a copy
      7  1.1  cherry  * of this software and associated documentation files (the "Software"), to
      8  1.1  cherry  * deal in the Software without restriction, including without limitation the
      9  1.1  cherry  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     10  1.1  cherry  * sell copies of the Software, and to permit persons to whom the Software is
     11  1.1  cherry  * furnished to do so, subject to the following conditions:
     12  1.1  cherry  *
     13  1.1  cherry  * The above copyright notice and this permission notice shall be included in
     14  1.1  cherry  * all copies or substantial portions of the Software.
     15  1.1  cherry  *
     16  1.1  cherry  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  cherry  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  cherry  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19  1.1  cherry  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20  1.1  cherry  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     21  1.1  cherry  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     22  1.1  cherry  * DEALINGS IN THE SOFTWARE.
     23  1.1  cherry  *
     24  1.1  cherry  * Copyright (c) 2005, Keir Fraser <keir (at) xensource.com>
     25  1.1  cherry  */
     26  1.1  cherry 
     27  1.1  cherry #ifndef __XEN_PUBLIC_VCPU_H__
     28  1.1  cherry #define __XEN_PUBLIC_VCPU_H__
     29  1.1  cherry 
     30  1.1  cherry #include "xen.h"
     31  1.1  cherry 
     32  1.1  cherry /*
     33  1.1  cherry  * Prototype for this hypercall is:
     34  1.1  cherry  *  long vcpu_op(int cmd, unsigned int vcpuid, void *extra_args)
     35  1.1  cherry  * @cmd        == VCPUOP_??? (VCPU operation).
     36  1.1  cherry  * @vcpuid     == VCPU to operate on.
     37  1.1  cherry  * @extra_args == Operation-specific extra arguments (NULL if none).
     38  1.1  cherry  */
     39  1.1  cherry 
     40  1.1  cherry /*
     41  1.1  cherry  * Initialise a VCPU. Each VCPU can be initialised only once. A
     42  1.1  cherry  * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
     43  1.1  cherry  *
     44  1.1  cherry  * @extra_arg == For PV or ARM guests this is a pointer to a vcpu_guest_context
     45  1.1  cherry  *               structure containing the initial state for the VCPU. For x86
     46  1.1  cherry  *               HVM based guests this is a pointer to a vcpu_hvm_context
     47  1.1  cherry  *               structure.
     48  1.1  cherry  */
     49  1.1  cherry #define VCPUOP_initialise            0
     50  1.1  cherry 
     51  1.1  cherry /*
     52  1.1  cherry  * Bring up a VCPU. This makes the VCPU runnable. This operation will fail
     53  1.1  cherry  * if the VCPU has not been initialised (VCPUOP_initialise).
     54  1.1  cherry  */
     55  1.1  cherry #define VCPUOP_up                    1
     56  1.1  cherry 
     57  1.1  cherry /*
     58  1.1  cherry  * Bring down a VCPU (i.e., make it non-runnable).
     59  1.1  cherry  * There are a few caveats that callers should observe:
     60  1.1  cherry  *  1. This operation may return, and VCPU_is_up may return false, before the
     61  1.1  cherry  *     VCPU stops running (i.e., the command is asynchronous). It is a good
     62  1.1  cherry  *     idea to ensure that the VCPU has entered a non-critical loop before
     63  1.1  cherry  *     bringing it down. Alternatively, this operation is guaranteed
     64  1.1  cherry  *     synchronous if invoked by the VCPU itself.
     65  1.1  cherry  *  2. After a VCPU is initialised, there is currently no way to drop all its
     66  1.1  cherry  *     references to domain memory. Even a VCPU that is down still holds
     67  1.1  cherry  *     memory references via its pagetable base pointer and GDT. It is good
     68  1.1  cherry  *     practise to move a VCPU onto an 'idle' or default page table, LDT and
     69  1.1  cherry  *     GDT before bringing it down.
     70  1.1  cherry  */
     71  1.1  cherry #define VCPUOP_down                  2
     72  1.1  cherry 
     73  1.1  cherry /* Returns 1 if the given VCPU is up. */
     74  1.1  cherry #define VCPUOP_is_up                 3
     75  1.1  cherry 
     76  1.1  cherry /*
     77  1.1  cherry  * Return information about the state and running time of a VCPU.
     78  1.1  cherry  * @extra_arg == pointer to vcpu_runstate_info structure.
     79  1.1  cherry  */
     80  1.1  cherry #define VCPUOP_get_runstate_info     4
     81  1.1  cherry struct vcpu_runstate_info {
     82  1.1  cherry     /* VCPU's current state (RUNSTATE_*). */
     83  1.1  cherry     int      state;
     84  1.1  cherry     /* When was current state entered (system time, ns)? */
     85  1.1  cherry     uint64_t state_entry_time;
     86  1.1  cherry     /*
     87  1.1  cherry      * Update indicator set in state_entry_time:
     88  1.1  cherry      * When activated via VMASST_TYPE_runstate_update_flag, set during
     89  1.1  cherry      * updates in guest memory mapped copy of vcpu_runstate_info.
     90  1.1  cherry      */
     91  1.1  cherry #define XEN_RUNSTATE_UPDATE          (xen_mk_ullong(1) << 63)
     92  1.1  cherry     /*
     93  1.1  cherry      * Time spent in each RUNSTATE_* (ns). The sum of these times is
     94  1.1  cherry      * guaranteed not to drift from system time.
     95  1.1  cherry      */
     96  1.1  cherry     uint64_t time[4];
     97  1.1  cherry };
     98  1.1  cherry typedef struct vcpu_runstate_info vcpu_runstate_info_t;
     99  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
    100  1.1  cherry 
    101  1.1  cherry /* VCPU is currently running on a physical CPU. */
    102  1.1  cherry #define RUNSTATE_running  0
    103  1.1  cherry 
    104  1.1  cherry /* VCPU is runnable, but not currently scheduled on any physical CPU. */
    105  1.1  cherry #define RUNSTATE_runnable 1
    106  1.1  cherry 
    107  1.1  cherry /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
    108  1.1  cherry #define RUNSTATE_blocked  2
    109  1.1  cherry 
    110  1.1  cherry /*
    111  1.1  cherry  * VCPU is not runnable, but it is not blocked.
    112  1.1  cherry  * This is a 'catch all' state for things like hotplug and pauses by the
    113  1.1  cherry  * system administrator (or for critical sections in the hypervisor).
    114  1.1  cherry  * RUNSTATE_blocked dominates this state (it is the preferred state).
    115  1.1  cherry  */
    116  1.1  cherry #define RUNSTATE_offline  3
    117  1.1  cherry 
    118  1.1  cherry /*
    119  1.1  cherry  * Register a shared memory area from which the guest may obtain its own
    120  1.1  cherry  * runstate information without needing to execute a hypercall.
    121  1.1  cherry  * Notes:
    122  1.1  cherry  *  1. The registered address may be virtual or physical or guest handle,
    123  1.1  cherry  *     depending on the platform. Virtual address or guest handle should be
    124  1.1  cherry  *     registered on x86 systems.
    125  1.1  cherry  *  2. Only one shared area may be registered per VCPU. The shared area is
    126  1.1  cherry  *     updated by the hypervisor each time the VCPU is scheduled. Thus
    127  1.1  cherry  *     runstate.state will always be RUNSTATE_running and
    128  1.1  cherry  *     runstate.state_entry_time will indicate the system time at which the
    129  1.1  cherry  *     VCPU was last scheduled to run.
    130  1.1  cherry  * @extra_arg == pointer to vcpu_register_runstate_memory_area structure.
    131  1.1  cherry  */
    132  1.1  cherry #define VCPUOP_register_runstate_memory_area 5
    133  1.1  cherry struct vcpu_register_runstate_memory_area {
    134  1.1  cherry     union {
    135  1.1  cherry         XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
    136  1.1  cherry         struct vcpu_runstate_info *v;
    137  1.1  cherry         uint64_t p;
    138  1.1  cherry     } addr;
    139  1.1  cherry };
    140  1.1  cherry typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t;
    141  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t);
    142  1.1  cherry 
    143  1.1  cherry /*
    144  1.1  cherry  * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer
    145  1.1  cherry  * which can be set via these commands. Periods smaller than one millisecond
    146  1.1  cherry  * may not be supported.
    147  1.1  cherry  */
    148  1.1  cherry #define VCPUOP_set_periodic_timer    6 /* arg == vcpu_set_periodic_timer_t */
    149  1.1  cherry #define VCPUOP_stop_periodic_timer   7 /* arg == NULL */
    150  1.1  cherry struct vcpu_set_periodic_timer {
    151  1.1  cherry     uint64_t period_ns;
    152  1.1  cherry };
    153  1.1  cherry typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t;
    154  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t);
    155  1.1  cherry 
    156  1.1  cherry /*
    157  1.1  cherry  * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot
    158  1.1  cherry  * timer which can be set via these commands.
    159  1.1  cherry  */
    160  1.1  cherry #define VCPUOP_set_singleshot_timer  8 /* arg == vcpu_set_singleshot_timer_t */
    161  1.1  cherry #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */
    162  1.1  cherry struct vcpu_set_singleshot_timer {
    163  1.1  cherry     uint64_t timeout_abs_ns;   /* Absolute system time value in nanoseconds. */
    164  1.1  cherry     uint32_t flags;            /* VCPU_SSHOTTMR_??? */
    165  1.1  cherry };
    166  1.1  cherry typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t;
    167  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t);
    168  1.1  cherry 
    169  1.1  cherry /* Flags to VCPUOP_set_singleshot_timer. */
    170  1.1  cherry  /* Require the timeout to be in the future (return -ETIME if it's passed). */
    171  1.1  cherry #define _VCPU_SSHOTTMR_future (0)
    172  1.1  cherry #define VCPU_SSHOTTMR_future  (1U << _VCPU_SSHOTTMR_future)
    173  1.1  cherry 
    174  1.1  cherry /*
    175  1.1  cherry  * Register a memory location in the guest address space for the
    176  1.1  cherry  * vcpu_info structure.  This allows the guest to place the vcpu_info
    177  1.1  cherry  * structure in a convenient place, such as in a per-cpu data area.
    178  1.1  cherry  * The pointer need not be page aligned, but the structure must not
    179  1.1  cherry  * cross a page boundary.
    180  1.1  cherry  *
    181  1.1  cherry  * This may be called only once per vcpu.
    182  1.1  cherry  */
    183  1.1  cherry #define VCPUOP_register_vcpu_info   10  /* arg == vcpu_register_vcpu_info_t */
    184  1.1  cherry struct vcpu_register_vcpu_info {
    185  1.1  cherry     uint64_t mfn;    /* mfn of page to place vcpu_info */
    186  1.1  cherry     uint32_t offset; /* offset within page */
    187  1.1  cherry     uint32_t rsvd;   /* unused */
    188  1.1  cherry };
    189  1.1  cherry typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t;
    190  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t);
    191  1.1  cherry 
    192  1.1  cherry /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
    193  1.1  cherry #define VCPUOP_send_nmi             11
    194  1.1  cherry 
    195  1.1  cherry /*
    196  1.1  cherry  * Get the physical ID information for a pinned vcpu's underlying physical
    197  1.1  cherry  * processor.  The physical ID informmation is architecture-specific.
    198  1.1  cherry  * On x86: id[31:0]=apic_id, id[63:32]=acpi_id.
    199  1.1  cherry  * This command returns -EINVAL if it is not a valid operation for this VCPU.
    200  1.1  cherry  */
    201  1.1  cherry #define VCPUOP_get_physid           12 /* arg == vcpu_get_physid_t */
    202  1.1  cherry struct vcpu_get_physid {
    203  1.1  cherry     uint64_t phys_id;
    204  1.1  cherry };
    205  1.1  cherry typedef struct vcpu_get_physid vcpu_get_physid_t;
    206  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t);
    207  1.1  cherry #define xen_vcpu_physid_to_x86_apicid(physid) ((uint32_t)(physid))
    208  1.1  cherry #define xen_vcpu_physid_to_x86_acpiid(physid) ((uint32_t)((physid) >> 32))
    209  1.1  cherry 
    210  1.1  cherry /*
    211  1.1  cherry  * Register a memory location to get a secondary copy of the vcpu time
    212  1.1  cherry  * parameters.  The master copy still exists as part of the vcpu shared
    213  1.1  cherry  * memory area, and this secondary copy is updated whenever the master copy
    214  1.1  cherry  * is updated (and using the same versioning scheme for synchronisation).
    215  1.1  cherry  *
    216  1.1  cherry  * The intent is that this copy may be mapped (RO) into userspace so
    217  1.1  cherry  * that usermode can compute system time using the time info and the
    218  1.1  cherry  * tsc.  Usermode will see an array of vcpu_time_info structures, one
    219  1.1  cherry  * for each vcpu, and choose the right one by an existing mechanism
    220  1.1  cherry  * which allows it to get the current vcpu number (such as via a
    221  1.1  cherry  * segment limit).  It can then apply the normal algorithm to compute
    222  1.1  cherry  * system time from the tsc.
    223  1.1  cherry  *
    224  1.1  cherry  * @extra_arg == pointer to vcpu_register_time_info_memory_area structure.
    225  1.1  cherry  */
    226  1.1  cherry #define VCPUOP_register_vcpu_time_memory_area   13
    227  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_time_info_t);
    228  1.1  cherry struct vcpu_register_time_memory_area {
    229  1.1  cherry     union {
    230  1.1  cherry         XEN_GUEST_HANDLE(vcpu_time_info_t) h;
    231  1.1  cherry         struct vcpu_time_info *v;
    232  1.1  cherry         uint64_t p;
    233  1.1  cherry     } addr;
    234  1.1  cherry };
    235  1.1  cherry typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
    236  1.1  cherry DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
    237  1.1  cherry 
    238  1.1  cherry #endif /* __XEN_PUBLIC_VCPU_H__ */
    239  1.1  cherry 
    240  1.1  cherry /*
    241  1.1  cherry  * Local variables:
    242  1.1  cherry  * mode: C
    243  1.1  cherry  * c-file-style: "BSD"
    244  1.1  cherry  * c-basic-offset: 4
    245  1.1  cherry  * tab-width: 4
    246  1.1  cherry  * indent-tabs-mode: nil
    247  1.1  cherry  * End:
    248  1.1  cherry  */
    249