]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/hidsystem/IOHIDSystem.h
c39558c89ce1f45c11ba2778e1fc05ab23ec23b2
[apple/xnu.git] / iokit / IOKit / hidsystem / IOHIDSystem.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 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
23 *
24 * EventDriver.h - Exported Interface Event Driver object.
25 *
26 * The EventDriver is a pseudo-device driver.
27 *
28 * HISTORY
29 * 19 Mar 1992 Mike Paquette at NeXT
30 * Created.
31 * 4 Aug 1993 Erik Kay at NeXT
32 * API cleanup
33 */
34
35 #ifndef _IOHIDSYSTEM_H
36 #define _IOHIDSYSTEM_H
37
38 #include <IOKit/IOTimerEventSource.h>
39 #include <IOKit/IOService.h>
40 #include <IOKit/IOUserClient.h>
41 #include <IOKit/IOWorkLoop.h>
42 #include <IOKit/IOCommandQueue.h>
43 #include <IOKit/IOBufferMemoryDescriptor.h>
44 #include <IOKit/pwr_mgt/IOPM.h>
45 #include <IOKit/graphics/IOGraphicsDevice.h>
46 #include <IOKit/hidsystem/IOHIDevice.h>
47 #include <IOKit/hidsystem/IOHIDShared.h>
48 #include <IOKit/hidsystem/IOHIDTypes.h>
49 #include <IOKit/hidsystem/IOLLEvent.h>
50 #include "ev_keymap.h" /* For NX_NUM_SCANNED_SPECIALKEYS */
51
52 typedef void (*IOHIDAction)(OSObject *, void *);
53
54 class IOHIDSystem : public IOService
55 {
56 OSDeclareDefaultStructors(IOHIDSystem);
57
58 friend class IOHIDUserClient;
59 friend class IOHIDParamUserClient;
60
61 private:
62 IOLock * driverLock;
63
64 IOWorkLoop * workLoop;
65 IOTimerEventSource * timerES;
66 IOCommandQueue * cmdQ;
67 IOUserClient * serverConnect;
68 IOUserClient * paramConnect;
69 IONotifier * publishNotify;
70
71 // Ports on which we hold send rights
72 mach_port_t eventPort; // Send msg here when event queue
73 // goes non-empty
74 mach_port_t _specialKeyPort[NX_NUM_SCANNED_SPECIALKEYS]; // Special key msgs
75 void *eventMsg; // Msg to be sent to Window Server.
76
77 // Shared memory area information
78 IOBufferMemoryDescriptor * globalMemory;
79 vm_offset_t shmem_addr; // kernel address of shared memory
80 vm_size_t shmem_size; // size of shared memory
81
82 // Pointers to structures which occupy the shared memory area.
83 volatile void *evs; // Pointer to private driver shmem
84 volatile EvGlobals *evg; // Pointer to EvGlobals (shmem)
85 // Internal variables related to the shared memory area
86 int lleqSize; // # of entries in low-level queue
87 // FIXME: why is this ivar lleqSize an ivar? {Dan]
88
89 // Screens list
90 vm_size_t evScreenSize; // Byte size of evScreen array
91 void *evScreen; // array of screens known to driver
92 volatile void *lastShmemPtr; // Pointer used to index thru shmem
93 // while assigning shared areas to
94 // drivers.
95 int screens; // running total of allocated screens
96 UInt32 cursorScreens; // bit mask of screens with cursor present
97 UInt32 cursorPinScreen;// a screen to pin against
98 Bounds cursorPin; // Range to which cursor is pinned
99 // while on this screen.
100 Bounds workSpace; // Bounds of full workspace.
101 // Event Status state - This includes things like event timestamps,
102 // time til screen dim, and related things manipulated through the
103 // Event Status API.
104 //
105 Point pointerLoc; // Current pointing device location
106 // The value leads evg->cursorLoc.
107 Point pointerDelta; // The cumulative pointer delta values since
108 // previous mouse move event was posted
109 Point clickLoc; // location of last mouse click
110 Point clickSpaceThresh; // max mouse delta to be a doubleclick
111 int clickState; // Current click state
112 unsigned char lastPressure; // last pressure seen
113 bool lastProximity; // last proximity state seen
114
115 SInt32 curVolume; // Value of volume setting.
116 SInt32 dimmedBrightness;// Value of screen brightness when autoDim
117 // has turned on.
118 SInt32 curBright; // The current brightness is cached here while
119 // the driver is open. This number is always
120 // the user-specified brightness level; if the
121 // screen is autodimmed, the actual brightness
122 // level in the monitor will be less.
123 SInt32 autoDimmed; // Is screen currently autodimmed?
124 bool evOpenCalled; // Has the driver been opened?
125 bool evInitialized; // Has the first-open-only initialization run?
126 bool eventsOpen; // Boolean: has evmmap been called yet?
127 bool cursorStarted; // periodic events running?
128 bool cursorEnabled; // cursor positioning ok?
129 bool cursorCoupled; // cursor positioning on pointer moves ok?
130
131 short leftENum; // Unique ID for last left down event
132 short rightENum; // Unique ID for last right down event
133
134 // The periodic event mechanism timestamps and state
135 // are recorded here.
136 AbsoluteTime thisPeriodicRun;
137 AbsoluteTime periodicEventDelta;// Time between periodic events
138 // todo: make infinite
139 AbsoluteTime clickTime; // Timestamps used to determine doubleclicks
140 AbsoluteTime clickTimeThresh;
141 AbsoluteTime autoDimPeriod; // How long since last user action before
142 // we autodim screen? User preference item,
143 // set by InitMouse and evsioctl
144 AbsoluteTime autoDimTime; // Time value when we will autodim screen,
145 // if autoDimmed is 0.
146 // Set in LLEventPost.
147
148 AbsoluteTime waitSustain; // Sustain time before removing cursor
149 AbsoluteTime waitSusTime; // Sustain counter
150 AbsoluteTime waitFrameRate; // Ticks per wait cursor frame
151 AbsoluteTime waitFrameTime; // Wait cursor frame timer
152
153 AbsoluteTime postedVBLTime; // Used to post mouse events once per frame
154 AbsoluteTime lastEventTime;
155 AbsoluteTime lastMoveTime;
156 SInt32 accumDX;
157 SInt32 accumDY;
158
159 // Flags used in scheduling periodic event callbacks
160 bool needSetCursorPosition;
161 bool needToKickEventConsumer;
162 IOLock * kickConsumerLock;
163
164 public:
165 IOService * displayManager; // points to display manager
166 IOPMPowerFlags displayState;
167
168 private:
169 inline short getUniqueEventNum();
170
171 virtual IOReturn powerStateDidChangeTo ( IOPMPowerFlags, unsigned long, IOService*);
172 /* Resets */
173 void _resetMouseParameters();
174 void _resetKeyboardParameters();
175
176 /* Initialize the shared memory area */
177 void initShmem();
178 /* Dispatch low level events through shared memory to the WindowServer */
179 void postEvent(int what,
180 /* at */ Point * location,
181 /* atTime */ AbsoluteTime ts,
182 /* withData */ NXEventData * myData);
183 /* Dispatch mechanisms for screen state changes */
184 void evDispatch(
185 /* command */ EvCmd evcmd);
186 /* Dispatch mechanism for special key press */
187 void evSpecialKeyMsg(unsigned key,
188 /* direction */ unsigned dir,
189 /* flags */ unsigned f,
190 /* level */ unsigned l);
191 /* Message the event consumer to process posted events */
192 void kickEventConsumer();
193 IOReturn sendWorkLoopCommand(OSObject * target,
194 IOHIDAction action,
195 void * data);
196 static void _doPerformInIOThread( void* self,
197 void* target,
198 void* action,
199 void* data,
200 void* unused);
201 static void _periodicEvents(IOHIDSystem * self,
202 IOTimerEventSource *timer);
203
204 static void _performSpecialKeyMsg(IOHIDSystem * self,
205 struct evioSpecialKeyMsg *msg);
206 static void _performKickEventConsumer(IOHIDSystem * self,void *);
207
208 static bool publishNotificationHandler( IOHIDSystem * self,
209 void * ref, IOService * newService );
210
211 /*
212 * HISTORICAL NOTE:
213 * The following methods were part of the IOHIDSystem(Input) category;
214 * the declarations have now been merged directly into this class.
215 *
216 * Exported Interface Event Driver object input services.
217 */
218
219 private:
220 // Schedule next periodic run based on current event system state.
221 void scheduleNextPeriodicEvent();
222 // Message invoked to run periodic events. This method runs in the workloop.
223 void periodicEvents(IOTimerEventSource *timer);
224 // Start the cursor running.
225 bool startCursor();
226 // Repin cursor location.
227 bool resetCursor();
228 // Wait Cursor machinery.
229 void showWaitCursor();
230 void hideWaitCursor();
231 void animateWaitCursor();
232 void changeCursor(int frame);
233 // Return screen number a point lies on.
234 int pointToScreen(Point * p);
235 // Set the undimmed brightness.
236 void setBrightness(int b);
237 // Return undimmed brightness.
238 int brightness();
239 // Set the dimmed brightness.
240 void setAutoDimBrightness(int b);
241 // Return dimmed brightness.
242 int autoDimBrightness();
243 // Return the current brightness.
244 int currentBrightness();
245 // Dim all displays.
246 void doAutoDim();
247 // Return display brightness to normal.
248 void undoAutoDim();
249 // Force dim/undim.
250 void forceAutoDimState(bool dim);
251 // Audio volume control.
252 void setAudioVolume(int v);
253 // Audio volume control, from ext user.
254 void setUserAudioVolume(int v);
255 // Return audio volume.
256 int audioVolume();
257 // Propagate state out to screens.
258 inline void setBrightness();
259
260 inline void showCursor();
261 inline void hideCursor();
262 inline void moveCursor();
263 // Claim ownership of event sources.
264 void attachDefaultEventSources();
265 // Give up ownership of event sources.
266 void detachEventSources();
267 bool registerEventSource(IOHIDevice * source);
268
269 // Set abs cursor position.
270 void setCursorPosition(Point * newLoc, bool external);
271 void _setButtonState(int buttons,
272 /* atTime */ AbsoluteTime ts);
273 void _setCursorPosition(Point * newLoc, bool external);
274
275 void _postMouseMoveEvent(int what,
276 Point * location,
277 AbsoluteTime theClock);
278
279 /* END HISTORICAL NOTE */
280
281 public:
282 static IOHIDSystem * instance(); /* Return the current instance of the */
283 /* EventDriver, or 0 if none. */
284
285 virtual bool init(OSDictionary * properties = 0);
286 virtual IOHIDSystem * probe(IOService * provider,
287 SInt32 * score);
288 virtual bool start(IOService * provider);
289 virtual IOReturn message(UInt32 type, IOService * provider,
290 void * argument);
291 virtual void free();
292
293 virtual IOWorkLoop *getWorkLoop() const;
294
295 virtual IOReturn evOpen(void);
296 virtual IOReturn evClose(void);
297
298 virtual bool updateProperties(void);
299 virtual IOReturn setParamProperties(OSDictionary * dict);
300 virtual bool serializeProperties( OSSerialize * s ) const;
301
302 /* Create the shared memory area */
303 virtual IOReturn createShmem(void*,void*,void*,void*,void*,void*);
304 /* Set the port for event available notify msg */
305 virtual void setEventPort(mach_port_t port);
306 /* Set the port for the special key keypress msg */
307 virtual IOReturn setSpecialKeyPort(
308 /* keyFlavor */ int special_key,
309 /* keyPort */ mach_port_t key_port);
310 virtual mach_port_t specialKeyPort(int special_key);
311
312
313 virtual IOReturn newUserClient(task_t owningTask,
314 /* withToken */ void * security_id,
315 /* ofType */ UInt32 type,
316 /* client */ IOUserClient ** handler);
317
318 /*
319 * HISTORICAL NOTE:
320 * The following methods were part of the IOHIPointingEvents protocol;
321 * the declarations have now been merged directly into this class.
322 */
323
324 public:
325 /* Mouse event reporting */
326 virtual void relativePointerEvent(int buttons,
327 /* deltaX */ int dx,
328 /* deltaY */ int dy,
329 /* atTime */ AbsoluteTime ts);
330
331 /* Tablet event reporting */
332 virtual void absolutePointerEvent(int buttons,
333 /* at */ Point * newLoc,
334 /* withBounds */ Bounds * bounds,
335 /* inProximity */ bool proximity,
336 /* withPressure */ int pressure,
337 /* withAngle */ int stylusAngle,
338 /* atTime */ AbsoluteTime ts);
339
340 /* Mouse scroll wheel event reporting */
341 virtual void scrollWheelEvent(short deltaAxis1,
342 short deltaAxis2,
343 short deltaAxis3,
344 AbsoluteTime ts);
345
346
347 virtual void tabletEvent(NXEventData *tabletData,
348 AbsoluteTime ts);
349
350 virtual void proximityEvent(NXEventData *proximityData,
351 AbsoluteTime ts);
352
353 /*
354 * HISTORICAL NOTE:
355 * The following methods were part of the IOHIKeyboardEvents protocol;
356 * the declarations have now been merged directly into this class.
357 */
358
359 public:
360 virtual void keyboardEvent(unsigned eventType,
361 /* flags */ unsigned flags,
362 /* keyCode */ unsigned key,
363 /* charCode */ unsigned charCode,
364 /* charSet */ unsigned charSet,
365 /* originalCharCode */ unsigned origCharCode,
366 /* originalCharSet */ unsigned origCharSet,
367 /* keyboardType */ unsigned keyboardType,
368 /* repeat */ bool repeat,
369 /* atTime */ AbsoluteTime ts);
370
371 virtual void keyboardSpecialEvent( unsigned eventType,
372 /* flags */ unsigned flags,
373 /* keyCode */ unsigned key,
374 /* specialty */ unsigned flavor,
375 /* guid */ UInt64 guid,
376 /* repeat */ bool repeat,
377 /* atTime */ AbsoluteTime ts);
378
379 virtual void updateEventFlags(unsigned flags); /* Does not generate events */
380
381
382
383
384 private:
385
386 /*
387 * statics for upstream callouts
388 */
389
390 void _scaleLocationToCurrentScreen(Point *location, Bounds *bounds); // Should this one be public???
391
392 static void _relativePointerEvent( IOHIDSystem * self,
393 int buttons,
394 /* deltaX */ int dx,
395 /* deltaY */ int dy,
396 /* atTime */ AbsoluteTime ts);
397
398 /* Tablet event reporting */
399 static void _absolutePointerEvent(IOHIDSystem * self,
400 int buttons,
401 /* at */ Point * newLoc,
402 /* withBounds */ Bounds * bounds,
403 /* inProximity */ bool proximity,
404 /* withPressure */ int pressure,
405 /* withAngle */ int stylusAngle,
406 /* atTime */ AbsoluteTime ts);
407
408 /* Mouse scroll wheel event reporting */
409 static void _scrollWheelEvent(IOHIDSystem *self,
410 short deltaAxis1,
411 short deltaAxis2,
412 short deltaAxis3,
413 AbsoluteTime ts);
414
415 static void _tabletEvent(IOHIDSystem *self,
416 NXEventData *tabletData,
417 AbsoluteTime ts);
418
419 static void _proximityEvent(IOHIDSystem *self,
420 NXEventData *proximityData,
421 AbsoluteTime ts);
422
423 static void _keyboardEvent( IOHIDSystem * self,
424 unsigned eventType,
425 /* flags */ unsigned flags,
426 /* keyCode */ unsigned key,
427 /* charCode */ unsigned charCode,
428 /* charSet */ unsigned charSet,
429 /* originalCharCode */ unsigned origCharCode,
430 /* originalCharSet */ unsigned origCharSet,
431 /* keyboardType */ unsigned keyboardType,
432 /* repeat */ bool repeat,
433 /* atTime */ AbsoluteTime ts);
434 static void _keyboardSpecialEvent( IOHIDSystem * self,
435 unsigned eventType,
436 /* flags */ unsigned flags,
437 /* keyCode */ unsigned key,
438 /* specialty */ unsigned flavor,
439 /* guid */ UInt64 guid,
440 /* repeat */ bool repeat,
441 /* atTime */ AbsoluteTime ts);
442 static void _updateEventFlags( IOHIDSystem * self,
443 unsigned flags); /* Does not generate events */
444
445
446 /*
447 * HISTORICAL NOTE:
448 * The following methods were part of the IOUserClient protocol;
449 * the declarations have now been merged directly into this class.
450 */
451
452 public:
453
454 virtual IOReturn setEventsEnable(void*,void*,void*,void*,void*,void*);
455 virtual IOReturn setCursorEnable(void*,void*,void*,void*,void*,void*);
456 virtual IOReturn extPostEvent(void*,void*,void*,void*,void*,void*);
457 virtual IOReturn extSetMouseLocation(void*,void*,void*,void*,void*,void*);
458 virtual IOReturn extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
459
460 /*
461 * HISTORICAL NOTE:
462 * The following methods were part of the IOScreenRegistration protocol;
463 * the declarations have now been merged directly into this class.
464 *
465 * Methods exported by the EventDriver for display systems.
466 *
467 * The screenRegister protocol is used by frame buffer drivers to register
468 * themselves with the Event Driver. These methods are called in response
469 * to an _IOGetParameterInIntArray() call with "IO_Framebuffer_Register" or
470 * "IO_Framebuffer_Unregister".
471 */
472
473 public:
474 virtual int registerScreen(IOGraphicsDevice * instance,
475 /* bounds */ Bounds * bp);
476 // /* shmem */ void ** addr,
477 // /* size */ int * size)
478 virtual void unregisterScreen(int index);
479
480 /*
481 * HISTORICAL NOTE:
482 * The following methods were part of the IOWorkspaceBounds protocol;
483 * the declarations have now been merged directly into this class.
484 *
485 * Absolute position input devices and some specialized output devices
486 * may need to know the bounding rectangle for all attached displays.
487 * The following method returns a Bounds* for the workspace. Please note
488 * that the bounds are kept as signed values, and that on a multi-display
489 * system the minx and miny values may very well be negative.
490 */
491
492 public:
493 virtual Bounds * workspaceBounds();
494
495 /* END HISTORICAL NOTES */
496 };
497
498 #endif /* !_IOHIDSYSTEM_H */