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 #ifdef __cplusplus 40 41 #include <libkern/c++/OSDictionary.h> 42 #include <libkern/c++/OSSymbol.h> 43 44 /* Global IOExclaveProxyState lookup table */ 45 extern OSDictionary *gExclaveProxyStates; 46 extern IORecursiveLock *gExclaveProxyStateLock; 47 extern const OSSymbol * gDARTMapperFunctionSetActive; 48 49 extern "C" { 50 #endif /* __cplusplus */ 51 52 /* Exclave upcall handler arguments */ 53 54 enum IOExclaveInterruptUpcallType { 55 kIOExclaveInterruptUpcallTypeRegister, 56 kIOExclaveInterruptUpcallTypeRemove, 57 kIOExclaveInterruptUpcallTypeEnable 58 }; 59 60 struct IOExclaveInterruptUpcallArgs { 61 int index; 62 enum IOExclaveInterruptUpcallType type; 63 union { 64 struct { 65 // Register an IOIES with no provider for testing purposes 66 bool test_irq; 67 } register_args; 68 struct { 69 bool enable; 70 } enable_args; 71 } data; 72 }; 73 74 enum IOExclaveTimerUpcallType { 75 kIOExclaveTimerUpcallTypeRegister, 76 kIOExclaveTimerUpcallTypeRemove, 77 kIOExclaveTimerUpcallTypeEnable, 78 kIOExclaveTimerUpcallTypeSetTimeout, 79 kIOExclaveTimerUpcallTypeCancelTimeout 80 }; 81 82 struct IOExclaveTimerUpcallArgs { 83 uint32_t timer_id; 84 enum IOExclaveTimerUpcallType type; 85 union { 86 struct { 87 bool enable; 88 } enable_args; 89 struct { 90 bool clock_continuous; 91 AbsoluteTime duration; 92 kern_return_t kr; 93 } set_timeout_args; 94 } data; 95 }; 96 97 enum IOExclaveAsyncNotificationUpcallType { 98 AsyncNotificationUpcallTypeSignal, 99 }; 100 101 struct IOExclaveAsyncNotificationUpcallArgs { 102 enum IOExclaveAsyncNotificationUpcallType type; 103 uint32_t notificationID; 104 }; 105 106 enum IOExclaveMapperOperationUpcallType { 107 MapperActivate, 108 MapperDeactivate, 109 }; 110 111 struct IOExclaveMapperOperationUpcallArgs { 112 enum IOExclaveMapperOperationUpcallType type; 113 uint32_t mapperIndex; 114 }; 115 116 enum IOExclaveANEUpcallType { 117 kIOExclaveANEUpcallTypeSetPowerState, 118 kIOExclaveANEUpcallTypeWorkSubmit, 119 kIOExclaveANEUpcallTypeWorkBegin, 120 kIOExclaveANEUpcallTypeWorkEnd, 121 }; 122 123 struct IOExclaveANEUpcallArgs { 124 enum IOExclaveANEUpcallType type; 125 union { 126 struct { 127 uint32_t desired_state; 128 } setpowerstate_args; 129 struct { 130 uint64_t arg0; 131 uint64_t arg1; 132 uint64_t arg2; 133 } work_args; 134 }; 135 }; 136 137 /* 138 * Exclave upcall handlers 139 * 140 * id is the registry ID of the proxy IOService. 141 */ 142 bool IOExclaveInterruptUpcallHandler(uint64_t id, struct IOExclaveInterruptUpcallArgs *args); 143 bool IOExclaveTimerUpcallHandler(uint64_t id, struct IOExclaveTimerUpcallArgs *args); 144 bool IOExclaveLockWorkloop(uint64_t id, bool lock); 145 bool IOExclaveAsyncNotificationUpcallHandler(uint64_t id, struct IOExclaveAsyncNotificationUpcallArgs *args); 146 bool IOExclaveMapperOperationUpcallHandler(uint64_t id, struct IOExclaveMapperOperationUpcallArgs *args); 147 bool IOExclaveANEUpcallHandler(uint64_t id, struct IOExclaveANEUpcallArgs *args, bool *result); 148 149 /* Test support */ 150 151 struct IOExclaveTestSignalInterruptParam { 152 uint64_t id; 153 uint64_t index; 154 }; 155 void IOExclaveTestSignalInterrupt(thread_call_param_t, thread_call_param_t); 156 157 void exclaves_wait_for_cpu_init(void); 158 159 #ifdef __cplusplus 160 } /* extern "C" */ 161 #endif /* __cplusplus */ 162 163 #endif /* CONFIG_EXCLAVES */ 164 165 #endif /* ! _IOKIT_EXCLAVES_H */ 166