xref: /onnv-gate/usr/src/uts/common/xen/public/vcpu.h (revision 10175:dd9708d1f561)
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  */
456144Srab #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  */
516144Srab #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  */
676144Srab #define VCPUOP_down                  2
685084Sjohnlev 
695084Sjohnlev /* Returns 1 if the given VCPU is up. */
706144Srab #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  */
766144Srab #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;
1316144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t);
1326144Srab 
1336144Srab /*
1346144Srab  * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer
1356144Srab  * which can be set via these commands. Periods smaller than one millisecond
1366144Srab  * may not be supported.
1376144Srab  */
1386144Srab #define VCPUOP_set_periodic_timer    6 /* arg == vcpu_set_periodic_timer_t */
1396144Srab #define VCPUOP_stop_periodic_timer   7 /* arg == NULL */
1406144Srab struct vcpu_set_periodic_timer {
1416144Srab     uint64_t period_ns;
1426144Srab };
1436144Srab typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t;
1446144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t);
1456144Srab 
1466144Srab /*
1476144Srab  * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot
1486144Srab  * timer which can be set via these commands.
1496144Srab  */
1506144Srab #define VCPUOP_set_singleshot_timer  8 /* arg == vcpu_set_singleshot_timer_t */
1516144Srab #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */
1526144Srab struct vcpu_set_singleshot_timer {
1536144Srab     uint64_t timeout_abs_ns;   /* Absolute system time value in nanoseconds. */
1546144Srab     uint32_t flags;            /* VCPU_SSHOTTMR_??? */
1556144Srab };
1566144Srab typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t;
1576144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t);
1586144Srab 
1596144Srab /* Flags to VCPUOP_set_singleshot_timer. */
1606144Srab  /* Require the timeout to be in the future (return -ETIME if it's passed). */
1616144Srab #define _VCPU_SSHOTTMR_future (0)
1626144Srab #define VCPU_SSHOTTMR_future  (1U << _VCPU_SSHOTTMR_future)
1636144Srab 
1646144Srab /*
1656144Srab  * Register a memory location in the guest address space for the
1666144Srab  * vcpu_info structure.  This allows the guest to place the vcpu_info
1676144Srab  * structure in a convenient place, such as in a per-cpu data area.
1686144Srab  * The pointer need not be page aligned, but the structure must not
1696144Srab  * cross a page boundary.
1706144Srab  *
1716144Srab  * This may be called only once per vcpu.
1726144Srab  */
173*10175SStuart.Maybee@Sun.COM #define VCPUOP_register_vcpu_info   10  /* arg == vcpu_register_vcpu_info_t */
1746144Srab struct vcpu_register_vcpu_info {
1756144Srab     uint64_t mfn;    /* mfn of page to place vcpu_info */
1766144Srab     uint32_t offset; /* offset within page */
1776144Srab     uint32_t rsvd;   /* unused */
1786144Srab };
1796144Srab typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t;
1806144Srab DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t);
1815084Sjohnlev 
182*10175SStuart.Maybee@Sun.COM /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
183*10175SStuart.Maybee@Sun.COM #define VCPUOP_send_nmi             11
184*10175SStuart.Maybee@Sun.COM 
185*10175SStuart.Maybee@Sun.COM /*
186*10175SStuart.Maybee@Sun.COM  * Get the physical ID information for a pinned vcpu's underlying physical
187*10175SStuart.Maybee@Sun.COM  * processor.  The physical ID informmation is architecture-specific.
188*10175SStuart.Maybee@Sun.COM  * On x86: id[31:0]=apic_id, id[63:32]=acpi_id, and all values 0xff and
189*10175SStuart.Maybee@Sun.COM  *         greater are reserved.
190*10175SStuart.Maybee@Sun.COM  * This command returns -EINVAL if it is not a valid operation for this VCPU.
191*10175SStuart.Maybee@Sun.COM  */
192*10175SStuart.Maybee@Sun.COM #define VCPUOP_get_physid           12 /* arg == vcpu_get_physid_t */
193*10175SStuart.Maybee@Sun.COM struct vcpu_get_physid {
194*10175SStuart.Maybee@Sun.COM     uint64_t phys_id;
195*10175SStuart.Maybee@Sun.COM };
196*10175SStuart.Maybee@Sun.COM typedef struct vcpu_get_physid vcpu_get_physid_t;
197*10175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t);
198*10175SStuart.Maybee@Sun.COM #define xen_vcpu_physid_to_x86_apicid(physid) \
199*10175SStuart.Maybee@Sun.COM     ((((uint32_t)(physid)) >= 0xff) ? 0xff : ((uint8_t)(physid)))
200*10175SStuart.Maybee@Sun.COM #define xen_vcpu_physid_to_x86_acpiid(physid) \
201*10175SStuart.Maybee@Sun.COM     ((((uint32_t)((physid)>>32)) >= 0xff) ? 0xff : ((uint8_t)((physid)>>32)))
202*10175SStuart.Maybee@Sun.COM 
2035084Sjohnlev #endif /* __XEN_PUBLIC_VCPU_H__ */
2045084Sjohnlev 
2055084Sjohnlev /*
2065084Sjohnlev  * Local variables:
2075084Sjohnlev  * mode: C
2085084Sjohnlev  * c-set-style: "BSD"
2095084Sjohnlev  * c-basic-offset: 4
2105084Sjohnlev  * tab-width: 4
2115084Sjohnlev  * indent-tabs-mode: nil
2125084Sjohnlev  * End:
2135084Sjohnlev  */
214