xref: /freebsd/sys/contrib/xen/sysctl.h (revision 3a9fd8242b35884921dfc4e886f284a75870a536)
1 /******************************************************************************
2  * sysctl.h
3  *
4  * System management operations. For use by node control stack.
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) 2002-2006, K Fraser
25  */
26 
27 #ifndef __XEN_PUBLIC_SYSCTL_H__
28 #define __XEN_PUBLIC_SYSCTL_H__
29 
30 #if !defined(__XEN__) && !defined(__XEN_TOOLS__)
31 #error "sysctl operations are intended for use by node control tools only"
32 #endif
33 
34 #include "xen.h"
35 #include "domctl.h"
36 #include "physdev.h"
37 
38 #define XEN_SYSCTL_INTERFACE_VERSION 0x00000014
39 
40 /*
41  * Read console content from Xen buffer ring.
42  */
43 /* XEN_SYSCTL_readconsole */
44 struct xen_sysctl_readconsole {
45     /* IN: Non-zero -> clear after reading. */
46     uint8_t clear;
47     /* IN: Non-zero -> start index specified by @index field. */
48     uint8_t incremental;
49     uint8_t pad0, pad1;
50     /*
51      * IN:  Start index for consuming from ring buffer (if @incremental);
52      * OUT: End index after consuming from ring buffer.
53      */
54     uint32_t index;
55     /* IN: Virtual address to write console data. */
56     XEN_GUEST_HANDLE_64(char) buffer;
57     /* IN: Size of buffer; OUT: Bytes written to buffer. */
58     uint32_t count;
59 };
60 
61 /* Get trace buffers machine base address */
62 /* XEN_SYSCTL_tbuf_op */
63 struct xen_sysctl_tbuf_op {
64     /* IN variables */
65 #define XEN_SYSCTL_TBUFOP_get_info     0
66 #define XEN_SYSCTL_TBUFOP_set_cpu_mask 1
67 #define XEN_SYSCTL_TBUFOP_set_evt_mask 2
68 #define XEN_SYSCTL_TBUFOP_set_size     3
69 #define XEN_SYSCTL_TBUFOP_enable       4
70 #define XEN_SYSCTL_TBUFOP_disable      5
71     uint32_t cmd;
72     /* IN/OUT variables */
73     struct xenctl_bitmap cpu_mask;
74     uint32_t             evt_mask;
75     /* OUT variables */
76     uint64_aligned_t buffer_mfn;
77     uint32_t size;  /* Also an IN variable! */
78 };
79 
80 /*
81  * Get physical information about the host machine
82  */
83 /* XEN_SYSCTL_physinfo */
84  /* The platform supports HVM guests. */
85 #define _XEN_SYSCTL_PHYSCAP_hvm          0
86 #define XEN_SYSCTL_PHYSCAP_hvm           (1u<<_XEN_SYSCTL_PHYSCAP_hvm)
87  /* The platform supports PV guests. */
88 #define _XEN_SYSCTL_PHYSCAP_pv           1
89 #define XEN_SYSCTL_PHYSCAP_pv            (1u<<_XEN_SYSCTL_PHYSCAP_pv)
90  /* The platform supports direct access to I/O devices with IOMMU. */
91 #define _XEN_SYSCTL_PHYSCAP_directio     2
92 #define XEN_SYSCTL_PHYSCAP_directio  (1u<<_XEN_SYSCTL_PHYSCAP_directio)
93 /* The platform supports Hardware Assisted Paging. */
94 #define _XEN_SYSCTL_PHYSCAP_hap          3
95 #define XEN_SYSCTL_PHYSCAP_hap           (1u<<_XEN_SYSCTL_PHYSCAP_hap)
96 /* The platform supports software paging. */
97 #define _XEN_SYSCTL_PHYSCAP_shadow       4
98 #define XEN_SYSCTL_PHYSCAP_shadow        (1u<<_XEN_SYSCTL_PHYSCAP_shadow)
99 /* The platform supports sharing of HAP page tables with the IOMMU. */
100 #define _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share 5
101 #define XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share  \
102     (1u << _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share)
103 #define XEN_SYSCTL_PHYSCAP_vmtrace       (1u << 6)
104 /* The platform supports vPMU. */
105 #define XEN_SYSCTL_PHYSCAP_vpmu          (1u << 7)
106 
107 /* Xen supports the Grant v1 and/or v2 ABIs. */
108 #define XEN_SYSCTL_PHYSCAP_gnttab_v1     (1u << 8)
109 #define XEN_SYSCTL_PHYSCAP_gnttab_v2     (1u << 9)
110 
111 /* Max XEN_SYSCTL_PHYSCAP_* constant.  Used for ABI checking. */
112 #define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_gnttab_v2
113 
114 struct xen_sysctl_physinfo {
115     uint32_t threads_per_core;
116     uint32_t cores_per_socket;
117     uint32_t nr_cpus;     /* # CPUs currently online */
118     uint32_t max_cpu_id;  /* Largest possible CPU ID on this host */
119     uint32_t nr_nodes;    /* # nodes currently online */
120     uint32_t max_node_id; /* Largest possible node ID on this host */
121     uint32_t cpu_khz;
122     uint32_t capabilities;/* XEN_SYSCTL_PHYSCAP_??? */
123     uint64_aligned_t total_pages;
124     uint64_aligned_t free_pages;
125     uint64_aligned_t scrub_pages;
126     uint64_aligned_t outstanding_pages;
127     uint64_aligned_t max_mfn; /* Largest possible MFN on this host */
128     uint32_t hw_cap[8];
129 };
130 
131 /*
132  * Get the ID of the current scheduler.
133  */
134 /* XEN_SYSCTL_sched_id */
135 struct xen_sysctl_sched_id {
136     /* OUT variable */
137     uint32_t sched_id;
138 };
139 
140 /* Interface for controlling Xen software performance counters. */
141 /* XEN_SYSCTL_perfc_op */
142 /* Sub-operations: */
143 #define XEN_SYSCTL_PERFCOP_reset 1   /* Reset all counters to zero. */
144 #define XEN_SYSCTL_PERFCOP_query 2   /* Get perfctr information. */
145 struct xen_sysctl_perfc_desc {
146     char         name[80];             /* name of perf counter */
147     uint32_t     nr_vals;              /* number of values for this counter */
148 };
149 typedef struct xen_sysctl_perfc_desc xen_sysctl_perfc_desc_t;
150 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_desc_t);
151 typedef uint32_t xen_sysctl_perfc_val_t;
152 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_val_t);
153 
154 struct xen_sysctl_perfc_op {
155     /* IN variables. */
156     uint32_t       cmd;                /*  XEN_SYSCTL_PERFCOP_??? */
157     /* OUT variables. */
158     uint32_t       nr_counters;       /*  number of counters description  */
159     uint32_t       nr_vals;           /*  number of values  */
160     /* counter information (or NULL) */
161     XEN_GUEST_HANDLE_64(xen_sysctl_perfc_desc_t) desc;
162     /* counter values (or NULL) */
163     XEN_GUEST_HANDLE_64(xen_sysctl_perfc_val_t) val;
164 };
165 
166 /* XEN_SYSCTL_getdomaininfolist */
167 struct xen_sysctl_getdomaininfolist {
168     /* IN variables. */
169     domid_t               first_domain;
170     uint32_t              max_domains;
171     XEN_GUEST_HANDLE_64(xen_domctl_getdomaininfo_t) buffer;
172     /* OUT variables. */
173     uint32_t              num_domains;
174 };
175 
176 /* Inject debug keys into Xen. */
177 /* XEN_SYSCTL_debug_keys */
178 struct xen_sysctl_debug_keys {
179     /* IN variables. */
180     XEN_GUEST_HANDLE_64(const_char) keys;
181     uint32_t nr_keys;
182 };
183 
184 /* Get physical CPU information. */
185 /* XEN_SYSCTL_getcpuinfo */
186 struct xen_sysctl_cpuinfo {
187     uint64_aligned_t idletime;
188 };
189 typedef struct xen_sysctl_cpuinfo xen_sysctl_cpuinfo_t;
190 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpuinfo_t);
191 struct xen_sysctl_getcpuinfo {
192     /* IN variables. */
193     uint32_t max_cpus;
194     XEN_GUEST_HANDLE_64(xen_sysctl_cpuinfo_t) info;
195     /* OUT variables. */
196     uint32_t nr_cpus;
197 };
198 
199 /* XEN_SYSCTL_availheap */
200 struct xen_sysctl_availheap {
201     /* IN variables. */
202     uint32_t min_bitwidth;  /* Smallest address width (zero if don't care). */
203     uint32_t max_bitwidth;  /* Largest address width (zero if don't care). */
204     int32_t  node;          /* NUMA node of interest (-1 for all nodes). */
205     /* OUT variables. */
206     uint64_aligned_t avail_bytes;/* Bytes available in the specified region. */
207 };
208 
209 /* XEN_SYSCTL_get_pmstat */
210 struct pm_px_val {
211     uint64_aligned_t freq;        /* Px core frequency */
212     uint64_aligned_t residency;   /* Px residency time */
213     uint64_aligned_t count;       /* Px transition count */
214 };
215 typedef struct pm_px_val pm_px_val_t;
216 DEFINE_XEN_GUEST_HANDLE(pm_px_val_t);
217 
218 struct pm_px_stat {
219     uint8_t total;        /* total Px states */
220     uint8_t usable;       /* usable Px states */
221     uint8_t last;         /* last Px state */
222     uint8_t cur;          /* current Px state */
223     XEN_GUEST_HANDLE_64(uint64) trans_pt;   /* Px transition table */
224     XEN_GUEST_HANDLE_64(pm_px_val_t) pt;
225 };
226 
227 struct pm_cx_stat {
228     uint32_t nr;    /* entry nr in triggers & residencies, including C0 */
229     uint32_t last;  /* last Cx state */
230     uint64_aligned_t idle_time;                 /* idle time from boot */
231     XEN_GUEST_HANDLE_64(uint64) triggers;    /* Cx trigger counts */
232     XEN_GUEST_HANDLE_64(uint64) residencies; /* Cx residencies */
233     uint32_t nr_pc;                          /* entry nr in pc[] */
234     uint32_t nr_cc;                          /* entry nr in cc[] */
235     /*
236      * These two arrays may (and generally will) have unused slots; slots not
237      * having a corresponding hardware register will not be written by the
238      * hypervisor. It is therefore up to the caller to put a suitable sentinel
239      * into all slots before invoking the function.
240      * Indexing is 1-biased (PC1/CC1 being at index 0).
241      */
242     XEN_GUEST_HANDLE_64(uint64) pc;
243     XEN_GUEST_HANDLE_64(uint64) cc;
244 };
245 
246 struct xen_sysctl_get_pmstat {
247 #define PMSTAT_CATEGORY_MASK 0xf0
248 #define PMSTAT_PX            0x10
249 #define PMSTAT_CX            0x20
250 #define PMSTAT_get_max_px    (PMSTAT_PX | 0x1)
251 #define PMSTAT_get_pxstat    (PMSTAT_PX | 0x2)
252 #define PMSTAT_reset_pxstat  (PMSTAT_PX | 0x3)
253 #define PMSTAT_get_max_cx    (PMSTAT_CX | 0x1)
254 #define PMSTAT_get_cxstat    (PMSTAT_CX | 0x2)
255 #define PMSTAT_reset_cxstat  (PMSTAT_CX | 0x3)
256     uint32_t type;
257     uint32_t cpuid;
258     union {
259         struct pm_px_stat getpx;
260         struct pm_cx_stat getcx;
261         /* other struct for tx, etc */
262     } u;
263 };
264 
265 /* XEN_SYSCTL_cpu_hotplug */
266 struct xen_sysctl_cpu_hotplug {
267     /* IN variables */
268     uint32_t cpu;   /* Physical cpu. */
269 
270     /* Single CPU enable/disable. */
271 #define XEN_SYSCTL_CPU_HOTPLUG_ONLINE  0
272 #define XEN_SYSCTL_CPU_HOTPLUG_OFFLINE 1
273 
274     /*
275      * SMT enable/disable.
276      *
277      * These two ops loop over all present CPUs, and either online or offline
278      * every non-primary sibling thread (those with a thread id which is not
279      * 0).  This behaviour is chosen to simplify the implementation.
280      *
281      * They are intended as a shorthand for identifying and feeding the cpu
282      * numbers individually to HOTPLUG_{ON,OFF}LINE.
283      *
284      * These are not expected to be used in conjunction with debugging options
285      * such as `maxcpus=` or when other manual configuration of offline cpus
286      * is in use.
287      */
288 #define XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE  2
289 #define XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE 3
290     uint32_t op;    /* hotplug opcode */
291 };
292 
293 /*
294  * Get/set xen power management, include
295  * 1. cpufreq governors and related parameters
296  */
297 /* XEN_SYSCTL_pm_op */
298 struct xen_userspace {
299     uint32_t scaling_setspeed;
300 };
301 
302 struct xen_ondemand {
303     uint32_t sampling_rate_max;
304     uint32_t sampling_rate_min;
305 
306     uint32_t sampling_rate;
307     uint32_t up_threshold;
308 };
309 
310 /*
311  * cpufreq para name of this structure named
312  * same as sysfs file name of native linux
313  */
314 #define CPUFREQ_NAME_LEN 16
315 struct xen_get_cpufreq_para {
316     /* IN/OUT variable */
317     uint32_t cpu_num;
318     uint32_t freq_num;
319     uint32_t gov_num;
320 
321     /* for all governors */
322     /* OUT variable */
323     XEN_GUEST_HANDLE_64(uint32) affected_cpus;
324     XEN_GUEST_HANDLE_64(uint32) scaling_available_frequencies;
325     XEN_GUEST_HANDLE_64(char)   scaling_available_governors;
326     char scaling_driver[CPUFREQ_NAME_LEN];
327 
328     uint32_t cpuinfo_cur_freq;
329     uint32_t cpuinfo_max_freq;
330     uint32_t cpuinfo_min_freq;
331     uint32_t scaling_cur_freq;
332 
333     char scaling_governor[CPUFREQ_NAME_LEN];
334     uint32_t scaling_max_freq;
335     uint32_t scaling_min_freq;
336 
337     /* for specific governor */
338     union {
339         struct  xen_userspace userspace;
340         struct  xen_ondemand ondemand;
341     } u;
342 
343     int32_t turbo_enabled;
344 };
345 
346 struct xen_set_cpufreq_gov {
347     char scaling_governor[CPUFREQ_NAME_LEN];
348 };
349 
350 struct xen_set_cpufreq_para {
351     #define SCALING_MAX_FREQ           1
352     #define SCALING_MIN_FREQ           2
353     #define SCALING_SETSPEED           3
354     #define SAMPLING_RATE              4
355     #define UP_THRESHOLD               5
356 
357     uint32_t ctrl_type;
358     uint32_t ctrl_value;
359 };
360 
361 struct xen_sysctl_pm_op {
362     #define PM_PARA_CATEGORY_MASK      0xf0
363     #define CPUFREQ_PARA               0x10
364 
365     /* cpufreq command type */
366     #define GET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x01)
367     #define SET_CPUFREQ_GOV            (CPUFREQ_PARA | 0x02)
368     #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
369     #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
370 
371     /* set/reset scheduler power saving option */
372     #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21
373 
374     /*
375      * cpuidle max C-state and max C-sub-state access command:
376      * Set cpuid to 0 for max C-state.
377      * Set cpuid to 1 for max C-sub-state.
378      */
379     #define XEN_SYSCTL_pm_op_get_max_cstate       0x22
380     #define XEN_SYSCTL_pm_op_set_max_cstate       0x23
381 
382     /* set scheduler migration cost value */
383     #define XEN_SYSCTL_pm_op_set_vcpu_migration_delay   0x24
384     #define XEN_SYSCTL_pm_op_get_vcpu_migration_delay   0x25
385 
386     /* enable/disable turbo mode when in dbs governor */
387     #define XEN_SYSCTL_pm_op_enable_turbo               0x26
388     #define XEN_SYSCTL_pm_op_disable_turbo              0x27
389 
390     uint32_t cmd;
391     uint32_t cpuid;
392     union {
393         struct xen_get_cpufreq_para get_para;
394         struct xen_set_cpufreq_gov  set_gov;
395         struct xen_set_cpufreq_para set_para;
396         uint64_aligned_t get_avgfreq;
397         uint32_t                    set_sched_opt_smt;
398 #define XEN_SYSCTL_CX_UNLIMITED 0xffffffff
399         uint32_t                    get_max_cstate;
400         uint32_t                    set_max_cstate;
401     } u;
402 };
403 
404 /* XEN_SYSCTL_page_offline_op */
405 struct xen_sysctl_page_offline_op {
406     /* IN: range of page to be offlined */
407 #define sysctl_page_offline     1
408 #define sysctl_page_online      2
409 #define sysctl_query_page_offline  3
410     uint32_t cmd;
411     uint32_t start;
412     uint32_t end;
413     /* OUT: result of page offline request */
414     /*
415      * bit 0~15: result flags
416      * bit 16~31: owner
417      */
418     XEN_GUEST_HANDLE(uint32) status;
419 };
420 
421 #define PG_OFFLINE_STATUS_MASK    (0xFFUL)
422 
423 /* The result is invalid, i.e. HV does not handle it */
424 #define PG_OFFLINE_INVALID   (0x1UL << 0)
425 
426 #define PG_OFFLINE_OFFLINED  (0x1UL << 1)
427 #define PG_OFFLINE_PENDING   (0x1UL << 2)
428 #define PG_OFFLINE_FAILED    (0x1UL << 3)
429 #define PG_OFFLINE_AGAIN     (0x1UL << 4)
430 
431 #define PG_ONLINE_FAILED     PG_OFFLINE_FAILED
432 #define PG_ONLINE_ONLINED    PG_OFFLINE_OFFLINED
433 
434 #define PG_OFFLINE_STATUS_OFFLINED              (0x1UL << 1)
435 #define PG_OFFLINE_STATUS_ONLINE                (0x1UL << 2)
436 #define PG_OFFLINE_STATUS_OFFLINE_PENDING       (0x1UL << 3)
437 #define PG_OFFLINE_STATUS_BROKEN                (0x1UL << 4)
438 
439 #define PG_OFFLINE_MISC_MASK    (0xFFUL << 4)
440 
441 /* valid when PG_OFFLINE_FAILED or PG_OFFLINE_PENDING */
442 #define PG_OFFLINE_XENPAGE   (0x1UL << 8)
443 #define PG_OFFLINE_DOM0PAGE  (0x1UL << 9)
444 #define PG_OFFLINE_ANONYMOUS (0x1UL << 10)
445 #define PG_OFFLINE_NOT_CONV_RAM   (0x1UL << 11)
446 #define PG_OFFLINE_OWNED     (0x1UL << 12)
447 
448 #define PG_OFFLINE_BROKEN    (0x1UL << 13)
449 #define PG_ONLINE_BROKEN     PG_OFFLINE_BROKEN
450 
451 #define PG_OFFLINE_OWNER_SHIFT 16
452 
453 /* XEN_SYSCTL_lockprof_op */
454 /* Sub-operations: */
455 #define XEN_SYSCTL_LOCKPROF_reset 1   /* Reset all profile data to zero. */
456 #define XEN_SYSCTL_LOCKPROF_query 2   /* Get lock profile information. */
457 /* Record-type: */
458 #define LOCKPROF_TYPE_GLOBAL      0   /* global lock, idx meaningless */
459 #define LOCKPROF_TYPE_PERDOM      1   /* per-domain lock, idx is domid */
460 #define LOCKPROF_TYPE_N           2   /* number of types */
461 struct xen_sysctl_lockprof_data {
462     char     name[40];     /* lock name (may include up to 2 %d specifiers) */
463     int32_t  type;         /* LOCKPROF_TYPE_??? */
464     int32_t  idx;          /* index (e.g. domain id) */
465     uint64_aligned_t lock_cnt;     /* # of locking succeeded */
466     uint64_aligned_t block_cnt;    /* # of wait for lock */
467     uint64_aligned_t lock_time;    /* nsecs lock held */
468     uint64_aligned_t block_time;   /* nsecs waited for lock */
469 };
470 typedef struct xen_sysctl_lockprof_data xen_sysctl_lockprof_data_t;
471 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_lockprof_data_t);
472 struct xen_sysctl_lockprof_op {
473     /* IN variables. */
474     uint32_t       cmd;               /* XEN_SYSCTL_LOCKPROF_??? */
475     uint32_t       max_elem;          /* size of output buffer */
476     /* OUT variables (query only). */
477     uint32_t       nr_elem;           /* number of elements available */
478     uint64_aligned_t time;            /* nsecs of profile measurement */
479     /* profile information (or NULL) */
480     XEN_GUEST_HANDLE_64(xen_sysctl_lockprof_data_t) data;
481 };
482 
483 /* XEN_SYSCTL_cputopoinfo */
484 #define XEN_INVALID_CORE_ID     (~0U)
485 #define XEN_INVALID_SOCKET_ID   (~0U)
486 #define XEN_INVALID_NODE_ID     (~0U)
487 
488 struct xen_sysctl_cputopo {
489     uint32_t core;
490     uint32_t socket;
491     uint32_t node;
492 };
493 typedef struct xen_sysctl_cputopo xen_sysctl_cputopo_t;
494 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopo_t);
495 
496 /*
497  * IN:
498  *  - a NULL 'cputopo' handle is a request for maximun 'num_cpus'.
499  *  - otherwise it's the number of entries in 'cputopo'
500  *
501  * OUT:
502  *  - If 'num_cpus' is less than the number Xen wants to write but the handle
503  *    handle is not a NULL one, partial data gets returned and 'num_cpus' gets
504  *    updated to reflect the intended number.
505  *  - Otherwise, 'num_cpus' shall indicate the number of entries written, which
506  *    may be less than the input value.
507  */
508 struct xen_sysctl_cputopoinfo {
509     uint32_t num_cpus;
510     XEN_GUEST_HANDLE_64(xen_sysctl_cputopo_t) cputopo;
511 };
512 
513 /* XEN_SYSCTL_numainfo */
514 #define XEN_INVALID_MEM_SZ     (~0U)
515 #define XEN_INVALID_NODE_DIST  (~0U)
516 
517 struct xen_sysctl_meminfo {
518     uint64_t memsize;
519     uint64_t memfree;
520 };
521 typedef struct xen_sysctl_meminfo xen_sysctl_meminfo_t;
522 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_meminfo_t);
523 
524 /*
525  * IN:
526  *  - Both 'meminfo' and 'distance' handles being null is a request
527  *    for maximum value of 'num_nodes'.
528  *  - Otherwise it's the number of entries in 'meminfo' and square root
529  *    of number of entries in 'distance' (when corresponding handle is
530  *    non-null)
531  *
532  * OUT:
533  *  - If 'num_nodes' is less than the number Xen wants to write but either
534  *    handle is not a NULL one, partial data gets returned and 'num_nodes'
535  *    gets updated to reflect the intended number.
536  *  - Otherwise, 'num_nodes' shall indicate the number of entries written, which
537  *    may be less than the input value.
538  */
539 
540 struct xen_sysctl_numainfo {
541     uint32_t num_nodes;
542 
543     XEN_GUEST_HANDLE_64(xen_sysctl_meminfo_t) meminfo;
544 
545     /*
546      * Distance between nodes 'i' and 'j' is stored in index 'i*N + j',
547      * where N is the number of nodes that will be returned in 'num_nodes'
548      * (i.e. not 'num_nodes' provided by the caller)
549      */
550     XEN_GUEST_HANDLE_64(uint32) distance;
551 };
552 
553 /* XEN_SYSCTL_cpupool_op */
554 #define XEN_SYSCTL_CPUPOOL_OP_CREATE                1  /* C */
555 #define XEN_SYSCTL_CPUPOOL_OP_DESTROY               2  /* D */
556 #define XEN_SYSCTL_CPUPOOL_OP_INFO                  3  /* I */
557 #define XEN_SYSCTL_CPUPOOL_OP_ADDCPU                4  /* A */
558 #define XEN_SYSCTL_CPUPOOL_OP_RMCPU                 5  /* R */
559 #define XEN_SYSCTL_CPUPOOL_OP_MOVEDOMAIN            6  /* M */
560 #define XEN_SYSCTL_CPUPOOL_OP_FREEINFO              7  /* F */
561 #define XEN_SYSCTL_CPUPOOL_PAR_ANY     0xFFFFFFFF
562 struct xen_sysctl_cpupool_op {
563     uint32_t op;          /* IN */
564     uint32_t cpupool_id;  /* IN: CDIARM OUT: CI */
565     uint32_t sched_id;    /* IN: C      OUT: I  */
566     uint32_t domid;       /* IN: M              */
567     uint32_t cpu;         /* IN: AR             */
568     uint32_t n_dom;       /*            OUT: I  */
569     struct xenctl_bitmap cpumap; /*     OUT: IF */
570 };
571 
572 /*
573  * Error return values of cpupool operations:
574  *
575  * -EADDRINUSE:
576  *  XEN_SYSCTL_CPUPOOL_OP_RMCPU: A vcpu is temporarily pinned to the cpu
577  *    which is to be removed from a cpupool.
578  * -EADDRNOTAVAIL:
579  *  XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: A previous
580  *    request to remove a cpu from a cpupool was terminated with -EAGAIN
581  *    and has not been retried using the same parameters.
582  * -EAGAIN:
583  *  XEN_SYSCTL_CPUPOOL_OP_RMCPU: The cpu can't be removed from the cpupool
584  *    as it is active in the hypervisor. A retry will succeed soon.
585  * -EBUSY:
586  *  XEN_SYSCTL_CPUPOOL_OP_DESTROY, XEN_SYSCTL_CPUPOOL_OP_RMCPU: A cpupool
587  *    can't be destroyed or the last cpu can't be removed as there is still
588  *    a running domain in that cpupool.
589  * -EEXIST:
590  *  XEN_SYSCTL_CPUPOOL_OP_CREATE: A cpupool_id was specified and is already
591  *    existing.
592  * -EINVAL:
593  *  XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: An illegal
594  *    cpu was specified (cpu does not exist).
595  *  XEN_SYSCTL_CPUPOOL_OP_MOVEDOMAIN: An illegal domain was specified
596  *    (domain id illegal or not suitable for operation).
597  * -ENODEV:
598  *  XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: The specified
599  *    cpu is either not free (add) or not member of the specified cpupool
600  *    (remove).
601  * -ENOENT:
602  *  all: The cpupool with the specified cpupool_id doesn't exist.
603  *
604  * Some common error return values like -ENOMEM and -EFAULT are possible for
605  * all the operations.
606  */
607 
608 #define ARINC653_MAX_DOMAINS_PER_SCHEDULE   64
609 /*
610  * This structure is used to pass a new ARINC653 schedule from a
611  * privileged domain (ie dom0) to Xen.
612  */
613 struct xen_sysctl_arinc653_schedule {
614     /* major_frame holds the time for the new schedule's major frame
615      * in nanoseconds. */
616     uint64_aligned_t     major_frame;
617     /* num_sched_entries holds how many of the entries in the
618      * sched_entries[] array are valid. */
619     uint8_t     num_sched_entries;
620     /* The sched_entries array holds the actual schedule entries. */
621     struct {
622         /* dom_handle must match a domain's UUID */
623         xen_domain_handle_t dom_handle;
624         /* If a domain has multiple VCPUs, vcpu_id specifies which one
625          * this schedule entry applies to. It should be set to 0 if
626          * there is only one VCPU for the domain. */
627         unsigned int vcpu_id;
628         /* runtime specifies the amount of time that should be allocated
629          * to this VCPU per major frame. It is specified in nanoseconds */
630         uint64_aligned_t runtime;
631     } sched_entries[ARINC653_MAX_DOMAINS_PER_SCHEDULE];
632 };
633 typedef struct xen_sysctl_arinc653_schedule xen_sysctl_arinc653_schedule_t;
634 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_arinc653_schedule_t);
635 
636 /*
637  * Valid range for context switch rate limit (in microseconds).
638  * Applicable to Credit and Credit2 schedulers.
639  */
640 #define XEN_SYSCTL_SCHED_RATELIMIT_MAX 500000
641 #define XEN_SYSCTL_SCHED_RATELIMIT_MIN 100
642 
643 struct xen_sysctl_credit_schedule {
644     /* Length of timeslice in milliseconds */
645 #define XEN_SYSCTL_CSCHED_TSLICE_MAX 1000
646 #define XEN_SYSCTL_CSCHED_TSLICE_MIN 1
647     unsigned tslice_ms;
648     unsigned ratelimit_us;
649     /*
650      * How long we consider a vCPU to be cache-hot on the
651      * CPU where it has run (max 100ms, in microseconds)
652     */
653 #define XEN_SYSCTL_CSCHED_MGR_DLY_MAX_US (100 * 1000)
654     unsigned vcpu_migr_delay_us;
655 };
656 
657 struct xen_sysctl_credit2_schedule {
658     unsigned ratelimit_us;
659 };
660 
661 /* XEN_SYSCTL_scheduler_op */
662 /* Set or get info? */
663 #define XEN_SYSCTL_SCHEDOP_putinfo 0
664 #define XEN_SYSCTL_SCHEDOP_getinfo 1
665 struct xen_sysctl_scheduler_op {
666     uint32_t cpupool_id; /* Cpupool whose scheduler is to be targetted. */
667     uint32_t sched_id;   /* XEN_SCHEDULER_* (domctl.h) */
668     uint32_t cmd;        /* XEN_SYSCTL_SCHEDOP_* */
669     union {
670         struct xen_sysctl_sched_arinc653 {
671             XEN_GUEST_HANDLE_64(xen_sysctl_arinc653_schedule_t) schedule;
672         } sched_arinc653;
673         struct xen_sysctl_credit_schedule sched_credit;
674         struct xen_sysctl_credit2_schedule sched_credit2;
675     } u;
676 };
677 
678 /*
679  * Output format of gcov data:
680  *
681  * XEN_GCOV_FORMAT_MAGIC XEN_GCOV_RECORD ... XEN_GCOV_RECORD
682  *
683  * That is, one magic number followed by 0 or more record.
684  *
685  * The magic number is stored as an uint32_t field.
686  *
687  * The record is packed and variable in length. It has the form:
688  *
689  *  filename: a NULL terminated path name extracted from gcov, used to
690  *            create the name of gcda file.
691  *  size:     a uint32_t field indicating the size of the payload, the
692  *            unit is byte.
693  *  payload:  the actual payload, length is `size' bytes.
694  *
695  * Userspace tool will split the record to different files.
696  */
697 
698 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */
699 
700 /*
701  * Ouput format of LLVM coverage data is just a raw stream, as would be
702  * written by the compiler_rt run time library into a .profraw file. There
703  * are no special Xen tags or delimiters because none are needed.
704  */
705 
706 #define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */
707 #define XEN_SYSCTL_COVERAGE_read     1 /* Read output data */
708 #define XEN_SYSCTL_COVERAGE_reset    2 /* Reset all counters */
709 
710 struct xen_sysctl_coverage_op {
711     uint32_t cmd;
712     uint32_t size; /* IN/OUT: size of the buffer  */
713     XEN_GUEST_HANDLE_64(char) buffer; /* OUT */
714 };
715 
716 #define XEN_SYSCTL_PSR_CMT_get_total_rmid            0
717 #define XEN_SYSCTL_PSR_CMT_get_l3_upscaling_factor   1
718 /* The L3 cache size is returned in KB unit */
719 #define XEN_SYSCTL_PSR_CMT_get_l3_cache_size         2
720 #define XEN_SYSCTL_PSR_CMT_enabled                   3
721 #define XEN_SYSCTL_PSR_CMT_get_l3_event_mask         4
722 struct xen_sysctl_psr_cmt_op {
723     uint32_t cmd;       /* IN: XEN_SYSCTL_PSR_CMT_* */
724     uint32_t flags;     /* padding variable, may be extended for future use */
725     union {
726         uint64_t data;  /* OUT */
727         struct {
728             uint32_t cpu;   /* IN */
729             uint32_t rsvd;
730         } l3_cache;
731     } u;
732 };
733 
734 /* XEN_SYSCTL_pcitopoinfo */
735 #define XEN_INVALID_DEV (XEN_INVALID_NODE_ID - 1)
736 struct xen_sysctl_pcitopoinfo {
737     /*
738      * IN: Number of elements in 'devs' and 'nodes' arrays.
739      * OUT: Number of processed elements of those arrays.
740      */
741     uint32_t num_devs;
742 
743     /* IN: list of devices for which node IDs are requested. */
744     XEN_GUEST_HANDLE_64(physdev_pci_device_t) devs;
745 
746     /*
747      * OUT: node identifier for each device.
748      * If information for a particular device is not available then
749      * corresponding entry will be set to XEN_INVALID_NODE_ID. If
750      * device is not known to the hypervisor then XEN_INVALID_DEV
751      * will be provided.
752      */
753     XEN_GUEST_HANDLE_64(uint32) nodes;
754 };
755 
756 #define XEN_SYSCTL_PSR_get_l3_info               0
757 #define XEN_SYSCTL_PSR_get_l2_info               1
758 #define XEN_SYSCTL_PSR_get_mba_info              2
759 struct xen_sysctl_psr_alloc {
760     uint32_t cmd;       /* IN: XEN_SYSCTL_PSR_* */
761     uint32_t target;    /* IN */
762     union {
763         struct {
764             uint32_t cbm_len;   /* OUT: CBM length */
765             uint32_t cos_max;   /* OUT: Maximum COS */
766 #define XEN_SYSCTL_PSR_CAT_L3_CDP       (1u << 0)
767             uint32_t flags;     /* OUT: CAT flags */
768         } cat_info;
769 
770         struct {
771             uint32_t thrtl_max; /* OUT: Maximum throttle */
772             uint32_t cos_max;   /* OUT: Maximum COS */
773 #define XEN_SYSCTL_PSR_MBA_LINEAR      (1u << 0)
774             uint32_t flags;     /* OUT: MBA flags */
775         } mba_info;
776     } u;
777 };
778 
779 /*
780  * XEN_SYSCTL_get_cpu_levelling_caps (x86 specific)
781  *
782  * Return hardware capabilities concerning masking or faulting of the cpuid
783  * instruction for PV guests.
784  */
785 struct xen_sysctl_cpu_levelling_caps {
786 #define XEN_SYSCTL_CPU_LEVELCAP_faulting    (1ul <<  0) /* CPUID faulting    */
787 #define XEN_SYSCTL_CPU_LEVELCAP_ecx         (1ul <<  1) /* 0x00000001.ecx    */
788 #define XEN_SYSCTL_CPU_LEVELCAP_edx         (1ul <<  2) /* 0x00000001.edx    */
789 #define XEN_SYSCTL_CPU_LEVELCAP_extd_ecx    (1ul <<  3) /* 0x80000001.ecx    */
790 #define XEN_SYSCTL_CPU_LEVELCAP_extd_edx    (1ul <<  4) /* 0x80000001.edx    */
791 #define XEN_SYSCTL_CPU_LEVELCAP_xsave_eax   (1ul <<  5) /* 0x0000000D:1.eax  */
792 #define XEN_SYSCTL_CPU_LEVELCAP_thermal_ecx (1ul <<  6) /* 0x00000006.ecx    */
793 #define XEN_SYSCTL_CPU_LEVELCAP_l7s0_eax    (1ul <<  7) /* 0x00000007:0.eax  */
794 #define XEN_SYSCTL_CPU_LEVELCAP_l7s0_ebx    (1ul <<  8) /* 0x00000007:0.ebx  */
795     uint32_t caps;
796 };
797 
798 /*
799  * XEN_SYSCTL_get_cpu_featureset (x86 specific)
800  *
801  * Return information about featuresets available on this host.
802  *  -  Raw: The real cpuid values.
803  *  - Host: The values Xen is using, (after command line overrides, etc).
804  *  -   PV: Maximum set of features which can be given to a PV guest.
805  *  -  HVM: Maximum set of features which can be given to a HVM guest.
806  * May fail with -EOPNOTSUPP if querying for PV or HVM data when support is
807  * compiled out of Xen.
808  */
809 struct xen_sysctl_cpu_featureset {
810 #define XEN_SYSCTL_cpu_featureset_raw      0
811 #define XEN_SYSCTL_cpu_featureset_host     1
812 #define XEN_SYSCTL_cpu_featureset_pv       2
813 #define XEN_SYSCTL_cpu_featureset_hvm      3
814     uint32_t index;       /* IN: Which featureset to query? */
815     uint32_t nr_features; /* IN/OUT: Number of entries in/written to
816                            * 'features', or the maximum number of features if
817                            * the guest handle is NULL.  NB. All featuresets
818                            * come from the same numberspace, so have the same
819                            * maximum length. */
820     XEN_GUEST_HANDLE_64(uint32) features; /* OUT: */
821 };
822 
823 /*
824  * XEN_SYSCTL_LIVEPATCH_op
825  *
826  * Refer to the docs/unstable/misc/livepatch.markdown
827  * for the design details of this hypercall.
828  *
829  * There are four sub-ops:
830  *  XEN_SYSCTL_LIVEPATCH_UPLOAD (0)
831  *  XEN_SYSCTL_LIVEPATCH_GET (1)
832  *  XEN_SYSCTL_LIVEPATCH_LIST (2)
833  *  XEN_SYSCTL_LIVEPATCH_ACTION (3)
834  *
835  * The normal sequence of sub-ops is to:
836  *  1) XEN_SYSCTL_LIVEPATCH_UPLOAD to upload the payload. If errors STOP.
837  *  2) XEN_SYSCTL_LIVEPATCH_GET to check the `->rc`. If -XEN_EAGAIN spin.
838  *     If zero go to next step.
839  *  3) XEN_SYSCTL_LIVEPATCH_ACTION with LIVEPATCH_ACTION_APPLY to apply the patch.
840  *  4) XEN_SYSCTL_LIVEPATCH_GET to check the `->rc`. If in -XEN_EAGAIN spin.
841  *     If zero exit with success.
842  */
843 
844 #define LIVEPATCH_PAYLOAD_VERSION 2
845 /*
846  * .livepatch.funcs structure layout defined in the `Payload format`
847  * section in the Live Patch design document.
848  *
849  * We guard this with __XEN__ as toolstacks SHOULD not use it.
850  */
851 #ifdef __XEN__
852 #define LIVEPATCH_OPAQUE_SIZE 31
853 
854 struct livepatch_expectation {
855     uint8_t enabled : 1;
856     uint8_t len : 5;        /* Length of data up to LIVEPATCH_OPAQUE_SIZE
857                                (5 bits is enough for now) */
858     uint8_t rsv : 2;        /* Reserved. Zero value */
859     uint8_t data[LIVEPATCH_OPAQUE_SIZE]; /* Same size as opaque[] buffer of
860                                             struct livepatch_func. This is the
861                                             max number of bytes to be patched */
862 };
863 typedef struct livepatch_expectation livepatch_expectation_t;
864 
865 typedef enum livepatch_func_state {
866     LIVEPATCH_FUNC_NOT_APPLIED,
867     LIVEPATCH_FUNC_APPLIED
868 } livepatch_func_state_t;
869 
870 struct livepatch_func {
871     const char *name;       /* Name of function to be patched. */
872     void *new_addr;
873     void *old_addr;
874     uint32_t new_size;
875     uint32_t old_size;
876     uint8_t version;        /* MUST be LIVEPATCH_PAYLOAD_VERSION. */
877     uint8_t opaque[LIVEPATCH_OPAQUE_SIZE];
878     uint8_t applied;
879     uint8_t _pad[7];
880     livepatch_expectation_t expect;
881 };
882 typedef struct livepatch_func livepatch_func_t;
883 #endif
884 
885 /*
886  * Structure describing an ELF payload. Uniquely identifies the
887  * payload. Should be human readable.
888  * Recommended length is upto XEN_LIVEPATCH_NAME_SIZE.
889  * Includes the NUL terminator.
890  */
891 #define XEN_LIVEPATCH_NAME_SIZE 128
892 struct xen_livepatch_name {
893     XEN_GUEST_HANDLE_64(char) name;         /* IN: pointer to name. */
894     uint16_t size;                          /* IN: size of name. May be upto
895                                                XEN_LIVEPATCH_NAME_SIZE. */
896     uint16_t pad[3];                        /* IN: MUST be zero. */
897 };
898 
899 /*
900  * Upload a payload to the hypervisor. The payload is verified
901  * against basic checks and if there are any issues the proper return code
902  * will be returned. The payload is not applied at this time - that is
903  * controlled by XEN_SYSCTL_LIVEPATCH_ACTION.
904  *
905  * The return value is zero if the payload was succesfully uploaded.
906  * Otherwise an EXX return value is provided. Duplicate `name` are not
907  * supported.
908  *
909  * The payload at this point is verified against basic checks.
910  *
911  * The `payload` is the ELF payload as mentioned in the `Payload format`
912  * section in the Live Patch design document.
913  */
914 #define XEN_SYSCTL_LIVEPATCH_UPLOAD 0
915 struct xen_sysctl_livepatch_upload {
916     struct xen_livepatch_name name;         /* IN, name of the patch. */
917     uint64_t size;                          /* IN, size of the ELF file. */
918     XEN_GUEST_HANDLE_64(uint8) payload;     /* IN, the ELF file. */
919 };
920 
921 /*
922  * Retrieve an status of an specific payload.
923  *
924  * Upon completion the `struct xen_livepatch_status` is updated.
925  *
926  * The return value is zero on success and XEN_EXX on failure. This operation
927  * is synchronous and does not require preemption.
928  */
929 #define XEN_SYSCTL_LIVEPATCH_GET 1
930 
931 struct xen_livepatch_status {
932 #define LIVEPATCH_STATE_CHECKED      1
933 #define LIVEPATCH_STATE_APPLIED      2
934     uint32_t state;                /* OUT: LIVEPATCH_STATE_*. */
935     int32_t rc;                    /* OUT: 0 if no error, otherwise -XEN_EXX. */
936 };
937 typedef struct xen_livepatch_status xen_livepatch_status_t;
938 DEFINE_XEN_GUEST_HANDLE(xen_livepatch_status_t);
939 
940 struct xen_sysctl_livepatch_get {
941     struct xen_livepatch_name name;         /* IN, name of the payload. */
942     struct xen_livepatch_status status;     /* IN/OUT, state of it. */
943 };
944 
945 /*
946  * Retrieve an array of abbreviated status, names and metadata of payloads that
947  * are loaded in the hypervisor.
948  *
949  * If the hypercall returns an positive number, it is the number (up to `nr`)
950  * of the payloads returned, along with `nr` updated with the number of remaining
951  * payloads, `version` updated (it may be the same across hypercalls. If it varies
952  * the data is stale and further calls could fail), `name_total_size` and
953  * `metadata_total_size` containing total sizes of transferred data for both the
954  * arrays.
955  * The `status`, `name`, `len`, `metadata` and `metadata_len` are updated at their
956  * designed index value (`idx`) with the returned value of data.
957  *
958  * If the hypercall returns E2BIG the `nr` is too big and should be
959  * lowered. The upper limit of `nr` is left to the implemention.
960  *
961  * Note that due to the asynchronous nature of hypercalls the domain might have
962  * added or removed the number of payloads making this information stale. It is
963  * the responsibility of the toolstack to use the `version` field to check
964  * between each invocation. if the version differs it should discard the stale
965  * data and start from scratch. It is OK for the toolstack to use the new
966  * `version` field.
967  */
968 #define XEN_SYSCTL_LIVEPATCH_LIST 2
969 struct xen_sysctl_livepatch_list {
970     uint32_t version;                       /* OUT: Hypervisor stamps value.
971                                                If varies between calls, we are
972                                              * getting stale data. */
973     uint32_t idx;                           /* IN: Index into hypervisor list. */
974     uint32_t nr;                            /* IN: How many status, name, and len
975                                                should fill out. Can be zero to get
976                                                amount of payloads and version.
977                                                OUT: How many payloads left. */
978     uint32_t pad;                           /* IN: Must be zero. */
979     uint32_t name_total_size;               /* OUT: Total size of all transfer names */
980     uint32_t metadata_total_size;           /* OUT: Total size of all transfer metadata */
981     XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status;  /* OUT. Must have enough
982                                                space allocate for nr of them. */
983     XEN_GUEST_HANDLE_64(char) name;         /* OUT: Array of names. Each member
984                                                may have an arbitrary length up to
985                                                XEN_LIVEPATCH_NAME_SIZE bytes. Must have
986                                                nr of them. */
987     XEN_GUEST_HANDLE_64(uint32) len;        /* OUT: Array of lengths of name's.
988                                                Must have nr of them. */
989     XEN_GUEST_HANDLE_64(char) metadata;     /* OUT: Array of metadata strings. Each
990                                                member may have an arbitrary length.
991                                                Must have nr of them. */
992     XEN_GUEST_HANDLE_64(uint32) metadata_len;  /* OUT: Array of lengths of metadata's.
993                                                   Must have nr of them. */
994 };
995 
996 /*
997  * Perform an operation on the payload structure referenced by the `name` field.
998  * The operation request is asynchronous and the status should be retrieved
999  * by using either XEN_SYSCTL_LIVEPATCH_GET or XEN_SYSCTL_LIVEPATCH_LIST hypercall.
1000  */
1001 #define XEN_SYSCTL_LIVEPATCH_ACTION 3
1002 struct xen_sysctl_livepatch_action {
1003     struct xen_livepatch_name name;         /* IN, name of the patch. */
1004 #define LIVEPATCH_ACTION_UNLOAD       1
1005 #define LIVEPATCH_ACTION_REVERT       2
1006 #define LIVEPATCH_ACTION_APPLY        3
1007 #define LIVEPATCH_ACTION_REPLACE      4
1008     uint32_t cmd;                           /* IN: LIVEPATCH_ACTION_*. */
1009     uint32_t timeout;                       /* IN: If zero then uses */
1010                                             /* hypervisor default. */
1011                                             /* Or upper bound of time (ns) */
1012                                             /* for operation to take. */
1013 
1014 /*
1015  * Override default inter-module buildid dependency chain enforcement.
1016  * Check only if module is built for given hypervisor by comparing buildid.
1017  */
1018 #define LIVEPATCH_ACTION_APPLY_NODEPS (1 << 0)
1019     uint32_t flags;                         /* IN: action flags. */
1020                                             /* Provide additional parameters */
1021                                             /* for an action. */
1022     uint32_t pad;                           /* IN: Always zero. */
1023 };
1024 
1025 struct xen_sysctl_livepatch_op {
1026     uint32_t cmd;                           /* IN: XEN_SYSCTL_LIVEPATCH_*. */
1027     uint32_t pad;                           /* IN: Always zero. */
1028     union {
1029         struct xen_sysctl_livepatch_upload upload;
1030         struct xen_sysctl_livepatch_list list;
1031         struct xen_sysctl_livepatch_get get;
1032         struct xen_sysctl_livepatch_action action;
1033     } u;
1034 };
1035 
1036 #if defined(__i386__) || defined(__x86_64__)
1037 /*
1038  * XEN_SYSCTL_get_cpu_policy (x86 specific)
1039  *
1040  * Return information about CPUID and MSR policies available on this host.
1041  *  -       Raw: The real H/W values.
1042  *  -      Host: The values Xen is using, (after command line overrides, etc).
1043  *  -     Max_*: Maximum set of features a PV or HVM guest can use.  Includes
1044  *               experimental features outside of security support.
1045  *  - Default_*: Default set of features a PV or HVM guest can use.  This is
1046  *               the security supported set.
1047  * May fail with -EOPNOTSUPP if querying for PV or HVM data when support is
1048  * compiled out of Xen.
1049  */
1050 struct xen_sysctl_cpu_policy {
1051 #define XEN_SYSCTL_cpu_policy_raw          0
1052 #define XEN_SYSCTL_cpu_policy_host         1
1053 #define XEN_SYSCTL_cpu_policy_pv_max       2
1054 #define XEN_SYSCTL_cpu_policy_hvm_max      3
1055 #define XEN_SYSCTL_cpu_policy_pv_default   4
1056 #define XEN_SYSCTL_cpu_policy_hvm_default  5
1057     uint32_t index;       /* IN: Which policy to query? */
1058     uint32_t nr_leaves;   /* IN/OUT: Number of leaves in/written to
1059                            * 'cpuid_policy', or the maximum number of leaves
1060                            * if the guest handle is NULL. */
1061     uint32_t nr_msrs;     /* IN/OUT: Number of MSRs in/written to
1062                            * 'msr_policy', or the maximum number of MSRs if
1063                            * the guest handle is NULL. */
1064     uint32_t _rsvd;       /* Must be zero. */
1065     XEN_GUEST_HANDLE_64(xen_cpuid_leaf_t) cpuid_policy; /* OUT */
1066     XEN_GUEST_HANDLE_64(xen_msr_entry_t) msr_policy;    /* OUT */
1067 };
1068 typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t;
1069 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t);
1070 #endif
1071 
1072 struct xen_sysctl {
1073     uint32_t cmd;
1074 #define XEN_SYSCTL_readconsole                    1
1075 #define XEN_SYSCTL_tbuf_op                        2
1076 #define XEN_SYSCTL_physinfo                       3
1077 #define XEN_SYSCTL_sched_id                       4
1078 #define XEN_SYSCTL_perfc_op                       5
1079 #define XEN_SYSCTL_getdomaininfolist              6
1080 #define XEN_SYSCTL_debug_keys                     7
1081 #define XEN_SYSCTL_getcpuinfo                     8
1082 #define XEN_SYSCTL_availheap                      9
1083 #define XEN_SYSCTL_get_pmstat                    10
1084 #define XEN_SYSCTL_cpu_hotplug                   11
1085 #define XEN_SYSCTL_pm_op                         12
1086 #define XEN_SYSCTL_page_offline_op               14
1087 #define XEN_SYSCTL_lockprof_op                   15
1088 #define XEN_SYSCTL_cputopoinfo                   16
1089 #define XEN_SYSCTL_numainfo                      17
1090 #define XEN_SYSCTL_cpupool_op                    18
1091 #define XEN_SYSCTL_scheduler_op                  19
1092 #define XEN_SYSCTL_coverage_op                   20
1093 #define XEN_SYSCTL_psr_cmt_op                    21
1094 #define XEN_SYSCTL_pcitopoinfo                   22
1095 #define XEN_SYSCTL_psr_alloc                     23
1096 /* #define XEN_SYSCTL_tmem_op                       24 */
1097 #define XEN_SYSCTL_get_cpu_levelling_caps        25
1098 #define XEN_SYSCTL_get_cpu_featureset            26
1099 #define XEN_SYSCTL_livepatch_op                  27
1100 /* #define XEN_SYSCTL_set_parameter              28 */
1101 #define XEN_SYSCTL_get_cpu_policy                29
1102     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
1103     union {
1104         struct xen_sysctl_readconsole       readconsole;
1105         struct xen_sysctl_tbuf_op           tbuf_op;
1106         struct xen_sysctl_physinfo          physinfo;
1107         struct xen_sysctl_cputopoinfo       cputopoinfo;
1108         struct xen_sysctl_pcitopoinfo       pcitopoinfo;
1109         struct xen_sysctl_numainfo          numainfo;
1110         struct xen_sysctl_sched_id          sched_id;
1111         struct xen_sysctl_perfc_op          perfc_op;
1112         struct xen_sysctl_getdomaininfolist getdomaininfolist;
1113         struct xen_sysctl_debug_keys        debug_keys;
1114         struct xen_sysctl_getcpuinfo        getcpuinfo;
1115         struct xen_sysctl_availheap         availheap;
1116         struct xen_sysctl_get_pmstat        get_pmstat;
1117         struct xen_sysctl_cpu_hotplug       cpu_hotplug;
1118         struct xen_sysctl_pm_op             pm_op;
1119         struct xen_sysctl_page_offline_op   page_offline;
1120         struct xen_sysctl_lockprof_op       lockprof_op;
1121         struct xen_sysctl_cpupool_op        cpupool_op;
1122         struct xen_sysctl_scheduler_op      scheduler_op;
1123         struct xen_sysctl_coverage_op       coverage_op;
1124         struct xen_sysctl_psr_cmt_op        psr_cmt_op;
1125         struct xen_sysctl_psr_alloc         psr_alloc;
1126         struct xen_sysctl_cpu_levelling_caps cpu_levelling_caps;
1127         struct xen_sysctl_cpu_featureset    cpu_featureset;
1128         struct xen_sysctl_livepatch_op      livepatch;
1129 #if defined(__i386__) || defined(__x86_64__)
1130         struct xen_sysctl_cpu_policy        cpu_policy;
1131 #endif
1132         uint8_t                             pad[128];
1133     } u;
1134 };
1135 typedef struct xen_sysctl xen_sysctl_t;
1136 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_t);
1137 
1138 #endif /* __XEN_PUBLIC_SYSCTL_H__ */
1139 
1140 /*
1141  * Local variables:
1142  * mode: C
1143  * c-file-style: "BSD"
1144  * c-basic-offset: 4
1145  * tab-width: 4
1146  * indent-tabs-mode: nil
1147  * End:
1148  */
1149