Root/
Source at commit 1165 created 13 years 11 days ago. By slice, new targets: make image and make pkg, Russian localization | |
---|---|
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_LOGGING␉0␊ |
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 kHIDDriverRetryCount␉3␊ |
76 | #define␉kUSBHIDReportLoggingLevel␉"USB HID Report Logging Level"␊ |
77 | ␊ |
78 | ␊ |
79 | // power states for the driver (awake or suspended)␊ |
80 | enum␊ |
81 | {␊ |
82 | ␉kUSBHIDPowerStateOff␉␉= 0,␊ |
83 | ␉kUSBHIDPowerStateRestart␉= 1,␊ |
84 | ␉kUSBHIDPowerStateSleep␉␉= 2,␉␉␉// this could be system sleep or idle sleep␊ |
85 | ␉kUSBHIDPowerStateLowPower␉= 3,␉␉␉// this is idling␊ |
86 | ␉kUSBHIDPowerStateOn␉␉␉= 4,␉␉␉// this is fully on␊ |
87 | ␉kUSBHIDNumberPowerStates␉= 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 | */␊ |
96 | class 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;␊ |
131 | ␉␉bool␉␉␉␉␉␉␉_portSuspended;␊ |
132 | ␉␉UInt32␉␉␉␉␉␉␉_suspendTimeoutInMS;␊ |
133 | ␉␉UInt8␉␉␉␉␉␉␉_interfaceNumber;␊ |
134 | ␉␉bool␉␉␉␉␉␉␉_logHIDReports;␊ |
135 | ␉␉UInt8␉␉␉␉␉␉␉_hidLoggingLevel;␊ |
136 | ␉␉bool␉␉␉␉␉␉␉_needToClearPipeStall;␊ |
137 | ␉␉SInt32␉␉␉␉␉␉␉_queuedReports;␊ |
138 | ␉␉AbsoluteTime␉␉␉␉␉_interruptTimeStamp;␊ |
139 | ␉␉bool␉␉␉␉␉␉␉_powerStateChanging;␊ |
140 | ␉␉unsigned long␉␉␉␉␉_myPowerState;␊ |
141 | ␉␉bool␉␉␉␉␉␉␉_pendingRead;␊ |
142 | ␉␉UInt32␉␉␉␉␉␉␉_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 | void␉␉␉␉InterruptReadHandler(IOReturn status, UInt32 bufferSizeRemaining, AbsoluteTime timeStamp);␊ |
149 | ␊ |
150 | static void ␉␉CheckForDeadDeviceEntry(OSObject *target);␊ |
151 | void␉␉␉␉CheckForDeadDevice();␊ |
152 | ␊ |
153 | static void␉␉␉ClearFeatureEndpointHaltEntry(OSObject *target);␊ |
154 | void␉␉␉␉ClearFeatureEndpointHalt(void);␊ |
155 | ␊ |
156 | static void␉␉␉HandleReportEntry(OSObject *target, thread_call_param_t timeStamp);␊ |
157 | void␉␉␉␉HandleReport(AbsoluteTime timeStamp);␊ |
158 | ␊ |
159 | virtual void ␉␉processPacket(void *data, UInt32 size);␉␉// Obsolete␊ |
160 | ␊ |
161 | static IOReturn␉␉ChangeOutstandingIO(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);␊ |
162 | static IOReturn␉␉ClaimPendingRead(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);␊ |
163 | ␊ |
164 | static void␉␉␉SuspendPortTimer(OSObject *target, IOTimerEventSource *sender);␊ |
165 | ␊ |
166 | public:␊ |
167 | ␊ |
168 | // IOService methods␊ |
169 | //␊ |
170 | virtual bool␉␉␉init(OSDictionary *properties);␊ |
171 | virtual bool␉␉␉start(IOService * provider);␊ |
172 | virtual bool␉␉␉didTerminate( IOService * provider, IOOptionBits options, bool * defer );␊ |
173 | virtual bool␉␉␉willTerminate( IOService * provider, IOOptionBits options );␊ |
174 | virtual void␉␉␉stop(IOService * provider);␊ |
175 | virtual void␉␉␉free();␊ |
176 | virtual IOReturn␉␉message( UInt32 type, IOService * provider, void * argument = 0 );␊ |
177 | ␉virtual unsigned long␉maxCapabilityForDomainState ( IOPMPowerFlags domainState );␊ |
178 | ␉virtual IOReturn␉␉powerStateWillChangeTo ( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService* whatDevice);␊ |
179 | ␉virtual IOReturn␉␉setPowerState ( unsigned long powerStateOrdinal, IOService* whatDevice );␊ |
180 | ␉virtual IOReturn␉␉powerStateDidChangeTo ( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService* whatDevice);␊ |
181 | ␉virtual void␉␉␉powerChangeDone ( unsigned long fromState);␊ |
182 | ␊ |
183 | ␊ |
184 | // IOHIDDevice methods␊ |
185 | //␊ |
186 | virtual bool␉␉handleStart(IOService * provider);␊ |
187 | virtual void␉␉handleStop(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 IOReturn␉getReport( 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 UInt32␉␉getMaxReportSize();␊ |
222 | ␉␊ |
223 | virtual void␉␉DecrementOutstandingIO(void);␊ |
224 | virtual void␉␉IncrementOutstandingIO(void);␊ |
225 | virtual IOReturn␉StartFinalProcessing();␊ |
226 | virtual IOReturn␉SetIdleMillisecs(UInt16 msecs);␊ |
227 | ␊ |
228 | private:␊ |
229 | ␊ |
230 | ␉IOReturn␉␉␉GetHIDDescriptor(UInt8 inDescriptorType, UInt8 inDescriptorIndex, UInt8 *vOutBuf, UInt32 *vOutSize);␊ |
231 | ␉IOReturn␉␉␉GetReport(UInt8 inReportType, UInt8 inReportID, UInt8 *vInBuf, UInt32 *vInSize);␊ |
232 | ␉IOReturn␉␉␉SetReport(UInt8 outReportType, UInt8 outReportID, UInt8 *vOutBuf, UInt32 vOutSize);␊ |
233 | ␉IOReturn␉␉␉GetIndexedString(UInt8 index, UInt8 *vOutBuf, UInt32 *vOutSize, UInt16 lang = 0x409) const;␊ |
234 | ␉IOReturn␉␉␉SetProtocol(UInt32 protocolType);␊ |
235 | ␉char␉␉␉␉GetHexChar(char hexChar);␊ |
236 | ␉IOReturn␉␉␉AbortAndSuspend( 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 | ␊ |
246 | public:␊ |
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 timeoutMS␉Value 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);␊ |
261 | ␉virtual IOReturn␉SuspendPort(bool suspendPort, UInt32 timeoutMS = 0);␊ |
262 | ␉␊ |
263 | OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 2);␊ |
264 | ␉virtual bool␉␉IsPortSuspended();␊ |
265 | ␉␊ |
266 | OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 3);␊ |
267 | virtual void␉␉LogMemReport(UInt8 level, IOMemoryDescriptor * reportBuffer, IOByteCount size);␊ |
268 | ␊ |
269 | OSMetaClassDeclareReservedUsed(IOUSBHIDDriver, 4);␊ |
270 | ␉virtual IOReturn␉InitializeUSBHIDPowerManagement(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 |