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