2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /******************************************************************************
25 Ioctl calls for the events driver
28 Copyright 1988 NeXT, Inc.
30 CAUTION: Developers should stick to the API exported in
31 <drivers/event_status_driver.h> to guarantee
32 binary compatability of their applications in future
37 09Dec88 Leo Broken out from evsio.h
38 24Aug89 Ted ANSI function prototyping.
39 19Feb90 Ted Major revision for multiple driver support.
40 26Feb90 Ted New evioScreen structure and EVIOST ioctl.
41 12Mar90 Ted New ev_unregister_screen function, SCREENTOKEN constant.
42 06May90 Ted Added AALastEventSent and AALastEventConsumed to EvVars.
43 22May90 Trey More wait cursor vars in EvVars.
44 13Jun90 Ted NXCursorData structure.
45 18Jun90 Ted Default wait cursor constants.
46 26Sep90 Ted Enhanced cursor system to support intelligent drivers.
47 26Nov90 Ted Removed NXSaveCursor and NXCursorData structures
48 28Nov90 Ted Remove EvVars, rolled into EventGlobals
49 28Nov90 Ted Renamed EventGlobals -> EvGlobals, eventGlobals -> evg
50 05May92 Mike Reworked for NRW driver architecture.
52 ******************************************************************************/
57 #include <sys/cdefs.h>
62 #include <IOKit/system.h>
64 #include <mach/message.h>
65 #include <IOKit/IOKitLib.h>
68 #include <IOKit/IOReturn.h>
69 #include <IOKit/graphics/IOGraphicsTypes.h>
70 #include <IOKit/hidsystem/IOHIDTypes.h>
71 #include <IOKit/hidsystem/IOLLEvent.h>
74 * Identify this driver as one that uses the new driverkit and messaging API
76 #ifndef _NeXT_MACH_EVENT_DRIVER_
77 #define _NeXT_MACH_EVENT_DRIVER_ (1)
78 #endif /* _NeXT_MACH_EVENT_DRIVER_ */
81 /* Pressure Constants */
82 #define MINPRESSURE EV_MINPRESSURE
83 #define MAXPRESSURE EV_MAXPRESSURE
85 #define LLEQSIZE 80 /* Entries in low-level event queue */
87 typedef struct _NXEQElStruct
{
88 int next
; /* Slot of lleq for next event */
89 ev_lock_data_t sema
; /* Is high-level code reading this event now? */
90 NXEvent event
; /* The event itself */
94 /******************************************************************************
95 SHARED MEMORY OVERVIEW
98 The ev driver and PostScript share at least one page of wired memory.
99 This memory contains the low-level event queue which ev deposits events
100 into and PostScript reads events from. Also, this memory contains other
101 important data such as wait cursor state and some general cursor state.
102 This memory is critical for speed. That is, we avoid having to make
103 system calls for common operations.
105 SHARED MEMORY REGIONS
106 There are currently three "regions" or "zones" delineated within this
107 shared memory. The first zone is the EvOffsets structure. This structure
108 contains two offsets from the beginning of shared memory. The first offset
109 is to the second zone, EvGlobals. The second offset is to the third
110 zone, private shmem for drivers.
112 INITIALIZATION OF SHARED MEMORY
113 When the WindowServer starts up, it finds all screens that will be active.
114 It then opens the ev driver and calls the EVIOSSCR ioctl repeatedly for
115 each screen in use. This lets the ev driver set up the evScreen array
116 and fill in each element. This ioctl also returns to PostScript a running
117 total shared memory size with which to allocate. PostScript then allocates
118 a region of memory this size and calls evmmap to "map in" this shared
119 region. Evmmap initializes and fills in the EvOffsets and EvGlobals.
120 Next the WindowServer calls each screen in turn to register itself with
121 the ev driver in the same sequence as presented to EVIOSSCR. Each screen
122 driver calls ev_register_screen() which among other things allocates a
123 part of the private shmem (of the third shared memory zone) for the driver.
126 You can easily display and set this shared memory from kgdb, but usually
127 cannot do so from within PostScript. Gdb (or some weird interaction
128 between gdb and the os) chokes on this shmem. So if you read or write
129 this area of memory, copy-on-write will occur and you'll get a completely
130 new page for PostScript. This will render the shared memory scheme
131 useless and you will have to restart PostScript. It was my understanding
132 that before, we were able to "read" this area from PS, but not write to
133 it (the idea behind copy-on-WRITE). However, this seems to be broken
134 in 2.0. We think this is a kernel bug.
135 ******************************************************************************/
137 typedef volatile struct _evOffsets
{
138 int evGlobalsOffset
; /* Offset to EvGlobals structure */
139 int evShmemOffset
; /* Offset to private shmem regions */
142 /******************************************************************************
144 This structures defines the portion of the events driver data structure
145 that is exported to the PostScript server. It contains the event queue
146 which is in memory shared between the driver and the PostScript server.
147 All the variables necessary to read and process events from the queue are
149 ******************************************************************************/
151 typedef volatile struct _evGlobals
{
152 ev_lock_data_t cursorSema
; /* set to disable periodic code */
153 int LLEHead
; /* The next event to be read */
154 int LLETail
; /* Where the next event will go */
155 int LLELast
; /* The last event entered */
156 int eNum
; /* Unique id for mouse events */
157 int buttons
; /* State of the mouse buttons 1==down, 0==up */
158 int eventFlags
; /* The current value of event.flags */
159 int VertRetraceClock
; /* The current value of event.time */
160 IOGPoint cursorLoc
; /* The current location of the cursor */
161 int frame
; /* current cursor frame */
162 IOGBounds workBounds
; /* bounding box of all screens */
163 IOGBounds mouseRect
; /* Rect for mouse-exited events */
164 int version
; /* for run time checks */
165 int structSize
; /* for run time checks */
166 unsigned int reservedA
[32];
168 unsigned reserved
:27;
169 unsigned wantPressure
:1; /* pressure in current mouseRect? */
170 unsigned wantPrecision
:1; /* precise coordinates in current mouseRect? */
171 unsigned dontWantCoalesce
:1;/* coalesce within the current mouseRect? */
172 unsigned dontCoalesce
:1; /* actual flag which determines coalescing */
173 unsigned mouseRectValid
:1; /* If nonzero, post a mouse-exited
174 whenever mouse outside mouseRect. */
175 int movedMask
; /* This contains an event mask for the
176 three events MOUSEMOVED,
177 LMOUSEDRAGGED, and RMOUSEDRAGGED.
178 It says whether driver should
179 generate those events. */
180 int AALastEventSent
; /* timestamp for wait cursor */
181 int AALastEventConsumed
; /* timestamp for wait cursor */
182 ev_lock_data_t waitCursorSema
; /* protects wait cursor fields */
183 int waitCursorUp
; /* Is wait cursor up? */
184 char ctxtTimedOut
; /* Has wait cursor timer expired? */
185 char waitCursorEnabled
; /* Play wait cursor game (per ctxt)? */
186 char globalWaitCursorEnabled
; /* Play wait cursor game (global)? */
187 int waitThreshold
; /* time before wait cursor appears */
188 NXEQElement lleq
[LLEQSIZE
]; /* The event queue itself */
192 /* These evio structs are used in various calls supported by the ev driver. */
203 typedef struct evioLLEvent _NXLLEvent
;
208 * On a keypress of a VOL UP or VOL DOWN key, we send a message to the
209 * sound server to notify it of the volume change. The message includes
210 * a flag to indicate which key was pressed, and the machine independant
211 * flag bits to indicate which modifier keys were pressed.
214 struct evioSpecialKeyMsg
218 int key
; // special key number, from bsd/dev/ev_keymap.h
219 msg_type_t directionType
;
220 int direction
; // NX_KEYDOWN, NX_KEYUP from event.h
221 msg_type_t flagsType
;
222 int flags
; // device independant flags from event.h
223 msg_type_t levelType
;
224 int level
; // EV_AUDIO_MIN_VOLUME to EV_AUDIO_MAX_VOLUME
227 struct evioSpecialKeyMsg
229 mach_msg_header_t Head
;
230 int key
; // special key number, from bsd/dev/ev_keymap.h
231 int direction
; // NX_KEYDOWN, NX_KEYUP from event.h
232 int flags
; // device independant flags from event.h
233 int level
; // EV_AUDIO_MIN_VOLUME to EV_AUDIO_MAX_VOLUME
237 #define EV_SPECIAL_KEY_MSG_ID (('S'<<24) | ('k'<<16) | ('e'<<8) | ('y'))
238 typedef struct evioSpecialKeyMsg
*evioSpecialKeyMsg_t
;
243 #define EV_AUDIO_MIN_VOLUME 0
244 #define EV_AUDIO_MAX_VOLUME 64
246 #define kIOHIDSystemClass "IOHIDSystem"
247 #define kIOHIKeyboardClass "IOHIKeyboard"
248 #define kIOHIPointingClass "IOHIPointing"
250 #define IOHIDSYSTEM_CONFORMSTO kIOHIDSystemClass
253 kIOHIDCurrentShmemVersion
= 2,
254 kIOHIDServerConnectType
= 0,
255 kIOHIDParamConnectType
= 1,
256 kIOHIDGlobalMemory
= 0,
257 kIOHIDEventNotification
= 0
261 typedef UInt16 (*MasterVolumeUpdate
)(void);
262 typedef bool (*MasterMuteUpdate
)(void);
265 MasterVolumeUpdate incrementMasterVolume
;
266 MasterVolumeUpdate decrementMasterVolume
;
267 MasterMuteUpdate toggleMasterMute
;
268 } MasterAudioFunctions
;
270 extern MasterAudioFunctions
*masterAudioFunctions
;
274 #ifndef _IOKIT_IOHIDLIB_H
275 #include <IOKit/hidsystem/IOHIDLib.h>
282 #endif /* !_DEV_EVIO_H */