1/*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _KERN_HVG_HYPERCALL_H_
30#define _KERN_HVG_HYPERCALL_H_
31
32#include <os/base.h>
33#include <stdint.h>
34#include <stdbool.h>
35#include <uuid/uuid.h>
36
37/* Architecture-independent definitions (exported to userland) */
38
39/*
40 * Apple Hypercall arguments
41 */
42typedef struct hvg_hcall_args {
43 uint64_t args[6];
44} hvg_hcall_args_t;
45
46
47/*
48 * Apple Hypercall return output
49 */
50typedef struct hvg_hcall_output {
51 uint64_t regs[7];
52} hvg_hcall_output_t;
53
54
55/*
56 * Apple Hypercall return code
57 */
58
59OS_CLOSED_ENUM(hvg_hcall_return, uint32_t,
60 HVG_HCALL_SUCCESS = 0x0000, /* The call succeeded */
61 HVG_HCALL_ACCESS_DENIED = 0x0001, /* Invalid access right */
62 HVG_HCALL_INVALID_CODE = 0x0002, /* Hypercall code not recognized */
63 HVG_HCALL_INVALID_PARAMETER = 0x0003, /* Specified register value not valid */
64 HVG_HCALL_IO_FAILED = 0x0004, /* Input/output error */
65 HVG_HCALL_FEAT_DISABLED = 0x0005, /* Feature not available */
66 HVG_HCALL_UNSUPPORTED = 0x0006, /* Hypercall not supported */
67 );
68
69
70/*
71 * Apple Hypercall call code
72 */
73
74OS_CLOSED_ENUM(hvg_hcall_code, uint32_t,
75 HVG_HCALL_TRIGGER_DUMP = 0x0001, /* Collect guest dump */
76 HVG_HCALL_SET_COREDUMP_DATA = 0x0002, /* Set necessary info for reliable coredump */
77 HVG_HCALL_GET_MABS_OFFSET = 0x0003, /* Determine mach_absolute_time offset */
78 HVG_HCALL_GET_BOOTSESSIONUUID = 0x0004, /* Read host boot sesssion ID */
79 HVG_HCALL_VCPU_WFK = 0x0005, /* Wait-for-kick (or exception) */
80 HVG_HCALL_VCPU_KICK = 0x0006, /* Kick a vcpu */
81 HVG_HCALL_COUNT
82 );
83
84/*
85 * Options for collecting kernel vmcore
86 */
87
88OS_CLOSED_OPTIONS(hvg_hcall_dump_option, uint32_t,
89 HVG_HCALL_DUMP_OPTION_REGULAR = 0x0001 /* Regular dump-guest-memory */
90 );
91
92typedef struct hvg_hcall_vmcore_file {
93 char tag[57]; /* 7 64-bit registers plus 1 byte for '\0' */
94} hvg_hcall_vmcore_file_t;
95
96
97#ifdef XNU_KERNEL_PRIVATE
98
99/*
100 * For XNU kernel use only (omitted from userland headers)
101 */
102
103extern bool hvg_is_hcall_available(hvg_hcall_code_t);
104
105extern void hvg_hcall_set_coredump_data(void);
106
107extern hvg_hcall_return_t hvg_hcall_trigger_dump(hvg_hcall_vmcore_file_t *vmcore,
108 const hvg_hcall_dump_option_t dump_option);
109extern hvg_hcall_return_t hvg_hcall_get_bootsessionuuid(uuid_string_t uuid);
110extern hvg_hcall_return_t hvg_hcall_get_mabs_offset(uint64_t *mabs_offset);
111extern void hvg_hc_kick_cpu(unsigned int cpu_id);
112extern void hvg_hc_wait_for_kick(unsigned int ien);
113
114#endif /* XNU_KERNEL_PRIVATE */
115
116#endif /* _KERN_HV_HYPERCALL_H_ */
117