]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOUserClient.h
cbf9d4969f03e849087268560b407479d2622fcf
[apple/xnu.git] / iokit / IOKit / IOUserClient.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Changes to this API are expected.
25 */
26
27 #ifndef _IOKIT_IOUSERCLIENT_H
28 #define _IOKIT_IOUSERCLIENT_H
29
30 #include <IOKit/IOTypes.h>
31 #include <IOKit/IOService.h>
32 #include <IOKit/OSMessageNotification.h>
33
34
35 enum {
36 kIOUCTypeMask = 0x0000000f,
37 kIOUCScalarIScalarO = 0,
38 kIOUCScalarIStructO = 2,
39 kIOUCStructIStructO = 3,
40 kIOUCScalarIStructI = 4
41 };
42
43 typedef IOReturn (IOService::*IOMethod)(void * p1, void * p2, void * p3,
44 void * p4, void * p5, void * p6 );
45
46 typedef IOReturn (IOService::*IOAsyncMethod)(OSAsyncReference asyncRef,
47 void * p1, void * p2, void * p3,
48 void * p4, void * p5, void * p6 );
49
50 typedef IOReturn (IOService::*IOTrap)(void * p1, void * p2, void * p3,
51 void * p4, void * p5, void * p6 );
52
53 struct IOExternalMethod {
54 IOService * object;
55 IOMethod func;
56 IOOptionBits flags;
57 IOByteCount count0;
58 IOByteCount count1;
59 };
60
61 struct IOExternalAsyncMethod {
62 IOService * object;
63 IOAsyncMethod func;
64 IOOptionBits flags;
65 IOByteCount count0;
66 IOByteCount count1;
67 };
68
69 struct IOExternalTrap {
70 IOService * object;
71 IOTrap func;
72 };
73
74 enum {
75 kIOUserNotifyMaxMessageSize = 64
76 };
77
78 // keys for clientHasPrivilege
79 #define kIOClientPrivilegeAdministrator "root"
80 #define kIOClientPrivilegeLocalUser "local"
81
82 /*!
83 @class IOUserClient
84 @abstract Provides a basis for communication between client applications and I/O Kit objects.
85 */
86
87
88 class IOUserClient : public IOService
89 {
90 OSDeclareAbstractStructors(IOUserClient)
91
92 protected:
93 /*! @struct ExpansionData
94 @discussion This structure will be used to expand the capablilties of this class in the future.
95 */
96 struct ExpansionData { };
97
98 /*! @var reserved
99 Reserved for future use. (Internal use only)
100 */
101 ExpansionData * reserved;
102
103 public:
104 OSSet * mappings;
105 UInt8 sharedInstance;
106
107 UInt8 __reservedA[3];
108 void * __reserved[7];
109
110 private:
111 OSMetaClassDeclareReservedUnused(IOUserClient, 0);
112 OSMetaClassDeclareReservedUnused(IOUserClient, 1);
113 OSMetaClassDeclareReservedUnused(IOUserClient, 2);
114 OSMetaClassDeclareReservedUnused(IOUserClient, 3);
115 OSMetaClassDeclareReservedUnused(IOUserClient, 4);
116 OSMetaClassDeclareReservedUnused(IOUserClient, 5);
117 OSMetaClassDeclareReservedUnused(IOUserClient, 6);
118 OSMetaClassDeclareReservedUnused(IOUserClient, 7);
119 OSMetaClassDeclareReservedUnused(IOUserClient, 8);
120 OSMetaClassDeclareReservedUnused(IOUserClient, 9);
121 OSMetaClassDeclareReservedUnused(IOUserClient, 10);
122 OSMetaClassDeclareReservedUnused(IOUserClient, 11);
123 OSMetaClassDeclareReservedUnused(IOUserClient, 12);
124 OSMetaClassDeclareReservedUnused(IOUserClient, 13);
125 OSMetaClassDeclareReservedUnused(IOUserClient, 14);
126 OSMetaClassDeclareReservedUnused(IOUserClient, 15);
127
128 protected:
129 static IOReturn sendAsyncResult(OSAsyncReference reference,
130 IOReturn result, void *args[], UInt32 numArgs);
131 static void setAsyncReference(OSAsyncReference asyncRef,
132 mach_port_t wakePort,
133 void *callback, void *refcon);
134 public:
135
136 static void initialize( void );
137
138 static void destroyUserReferences( OSObject * obj );
139
140 static IOReturn clientHasPrivilege( void * securityToken,
141 const char * privilegeName );
142
143 #if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
144 virtual bool init();
145 virtual bool init( OSDictionary * dictionary );
146 #endif
147 // Currently ignores the all args, just passes up to IOService::init()
148 virtual bool initWithTask(
149 task_t owningTask, void * securityToken, UInt32 type,
150 OSDictionary * properties);
151
152 virtual bool initWithTask(
153 task_t owningTask, void * securityToken, UInt32 type);
154
155 virtual void free();
156
157 virtual IOReturn clientClose( void );
158 virtual IOReturn clientDied( void );
159
160 virtual IOService * getService( void );
161
162 virtual IOReturn registerNotificationPort(
163 mach_port_t port, UInt32 type, UInt32 refCon );
164
165 virtual IOReturn getNotificationSemaphore( UInt32 notification_type,
166 semaphore_t * semaphore );
167
168 virtual IOReturn connectClient( IOUserClient * client );
169
170 // memory will be released by user client when last map is destroyed
171 virtual IOReturn clientMemoryForType( UInt32 type,
172 IOOptionBits * options,
173 IOMemoryDescriptor ** memory );
174
175 virtual IOMemoryMap * mapClientMemory( IOOptionBits type,
176 task_t task,
177 IOOptionBits mapFlags = kIOMapAnywhere,
178 IOVirtualAddress atAddress = 0 );
179
180 /*!
181 @function removeMappingForDescriptor
182 Remove the first mapping created from the memory descriptor returned by clientMemoryForType() from IOUserClient's list of mappings. If such a mapping exists, it is retained and the reference currently held by IOUserClient is returned to the caller.
183 @param memory The memory descriptor instance previously returned by the implementation of clientMemoryForType().
184 @result A reference to the first IOMemoryMap instance found in the list of mappings created by IOUserClient from that passed memory descriptor is returned, or zero if none exist. The caller should release this reference.
185 */
186 IOMemoryMap * removeMappingForDescriptor(IOMemoryDescriptor * memory);
187
188 /*!
189 @function exportObjectToClient
190 Make an arbitrary OSObject available to the client task.
191 @param task The task.
192 @param obj The object we want to export to the client.
193 @param clientObj Returned value is the client's port name.
194 */
195 virtual IOReturn exportObjectToClient(task_t task,
196 OSObject *obj, io_object_t *clientObj);
197
198 // Old methods for accessing method vector backward compatiblility only
199 virtual IOExternalMethod *
200 getExternalMethodForIndex( UInt32 index );
201 virtual IOExternalAsyncMethod *
202 getExternalAsyncMethodForIndex( UInt32 index );
203
204 // Methods for accessing method vector.
205 virtual IOExternalMethod *
206 getTargetAndMethodForIndex( IOService ** targetP, UInt32 index );
207 virtual IOExternalAsyncMethod *
208 getAsyncTargetAndMethodForIndex( IOService ** targetP, UInt32 index );
209
210 // Methods for accessing trap vector - old and new style
211 virtual IOExternalTrap *
212 getExternalTrapForIndex( UInt32 index );
213 virtual IOExternalTrap *
214 getTargetAndTrapForIndex( IOService **targetP, UInt32 index );
215 };
216
217 #endif /* ! _IOKIT_IOUSERCLIENT_H */
218