1 /* 2 * Copyright (c) 1998-2023 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 _IOKIT_EXCLAVES_H 30 #define _IOKIT_EXCLAVES_H 31 32 #if CONFIG_EXCLAVES 33 34 #include <kern/thread_call.h> 35 #include <libkern/OSTypes.h> 36 #include <stdbool.h> 37 #include <stdint.h> 38 39 #include <IOKit/IOReturn.h> 40 41 #ifdef __cplusplus 42 43 #include <libkern/c++/OSDictionary.h> 44 #include <libkern/c++/OSSymbol.h> 45 46 /* Global IOExclaveProxyState lookup table */ 47 extern OSDictionary *gExclaveProxyStates; 48 extern IORecursiveLock *gExclaveProxyStateLock; 49 extern const OSSymbol * gDARTMapperFunctionSetActive; 50 51 extern "C" { 52 #endif /* __cplusplus */ 53 54 /* Exclave upcall handler arguments */ 55 56 enum IOExclaveInterruptUpcallType { 57 kIOExclaveInterruptUpcallTypeRegister, 58 kIOExclaveInterruptUpcallTypeRemove, 59 kIOExclaveInterruptUpcallTypeEnable 60 }; 61 62 struct IOExclaveInterruptUpcallArgs { 63 int index; 64 enum IOExclaveInterruptUpcallType type; 65 union { 66 struct { 67 // Register an IOIES with no provider for testing purposes 68 bool test_irq; 69 } register_args; 70 struct { 71 bool enable; 72 } enable_args; 73 } data; 74 }; 75 76 enum IOExclaveTimerUpcallType { 77 kIOExclaveTimerUpcallTypeRegister, 78 kIOExclaveTimerUpcallTypeRemove, 79 kIOExclaveTimerUpcallTypeEnable, 80 kIOExclaveTimerUpcallTypeSetTimeout, 81 kIOExclaveTimerUpcallTypeCancelTimeout 82 }; 83 84 struct IOExclaveTimerUpcallArgs { 85 uint32_t timer_id; 86 enum IOExclaveTimerUpcallType type; 87 union { 88 struct { 89 bool enable; 90 } enable_args; 91 struct { 92 bool clock_continuous; 93 AbsoluteTime duration; 94 kern_return_t kr; 95 } set_timeout_args; 96 } data; 97 }; 98 99 enum IOExclaveAsyncNotificationUpcallType { 100 AsyncNotificationUpcallTypeSignal, 101 }; 102 103 struct IOExclaveAsyncNotificationUpcallArgs { 104 enum IOExclaveAsyncNotificationUpcallType type; 105 uint32_t notificationID; 106 }; 107 108 enum IOExclaveMapperOperationUpcallType { 109 MapperActivate, 110 MapperDeactivate, 111 }; 112 113 struct IOExclaveMapperOperationUpcallArgs { 114 enum IOExclaveMapperOperationUpcallType type; 115 uint32_t mapperIndex; 116 }; 117 118 enum IOExclaveANEUpcallType { 119 kIOExclaveANEUpcallTypeSetPowerState, 120 kIOExclaveANEUpcallTypeWorkSubmit, 121 kIOExclaveANEUpcallTypeWorkBegin, 122 kIOExclaveANEUpcallTypeWorkEnd, 123 }; 124 125 struct IOExclaveANEUpcallArgs { 126 enum IOExclaveANEUpcallType type; 127 union { 128 struct { 129 uint32_t desired_state; 130 } setpowerstate_args; 131 struct { 132 uint64_t arg0; 133 uint64_t arg1; 134 uint64_t arg2; 135 } work_args; 136 }; 137 }; 138 139 enum IOExclaveLPWUpcallType { 140 kIOExclaveLPWUpcallTypeCreateAssertion, 141 kIOExclaveLPWUpcallTypeReleaseAssertion, 142 kIOExclaveLPWUpcallTypeRequestRunMode, 143 }; 144 145 struct IOExclaveLPWUpcallArgs { 146 enum IOExclaveLPWUpcallType type; 147 union { 148 struct { 149 uint64_t id_out; 150 } createassertion; 151 struct { 152 uint64_t id; 153 } releaseassertion; 154 struct { 155 uint64_t runmode_mask; 156 } requestrunmode; 157 } data; 158 }; 159 160 /* 161 * Exclave upcall handlers 162 * 163 * id is the registry ID of the proxy IOService. 164 */ 165 bool IOExclaveInterruptUpcallHandler(uint64_t id, struct IOExclaveInterruptUpcallArgs *args); 166 bool IOExclaveTimerUpcallHandler(uint64_t id, struct IOExclaveTimerUpcallArgs *args); 167 bool IOExclaveLockWorkloop(uint64_t id, bool lock); 168 bool IOExclaveAsyncNotificationUpcallHandler(uint64_t id, struct IOExclaveAsyncNotificationUpcallArgs *args); 169 bool IOExclaveMapperOperationUpcallHandler(uint64_t id, struct IOExclaveMapperOperationUpcallArgs *args); 170 bool IOExclaveANEUpcallHandler(uint64_t id, struct IOExclaveANEUpcallArgs *args, bool *result); 171 IOReturn IOExclaveLPWUpcallHandler(struct IOExclaveLPWUpcallArgs *args); 172 173 IOReturn IOExclaveLPWCreateAssertion(uint64_t *id_out, const char *desc); 174 IOReturn IOExclaveLPWReleaseAssertion(uint64_t id); 175 176 /* Test support */ 177 178 struct IOExclaveTestSignalInterruptParam { 179 uint64_t id; 180 uint64_t index; 181 }; 182 void IOExclaveTestSignalInterrupt(thread_call_param_t, thread_call_param_t); 183 184 void exclaves_wait_for_cpu_init(void); 185 186 #ifdef __cplusplus 187 } /* extern "C" */ 188 #endif /* __cplusplus */ 189 190 #endif /* CONFIG_EXCLAVES */ 191 192 #endif /* ! _IOKIT_EXCLAVES_H */ 193