xref: /xnu-12377.61.12/iokit/IOKit/skywalk/IOSkywalkSupport.h (revision 4d495c6e23c53686cf65f45067f79024cf5dcee8)
1 /*
2  * Copyright (c) 2015-2022 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 #ifndef __IOSKYWALKSUPPORT_H
29 #define __IOSKYWALKSUPPORT_H
30 
31 #ifdef KERNEL_PRIVATE
32 #include <sys/cdefs.h>
33 #include <IOKit/IOReturn.h>
34 
35 #ifdef __cplusplus
36 class IOMemoryDescriptor;
37 typedef IOMemoryDescriptor *        IOSKMemoryRef;
38 class IOSKArena;
39 typedef IOSKArena *                 IOSKArenaRef;
40 class IOSKRegion;
41 typedef IOSKRegion *                IOSKRegionRef;
42 class IOSKMapper;
43 typedef IOSKMapper *                IOSKMapperRef;
44 #define IOSK_CONSUMED LIBKERN_CONSUMED
45 #else /* !__cplusplus */
46 typedef struct IOMemoryDescriptor * IOSKMemoryRef;
47 typedef struct IOSKArena *          IOSKArenaRef;
48 typedef struct IOSKRegion *         IOSKRegionRef;
49 typedef struct IOSKMapper *         IOSKMapperRef;
50 #define IOSK_CONSUMED
51 #endif /* !__cplusplus */
52 
53 typedef IOSKMemoryRef   IOSKMemoryDescriptor;
54 
55 #if defined(__x86_64__) && defined(__cplusplus)
56 const OSSymbol *  IOSKCopyKextIdentifierWithAddress( vm_address_t address );
57 #endif
58 
59 #ifdef XNU_KERNEL_PRIVATE
60 #ifdef __cplusplus
61 class IOMemoryMap;
62 typedef IOMemoryMap *               IOSKMemoryMapRef;
63 #else /* !__cplusplus */
64 typedef struct IOMemoryMap *        IOSKMemoryMapRef;
65 #endif /* !__cplusplus */
66 
67 typedef IOSKMemoryRef   IOSKMemoryArrayRef;
68 typedef IOSKMemoryRef   IOSKMemoryBufferRef;
69 typedef uint32_t        IOSKSize;
70 typedef uint32_t        IOSKIndex;
71 typedef uint32_t        IOSKCount;
72 typedef uint32_t        IOSKOffset;
73 
74 typedef struct {
75 	boolean_t user_writable;        /* writable by user task */
76 	boolean_t kernel_writable;      /* writable by kernel task */
77 	boolean_t iodir_in;             /* direction: device-to-host */
78 	boolean_t iodir_out;            /* direction: host-to-device */
79 	boolean_t purgeable;            /* purgeable (not wired) */
80 	boolean_t inhibitCache;         /* cache-inhibit */
81 	boolean_t physcontig;           /* physically contiguous */
82 	boolean_t puredata;             /* data only, no pointers */
83 	boolean_t threadSafe;           /* thread safe */
84 	boolean_t memtag;               /* memtag enabled */
85 } IOSKMemoryBufferSpec;
86 
87 typedef struct {
88 	boolean_t noRedirect;
89 } IOSKRegionSpec;
90 
91 __BEGIN_DECLS
92 
93 IOSKMemoryBufferRef IOSKMemoryBufferCreate( mach_vm_size_t capacity,
94     const IOSKMemoryBufferSpec * spec,
95     mach_vm_address_t * kvaddr );
96 
97 IOSKMemoryArrayRef  IOSKMemoryArrayCreate( const IOSKMemoryRef refs[__counted_by(count)],
98     uint32_t count );
99 
100 void                IOSKMemoryDestroy( IOSK_CONSUMED IOSKMemoryRef reference );
101 
102 IOSKMemoryMapRef    IOSKMemoryMapToTask( IOSKMemoryRef reference,
103     task_t intoTask,
104     mach_vm_address_t * mapAddr,
105     mach_vm_size_t * mapSize );
106 
107 IOSKMemoryMapRef    IOSKMemoryMapToKernelTask( IOSKMemoryRef reference,
108     mach_vm_address_t * mapAddr,
109     mach_vm_size_t * mapSize );
110 
111 void                IOSKMemoryMapDestroy(
112 	IOSK_CONSUMED IOSKMemoryMapRef reference );
113 
114 IOReturn            IOSKMemoryReclaim( IOSKMemoryRef reference );
115 IOReturn            IOSKMemoryDiscard( IOSKMemoryRef reference );
116 
117 IOReturn            IOSKMemoryWire( IOSKMemoryRef reference );
118 IOReturn            IOSKMemoryUnwire( IOSKMemoryRef reference );
119 
120 IOSKArenaRef
121 IOSKArenaCreate( IOSKRegionRef * regionList, IOSKCount regionCount );
122 
123 void
124 IOSKArenaDestroy( IOSK_CONSUMED IOSKArenaRef arena );
125 
126 void
127 IOSKArenaRedirect( IOSKArenaRef arena );
128 
129 IOSKRegionRef
130 IOSKRegionCreate( const IOSKRegionSpec * regionSpec,
131     IOSKSize segmentSize, IOSKCount segmentCount );
132 
133 void
134 IOSKRegionDestroy( IOSK_CONSUMED IOSKRegionRef region );
135 
136 IOReturn
137 IOSKRegionSetBuffer( IOSKRegionRef region, IOSKIndex segmentIndex,
138     IOSKMemoryBufferRef buffer );
139 
140 void
141 IOSKRegionClearBuffer( IOSKRegionRef region, IOSKIndex segmentIndex );
142 
143 void
144 IOSKRegionClearBufferDebug( IOSKRegionRef region, IOSKIndex segmentIndex,
145     IOSKMemoryBufferRef * prevBufferRef );
146 
147 IOSKMapperRef
148 IOSKMapperCreate( IOSKArenaRef arena, task_t task );
149 
150 void
151 IOSKMapperDestroy( IOSK_CONSUMED IOSKMapperRef mapper );
152 
153 void
154 IOSKMapperRedirect( IOSKMapperRef mapper );
155 
156 IOReturn
157 IOSKMapperGetAddress( IOSKMapperRef mapper,
158     mach_vm_address_t * address, mach_vm_size_t * size );
159 
160 boolean_t
161 IOSKBufferIsWired( IOSKMemoryBufferRef buffer );
162 
163 __END_DECLS
164 #endif /* XNU_KERNEL_PRIVATE */
165 #endif /* KERNEL_PRIVATE */
166 #endif /* __IOSKYWALKSUPPORT_H */
167