xref: /titanic_44/usr/src/uts/common/xen/public/sysctl.h (revision 1e4c938b57d1656808e4112127ff1dce3eba5314)
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 
37 #define XEN_SYSCTL_INTERFACE_VERSION 0x00000006
38 
39 /*
40  * Read console content from Xen buffer ring.
41  */
42 #define XEN_SYSCTL_readconsole       1
43 struct xen_sysctl_readconsole {
44     /* IN: Non-zero -> clear after reading. */
45     uint8_t clear;
46     /* IN: Non-zero -> start index specified by @index field. */
47     uint8_t incremental;
48     uint8_t pad0, pad1;
49     /*
50      * IN:  Start index for consuming from ring buffer (if @incremental);
51      * OUT: End index after consuming from ring buffer.
52      */
53     uint32_t index;
54     /* IN: Virtual address to write console data. */
55     XEN_GUEST_HANDLE_64(char) buffer;
56     /* IN: Size of buffer; OUT: Bytes written to buffer. */
57     uint32_t count;
58 };
59 typedef struct xen_sysctl_readconsole xen_sysctl_readconsole_t;
60 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_readconsole_t);
61 
62 /* Get trace buffers machine base address */
63 #define XEN_SYSCTL_tbuf_op           2
64 struct xen_sysctl_tbuf_op {
65     /* IN variables */
66 #define XEN_SYSCTL_TBUFOP_get_info     0
67 #define XEN_SYSCTL_TBUFOP_set_cpu_mask 1
68 #define XEN_SYSCTL_TBUFOP_set_evt_mask 2
69 #define XEN_SYSCTL_TBUFOP_set_size     3
70 #define XEN_SYSCTL_TBUFOP_enable       4
71 #define XEN_SYSCTL_TBUFOP_disable      5
72     uint32_t cmd;
73     /* IN/OUT variables */
74     struct xenctl_cpumap cpu_mask;
75     uint32_t             evt_mask;
76     /* OUT variables */
77     uint64_aligned_t buffer_mfn;
78     uint32_t size;
79 };
80 typedef struct xen_sysctl_tbuf_op xen_sysctl_tbuf_op_t;
81 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tbuf_op_t);
82 
83 /*
84  * Get physical information about the host machine
85  */
86 #define XEN_SYSCTL_physinfo          3
87  /* (x86) The platform supports HVM guests. */
88 #define _XEN_SYSCTL_PHYSCAP_hvm          0
89 #define XEN_SYSCTL_PHYSCAP_hvm           (1u<<_XEN_SYSCTL_PHYSCAP_hvm)
90  /* (x86) The platform supports HVM-guest direct access to I/O devices. */
91 #define _XEN_SYSCTL_PHYSCAP_hvm_directio 1
92 #define XEN_SYSCTL_PHYSCAP_hvm_directio  (1u<<_XEN_SYSCTL_PHYSCAP_hvm_directio)
93 struct xen_sysctl_physinfo {
94     uint32_t threads_per_core;
95     uint32_t cores_per_socket;
96     uint32_t nr_cpus;
97     uint32_t nr_nodes;
98     uint32_t cpu_khz;
99     uint64_aligned_t total_pages;
100     uint64_aligned_t free_pages;
101     uint64_aligned_t scrub_pages;
102     uint32_t hw_cap[8];
103 
104     /*
105      * IN: maximum addressable entry in the caller-provided cpu_to_node array.
106      * OUT: largest cpu identifier in the system.
107      * If OUT is greater than IN then the cpu_to_node array is truncated!
108      */
109     uint32_t max_cpu_id;
110     /*
111      * If not NULL, this array is filled with node identifier for each cpu.
112      * If a cpu has no node information (e.g., cpu not present) then the
113      * sentinel value ~0u is written.
114      * The size of this array is specified by the caller in @max_cpu_id.
115      * If the actual @max_cpu_id is smaller than the array then the trailing
116      * elements of the array will not be written by the sysctl.
117      */
118     XEN_GUEST_HANDLE_64(uint32) cpu_to_node;
119 
120     /* XEN_SYSCTL_PHYSCAP_??? */
121     uint32_t capabilities;
122 };
123 typedef struct xen_sysctl_physinfo xen_sysctl_physinfo_t;
124 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_physinfo_t);
125 
126 /*
127  * Get the ID of the current scheduler.
128  */
129 #define XEN_SYSCTL_sched_id          4
130 struct xen_sysctl_sched_id {
131     /* OUT variable */
132     uint32_t sched_id;
133 };
134 typedef struct xen_sysctl_sched_id xen_sysctl_sched_id_t;
135 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_sched_id_t);
136 
137 /* Interface for controlling Xen software performance counters. */
138 #define XEN_SYSCTL_perfc_op          5
139 /* Sub-operations: */
140 #define XEN_SYSCTL_PERFCOP_reset 1   /* Reset all counters to zero. */
141 #define XEN_SYSCTL_PERFCOP_query 2   /* Get perfctr information. */
142 struct xen_sysctl_perfc_desc {
143     char         name[80];             /* name of perf counter */
144     uint32_t     nr_vals;              /* number of values for this counter */
145 };
146 typedef struct xen_sysctl_perfc_desc xen_sysctl_perfc_desc_t;
147 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_desc_t);
148 typedef uint32_t xen_sysctl_perfc_val_t;
149 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_val_t);
150 
151 struct xen_sysctl_perfc_op {
152     /* IN variables. */
153     uint32_t       cmd;                /*  XEN_SYSCTL_PERFCOP_??? */
154     /* OUT variables. */
155     uint32_t       nr_counters;       /*  number of counters description  */
156     uint32_t       nr_vals;           /*  number of values  */
157     /* counter information (or NULL) */
158     XEN_GUEST_HANDLE_64(xen_sysctl_perfc_desc_t) desc;
159     /* counter values (or NULL) */
160     XEN_GUEST_HANDLE_64(xen_sysctl_perfc_val_t) val;
161 };
162 typedef struct xen_sysctl_perfc_op xen_sysctl_perfc_op_t;
163 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_op_t);
164 
165 #define XEN_SYSCTL_getdomaininfolist 6
166 struct xen_sysctl_getdomaininfolist {
167     /* IN variables. */
168     domid_t               first_domain;
169     uint32_t              max_domains;
170     XEN_GUEST_HANDLE_64(xen_domctl_getdomaininfo_t) buffer;
171     /* OUT variables. */
172     uint32_t              num_domains;
173 };
174 typedef struct xen_sysctl_getdomaininfolist xen_sysctl_getdomaininfolist_t;
175 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getdomaininfolist_t);
176 
177 /* Inject debug keys into Xen. */
178 #define XEN_SYSCTL_debug_keys        7
179 struct xen_sysctl_debug_keys {
180     /* IN variables. */
181     XEN_GUEST_HANDLE_64(char) keys;
182     uint32_t nr_keys;
183 };
184 typedef struct xen_sysctl_debug_keys xen_sysctl_debug_keys_t;
185 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_debug_keys_t);
186 
187 /* Get physical CPU information. */
188 #define XEN_SYSCTL_getcpuinfo        8
189 struct xen_sysctl_cpuinfo {
190     uint64_aligned_t idletime;
191 };
192 typedef struct xen_sysctl_cpuinfo xen_sysctl_cpuinfo_t;
193 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpuinfo_t);
194 struct xen_sysctl_getcpuinfo {
195     /* IN variables. */
196     uint32_t max_cpus;
197     XEN_GUEST_HANDLE_64(xen_sysctl_cpuinfo_t) info;
198     /* OUT variables. */
199     uint32_t nr_cpus;
200 };
201 typedef struct xen_sysctl_getcpuinfo xen_sysctl_getcpuinfo_t;
202 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcpuinfo_t);
203 
204 #define XEN_SYSCTL_availheap         9
205 struct xen_sysctl_availheap {
206     /* IN variables. */
207     uint32_t min_bitwidth;  /* Smallest address width (zero if don't care). */
208     uint32_t max_bitwidth;  /* Largest address width (zero if don't care). */
209     int32_t  node;          /* NUMA node of interest (-1 for all nodes). */
210     /* OUT variables. */
211     uint64_aligned_t avail_bytes;/* Bytes available in the specified region. */
212 };
213 typedef struct xen_sysctl_availheap xen_sysctl_availheap_t;
214 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_availheap_t);
215 
216 #define XEN_SYSCTL_get_pmstat        10
217 struct pm_px_val {
218     uint64_aligned_t freq;        /* Px core frequency */
219     uint64_aligned_t residency;   /* Px residency time */
220     uint64_aligned_t count;       /* Px transition count */
221 };
222 typedef struct pm_px_val pm_px_val_t;
223 DEFINE_XEN_GUEST_HANDLE(pm_px_val_t);
224 
225 struct pm_px_stat {
226     uint8_t total;        /* total Px states */
227     uint8_t usable;       /* usable Px states */
228     uint8_t last;         /* last Px state */
229     uint8_t cur;          /* current Px state */
230     XEN_GUEST_HANDLE_64(uint64) trans_pt;   /* Px transition table */
231     XEN_GUEST_HANDLE_64(pm_px_val_t) pt;
232 };
233 typedef struct pm_px_stat pm_px_stat_t;
234 DEFINE_XEN_GUEST_HANDLE(pm_px_stat_t);
235 
236 struct pm_cx_stat {
237     uint32_t nr;    /* entry nr in triggers & residencies, including C0 */
238     uint32_t last;  /* last Cx state */
239     uint64_aligned_t idle_time;                 /* idle time from boot */
240     XEN_GUEST_HANDLE_64(uint64) triggers;    /* Cx trigger counts */
241     XEN_GUEST_HANDLE_64(uint64) residencies; /* Cx residencies */
242 };
243 
244 struct xen_sysctl_get_pmstat {
245 #define PMSTAT_CATEGORY_MASK 0xf0
246 #define PMSTAT_PX            0x10
247 #define PMSTAT_CX            0x20
248 #define PMSTAT_get_max_px    (PMSTAT_PX | 0x1)
249 #define PMSTAT_get_pxstat    (PMSTAT_PX | 0x2)
250 #define PMSTAT_reset_pxstat  (PMSTAT_PX | 0x3)
251 #define PMSTAT_get_max_cx    (PMSTAT_CX | 0x1)
252 #define PMSTAT_get_cxstat    (PMSTAT_CX | 0x2)
253 #define PMSTAT_reset_cxstat  (PMSTAT_CX | 0x3)
254     uint32_t type;
255     uint32_t cpuid;
256     union {
257         struct pm_px_stat getpx;
258         struct pm_cx_stat getcx;
259         /* other struct for tx, etc */
260     } u;
261 };
262 typedef struct xen_sysctl_get_pmstat xen_sysctl_get_pmstat_t;
263 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_get_pmstat_t);
264 
265 /*
266  * Status codes. Must be greater than 0 to avoid confusing
267  * sysctl callers that see 0 as a plain successful return.
268  */
269 #define XEN_CPU_HOTPLUG_STATUS_OFFLINE 1
270 #define XEN_CPU_HOTPLUG_STATUS_ONLINE  2
271 #define XEN_CPU_HOTPLUG_STATUS_NEW     3
272 
273 #define XEN_SYSCTL_cpu_hotplug       11
274 struct xen_sysctl_cpu_hotplug {
275     /* IN variables */
276     uint32_t cpu;   /* Physical cpu. */
277 #define XEN_SYSCTL_CPU_HOTPLUG_ONLINE  0
278 #define XEN_SYSCTL_CPU_HOTPLUG_OFFLINE 1
279 #define XEN_SYSCTL_CPU_HOTPLUG_STATUS 2
280     uint32_t op;    /* hotplug opcode */
281 };
282 typedef struct xen_sysctl_cpu_hotplug xen_sysctl_cpu_hotplug_t;
283 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_hotplug_t);
284 
285 /*
286  * Get/set xen power management, include
287  * 1. cpufreq governors and related parameters
288  */
289 #define XEN_SYSCTL_pm_op        12
290 struct xen_userspace {
291     uint32_t scaling_setspeed;
292 };
293 typedef struct xen_userspace xen_userspace_t;
294 
295 struct xen_ondemand {
296     uint32_t sampling_rate_max;
297     uint32_t sampling_rate_min;
298 
299     uint32_t sampling_rate;
300     uint32_t up_threshold;
301 };
302 typedef struct xen_ondemand xen_ondemand_t;
303 
304 /*
305  * cpufreq para name of this structure named
306  * same as sysfs file name of native linux
307  */
308 #define CPUFREQ_NAME_LEN 16
309 struct xen_get_cpufreq_para {
310     /* IN/OUT variable */
311     uint32_t cpu_num;
312     uint32_t freq_num;
313     uint32_t gov_num;
314 
315     /* for all governors */
316     /* OUT variable */
317     XEN_GUEST_HANDLE_64(uint32) affected_cpus;
318     XEN_GUEST_HANDLE_64(uint32) scaling_available_frequencies;
319     XEN_GUEST_HANDLE_64(char)   scaling_available_governors;
320     char scaling_driver[CPUFREQ_NAME_LEN];
321 
322     uint32_t cpuinfo_cur_freq;
323     uint32_t cpuinfo_max_freq;
324     uint32_t cpuinfo_min_freq;
325     uint32_t scaling_cur_freq;
326 
327     char scaling_governor[CPUFREQ_NAME_LEN];
328     uint32_t scaling_max_freq;
329     uint32_t scaling_min_freq;
330 
331     /* for specific governor */
332     union {
333         struct  xen_userspace userspace;
334         struct  xen_ondemand ondemand;
335     } u;
336 };
337 
338 struct xen_set_cpufreq_gov {
339     char scaling_governor[CPUFREQ_NAME_LEN];
340 };
341 
342 struct xen_set_cpufreq_para {
343     #define SCALING_MAX_FREQ           1
344     #define SCALING_MIN_FREQ           2
345     #define SCALING_SETSPEED           3
346     #define SAMPLING_RATE              4
347     #define UP_THRESHOLD               5
348 
349     uint32_t ctrl_type;
350     uint32_t ctrl_value;
351 };
352 
353 /* Get physical CPU topology information. */
354 #define INVALID_TOPOLOGY_ID  (~0U)
355 struct xen_get_cputopo {
356      /* IN: maximum addressable entry in
357       * the caller-provided cpu_to_core/socket.
358       */
359     uint32_t max_cpus;
360     XEN_GUEST_HANDLE_64(uint32) cpu_to_core;
361     XEN_GUEST_HANDLE_64(uint32) cpu_to_socket;
362 
363     /* OUT: number of cpus returned
364      * If OUT is greater than IN then the cpu_to_core/socket is truncated!
365      */
366     uint32_t nr_cpus;
367 };
368 
369 struct xen_sysctl_pm_op {
370     #define PM_PARA_CATEGORY_MASK      0xf0
371     #define CPUFREQ_PARA               0x10
372 
373     /* cpufreq command type */
374     #define GET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x01)
375     #define SET_CPUFREQ_GOV            (CPUFREQ_PARA | 0x02)
376     #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
377     #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
378 
379     /* get CPU topology */
380     #define XEN_SYSCTL_pm_op_get_cputopo  0x20
381 
382     /* set/reset scheduler power saving option */
383     #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21
384 
385     /* cpuidle max_cstate access command */
386     #define XEN_SYSCTL_pm_op_get_max_cstate       0x22
387     #define XEN_SYSCTL_pm_op_set_max_cstate       0x23
388 
389     /* set scheduler migration cost value */
390     #define XEN_SYSCTL_pm_op_set_vcpu_migration_delay   0x24
391     #define XEN_SYSCTL_pm_op_get_vcpu_migration_delay   0x25
392 
393     uint32_t cmd;
394     uint32_t cpuid;
395     union {
396         struct xen_get_cpufreq_para get_para;
397         struct xen_set_cpufreq_gov  set_gov;
398         struct xen_set_cpufreq_para set_para;
399         uint64_t get_avgfreq;
400         struct xen_get_cputopo      get_topo;
401         uint32_t                    set_sched_opt_smt;
402         uint32_t                    get_max_cstate;
403         uint32_t                    set_max_cstate;
404         uint32_t                    get_vcpu_migration_delay;
405         uint32_t                    set_vcpu_migration_delay;
406     } u;
407 };
408 
409 #define XEN_SYSCTL_page_offline_op        14
410 struct xen_sysctl_page_offline_op {
411     /* IN: range of page to be offlined */
412 #define sysctl_page_offline     1
413 #define sysctl_page_online      2
414 #define sysctl_query_page_offline  3
415     uint32_t cmd;
416     uint32_t start;
417     uint32_t end;
418     /* OUT: result of page offline request */
419     /*
420      * bit 0~15: result flags
421      * bit 16~31: owner
422      */
423     XEN_GUEST_HANDLE(uint32) status;
424 };
425 
426 #define PG_OFFLINE_STATUS_MASK    (0xFFUL)
427 
428 /* The result is invalid, i.e. HV does not handle it */
429 #define PG_OFFLINE_INVALID   (0x1UL << 0)
430 
431 #define PG_OFFLINE_OFFLINED  (0x1UL << 1)
432 #define PG_OFFLINE_PENDING   (0x1UL << 2)
433 #define PG_OFFLINE_FAILED    (0x1UL << 3)
434 
435 #define PG_ONLINE_FAILED     PG_OFFLINE_FAILED
436 #define PG_ONLINE_ONLINED    PG_OFFLINE_OFFLINED
437 
438 #define PG_OFFLINE_STATUS_OFFLINED              (0x1UL << 1)
439 #define PG_OFFLINE_STATUS_ONLINE                (0x1UL << 2)
440 #define PG_OFFLINE_STATUS_OFFLINE_PENDING       (0x1UL << 3)
441 #define PG_OFFLINE_STATUS_BROKEN                (0x1UL << 4)
442 
443 #define PG_OFFLINE_MISC_MASK    (0xFFUL << 4)
444 
445 /* only valid when PG_OFFLINE_FAILED */
446 #define PG_OFFLINE_XENPAGE   (0x1UL << 8)
447 #define PG_OFFLINE_DOM0PAGE  (0x1UL << 9)
448 #define PG_OFFLINE_ANONYMOUS (0x1UL << 10)
449 #define PG_OFFLINE_NOT_CONV_RAM   (0x1UL << 11)
450 #define PG_OFFLINE_OWNED     (0x1UL << 12)
451 
452 #define PG_OFFLINE_BROKEN    (0x1UL << 13)
453 #define PG_ONLINE_BROKEN     PG_OFFLINE_BROKEN
454 
455 #define PG_OFFLINE_OWNER_SHIFT 16
456 
457 struct xen_sysctl {
458     uint32_t cmd;
459     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
460     union {
461         struct xen_sysctl_readconsole       readconsole;
462         struct xen_sysctl_tbuf_op           tbuf_op;
463         struct xen_sysctl_physinfo          physinfo;
464         struct xen_sysctl_sched_id          sched_id;
465         struct xen_sysctl_perfc_op          perfc_op;
466         struct xen_sysctl_getdomaininfolist getdomaininfolist;
467         struct xen_sysctl_debug_keys        debug_keys;
468         struct xen_sysctl_getcpuinfo        getcpuinfo;
469         struct xen_sysctl_availheap         availheap;
470         struct xen_sysctl_get_pmstat        get_pmstat;
471         struct xen_sysctl_cpu_hotplug       cpu_hotplug;
472         struct xen_sysctl_pm_op             pm_op;
473         struct xen_sysctl_page_offline_op   page_offline;
474         uint8_t                             pad[128];
475     } u;
476 };
477 typedef struct xen_sysctl xen_sysctl_t;
478 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_t);
479 
480 #endif /* __XEN_PUBLIC_SYSCTL_H__ */
481 
482 /*
483  * Local variables:
484  * mode: C
485  * c-set-style: "BSD"
486  * c-basic-offset: 4
487  * tab-width: 4
488  * indent-tabs-mode: nil
489  * End:
490  */
491