xref: /titanic_52/usr/src/uts/common/xen/public/vcpu.h (revision dc20a3024900c47dd2ee44b9707e6df38f7d62a5)
1 /******************************************************************************
2  * vcpu.h
3  *
4  * VCPU initialisation, query, and hotplug.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
25  */
26 
27 #ifndef __XEN_PUBLIC_VCPU_H__
28 #define __XEN_PUBLIC_VCPU_H__
29 
30 /*
31  * Prototype for this hypercall is:
32  *  int vcpu_op(int cmd, int vcpuid, void *extra_args)
33  * @cmd        == VCPUOP_??? (VCPU operation).
34  * @vcpuid     == VCPU to operate on.
35  * @extra_args == Operation-specific extra arguments (NULL if none).
36  */
37 
38 /*
39  * Initialise a VCPU. Each VCPU can be initialised only once. A
40  * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
41  *
42  * @extra_arg == pointer to vcpu_guest_context structure containing initial
43  *               state for the VCPU.
44  */
45 #define VCPUOP_initialise           0
46 
47 /*
48  * Bring up a VCPU. This makes the VCPU runnable. This operation will fail
49  * if the VCPU has not been initialised (VCPUOP_initialise).
50  */
51 #define VCPUOP_up                   1
52 
53 /*
54  * Bring down a VCPU (i.e., make it non-runnable).
55  * There are a few caveats that callers should observe:
56  *  1. This operation may return, and VCPU_is_up may return false, before the
57  *     VCPU stops running (i.e., the command is asynchronous). It is a good
58  *     idea to ensure that the VCPU has entered a non-critical loop before
59  *     bringing it down. Alternatively, this operation is guaranteed
60  *     synchronous if invoked by the VCPU itself.
61  *  2. After a VCPU is initialised, there is currently no way to drop all its
62  *     references to domain memory. Even a VCPU that is down still holds
63  *     memory references via its pagetable base pointer and GDT. It is good
64  *     practise to move a VCPU onto an 'idle' or default page table, LDT and
65  *     GDT before bringing it down.
66  */
67 #define VCPUOP_down                 2
68 
69 /* Returns 1 if the given VCPU is up. */
70 #define VCPUOP_is_up                3
71 
72 /*
73  * Return information about the state and running time of a VCPU.
74  * @extra_arg == pointer to vcpu_runstate_info structure.
75  */
76 #define VCPUOP_get_runstate_info    4
77 struct vcpu_runstate_info {
78     /* VCPU's current state (RUNSTATE_*). */
79     int      state;
80     /* When was current state entered (system time, ns)? */
81     uint64_t state_entry_time;
82     /*
83      * Time spent in each RUNSTATE_* (ns). The sum of these times is
84      * guaranteed not to drift from system time.
85      */
86     uint64_t time[4];
87 };
88 typedef struct vcpu_runstate_info vcpu_runstate_info_t;
89 DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
90 
91 /* VCPU is currently running on a physical CPU. */
92 #define RUNSTATE_running  0
93 
94 /* VCPU is runnable, but not currently scheduled on any physical CPU. */
95 #define RUNSTATE_runnable 1
96 
97 /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
98 #define RUNSTATE_blocked  2
99 
100 /*
101  * VCPU is not runnable, but it is not blocked.
102  * This is a 'catch all' state for things like hotplug and pauses by the
103  * system administrator (or for critical sections in the hypervisor).
104  * RUNSTATE_blocked dominates this state (it is the preferred state).
105  */
106 #define RUNSTATE_offline  3
107 
108 /*
109  * Register a shared memory area from which the guest may obtain its own
110  * runstate information without needing to execute a hypercall.
111  * Notes:
112  *  1. The registered address may be virtual or physical or guest handle,
113  *     depending on the platform. Virtual address or guest handle should be
114  *     registered on x86 systems.
115  *  2. Only one shared area may be registered per VCPU. The shared area is
116  *     updated by the hypervisor each time the VCPU is scheduled. Thus
117  *     runstate.state will always be RUNSTATE_running and
118  *     runstate.state_entry_time will indicate the system time at which the
119  *     VCPU was last scheduled to run.
120  * @extra_arg == pointer to vcpu_register_runstate_memory_area structure.
121  */
122 #define VCPUOP_register_runstate_memory_area 5
123 struct vcpu_register_runstate_memory_area {
124     union {
125         XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
126         struct vcpu_runstate_info *v;
127         uint64_t p;
128     } addr;
129 };
130 typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t;
131 
132 #endif /* __XEN_PUBLIC_VCPU_H__ */
133 
134 /*
135  * Local variables:
136  * mode: C
137  * c-set-style: "BSD"
138  * c-basic-offset: 4
139  * tab-width: 4
140  * indent-tabs-mode: nil
141  * End:
142  */
143