Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/i386/include/IOKit/usb/IOUSBHIDDriver.h

Source at commit 1129 created 12 years 11 months ago.
By meklort, Change options.o so that it reloads the system config as well. Also change it so that it uses that config for variables (NOTE: if the calue exists in chameleonConfig, it's used instead.
1/*
2 * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef IOUSBHIDDRIVER_H
25#define IOUSBHIDDRIVER_H
26
27#include <IOKit/IOBufferMemoryDescriptor.h>
28
29#include <IOKit/hid/IOHIDDevice.h>
30
31#include <IOKit/usb/IOUSBBus.h>
32#include <IOKit/usb/IOUSBInterface.h>
33#include <IOKit/usb/USB.h>
34
35
36#define ENABLE_HIDREPORT_LOGGING0
37
38// Report types from low level USB:
39//from USBSpec.h:
40// enum {
41// kHIDRtInputReport= 1,
42// kHIDRtOutputReport= 2,
43// kHIDRtFeatureReport= 3
44// };
45//
46//from IOHIDDescriptorParser.h:
47// // types of HID reports (input, output, feature)
48// enum
49// {
50// kHIDInputReport= 1,
51// kHIDOutputReport,
52// kHIDFeatureReport,
53// kHIDUnknownReport=255
54// };
55//
56// Report types from high level HID Manager:
57//from IOHIDKeys.h:
58// enum IOHIDReportType
59// {
60// kIOHIDReportTypeInput = 0,
61// kIOHIDReportTypeOutput,
62// kIOHIDReportTypeFeature,
63// kIOHIDReportTypeCount
64// };
65//
66#define HIDMGR2USBREPORTTYPE(x) (x + 1)
67#define USB2HIDMGRREPORTTYPE(x) (x - 1)
68
69
70// Note: In other Neptune files, kMaxHIDReportSize was defined as 64. But Ferg & Keithen were unable to
71// find that value in the USB HID 1.1 specs. Brent had previously changed it to 256 in the OS 9 HID Driver
72// to allow for reports spanning multiple packets. 256 may be no more a hard and fast limit, but it's
73// working for now in OS 9.
74#define kMaxHIDReportSize 256// Max packet size = 8 for low speed & 64 for high speed.
75#define kHIDDriverRetryCount3
76#definekUSBHIDReportLoggingLevel"USB HID Report Logging Level"
77
78
79// power states for the driver (awake or suspended)
80enum
81{
82kUSBHIDPowerStateOff= 0,
83kUSBHIDPowerStateRestart= 1,
84kUSBHIDPowerStateSleep= 2,// this could be system sleep or idle sleep
85kUSBHIDPowerStateLowPower= 3,// this is idling
86kUSBHIDPowerStateOn= 4,// this is fully on
87kUSBHIDNumberPowerStates= 5
88};
89
90
91/*!
92 @class IOUSBHIDDriver
93 @abstract Driver that matches to USB HID devices.
94 @discussion This class can be overriden to provide for specific behaviors.
95 */
96class IOUSBHIDDriver : public IOHIDDevice
97{
98 OSDeclareDefaultStructors(IOUSBHIDDriver)
99
100 IOUSBInterface *_interface;
101 IOUSBDevice*_device;
102 IOUSBPipe *_interruptPipe;
103 UInt32_maxReportSize;
104 IOBufferMemoryDescriptor *_buffer;
105 IOUSBCompletion_completion;
106 UInt32_retryCount;
107 thread_call_t_deviceDeadCheckThread;
108 thread_call_t_clearFeatureEndpointHaltThread;
109 bool_deviceDeadThreadActive;
110 bool_deviceIsDead; // Should really be called "abort expected"
111 bool_deviceHasBeenDisconnected;
112 bool_needToClose;
113 UInt32_outstandingIO;
114 IOCommandGate *_gate;
115 IOUSBPipe *_interruptOutPipe;
116 UInt32_locationID;
117 IOBufferMemoryDescriptor *_outBuffer;// Obsolete
118 UInt32_deviceUsage;// Obsolete
119 UInt32_deviceUsagePage;// Obsolete
120
121 struct IOUSBHIDDriverExpansionData
122 {
123 IOWorkLoop*_workLoop;
124 thread_call_t_handleReportThread;
125 IOService *_rootDomain;
126 AbsoluteTime_wakeUpTime;
127 IOUSBCompletionWithTimeStamp_completionWithTimeStamp;
128 bool_checkForTimeStamp;
129 UInt32_msToIgnoreTransactionsAfterWake;
130 IOTimerEventSource*_suspendPortTimer;
131bool_portSuspended;
132UInt32_suspendTimeoutInMS;
133UInt8_interfaceNumber;
134bool_logHIDReports;
135UInt8_hidLoggingLevel;
136bool_needToClearPipeStall;
137SInt32_queuedReports;
138AbsoluteTime_interruptTimeStamp;
139bool_powerStateChanging;
140unsigned long_myPowerState;
141bool_pendingRead;
142UInt32_deviceDeadCheckLock;// "Lock" to prevent us from executing the device dead check while in progress
143 };
144 IOUSBHIDDriverExpansionData *_usbHIDExpansionData;
145
146 static void InterruptReadHandlerEntry(OSObject *target, void *param, IOReturn status, UInt32 bufferSizeRemaining);
147 static void InterruptReadHandlerWithTimeStampEntry(OSObject *target, void *param, IOReturn status, UInt32 bufferSizeRemaining, AbsoluteTime timeStamp);
148 voidInterruptReadHandler(IOReturn status, UInt32 bufferSizeRemaining, AbsoluteTime timeStamp);
149
150 static void CheckForDeadDeviceEntry(OSObject *target);
151 voidCheckForDeadDevice();
152
153 static voidClearFeatureEndpointHaltEntry(OSObject *target);
154 voidClearFeatureEndpointHalt(void);
155
156 static voidHandleReportEntry(OSObject *target, thread_call_param_t timeStamp);
157 voidHandleReport(AbsoluteTime timeStamp);
158
159 virtual void processPacket(void *data, UInt32 size);// Obsolete
160
161 static IOReturnChangeOutstandingIO(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);
162 static IOReturnClaimPendingRead(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);
163
164 static voidSuspendPortTimer(OSObject *target, IOTimerEventSource *sender);
165
166public:
167
168 // IOService methods
169 //
170 virtual boolinit(OSDictionary *properties);
171 virtual boolstart(IOService * provider);
172 virtual booldidTerminate( IOService * provider, IOOptionBits options, bool * defer );
173 virtual boolwillTerminate( IOService * provider, IOOptionBits options );
174 virtual voidstop(IOService * provider);
175 virtual voidfree();
176 virtual IOReturnmessage( UInt32 type, IOService * provider, void * argument = 0 );
177virtual unsigned longmaxCapabilityForDomainState ( IOPMPowerFlags domainState );
178virtual IOReturnpowerStateWillChangeTo ( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService* whatDevice);
179virtual IOReturnsetPowerState ( unsigned long powerStateOrdinal, IOService* whatDevice );
180virtual IOReturnpowerStateDidChangeTo ( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService* whatDevice);
181 virtual voidpowerChangeDone ( unsigned long fromState);
182
183
184 // IOHIDDevice methods
185 //
186 virtual boolhandleStart(IOService * provider);
187 virtual voidhandleStop(IOService * provider);
188
189 virtual IOReturn newReportDescriptor( IOMemoryDescriptor ** descriptor ) const;
190
191 virtual OSString * newTransportString() const;
192
193 virtual OSNumber * newVendorIDNumber() const;
194
195 virtual OSNumber * newProductIDNumber() const;
196
197 virtual OSNumber * newVersionNumber() const;
198
199 virtual OSString * newManufacturerString() const;
200
201 virtual OSString * newProductString() const;
202
203 virtual OSString * newSerialNumberString() const;
204
205 virtual OSNumber * newLocationIDNumber() const;
206
207 virtual OSNumber * newCountryCodeNumber() const;
208
209 virtual IOReturngetReport( IOMemoryDescriptor * report,
210 IOHIDReportType reportType,
211 IOOptionBits options = 0 );
212
213 virtual IOReturn setReport( IOMemoryDescriptor * report,
214 IOHIDReportType reportType,
215 IOOptionBits options = 0 );
216
217 // HID driver methods
218 //
219 virtual OSString * newIndexedString(UInt8 index) const;
220
221 virtual UInt32getMaxReportSize();
222
223 virtual voidDecrementOutstandingIO(void);
224 virtual voidIncrementOutstandingIO(void);
225 virtual IOReturnStartFinalProcessing();
226 virtual IOReturnSetIdleMillisecs(UInt16 msecs);
227
228private:
229
230IOReturnGetHIDDescriptor(UInt8 inDescriptorType, UInt8 inDescriptorIndex, UInt8 *vOutBuf, UInt32 *vOutSize);
231IOReturnGetReport(UInt8 inReportType, UInt8 inReportID, UInt8 *vInBuf, UInt32 *vInSize);
232IOReturnSetReport(UInt8 outReportType, UInt8 outReportID, UInt8 *vOutBuf, UInt32 vOutSize);
233IOReturnGetIndexedString(UInt8 index, UInt8 *vOutBuf, UInt32 *vOutSize, UInt16 lang = 0x409) const;
234IOReturnSetProtocol(UInt32 protocolType);
235charGetHexChar(char hexChar);
236IOReturnAbortAndSuspend( bool suspend );
237
238
239
240#if ENABLE_HIDREPORT_LOGGING
241 void LogBufferReport(char *report, UInt32 len);
242 void LogMemReport(IOMemoryDescriptor * reportBuffer);
243 char GetHexChar(char hexChar);
244#endif
245
246public:
247 OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 0);
248 virtual IOReturn RearmInterruptRead();
249
250 /*!
251@function SuspendPort
252 @abstract Suspends the port for this device or optionally sets a timeout to suspend after a period of inactivity.
253 @discussion This call can be used to immediately suspend/resume a port or to enable the suspension of the port after a period of inactivity. If called with suspendPort = true (no timeout parameter), the HID driver
254 will immediately suspend the port, after aborting any outstanding reads on the interrupt pipe. If called with suspendPort = true and timeout != 0, it will suspend the port after the timeout number of ms have
255 passed without any read completions. If called with suspendPort = false, the port will be immediately resumed and the reads will be re-issued. If a timeout was enabled, it will be cancelled.
256 @param suspendPort Boolean value. true = suspend the port, false = resume the port.
257 @param timeoutMSValue in milliseconds If value is non-zero, the port will be suspended after the timeout milliseconds have passed without any read completions.
258 @result The IOReturn value from the IOUSBDevice::Suspend() call.
259*/
260 OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 1);
261virtual IOReturnSuspendPort(bool suspendPort, UInt32 timeoutMS = 0);
262
263 OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 2);
264virtual boolIsPortSuspended();
265
266 OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 3);
267 virtual voidLogMemReport(UInt8 level, IOMemoryDescriptor * reportBuffer, IOByteCount size);
268
269 OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 4);
270virtual IOReturnInitializeUSBHIDPowerManagement(IOService *provider);
271
272 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 5);
273 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 6);
274 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 7);
275 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 8);
276 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 9);
277 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 10);
278 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 11);
279 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 12);
280 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 13);
281 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 14);
282 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 15);
283 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 16);
284 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 17);
285 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 18);
286 OSMetaClassDeclareReservedUnused(IOUSBHIDDriver, 19);
287};
288
289#endif// IOUSBHIDDRIVER_H
290

Archive Download this file

Revision: 1129