xref: /openbmc/linux/include/xen/interface/platform.h (revision 3c6a73cc)
1 /******************************************************************************
2  * platform.h
3  *
4  * Hardware platform operations. Intended for use by domain-0 kernel.
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_PLATFORM_H__
28 #define __XEN_PUBLIC_PLATFORM_H__
29 
30 #include <xen/interface/xen.h>
31 
32 #define XENPF_INTERFACE_VERSION 0x03000001
33 
34 /*
35  * Set clock such that it would read <secs,nsecs> after 00:00:00 UTC,
36  * 1 January, 1970 if the current system time was <system_time>.
37  */
38 #define XENPF_settime             17
39 struct xenpf_settime {
40 	/* IN variables. */
41 	uint32_t secs;
42 	uint32_t nsecs;
43 	uint64_t system_time;
44 };
45 DEFINE_GUEST_HANDLE_STRUCT(xenpf_settime_t);
46 
47 /*
48  * Request memory range (@mfn, @mfn+@nr_mfns-1) to have type @type.
49  * On x86, @type is an architecture-defined MTRR memory type.
50  * On success, returns the MTRR that was used (@reg) and a handle that can
51  * be passed to XENPF_DEL_MEMTYPE to accurately tear down the new setting.
52  * (x86-specific).
53  */
54 #define XENPF_add_memtype         31
55 struct xenpf_add_memtype {
56 	/* IN variables. */
57 	xen_pfn_t mfn;
58 	uint64_t nr_mfns;
59 	uint32_t type;
60 	/* OUT variables. */
61 	uint32_t handle;
62 	uint32_t reg;
63 };
64 DEFINE_GUEST_HANDLE_STRUCT(xenpf_add_memtype_t);
65 
66 /*
67  * Tear down an existing memory-range type. If @handle is remembered then it
68  * should be passed in to accurately tear down the correct setting (in case
69  * of overlapping memory regions with differing types). If it is not known
70  * then @handle should be set to zero. In all cases @reg must be set.
71  * (x86-specific).
72  */
73 #define XENPF_del_memtype         32
74 struct xenpf_del_memtype {
75 	/* IN variables. */
76 	uint32_t handle;
77 	uint32_t reg;
78 };
79 DEFINE_GUEST_HANDLE_STRUCT(xenpf_del_memtype_t);
80 
81 /* Read current type of an MTRR (x86-specific). */
82 #define XENPF_read_memtype        33
83 struct xenpf_read_memtype {
84 	/* IN variables. */
85 	uint32_t reg;
86 	/* OUT variables. */
87 	xen_pfn_t mfn;
88 	uint64_t nr_mfns;
89 	uint32_t type;
90 };
91 DEFINE_GUEST_HANDLE_STRUCT(xenpf_read_memtype_t);
92 
93 #define XENPF_microcode_update    35
94 struct xenpf_microcode_update {
95 	/* IN variables. */
96 	GUEST_HANDLE(void) data;          /* Pointer to microcode data */
97 	uint32_t length;                  /* Length of microcode data. */
98 };
99 DEFINE_GUEST_HANDLE_STRUCT(xenpf_microcode_update_t);
100 
101 #define XENPF_platform_quirk      39
102 #define QUIRK_NOIRQBALANCING      1 /* Do not restrict IO-APIC RTE targets */
103 #define QUIRK_IOAPIC_BAD_REGSEL   2 /* IO-APIC REGSEL forgets its value    */
104 #define QUIRK_IOAPIC_GOOD_REGSEL  3 /* IO-APIC REGSEL behaves properly     */
105 struct xenpf_platform_quirk {
106 	/* IN variables. */
107 	uint32_t quirk_id;
108 };
109 DEFINE_GUEST_HANDLE_STRUCT(xenpf_platform_quirk_t);
110 
111 #define XENPF_efi_runtime_call    49
112 #define XEN_EFI_get_time                      1
113 #define XEN_EFI_set_time                      2
114 #define XEN_EFI_get_wakeup_time               3
115 #define XEN_EFI_set_wakeup_time               4
116 #define XEN_EFI_get_next_high_monotonic_count 5
117 #define XEN_EFI_get_variable                  6
118 #define XEN_EFI_set_variable                  7
119 #define XEN_EFI_get_next_variable_name        8
120 #define XEN_EFI_query_variable_info           9
121 #define XEN_EFI_query_capsule_capabilities   10
122 #define XEN_EFI_update_capsule               11
123 
124 struct xenpf_efi_runtime_call {
125 	uint32_t function;
126 	/*
127 	 * This field is generally used for per sub-function flags (defined
128 	 * below), except for the XEN_EFI_get_next_high_monotonic_count case,
129 	 * where it holds the single returned value.
130 	 */
131 	uint32_t misc;
132 	xen_ulong_t status;
133 	union {
134 #define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001
135 		struct {
136 			struct xenpf_efi_time {
137 				uint16_t year;
138 				uint8_t month;
139 				uint8_t day;
140 				uint8_t hour;
141 				uint8_t min;
142 				uint8_t sec;
143 				uint32_t ns;
144 				int16_t tz;
145 				uint8_t daylight;
146 			} time;
147 			uint32_t resolution;
148 			uint32_t accuracy;
149 		} get_time;
150 
151 		struct xenpf_efi_time set_time;
152 
153 #define XEN_EFI_GET_WAKEUP_TIME_ENABLED 0x00000001
154 #define XEN_EFI_GET_WAKEUP_TIME_PENDING 0x00000002
155 		struct xenpf_efi_time get_wakeup_time;
156 
157 #define XEN_EFI_SET_WAKEUP_TIME_ENABLE      0x00000001
158 #define XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY 0x00000002
159 		struct xenpf_efi_time set_wakeup_time;
160 
161 #define XEN_EFI_VARIABLE_NON_VOLATILE       0x00000001
162 #define XEN_EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
163 #define XEN_EFI_VARIABLE_RUNTIME_ACCESS     0x00000004
164 		struct {
165 			GUEST_HANDLE(void) name;  /* UCS-2/UTF-16 string */
166 			xen_ulong_t size;
167 			GUEST_HANDLE(void) data;
168 			struct xenpf_efi_guid {
169 				uint32_t data1;
170 				uint16_t data2;
171 				uint16_t data3;
172 				uint8_t data4[8];
173 			} vendor_guid;
174 		} get_variable, set_variable;
175 
176 		struct {
177 			xen_ulong_t size;
178 			GUEST_HANDLE(void) name;  /* UCS-2/UTF-16 string */
179 			struct xenpf_efi_guid vendor_guid;
180 		} get_next_variable_name;
181 
182 		struct {
183 			uint32_t attr;
184 			uint64_t max_store_size;
185 			uint64_t remain_store_size;
186 			uint64_t max_size;
187 		} query_variable_info;
188 
189 		struct {
190 			GUEST_HANDLE(void) capsule_header_array;
191 			xen_ulong_t capsule_count;
192 			uint64_t max_capsule_size;
193 			uint32_t reset_type;
194 		} query_capsule_capabilities;
195 
196 		struct {
197 			GUEST_HANDLE(void) capsule_header_array;
198 			xen_ulong_t capsule_count;
199 			uint64_t sg_list; /* machine address */
200 		} update_capsule;
201 	} u;
202 };
203 DEFINE_GUEST_HANDLE_STRUCT(xenpf_efi_runtime_call);
204 
205 #define  XEN_FW_EFI_VERSION        0
206 #define  XEN_FW_EFI_CONFIG_TABLE   1
207 #define  XEN_FW_EFI_VENDOR         2
208 #define  XEN_FW_EFI_MEM_INFO       3
209 #define  XEN_FW_EFI_RT_VERSION     4
210 
211 #define XENPF_firmware_info       50
212 #define XEN_FW_DISK_INFO          1 /* from int 13 AH=08/41/48 */
213 #define XEN_FW_DISK_MBR_SIGNATURE 2 /* from MBR offset 0x1b8 */
214 #define XEN_FW_VBEDDC_INFO        3 /* from int 10 AX=4f15 */
215 #define XEN_FW_EFI_INFO           4 /* from EFI */
216 #define XEN_FW_KBD_SHIFT_FLAGS    5 /* Int16, Fn02: Get keyboard shift flags. */
217 
218 struct xenpf_firmware_info {
219 	/* IN variables. */
220 	uint32_t type;
221 	uint32_t index;
222 	/* OUT variables. */
223 	union {
224 		struct {
225 			/* Int13, Fn48: Check Extensions Present. */
226 			uint8_t device;                   /* %dl: bios device number */
227 			uint8_t version;                  /* %ah: major version      */
228 			uint16_t interface_support;       /* %cx: support bitmap     */
229 			/* Int13, Fn08: Legacy Get Device Parameters. */
230 			uint16_t legacy_max_cylinder;     /* %cl[7:6]:%ch: max cyl # */
231 			uint8_t legacy_max_head;          /* %dh: max head #         */
232 			uint8_t legacy_sectors_per_track; /* %cl[5:0]: max sector #  */
233 			/* Int13, Fn41: Get Device Parameters (as filled into %ds:%esi). */
234 			/* NB. First uint16_t of buffer must be set to buffer size.      */
235 			GUEST_HANDLE(void) edd_params;
236 		} disk_info; /* XEN_FW_DISK_INFO */
237 		struct {
238 			uint8_t device;                   /* bios device number  */
239 			uint32_t mbr_signature;           /* offset 0x1b8 in mbr */
240 		} disk_mbr_signature; /* XEN_FW_DISK_MBR_SIGNATURE */
241 		struct {
242 			/* Int10, AX=4F15: Get EDID info. */
243 			uint8_t capabilities;
244 			uint8_t edid_transfer_time;
245 			/* must refer to 128-byte buffer */
246 			GUEST_HANDLE(uchar) edid;
247 		} vbeddc_info; /* XEN_FW_VBEDDC_INFO */
248 
249 		union xenpf_efi_info {
250 			uint32_t version;
251 			struct {
252 				uint64_t addr;   /* EFI_CONFIGURATION_TABLE */
253 				uint32_t nent;
254 			} cfg;
255 			struct {
256 				uint32_t revision;
257 				uint32_t bufsz;  /* input, in bytes */
258 				GUEST_HANDLE(void) name;
259 				/* UCS-2/UTF-16 string */
260 			} vendor;
261 			struct {
262 				uint64_t addr;
263 				uint64_t size;
264 				uint64_t attr;
265 				uint32_t type;
266 			} mem;
267 		} efi_info; /* XEN_FW_EFI_INFO */
268 
269 		uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
270 	} u;
271 };
272 DEFINE_GUEST_HANDLE_STRUCT(xenpf_firmware_info_t);
273 
274 #define XENPF_enter_acpi_sleep    51
275 struct xenpf_enter_acpi_sleep {
276 	/* IN variables */
277 	uint16_t val_a;             /* PM1a control / sleep type A. */
278 	uint16_t val_b;             /* PM1b control / sleep type B. */
279 	uint32_t sleep_state;       /* Which state to enter (Sn). */
280 #define XENPF_ACPI_SLEEP_EXTENDED 0x00000001
281 	uint32_t flags;             /* XENPF_ACPI_SLEEP_*. */
282 };
283 DEFINE_GUEST_HANDLE_STRUCT(xenpf_enter_acpi_sleep_t);
284 
285 #define XENPF_change_freq         52
286 struct xenpf_change_freq {
287 	/* IN variables */
288 	uint32_t flags; /* Must be zero. */
289 	uint32_t cpu;   /* Physical cpu. */
290 	uint64_t freq;  /* New frequency (Hz). */
291 };
292 DEFINE_GUEST_HANDLE_STRUCT(xenpf_change_freq_t);
293 
294 /*
295  * Get idle times (nanoseconds since boot) for physical CPUs specified in the
296  * @cpumap_bitmap with range [0..@cpumap_nr_cpus-1]. The @idletime array is
297  * indexed by CPU number; only entries with the corresponding @cpumap_bitmap
298  * bit set are written to. On return, @cpumap_bitmap is modified so that any
299  * non-existent CPUs are cleared. Such CPUs have their @idletime array entry
300  * cleared.
301  */
302 #define XENPF_getidletime         53
303 struct xenpf_getidletime {
304 	/* IN/OUT variables */
305 	/* IN: CPUs to interrogate; OUT: subset of IN which are present */
306 	GUEST_HANDLE(uchar) cpumap_bitmap;
307 	/* IN variables */
308 	/* Size of cpumap bitmap. */
309 	uint32_t cpumap_nr_cpus;
310 	/* Must be indexable for every cpu in cpumap_bitmap. */
311 	GUEST_HANDLE(uint64_t) idletime;
312 	/* OUT variables */
313 	/* System time when the idletime snapshots were taken. */
314 	uint64_t now;
315 };
316 DEFINE_GUEST_HANDLE_STRUCT(xenpf_getidletime_t);
317 
318 #define XENPF_set_processor_pminfo      54
319 
320 /* ability bits */
321 #define XEN_PROCESSOR_PM_CX	1
322 #define XEN_PROCESSOR_PM_PX	2
323 #define XEN_PROCESSOR_PM_TX	4
324 
325 /* cmd type */
326 #define XEN_PM_CX   0
327 #define XEN_PM_PX   1
328 #define XEN_PM_TX   2
329 #define XEN_PM_PDC  3
330 /* Px sub info type */
331 #define XEN_PX_PCT   1
332 #define XEN_PX_PSS   2
333 #define XEN_PX_PPC   4
334 #define XEN_PX_PSD   8
335 
336 struct xen_power_register {
337 	uint32_t     space_id;
338 	uint32_t     bit_width;
339 	uint32_t     bit_offset;
340 	uint32_t     access_size;
341 	uint64_t     address;
342 };
343 
344 struct xen_processor_csd {
345 	uint32_t    domain;      /* domain number of one dependent group */
346 	uint32_t    coord_type;  /* coordination type */
347 	uint32_t    num;         /* number of processors in same domain */
348 };
349 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_csd);
350 
351 struct xen_processor_cx {
352 	struct xen_power_register  reg; /* GAS for Cx trigger register */
353 	uint8_t     type;     /* cstate value, c0: 0, c1: 1, ... */
354 	uint32_t    latency;  /* worst latency (ms) to enter/exit this cstate */
355 	uint32_t    power;    /* average power consumption(mW) */
356 	uint32_t    dpcnt;    /* number of dependency entries */
357 	GUEST_HANDLE(xen_processor_csd) dp; /* NULL if no dependency */
358 };
359 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_cx);
360 
361 struct xen_processor_flags {
362 	uint32_t bm_control:1;
363 	uint32_t bm_check:1;
364 	uint32_t has_cst:1;
365 	uint32_t power_setup_done:1;
366 	uint32_t bm_rld_set:1;
367 };
368 
369 struct xen_processor_power {
370 	uint32_t count;  /* number of C state entries in array below */
371 	struct xen_processor_flags flags;  /* global flags of this processor */
372 	GUEST_HANDLE(xen_processor_cx) states; /* supported c states */
373 };
374 
375 struct xen_pct_register {
376 	uint8_t  descriptor;
377 	uint16_t length;
378 	uint8_t  space_id;
379 	uint8_t  bit_width;
380 	uint8_t  bit_offset;
381 	uint8_t  reserved;
382 	uint64_t address;
383 };
384 
385 struct xen_processor_px {
386 	uint64_t core_frequency; /* megahertz */
387 	uint64_t power;      /* milliWatts */
388 	uint64_t transition_latency; /* microseconds */
389 	uint64_t bus_master_latency; /* microseconds */
390 	uint64_t control;        /* control value */
391 	uint64_t status;     /* success indicator */
392 };
393 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_px);
394 
395 struct xen_psd_package {
396 	uint64_t num_entries;
397 	uint64_t revision;
398 	uint64_t domain;
399 	uint64_t coord_type;
400 	uint64_t num_processors;
401 };
402 
403 struct xen_processor_performance {
404 	uint32_t flags;     /* flag for Px sub info type */
405 	uint32_t platform_limit;  /* Platform limitation on freq usage */
406 	struct xen_pct_register control_register;
407 	struct xen_pct_register status_register;
408 	uint32_t state_count;     /* total available performance states */
409 	GUEST_HANDLE(xen_processor_px) states;
410 	struct xen_psd_package domain_info;
411 	uint32_t shared_type;     /* coordination type of this processor */
412 };
413 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_performance);
414 
415 struct xenpf_set_processor_pminfo {
416 	/* IN variables */
417 	uint32_t id;    /* ACPI CPU ID */
418 	uint32_t type;  /* {XEN_PM_CX, XEN_PM_PX} */
419 	union {
420 		struct xen_processor_power          power;/* Cx: _CST/_CSD */
421 		struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS/_PSD */
422 		GUEST_HANDLE(uint32_t)              pdc;
423 	};
424 };
425 DEFINE_GUEST_HANDLE_STRUCT(xenpf_set_processor_pminfo);
426 
427 #define XENPF_get_cpuinfo 55
428 struct xenpf_pcpuinfo {
429 	/* IN */
430 	uint32_t xen_cpuid;
431 	/* OUT */
432 	/* The maxium cpu_id that is present */
433 	uint32_t max_present;
434 #define XEN_PCPU_FLAGS_ONLINE   1
435 	/* Correponding xen_cpuid is not present*/
436 #define XEN_PCPU_FLAGS_INVALID  2
437 	uint32_t flags;
438 	uint32_t apic_id;
439 	uint32_t acpi_id;
440 };
441 DEFINE_GUEST_HANDLE_STRUCT(xenpf_pcpuinfo);
442 
443 #define XENPF_cpu_online	56
444 #define XENPF_cpu_offline	57
445 struct xenpf_cpu_ol {
446 	uint32_t cpuid;
447 };
448 DEFINE_GUEST_HANDLE_STRUCT(xenpf_cpu_ol);
449 
450 #define XENPF_cpu_hotadd	58
451 struct xenpf_cpu_hotadd {
452 	uint32_t apic_id;
453 	uint32_t acpi_id;
454 	uint32_t pxm;
455 };
456 
457 #define XENPF_mem_hotadd	59
458 struct xenpf_mem_hotadd {
459 	uint64_t spfn;
460 	uint64_t epfn;
461 	uint32_t pxm;
462 	uint32_t flags;
463 };
464 
465 #define XENPF_core_parking     60
466 struct xenpf_core_parking {
467 	/* IN variables */
468 #define XEN_CORE_PARKING_SET   1
469 #define XEN_CORE_PARKING_GET   2
470 	uint32_t type;
471 	/* IN variables:  set cpu nums expected to be idled */
472 	/* OUT variables: get cpu nums actually be idled */
473 	uint32_t idle_nums;
474 };
475 DEFINE_GUEST_HANDLE_STRUCT(xenpf_core_parking);
476 
477 struct xen_platform_op {
478 	uint32_t cmd;
479 	uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
480 	union {
481 		struct xenpf_settime           settime;
482 		struct xenpf_add_memtype       add_memtype;
483 		struct xenpf_del_memtype       del_memtype;
484 		struct xenpf_read_memtype      read_memtype;
485 		struct xenpf_microcode_update  microcode;
486 		struct xenpf_platform_quirk    platform_quirk;
487 		struct xenpf_efi_runtime_call  efi_runtime_call;
488 		struct xenpf_firmware_info     firmware_info;
489 		struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
490 		struct xenpf_change_freq       change_freq;
491 		struct xenpf_getidletime       getidletime;
492 		struct xenpf_set_processor_pminfo set_pminfo;
493 		struct xenpf_pcpuinfo          pcpu_info;
494 		struct xenpf_cpu_ol            cpu_ol;
495 		struct xenpf_cpu_hotadd        cpu_add;
496 		struct xenpf_mem_hotadd        mem_add;
497 		struct xenpf_core_parking      core_parking;
498 		uint8_t                        pad[128];
499 	} u;
500 };
501 DEFINE_GUEST_HANDLE_STRUCT(xen_platform_op_t);
502 
503 #endif /* __XEN_PUBLIC_PLATFORM_H__ */
504