xref: /xnu-8020.140.41/iokit/IOKit/skywalk/IOSkywalkSupport.h (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1 /*
2  * Copyright (c) 2015-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 #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 } IOSKMemoryBufferSpec;
84 
85 typedef struct {
86 	boolean_t noRedirect;
87 } IOSKRegionSpec;
88 
89 __BEGIN_DECLS
90 
91 IOSKMemoryBufferRef IOSKMemoryBufferCreate( mach_vm_size_t capacity,
92     const IOSKMemoryBufferSpec * spec,
93     mach_vm_address_t * kvaddr );
94 
95 IOSKMemoryArrayRef  IOSKMemoryArrayCreate( const IOSKMemoryRef refs[],
96     uint32_t count );
97 
98 void                IOSKMemoryDestroy( IOSK_CONSUMED IOSKMemoryRef reference );
99 
100 IOSKMemoryMapRef    IOSKMemoryMapToTask( IOSKMemoryRef reference,
101     task_t intoTask,
102     mach_vm_address_t * mapAddr,
103     mach_vm_size_t * mapSize );
104 
105 IOSKMemoryMapRef    IOSKMemoryMapToKernelTask( IOSKMemoryRef reference,
106     mach_vm_address_t * mapAddr,
107     mach_vm_size_t * mapSize );
108 
109 void                IOSKMemoryMapDestroy(
110 	IOSK_CONSUMED IOSKMemoryMapRef reference );
111 
112 IOReturn            IOSKMemoryReclaim( IOSKMemoryRef reference );
113 IOReturn            IOSKMemoryDiscard( IOSKMemoryRef reference );
114 
115 IOReturn            IOSKMemoryWire( IOSKMemoryRef reference );
116 IOReturn            IOSKMemoryUnwire( IOSKMemoryRef reference );
117 
118 IOSKArenaRef
119 IOSKArenaCreate( IOSKRegionRef * regionList, IOSKCount regionCount );
120 
121 void
122 IOSKArenaDestroy( IOSK_CONSUMED IOSKArenaRef arena );
123 
124 void
125 IOSKArenaRedirect( IOSKArenaRef arena );
126 
127 IOSKRegionRef
128 IOSKRegionCreate( const IOSKRegionSpec * regionSpec,
129     IOSKSize segmentSize, IOSKCount segmentCount );
130 
131 void
132 IOSKRegionDestroy( IOSK_CONSUMED IOSKRegionRef region );
133 
134 IOReturn
135 IOSKRegionSetBuffer( IOSKRegionRef region, IOSKIndex segmentIndex,
136     IOSKMemoryBufferRef buffer );
137 
138 void
139 IOSKRegionClearBuffer( IOSKRegionRef region, IOSKIndex segmentIndex );
140 
141 void
142 IOSKRegionClearBufferDebug( IOSKRegionRef region, IOSKIndex segmentIndex,
143     IOSKMemoryBufferRef * prevBufferRef );
144 
145 IOSKMapperRef
146 IOSKMapperCreate( IOSKArenaRef arena, task_t task );
147 
148 void
149 IOSKMapperDestroy( IOSK_CONSUMED IOSKMapperRef mapper );
150 
151 void
152 IOSKMapperRedirect( IOSKMapperRef mapper );
153 
154 IOReturn
155 IOSKMapperGetAddress( IOSKMapperRef mapper,
156     mach_vm_address_t * address, mach_vm_size_t * size );
157 
158 boolean_t
159 IOSKBufferIsWired( IOSKMemoryBufferRef buffer );
160 
161 __END_DECLS
162 #endif /* XNU_KERNEL_PRIVATE */
163 #endif /* KERNEL_PRIVATE */
164 #endif /* __IOSKYWALKSUPPORT_H */
165