xref: /onnv-gate/usr/src/uts/common/xen/public/vcpu.h (revision 6144:5a5f883be4e5)
15084Sjohnlev /******************************************************************************
25084Sjohnlev  * vcpu.h
35084Sjohnlev  *
45084Sjohnlev  * VCPU initialisation, query, and hotplug.
55084Sjohnlev  *
65084Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
75084Sjohnlev  * of this software and associated documentation files (the "Software"), to
85084Sjohnlev  * deal in the Software without restriction, including without limitation the
95084Sjohnlev  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
105084Sjohnlev  * sell copies of the Software, and to permit persons to whom the Software is
115084Sjohnlev  * furnished to do so, subject to the following conditions:
125084Sjohnlev  *
135084Sjohnlev  * The above copyright notice and this permission notice shall be included in
145084Sjohnlev  * all copies or substantial portions of the Software.
155084Sjohnlev  *
165084Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175084Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185084Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
195084Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
205084Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
215084Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
225084Sjohnlev  * DEALINGS IN THE SOFTWARE.
235084Sjohnlev  *
245084Sjohnlev  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
255084Sjohnlev  */
265084Sjohnlev 
275084Sjohnlev #ifndef __XEN_PUBLIC_VCPU_H__
285084Sjohnlev #define __XEN_PUBLIC_VCPU_H__
295084Sjohnlev 
305084Sjohnlev /*
315084Sjohnlev  * Prototype for this hypercall is:
325084Sjohnlev  *  int vcpu_op(int cmd, int vcpuid, void *extra_args)
335084Sjohnlev  * @cmd        == VCPUOP_??? (VCPU operation).
345084Sjohnlev  * @vcpuid     == VCPU to operate on.
355084Sjohnlev  * @extra_args == Operation-specific extra arguments (NULL if none).
365084Sjohnlev  */
375084Sjohnlev 
385084Sjohnlev /*
395084Sjohnlev  * Initialise a VCPU. Each VCPU can be initialised only once. A
405084Sjohnlev  * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
415084Sjohnlev  *
425084Sjohnlev  * @extra_arg == pointer to vcpu_guest_context structure containing initial
435084Sjohnlev  *               state for the VCPU.
445084Sjohnlev  */
45*6144Srab #define VCPUOP_initialise            0
465084Sjohnlev 
475084Sjohnlev /*
485084Sjohnlev  * Bring up a VCPU. This makes the VCPU runnable. This operation will fail
495084Sjohnlev  * if the VCPU has not been initialised (VCPUOP_initialise).
505084Sjohnlev  */
51*6144Srab #define VCPUOP_up                    1
525084Sjohnlev 
535084Sjohnlev /*
545084Sjohnlev  * Bring down a VCPU (i.e., make it non-runnable).
555084Sjohnlev  * There are a few caveats that callers should observe:
565084Sjohnlev  *  1. This operation may return, and VCPU_is_up may return false, before the
575084Sjohnlev  *     VCPU stops running (i.e., the command is asynchronous). It is a good
585084Sjohnlev  *     idea to ensure that the VCPU has entered a non-critical loop before
595084Sjohnlev  *     bringing it down. Alternatively, this operation is guaranteed
605084Sjohnlev  *     synchronous if invoked by the VCPU itself.
615084Sjohnlev  *  2. After a VCPU is initialised, there is currently no way to drop all its
625084Sjohnlev  *     references to domain memory. Even a VCPU that is down still holds
635084Sjohnlev  *     memory references via its pagetable base pointer and GDT. It is good
645084Sjohnlev  *     practise to move a VCPU onto an 'idle' or default page table, LDT and
655084Sjohnlev  *     GDT before bringing it down.
665084Sjohnlev  */
67*6144Srab #define VCPUOP_down                  2
685084Sjohnlev 
695084Sjohnlev /* Returns 1 if the given VCPU is up. */
70*6144Srab #define VCPUOP_is_up                 3
715084Sjohnlev 
725084Sjohnlev /*
735084Sjohnlev  * Return information about the state and running time of a VCPU.
745084Sjohnlev  * @extra_arg == pointer to vcpu_runstate_info structure.
755084Sjohnlev  */
76*6144Srab #define VCPUOP_get_runstate_info     4
775084Sjohnlev struct vcpu_runstate_info {
785084Sjohnlev     /* VCPU's current state (RUNSTATE_*). */
795084Sjohnlev     int      state;
805084Sjohnlev     /* When was current state entered (system time, ns)? */
815084Sjohnlev     uint64_t state_entry_time;
825084Sjohnlev     /*
835084Sjohnlev      * Time spent in each RUNSTATE_* (ns). The sum of these times is
845084Sjohnlev      * guaranteed not to drift from system time.
855084Sjohnlev      */
865084Sjohnlev     uint64_t time[4];
875084Sjohnlev };
885084Sjohnlev typedef struct vcpu_runstate_info vcpu_runstate_info_t;
895084Sjohnlev DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
905084Sjohnlev 
915084Sjohnlev /* VCPU is currently running on a physical CPU. */
925084Sjohnlev #define RUNSTATE_running  0
935084Sjohnlev 
945084Sjohnlev /* VCPU is runnable, but not currently scheduled on any physical CPU. */
955084Sjohnlev #define RUNSTATE_runnable 1
965084Sjohnlev 
975084Sjohnlev /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
985084Sjohnlev #define RUNSTATE_blocked  2
995084Sjohnlev 
1005084Sjohnlev /*
1015084Sjohnlev  * VCPU is not runnable, but it is not blocked.
1025084Sjohnlev  * This is a 'catch all' state for things like hotplug and pauses by the
1035084Sjohnlev  * system administrator (or for critical sections in the hypervisor).
1045084Sjohnlev  * RUNSTATE_blocked dominates this state (it is the preferred state).
1055084Sjohnlev  */
1065084Sjohnlev #define RUNSTATE_offline  3
1075084Sjohnlev 
1085084Sjohnlev /*
1095084Sjohnlev  * Register a shared memory area from which the guest may obtain its own
1105084Sjohnlev  * runstate information without needing to execute a hypercall.
1115084Sjohnlev  * Notes:
1125084Sjohnlev  *  1. The registered address may be virtual or physical or guest handle,
1135084Sjohnlev  *     depending on the platform. Virtual address or guest handle should be
1145084Sjohnlev  *     registered on x86 systems.
1155084Sjohnlev  *  2. Only one shared area may be registered per VCPU. The shared area is
1165084Sjohnlev  *     updated by the hypervisor each time the VCPU is scheduled. Thus
1175084Sjohnlev  *     runstate.state will always be RUNSTATE_running and
1185084Sjohnlev  *     runstate.state_entry_time will indicate the system time at which the
1195084Sjohnlev  *     VCPU was last scheduled to run.
1205084Sjohnlev  * @extra_arg == pointer to vcpu_register_runstate_memory_area structure.
1215084Sjohnlev  */
1225084Sjohnlev #define VCPUOP_register_runstate_memory_area 5
1235084Sjohnlev struct vcpu_register_runstate_memory_area {
1245084Sjohnlev     union {
1255084Sjohnlev         XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
1265084Sjohnlev         struct vcpu_runstate_info *v;
1275084Sjohnlev         uint64_t p;
1285084Sjohnlev     } addr;
1295084Sjohnlev };
1305084Sjohnlev typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t;
131*6144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t);
132*6144Srab 
133*6144Srab /*
134*6144Srab  * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer
135*6144Srab  * which can be set via these commands. Periods smaller than one millisecond
136*6144Srab  * may not be supported.
137*6144Srab  */
138*6144Srab #define VCPUOP_set_periodic_timer    6 /* arg == vcpu_set_periodic_timer_t */
139*6144Srab #define VCPUOP_stop_periodic_timer   7 /* arg == NULL */
140*6144Srab struct vcpu_set_periodic_timer {
141*6144Srab     uint64_t period_ns;
142*6144Srab };
143*6144Srab typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t;
144*6144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t);
145*6144Srab 
146*6144Srab /*
147*6144Srab  * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot
148*6144Srab  * timer which can be set via these commands.
149*6144Srab  */
150*6144Srab #define VCPUOP_set_singleshot_timer  8 /* arg == vcpu_set_singleshot_timer_t */
151*6144Srab #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */
152*6144Srab struct vcpu_set_singleshot_timer {
153*6144Srab     uint64_t timeout_abs_ns;   /* Absolute system time value in nanoseconds. */
154*6144Srab     uint32_t flags;            /* VCPU_SSHOTTMR_??? */
155*6144Srab };
156*6144Srab typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t;
157*6144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t);
158*6144Srab 
159*6144Srab /* Flags to VCPUOP_set_singleshot_timer. */
160*6144Srab  /* Require the timeout to be in the future (return -ETIME if it's passed). */
161*6144Srab #define _VCPU_SSHOTTMR_future (0)
162*6144Srab #define VCPU_SSHOTTMR_future  (1U << _VCPU_SSHOTTMR_future)
163*6144Srab 
164*6144Srab /*
165*6144Srab  * Register a memory location in the guest address space for the
166*6144Srab  * vcpu_info structure.  This allows the guest to place the vcpu_info
167*6144Srab  * structure in a convenient place, such as in a per-cpu data area.
168*6144Srab  * The pointer need not be page aligned, but the structure must not
169*6144Srab  * cross a page boundary.
170*6144Srab  *
171*6144Srab  * This may be called only once per vcpu.
172*6144Srab  */
173*6144Srab #define VCPUOP_register_vcpu_info   10  /* arg == struct vcpu_info */
174*6144Srab struct vcpu_register_vcpu_info {
175*6144Srab     uint64_t mfn;    /* mfn of page to place vcpu_info */
176*6144Srab     uint32_t offset; /* offset within page */
177*6144Srab     uint32_t rsvd;   /* unused */
178*6144Srab };
179*6144Srab typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t;
180*6144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t);
1815084Sjohnlev 
1825084Sjohnlev #endif /* __XEN_PUBLIC_VCPU_H__ */
1835084Sjohnlev 
1845084Sjohnlev /*
1855084Sjohnlev  * Local variables:
1865084Sjohnlev  * mode: C
1875084Sjohnlev  * c-set-style: "BSD"
1885084Sjohnlev  * c-basic-offset: 4
1895084Sjohnlev  * tab-width: 4
1905084Sjohnlev  * indent-tabs-mode: nil
1915084Sjohnlev  * End:
1925084Sjohnlev  */
193