2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * Changes to this API are expected.
33 #ifndef _IOKIT_IOUSERCLIENT_H
34 #define _IOKIT_IOUSERCLIENT_H
36 #include <IOKit/IOTypes.h>
37 #include <IOKit/IOService.h>
38 #include <IOKit/OSMessageNotification.h>
42 kIOUCTypeMask
= 0x0000000f,
43 kIOUCScalarIScalarO
= 0,
44 kIOUCScalarIStructO
= 2,
45 kIOUCStructIStructO
= 3,
46 kIOUCScalarIStructI
= 4
50 @abstract Constant to denote a variable length structure argument to IOUserClient.
51 @constant kIOUCVariableStructureSize Use in the structures IOExternalMethod, IOExternalAsyncMethod, IOExternalMethodDispatch to specify the size of the structure is variable.
54 kIOUCVariableStructureSize
= 0xffffffff
58 typedef IOReturn (IOService::*IOMethod
)(void * p1
, void * p2
, void * p3
,
59 void * p4
, void * p5
, void * p6
);
61 typedef IOReturn (IOService::*IOAsyncMethod
)(OSAsyncReference asyncRef
,
62 void * p1
, void * p2
, void * p3
,
63 void * p4
, void * p5
, void * p6
);
65 typedef IOReturn (IOService::*IOTrap
)(void * p1
, void * p2
, void * p3
,
66 void * p4
, void * p5
, void * p6
);
68 struct IOExternalMethod
{
76 struct IOExternalAsyncMethod
{
84 struct IOExternalTrap
{
90 kIOUserNotifyMaxMessageSize
= 64
93 // keys for clientHasPrivilege
94 #define kIOClientPrivilegeAdministrator "root"
95 #define kIOClientPrivilegeLocalUser "local"
98 @abstract Constants to specify the maximum number of scalar arguments in the IOExternalMethodArguments structure. These constants are documentary since the scalarInputCount, scalarOutputCount fields reflect the actual number passed.
99 @constant kIOExternalMethodScalarInputCountMax The maximum number of scalars able to passed on input.
100 @constant kIOExternalMethodScalarOutputCountMax The maximum number of scalars able to passed on output.
103 kIOExternalMethodScalarInputCountMax
= 16,
104 kIOExternalMethodScalarOutputCountMax
= 16,
108 struct IOExternalMethodArguments
114 mach_port_t asyncWakePort
;
115 io_user_reference_t
* asyncReference
;
116 uint32_t asyncReferenceCount
;
118 const uint64_t * scalarInput
;
119 uint32_t scalarInputCount
;
121 const void * structureInput
;
122 uint32_t structureInputSize
;
124 IOMemoryDescriptor
* structureInputDescriptor
;
126 uint64_t * scalarOutput
;
127 uint32_t scalarOutputCount
;
129 void * structureOutput
;
130 uint32_t structureOutputSize
;
132 IOMemoryDescriptor
* structureOutputDescriptor
;
133 uint32_t structureOutputDescriptorSize
;
135 uint32_t __reserved
[32];
138 typedef IOReturn (*IOExternalMethodAction
)(OSObject
* target
, void * reference
,
139 IOExternalMethodArguments
* arguments
);
140 struct IOExternalMethodDispatch
142 IOExternalMethodAction function
;
143 uint32_t checkScalarInputCount
;
144 uint32_t checkStructureInputSize
;
145 uint32_t checkScalarOutputCount
;
146 uint32_t checkStructureOutputSize
;
150 #define IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION 1
151 kIOExternalMethodArgumentsCurrentVersion
= IO_EXTERNAL_METHOD_ARGUMENTS_CURRENT_VERSION
157 @abstract Provides a basis for communication between client applications and I/O Kit objects.
161 class IOUserClient
: public IOService
163 OSDeclareAbstractStructors(IOUserClient
)
166 /*! @struct ExpansionData
167 @discussion This structure will be used to expand the capablilties of this class in the future.
169 struct ExpansionData
{ };
172 Reserved for future use. (Internal use only)
174 ExpansionData
* reserved
;
178 UInt8 sharedInstance
;
179 UInt8 __reservedA
[3];
180 void * __reserved
[7];
182 virtual IOReturn
externalMethod( uint32_t selector
, IOExternalMethodArguments
* arguments
,
183 IOExternalMethodDispatch
* dispatch
= 0, OSObject
* target
= 0, void * reference
= 0 );
184 OSMetaClassDeclareReservedUsed(IOUserClient
, 0);
188 OSMetaClassDeclareReservedUnused(IOUserClient
, 1);
189 OSMetaClassDeclareReservedUnused(IOUserClient
, 2);
190 OSMetaClassDeclareReservedUnused(IOUserClient
, 3);
191 OSMetaClassDeclareReservedUnused(IOUserClient
, 4);
192 OSMetaClassDeclareReservedUnused(IOUserClient
, 5);
193 OSMetaClassDeclareReservedUnused(IOUserClient
, 6);
194 OSMetaClassDeclareReservedUnused(IOUserClient
, 7);
195 OSMetaClassDeclareReservedUnused(IOUserClient
, 8);
196 OSMetaClassDeclareReservedUnused(IOUserClient
, 9);
197 OSMetaClassDeclareReservedUnused(IOUserClient
, 10);
198 OSMetaClassDeclareReservedUnused(IOUserClient
, 11);
199 OSMetaClassDeclareReservedUnused(IOUserClient
, 12);
200 OSMetaClassDeclareReservedUnused(IOUserClient
, 13);
201 OSMetaClassDeclareReservedUnused(IOUserClient
, 14);
202 OSMetaClassDeclareReservedUnused(IOUserClient
, 15);
205 static IOReturn
sendAsyncResult(OSAsyncReference reference
,
206 IOReturn result
, void *args
[], UInt32 numArgs
);
207 static void setAsyncReference(OSAsyncReference asyncRef
,
208 mach_port_t wakePort
,
209 void *callback
, void *refcon
);
211 static IOReturn
sendAsyncResult64(OSAsyncReference64 reference
,
212 IOReturn result
, io_user_reference_t args
[], UInt32 numArgs
);
213 static void setAsyncReference64(OSAsyncReference64 asyncRef
,
214 mach_port_t wakePort
,
215 mach_vm_address_t callback
, io_user_reference_t refcon
);
218 static void initialize( void );
220 static void destroyUserReferences( OSObject
* obj
);
222 static IOReturn
clientHasPrivilege( void * securityToken
,
223 const char * privilegeName
);
226 virtual bool init( OSDictionary
* dictionary
);
227 // Currently ignores the all args, just passes up to IOService::init()
228 virtual bool initWithTask(
229 task_t owningTask
, void * securityToken
, UInt32 type
,
230 OSDictionary
* properties
);
232 virtual bool initWithTask(
233 task_t owningTask
, void * securityToken
, UInt32 type
);
237 virtual IOReturn
clientClose( void );
238 virtual IOReturn
clientDied( void );
240 virtual IOService
* getService( void );
242 virtual IOReturn
registerNotificationPort(
243 mach_port_t port
, UInt32 type
, UInt32 refCon
);
245 virtual IOReturn
getNotificationSemaphore( UInt32 notification_type
,
246 semaphore_t
* semaphore
);
248 virtual IOReturn
connectClient( IOUserClient
* client
);
250 // memory will be released by user client when last map is destroyed
251 virtual IOReturn
clientMemoryForType( UInt32 type
,
252 IOOptionBits
* options
,
253 IOMemoryDescriptor
** memory
);
255 virtual IOMemoryMap
* mapClientMemory( IOOptionBits type
,
257 IOOptionBits mapFlags
= kIOMapAnywhere
,
258 IOVirtualAddress atAddress
= 0 );
260 IOMemoryMap
* mapClientMemory64( IOOptionBits type
,
262 IOOptionBits mapFlags
= kIOMapAnywhere
,
263 mach_vm_address_t atAddress
= 0 );
266 @function removeMappingForDescriptor
267 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.
268 @param memory The memory descriptor instance previously returned by the implementation of clientMemoryForType().
269 @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.
271 IOMemoryMap
* removeMappingForDescriptor(IOMemoryDescriptor
* memory
);
274 @function exportObjectToClient
275 Make an arbitrary OSObject available to the client task.
276 @param task The task.
277 @param obj The object we want to export to the client.
278 @param clientObj Returned value is the client's port name.
280 virtual IOReturn
exportObjectToClient(task_t task
,
281 OSObject
*obj
, io_object_t
*clientObj
);
283 // Old methods for accessing method vector backward compatiblility only
284 virtual IOExternalMethod
*
285 getExternalMethodForIndex( UInt32 index
);
286 virtual IOExternalAsyncMethod
*
287 getExternalAsyncMethodForIndex( UInt32 index
);
289 // Methods for accessing method vector.
290 virtual IOExternalMethod
*
291 getTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
);
292 virtual IOExternalAsyncMethod
*
293 getAsyncTargetAndMethodForIndex( IOService
** targetP
, UInt32 index
);
295 // Methods for accessing trap vector - old and new style
296 virtual IOExternalTrap
*
297 getExternalTrapForIndex( UInt32 index
);
298 virtual IOExternalTrap
*
299 getTargetAndTrapForIndex( IOService
**targetP
, UInt32 index
);
302 #endif /* ! _IOKIT_IOUSERCLIENT_H */